Original old kempston joystick interfaces for ZX Spectrum don't use data lines D7-D5. IN 31 can return on this hardware undefined values ( floating bus / attribute / pull-up / zero values )
Modern joystick interfaces return always value 0 on D7-D5 and is possible detect joy interface if IN 31 return:
D7 must contain 0 (D4-D6 can be used for three joy buttons) - 0xxxxxxx
D3 and D2 can't contain values 1 - xxxx11xx
D1 and D0 can't contain values 1 - xxxxxx11
Joystick port 31 (for joy detect only) must be read after interrupt - HALT+IN A,(31) for return corect data value (port 31 can return screen attribute value if joy interface absent)
complette test:
EI
HALT
LD E,0
LD BC,#001F
IN B,(C)
LD A,B
RLCA
RET C
LD A,B
AND 3
CP 3
RET Z
LD A,B
RRCA
RRCA
AND 3
CP 3
RET Z
LD E,1
RET
;this code detect joystick interface and return E=1 if joy connect / E=0 if joy absent






Ответить с цитированием