Bastion Raid: isometric scrolling shooter, graphics scroll and border
Ports 35h-37h scroll the graphics layer (wrapping at 320 x 240); bit 1 of 36h hides a border (4 columns, 2 rows) where a program draws the strip coming into view unseen. The video loads its own column/row counters from the scroll registers each line and frame. CLS resets both. Testbench checks scroll, wrap and border. games/raid: an original Zaxxon-style game in C - fly over a fortress that scrolls diagonally, climb over low walls and through doorways in tall ones, shoot turrets, fuel tanks, radar and fighters, destroy the reactor. The world is drawn pixel by pixel from a formula, two columns and a row a frame (about 40% of the Z-80). test-raid.py flies the level with an autopilot and checks the frame budget; tools/boardemu.py is now shared by both games' tests. send-hex.py sets the date before saving. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
743071cff3
commit
62d0883a7f
19 files changed
+1807
-163
No files matched your search
@@ -326,6 +326,9 @@ module basys3_terminal #(
|
||||
wire [16:0] gfx_addr;
|
||||
wire [3:0] gfx_pix;
|
||||
wire sp_go, sp_buf, sp_on, pix_frame;
|
||||
wire [8:0] scroll_x;
|
||||
wire [7:0] scroll_y;
|
||||
wire g_border;
|
||||
wire [7:0] sp_line;
|
||||
wire [8:0] sp_x;
|
||||
wire [3:0] sp_pix;
|
||||
@@ -343,6 +346,7 @@ module basys3_terminal #(
|
||||
.tx_req(ztx_req), .tx_data(ztx_data), .tx_ack(ztx_ack),
|
||||
.seg_val(z80_seg), .halted(), .brk_key(brk_s[2] ^ brk_s[1]),
|
||||
.vclk(pix_clk), .gfx_vaddr(gfx_addr), .gfx_vpix(gfx_pix),
|
||||
.scroll_x(scroll_x), .scroll_y(scroll_y), .g_border(g_border),
|
||||
.sp_go(sp_go), .sp_line(sp_line), .sp_buf(sp_buf), .sp_x(sp_x), .sp_on(sp_on),
|
||||
.sp_pix(sp_pix), .sp_ftick(pix_frame), .keys(keys_down),
|
||||
.fl_cs_n(QspiCSn), .fl_sck(fl_sck), .fl_mosi(QspiDB[0]), .fl_miso(QspiDB[1])
|
||||
@@ -460,6 +464,7 @@ module basys3_terminal #(
|
||||
.cur_row(cur_row), .cur_col(cur_col), .cur_vis(cur_vis),
|
||||
.stop(stop), .sbot(sbot), .sm_on(sm_on), .sm_dir(sm_dir), .sm_off(sm_off),
|
||||
.ram_addr(v_addr), .ram_data(v_data), .gfx_addr(gfx_addr), .gfx_pix(alt_scr ? 4'd0 : gfx_pix),
|
||||
.scroll_x(scroll_x), .scroll_y(scroll_y), .g_border(g_border),
|
||||
.sp_go(sp_go), .sp_line(sp_line), .sp_buf(sp_buf), .sp_x(sp_x), .sp_on(sp_on),
|
||||
.sp_pix(alt_scr ? 4'd0 : sp_pix),
|
||||
.red(vgaRed), .green(vgaGreen), .blue(vgaBlue), .hsync(Hsync), .vsync(Vsync),
|
||||
|
||||
+32
-7
@@ -8,7 +8,10 @@
|
||||
// Hardware sprites (sprites.v) sit between the graphics and the text.
|
||||
// A 320x240 graphics layer (each pixel 4x4, the top 960 lines, so 80-column
|
||||
// text row r still starts at graphics line 8(r-1)) shows through wherever the
|
||||
// text is background; colour 0 is transparent.
|
||||
// text is background; colour 0 is transparent. It scrolls: the picture starts
|
||||
// at (scroll_x, scroll_y) of the buffer and wraps round at 320 and 240. With
|
||||
// g_border the graphics are hidden in a border (4 columns each side, 2 rows
|
||||
// top and bottom), where a scrolling program can draw what comes next unseen.
|
||||
// One pixel per clock, pipelined:
|
||||
// clock 0 position -> row, column, glyph line (registered)
|
||||
// clock 1 character RAM and graphics reads
|
||||
@@ -32,6 +35,9 @@ module text_display #(
|
||||
input [17:0] ram_data, // {blink, underline, bg, fg, code}
|
||||
output [16:0] gfx_addr, // graphics pixel, read a clock later
|
||||
input [3:0] gfx_pix,
|
||||
input [8:0] scroll_x, // graphics pixel shown at the top left
|
||||
input [7:0] scroll_y,
|
||||
input g_border, // hide 4 graphics columns each side, 2 rows top and bottom
|
||||
// sprites: the line to prepare next, and the pixel on screen
|
||||
output reg sp_go,
|
||||
output reg [7:0] sp_line,
|
||||
@@ -72,6 +78,22 @@ module text_display #(
|
||||
h <= h + 1'b1;
|
||||
end
|
||||
|
||||
// graphics pixel for this h, v with the scroll added: counters set from
|
||||
// the scroll registers at the end of each line and each frame
|
||||
reg [8:0] g_col = 9'd0;
|
||||
reg [7:0] g_row = 8'd0;
|
||||
reg [1:0] g_sub = 2'd0;
|
||||
always @(posedge clk)
|
||||
if (h == H_TOTAL - 1) begin
|
||||
g_col <= scroll_x;
|
||||
g_sub <= 2'd0;
|
||||
if (v == V_TOTAL - 1) g_row <= scroll_y;
|
||||
else if (v[1:0] == 2'd3) g_row <= g_row == 8'd239 ? 8'd0 : g_row + 1'b1;
|
||||
end else begin
|
||||
g_sub <= g_sub + 1'b1;
|
||||
if (g_sub == 2'd3) g_col <= g_col >= 9'd319 ? 9'd0 : g_col + 1'b1;
|
||||
end
|
||||
|
||||
// ---- clock 0: where this pixel is in the text, in font units
|
||||
// yl counts font lines (a 16-line font: 32 pixels a row in 80 columns)
|
||||
wire [9:0] yl = wide ? v[9:0] : {1'b0, v[9:1]};
|
||||
@@ -88,7 +110,9 @@ module text_display #(
|
||||
reg [7:0] a_col;
|
||||
reg [3:0] a_line;
|
||||
reg [2:0] a_bit;
|
||||
reg a_blank, a_text, a_vis, a_cur, a_hs, a_vs, a_gon;
|
||||
reg a_blank, a_text, a_vis, a_cur, a_hs, a_vs, a_gon, a_ghide;
|
||||
wire [8:0] gcol_s = h[10:2]; // graphics pixel on the screen, unscrolled
|
||||
wire [7:0] grow_s = v[9:2];
|
||||
reg [16:0] a_gfx;
|
||||
reg [8:0] a_spx;
|
||||
reg a_spbuf;
|
||||
@@ -104,7 +128,8 @@ module text_display #(
|
||||
a_hs <= h >= H_VIS + H_FP && h < H_VIS + H_FP + H_SYNC; // positive sync
|
||||
a_vs <= v >= V_VIS + V_FP && v < V_VIS + V_FP + V_SYNC;
|
||||
a_gon <= v < 960;
|
||||
a_gfx <= {v[9:2], 8'd0} + {2'd0, v[9:2], 6'd0} + {8'd0, h[10:2]};
|
||||
a_ghide <= g_border && (gcol_s < 9'd4 || gcol_s >= 9'd316 || grow_s < 8'd2 || grow_s >= 8'd238);
|
||||
a_gfx <= {1'b0, g_row, 8'd0} + {3'd0, g_row, 6'd0} + {8'd0, g_col};
|
||||
a_spx <= h[10:2];
|
||||
a_spbuf <= v[2];
|
||||
end
|
||||
@@ -117,10 +142,10 @@ module text_display #(
|
||||
assign sp_on = a_gon;
|
||||
reg [3:0] b_line;
|
||||
reg [2:0] b_bit;
|
||||
reg b_blank, b_text, b_vis, b_cur, b_hs, b_vs, b_gon;
|
||||
reg b_blank, b_text, b_vis, b_cur, b_hs, b_vs, b_gon, b_ghide;
|
||||
always @(posedge clk)
|
||||
{b_line, b_bit, b_blank, b_text, b_vis, b_cur, b_hs, b_vs, b_gon} <=
|
||||
{a_line, a_bit, a_blank, a_text, a_vis, a_cur, a_hs, a_vs, a_gon};
|
||||
{b_line, b_bit, b_blank, b_text, b_vis, b_cur, b_hs, b_vs, b_gon, b_ghide} <=
|
||||
{a_line, a_bit, a_blank, a_text, a_vis, a_cur, a_hs, a_vs, a_gon, a_ghide};
|
||||
|
||||
// ---- clock 2: font ROM
|
||||
reg [7:0] font [0:4095];
|
||||
@@ -133,7 +158,7 @@ module text_display #(
|
||||
always @(posedge clk) begin
|
||||
glyph <= font[{ram_data[7:0], b_line}];
|
||||
c_cell <= ram_data;
|
||||
c_gfx <= b_gon ? gfx_pix : 4'd0;
|
||||
c_gfx <= b_gon && !b_ghide ? gfx_pix : 4'd0;
|
||||
c_spr <= sp_pix;
|
||||
{c_line, c_bit, c_blank, c_text, c_vis, c_cur, c_hs, c_vs} <=
|
||||
{b_line, b_bit, b_blank, b_text, b_vis, b_cur, b_hs, b_vs};
|
||||
|
||||
+17
-2
@@ -12,7 +12,12 @@
|
||||
// 30 out graphics X bits 7:0 31 out X bit 8 32 out Y
|
||||
// 33 out plot colour at (X,Y), then X+1 in colour at (X,Y)
|
||||
// 34 out fill the whole graphics screen in bit 0 = fill busy
|
||||
// (also turns the sprites off unless bit 7 is set)
|
||||
// (also turns the sprites off and the scroll back to 0, unless
|
||||
// bit 7 is set)
|
||||
// 35 out scroll: buffer X shown at the left, bits 7:0
|
||||
// 36 out bit 0 = scroll X bit 8; bit 1 = hide the graphics in a border (4
|
||||
// columns each side, 2 rows top and bottom) to draw in unseen
|
||||
// 37 out scroll: buffer Y shown at the top (0-239)
|
||||
// 40 SPI flash control, 41 SPI flash data (see flash_spi.v)
|
||||
// 60 out bit 0 = monitor bank in; bit 1 (with bit 0 = 0) = stop again after
|
||||
// one instruction of the program
|
||||
@@ -63,6 +68,9 @@ module z80_system #(
|
||||
input vclk,
|
||||
input [16:0] gfx_vaddr,
|
||||
output reg [3:0] gfx_vpix,
|
||||
output reg [8:0] scroll_x,
|
||||
output reg [7:0] scroll_y,
|
||||
output reg g_border,
|
||||
// sprites, on the video clock (see sprites.v)
|
||||
input sp_go,
|
||||
input [7:0] sp_line,
|
||||
@@ -147,13 +155,20 @@ module z80_system #(
|
||||
if (rst) begin
|
||||
fill_busy <= 1'b0;
|
||||
gx <= 9'd0; gy <= 8'd0;
|
||||
scroll_x <= 9'd0; scroll_y <= 8'd0; g_border <= 1'b0;
|
||||
end else begin
|
||||
if (io_wr) case (io_addr[7:0])
|
||||
8'h30: gx[7:0] <= io_wd;
|
||||
8'h31: gx[8] <= io_wd[0];
|
||||
8'h32: gy <= io_wd;
|
||||
8'h33: gx <= gx + 1'b1;
|
||||
8'h34: begin fill_busy <= 1'b1; fill_a <= 17'd0; fill_c <= io_wd[3:0]; end
|
||||
8'h34: begin
|
||||
fill_busy <= 1'b1; fill_a <= 17'd0; fill_c <= io_wd[3:0];
|
||||
if (!io_wd[7]) begin scroll_x <= 9'd0; scroll_y <= 8'd0; g_border <= 1'b0; end
|
||||
end
|
||||
8'h35: scroll_x[7:0] <= io_wd;
|
||||
8'h36: begin scroll_x[8] <= io_wd[0]; g_border <= io_wd[1]; end
|
||||
8'h37: scroll_y <= io_wd >= 8'd240 ? io_wd - 8'd240 : io_wd;
|
||||
default: ;
|
||||
endcase
|
||||
if (fill_busy) begin
|
||||
|
||||
Reference in new issue
Block a user