Selaa lähdekoodia

M2.1: mark/unmark with RETURN and joystick in port 2

RETURN or joystick fire toggles the mark on the rock tile under the
cursor; floor cannot be marked. Joystick in port 2 (cc65 static stddrv)
moves the cursor with its own repeat (15-frame delay, then every 4
frames), diagonals included; fire is edge-triggered. The changed tile
shows briefly before the cursor blinks back. Smoke checks joy_ok.
Also records the user's confirmation of the M1 manual tests.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
main
Daniel Covington 1 viikko sitten
vanhempi
commit
b4108ab296
4 muutettua tiedostoa jossa 115 lisäystä ja 35 poistoa
  1. +10
    -6
      docs/manual-tests.md
  2. +5
    -5
      docs/verification-status.md
  3. +14
    -0
      project.json
  4. +86
    -24
      src/main.c

+ 10
- 6
docs/manual-tests.md Näytä tiedosto

@@ -87,18 +87,22 @@ Verifies: R3.3

### MT2.1: Mark by keyboard and joystick (c64)

Setup: VICE x64sc, PAL, a joystick or keyset mapped to port 2.
Setup: VICE x64sc, PAL, a joystick or keyset mapped to port 2 (Preferences > Settings > Input devices > Joystick; a keyset must not use the cursor keys, W/A/S/D or RETURN).
Start: `pwsh -File tools/run.ps1 -Target c64`

Steps:
1. Move the cursor onto a rock tile and press RETURN, then RETURN again.
2. Move onto a floor tile and press RETURN.
3. Use the joystick to move to another rock tile and press fire.
1. Move the cursor out of the cave onto a rock tile (brown or grey) and press RETURN. Then press RETURN again.
2. Move onto a floor tile (dark, inside the cave) and press RETURN.
3. With the joystick: tap a direction once, then hold it for a second, then try a diagonal.
4. Move with the joystick onto another rock tile and press fire. Press fire again.
5. Mark a few tiles, scroll them out of view and back.

Expected:
- RETURN marks the rock tile (yellow marked glyph) and the second RETURN unmarks it
- After RETURN the tile under the cursor shows for a moment as the yellow marked glyph (framed X), and the blinking cursor then returns. The tile stays yellow between blinks. The second RETURN restores the brown or grey rock.
- RETURN on floor changes nothing
- The joystick moves the cursor and fire marks the tile
- A joystick tap moves exactly one tile. Holding moves one tile, pauses briefly, then repeats steadily (about 12 tiles per second). Diagonals move both ways at once. The view scrolls at the edges as with the keys.
- Each fire press marks or unmarks once, exactly like RETURN. Holding fire does not keep toggling.
- Marked tiles are still yellow after scrolling away and back

Verifies: R4



+ 5
- 5
docs/verification-status.md Näytä tiedosto

