Hardware sprites: 32 x 16x16 from 64 shapes, collisions, frame counter
rtl/sprites.v draws sprites between the graphics and the text from a pair of line buffers filled one graphics line ahead. Ports 70h-77h set position, shape, flip and on/off and load shapes; 78h is a frame counter; 80h-87h report sprite-sprite and sprite-graphics collisions per frame. The graphics fill (CLS) turns sprites off unless bit 7 is set. Testbench checks pixels, priority, flip, edge clipping, collisions and CLS. Manual, README and basic/examples/sprites.bas demo. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
c78073320b
commit
13373244e8
9 files changed
+480
-7
No files matched your search
@@ -223,9 +223,15 @@ edit the line being typed.
|
||||
About 20.5 KB of program space is free; F000h-F3F7h is kept free for machine code.
|
||||
|
||||
**Graphics:** the layer is 320×240 pixels in the 16 terminal colours, each
|
||||
pixel a 2×2 block, with (0,0) at the top left. Colour 0 is transparent. Text is
|
||||
pixel a 4×4 block, with (0,0) at the top left. Colour 0 is transparent. Text is
|
||||
drawn on top, and the graphics show through blank text.
|
||||
|
||||
**Sprites:** 32 hardware sprites of 16×16 graphics pixels, from 64 shapes, in
|
||||
front of the graphics and behind the text, with flipping and sprite-sprite and
|
||||
sprite-graphics collision flags. BASIC moves them with `OUT` (ports 112–119)
|
||||
and reads the frame counter and collisions with `INP` (120, 128–135); see the
|
||||
manual. `basic/examples/sprites.bas` is a small example.
|
||||
|
||||
**Manual:** [docs/basic-manual.md](docs/basic-manual.md) describes every
|
||||
statement and function, with examples, error messages and limits.
|
||||
`docs/build-manual.sh` rebuilds the PDF from it.
|
||||
@@ -358,10 +364,20 @@ tools/gen-asmtab.py # regenerate monitor/asmtab.h after changing the d
|
||||
and jumps to 0066h. It also wakes the CPU from HALT.
|
||||
|
||||
The 320×240×4-bit graphics layer is a separate dual-clock block RAM: the Z-80
|
||||
writes it on its own clock, and the video reads it on the 100 MHz clock.
|
||||
writes it on its own clock, and the video reads it on the 108 MHz pixel clock.
|
||||
`rtl/text_display.v` overlays it on the text. A hardware fill clears it in
|
||||
76,800 clocks.
|
||||
|
||||
`rtl/sprites.v` draws the sprites. The video asks for each graphics line one
|
||||
line ahead; the engine clears a 320-pixel line buffer, then walks the sprites
|
||||
from 31 down to 0 writing their visible pixels (about 900 clocks of the 6,752
|
||||
a graphics line lasts), while the video reads the other buffer. A pixel
|
||||
written over another sprite's flags both; a sprite pixel shown over a graphics
|
||||
pixel flags that sprite. The flags are collected per frame and handed to the
|
||||
Z-80 at the start of vertical blank, along with a frame counter. Shapes are a
|
||||
dual-clock block RAM (64 × 16 × 16 × 4 bits); positions and shapes are in
|
||||
distributed RAM.
|
||||
|
||||
Memory is 64 KB of block RAM loaded with BASIC at configuration. Writes below
|
||||
8000h are ignored, so the interpreter can't be damaged. BASIC's data and the
|
||||
stack fill the top half.
|
||||
@@ -374,13 +390,20 @@ stack fill the top half.
|
||||
| 20h / 21h | | 7-segment display, right / left byte |
|
||||
| 30h, 31h, 32h | | graphics X low byte, X bit 8, Y |
|
||||
| 33h | colour at X,Y | plot at X,Y, then X+1 |
|
||||
| 34h | bit 0: fill busy | fill the whole graphics layer with a colour |
|
||||
| 34h | bit 0: fill busy | fill the whole graphics layer with a colour; also turns the sprites off unless bit 7 is set |
|
||||
| 40h | bit 0: SPI byte busy, bit 1: command refused | 1 starts a flash command (chip select low), 0 ends it |
|
||||
| 41h | byte received during the last transfer | send a byte to the flash |
|
||||
| 60h | why the monitor was entered (1 Pause, 2 port 61h, 3 step, 4/5 breakpoint) | bit 0: monitor bank in; bit 1: stop after one instruction |
|
||||
| 61h | | enter the monitor (NMI) |
|
||||
| 62h, 63h, 64h | 64h: byte of main memory at the debug address, then address+1 | 62h/63h: debug address |
|
||||
| 65h/66h, 68h/69h, 67h | | breakpoint 0 and 1 addresses; 67h bits 1:0 turn them on |
|
||||
| 70h | | select sprite 0–31 |
|
||||
| 71h, 72h, 73h | | sprite X low byte, X bit 8, Y (writing Y moves it) |
|
||||
| 74h, 75h | | sprite shape 0–63; bit 0 on, bit 1 flip X, bit 2 flip Y |
|
||||
| 76h, 77h | | start loading shape n; two pixels (left in bits 7:4), then next |
|
||||
| 78h | frame counter (+1 each vertical blank) | |
|
||||
| 80h–83h | sprites that touched another sprite last frame (bit per sprite) | |
|
||||
| 84h–87h | sprites that touched a graphics pixel last frame | |
|
||||
|
||||
BASIC is C (`basic/basic.c`) compiled with SDCC (`sudo apt install sdcc`):
|
||||
|
||||
@@ -455,6 +478,9 @@ older boards, Macronix `mx25l3273f` on newer ones).
|
||||
`JP` onto its target and sets a breakpoint that BASIC then hits. It also
|
||||
enters through the Pause key and checks BASIC's screen comes back.
|
||||
- It draws graphics from BASIC and checks the pixels.
|
||||
- It defines sprite shapes and places overlapping, flipped and edge-clipped
|
||||
sprites from BASIC, then checks the pixels on screen, the collision ports and
|
||||
that `CLS` turns the sprites off.
|
||||
- Against a model flash (`sim/spiflash_model.v`) it sets the date, saves,
|
||||
loads, runs and lists a program (checking the date in `DIR`), tries to erase
|
||||
address 0 and checks the model saw no write below 240000h, then writes a data
|
||||
@@ -474,6 +500,7 @@ which Vivado needs on newer distros.
|
||||
| `rtl/basys3_terminal.v` | Top level: reset, switches, FIFOs, flow control, banner, LEDs, Z-80 clock |
|
||||
| `rtl/z80_cpu.v` | Z-80 CPU |
|
||||
| `rtl/z80_system.v` | Z-80 RAM, console, timer, graphics and flash ports, monitor bank, step and breakpoints |
|
||||
| `rtl/sprites.v` | Hardware sprites: shapes, line buffers, collisions |
|
||||
| `rtl/flash_spi.v` | SPI port to the configuration flash, with bitstream write protection |
|
||||
| `monitor/` | Machine-code monitor (C and start-up code), its build script and disassembler test |
|
||||
| `basic/tramp.s` | The NMI entry and exit bytes shared by BASIC and the monitor |
|
||||
|
||||
Reference in new issue
Block a user