diff --git a/.gitignore b/.gitignore index 260c645..c2d309b 100644 --- a/.gitignore +++ b/.gitignore @@ -27,3 +27,6 @@ HELLO.dsk # Historical probe build product; source and selected evidence are retained. /APIProbe.DSK + +# Superseded delivery remains loaded/personal locally; pristine copy is in history. +/QUADPSL01.DSK diff --git a/AGENTS.md b/AGENTS.md index 5c94d94..e5c06c9 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -9,7 +9,7 @@ Brian take precedence. Read `SPECIFICATION.md` and `docs/VCC_PLUS_WORKFLOW.md`. by default for authorized solo work. Preserve unrelated edits and user disks. - The chat may be organized within the VCC Plus project. This does not authorize reading or editing other project repositories. -- Use official `/Applications/VCC Plus.app` **3.6.0 (51)** (approved by Brian November 11, 2026) and its supported MCP. +- Use official `/Applications/VCC Plus.app` **3.6.1 (53)** (approved by Brian November 11, 2026 for the joystick checks) and its supported MCP. No custom VCC Plus builds, emulator patches, private protocol calls, replacement MCP integration, or requests for VCC Plus feature changes. - Do not inspect VCC Plus implementation source, private developer guides or diff --git a/Makefile b/Makefile index ff2028f..bc03e9a 100644 --- a/Makefile +++ b/Makefile @@ -20,7 +20,7 @@ SOURCES := src/game/rules.c src/platform/coco3_video.c src/APIProbe/src/disk.c g LDLIBS += -ldecbfile else ENTRY := main.c -SOURCES := src/game/rules.c src/game/input.c src/game/store.c src/platform/coco3_video.c src/platform/video.c src/platform/disk_store.c +SOURCES := src/game/rules.c src/game/input.c src/game/store.c src/platform/coco3_video.c src/platform/video.c src/platform/keyboard.c src/platform/disk_store.c LDLIBS += -lcardgame -lbsound -ldecbfile endif OBJECTS := obj/entry.o $(SOURCES:%.c=obj/%.o) diff --git a/QUADPSL01.DSK b/QUADPSL02.DSK similarity index 86% rename from QUADPSL01.DSK rename to QUADPSL02.DSK index 3435aa2..b4b2c7d 100644 Binary files a/QUADPSL01.DSK and b/QUADPSL02.DSK differ diff --git a/README.md b/README.md index e1ddb74..5d1a8a1 100644 --- a/README.md +++ b/README.md @@ -74,15 +74,15 @@ ROM, emulator implementation, or third-party sound payload is included. ## Run the current CoCo 3 disk -Mount a writable copy of [QUADPSL01.DSK](QUADPSL01.DSK) in drive 0 and type +Mount a writable copy of [QUADPSL02.DSK](QUADPSL02.DSK) in drive 0 and type `DOS`. Keep the downloaded original pristine. The current build targets the CoCo 3; CoCo 2 adaptation is deferred. Allow disk loading and explicit saves to finish before the next action. High scores/settings use QPSAVE0.DAT and QPSAVE1.DAT; QPTEXT.DAT contains read-only menu text. Each numbered build starts with empty high scores and default preferences. Existing personal score disks remain untouched; scores are not copied into the -new build. The current delivery is **build 01**; the next changed delivery will -be build 02. See [build records](docs/BUILDS.md). The official recipe still uses +new build. The current delivery is **build 02**; the next changed delivery will +be build 03. See [build records](docs/BUILDS.md). The official recipe still uses Quadrapassel.DSK as its clean staging artifact. The separately verified manual fallback on the 512 KB test machine is: @@ -111,3 +111,8 @@ Settings names the scoring choices **Modern** and **Classic (40.2)**. Switching changes the next game and defaults to keeping existing high scores. Both formulas match the supplied Mac source. The reported normal-window buzz remains unconfirmed fixed; isolated audio is quiet between effects. + +Build 02 corrects joystick fire being mistaken for keyboard actions and allows +horizontal movement when only X has centered. Host regressions and official +keyboard smoke checks pass; actual joystick confirmation remains pending. +See [joystick correction](docs/JOYSTICK_FIX.md). diff --git a/docs/AUDIO_VALIDATION.md b/docs/AUDIO_VALIDATION.md index d7766eb..67df54e 100644 --- a/docs/AUDIO_VALIDATION.md +++ b/docs/AUDIO_VALIDATION.md @@ -121,3 +121,11 @@ capture contains 88,651 frames, idle captures 88,652 at 44,100 Hz. Checks pass. Owned runs are stopped. The normal-window buzz remains unconfirmed fixed and needs the new candidate retested in that same environment. Full final identity and preserved-score disk are in TITLE_AND_SCORING_UPDATE.md. + +Build 02 changes keyboard/joystick logical handling, not sound APIs. Official +build-53 MC6809/512 KB idle capture remains zero; the positive movement capture +has both-channel peak 7936, ten changing edges and silent final 500 ms. These +120-field captures pass the existing checker. The user-reported normal-window +buzz was still present on build 01 and remains open pending build-02 retest; +the differing emulator versions prevent treating effect peak changes as a +controlled game-volume comparison. See JOYSTICK_FIX.md for the current artifact. diff --git a/docs/BUILDS.md b/docs/BUILDS.md index 49e4d77..aa3464c 100644 --- a/docs/BUILDS.md +++ b/docs/BUILDS.md @@ -2,12 +2,13 @@ Brian requested this delivery convention on November 11, 2026: `QUADPSLxx.DSK`, with a two-digit build number and fresh high scores for each -new delivered build. Begin at 01. The next changed delivery is 02. This number +new delivered build. Begin at 01. The current delivery is 02; the next changed delivery is 03. This number identifies the game disk, independently of the VCC Plus application build. | Build | Date | Filename | Contents / validation | | --- | --- | --- | --- | -| 01 | 2026-11-11 | QUADPSL01.DSK | Current title spacing, credits, scoring labels and extra standard-library mute; byte-identical to the verified clean official artifact described in TITLE_AND_SCORING_UPDATE.md | +| 01 | 2026-11-11 | QUADPSL01.DSK | Title spacing, credits, scoring labels and extra standard-library mute; historical artifact in Git | +| 02 | 2026-11-11 | QUADPSL02.DSK | Fix shared fire/keyboard rows and independently arm joystick axes; see JOYSTICK_FIX.md | Build 01 is 161,280 bytes, SHA-256: `4ac171e87c51dfd99b302b9e035a91a59c030144e5ae0661a6d2dfc84ba3a63f`. @@ -34,9 +35,15 @@ November 11. The Git commit adding QUADPSL01.DSK records its source snapshot; use `git log -- QUADPSL01.DSK` to identify that commit. The game bytes were qualified before committing and are unchanged from the official artifact. -Brian also requested cleanup of obsolete builds. Build 01 is the only retained -current game delivery. Compiled objects, generated staging files, old probe/ +At the build-01 stage, Brian requested cleanup of obsolete builds. Build 01 +was then the only retained current game delivery. Compiled objects, generated staging files, old probe/ staging images and host test scratch were removed after verification. Personal score backups and the mounted disk remain untouched; ignored WAV/JSON diagnostic evidence is retained while the normal-window buzz is unresolved. Historical source and selected evidence remain in Git. + +Build 02 is the current clean delivery. SHA-256: +`4e3af2440a3195ee5864498e39a779362988257d8a39cfc1c413157ace287a3c`. +The old build-01 filename was observed loaded in VCC Plus, so that local disk is +left untouched during cleanup. Its pristine historical artifact remains in Git +history; it is excluded from future commits to protect any personal save writes. diff --git a/docs/IMPLEMENTATION_STATUS.md b/docs/IMPLEMENTATION_STATUS.md index 1fa6883..d9935f9 100644 --- a/docs/IMPLEMENTATION_STATUS.md +++ b/docs/IMPLEMENTATION_STATUS.md @@ -4,7 +4,21 @@ The current disk contains a playable CoCo 3 game with standard CMOC sound, settings and disk-backed high scores. Actual 128 KB qualification remains pending; CoCo 2 adaptation is deferred at Brian's direction. -## Current numbered delivery +## Current joystick correction — build 02 + +QUADPSL02.DSK fixes shared fire/keyboard input lines and arms joystick axes +independently. Both reported failure patterns were reproduced in host regressions +and pass after correction. Standard CMOC APIs are retained. Official VCC Plus +3.6.1 (53) Release build and MC6809/512 KB keyboard/gameplay smoke checks pass; +physical joystick testing is still pending. Details, source references and final +identity: [JOYSTICK_FIX.md](JOYSTICK_FIX.md). + +Clean disk SHA-256: +`4e3af2440a3195ee5864498e39a779362988257d8a39cfc1c413157ace287a3c`. +Code/constants end $7AF6, static data end $13F6; original stack/bounds retained. +The normal-window buzz remains open. Old personal score disks are untouched. + +## Earlier numbered delivery Brian requested `QUADPSLxx.DSK` with a two-digit build number and fresh high scores. The first is **QUADPSL01.DSK**, byte-identical to the clean official diff --git a/docs/JOYSTICK_FIX.md b/docs/JOYSTICK_FIX.md new file mode 100644 index 0000000..bd81479 --- /dev/null +++ b/docs/JOYSTICK_FIX.md @@ -0,0 +1,112 @@ +# Build 02 joystick correction — November 11, 2026 + +Brian reported that the right joystick could not move pieces reliably in either +VCC Plus or on the physical CoCo 3. Pressing fire appeared to rotate a piece; +releasing it turned the piece back. Build 01's simulated input tests had not +covered the actual keyboard adapter or a separately uncentered vertical axis. + +## Reproduced causes and changes + +The public coco.h key coordinates put A, D and E on row bit 0x01. Right fire +also grounds this shared input line. Calling isKeyPressed on that row while fire +is down can therefore report Left, Right and clockwise rotation together. +Releasing fire then generates the intended preferred rotation. With the default +counterclockwise preference, those two turns cancel, matching Brian's report. + +The keyboard adapter now calls the same standard isKeyPressed API but skips only +rows grounded by joystick buttons. It uses the raw low nibble returned by the +standard readJoystickButtons API, covering all four button lines, including the +other port. Unaffected keyboard rows remain usable. Keyboard/joystick aliasing +is filtered before logical action processing. No direct hardware accesses, +custom driver or assembly were added. The adapter is now a separate, testable +C module, src/platform/keyboard.c, with build/project membership updated. + +Separately, the old neutral guard required both X and Y to center before either +axis could work. A centered horizontal axis followed by left/right movement was +ignored indefinitely if Y remained outside its dead zone. The new guard arms +X and Y independently. It still requires an axis to center before accepting it, +retains hysteresis and horizontal repeat, requires neutral before another upward +hard drop, and keeps keyboard controls usable with a disconnected stick. +This independent guard defect is reproduced by tests; actual ADC traces from +Brian's physical joystick have not been captured. + +## Shared examples and attribution + +Pierre Sarrazin's CoCoPlanes 0.1.0 coco-planes.c (Copyright 2026 Pierre Sarrazin, +GPL-3.0-or-later) was consulted read-only. Its separate keyboard/joystick +controller paths, periodic sampling and active-low right/left primary-button +masks informed the comparison. The public installed Joystick.h and coco.h API +contracts were also read, including shared sound/analog input behavior. No +CoCoPlanes raw-register, interrupt or assembly routines were copied or used. +Existing standard CMOC joystick/sound APIs remain in use. + +## Tests and memory + +The new keyboard regression uses the actual keyboard adapter and an authored +mock of the shared keyboard/fire input lines. With the original polling it +fails immediately on right fire, reproducing false A/D/E actions. With the +filter it passes: all four fire lines, an unaffected BREAK key, left/right while +holding fire, one lasting rotation on release, both preferred rotation choices, +and normal keyboard/menu/initials aliases. The original axis guard also failed +the new centered-X/off-center-Y left/right test; the independent guards pass it. + +Host ASan/UBSan rules, input, keyboard-adapter, persistence and video suites pass. +The existing 25 scoring cases still pass, including actual piece drops. Palette +and font pixels are unchanged. All caption scene/column/row/label values were +checked against build 01 after packing scene+column into one byte. + +To retain the existing memory contract, unchanged caption coordinates are packed, +the 11 palette bytes and 15 preference-validation limits live in low static data, +and optional video_worst_ticks instrumentation is compiled only with +QUAD_PROFILE. That instrumentation is absent/unavailable in Release, rather than +reporting zero timing as a measurement. Profile builds still must pass the same +memory guard; they are not qualified by this release. Menu/game rendering and +all original bounds remain intact. + +Release code/constants end $7AF6; static data end $13F6. Ten bytes remain before +each enforced limit. The 1,024-byte stack reserve is unchanged. No extra RAM is +required by design; actual 128 KB qualification remains pending. + +## Official build and guest checks + +Brian explicitly approved installed VCC Plus 3.6.1 (53) for the joystick checks +and granted an idle desktop window. The official project refresh reviewed the +new adapter, fixtures and Make/settings changes. + +- Base revision: 356a7fc, main, plus this correction. +- Project: 7D6E1D9C-DF7C-4B15-B64D-6B30732417CB, revision 2. +- Release build: 9CFA6AC6-F75A-4515-9029-69129FEF3DD2; zero diagnostics. +- Artifact: C5E785C7-F0D2-407B-A626-D0FF3F9BCC22. +- QUAD.bin: 26,608 bytes, SHA-256 + `f7e0aacb35782f6bbb8ccab1761b196b02afa4120ea496277c5a14dc478856db`. +- QUADPSL02.DSK: 161,280 bytes, SHA-256 + `4e3af2440a3195ee5864498e39a779362988257d8a39cfc1c413157ace287a3c`. + Local delivery bytes match the official clean artifact. No QPSAVE data is + present; build 02 starts with defaults and an empty scoreboard. +- Owned MC6809/512 KB run: 4F2B442F-433B-4F30-8394-A6205C01FA0B, stopped. + DOS/title and keyboard move/rotate/Hold smoke checks passed. The title layout + and gameplay framebuffer were inspected after caption packing. +- Direct 120-field stereo PCM captures: idle entirely zero; movement effect + varies in both channels, peak 7936, ten changing edges, final 500 ms zero. + These build-53 results do not establish that the reported normal-window buzz + is fixed. The sound API usage was not changed by this correction. + +![Build 02 title](screenshots/build02-title-512k.png) +![Build 02 gameplay](screenshots/build02-gameplay-512k.png) + +The current MCP playtest_input schema injects keys only. These guest smoke checks +are keyboard evidence; authored host hardware models are regression evidence, +not physical joystick-port passes. Actual right/left port testing and the reported +normal-window buzzing remain pending user confirmation with build 02. No new +HD6309 qualification was performed. The personal normal emulator was not reset +or remounted; its loaded build-01 disk and personal score backups remain intact. + +## Manual check for build 02 + +Use the right port and a fresh QUADPSL02.DSK copy. Center the stick, then hold +left, reverse to right and return to center. A short fire press must produce +one rotation on release that remains after the button is released. Repeat while +steering. Hold fire 400 ms to open Actions; release must not rotate or select a +second action. Check keyboard fallback and, separately, the left-port setting. +If X still sticks, distinguish movement that never starts from movement that +works once and then locks; record which system and port exhibit it. diff --git a/docs/MCP_SETUP.md b/docs/MCP_SETUP.md index 26f1f28..b20edf3 100644 --- a/docs/MCP_SETUP.md +++ b/docs/MCP_SETUP.md @@ -59,3 +59,9 @@ project connection was renewed through the supported interface. Current project on official build 51. get_machine_status read normal-session configuration; no writable disks or peripherals were removed to satisfy native-run blockers. The new candidate used only disposable playtests. + +Brian approved official VCC Plus 3.6.1 (53) and an idle desktop window for the +joystick investigation. The renewed connection verified project +7D6E1D9C-DF7C-4B15-B64D-6B30732417CB, revision 2, built successfully and ran the +frozen artifact. Its playtest_input schema still supports only keyboard keys, +not analog axes/fire injection. No native joystick pass is inferred from it. diff --git a/docs/MEMORY_LAYOUT.md b/docs/MEMORY_LAYOUT.md index 8796a25..f713c20 100644 --- a/docs/MEMORY_LAYOUT.md +++ b/docs/MEMORY_LAYOUT.md @@ -14,8 +14,8 @@ outside live game state. No BASIC user program or prior low-resolution picture is preserved by launching this game. BASIC system RAM, text RAM and disk buffers below $0E00 remain intact. -The November 11 layout/scoring-label update ends code/constants at $7AF4 and static data at -$13DE (1,502 bytes including initialized variables). The limits remain unchanged. +The November 11 joystick update ends code/constants at $7AF6 and static data at +$13F6 (1,526 bytes including initialized variables). The limits remain unchanged. The font uses 336 row bytes plus 12 punctuation codes; 198 bytes of font/packing data are stored in the low data region and only read by the renderer. $7B00–$7FFF is kept free for the foreground/ROM stack, with CMOC configured for 1,024 bytes. The split layout has passed settings and earned-score save/reload checks on @@ -47,3 +47,9 @@ Files longer than the schema allows are rejected and reported; the program does not truncate an unexpectedly oversized file. Missing/short inactive files can be created/extended using the documented file API. Only the two named save files are written. QPTEXT.DAT is read-only game data. + +Build 02 packs each caption's scene and column into one byte, preserving all +positions. The palette (11 bytes) and preference-validation table (15 bytes) +use low static data; they are only read. Optional video timing instrumentation +is enabled only by QUAD_PROFILE and is unavailable in Release. Every profile +build still needs the unchanged link guard; profile configurations are unqualified. diff --git a/docs/PROVENANCE.md b/docs/PROVENANCE.md index 05830ce..9308021 100644 --- a/docs/PROVENANCE.md +++ b/docs/PROVENANCE.md @@ -107,3 +107,10 @@ Classic (40.2) formulas. `scoring_through_drop` in tests/rules_test.c adapts the GPL-3.0-or-later setup in its tests/test-scoring.vala to exercise actual piece drops, bottom-row detection and level changes in the CoCo rules engine. No Mac application code was changed or bundled. + +For the build-02 joystick correction, Pierre Sarrazin's GPL-3.0-or-later +CoCoPlanes 0.1.0 coco-planes.c was consulted for its separate controller paths, +periodic sampling and active-low primary-button masks. Public coco.h keyboard +coordinates and Joystick.h contracts identify the shared input rows. No raw +register/interrupt/assembly code was copied. The new keyboard-row fixture is +authored for this repository; details are in JOYSTICK_FIX.md. diff --git a/docs/VCC_PLUS_WORKFLOW.md b/docs/VCC_PLUS_WORKFLOW.md index c13d930..3f7fb49 100644 --- a/docs/VCC_PLUS_WORKFLOW.md +++ b/docs/VCC_PLUS_WORKFLOW.md @@ -2,8 +2,8 @@ ## Required installed app -Use `/Applications/VCC Plus.app`, **version 3.6.0, build 51**, explicitly approved by Brian -on November 11, 2026 for reconnection and isolated build/playtest. The installed +Use `/Applications/VCC Plus.app`, **version 3.6.1, build 53**, explicitly approved by Brian +on November 11, 2026 for the joystick investigation, reconnection and isolated build/playtest. The installed Info.plist was verified. Earlier build-48 evidence remains historical. Verify again at implementation start. If the app differs, report it and wait for Brian to approve a different version. diff --git a/docs/screenshots/build02-gameplay-512k.png b/docs/screenshots/build02-gameplay-512k.png new file mode 100644 index 0000000..f8bd3a7 Binary files /dev/null and b/docs/screenshots/build02-gameplay-512k.png differ diff --git a/docs/screenshots/build02-title-512k.png b/docs/screenshots/build02-title-512k.png new file mode 100644 index 0000000..8272561 Binary files /dev/null and b/docs/screenshots/build02-title-512k.png differ diff --git a/main.c b/main.c index d00decb..01aad4a 100644 --- a/main.c +++ b/main.c @@ -4,6 +4,7 @@ #include #include "rules.h" #include "input.h" +#include "keyboard.h" #include "preferences.h" #include "video.h" #include "disk_store.h" @@ -53,28 +54,6 @@ static void new_game(void) q_start(&game,&options);active=1;score_eligible=1;enter(PLAY); } -typedef struct { Q8 probe,bit;Q16 action; } KeyBinding; -#define BIND(name,action) {KEY_PROBE_##name,KEY_BIT_##name,action} -static const KeyBinding keys[]={ - BIND(LEFT,Q_LEFT),BIND(RIGHT,Q_RIGHT),BIND(UP,Q_UP),BIND(DOWN,Q_DOWN), - BIND(ENTER,Q_CONFIRM),BIND(BREAK,Q_BACK), - BIND(A,Q_LEFT),BIND(D,Q_RIGHT),BIND(W,Q_UP),BIND(S,Q_DOWN), - BIND(Q,Q_CCW),BIND(E,Q_CW),BIND(SPACE,Q_CONFIRM),BIND(H,Q_HOLD),BIND(P,Q_PAUSE) -}; -static Q16 keyboard(void) -{ - Q16 held=0,action;Q8 i,count=scene==INITIALS?6:sizeof(keys)/sizeof(keys[0]); - for(i=0;i>3)==scene)video_text(captions[i][0]&7,captions[i][1],ui_label(captions[i][2])); } static void picture(void) diff --git a/src/game/input.c b/src/game/input.c index 5dff385..f91a06f 100644 --- a/src/game/input.c +++ b/src/game/input.c @@ -26,15 +26,18 @@ QActions q_input_step(QInput *s,Q16 keys,Q8 button,Q8 x,Q8 y,Q8 cx,Q8 cy,Q8 joys a.held=a.pressed=0;a.move=0;a.repeats=0; if(!joystick){button=0;dx=dy=0;} s->axis_x=axis(s->axis_x,dx);s->axis_y=axis(s->axis_y,dy); - if(!s->axis_x&&!s->axis_y){s->stick_armed=1;s->up_armed=1;} + if(!s->axis_x)s->stick_armed|=1; + if(!s->axis_y){s->stick_armed|=2;s->up_armed=1;} if(s->guard){ if(!keys&&!button)s->guard=0; s->button_before=button; return a; } - if(s->stick_armed){ + if(s->stick_armed&1){ if(s->axis_x<0)held|=Q_LEFT; if(s->axis_x>0)held|=Q_RIGHT; + } + if(s->stick_armed&2){ if(s->axis_y>0)held|=Q_DOWN; ax=dx<0?-dx:dx;ay=dy<0?-dy:dy; if(s->axis_y<0){ diff --git a/src/game/input.h b/src/game/input.h index 91542f7..70b7257 100644 --- a/src/game/input.h +++ b/src/game/input.h @@ -17,7 +17,8 @@ typedef struct { Q16 previous,repeat_ms,button_ms; signed char direction,axis_x,axis_y; - Q8 guard,button_before,button_used,up_armed,stick_armed; + Q8 guard,button_before,button_used,up_armed; + Q8 stick_armed; /* bit 0: X has centered; bit 1: Y has centered */ } QInput; typedef struct { Q16 held,pressed; signed char move; Q8 repeats; } QActions; void q_input_reset(QInput *state); diff --git a/src/game/store.c b/src/game/store.c index 3fa3f16..d362f54 100644 --- a/src/game/store.c +++ b/src/game/store.c @@ -57,7 +57,7 @@ void q_preferences_default(QPreferences *p) static Q8 preferences_ok(void) { - static const Q8 maximum[15]={16,1,1,2,1,1,1,1,1,2,60,63,63,63,63}; + static Q8 maximum[15]={16,1,1,2,1,1,1,1,1,2,60,63,63,63,63}; Q8 i;for(i=0;i<15;++i)if(page[12+i]>maximum[i])return 0; if(page[22]!=50&&page[22]!=60)return 0; return 1; diff --git a/src/platform/keyboard.c b/src/platform/keyboard.c new file mode 100644 index 0000000..2de7683 --- /dev/null +++ b/src/platform/keyboard.c @@ -0,0 +1,27 @@ +/* SPDX-License-Identifier: GPL-3.0-or-later */ +#include +#include "keyboard.h" +typedef struct { Q8 probe,bit;Q16 action; } KeyBinding; +#define BIND(name,action) {KEY_PROBE_##name,KEY_BIT_##name,action} +static const KeyBinding keys[]={ + BIND(LEFT,Q_LEFT),BIND(RIGHT,Q_RIGHT),BIND(UP,Q_UP),BIND(DOWN,Q_DOWN), + BIND(ENTER,Q_CONFIRM),BIND(BREAK,Q_BACK), + BIND(A,Q_LEFT),BIND(D,Q_RIGHT),BIND(W,Q_UP),BIND(S,Q_DOWN), + BIND(Q,Q_CCW),BIND(E,Q_CW),BIND(SPACE,Q_CONFIRM),BIND(H,Q_HOLD),BIND(P,Q_PAUSE) +}; +/* Pressed joystick buttons ground the same PIA rows used by isKeyPressed. + * Suppress only those ambiguous rows, including buttons on the other port. */ +Q16 keyboard_read(Q8 buttons,Q8 mode) +{ + Q16 held=0,action;Q8 blocked=(~buttons)&15; + const KeyBinding *key,*end=keys+((mode&KEYBOARD_INITIALS)?6:sizeof(keys)/sizeof(keys[0])); + for(key=keys;key!=end;++key)if(!(key->bit&blocked)&&isKeyPressed(key->probe,key->bit)){ + action=key->action; + if(mode&KEYBOARD_PLAY){ + if(action==Q_UP)action=(mode&KEYBOARD_CLOCKWISE)?Q_CW:Q_CCW; + if(key==keys+12)action=Q_HARD; + } + held|=action; + } + return held; +} diff --git a/src/platform/keyboard.h b/src/platform/keyboard.h new file mode 100644 index 0000000..e9e947e --- /dev/null +++ b/src/platform/keyboard.h @@ -0,0 +1,9 @@ +/* SPDX-License-Identifier: GPL-3.0-or-later */ +#ifndef QUAD_KEYBOARD_H +#define QUAD_KEYBOARD_H +#include "input.h" +#define KEYBOARD_PLAY 1 +#define KEYBOARD_CLOCKWISE 2 +#define KEYBOARD_INITIALS 4 +Q16 keyboard_read(Q8 buttons,Q8 mode); +#endif diff --git a/src/platform/video.c b/src/platform/video.c index 73c297a..cca8bb1 100644 --- a/src/platform/video.c +++ b/src/platform/video.c @@ -9,11 +9,13 @@ static union {GameBuffers game;Q8 menu[512];} buffers; #define old_cells buffers.game.old_cells static Q8 menu_mode; #include "pierre_font.h" +#ifdef QUAD_PROFILE Q16 video_worst_ticks; +#endif static void palette_setup(void) { - static const Q8 colors[11]={0,48,12,7,42,60,35,52,63,1,21}; + static Q8 colors[11]={0,48,12,7,42,60,35,52,63,1,21}; Q8 i,c;rgb(); for(i=0;i<11;++i){c=colors[i];paletteRGB(i,c>>4,(c>>2)&3,c&3);} } @@ -166,7 +168,9 @@ void video_number(Q8 col,Q8 row,Q32 n) void video_game(const QGame *g,Q8 shadow,Q8 force) { Q8 cells[200],x,y; +#ifdef QUAD_PROFILE Q16 start=getTimer(),elapsed; +#endif QPiece ghost; if(force&1){ menu_mode=0;video_style(style,grid); @@ -194,7 +198,9 @@ void video_game(const QGame *g,Q8 shadow,Q8 force) video_text(23,17,g->hold_used?"USED":" "); } if(g->over)video_text(10,11,"GAME OVER"); +#ifdef QUAD_PROFILE elapsed=(Q16)(getTimer()-start);if(elapsed>video_worst_ticks)video_worst_ticks=elapsed; +#endif } static void title_piece(Q8 x,Q8 y,Q8 type,Q8 rotation) diff --git a/src/platform/video.h b/src/platform/video.h index 8679cfd..5da75bc 100644 --- a/src/platform/video.h +++ b/src/platform/video.h @@ -12,7 +12,9 @@ void video_cell(Q8 x,Q8 y,Q8 value); void video_piece(Q8 x,Q8 y,Q8 type,Q8 rotation); void video_game(const QGame *game,Q8 shadow,Q8 force); void video_title_art(void); +#ifdef QUAD_PROFILE extern Q16 video_worst_ticks; +#endif void video_number(Q8 col,Q8 row,Q32 n); Q8 *video_menu_buffer(void); #endif diff --git a/tests/include/coco.h b/tests/include/coco.h index 75f1ebb..08a1ad4 100644 --- a/tests/include/coco.h +++ b/tests/include/coco.h @@ -16,4 +16,24 @@ void width(byte columns); void setHighSpeed(byte speed); word getTimer(void); byte hset(word x,word y,byte color); + +/* Public coco.h key coordinates used by the real keyboard adapter. */ +enum { + KEY_PROBE_LEFT=0xDF, KEY_BIT_LEFT=0x08, + KEY_PROBE_RIGHT=0xBF, KEY_BIT_RIGHT=0x08, + KEY_PROBE_UP=0xF7, KEY_BIT_UP=0x08, + KEY_PROBE_DOWN=0xEF, KEY_BIT_DOWN=0x08, + KEY_PROBE_ENTER=0xFE, KEY_BIT_ENTER=0x40, + KEY_PROBE_BREAK=0xFB, KEY_BIT_BREAK=0x40, + KEY_PROBE_A=0xFD, KEY_BIT_A=0x01, + KEY_PROBE_D=0xEF, KEY_BIT_D=0x01, + KEY_PROBE_W=0x7F, KEY_BIT_W=0x04, + KEY_PROBE_S=0xEF, KEY_BIT_S=0x04, + KEY_PROBE_Q=0xFD, KEY_BIT_Q=0x04, + KEY_PROBE_E=0xDF, KEY_BIT_E=0x01, + KEY_PROBE_SPACE=0x7F, KEY_BIT_SPACE=0x08, + KEY_PROBE_H=0xFE, KEY_BIT_H=0x02, + KEY_PROBE_P=0xFE, KEY_BIT_P=0x04 +}; +byte isKeyPressed(byte probe,byte bit); #endif diff --git a/tests/input_test.c b/tests/input_test.c index 6c2912f..b059500 100644 --- a/tests/input_test.c +++ b/tests/input_test.c @@ -26,4 +26,14 @@ int main(void){QActions a; a=step(0,0,24,31,1,1);assert(a.held&Q_LEFT); a=step(0,0,25,31,1,1);assert(!(a.held&Q_LEFT)); reset();step(0,1,31,31,100,0);a=step(0,0,31,31,1,0);assert(a.pressed&Q_CONFIRM); + /* X can center/arm while an uncalibrated or deliberately held Y stays low. */ + q_input_reset(&s);step(0,0,31,0,1,1); + a=step(0,0,0,0,1,1);assert(a.move==-1&&a.repeats==1&&!(a.pressed&Q_HARD)); + a=step(0,0,0,0,200,1);assert(a.move==-1&&a.repeats==1); + a=step(0,0,63,0,1,1);assert(a.move==1&&a.repeats==1); + a=step(0,0,31,0,1,1);assert(!a.repeats); + /* Releasing a deflected joystick need not center both axes at once. */ + q_input_reset(&s);step(0,0,0,0,1,1); + a=step(0,0,63,0,1,1);assert(!a.repeats); /* no X neutral observed yet */ + step(0,0,31,0,1,1);a=step(0,0,63,0,1,1);assert(a.move==1); puts("PASS: input repeat, conflicting directions, edges, one-button timing, hysteresis, diagonal guard, disconnected-stick keyboard");return 0;} diff --git a/tests/keyboard_test.c b/tests/keyboard_test.c new file mode 100644 index 0000000..6854e05 --- /dev/null +++ b/tests/keyboard_test.c @@ -0,0 +1,64 @@ +/* SPDX-License-Identifier: GPL-3.0-or-later */ +#include +#include +#include +#include +#include "keyboard.h" +static Q8 raw_buttons=15,contact_probe,contact_bit; +/* Model the shared PIA input lines: a fire button grounds its row for EVERY + * keyboard column probe. A real key grounds it only for its selected column. */ +byte isKeyPressed(byte probe,byte bit) +{ + if((bit&15)&~raw_buttons)return 1; + return probe==contact_probe&&(bit&contact_bit)!=0; +} +static QActions poll(QInput *in,Q8 button,Q16 ms) +{ + return q_input_step(in,keyboard_read(raw_buttons,KEYBOARD_PLAY),button,31,31,31,31,1,ms,1,0); +} +int main(void) +{ + QInput in;QActions a;QGame game;QOptions options={0,Q_MODERN,0,1};Q8 pressed; + /* CoCo right fire grounds A/D/E. It must not masquerade as left/right/CW. */ + raw_buttons=14;assert(keyboard_read(raw_buttons,KEYBOARD_PLAY)==0); + for(pressed=0;pressed<4;++pressed){ + raw_buttons=(Q8)(15&~(1<