-cnv_2: txa
- ; tested with https://sourceforge.net/projects/creativisionemulator
- ; $49 - %01001001 - up
- ; $41 - %01000001 - down
- ; $4D - %01001101 - left
- ; $45 - %01000101 - right
- ;
- ; are these correct? "Second book of programs for the Dick Smith Wizard" pg. 85 says something different
- ; ignored for now...
- ; $85 - %10000101 - up + right
- ; $8D - %10001101 - down + left
- ; $89 - %10001001 - up + left
- ; $85 - %10000101 - down + right (emulator bug?)
-
- bit testbit ; bit #0 set?
- beq done ; no, no direction
-
- and #%00001100 ; mask out other bits
- lsr a
- lsr a
- tax
- lda #%00000100 ; init bitmask
-loop: dex
- bmi done2
- asl a
- bne loop
-
-done2: ora retval
- rts
-
-done: lda retval
- rts
+; CV has a 16-direction joystick
+;
+; port values: (compass points)
+; N - $49 - %01001001
+; NNE - $48 - %01001000
+; NE - $47 - %01000111
+; ENE - $46 - %01000110
+; E - $45 - %01000101
+; ESE - $44 - %01000100
+; SE - $43 - %01000011
+; SSE - $42 - %01000010
+; S - $41 - %01000001
+; SSW - $40 - %01000000
+; SW - $4F - %01001111
+; WSW - $4E - %01001110
+; W - $4D - %01001101
+; WNW - $4C - %01001100
+; NW - $4B - %01001011
+; NNW - $4A - %01001010
+; center - $00 - %00000000
+;
+; mapping to cc65 definitions (4-direction joystick with 8 possible directions thru combinations)
+; N, E, S, W -> JOY_UP, JOY_RIGHT, JOY_DOWN, JOY_LEFT
+; NE, SE, SW, NW -> (JOY_UP | JOY_RIGHT), (JOY_DOWN | JOY_RIGHT), (JOY_DOWN | JOY_LEFT), (JOY_UP | JOY_LEFT)
+; NNE, ENE, ESE, SSE, SSW, WSW, WNW, NNW:
+; toggle between straight and diagonal direction for every call, e.g.
+; NNE:
+; call to READJOY: return JOY_UP | JOY_RIGHT
+; call to READJOY: return JOY_UP
+; call to READJOY: return JOY_UP | JOY_RIGHT
+; call to READJOY: return JOY_UP
+; call to READJOY: return JOY_UP | JOY_RIGHT
+; etc...
+
+ txa ; move direction status into A
+ beq done ; center position (no bits are set), nothing to do
+
+ and #$0F ; get rid of the "$40" bit
+ bit bit0 ; is it a "three letter" direction (NNE, ENE, etc.)?
+ beq special ; yes (bit #0 is zero)
+
+ lsr a ; create index into table
+ tax
+ lda dirtable,x
+done: ora retval ; include "button" bits
+ ldx #0
+ rts
+
+; NNE, ENE, ESE, SSE, SSW, WSW, WNW, NNW
+
+special: lsr a
+ tax
+
+ lda toggler ; toggle the toggler
+ eor #$01
+ sta toggler
+ bne spec_1 ; toggler is 1, use spectable_1 entry
+
+ lda spectable_0,x ; toggler is 0, use spectable_0 entry
+ bne done ; jump always
+
+spec_1: lda spectable_1,x
+ bne done ; jump always