diff --git a/docs/manual-tests.md b/docs/manual-tests.md index 1f76816..ce2bb44 100644 --- a/docs/manual-tests.md +++ b/docs/manual-tests.md @@ -53,12 +53,16 @@ Setup: VICE x64sc, PAL. Start: `pwsh -File tools/run.ps1 -Target c64` Steps: -1. Hold the right cursor key until the view stops moving. -2. Repeat for down, left and up (W/A/S/D as well). +1. Note row 24 and the blinking white cursor bracket in the starting cave. +2. Tap the right cursor key a few times. Then hold it until the view stops moving, and keep holding. +3. Repeat for down, left and up. Then do the same with W (up), A (left), S (down) and D (right). Expected: -- The view scrolls one tile at a time without garbage characters -- Scrolling stops at each map edge and the cursor cannot leave the map +- Row 24 reads 'STONE 000 SEED nnnnn RUN' +- Each tap moves the cursor one tile. The cursor blinks, showing the tile or dwarf under it in between. +- The view starts scrolling when the cursor is 2 tiles from an edge, and scrolls steadily one tile at a time while the key is held, without garbage characters. A brief shear or tear in the map while it scrolls is a known limitation, not a failure. +- At each map edge the view stops scrolling and the cursor goes on to the outermost tile (2 tiles from the view edge), then stops. It cannot leave the map. +- W/A/S/D move exactly like the cursor keys Verifies: R3 diff --git a/docs/verification-status.md b/docs/verification-status.md index dd70821..ba980cb 100644 --- a/docs/verification-status.md +++ b/docs/verification-status.md @@ -12,7 +12,7 @@ manual = `pending`, `confirmed by user ()`, `problem reported (): )`, `problem reported (): (unsigned char)(limit - size) ? (unsigned char)(limit - size) : centre; } +/* Move the cursor by (dx, dy), clamp it to the map, and scroll the view if the cursor is +** within SCROLL_MARGIN tiles of a view edge. Returns 1 if the view scrolled. */ +static unsigned char move_cursor(signed char dx, signed char dy) +{ + unsigned char scrolled = 0; + + if (dx < 0 && cur_x > 0) --cur_x; + if (dx > 0 && cur_x < MAP_W - 1) ++cur_x; + if (dy < 0 && cur_y > 0) --cur_y; + if (dy > 0 && cur_y < MAP_H - 1) ++cur_y; + + if (cur_x < view_x + SCROLL_MARGIN && view_x > 0) { + --view_x; scrolled = 1; + } else if (cur_x > view_x + (VIEW_W - 1 - SCROLL_MARGIN) && view_x < VIEW_MAX_X) { + ++view_x; scrolled = 1; + } + if (cur_y < view_y + SCROLL_MARGIN && view_y > 0) { + --view_y; scrolled = 1; + } else if (cur_y > view_y + (VIEW_H - 1 - SCROLL_MARGIN) && view_y < VIEW_MAX_Y) { + ++view_y; scrolled = 1; + } + 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) +{ + 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; + } + } + return result; +} + int main(void) { - unsigned seed, t0; - unsigned char vx, vy; + unsigned seed, t0, c; + unsigned char changed; bordercolor(COLOR_BLACK); bgcolor(COLOR_BLACK); @@ -101,11 +218,10 @@ int main(void) textcolor(COLOR_LIGHTRED); cputsxy(0, 1, "MEMORY CLASH"); textcolor(COLOR_WHITE); - cputsxy(0, 24, "STONE 000 ANY KEY EXITS"); + cputsxy(0, 24, "STONE 000"); smoke_capture(); smoke_ready(); - cgetc(); - return 1; + for (;;) { } } charset_install(); @@ -120,31 +236,48 @@ int main(void) map_generate(seed); gen_jiffies = jiffies() - t0; - vx = view_origin(map_start_x, VIEW_W, MAP_W); - vy = view_origin(map_start_y, VIEW_H, MAP_H); + cur_x = map_start_x; + cur_y = map_start_y; + view_x = view_origin(cur_x, VIEW_W, MAP_W); + view_y = view_origin(cur_y, VIEW_H, MAP_H); cycles_start(); - draw_view(vx, vy); + draw_view(view_x, view_y); view_cycles = cycles_read(); view_fast = view_cycles < (get_tv() == TV_NTSC ? FRAME_CYCLES_NTSC : FRAME_CYCLES_PAL); - draw_dwarves(vx, vy); + draw_dwarves(); gotoxy(0, 24); - cprintf("STONE 000 SEED %05u ANY KEY EXITS", map_seed); + cprintf("STONE 000 SEED %05u RUN", map_seed); + + KEY_REPEAT_MODE = 0x80; + while (kbhit()) { /* drop keys pressed while the map was generated */ + cgetc(); + } smoke_capture(); smoke_ready(); - while (!kbhit()) { + for (;;) { wait_frame(); + cycles_start(); #ifdef VIEW_TIMING bordercolor(COLOR_RED); - draw_view(vx, vy); + redraw_all(); bordercolor(COLOR_BLACK); - draw_dwarves(vx, vy); #endif + changed = handle_keys(); + if (changed == 1) { + redraw_all(); + } + if (changed) { + blink = 0; /* show the cursor at once after a move */ + } + ++blink; + draw_cursor_cell((blink & 31u) < CURSOR_ON_FRAMES); + c = cycles_read(); + if (c > frame_max_cycles) { + frame_max_cycles = c; + } } - cgetc(); - charset_remove(); - clrscr(); - return 0; + /* not reached: the game runs until reset */ }