Kaynağa Gözat

M1.3: display generated terrain and regenerate on SPACE

main
Daniel Covington 2 gün önce
ebeveyn
işleme
00a5a7dd36
6 değiştirilmiş dosya ile 119 ekleme ve 102 silme
  1. +7
    -4
      docs/manual-tests.md
  2. +1
    -1
      docs/verification-status.md
  3. +2
    -2
      project.json
  4. +90
    -64
      src/main.s
  5. +0
    -30
      src/tiles.inc
  6. +19
    -1
      src/world.inc

+ 7
- 4
docs/manual-tests.md Dosyayı Görüntüle

@@ -61,13 +61,16 @@ Setup: VICE x64sc, NTSC (-ntsc), warp off.
Start: `pwsh -File tools/run.ps1 -Target c64`

Steps:
1. Note the map.
2. Press SPACE and wait.
1. Watch for the generating message, then note the map shown within 15 seconds.
2. Tap SPACE, wait for the new map, then tap SPACE again.
3. Hold SPACE for about two seconds and release it.

Expected:
- A visibly different map appears
- Look for brown land, green grass and trees, grey stone, blue water, and black roads with no gaps at crossings or stray colours.
- A visibly different map appears after each tap.
- Holding SPACE generates one new map. The map stays steady until the next press.

Verifies: R4
Verifies: the M1 portions of R1 and R4.

## M2 - People and double-buffered partial redraw



+ 1
- 1
docs/verification-status.md Dosyayı Görüntüle

