Skip to content

Commit 1951ca5

Browse files
committed
allow up to 4095 roms (was 255)
1 parent 34d59fd commit 1951ca5

File tree

3 files changed

+33
-28
lines changed

3 files changed

+33
-28
lines changed

src/nes_tang20k.v

+19-15
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ reg [3:0] sd_state0 = 0;
432432
reg [19:0] timer; // 37 times per second
433433
always @(posedge clk) timer <= timer + 1;
434434

435-
//`define SD_REPORT
435+
// `define SD_REPORT
436436

437437
always@(posedge clk)begin
438438
state_0<={2'b0, loader_done};
@@ -443,31 +443,35 @@ always@(posedge clk)begin
443443
case (timer)
444444
20'h00000: begin
445445
`print("sd: file_total=", STR);
446+
sd_debug_reg = 2;
447+
end
448+
20'h10000: begin
449+
`print(sd_debug_out, 1);
446450
sd_debug_reg = 1;
447451
end
448-
20'h10000: `print(sd_debug_out, 1);
449-
20'h20000: begin
452+
20'h20000: `print(sd_debug_out, 1);
453+
20'h30000: begin
450454
`print(", file_start=", STR);
451-
sd_debug_reg = 2;
455+
sd_debug_reg = 3;
452456
end
453-
20'h30000: `print(sd_debug_out, 1);
454-
20'h40000: begin
457+
20'h40000: `print(sd_debug_out, 1);
458+
20'h50000: begin
455459
`print(", active=", STR);
456-
sd_debug_reg = 3;
460+
sd_debug_reg = 4;
457461
end
458-
20'h50000: `print(sd_debug_out, 1);
459-
20'h60000: begin
462+
20'h60000: `print(sd_debug_out, 1);
463+
20'h70000: begin
460464
`print(", total=", STR);
461-
sd_debug_reg = 4;
465+
sd_debug_reg = 5;
462466
end
463-
20'h70000: `print(sd_debug_out, 1);
467+
20'h80000: `print(sd_debug_out, 1);
464468
20'h80000: begin
465469
`print(", state=", STR);
466-
sd_debug_reg = 5;
470+
sd_debug_reg = 6;
467471
end
468-
20'h90000: `print(sd_debug_out, 1);
469-
20'ha0000: `print(", buttons=", STR);
470-
20'hb0000: `print({nes_btn, nes_btn2}, 2);
472+
20'ha0000: `print(sd_debug_out, 1);
473+
20'hb0000: `print(", buttons=", STR);
474+
20'hc0000: `print({nes_btn, nes_btn2}, 2);
471475
20'hf0000: `print("\n", STR);
472476
endcase
473477
`endif

src/sd_file_list_reader.v

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ module sd_file_list_reader #(
3030
input wire sddat0, // FPGA only read SDDAT signal but never drive it
3131
// command interface
3232
input op, // 0: list root dir, 1: read file. rstn <= 0 to restart a new operation.
33-
input [9:0] read_file, // file number to read for cmd=2
33+
input [11:0] read_file, // file number to read for cmd=2
3434
output [2:0] done, // operation finished
3535
// status output (optional for user)
3636
output wire [3:0] card_stat, // show the sdcard initialize status
@@ -40,7 +40,7 @@ module sd_file_list_reader #(
4040
// listing output (root directory, files only)
4141
output [7:0] list_name[0:51], // name of current file, max 52 chars, [255:248] is first char, etc.
4242
output [7:0] list_namelen,
43-
output reg [9:0] list_file_num, // number of current file: 0, 1...
43+
output reg [11:0] list_file_num, // number of current file: 0, 1...
4444
output list_en, // pulse on new list result
4545
// reading content data output (sync with clk)
4646
output reg outen, // when outen=1, a byte of file content is read out from outbyte

src/sd_loader.v

+12-11
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ module SDLoader #(
3434
`include "font.vh"
3535

3636
localparam [5:0] COLOR_BACK=13, COLOR_CURSOR=55, COLOR_TEXT=56;
37-
reg [4:0] active; // within the page
38-
reg [9:0] file_total; // max 1023 files
39-
reg [9:0] file_start = 1; // file number is 1-based
37+
reg [4:0] active; // within the page
38+
reg [11:0] file_total; // max 4095 files
39+
reg [11:0] file_start = 1; // file number is 1-based
4040
wire [4:0] total = file_total < file_start ? 0 : // number of files in this page
4141
file_total >= file_start + 19 ? 20 : file_total - file_start + 1;
4242
reg [4:0] cursor_now; // current cursor under refresh
@@ -72,10 +72,10 @@ reg sd_loading;
7272
reg sd_op = 0;
7373
wire sd_done;
7474
reg sd_restart = 0;
75-
reg [9:0] sd_file;
75+
reg [11:0] sd_file;
7676
wire [7:0] sd_list_name[0:51];
7777
wire [7:0] sd_list_namelen;
78-
wire [9:0] sd_list_file;
78+
wire [11:0] sd_list_file;
7979
wire sd_list_en;
8080

8181
// whether current sd_outbyte is valid NES data
@@ -135,7 +135,7 @@ always @(posedge clk) begin
135135
// fill in actual pixels, one pixel per clock cycle
136136
// so one file name takes 30*64=1920 cycles
137137
overlay <= 1;
138-
if (fn + file_start == sd_list_file[7:0] /* && ch < sd_list_namelen*/) begin
138+
if (fn + file_start == sd_list_file) begin
139139
if (FONT[sd_list_name[ch]][ny[2:0]][nx[2:0]])
140140
color <= COLOR_TEXT; // yellow
141141
else
@@ -225,11 +225,12 @@ end
225225

226226
always @* begin
227227
case (debug_reg)
228-
8'h1: debug_out = file_total;
229-
8'h2: debug_out = file_start;
230-
8'h3: debug_out = active;
231-
8'h4: debug_out = total;
232-
8'h5: debug_out = state;
228+
8'h1: debug_out = file_total[7:0];
229+
8'h2: debug_out = file_total[11:8];
230+
8'h3: debug_out = file_start;
231+
8'h4: debug_out = active;
232+
8'h5: debug_out = total;
233+
8'h6: debug_out = state;
233234
default: debug_out = 0;
234235
endcase
235236
end

0 commit comments

Comments
 (0)