base:fast_joystick_handling
Differences
This shows you the differences between two versions of the page.
base:fast_joystick_handling [2023-08-21 09:05] – created tww | base:fast_joystick_handling [2023-08-30 07:33] (current) – tww | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== Fast Joystick Handling ====== | ====== Fast Joystick Handling ====== | ||
+ | |||
+ | ==== Signed Movement ==== | ||
Returnes signed movement in A & Y, and CARRY gives FIRE state (SET = No Fire, CLEAR = Fire). | Returnes signed movement in A & Y, and CARRY gives FIRE state (SET = No Fire, CLEAR = Fire). | ||
Line 20: | Line 22: | ||
</ | </ | ||
- | The tabled can be reduced by 32 bytes by sacrificing 3 bytes and 4 cycles in the code to mask out the Fire bit (Bit #4). | + | The same routine, only smaller footprint at the cost of 4 cycles: |
+ | |||
+ | < | ||
+ | Joystick: | ||
+ | lda CIA1.DataPortB | ||
+ | cmp # | ||
+ | and # | ||
+ | tax | ||
+ | ldy ytab - 5,x | ||
+ | lda xtab - 5,x | ||
+ | rts | ||
+ | ytab: | ||
+ | .byte $01, $ff, $00, $00, $01, $ff, $00, $00, $01, $ff, $00 | ||
+ | xtab: | ||
+ | .byte $01, $01, $01, $00, $ff, $ff, $ff, $00, $00, $00, $00 | ||
+ | </ | ||
+ | |||
+ | Having the X-Movement returned | ||
+ | |||
+ | You could also change | ||
+ | |||
+ | The above routines are the **fastest**, | ||
+ | |||
+ | Above routines by JAS/CTR. | ||
+ | |||
+ | |||
+ | ==== Explicit direction handling ==== | ||
+ | |||
+ | If you need explicit direction support | ||
+ | |||
+ | < | ||
+ | // | ||
+ | // Explicit direction joy-routine by TWW/CTR | ||
+ | // | ||
+ | Joystick: | ||
+ | lda CIA1.DataPortB | ||
+ | cmp #%11110000 | ||
+ | and # | ||
+ | tax | ||
+ | lda BranchOffsetTable - 5,x | ||
+ | sta SMC_BranchOffset | ||
+ | beq SMC_BranchOffset: | ||
+ | NoMove: | ||
+ | rts | ||
+ | // | ||
+ | NE: jmp Sub_JoystickNorthEast | ||
+ | E: jmp Sub_JoystickEast | ||
+ | NW: jmp Sub_JoystickNorthWest | ||
+ | N: jmp Sub_JoystickNorth | ||
+ | SE: jmp Sub_JoystickSouthEast | ||
+ | S: jmp Sub_JoystickSouth | ||
+ | SW: jmp Sub_JoystickSouthWest | ||
+ | W: jmp Sub_JoystickWest | ||
+ | // | ||
+ | BranchOffsetTable: | ||
+ | .byte SE - NoMove, NE - NoMove, E - NoMove, $00 | ||
+ | .byte SW - NoMove, NW - NoMove, W - NoMove, $00 | ||
+ | .byte S - NoMove, | ||
+ | </ | ||
+ | |||
+ | The table may be expanded to include fire and subsequent routines as well, but the CARRY will be set/reset when the subroutines are called due to the CMP. Anyway here is how it looks with explicit fire included as well: | ||
+ | |||
+ | < | ||
+ | Joystick: | ||
+ | ldx CIA1.DataPortB | ||
+ | lda BranchTable - $e5,x | ||
+ | sta SMC_Branch | ||
+ | beq SMC_Branch: * | ||
+ | NoMove: | ||
+ | rts | ||
+ | NE: jmp UpRight | ||
+ | E: jmp Right | ||
+ | NW: jmp UpLeft | ||
+ | N: jmp Up | ||
+ | SE: jmp DownRight | ||
+ | S: jmp Down | ||
+ | SW: jmp DownLeft | ||
+ | W: jmp Left | ||
+ | FNE:jmp FireUpRight | ||
+ | FE: jmp FireRight | ||
+ | FNW:jmp FireUpLeft | ||
+ | FN: jmp FireUp | ||
+ | FSE:jmp FireDownRight | ||
+ | FS: jmp FireDown | ||
+ | FSW:jmp FireDownLeft | ||
+ | FW: jmp FireLeft | ||
+ | |||
+ | BranchTable: | ||
+ | .byte SE - NoMove, | ||
+ | .byte SW - NoMove, | ||
+ | .byte S - NoMove, | ||
+ | .byte FSE - NoMove, FNE - NoMove, FE - NoMove, $00 | ||
+ | .byte FSW - NoMove, FNW - NoMove, FW - NoMove, $00 | ||
+ | .byte FS - NoMove, | ||
+ | </ | ||
+ | |||
+ | You could also skipp the jmp if the direction handling subroutines are within branch range (just update the table accordingly). |
base/fast_joystick_handling.1692601544.txt.gz · Last modified: 2023-08-21 09:05 by tww