@@ -11,7 +11,7 @@ manual = `pending`, `confirmed by user (<date>)`, `problem reported (<date>): <n
| M0.1 Run tools/check-prereqs.ps1, then tools/smoke.ps1 for every target. | passed (2026-12-03, `pwsh -File tools/check-prereqs.ps1`; `pwsh -File tools/build.ps1`; `pwsh -File tools/smoke.ps1`) | confirmed by user (2026-12-03) |
| M1.1 Tile set: 8-byte multicolour patterns for land, grass, trees, stone, water and roads, including edge and corner patterns, with per-tile screen-RAM colour pairs. | passed (2026-12-03, `pwsh -File tools/build.ps1`; `pwsh -File tools/smoke.ps1`) | confirmed by user (2026-12-03) |
| M1.2 Seeded generator: 80x50 tile world with water, stone, grass with trees, and connected roads; enforce the at-most-two-colours-per-cell rule. | passed (2026-12-03, `pwsh -File tools/build.ps1`; `pwsh -File tools/smoke.ps1`; `pwsh -File tools/check-world.ps1`) | confirmed by user (2026-12-03) |
| M1.3 Render the top-left screen of the world into the visible buffer; SPACE regenerates. | not run | pending |
| M1.3 Render the top-left screen of the world into the visible buffer; SPACE regenerates. | passed (2026-12-03, `pwsh -File tools/build.ps1`; `pwsh -File tools/smoke.ps1`; `pwsh -File tools/check-world.ps1`; VICE monitor buffered SPACE and compared all 1,000 visible cells before and after) | pending |
| M2.1 People table (world x, y, direction) and movement rules; water and stone block. | not run | pending |
| M2.2 Per-buffer saved-byte lists: restore the bytes under people from two frames ago, draw people in view, flip in vertical blank. | not run | pending |
| M3.1 Keyboard matrix reading for the cursor keys with SHIFT, held-key repeat. | not run | pending |


+ 2
- 2
project.json Dosyayı Görüntüle

@@ -268,7 +268,7 @@
},
"starter": {
"screenTitle": "LAND MAP 64",
"expectedScreen": "The seeded 80x50 tile world is in RAM. VICE displays the static terrain tile test view. The hidden text screen shows \"LAND MAP 64\" and \"MAP READY\".",
"expectedScreen": "After a short generating message, VICE shows the top-left view of the generated terrain in multicolour bitmap mode. SPACE generates a different map. The hidden text screen shows \"LAND MAP 64\" and \"MAP READY\".",
"smokeChecks": [
{
"row": 0,
@@ -656,7 +656,7 @@
"description": "C64 KERNAL reset vector at $FFFC (machine is in C64 mode)"
}
],
"expectedScreen": "The seeded 80x50 tile world is in RAM. VICE displays the static terrain tile test view. The hidden text screen shows \"LAND MAP 64\" and \"MAP READY\"."
"expectedScreen": "After a short generating message, VICE shows the top-left view of the generated terrain in multicolour bitmap mode. SPACE generates a different map. The hidden text screen shows \"LAND MAP 64\" and \"MAP READY\"."
},
"recipeStatus": "verified",
"validationPlan": []


+ 90
- 64
src/main.s Dosyayı Görüntüle

@@ -1,4 +1,4 @@
; Land Map 64 - terrain tile test view (ca65).
; Land Map 64 - generated terrain view (ca65).
; Built with: cl65 -t c64 -C c64-asm.cfg -u __EXEHDR__ (BASIC SYS line included).
;
; Multicolour bitmap palette and VIC bank layout:
@@ -7,18 +7,14 @@
; screen RAM high nibble terrain (pixel %01) grey, green, blue or black
; screen RAM low nibble terrain (pixel %10)
; colour RAM light red (pixel %11) people; constant, never flipped
; - two complete buffers in separate VIC banks, flipped through $DD00:
; - bitmap buffer layout in separate VIC banks, selected through $DD00:
; buffer A: VIC bank 1, screen RAM $4000, bitmap $6000
; buffer B: VIC bank 2, screen RAM $8000, bitmap $A000 (RAM under BASIC ROM)
; Both use $D018 = $08 (screen at bank+$0000, bitmap at bank+$2000), so a flip
; changes only the two bank bits in $DD00.
;
; The static test picture draws the terrain tile table into buffer A.
;
; The text screen at $0400 is not displayed in bitmap mode. The program writes a
; status mirror there for the smoke test (row 0 title, row 2 status).
; smoke_ready is the VICE tracepoint used by tools/smoke.ps1: keep it after the
; buffers are drawn and the display is switched on.
; During generation VIC bank 0 displays the message at $0400. In bitmap mode
; that text screen is hidden and holds the smoke test status mirror.

.export smoke_ready

@@ -32,12 +28,18 @@ VIC_BG0 = $D021
COLOR_RAM = $D800
CIA2_PRA = $DD00 ; bits 0-1: VIC bank, inverted (%10 = bank 1, %01 = bank 2)
CPU_PORT = $01
KEY_REPEAT = $028A ; bit 6 disables KERNAL key repeat
GETIN = $FFE4
PETSCII_SPACE = $20

TEXT_SCREEN = $0400

SCREEN_A = $4000
BITMAP_A = $6000
VIEW_WIDTH = 40
VIEW_HEIGHT = 25

BANK_TEXT_BITS = %00000011 ; VIC bank 0 ($0000-$3FFF)
BANK_A_BITS = %00000010 ; VIC bank 1 ($4000-$7FFF)

COL_BROWN = 9
@@ -61,31 +63,59 @@ start:
lda #$36 ; BASIC ROM out, KERNAL and I/O in: the CPU can
sta CPU_PORT ; read buffer B's bitmap at $A000 (needed from M2)

jsr generate_world_from_timer
jsr draw_tile_view

lda #$40
sta KEY_REPEAT
lda #0
sta last_seed_low
sta last_seed_high
jsr fill_color_ram
jsr rebuild_map
smoke_ready: ; first generated world is on screen
nop

main_loop:
jsr GETIN
cmp #PETSCII_SPACE
bne main_loop
jsr rebuild_map
space_ready: ; regenerated map is on screen
jmp main_loop

; ---------------------------------------------------------------- routines

rebuild_map:
jsr write_generating
lda #COL_BROWN
sta VIC_BORDER
sta VIC_BG0
lda #$08 ; screen at bank+$0000, bitmap at bank+$2000
jsr wait_frame
lda #BANK_TEXT_BITS
jsr set_bank
lda #$14 ; text screen at $0400, uppercase ROM font
sta VIC_MEMPTR
lda #$18 ; multicolour on, 40 columns, x-scroll 0
lda #$08 ; single colour, 40 columns
sta VIC_CTRL2
jsr wait_frame ; switch modes below the visible area
lda #$1B ; text mode, 25 rows, y-scroll 3
sta VIC_CTRL1

jsr generate_world_from_timer
jsr draw_world_view

jsr wait_frame ; switch banks and modes below the visible area
lda #BANK_A_BITS
jsr set_bank
lda #$08 ; screen at bank+$0000, bitmap at bank+$2000
sta VIC_MEMPTR
lda #$18 ; multicolour on, 40 columns, x-scroll 0
sta VIC_CTRL2
lda #$3B ; bitmap mode, display on, 25 rows, y-scroll 3
sta VIC_CTRL1
jsr write_status
smoke_ready: ; world generated, test view on screen
nop

main_loop:
jmp main_loop

; ---------------------------------------------------------------- routines
ldx #STATUS_LENGTH-1
@ready: lda ready_text,x
sta TEXT_SCREEN+80,x
dex
bpl @ready
rts

; Wait until the raster reaches FLIP_RASTER, then until it has left that line,
; so each call returns once per frame.
@@ -100,7 +130,7 @@ wait_frame:
beq @leave
rts

; A = bank bits for $DD00 (BANK_A_BITS or BANK_B_BITS). Keeps the other bits.
; A = bank bits for $DD00. Keeps the other bits.
set_bank:
sta bank_bits
lda CIA2_PRA
@@ -109,7 +139,8 @@ set_bank:
sta CIA2_PRA
rts

draw_tile_view:
; Render the first 40 columns of each of the first 25 world rows.
draw_world_view:
lda #<BITMAP_A
sta bmp
lda #>BITMAP_A
@@ -119,29 +150,19 @@ draw_tile_view:
lda #>SCREEN_A
sta scr+1
lda #0
sta panel_row
lda #25
sta screen_rows
@row: jsr draw_panel_row
jsr draw_panel_row
lda panel_index
cmp #TEST_PANEL_SIZE
bne @next_row
sta view_row
@row: ldx view_row
; Set the source operand once per row. Both zero-page pointers
; remain dedicated to the two output streams.
lda world_row_low,x
sta @source+1
lda world_row_high,x
sta @source+2
lda #0
@next_row:
sta panel_row
dec screen_rows
bne @row
rts

; Draw the same panel row in either half of the screen.
draw_panel_row:
lda panel_row
sta panel_index
lda #TEST_PANEL_WIDTH
sta panel_cells
@cell: ldx panel_index
lda test_panel,x
sta view_column
@cell: ldy view_column
@source:
lda world_tiles,y
tax
ldy #0
lda tile_colors,x
@@ -166,12 +187,17 @@ draw_panel_row:
inc bmp+1
@advance_screen:
inc scr
bne @advance_panel
bne @advance_column
inc scr+1
@advance_panel:
inc panel_index
dec panel_cells
@advance_column:
inc view_column
lda view_column
cmp #VIEW_WIDTH
bne @cell
inc view_row
lda view_row
cmp #VIEW_HEIGHT
bne @row
rts

; Colour RAM is shared by both buffers: light red everywhere (pixel %11 = people).
@@ -186,8 +212,8 @@ fill_color_ram:
bne @loop
rts

; Clear the (hidden) text screen and write the status mirror for the smoke test.
write_status:
; Prepare the text screen before switching the VIC to it.
write_generating:
lda #$20 ; screen code for space
ldx #0
@clear: sta TEXT_SCREEN,x
@@ -203,23 +229,23 @@ write_status:
inx
bne @title
@status:
ldx #0
@stat: lda status_text,x
beq @done
ldx #STATUS_LENGTH-1
@stat: lda generating_text,x
sta TEXT_SCREEN+80,x ; row 2
inx
bne @stat
@done: rts
dex
bpl @stat
rts

.segment "RODATA"
title_text: .byte "LAND MAP 64", 0
status_text: .byte "MAP READY", 0
title_text: .byte "LAND MAP 64", 0
generating_text: .byte "GENERATING..."
STATUS_LENGTH = * - generating_text
ready_text: .byte "MAP READY "
.assert * - ready_text = STATUS_LENGTH, error, "Status text length"

.segment "BSS"
bank_bits: .res 1
panel_row: .res 1 ; starting index of the current test panel row
panel_index: .res 1
panel_cells: .res 1
screen_rows: .res 1
view_row: .res 1
view_column: .res 1

.include "world.inc"

+ 0
- 30
src/tiles.inc Dosyayı Görüntüle

@@ -58,33 +58,3 @@ tile_colors:
.byte $09
.endrepeat
.assert * - tile_colors = TILE_COUNT, error, "Tile colour table size"

; The test view repeats this 20x12 panel twice in each direction.
TEST_PANEL_WIDTH = 20
test_panel:
.byte LAND, LAND, LAND, LAND, LAND, LAND, LAND, LAND, LAND, LAND
.byte LAND, LAND, LAND, LAND, LAND, LAND, LAND, LAND, LAND, LAND
.byte LAND, LAND, LAND, LAND, LAND, LAND, LAND, LAND, ROAD_V, LAND
.byte LAND, LAND, LAND, LAND, LAND, LAND, LAND, LAND, LAND, LAND
.byte LAND, LAND, TREE, GRASS, GRASS, GRASS, TREE, LAND, ROAD_V, LAND
.byte WATER_NW, WATER_N, WATER_N, WATER_N, WATER_NE, LAND, LAND, LAND, LAND, LAND
.byte LAND, LAND, GRASS, GRASS, GRASS, TREE, GRASS, LAND, ROAD_V, LAND
.byte WATER_W, WATER, WATER, WATER, WATER_E, LAND, STONE, STONE, LAND, LAND
.byte LAND, LAND, GRASS, GRASS, TREE, GRASS, GRASS, LAND, ROAD_V, LAND
.byte WATER_W, WATER, WATER, WATER, WATER_E, LAND, STONE, STONE, LAND, LAND
.byte LAND, LAND, GRASS, TREE, GRASS, GRASS, GRASS, LAND, ROAD_V, LAND
.byte WATER_W, WATER, WATER, WATER, WATER_E, LAND, STONE, STONE, LAND, LAND
.byte LAND, LAND, TREE, GRASS, GRASS, GRASS, TREE, LAND, ROAD_V, LAND
.byte WATER_SW, WATER_S, WATER_S, WATER_S, WATER_SE, LAND, LAND, LAND, LAND, LAND
.byte LAND, LAND, LAND, LAND, LAND, LAND, LAND, LAND, ROAD_V, LAND
.byte LAND, LAND, LAND, LAND, LAND, ROAD_SE, ROAD_H, ROAD_H, ROAD_SW, LAND
.byte LAND, ROAD_H, ROAD_H, ROAD_H, ROAD_H, ROAD_H, ROAD_H, ROAD_H, ROAD_X, ROAD_H
.byte ROAD_H, ROAD_H, ROAD_H, ROAD_H, ROAD_H, ROAD_X, ROAD_H, ROAD_H, ROAD_X, LAND
.byte LAND, LAND, LAND, LAND, LAND, LAND, LAND, LAND, ROAD_V, LAND
.byte LAND, LAND, LAND, LAND, LAND, ROAD_V, LAND, LAND, ROAD_V, LAND
.byte LAND, LAND, LAND, LAND, LAND, LAND, LAND, LAND, ROAD_V, LAND
.byte LAND, LAND, LAND, LAND, LAND, ROAD_NE, ROAD_H, ROAD_H, ROAD_NW, LAND
.byte LAND, LAND, LAND, LAND, LAND, LAND, LAND, LAND, LAND, LAND
.byte LAND, LAND, LAND, LAND, LAND, LAND, LAND, LAND, LAND, LAND
TEST_PANEL_SIZE = * - test_panel
.assert TEST_PANEL_SIZE = TEST_PANEL_WIDTH * 12, error, "Test panel size"

+ 19
- 1
src/world.inc Dosyayı Görüntüle

@@ -9,10 +9,23 @@ world_ptr = bmp ; generator runs before bitmap drawing
.export world_tiles, generate_world

.segment "CODE"
; Read the running KERNAL timer. Fall through to the fixed-seed entry point.
; Read the running KERNAL timer. Avoid reusing the same seed on consecutive
; requests, even if SPACE happens to be sampled at the same timer value.
generate_world_from_timer:
lda CIA1_TIMER_A
ldx CIA1_TIMER_A+1
bne @compare
cmp #0
bne @compare
lda #1
@compare:
cpx last_seed_high
bne generate_world
cmp last_seed_low
bne generate_world
eor #$80
bne generate_world
lda #1

; A/X = low/high seed. Zero is mapped to one for the LFSR.
generate_world:
@@ -22,6 +35,9 @@ generate_world:
bne @seeded
inc seed_low
@seeded:
lda seed_low
sta last_seed_low
stx last_seed_high
ldx #0
@clear_row:
jsr point_world_row
@@ -262,6 +278,8 @@ world_row_high:
.segment "BSS"
seed_low: .res 1
seed_high: .res 1
last_seed_low: .res 1
last_seed_high: .res 1
sector: .res 1
origin_x: .res 1
origin_y: .res 1


Yükleniyor…
İptal
Kaydet

Powered by TurnKey Linux.