diff --git a/docs/manual-tests.md b/docs/manual-tests.md index ce2bb44..1f432d6 100644 --- a/docs/manual-tests.md +++ b/docs/manual-tests.md @@ -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 diff --git a/docs/verification-status.md b/docs/verification-status.md index ba980cb..96d40db 100644 --- a/docs/verification-status.md +++ b/docs/verification-status.md @@ -9,11 +9,11 @@ manual = `pending`, `confirmed by user ()`, `problem reported (): +#include #include #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;