@@ -9,11 +9,11 @@ manual = `pending`, `confirmed by user (<date>)`, `problem reported (<date>): <n
| Item | Automated check | Manual verification by user |
|---|---|---|
| M0.1 Run tools/check-prereqs.ps1, then tools/smoke.ps1 for every target. | passed (2026-11-26, `pwsh -File tools/check-prereqs.ps1` exit 0; `pwsh -File tools/build.ps1` exit 0; `pwsh -File tools/smoke.ps1` exit 0, [PASS] c64, 4/4 checks). Run on the working tree including the uncommitted src/charset.c/.h edit (glyphs at codes 128+), see Notes. | confirmed by user (2026-11-26) |
| M1.1 Settle the memory map (A3): where the 16 KB map, the charset and the program live. Add a check that fails the build or shows an error if they overlap. | passed (2026-11-26): `pwsh -File tools/build.ps1` exit 0, build/stonehold-64.map shows program $0801-$1702, CHARSET $3800-$3FFF, MAP $4000-$7FFF, no overlap; deliberate overflow links (1 extra byte in MAP, 10 KB extra BSS) failed with ld65 'overflows memory area', cl65 exit 1; `pwsh -File tools/smoke.ps1` exit 0, [PASS] c64 4/4. | pending |
| M1.2 Map generator in C: seeded PRNG, soft rock, hard-rock veins, caverns, starting cave near the centre. Show the seed on row 24. | passed (2026-11-26): `pwsh -File tools/build.ps1` exit 0; `pwsh -File tools/smoke.ps1` exit 0, [PASS] c64 5/5 (title, layout_ok=01, STONE 000, 'SEED ' on row 24, KERNAL vector). Extra VICE runs with memory dumps: two runs of the normal build gave seeds 21910 and 30091 with different maps (R2.2); two runs of a FIXED_SEED=12345 build gave byte-identical 16 KB maps (R2.3); dwarves on floor tiles in the starting cave (R2.4). Generation time 133 jiffies (about 2.2 s), measured by the program. | pending |
| M1.3 Assembly view redraw (draw_view(x, y), C prototype) copying a 40x23 window of the map to screen and colour RAM. Each map byte is its own screen code with its colour in the low nibble (changed from a tile-to-glyph/colour table with user approval on 2026-11-26: the table version measured 22,754 PAL / 23,177 NTSC cycles, over one frame). | passed (2026-11-26): `pwsh -File tools/build.ps1` exit 0; `pwsh -File tools/smoke.ps1 -Video pal` exit 0 and `-Video ntsc` exit 0, [PASS] c64 6/6 each, including view_fast = 01. Measured full redraw: 14,962 cycles PAL (frame 19,656), 15,131 NTSC (frame 17,095). VIEW_TIMING build screenshots in VICE: red bar ends partway down the screen on PAL and just above row 24 on NTSC. Earlier attempt (table version) failed: 22,754 PAL / 23,177 NTSC. | pending |
| M1.4 Keyboard cursor (cursor keys and W/A/S/D) with edge scrolling and map-border clamping. Status line: 'STONE 000 SEED nnnnn RUN'. | passed (2026-11-26): `pwsh -File tools/build.ps1` exit 0, no warnings; `pwsh -File tools/smoke.ps1 -Video pal` and `-Video ntsc` exit 0, [PASS] c64 7/7 each (adds 'RUN' on row 24). Scripted VICE runs that hold one cursor key (a key put into the KERNAL buffer every frame) reached every edge on PAL: view (88,y)/cursor x=127 right, (0,y)/x=0 left, (x,105)/y=127 down, (x,0)/y=0 up; right and down repeated on NTSC. Worst frame while scrolling: 19,581 cycles PAL (frame 19,656), 19,354 NTSC (frame 17,095): a scroll frame on NTSC runs one frame over, see Notes. | pending |
| M2.1 Mark/unmark with RETURN on rock tiles only; marked-rock glyph. Joystick port 2 cursor movement with key repeat and fire to mark. | not run | pending |
| M1.1 Settle the memory map (A3): where the 16 KB map, the charset and the program live. Add a check that fails the build or shows an error if they overlap. | passed (2026-11-26): `pwsh -File tools/build.ps1` exit 0, build/stonehold-64.map shows program $0801-$1702, CHARSET $3800-$3FFF, MAP $4000-$7FFF, no overlap; deliberate overflow links (1 extra byte in MAP, 10 KB extra BSS) failed with ld65 'overflows memory area', cl65 exit 1; `pwsh -File tools/smoke.ps1` exit 0, [PASS] c64 4/4. | confirmed by user (2026-11-26) |
| M1.2 Map generator in C: seeded PRNG, soft rock, hard-rock veins, caverns, starting cave near the centre. Show the seed on row 24. | passed (2026-11-26): `pwsh -File tools/build.ps1` exit 0; `pwsh -File tools/smoke.ps1` exit 0, [PASS] c64 5/5 (title, layout_ok=01, STONE 000, 'SEED ' on row 24, KERNAL vector). Extra VICE runs with memory dumps: two runs of the normal build gave seeds 21910 and 30091 with different maps (R2.2); two runs of a FIXED_SEED=12345 build gave byte-identical 16 KB maps (R2.3); dwarves on floor tiles in the starting cave (R2.4). Generation time 133 jiffies (about 2.2 s), measured by the program. | confirmed by user (2026-11-26) |
| M1.3 Assembly view redraw (draw_view(x, y), C prototype) copying a 40x23 window of the map to screen and colour RAM. Each map byte is its own screen code with its colour in the low nibble (changed from a tile-to-glyph/colour table with user approval on 2026-11-26: the table version measured 22,754 PAL / 23,177 NTSC cycles, over one frame). | passed (2026-11-26): `pwsh -File tools/build.ps1` exit 0; `pwsh -File tools/smoke.ps1 -Video pal` exit 0 and `-Video ntsc` exit 0, [PASS] c64 6/6 each, including view_fast = 01. Measured full redraw: 14,962 cycles PAL (frame 19,656), 15,131 NTSC (frame 17,095). VIEW_TIMING build screenshots in VICE: red bar ends partway down the screen on PAL and just above row 24 on NTSC. Earlier attempt (table version) failed: 22,754 PAL / 23,177 NTSC. | confirmed by user (2026-11-26) |
| M1.4 Keyboard cursor (cursor keys and W/A/S/D) with edge scrolling and map-border clamping. Status line: 'STONE 000 SEED nnnnn RUN'. | passed (2026-11-26): `pwsh -File tools/build.ps1` exit 0, no warnings; `pwsh -File tools/smoke.ps1 -Video pal` and `-Video ntsc` exit 0, [PASS] c64 7/7 each (adds 'RUN' on row 24). Scripted VICE runs that hold one cursor key (a key put into the KERNAL buffer every frame) reached every edge on PAL: view (88,y)/cursor x=127 right, (0,y)/x=0 left, (x,105)/y=127 down, (x,0)/y=0 up; right and down repeated on NTSC. Worst frame while scrolling: 19,581 cycles PAL (frame 19,656), 19,354 NTSC (frame 17,095): a scroll frame on NTSC runs one frame over, see Notes. | confirmed by user (2026-11-26) |
| M2.1 Mark/unmark with RETURN on rock tiles only; marked-rock glyph. Joystick port 2 cursor movement with key repeat and fire to mark. | passed (2026-11-26): `pwsh -File tools/build.ps1` exit 0, no warnings; `pwsh -File tools/smoke.ps1 -Video pal` and `-Video ntsc` exit 0, [PASS] c64 8/8 each (adds joy_ok = 01). Scripted VICE runs (FIXED_SEED=4242, keys put into the KERNAL buffer) compared with an untouched run: RETURN on the floor start tile changed nothing (R4.2); 6x down + RETURN turned soft rock (62,67) $99 into marked $97 and changed nothing else (R4.1); RETURN twice left the map byte-identical (R4.1). With no joystick input there were no phantom moves or marks. Joystick movement and fire cannot be scripted: manual only (MT2.1). | pending |
| M2.2 1351 mouse via cc65 c64_1351_mou: sprite 0 pointer, dig cursor = tile under the pointer tip, left button marks/unmarks, pointer at a view edge scrolls. Verify A1/A2 and record the exact VICE options in docs/. | not run | pending |
| M3.1 Dwarf job system: idle dwarves claim the nearest reachable marked tile via a windowed breadth-first search (one search per frame at most), walk there, mine for a time that depends on the rock type, turn it into floor. | not run | pending |
| M3.2 Stone counter increments per mined tile; SPACE pauses and resumes; marking still works while paused. | not run | pending |


+ 14
- 0
project.json Näytä tiedosto

@@ -800,6 +800,12 @@
"symbol": "_frame_max_cycles",
"address": null,
"length": 2
},
{
"name": "joy",
"symbol": "_joy_ok",
"address": null,
"length": 1
}
],
"checks": [
@@ -851,6 +857,14 @@
"bytes": "01",
"description": "Full view redraw fits in one frame (view_fast = 1, R3.3)"
},
{
"dump": "joy",
"offset": 0,
"text": null,
"encoding": null,
"bytes": "01",
"description": "Joystick driver installed (joy_ok = 1, R4.3)"
},
{
"dump": "vector",
"offset": 0,


+ 86
- 24
src/main.c Näytä tiedosto

@@ -17,6 +17,7 @@
** (timing bar for R3.3: the red band must end before the next frame starts at the bottom border).
*/
#include <conio.h>
#include <joystick.h>
#include <c64.h>
#include "smoke.h"
#include "frame.h"
@@ -65,9 +66,23 @@ static unsigned jiffies(void)
/* Cursor blink: shown for CURSOR_ON_FRAMES of every 32 frames, the tile shows the rest. */
#define CURSOR_ON_FRAMES 20u

/* Joystick in port 2 (R4.3): move at once, then repeat after JOY_REPEAT_DELAY frames
** every JOY_REPEAT_RATE frames while held. Fire marks/unmarks once per press. */
#define JOY_REPEAT_DELAY 15u
#define JOY_REPEAT_RATE 4u
#define JOY_DIR_MASK (JOY_UP_MASK | JOY_DOWN_MASK | JOY_LEFT_MASK | JOY_RIGHT_MASK)

static unsigned char view_x, view_y; /* top-left map tile of the view */
static unsigned char cur_x, cur_y; /* dig cursor, map tile */
static unsigned char blink; /* frame counter for the cursor blink */
static unsigned char joy_ok; /* joystick driver installed */
static unsigned char joy_fire_prev; /* fire was down last frame */
static unsigned char joy_timer; /* frames until the next joystick repeat */

/* Set by the input handlers each frame. */
static unsigned char moved; /* cursor moved (old cell already restored) */
static unsigned char need_redraw; /* view scrolled: full redraw */
static unsigned char toggled; /* a mark was set or cleared */

/* Read by tools/smoke.ps1 / test runs: worst cycles spent in one frame's work (input + redraw). */
unsigned frame_max_cycles;
@@ -167,40 +182,82 @@ static unsigned char move_cursor(signed char dx, signed char dy)
return scrolled;
}

/* Handle every key waiting in the buffer. Returns 1 if the view must be redrawn,
** 2 if only the cursor moved, 0 if nothing changed. */
static unsigned char handle_keys(void)
/* Mark or unmark the rock tile under the cursor (R4.1). Floor cannot be marked (R4.2). */
static void toggle_mark(void)
{
unsigned char *p = MAP_PTR(cur_x, cur_y);
unsigned char t = *p;
if (!TILE_IS_ROCK(t)) {
return;
}
*p = TILE_IS_MARKED(t) ? TILE_UNMARK(t) : TILE_MARK(t);
toggled = 1;
}

/* Move the cursor one step from keyboard or joystick. */
static void step(signed char dx, signed char dy)
{
if (!moved) {
moved = 1;
draw_cursor_cell(0); /* restore the old cursor cell before moving */
}
if (move_cursor(dx, dy)) {
need_redraw = 1;
}
}

/* Handle every key waiting in the buffer. */
static void handle_keys(void)
{
unsigned char result = 0;
signed char dx, dy;
char k;

while (kbhit()) {
k = cgetc();
dx = 0;
dy = 0;
switch (k) {
case CH_CURS_UP: case 'w': case 'W': dy = -1; break;
case CH_CURS_DOWN: case 's': case 'S': dy = 1; break;
case CH_CURS_LEFT: case 'a': case 'A': dx = -1; break;
case CH_CURS_RIGHT: case 'd': case 'D': dx = 1; break;
default: continue;
}
if (result == 0) {
result = 2;
draw_cursor_cell(0); /* restore the old cursor cell before moving */
}
if (move_cursor(dx, dy)) {
result = 1;
case CH_CURS_UP: case 'w': case 'W': step(0, -1); break;
case CH_CURS_DOWN: case 's': case 'S': step(0, 1); break;
case CH_CURS_LEFT: case 'a': case 'A': step(-1, 0); break;
case CH_CURS_RIGHT: case 'd': case 'D': step(1, 0); break;
case CH_ENTER: toggle_mark(); break;
default: break;
}
}
return result;
}

/* Joystick in port 2: directions (diagonals move both ways) with repeat, fire toggles. */
static void handle_joystick(void)
{
unsigned char j, dir, fire;

if (!joy_ok) {
return;
}
j = joy_read(JOY_2);
fire = (unsigned char)(j & JOY_BTN_1_MASK);
if (fire && !joy_fire_prev) {
toggle_mark();
}
joy_fire_prev = fire;

dir = (unsigned char)(j & JOY_DIR_MASK);
if (!dir) {
joy_timer = 0;
return;
}
if (joy_timer == 0) {
joy_timer = JOY_REPEAT_DELAY; /* first step at once */
} else if (--joy_timer == 0) {
joy_timer = JOY_REPEAT_RATE;
} else {
return;
}
step((signed char)(JOY_LEFT(dir) ? -1 : (JOY_RIGHT(dir) ? 1 : 0)),
(signed char)(JOY_UP(dir) ? -1 : (JOY_DOWN(dir) ? 1 : 0)));
}

int main(void)
{
unsigned seed, t0, c;
unsigned char changed;

bordercolor(COLOR_BLACK);
bgcolor(COLOR_BLACK);
@@ -250,6 +307,7 @@ int main(void)
cprintf("STONE 000 SEED %05u RUN", map_seed);

KEY_REPEAT_MODE = 0x80;
joy_ok = joy_install(joy_static_stddrv) == JOY_ERR_OK;
while (kbhit()) { /* drop keys pressed while the map was generated */
cgetc();
}
@@ -265,11 +323,15 @@ int main(void)
redraw_all();
bordercolor(COLOR_BLACK);
#endif
changed = handle_keys();
if (changed == 1) {
moved = need_redraw = toggled = 0;
handle_keys();
handle_joystick();
if (need_redraw) {
redraw_all();
}
if (changed) {
if (toggled) {
blink = CURSOR_ON_FRAMES; /* show the changed tile for a moment */
} else if (moved) {
blink = 0; /* show the cursor at once after a move */
}
++blink;


Loading…
Peruuta
Tallenna

Powered by TurnKey Linux.