From 14d05c61b67ab1a856f6b1202a2706e08e1eac6e Mon Sep 17 00:00:00 2001 From: Greg King Date: Fri, 4 Jun 2021 07:30:26 -0400 Subject: [PATCH] Made Creativision's joystick driver more efficient. --- libsrc/creativision/joy/creativision-stdjoy.s | 100 ++++++++---------- 1 file changed, 46 insertions(+), 54 deletions(-) diff --git a/libsrc/creativision/joy/creativision-stdjoy.s b/libsrc/creativision/joy/creativision-stdjoy.s index 5cf46c39f..73b0c249f 100644 --- a/libsrc/creativision/joy/creativision-stdjoy.s +++ b/libsrc/creativision/joy/creativision-stdjoy.s @@ -1,11 +1,11 @@ ; ; Standard joystick driver for the Creativision. ; -; Christian Groessler, 2017-03-08 +; 2017-03-08, Christian Groessler +; 2021-06-01, Greg King ; .include "zeropage.inc" - .include "joy-kernel.inc" .include "joy-error.inc" .include "creativision.inc" @@ -13,10 +13,12 @@ .macpack module +buttons := tmp2 + ; ------------------------------------------------------------------------ ; Header. Includes jump table - module_header _creativisionstd_joy + module_header _creativisionstd_joy ; Driver signature @@ -39,16 +41,14 @@ JOY_COUNT = 2 ; Number of joysticks we support -; Symbolic names for joystick masks (similar names like the defines in joystick.h, but not related to them) +; Symbolic names for joystick masks (similar names to the macros in joystick.h, +; with the same values as the masks in creativision.h) JOY_UP = $10 JOY_DOWN = $04 JOY_LEFT = $20 JOY_RIGHT = $08 -; ------------------------------------------------------------------------ -; Code - .code ; ------------------------------------------------------------------------ @@ -59,7 +59,7 @@ JOY_RIGHT = $08 ; INSTALL: lda #JOY_ERR_OK - ldx #0 + ldx #>$0000 ; rts ; Fall through ; ------------------------------------------------------------------------ @@ -82,14 +82,14 @@ COUNT: lda # 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. +; toggle between the straight and diagonal directions for each 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... +; etc. - txa ; move direction status into A - beq done ; center position (no bits are set), nothing to do + 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) + and #$0F ; Get rid of the "$40" bit + lsr a ; Is it "three-letter" direction (NNE, ENE, etc.)? + tax ; Create index into table + bcc special ; Yes (bit #0 was zero) - lsr a ; create index into table - tax lda dirtable,x -done: ora retval ; include "button" bits - ldx #0 +done: ora buttons ; Include button bits + ldx #>$0000 rts ; NNE, ENE, ESE, SSE, SSW, WSW, WNW, NNW -special: lsr a - tax - - lda toggler ; toggle the toggler +special: lda toggle ; Toggle the flag eor #$01 - sta toggler - bne spec_1 ; toggler is 1, use spectable_1 entry + sta toggle + bne spec_1 ; Flag is 1, use spectable_1 entry - lda spectable_0,x ; toggler is 0, use spectable_0 entry - bne done ; jump always + lda spectable_0,x + bne done ; Jump always spec_1: lda spectable_1,x - bne done ; jump always + bne done ; Jump always ; ------------------------------------------------------------------------ ; .rodata - ; a mapping table of "port values" to "cc65 values" - ; port value had been shifted one bit to the right (range 0..7) + ; A mapping table of "port values" to "cc65 values" + ; Port value had been shifted one bit to the right (range 0..7) dirtable: .byte JOY_DOWN ; S .byte JOY_DOWN | JOY_RIGHT ; SE .byte JOY_RIGHT ; E @@ -205,12 +201,12 @@ dirtable: .byte JOY_DOWN ; S .byte JOY_LEFT ; W .byte JOY_DOWN | JOY_LEFT ; SW - ; two "special" mapping tables for three-letter directions (NNE, etc.) + ; Two "special" mapping tables for three-letter directions (NNE, etc.) spectable_0: .byte JOY_DOWN ; SSW .byte JOY_DOWN ; SSE .byte JOY_RIGHT ; ESE .byte JOY_RIGHT ; ENE - .byte JOY_RIGHT ; NNE + .byte JOY_UP ; NNE .byte JOY_UP ; NNW .byte JOY_LEFT ; WNW .byte JOY_LEFT ; WSW @@ -224,14 +220,10 @@ spectable_1: .byte JOY_DOWN | JOY_LEFT ; SSW .byte JOY_UP | JOY_LEFT ; WNW .byte JOY_DOWN | JOY_LEFT ; WSW -; ------------------------------------------------------------------------ -; -bit0: .byte $01 - ; ------------------------------------------------------------------------ ; .bss -toggler: .res 1 -retval: .res 1 + +toggle: .res 1 .end