Files
Brian Holman a07c41555a Fix target joystick calibration arguments and scene transitions
Avoid a demonstrated CMOC -O2 removed-index-reload error with independent calibration and position pointers. Keep established joystick readiness across menus, stabilize shared fire/keyboard scans, and protect input sampling from IRQ interference.

Ship pristine QUADPSL04.DSK. Native right-port emulated analog/button checks pass for both directions, four lasting T-piece turns, and steering after keyboard resume. Host input/store/rules/video regressions and unchanged memory guards pass. Preserve personal score disks and record physical/128 KB/audio limits.
2026-11-11 14:26:06 -07:00

50 lines
2.9 KiB
C

/* SPDX-License-Identifier: GPL-3.0-or-later */
#include <assert.h>
#include <stdio.h>
#include "input.h"
static QInput s;
static QActions step(Q16 keys,Q8 button,Q8 x,Q8 y,Q16 ms,Q8 playing){return q_input_step(&s,keys,button,x,y,31,31,1,ms,playing,0);}
static void reset(void){q_input_reset(&s);step(0,0,31,31,0,1);}
int main(void){QActions a;
reset();a=step(Q_LEFT,0,31,31,0,1);assert(a.move==-1&&a.repeats==1);
a=step(Q_LEFT,0,31,31,199,1);assert(!a.repeats);
a=step(Q_LEFT,0,31,31,1,1);assert(a.move==-1&&a.repeats==1);
a=step(Q_LEFT,0,31,31,39,1);assert(!a.repeats);
a=step(Q_LEFT|Q_RIGHT,0,31,31,1,1);assert(a.move==-1&&a.repeats==1);
a=step(Q_RIGHT,0,31,31,1,1);assert(a.move==1&&a.repeats==1);
reset();a=step(Q_CCW,0,31,31,1,1);assert(a.pressed&Q_CCW);
a=step(Q_CCW,0,31,31,500,1);assert(!(a.pressed&Q_CCW));
reset();step(0,1,31,31,100,1);a=step(0,0,31,31,1,1);assert(a.pressed&Q_CCW);
reset();step(0,1,31,31,399,1);a=step(0,1,31,31,1,1);assert(a.pressed&Q_PAUSE);
a=step(0,0,31,31,1,1);assert(!(a.pressed&Q_CCW));
reset();a=step(0,0,31,10,1,1);assert(a.pressed&Q_HARD);
a=step(0,0,31,10,500,1);assert(!(a.pressed&Q_HARD));
step(0,0,31,31,1,1);a=step(0,0,31,10,1,1);assert(a.pressed&Q_HARD);
reset();a=step(0,0,0,10,1,1);assert(!(a.pressed&Q_HARD));
q_input_reset(&s);step(0,0,0,0,1,1);a=step(Q_LEFT,0,0,0,1,1);assert(a.move==-1);
reset();a=step(0,0,20,31,1,1);assert(a.move==-1);
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);
/* A keyboard-confirmed scene transition retains established X readiness. */
reset();step(0,0,0,31,1,0);q_input_release(&s);
a=step(Q_CONFIRM,0,0,31,1,1);assert(!a.repeats); /* held confirm guard */
a=step(0,0,0,31,1,1);assert(!a.repeats);
a=step(0,0,0,31,1,1);assert(a.move==-1&&a.repeats==1);
a=step(0,0,63,31,1,1);assert(a.move==1&&a.repeats==1);
/* Opening Actions with fire held cannot rotate on release in the next scene. */
reset();step(0,1,31,31,400,1);q_input_release(&s);
step(0,1,31,31,1,0);a=step(0,0,31,31,1,0);assert(!a.pressed);
a=step(0,0,31,31,1,0);assert(!a.pressed);
puts("PASS: input repeat, conflicting directions, edges, one-button timing, hysteresis, diagonal guard, disconnected-stick keyboard");return 0;}