1
1
// The Flash memory stores bytes from the hex -> mcs file as follows:
2
2
// Little Endian
3
- // Intellllll!!!!
4
3
// Notice that the Flash clock should be 1 for asynchronous read mode, which is
5
4
// the default mode.
6
5
@@ -28,7 +27,15 @@ module lcd_top(CLK_33MHZ_FPGA,
28
27
rotary_inc_a, rotary_inc_b,
29
28
dvi_d, dvi_vs, dvi_hs, dvi_xclk_p, dvi_xclk_n, dvi_reset_b,
30
29
dvi_de,
31
- dvi_sda, dvi_scl
30
+ dvi_sda, dvi_scl,
31
+ HDR1_2, HDR1_6, HDR1_8, HDR1_10,
32
+ HDR1_12, HDR1_14, HDR1_16, HDR1_18,
33
+ HDR1_20, HDR1_22, HDR1_24, HDR1_26,
34
+ HDR1_28, HDR1_30, HDR1_32, HDR1_34,
35
+ HDR1_36, HDR1_38, HDR1_40, HDR1_42,
36
+ HDR1_44, HDR1_46, HDR1_48, HDR1_50,
37
+ HDR1_52, HDR1_54, HDR1_56, HDR1_58,
38
+ HDR1_60, HDR1_64
32
39
);
33
40
parameter
34
41
I_HILO = 4 , I_SERIAL = 3 , I_TIMA = 2 , I_LCDC = 1 , I_VBLANK = 0 ;
@@ -57,7 +64,14 @@ module lcd_top(CLK_33MHZ_FPGA,
57
64
dvi_de, // DIV Outputs
58
65
dvi_reset_b; // DIV Outputs
59
66
inout dvi_sda, dvi_scl;
60
-
67
+ output wire HDR1_2, HDR1_6, HDR1_8, HDR1_10;
68
+ output wire HDR1_12, HDR1_14, HDR1_16, HDR1_18;
69
+ output wire HDR1_20, HDR1_22, HDR1_24, HDR1_26;
70
+ output wire HDR1_28, HDR1_30, HDR1_32, HDR1_34;
71
+ output wire HDR1_36, HDR1_38, HDR1_40, HDR1_42;
72
+ input HDR1_44, HDR1_46, HDR1_48, HDR1_50;
73
+ input HDR1_52, HDR1_54, HDR1_56, HDR1_58;
74
+ output wire HDR1_60, HDR1_64;
61
75
wire clock;
62
76
63
77
assign clock = CLK_33MHZ_FPGA;
@@ -324,14 +338,6 @@ module lcd_top(CLK_33MHZ_FPGA,
324
338
.clock(clock),
325
339
.reset(reset));
326
340
327
- `define MMIO_IF 16'hff0f
328
- `define MMIO_IE 16'hffff
329
- `define MMIO_DMA 16'hff46
330
- `define MMIO_DIV 16'hff04
331
- `define MMIO_TIMA 16'hff05
332
- `define MMIO_TMA 16'hff06
333
- `define MMIO_TAC 16'hff07
334
-
335
341
assign timer_reg_addr = (addr_ext == `MMIO_DIV) |
336
342
(addr_ext == `MMIO_TMA) |
337
343
(addr_ext == `MMIO_TIMA) |
@@ -350,16 +356,15 @@ module lcd_top(CLK_33MHZ_FPGA,
350
356
351
357
assign IF_load = timer_interrupt;
352
358
353
- timers tima_module (/*AUTOINST*/
354
- // Outputs
359
+ timers tima_module (// Outputs
355
360
.timer_interrupt (timer_interrupt),
356
361
// Inouts
357
362
.addr_ext (addr_ext[15 :0 ]),
358
363
.data_ext (data_ext[7 :0 ]),
359
364
// Inputs
360
365
.mem_re (mem_re),
361
366
.mem_we (mem_we),
362
- .clock (clock ),
367
+ .clock (cpu_clock ),
363
368
.reset (reset));
364
369
365
370
@@ -392,7 +397,7 @@ module lcd_top(CLK_33MHZ_FPGA,
392
397
cdiv (.clock_out(cpu_clock),
393
398
.clock_in(clock));
394
399
395
- breakpoints #(.reset_addr(16'h0007 ))
400
+ breakpoints #(.reset_addr(16'hffff ))
396
401
bpmod (.bp_addr(bp_addr[15 :0 ]),
397
402
.bp_addr_disp(bp_addr_disp[7 :0 ]),
398
403
// Inputs
@@ -402,11 +407,24 @@ module lcd_top(CLK_33MHZ_FPGA,
402
407
.reset(reset),
403
408
.clock(cpu_clock));
404
409
405
- wire addr_in_flash;
410
+ wire addr_in_bootstrap_reg;
411
+ addr_in_bootstrap_reg = addr_ext == `MMIO_BOOTSTRAP;
412
+ register #(8 ) bootstrap_reg (.in(data_ext),
413
+ .out(bootstrap_reg_data),
414
+ .load(addr_in_bootstrap_reg & mem_we),
415
+ .reset(reset),
416
+ .clock(clock));
406
417
407
- assign addr_in_flash = addr_ext <= 16'h140 ;
418
+ wire addr_in_flash;
419
+ assign addr_in_flash = (bootstrap_reg_data[0 ]) ? 1'b0 : addr_ext <= 16'h103 ;
408
420
409
421
/* The GPU */
422
+ wire addr_in_cart;
423
+ assign addr_in_cart = (bootstrap_reg_data[0 ]) ?
424
+ (`MEM_CART_START <= addr_ext) &&
425
+ (addr_ext <= `MEM_CART_END) :
426
+ 1'b0 ;
427
+
410
428
wire video_reg_w_enable;
411
429
wire [7 :0 ] video_reg_data_in;
412
430
wire [7 :0 ] video_reg_data_out;
@@ -441,8 +459,7 @@ module lcd_top(CLK_33MHZ_FPGA,
441
459
wire mem_enable_video;
442
460
assign mem_enable_video = video_reg_w_enable || video_vram_w_enable ||
443
461
video_oam_w_enable;
444
- gpu_top gpu (/*AUTOINST*/
445
- // Outputs
462
+ gpu_top gpu (// Outputs
446
463
.do_video (do_video[7 :0 ] ),
447
464
.mode_video (mode_video[1 :0 ]),
448
465
.int_req (int_req[1 :0 ]),
@@ -507,18 +524,57 @@ module lcd_top(CLK_33MHZ_FPGA,
507
524
.reg_w_enable(reg_w_enable)
508
525
);
509
526
510
- /* Dealing with memory */
511
- `define MEM_HIGH_END 16'hfffe
512
- `define MEM_HIGH_START 16'hff80
513
- `define MEM_OAM_END 16'hfe9f
514
- `define MEM_OAM_START 16'hfe00
515
- `define MEM_CART_END 16'hbfff
516
- `define MEM_CART_START 16'ha000
517
- `define MEM_WRAM_END 16'hdfff
518
- `define MEM_WRAM_START 16'hc000
519
- `define MEM_VRAM_END 16'h9fff
520
- `define MEM_VRAM_START 16'h8000
521
-
527
+ /* The cartridge */
528
+ wire [7 :0 ] cart_data;
529
+ wire [15 :0 ] cart_address;
530
+ wire cart_w_enable_l, cart_r_enable_l, cart_reset_l, cart_cs_sram_l;
531
+ assign cart_address = addr_ext;
532
+ assign cart_w_enable_l = 1 ;
533
+ assign cart_r_enable_l = 0 ;
534
+ assign cart_reset_l = 1 ;
535
+ assign cart_cs_sram_l = 1 ;
536
+
537
+ cartridge cart (/*AUTOINST*/
538
+ // Outputs
539
+ .HDR1_2 (HDR1_2),
540
+ .HDR1_6 (HDR1_6),
541
+ .HDR1_8 (HDR1_8),
542
+ .HDR1_10 (HDR1_10),
543
+ .HDR1_12 (HDR1_12),
544
+ .HDR1_14 (HDR1_14),
545
+ .HDR1_16 (HDR1_16),
546
+ .HDR1_18 (HDR1_18),
547
+ .HDR1_20 (HDR1_20),
548
+ .HDR1_22 (HDR1_22),
549
+ .HDR1_24 (HDR1_24),
550
+ .HDR1_26 (HDR1_26),
551
+ .HDR1_28 (HDR1_28),
552
+ .HDR1_30 (HDR1_30),
553
+ .HDR1_32 (HDR1_32),
554
+ .HDR1_34 (HDR1_34),
555
+ .HDR1_36 (HDR1_36),
556
+ .HDR1_38 (HDR1_38),
557
+ .HDR1_40 (HDR1_40),
558
+ .HDR1_42 (HDR1_42),
559
+ .HDR1_60 (HDR1_60),
560
+ .HDR1_64 (HDR1_64),
561
+ .cart_data (cart_data[7 :0 ]),
562
+ // Inputs
563
+ .HDR1_44 (HDR1_44),
564
+ .HDR1_46 (HDR1_46),
565
+ .HDR1_48 (HDR1_48),
566
+ .HDR1_50 (HDR1_50),
567
+ .HDR1_52 (HDR1_52),
568
+ .HDR1_54 (HDR1_54),
569
+ .HDR1_56 (HDR1_56),
570
+ .HDR1_58 (HDR1_58),
571
+ .cart_address (cart_address[15 :0 ]),
572
+ .clock (clock),
573
+ .cart_w_enable_l (cart_w_enable_l),
574
+ .cart_r_enable_l (cart_r_enable_l),
575
+ .cart_reset_l (cart_reset_l),
576
+ .cart_cs_sram_l (cart_cs_sram_l));
577
+
522
578
wire addr_in_wram, addr_in_junk;
523
579
wire addr_in_dma, addr_in_tima;
524
580
@@ -549,7 +605,7 @@ module lcd_top(CLK_33MHZ_FPGA,
549
605
.addra(wram_addr),
550
606
.dina(wram_data_in),
551
607
.douta(wram_data_out));
552
-
608
+
553
609
/* tristate #(8) gating_ff44(.out(data_ext),
554
610
.in(FF44_data),
555
611
.en(FF44_read&~mem_we));*/
@@ -578,9 +634,16 @@ module lcd_top(CLK_33MHZ_FPGA,
578
634
tristate #(8 ) gating_video_oam (.out(data_ext),
579
635
.in(do_video),// video_oam_data_out),
580
636
.en(video_oam_w_enable&~mem_we));
637
+ tristate #(8 ) gating_boostrap_reg (.out(data_ext),
638
+ .in(bootstrap_reg_data),
639
+ .en(addr_in_bootstrap_reg & ~mem_we));
640
+ tristate #(8 ) gating_boostrap_reg (.out(data_ext),
641
+ .in(cart_data),
642
+ .en(addr_in_cart & ~mem_we));
581
643
644
+
582
645
endmodule
583
646
// Local Variables:
584
647
// verilog-library-directories:("." "../../fpgaboy_files/" "../..")
585
- // verilog-library-files:("./cpu.v")
648
+ // verilog-library-files:("./cpu.v" "../../cartridge_interface.v" )
586
649
// End:
0 commit comments