### [Hardware] Analog joypad

Posted:

**Sat Mar 19, 2016 7:03 pm**I think I found the routines that detects and read an analog joypad.

According to Gamesx wiki, only 4 games (all by NEC Avenue) are supporting analogue controllers:

I attached 2 etripator configuration files for Operation Wolf and Afterburner II.

The code in both games are nearly identical.
The

Here's the code for Operation Wolf.

According to Gamesx wiki, only 4 games (all by NEC Avenue) are supporting analogue controllers:

- Afterburner II
- Forgotten Worlds
- Operation Wolf
- Outrun

I attached 2 etripator configuration files for Operation Wolf and Afterburner II.

The code in both games are nearly identical.

Code: Select all

```
X = 0
joyport = 0
delay
for (count=0; count<5; count++)
{ joyport = 2
delay
for(Y=0; Y<256; Y++)
{ A = joyport
if( (A & 3) == 0 )
break;
}
if( Y == 256 )
NOT FOUND
joyport = 3
delay
A = joyport
Y = A & 0x0F
out[X++] = tab[Y]
joyport = 2
delay
for(Y=0; Y<256; Y++)
{ A = joyport
if( (A & 3) == 1)
break;
}
if( Y == 256)
NOT FOUND
joyport = 3
delay
A = joyport
Y = A & 0x0F
out[X++] = tab[Y]
}
```

**tab**contains the following values:Code: Select all

```
tab:
.db $00, $01, $08, $09, $02, $03, $0a, $0b
.db $04, $05, $0c, $0d, $06, $07, $0e, $0f
```

**out**array contains only 4 bit values. They are therefore reassembled. Note that Operation Wolf and Afterburner II seems to do it differently.Here's the code for Operation Wolf.

Code: Select all

```
v30 = (out[0] << 4) | out[1]
Y = (out[2] << 4) | out[6]
v31 = unknown_array[Y]
Y = (out[3] << 4) | out[7]
v32 = another_unknown_array[Y]
v33 = (out[4] << 4) | out[8]
v34 = (out[5] << 4) | out[9]
```

**Edit:****v31**contains the vertical axis value.**v32**contains the horizontal axis value.

**v30**may contains some button values (at least START and SELECT). Indeed, the value is used to test the RESET combo in Operation Wolf.Code: Select all

```
l_f6cd:
JSR joy_analogue
LDA $2540
STA $2545
LDA $2a30
AND #$03
ASL A
ASL A
STA <$1d
LDA $2a30
AND #$c0
CLC
ROL A
ROL A
STA <$1e
ROL A
ROL A
AND #$02
ORA <$1e
ORA <$1d
EOR #$ff
AND #$0f
STA $2540
EOR $2545
AND $2540
STA $254a
LDA <$47
AND $f77c
BEQ lf77b_01
LDA $254a
CMP #$04
BNE lf77b_01
LDA $2540
CMP #$0c
BNE lf77b_01
JMP le000_01 ; RESET vector
; the "standard" joypad routine comes next...
lf77b_01:
RTS
```