A level does not need to be on screen for the game to ask what is there. Give it a byte per cell, keep those bytes in row order, and the same map can answer questions about walls, hazards, goals or scenery that has changed.
This implementation supplies four routines: checked get, checked set, property lookup and conversion from unsigned world positions to eight-unit cells. It does not draw or wait for a frame. The shared entry explains the arrangement and links the implementations across all 30 machines.
Include and initialise
Include the 68000 routine and point A0 at an even-aligned 24-byte context. The map contains W×H consecutive bytes, with width and height each from 1 to 255. Its property table contains one byte per possible ID, through the configured highest ID. Both ranges must remain addressable without crossing an address-space end, bank window or unmapped boundary. Use writable RAM for tile_set; a ROM map needs another way to record changes.
Pointers are 32-bit and coordinate words are 16-bit, in native big-endian order.
Context offsets: 0–3 map pointer; 4/5 width/height; 6/7 column/row; 8 tile; 9 valid; 10 property; 11 highest tile ID; 12–15 property pointer; 16–19 scratch; 20–21 X; 22–23 Y. Initialise the pointers, dimensions and highest ID before a call. Scratch bytes belong to the routine.
Initialise the diagnostic map and make its first checked query
start:
move.w #$2700,sr
move.b #3,$bfe201
move.b #2,$bfe001 ; remove reset ROM overlay before using RAM/stack
lea $7f000,sp
lea TM,a0
moveq #0,d0
moveq #23,d1
clear_context:
move.b d0,(a0)+
dbra d1,clear_context
lea TM,a0
lea initial_map(pc),a1
lea MAP,a2
moveq #34,d0
copy_map:
move.b (a1)+,(a2)+
dbra d0,copy_map
move.b #$a5,MAP+35
move.l #MAP,(a0)
move.b #7,4(a0)
move.b #5,5(a0)
move.b #3,11(a0)
move.l #(properties+$f80008),12(a0)
move.b #0,6(a0)
move.b #0,7(a0)
bsr tile_get
cmp.b #1,9(a0)
beq valid_0
move.b #255,8(a0)The complete diagnostic uses a 7×5 map. Its context starts at $2000, results at $2040 and writable map at $20F0. These locations belong to a caller taking over the machine; choose and reserve suitable memory in your own project, accounting for firmware, display, banking and interrupts.
Call the routine
Set column and row, call tile_get, then check the valid byte. A successful call returns the tile ID. Failure returns valid=0 and tile=0, so tile zero alone does not mean success. This compact variant uses unsigned byte coordinates; wider maps can use a wider-coordinate variant rather than treating this as a machine limit. Translate a signed or wider world into this representation explicitly.
For a write, set column/row/tile and call tile_set. Invalid coordinates or an ID above the configured maximum leave the map unchanged. To classify a tile, call tile_property; it returns the table byte and a separate valid flag. Your game decides whether those property bits mean blocking, damage, a goal or something else.
Reusable 68000 map/query implementation
; A0 points at 24-byte context. D0-D2/A1/CCR clobbered; A0 preserved.
tile_locate:
clr.b 9(a0)
moveq #0,d0
move.b 6(a0),d0
cmp.b 4(a0),d0
bcc tile_locate_done
moveq #0,d1
move.b 7(a0),d1
cmp.b 5(a0),d1
bcc tile_locate_done
moveq #0,d2
move.b 4(a0),d2
mulu.w d2,d1
add.l d0,d1
add.l (a0),d1
movea.l d1,a1
move.l a1,16(a0)
move.b #1,9(a0)
tile_locate_done:
rts
tile_get:
bsr tile_locate
tst.b 9(a0)
beq tile_get_invalid
move.b (a1),8(a0)
rts
tile_get_invalid:
clr.b 8(a0)
rts
tile_set:
clr.b 9(a0)
move.b 8(a0),d0
cmp.b 11(a0),d0
bhi tile_set_done
bsr tile_locate
tst.b 9(a0)
beq tile_set_done
move.b 8(a0),(a1)
tile_set_done:
rts
tile_property:
clr.b 9(a0)
clr.b 10(a0)
moveq #0,d0
move.b 8(a0),d0
cmp.b 11(a0),d0
bhi tile_property_done
movea.l 12(a0),a1
move.b (a1,d0.w),10(a0)
move.b #1,9(a0)
tile_property_done:
rts
tile_pixel8:
clr.b 9(a0)
clr.b 8(a0)
move.w 20(a0),d0
lsr.w #3,d0
cmp.w #255,d0
bhi tile_pixel_done
move.b d0,6(a0)
move.w 22(a0),d0
lsr.w #3,d0
cmp.w #255,d0
bhi tile_pixel_done
move.b d0,7(a0)
bsr tile_get
tile_pixel_done:
rtsFor tile_pixel8, set unsigned 16-bit X and Y in world coordinates. It divides by eight, rejects a cell coordinate too large for a byte, then performs the checked lookup. Read cell/tile outputs only after checking valid. X/Y inputs remain unchanged. Eight-unit square cells are this routine’s deliberate fast conversion; other sizes, wrapping or a signed origin need a corresponding variant.
State, stack and cost
A0 is preserved. D0–D2, A1 and CCR are clobbered. The routines use the current stack and the supplied context. They do not mask or install interrupts. An interrupt caller needs its own context and must preserve the state that the interrupted code needs.
Get/set use 8 bytes of return addresses at their deepest point, including the direct caller’s call into the library. Pixel conversion uses 12; property lookup uses 4. Add the surrounding caller stack and any interrupt frames.
Map storage is W×H bytes, plus highest-ID+1 property bytes, context, code and stack. The 68000 uses a multiply for row addressing. There is no whole-game frame-rate claim.
Run and adapt it
make ASM198X=/path/to/asm198x builds the complete original diagnostic. It uses a synthetic reset ROM/cartridge to execute the routines and observe their RAM results. This establishes the query code and its declared memory on this machine; it does not establish a stock BASIC/FORTH loader, video output, IRQ coexistence or a frame deadline.
The caller checks every cell of a non-square map, rejected reads/writes, a map-end guard, a valid change, properties and coordinate conversion. The same observer rejects completed wrong-stride and write-without-valid versions. The map crosses a 256-byte boundary so row/column address carries are exercised. Use the reusable include in your own program; the unrolled diagnostic queries make observations explicit and are not a proposed game loop.
- Complete caller and machine reservation
- Full CPU calling contract
- Execution records and all-system coverage
For the picture itself, use native region drawing. Keep the map/query contract separate from video access and cell dimensions.