Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>main
| @@ -54,8 +54,10 @@ Starter configurations marked verified were exercised by the Foundry's automated | |||||
| - Smoke test: `pwsh -File tools/smoke.ps1 -Target c64`. It runs VICE headless for 30000000 cycles, saves memory when the program reaches `smoke_ready`, and checks: | - Smoke test: `pwsh -File tools/smoke.ps1 -Target c64`. It runs VICE headless for 30000000 cycles, saves memory when the program reaches `smoke_ready`, and checks: | ||||
| - Title in the status mirror | - Title in the status mirror | ||||
| - World generation reached its ready point (`MAP READY`) | - World generation reached its ready point (`MAP READY`) | ||||
| - Status rows 20, 21, 22 and 24 in buffer A's text screen ($4720) and rows 20 and 24 in buffer B's ($8720) | |||||
| - C64 KERNAL reset vector at $FFFC (machine is in C64 mode) | - C64 KERNAL reset vector at $FFFC (machine is in C64 mode) | ||||
| - World check: `pwsh -File tools/check-world.ps1` validates the tile data saved by the smoke test. | - World check: `pwsh -File tools/check-world.ps1` validates the tile data saved by the smoke test. | ||||
| - Split check: `pwsh -File tools/check-split.ps1` runs VICE headless for 20,000,000 cycles. It logs the raster line and cycle of the three mode writes at `split_store` (src/status.inc) every frame and requires them to start between line 210 cycle 53 and line 210 cycle 64. That window was measured by building with split delays 6-12 under `+autostart-delay-random`: starts at 210:40-51 damaged the last map line, starts at 211:0-11 damaged the first text line, and 210:50-211:1 were clean; the shipped delay starts at 210:55-61. It also checks that a split happens every frame, that the people-in-view digits match the drawn count, and (coarsely) the screenshot colours at the boundary. Output: `build/check-split/`. | |||||
| - Key check: `pwsh -File tools/check-keys.ps1` runs eight headless VICE scenarios. VICE's monitor cannot press keys, so tracepoints on the `key_row_*` instructions in `src/keys.inc` replace the port B row bits with those of held keys (`r a = <bits>`). It checks `scroll_dx`/`scroll_dy` and the border indicator for no key, right, left (right SHIFT), down, up (left SHIFT), down-right and up-left, and that SPACE held from frame 60 regenerates exactly once. Output: `build/check-keys/`. | - Key check: `pwsh -File tools/check-keys.ps1` runs eight headless VICE scenarios. VICE's monitor cannot press keys, so tracepoints on the `key_row_*` instructions in `src/keys.inc` replace the port B row bits with those of held keys (`r a = <bits>`). It checks `scroll_dx`/`scroll_dy` and the border indicator for no key, right, left (right SHIFT), down, up (left SHIFT), down-right and up-left, and that SPACE held from frame 60 regenerates exactly once. Output: `build/check-keys/`. | ||||
| - People check: `pwsh -File tools/check-people.ps1` runs VICE headless (NTSC, warp) for 40,000,000 cycles, logs the people table at the `people_moved` hook every frame through the monitor, and checks that all 16 people stay inside the world, never stand on a water or stone tile, move at most one pixel per step, all move, and start spread over the four screens. It also saves both bitmap buffers before people are drawn and at the last frame, and checks byte for byte that the hidden buffer is the clean map plus the current dots and the visible buffer is the clean map plus the previous frame's dots (no trails, no damaged terrain). It checks that the main loop never misses a frame (x64sc NTSC frame: 263 lines x 65 = 17,095 cycles) and that each people update ends before raster line 51, the first visible line. Output: `build/check-people/`. | - People check: `pwsh -File tools/check-people.ps1` runs VICE headless (NTSC, warp) for 40,000,000 cycles, logs the people table at the `people_moved` hook every frame through the monitor, and checks that all 16 people stay inside the world, never stand on a water or stone tile, move at most one pixel per step, all move, and start spread over the four screens. It also saves both bitmap buffers before people are drawn and at the last frame, and checks byte for byte that the hidden buffer is the clean map plus the current dots and the visible buffer is the clean map plus the previous frame's dots (no trails, no damaged terrain). It checks that the main loop never misses a frame (x64sc NTSC frame: 263 lines x 65 = 17,095 cycles) and that each people update ends before raster line 51, the first visible line. Output: `build/check-people/`. | ||||
| @@ -15,12 +15,14 @@ manual = `pending`, `confirmed by user (<date>)`, `problem reported (<date>): <n | |||||
| | M2.1 People table (world x, y, direction) and movement rules; water and stone block. | passed (2026-12-03, `pwsh -File tools/build.ps1`; `pwsh -File tools/smoke.ps1`; `pwsh -File tools/check-world.ps1`; `pwsh -File tools/check-people.ps1`: 2,106 frames logged, every person stepped 263-264 times, none on water or stone) | confirmed by user (2026-12-03) | | | M2.1 People table (world x, y, direction) and movement rules; water and stone block. | passed (2026-12-03, `pwsh -File tools/build.ps1`; `pwsh -File tools/smoke.ps1`; `pwsh -File tools/check-world.ps1`; `pwsh -File tools/check-people.ps1`: 2,106 frames logged, every person stepped 263-264 times, none on water or stone) | confirmed by user (2026-12-03) | | ||||
| | M2.2 Per-buffer saved-byte lists: restore the bytes under people from two frames ago, draw people in view, flip in vertical blank. | passed (2026-12-03, `pwsh -File tools/build.ps1`; `pwsh -File tools/smoke.ps1`; `pwsh -File tools/check-world.ps1`; `pwsh -File tools/check-people.ps1`: 2,117 frames, 0 missed flips, update done by raster line 26 at the latest, both final bitmaps byte-exact against clean map plus dots) | confirmed by user (2026-12-03) | | | M2.2 Per-buffer saved-byte lists: restore the bytes under people from two frames ago, draw people in view, flip in vertical blank. | passed (2026-12-03, `pwsh -File tools/build.ps1`; `pwsh -File tools/smoke.ps1`; `pwsh -File tools/check-world.ps1`; `pwsh -File tools/check-people.ps1`: 2,117 frames, 0 missed flips, update done by raster line 26 at the latest, both final bitmaps byte-exact against clean map plus dots) | confirmed by user (2026-12-03) | | ||||
| | M3.1 Keyboard matrix reading for the cursor keys with SHIFT, held-key repeat. | passed (2026-12-03, `pwsh -File tools/build.ps1`; `pwsh -File tools/smoke.ps1`; `pwsh -File tools/check-world.ps1`; `pwsh -File tools/check-people.ps1`; `pwsh -File tools/check-keys.ps1`: 8 of 8 scenarios, SPACE held = 1 regeneration) | confirmed by user (2026-12-03) | | | M3.1 Keyboard matrix reading for the cursor keys with SHIFT, held-key repeat. | passed (2026-12-03, `pwsh -File tools/build.ps1`; `pwsh -File tools/smoke.ps1`; `pwsh -File tools/check-world.ps1`; `pwsh -File tools/check-people.ps1`; `pwsh -File tools/check-keys.ps1`: 8 of 8 scenarios, SPACE held = 1 regeneration) | confirmed by user (2026-12-03) | | ||||
| | M3.2 Split screen: raster interrupts switch to text below a 20-row map and back at the top of the frame; status text screen and ROM font copy in both banks; status lines with the people-in-view count. | not run | pending | | |||||
| | M3.2 Split screen: raster interrupts switch to text below a 20-row map and back at the top of the frame; status text screen and ROM font copy in both banks; status lines with the people-in-view count. | passed (2026-12-03, `pwsh -File tools/build.ps1`; `pwsh -File tools/smoke.ps1` incl. status text in both banks; `pwsh -File tools/check-world.ps1`; `pwsh -File tools/check-people.ps1`; `pwsh -File tools/check-keys.ps1`; `pwsh -File tools/check-split.ps1`: 955 splits in 955 frames, writes start at 210:55-61, digits right in every frame) | pending | | |||||
| | M3.3 Fine scroll via $D016/$D011 in the 38-column, 20-row map area; rebuild the hidden buffer from tiles over 8 frames and flip on wrap; stop at world edges; show the view position in the status area. | not run | pending | | | M3.3 Fine scroll via $D016/$D011 in the 38-column, 20-row map area; rebuild the hidden buffer from tiles over 8 frames and flip on wrap; stop at world edges; show the view position in the status area. | not run | pending | | ||||
| | M3.4 Draw people relative to the view; measure the frame budget with a border-colour timing bar. | not run | pending | | | M3.4 Draw people relative to the view; measure the frame budget with a border-colour timing bar. | not run | pending | | ||||
| ## Notes | ## Notes | ||||
| - 2026-12-03 (M3.2): A7 partly checked in VICE: with the map at y-scroll 3, the split's mode writes land in the measured border window every frame (tools/check-split.ps1). Under vertical fine scroll it is not checked yet (M3.3). Fixed while doing M3.2: the temporary M3.1 border indicator wrote $D020 every frame, which showed a single light grey pixel in the bottom border (consistent with the VIC-II grey-dot effect of a colour-register write mid-line); it now writes only when the colour changes, and the pixel is gone from the smoke and split-check screenshots. tools/check-people.ps1 now compares only the 20 map rows of each bitmap. | |||||
| - 2026-12-03: Spec change approved by the user: 5-line status area below a 20-row map (new R6, R1 and R5 updated, assumption A7 added). Old M3.2 is now M3.3 and old M3.3 is now M3.4; the new M3.2 is the split screen. M0-M3.1 results are unaffected. | - 2026-12-03: Spec change approved by the user: 5-line status area below a 20-row map (new R6, R1 and R5 updated, assumption A7 added). Old M3.2 is now M3.3 and old M3.3 is now M3.4; the new M3.2 is the split screen. M0-M3.1 results are unaffected. | ||||
| - 2026-12-03 (M2.2): VICE x64sc NTSC runs 263 lines x 65 cycles = 17,095 cycles per frame (measured with tools/check-people.ps1). The spec's budget said 17,030 (the 262-line 6567R56A figure). The difference does not affect any acceptance criterion. With the user's approval (2026-12-03), docs/spec.md and project.json now say 17,095. | - 2026-12-03 (M2.2): VICE x64sc NTSC runs 263 lines x 65 cycles = 17,095 cycles per frame (measured with tools/check-people.ps1). The spec's budget said 17,030 (the 262-line 6567R56A figure). The difference does not affect any acceptance criterion. With the user's approval (2026-12-03), docs/spec.md and project.json now say 17,095. | ||||
| @@ -290,7 +290,7 @@ | |||||
| }, | }, | ||||
| "starter": { | "starter": { | ||||
| "screenTitle": "LAND MAP 64", | "screenTitle": "LAND MAP 64", | ||||
| "expectedScreen": "After a short generating message, VICE shows the top-left view of the generated terrain in multicolour bitmap mode, with light red dots (people) walking on it. SPACE generates a different map. 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 (20 rows), with light red dots (people) walking on it and five status lines below. SPACE generates a different map. The hidden text screen shows \"LAND MAP 64\" and \"MAP READY\".", | |||||
| "smokeChecks": [ | "smokeChecks": [ | ||||
| { | { | ||||
| "row": 0, | "row": 0, | ||||
| @@ -684,6 +684,18 @@ | |||||
| "symbol": null, | "symbol": null, | ||||
| "address": "FFFC", | "address": "FFFC", | ||||
| "length": 2 | "length": 2 | ||||
| }, | |||||
| { | |||||
| "name": "status-a", | |||||
| "symbol": null, | |||||
| "address": "4720", | |||||
| "length": 200 | |||||
| }, | |||||
| { | |||||
| "name": "status-b", | |||||
| "symbol": null, | |||||
| "address": "8720", | |||||
| "length": 200 | |||||
| } | } | ||||
| ], | ], | ||||
| "checks": [ | "checks": [ | ||||
| @@ -710,9 +722,57 @@ | |||||
| "encoding": null, | "encoding": null, | ||||
| "bytes": "E2 FC", | "bytes": "E2 FC", | ||||
| "description": "C64 KERNAL reset vector at $FFFC (machine is in C64 mode)" | "description": "C64 KERNAL reset vector at $FFFC (machine is in C64 mode)" | ||||
| }, | |||||
| { | |||||
| "dump": "status-a", | |||||
| "offset": 0, | |||||
| "text": "LAND MAP 64", | |||||
| "encoding": "screen-upper", | |||||
| "bytes": null, | |||||
| "description": "Status row 20 title in buffer A's text screen" | |||||
| }, | |||||
| { | |||||
| "dump": "status-a", | |||||
| "offset": 40, | |||||
| "text": "VIEW X 00 Y 00", | |||||
| "encoding": "screen-upper", | |||||
| "bytes": null, | |||||
| "description": "Status row 21 view position in buffer A" | |||||
| }, | |||||
| { | |||||
| "dump": "status-a", | |||||
| "offset": 80, | |||||
| "text": "PEOPLE IN VIEW", | |||||
| "encoding": "screen-upper", | |||||
| "bytes": null, | |||||
| "description": "Status row 22 people label in buffer A" | |||||
| }, | |||||
| { | |||||
| "dump": "status-a", | |||||
| "offset": 160, | |||||
| "text": "CRSR SCROLL SPACE NEW WORLD", | |||||
| "encoding": "screen-upper", | |||||
| "bytes": null, | |||||
| "description": "Status row 24 key help in buffer A" | |||||
| }, | |||||
| { | |||||
| "dump": "status-b", | |||||
| "offset": 0, | |||||
| "text": "LAND MAP 64", | |||||
| "encoding": "screen-upper", | |||||
| "bytes": null, | |||||
| "description": "Status row 20 title in buffer B's text screen" | |||||
| }, | |||||
| { | |||||
| "dump": "status-b", | |||||
| "offset": 160, | |||||
| "text": "CRSR SCROLL SPACE NEW WORLD", | |||||
| "encoding": "screen-upper", | |||||
| "bytes": null, | |||||
| "description": "Status row 24 key help in buffer B" | |||||
| } | } | ||||
| ], | ], | ||||
| "expectedScreen": "After a short generating message, VICE shows the top-left view of the generated terrain in multicolour bitmap mode, with light red dots (people) walking on it. SPACE generates a different map. 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 (20 rows), with light red dots (people) walking on it and five status lines below. SPACE generates a different map. The hidden text screen shows \"LAND MAP 64\" and \"MAP READY\"." | |||||
| }, | }, | ||||
| "recipeStatus": "verified", | "recipeStatus": "verified", | ||||
| "validationPlan": [] | "validationPlan": [] | ||||
| @@ -117,8 +117,11 @@ show_scroll_direction: | |||||
| adc #1 | adc #1 | ||||
| tax | tax | ||||
| lda direction_colors,x | lda direction_colors,x | ||||
| cmp border_shown ; write only on a change: each write to a | |||||
| beq @same ; colour register can show a grey dot | |||||
| sta border_shown | |||||
| sta VIC_BORDER | sta VIC_BORDER | ||||
| rts | |||||
| @same: rts | |||||
| .segment "RODATA" | .segment "RODATA" | ||||
| direction_colors: | direction_colors: | ||||
| @@ -135,3 +138,4 @@ keys_rshift: .res 1 | |||||
| keys_space: .res 1 | keys_space: .res 1 | ||||
| space_down: .res 1 | space_down: .res 1 | ||||
| direction_index: .res 1 | direction_index: .res 1 | ||||
| border_shown: .res 1 ; last colour written by show_scroll_direction | |||||
| @@ -1,4 +1,4 @@ | |||||
| ; Land Map 64 - generated terrain view with walking people (ca65). | |||||
| ; Land Map 64 - generated terrain view with walking people and a status area (ca65). | |||||
| ; Built with: cl65 -t c64 -C c64-asm.cfg -u __EXEHDR__ (BASIC SYS line included). | ; Built with: cl65 -t c64 -C c64-asm.cfg -u __EXEHDR__ (BASIC SYS line included). | ||||
| ; | ; | ||||
| ; Multicolour bitmap palette and VIC bank layout: | ; Multicolour bitmap palette and VIC bank layout: | ||||
| @@ -36,7 +36,7 @@ BITMAP_A = $6000 | |||||
| SCREEN_B = $8000 | SCREEN_B = $8000 | ||||
| BITMAP_B = $A000 | BITMAP_B = $A000 | ||||
| VIEW_WIDTH = 40 | VIEW_WIDTH = 40 | ||||
| VIEW_HEIGHT = 25 | |||||
| VIEW_HEIGHT = 20 ; map rows; the status area (status.inc) is below | |||||
| BANK_TEXT_BITS = %00000011 ; VIC bank 0 ($0000-$3FFF) | BANK_TEXT_BITS = %00000011 ; VIC bank 0 ($0000-$3FFF) | ||||
| BANK_A_BITS = %00000010 ; VIC bank 1 ($4000-$7FFF) | BANK_A_BITS = %00000010 ; VIC bank 1 ($4000-$7FFF) | ||||
| @@ -64,6 +64,8 @@ start: | |||||
| sta CPU_PORT ; read buffer B's bitmap at $A000 (needed from M2) | sta CPU_PORT ; read buffer B's bitmap at $A000 (needed from M2) | ||||
| jsr stop_kernal_irq | jsr stop_kernal_irq | ||||
| jsr copy_font | |||||
| jsr install_raster_irq | |||||
| lda #0 | lda #0 | ||||
| sta last_seed_low | sta last_seed_low | ||||
| sta last_seed_high | sta last_seed_high | ||||
| @@ -82,6 +84,7 @@ main_loop: | |||||
| jsr restore_people | jsr restore_people | ||||
| jsr move_people | jsr move_people | ||||
| jsr draw_people | jsr draw_people | ||||
| jsr update_people_count | |||||
| people_moved: ; check hook: hidden buffer holds the new step | people_moved: ; check hook: hidden buffer holds the new step | ||||
| jsr wait_frame | jsr wait_frame | ||||
| ldx hidden | ldx hidden | ||||
| @@ -105,7 +108,9 @@ rebuild_map: | |||||
| lda #COL_BROWN | lda #COL_BROWN | ||||
| sta VIC_BORDER | sta VIC_BORDER | ||||
| sta VIC_BG0 | sta VIC_BG0 | ||||
| jsr wait_frame | |||||
| sta border_shown | |||||
| jsr wait_frame ; below the map: stop the split before | |||||
| jsr stop_raster_irq ; showing the message | |||||
| lda #BANK_TEXT_BITS | lda #BANK_TEXT_BITS | ||||
| jsr set_bank | jsr set_bank | ||||
| lda #$14 ; text screen at $0400, uppercase ROM font | lda #$14 ; text screen at $0400, uppercase ROM font | ||||
| @@ -121,18 +126,20 @@ rebuild_map: | |||||
| jsr draw_world_view | jsr draw_world_view | ||||
| lda #>SCREEN_B | lda #>SCREEN_B | ||||
| jsr draw_world_view | jsr draw_world_view | ||||
| jsr write_status_text | |||||
| lda #0 | lda #0 | ||||
| sta visible ; buffer A is shown first | sta visible ; buffer A is shown first | ||||
| jsr wait_frame ; switch banks and modes below the visible area | jsr wait_frame ; switch banks and modes below the visible area | ||||
| lda #BANK_A_BITS | lda #BANK_A_BITS | ||||
| jsr set_bank | jsr set_bank | ||||
| lda #$08 ; screen at bank+$0000, bitmap at bank+$2000 | |||||
| lda #MAP_D018 | |||||
| sta VIC_MEMPTR | sta VIC_MEMPTR | ||||
| lda #$18 ; multicolour on, 40 columns, x-scroll 0 | |||||
| lda #MAP_D016 | |||||
| sta VIC_CTRL2 | sta VIC_CTRL2 | ||||
| lda #$3B ; bitmap mode, display on, 25 rows, y-scroll 3 | |||||
| lda #MAP_D011 | |||||
| sta VIC_CTRL1 | sta VIC_CTRL1 | ||||
| jsr start_raster_irq ; status area from this frame on | |||||
| ldx #STATUS_LENGTH-1 | ldx #STATUS_LENGTH-1 | ||||
| @ready: lda ready_text,x | @ready: lda ready_text,x | ||||
| sta TEXT_SCREEN+80,x | sta TEXT_SCREEN+80,x | ||||
| @@ -281,3 +288,4 @@ view_column: .res 1 | |||||
| .include "world.inc" | .include "world.inc" | ||||
| .include "people.inc" | .include "people.inc" | ||||
| .include "keys.inc" | .include "keys.inc" | ||||
| .include "status.inc" | |||||
| @@ -0,0 +1,180 @@ | |||||
| ; Status area: a raster split shows five rows of text below the 20-row map. | |||||
| ; | |||||
| ; Each VIC bank holds, at the same offsets, so a flip still changes only $DD00: | |||||
| ; bank + $0000 map screen RAM (bitmap colours) | |||||
| ; bank + $0400 status text screen (rows 20-24 are shown) | |||||
| ; bank + $0800 copy of the upper-case ROM font (2 KB) | |||||
| ; bank + $2000 map bitmap | |||||
| ; Colour RAM is light red everywhere, which is also the text colour. | |||||
| ; | |||||
| ; Raster interrupt, two phases per frame: | |||||
| ; TOP_IRQ_LINE (vertical blank) multicolour bitmap, map screen RAM | |||||
| ; SPLIT_IRQ_LINE waits for line SPLIT_LINE - 1, the last pixel line of map | |||||
| ; row 19, then switches to text after that line's last pixel | |||||
| ; and before the text row's first fetch at SPLIT_LINE. | |||||
| STATUS_ROW = 20 | |||||
| STATUS_ROWS = 5 | |||||
| TEXT_OFFSET = $0400 | |||||
| FONT_OFFSET = $0800 | |||||
| TEXT_A = SCREEN_A + TEXT_OFFSET | |||||
| TEXT_B = SCREEN_B + TEXT_OFFSET | |||||
| FONT_A = SCREEN_A + FONT_OFFSET | |||||
| FONT_B = SCREEN_B + FONT_OFFSET | |||||
| CHAR_ROM = $D000 | |||||
| CPU_PORT_CHARS = $32 ; BASIC out, KERNAL in, character ROM at $D000 | |||||
| VIC_IRQ_FLAGS = $D019 | |||||
| VIC_IRQ_ENABLE = $D01A | |||||
| IRQ_VECTOR = $0314 ; KERNAL jumps here after saving A, X and Y | |||||
| KERNAL_IRQ_EXIT = $EA81 ; restores Y, X, A and returns from interrupt | |||||
| MAP_D011 = $3B ; bitmap, display on, 25 rows, y-scroll 3 | |||||
| MAP_D016 = $18 ; multicolour, 40 columns, x-scroll 0 | |||||
| MAP_D018 = $08 ; screen at bank + $0000, bitmap at bank + $2000 | |||||
| TEXT_D011 = $1B ; text, display on, 25 rows, y-scroll 3 | |||||
| TEXT_D016 = $08 ; single colour, 40 columns | |||||
| TEXT_D018 = ((TEXT_OFFSET / $0400) << 4) | ((FONT_OFFSET / $0800) << 1) | |||||
| FIRST_TEXT_LINE = 51 ; first display line with y-scroll 3 | |||||
| SPLIT_LINE = FIRST_TEXT_LINE + STATUS_ROW * 8 ; 211: first line of row 20 | |||||
| SPLIT_IRQ_LINE = SPLIT_LINE - 3 | |||||
| TOP_IRQ_LINE = 16 | |||||
| SPLIT_DELAY = 9 ; delay loop count; see tools/check-split.ps1 | |||||
| PEOPLE_DIGITS = 2 * 40 + 15 ; row 22, after "PEOPLE IN VIEW " | |||||
| .assert (TEXT_A & $03FF) = 0, error, "Text screen must be 1 KB aligned" | |||||
| .assert (FONT_A & $07FF) = 0, error, "Font must be 2 KB aligned" | |||||
| .export split_store, split_done, raster_irq | |||||
| .segment "CODE" | |||||
| ; Copy the upper-case half of the character ROM into both banks. | |||||
| copy_font: | |||||
| sei | |||||
| lda #CPU_PORT_CHARS | |||||
| sta CPU_PORT | |||||
| ldx #0 | |||||
| @page: lda CHAR_ROM,x | |||||
| sta FONT_A,x | |||||
| sta FONT_B,x | |||||
| inx | |||||
| bne @page | |||||
| inc @page+2 ; next 256 bytes of source and both targets | |||||
| inc @page+5 | |||||
| inc @page+8 | |||||
| lda @page+2 | |||||
| cmp #>(CHAR_ROM + $0800) | |||||
| bne @page | |||||
| lda #$36 | |||||
| sta CPU_PORT | |||||
| cli | |||||
| rts | |||||
| ; Write the five status lines into both text screens. | |||||
| write_status_text: | |||||
| ldx #STATUS_ROWS * 40 - 1 | |||||
| @copy: lda status_text,x | |||||
| sta TEXT_A + STATUS_ROW * 40,x | |||||
| sta TEXT_B + STATUS_ROW * 40,x | |||||
| dex | |||||
| cpx #$FF | |||||
| bne @copy | |||||
| rts | |||||
| ; Show the number of people drawn into the hidden buffer in its text screen. | |||||
| update_people_count: | |||||
| ldx hidden | |||||
| lda drawn_count,x | |||||
| ldy #'0' | |||||
| @tens: cmp #10 | |||||
| bcc @ones | |||||
| sbc #10 | |||||
| iny | |||||
| bne @tens | |||||
| @ones: ora #'0' | |||||
| ldx hidden | |||||
| bne @buffer_b | |||||
| sty TEXT_A + STATUS_ROW * 40 + PEOPLE_DIGITS | |||||
| sta TEXT_A + STATUS_ROW * 40 + PEOPLE_DIGITS + 1 | |||||
| rts | |||||
| @buffer_b: | |||||
| sty TEXT_B + STATUS_ROW * 40 + PEOPLE_DIGITS | |||||
| sta TEXT_B + STATUS_ROW * 40 + PEOPLE_DIGITS + 1 | |||||
| rts | |||||
| install_raster_irq: | |||||
| sei | |||||
| lda #<raster_irq | |||||
| sta IRQ_VECTOR | |||||
| lda #>raster_irq | |||||
| sta IRQ_VECTOR+1 | |||||
| cli | |||||
| rts | |||||
| ; Start the split with the top-of-frame phase. Call with the map shown. | |||||
| start_raster_irq: | |||||
| sei | |||||
| lda #0 | |||||
| sta irq_phase | |||||
| lda #TOP_IRQ_LINE | |||||
| sta VIC_RASTER ; $D011 bit 7 (raster bit 8) is kept clear | |||||
| lda #1 | |||||
| sta VIC_IRQ_FLAGS ; drop any stale request | |||||
| sta VIC_IRQ_ENABLE | |||||
| cli | |||||
| rts | |||||
| stop_raster_irq: | |||||
| lda #0 | |||||
| sta VIC_IRQ_ENABLE | |||||
| lda #1 | |||||
| sta VIC_IRQ_FLAGS | |||||
| rts | |||||
| raster_irq: | |||||
| lda #1 | |||||
| sta VIC_IRQ_FLAGS | |||||
| lda irq_phase | |||||
| bne @split | |||||
| lda #MAP_D011 ; top of frame: map in multicolour bitmap | |||||
| sta VIC_CTRL1 | |||||
| lda #MAP_D016 | |||||
| sta VIC_CTRL2 | |||||
| lda #MAP_D018 | |||||
| sta VIC_MEMPTR | |||||
| lda #SPLIT_IRQ_LINE | |||||
| sta VIC_RASTER | |||||
| inc irq_phase | |||||
| jmp KERNAL_IRQ_EXIT | |||||
| @split: lda #SPLIT_LINE - 1 | |||||
| @wait: cmp VIC_RASTER ; start of the last map pixel line | |||||
| bne @wait | |||||
| ldx #SPLIT_DELAY | |||||
| @delay: dex | |||||
| bne @delay | |||||
| lda #TEXT_D018 | |||||
| ldx #TEXT_D011 | |||||
| ldy #TEXT_D016 | |||||
| split_store: ; check hook: these three writes must land in | |||||
| sta VIC_MEMPTR ; the border after the last map pixel | |||||
| stx VIC_CTRL1 | |||||
| sty VIC_CTRL2 | |||||
| split_done: | |||||
| lda #TOP_IRQ_LINE | |||||
| sta VIC_RASTER | |||||
| lda #0 | |||||
| sta irq_phase | |||||
| jmp KERNAL_IRQ_EXIT | |||||
| .segment "RODATA" | |||||
| status_text: | |||||
| .byte "LAND MAP 64 " | |||||
| .byte "VIEW X 00 Y 00 " | |||||
| .byte "PEOPLE IN VIEW 00 OF 16 " | |||||
| .byte " " | |||||
| .byte "CRSR SCROLL SPACE NEW WORLD " | |||||
| .assert * - status_text = STATUS_ROWS * 40, error, "Status text size" | |||||
| .segment "BSS" | |||||
| irq_phase: .res 1 | |||||
| @@ -64,7 +64,7 @@ $world = Get-Label $target 'world_tiles' | |||||
| $people = Get-Label $target 'people_cx' | $people = Get-Label $target 'people_cx' | ||||
| $visibleFlag = Get-Label $target 'visible' | $visibleFlag = Get-Label $target 'visible' | ||||
| $tableEnd = $people + 5 * $count - 1 | $tableEnd = $people + 5 * $count - 1 | ||||
| $bitmapSize = 8000 | |||||
| $bitmapSize = 20 * 320 # the 20 map rows; rows 20-24 lie under the status text | |||||
| $buffers = @(0x6000, 0xA000) # bitmaps of buffers A and B (src/main.s) | $buffers = @(0x6000, 0xA000) # bitmaps of buffers A and B (src/main.s) | ||||
| $monitor = [System.Collections.Generic.List[string]]::new() | $monitor = [System.Collections.Generic.List[string]]::new() | ||||
| $monitor.Add('logname "monitor.log"') | $monitor.Add('logname "monitor.log"') | ||||
| @@ -167,7 +167,7 @@ function Get-ExpectedBitmap([byte[]]$Clean, [byte[]]$Table) { | |||||
| $masks = 0xC0, 0x30, 0x0C, 0x03 | $masks = 0xC0, 0x30, 0x0C, 0x03 | ||||
| for ($i = 0; $i -lt $count; $i++) { | for ($i = 0; $i -lt $count; $i++) { | ||||
| $cx = $Table[$i]; $cy = $Table[32 + $i] | $cx = $Table[$i]; $cy = $Table[32 + $i] | ||||
| if ($cx -ge 40 -or $cy -ge 25) { continue } | |||||
| if ($cx -ge 40 -or $cy -ge 20) { continue } | |||||
| $offset = $cy * 320 + $cx * 8 + $Table[48 + $i] | $offset = $cy * 320 + $cx * 8 + $Table[48 + $i] | ||||
| $bitmap[$offset] = $bitmap[$offset] -bor $masks[$Table[16 + $i]] | $bitmap[$offset] = $bitmap[$offset] -bor $masks[$Table[16 + $i]] | ||||
| } | } | ||||
| @@ -0,0 +1,149 @@ | |||||
| <# | |||||
| .SYNOPSIS | |||||
| Check the map/status raster split of the C64 build headless in VICE. | |||||
| .DESCRIPTION | |||||
| Runs x64sc (NTSC, warp, private config) with monitor tracepoints: | |||||
| - at split_store (src/status.inc): logs the raster line and cycle where the three | |||||
| mode writes start, every frame; | |||||
| - at people_moved: logs the hidden buffer, both drawn counts and the people-in-view | |||||
| digits of both status text screens. | |||||
| Then checks: | |||||
| - every split starts between line 210 cycle 53 and line 210 cycle 64. This window | |||||
| was measured by sweeping the delay: starts at 210:40-51 damaged the last map | |||||
| line, 211:0-11 damaged the first text line, 210:50-211:1 were clean; | |||||
| - a split happens on every frame (no missed interrupt); | |||||
| - the status digits of the hidden buffer equal the number of people drawn into it; | |||||
| - in the exit screenshot, the 40 text lines (raster 211-250) contain only brown | |||||
| and light red, status rows 20, 21, 22 and 24 are lit and row 23 is empty, and | |||||
| the last map line (raster 210) uses no colour foreign to the map. This is a | |||||
| coarse check: in the delay sweep it caught damage from writes at 210:40-46 but | |||||
| not subtler damage, so the timing window above is the main guard. | |||||
| Exit codes: 0 = pass, 1 = fail, 2 = a tool is missing. | |||||
| .EXAMPLE | |||||
| pwsh -File tools/check-split.ps1 | |||||
| #> | |||||
| [CmdletBinding()] | |||||
| param([int]$Cycles = 20000000, [switch]$NoBuild, [int]$TimeoutSeconds = 180) | |||||
| . (Join-Path $PSScriptRoot 'lib.ps1') | |||||
| function Get-Label([hashtable]$Target, [string]$Symbol) { | |||||
| foreach ($line in Get-Content -LiteralPath (Get-RepoPath $Target.build.labels)) { | |||||
| $parts = $line -split '\s+' | |||||
| if ($parts.Count -ge 3 -and $parts[2].TrimStart('.') -eq $Symbol) { return [Convert]::ToInt32($parts[1], 16) } | |||||
| } | |||||
| throw "Symbol '$Symbol' not found in $($Target.build.labels)." | |||||
| } | |||||
| try { | |||||
| $project = Get-ProjectConfig | |||||
| $target = Get-ProjectTargets $project 'c64' | |||||
| if (-not $NoBuild) { Invoke-TargetBuild $project $target @{} } | |||||
| $emu = Get-ToolPath $project $target.emulator.binary | |||||
| } catch [MissingToolException] { | |||||
| Write-Host $_.Exception.Message -ForegroundColor Yellow | |||||
| exit 2 | |||||
| } | |||||
| $dir = Get-RepoPath 'build/check-split' | |||||
| if (Test-Path -LiteralPath $dir) { Remove-Item -LiteralPath $dir -Recurse -Force } | |||||
| New-Item -ItemType Directory -Force -Path $dir | Out-Null | |||||
| $store = Get-Label $target 'split_store' | |||||
| $moved = Get-Label $target 'people_moved' | |||||
| $hidden = Get-Label $target 'hidden' | |||||
| $drawn = Get-Label $target 'drawn_count' | |||||
| $digits = @(0x4400, 0x8400) | ForEach-Object { $_ + 22 * 40 + 15 } # row 22, after "PEOPLE IN VIEW " | |||||
| Set-Content -LiteralPath (Join-Path $dir 'monitor.txt') -Value @( | |||||
| 'logname "monitor.log"', 'log on' | |||||
| ('trace exec ${0:x4}' -f $store) | |||||
| ('trace exec ${0:x4}' -f $moved), ('command 2 "m {0:x4} {0:x4}"' -f $hidden) | |||||
| ('trace exec ${0:x4}' -f $moved), ('command 3 "m {0:x4} {1:x4}"' -f $drawn, ($drawn + 1)) | |||||
| ('trace exec ${0:x4}' -f $moved), ('command 4 "m {0:x4} {1:x4}"' -f $digits[0], ($digits[0] + 1)) | |||||
| ('trace exec ${0:x4}' -f $moved), ('command 5 "m {0:x4} {1:x4}"' -f $digits[1], ($digits[1] + 1)) | |||||
| ) | |||||
| Set-Content -LiteralPath (Join-Path $dir 'vicerc') -Value '' | |||||
| $vargs = @('-config', 'vicerc', '-default', '-sounddev', 'dummy', '-warp', '-minimized') + (Get-VideoArgs $target) | |||||
| $vargs += @('-limitcycles', [string]$Cycles, '-exitscreenshot', 'screen.png', '-moncommands', 'monitor.txt', '-autostartprgmode', '1', '-autostart', (Get-AutostartFile $target)) | |||||
| $quoted = $vargs | ForEach-Object { if ($_ -match '[\s"]') { '"' + $_ + '"' } else { $_ } } | |||||
| Write-Host "[c64] running x64sc headless for $Cycles cycles" | |||||
| $p = Start-Process -FilePath $emu -ArgumentList $quoted -WorkingDirectory $dir -PassThru ` | |||||
| -RedirectStandardOutput (Join-Path $dir 'vice.log') -RedirectStandardError (Join-Path $dir 'vice.err') | |||||
| if (-not $p.WaitForExit($TimeoutSeconds * 1000)) { $p.Kill($true); Write-Host '[FAIL] VICE did not exit in time.' -ForegroundColor Red; exit 1 } | |||||
| $failures = [System.Collections.Generic.List[string]]::new() | |||||
| $log = Join-Path $dir 'monitor.log' | |||||
| if (-not (Test-Path -LiteralPath $log)) { Write-Host '[FAIL] no monitor log' -ForegroundColor Red; exit 1 } | |||||
| # Split timing. | |||||
| $starts = [System.Collections.Generic.List[string]]::new() | |||||
| $splitFrames = 0; $moveFrames = 0; $badCounts = 0 | |||||
| $values = @{} | |||||
| $lastCheckpoint = 0 | |||||
| foreach ($line in Get-Content -LiteralPath $log) { | |||||
| if ($line -match '^#(\d+) \(Trace\s+exec [0-9a-fA-F]+\)\s+(\d+)/\$\w+,\s+(\d+)/') { | |||||
| $lastCheckpoint = [int]$Matches[1] | |||||
| if ($lastCheckpoint -eq 1) { | |||||
| $splitFrames++ | |||||
| $rl = [int]$Matches[2]; $cy = [int]$Matches[3] | |||||
| $starts.Add("${rl}:$cy") | |||||
| if ($rl -ne 210 -or $cy -lt 53 -or $cy -gt 64) { $failures.Add("split started at line $rl cycle $cy (allowed 210:53-210:64)") } | |||||
| } | |||||
| continue | |||||
| } | |||||
| if ($line -match '^>C:[0-9a-fA-F]{4} ((?:[0-9a-fA-F]{2} )+)') { | |||||
| $bytes = @($Matches[1].Trim() -split ' ' | ForEach-Object { [Convert]::ToByte($_, 16) }) | |||||
| $values[$lastCheckpoint] = $bytes | |||||
| if ($lastCheckpoint -eq 5) { | |||||
| $moveFrames++ | |||||
| $h = $values[2][0] | |||||
| $count = $values[3][$h] | |||||
| $shown = $values[4 + $h] | |||||
| $number = ($shown[0] - 0x30) * 10 + ($shown[1] - 0x30) | |||||
| if ($number -ne $count) { $badCounts++ } | |||||
| } | |||||
| } | |||||
| if ($failures.Count -gt 10) { break } | |||||
| } | |||||
| if ($splitFrames -lt 100) { $failures.Add("only $splitFrames splits logged") } | |||||
| if ([Math]::Abs($splitFrames - $moveFrames) -gt 2) { $failures.Add("$splitFrames splits for $moveFrames frames: an interrupt was missed") } | |||||
| if ($badCounts -gt 0) { $failures.Add("people-in-view digits differed from the drawn count in $badCounts frames") } | |||||
| # Screenshot: raster line r is at y = r - 28 in x64sc's NTSC screenshot. | |||||
| Add-Type -AssemblyName System.Drawing | |||||
| $shot = Join-Path $dir 'screen.png' | |||||
| if (-not (Test-Path -LiteralPath $shot)) { $failures.Add('no exit screenshot') } else { | |||||
| $bmp = [System.Drawing.Bitmap]::new($shot) | |||||
| try { | |||||
| $brown = $bmp.GetPixel(2, 2).ToArgb() | |||||
| $textColours = @{} | |||||
| $textLit = @{} | |||||
| for ($y = 211 - 28; $y -le 250 - 28; $y++) { | |||||
| for ($x = 0; $x -lt $bmp.Width; $x++) { | |||||
| $c = $bmp.GetPixel($x, $y).ToArgb() | |||||
| if ($c -ne $brown) { $textColours[$c] = 1; $textLit[[int][Math]::Floor(($y - 183) / 8)] = 1 } | |||||
| } | |||||
| } | |||||
| if ($textColours.Count -gt 1) { $failures.Add("status area shows $($textColours.Count) colours besides brown (expected light red only)") } | |||||
| foreach ($row in 0, 1, 2, 4) { if (-not $textLit.ContainsKey($row)) { $failures.Add("status row $($row + 20) is empty in the screenshot") } } | |||||
| if ($textLit.ContainsKey(3)) { $failures.Add('the spare status row 23 is not empty') } | |||||
| # Map colours: brown, light red, grey, green, blue, black as rendered in the map area above. | |||||
| $mapColours = @{} | |||||
| for ($y = 51 - 28; $y -le 209 - 28; $y++) { for ($x = 0; $x -lt $bmp.Width; $x++) { $mapColours[$bmp.GetPixel($x, $y).ToArgb()] = 1 } } | |||||
| for ($x = 0; $x -lt $bmp.Width; $x++) { | |||||
| if (-not $mapColours.ContainsKey($bmp.GetPixel($x, 210 - 28).ToArgb())) { $failures.Add("last map line has a colour not used elsewhere in the map at x=$x"); break } | |||||
| } | |||||
| } finally { $bmp.Dispose() } | |||||
| } | |||||
| $distinct = ($starts | Group-Object | Sort-Object Name | ForEach-Object { "$($_.Name) x$($_.Count)" }) -join ', ' | |||||
| Write-Host "Split starts (line:cycle): $distinct" | |||||
| Write-Host "Frames: $splitFrames splits, $moveFrames people updates; people-in-view digits wrong in $badCounts frames." | |||||
| if ($failures.Count -gt 0) { | |||||
| $failures | Select-Object -First 10 | ForEach-Object { Write-Host " $_" } | |||||
| Write-Host '[FAIL] split check' -ForegroundColor Red | |||||
| exit 1 | |||||
| } | |||||
| Write-Host '[PASS] split writes land in the measured border window every frame; status digits match; no foreign colours at the boundary.' -ForegroundColor Green | |||||
| exit 0 | |||||
Powered by TurnKey Linux.