Flash file system for BASIC, with bitstream write protection
BASIC gets SAVE, LOAD, RUN "NAME", DIR and DEL, storing program listings in the configuration flash from 240000h (448 x 4 KB blocks, 64 files, 32 KB each). The directory is kept in two alternating blocks with a sequence number and checksum, new data is written before the directory switches to it, and every page is verified after programming. rtl/flash_spi.v drives the flash through STARTUPE2 on ports 40h/41h. It only passes read, status, WREN/WRDI, RDID, page program and 4 KB erase, and abandons any program or erase below 240000h before the address reaches the chip. Tested on the board: an erase at 0 and a write at 200000h were refused and left the flash unchanged. With SW14 up, the Z-80's output is also copied to the PC's serial port, and tools/get-bas.py uses that to LIST a program into a file or run commands and print the replies. Also fixes port 10h returning the previous millisecond latch (the first read after reset was undefined). Simulation adds a model flash and a save/load/run/protection test. Manual and README updated. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
dc7c7c22c5
commit
29a15bf7c7
15 files changed
+6907
-6056
No files matched your search
+43
-4
@@ -13,7 +13,8 @@
|
||||
// SW7 Enter sends CR LF instead of CR
|
||||
// SW8 smooth scrolling (also turned on by ESC [ ? 4 h)
|
||||
// SW9 fast smooth scrolling
|
||||
// SW14 in Z-80 mode, bytes from the PC's UART also go to the Z-80 (paste programs)
|
||||
// SW14 in Z-80 mode, link the PC's UART too: bytes from the PC also go to the
|
||||
// Z-80, and the Z-80's output is copied to the PC
|
||||
// SW15 Z-80 mode
|
||||
// BTNC reset BTNU clear screen BTND reset the Z-80 only
|
||||
// LED7:0 last byte received LED11:8 VT220 LEDs L4..L1 (DECLL)
|
||||
@@ -49,7 +50,9 @@ module basys3_terminal #(
|
||||
input RsRx,
|
||||
output RsTx,
|
||||
input PS2Clk,
|
||||
input PS2Data
|
||||
input PS2Data,
|
||||
output QspiCSn,
|
||||
inout [3:0] QspiDB
|
||||
);
|
||||
localparam [7:0] XON = 8'h11, XOFF = 8'h13;
|
||||
|
||||
@@ -156,6 +159,19 @@ module basys3_terminal #(
|
||||
.rd(zin_rd), .dout(zin), .empty(zin_empty), .full(zin_full), .count(zin_count)
|
||||
);
|
||||
|
||||
// Z-80 output copied to the PC when linked
|
||||
wire [7:0] mq;
|
||||
wire mq_empty;
|
||||
wire [10:0] mq_count;
|
||||
reg mq_rd;
|
||||
wire z80_out; // a Z-80 byte is going to the screen
|
||||
wire [7:0] z80_out_byte;
|
||||
|
||||
fifo #(.W(8), .A(10)) mirror_fifo (
|
||||
.clk(clk), .rst(rst), .din(z80_out_byte), .wr(z80_out && z80_link),
|
||||
.rd(mq_rd), .dout(mq), .empty(mq_empty), .full(), .count(mq_count)
|
||||
);
|
||||
|
||||
wire [10:0] tq_count;
|
||||
wire [10:0] flow_count = z80_mode ? zin_count : tq_count;
|
||||
reg xoff_sent;
|
||||
@@ -164,6 +180,7 @@ module basys3_terminal #(
|
||||
tx_start <= 1'b0;
|
||||
kq_rd <= 1'b0;
|
||||
rq_rd <= 1'b0;
|
||||
mq_rd <= 1'b0;
|
||||
if (rst) begin
|
||||
from_resp <= 1'b0;
|
||||
flow_pend <= 1'b0;
|
||||
@@ -191,6 +208,10 @@ module basys3_terminal #(
|
||||
tx_start <= 1'b1;
|
||||
kq_rd <= !from_resp;
|
||||
rq_rd <= from_resp;
|
||||
end else if (z80_mode && !mq_empty && !mq_rd) begin
|
||||
tx_byte <= mq;
|
||||
tx_start <= 1'b1;
|
||||
mq_rd <= 1'b1;
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -268,6 +289,7 @@ module basys3_terminal #(
|
||||
always @(posedge clk) ztx_req_s <= {ztx_req_s[0], ztx_req};
|
||||
|
||||
wire [15:0] z80_seg;
|
||||
wire fl_sck;
|
||||
wire [16:0] gfx_addr;
|
||||
wire [3:0] gfx_pix;
|
||||
|
||||
@@ -276,9 +298,22 @@ module basys3_terminal #(
|
||||
.rx_req(zrx_req), .rx_data(zrx_data), .rx_ack(zrx_ack),
|
||||
.tx_req(ztx_req), .tx_data(ztx_data), .tx_ack(ztx_ack),
|
||||
.seg_val(z80_seg), .halted(),
|
||||
.vclk(clk), .gfx_vaddr(gfx_addr), .gfx_vpix(gfx_pix)
|
||||
.vclk(clk), .gfx_vaddr(gfx_addr), .gfx_vpix(gfx_pix),
|
||||
.fl_cs_n(QspiCSn), .fl_sck(fl_sck), .fl_mosi(QspiDB[0]), .fl_miso(QspiDB[1])
|
||||
);
|
||||
|
||||
// The flash clock is the configuration clock pin, reached through STARTUPE2.
|
||||
// DQ2/DQ3 (write protect, hold) stay high.
|
||||
assign QspiDB[1] = 1'bz;
|
||||
assign QspiDB[3:2] = 2'b11;
|
||||
`ifndef SIMULATION
|
||||
STARTUPE2 #(.PROG_USR("FALSE"), .SIM_CCLK_FREQ(0.0)) startup (
|
||||
.CFGCLK(), .CFGMCLK(), .EOS(), .PREQ(),
|
||||
.CLK(1'b0), .GSR(1'b0), .GTS(1'b0), .KEYCLEARB(1'b1), .PACK(1'b0),
|
||||
.USRCCLKO(fl_sck), .USRCCLKTS(1'b0), .USRDONEO(1'b1), .USRDONETS(1'b1)
|
||||
);
|
||||
`endif
|
||||
|
||||
// terminal input: Z-80 output or received bytes, local echo, banner
|
||||
reg echo_pend;
|
||||
reg [7:0] echo_byte;
|
||||
@@ -286,6 +321,10 @@ module basys3_terminal #(
|
||||
reg tin_wr;
|
||||
wire tin_full;
|
||||
|
||||
assign z80_out = z80_mode && ztx_req_s[1] != ztx_ack && !tin_wr && tq_count < 1000 &&
|
||||
(!z80_link || mq_count < 1000);
|
||||
assign z80_out_byte = ztx_data;
|
||||
|
||||
always @(posedge clk) begin
|
||||
tin_wr <= 1'b0;
|
||||
if (kq_rd && sw_r[2] && !z80_mode) begin
|
||||
@@ -296,7 +335,7 @@ module basys3_terminal #(
|
||||
echo_pend <= 1'b0;
|
||||
ban_i <= z80_mode ? 8'hFF : 8'd199;
|
||||
end else if (z80_mode) begin
|
||||
if (ztx_req_s[1] != ztx_ack && !tin_wr && tq_count < 1000) begin
|
||||
if (z80_out) begin
|
||||
tin <= ztx_data;
|
||||
tin_wr <= 1'b1;
|
||||
ztx_ack <= ~ztx_ack;
|
||||
|
||||
Reference in new issue
Block a user