1
0
mirror of https://github.com/RevCurtisP/C02.git synced 2024-11-22 01:31:33 +00:00

Updated Commander X16 modules joystk and mouse

This commit is contained in:
Curtis F Kaylor 2020-04-27 12:45:06 -04:00
parent 1986abf96a
commit fb2e898922
4 changed files with 106 additions and 103 deletions

View File

@ -1,29 +1,15 @@
;Joystick Constants and Functions for Commander X16 Computer
;NOTE: As of R35, joystick_scan() has not been added to the
;vsync() interrupt routine. This will be in R36, so development
;on this module is currently on hold
SUBR _JOYSTK
JYSTKS EQU 2 ;Number of Joysticks
.GETJOY EQU $FF06 ;Kernal GETJOY Routine
.JYDATA EQU $02BC ;Joystick 0 Data
;JOY1 JOY2
;$02BC $02BF | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
; NES | A | B |SEL|STA|UP |DN |LT |RT |
; SNES | B | Y |SEL|STA|UP |DN |LT |RT |
;
;$02BD $20C0 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
; NES | 0 | 0 | 0 | 0 | 0 | 0 | 0 |KBD|
; SNES | A | X | L | R | 1 | 1 | 1 | 1 |
;
;$02BE $02C1 $00 = joystick present
; $FF = joystick not present
;The Joystick Button is mapped to
;A,B on the NES Controller and
;A,B,X,Y on the SNES Controller
;Select and Start are Ignored as Bits 4 and 5 of the return value
;are always 0 because returning $FF means no controller found
JOY0 EQU $A031 ;Joystick 0 Status
JOY1 EQU $A034 ;Joystick 1 Status
;Joystick Bit Masks
JOYUP EQU $08 ;Up
@ -54,75 +40,88 @@ JOYSNS EQU $02 ;SNS Controller
; TEMP2 - Extended Result (Buttons)
;Destroys: TEMP3
;Returns: A = Joystick Status (Joystick Bit Masks
; The Joystick Button is mapped to
; A,B on the NES Controller and
; A,B,X,Y on the SNES Controller
; Y = Extended Status (Extended Bit Masks)
; Used with Extended Bitmasks to check
; A,B,X,Y,Select, Start, Left and Right
; X = Controller Type (0=Keyboard, 1=NES, 2=SNES)
JOYSTK: CMP #JYSTKS ;If Invalid Joystick Number
BCS .JOYSTE ; Return ERROR
STA TEMP0 ;Save Joystick Number
BYTE $FF
JOYSTL: WAI ;Wait for Interrupt
LDA $9F27 ; Check Vera Interrupt Register
AND #$01 ; If Not Vera Interrupt
BEQ JOYSTL ; Loop
JSR .GETJOY ;Call Kernal GETJOY Routine
LDA TEMP0 ;Retrieve Joystick Number
ASL ;Multiply it by 3
ADC TEMP0 ;(Assumes Number<128)
TAX ;and Copy to X-Register
LDA .JYDATA+2,X ;If Controller Not Present
BNE .JOYSTE ; Return ERROR
LDA .JYDATA,X ;Get Base Status
EOR #$FF ;Invert Bits
JSR .JOYEXT ;Build Extended Results
AND #$CF ;Mask off Select and Start
.JOYSTX RTS
;Return Error
.JOYSTE LDA #$FF
RTS
;Build Extended Result
.JOYEXT STA TEMP0 ;Save Controller Status
JSR JOYGET ;Read Joystick State
EOR #$FF ;Invert Controller Status
STA TEMP0 ;and Save in TEMP0
STX TEMP1 ;Save Extended Status in TEMP1
TYA ;If Controller Not Present
BNE .JOYSTF ; Return $FF, $FF, $FF
;JOYEXT ;Process Extended Bits
STZ TEMP3 ;Clear Button Mask
LDA .JYDATA+1,X ;Get Extended Status
LDA TEMP1 ;Get Extended Status
BIT #$0E ;Check Bits 1 - 3
BNE .JOYEXS ;If NES/Keyboard
STA TEMP1 ; Save for Debugging
EOR #$01 ; Invert Extended Bits
BNE .JOYSNS ;If NES/Keyboard
;JOYNES ; Process NES Buttons
EOR #$01 ; Invert Extended Bit 0
TAX ; and Copy to X
LDA TEMP0 ; Get Controller Status
AND #$F0 ; Isolate Bits 4-7
TAY ; and Copy Back to Y
BRA .JOYEXX ;Else
.JOYEXS JSR .JOYSNS ; Process SNES Buttons
.JOYEXX LDA TEMP0 ;Restore Controller Status
ORA TEMP3 ;Combine Buttons
BRA .JOYSTX ;Else
.JOYSNS ; Process SNES Buttons
LDX #2 ; Set Controller Type to 2
LDA TEMP1 ; and Save Result
AND #$C0 ; Isolate SNES A,X Buttons
STA TEMP3 ; and Save in Button Mask
LDA TEMP1 ; Retrieve Extended Buttons
AND #$30 ; Isolate L and R
ASL ; and Shift to Bits 2 and 3
ASL
BIT TEMP1 ; Get Ext Status High Bits
BCC +2 ; If Extended Bit 7 was Set
ORA #$80 ; Set Buttons Bit 7 (A)
BVC +2 ; If Extended Bit 6 was Set
ORA #$20 ; Set Buttons Bit 1 (X)
STA TEMP2 ; Save Buttons A,X,L,R
LDA TEMP0 ; Retrieve Controller Status
AND #$30 ; Isolate Select and Start
ORA TEMP2 ; Combine with A,X,L,R
BIT TEMP2 ; Get Status High Bits
BCC +2 ; If Status Bit 7 was Set
ORA #$40 ; Set Buttons Bit 6 (B)
BVC +2 ; If Status Bit 6 was Set
ORA #$01 ; Set Buttons Bit 0 (Y)
STA TEMP2 ; Save Buttons in TEMP2
TAY ; and Copy to Y
.JOYSTX ;Build Joystick Status
LDA TEMP0 ; Restore Controller Status
ORA TEMP3 ; Combine Buttons
AND #$CF ; Mask off Select and Start
RTS
.JOYSTE ;Return Error
LDA #$FF ;Return $FF, $FF, $FF
TAY
.JOYSTF TAX ;A, Y already $FF
RTS
;Process SNES Buttons
.JOYSNS LDX #2 ;Set Controller Type to 2
EOR #$FF ;Invert Extended Bits
STA TEMP1 ; and Save Result
AND #$C0 ;Isolate SNES A,X Buttons
STA TEMP3 ;and Save in Button Mask
LDA TEMP1 ;Retrieve Extended Buttons
AND #$30 ;Isolate L and R
ASL ;and Shift to Bits 2 and 3
ASL
BIT TEMP1 ;Get Ext Status High Bits
BCC +2 ;If Extended Bit 7 was Set
ORA #$80 ; Set Buttons Bit 7 (A)
BVC +2 ;If Extended Bit 6 was Set
ORA #$20 ; Set Buttons Bit 1 (X)
STA TEMP2 ;Save Buttons A,X,L,R
LDA TEMP0 ;Retrieve Controller Status
AND #$30 ;Isolate Select and Start
ORA TEMP2 ;Combine with A,X,L,R
BIT TEMP2 ;Get Status High Bits
BCC +2 ;If Status Bit 7 was Set
ORA #$40 ; Set Buttons Bit 6 (B)
BVC +2 ;If Status Bit 6 was Set
ORA #$01 ; Set Buttons Nit 0 (Y)
STA TEMP2 ;Save Buttons in TEMP2
TAY ; and Copy to Y
RTS
;joyscn() - Queries the Joysticks and Saves their State
;Note: The default interrupt handler already takes care
;of this, so this routine should only be called if the
;interrupt handler has been completely replaced.
JOYSCN EQU $FF53 ;Kernal joystick_scan Routine
;joyget(j) - Get State of Joystick Number j
;Args: A = Joystick Number (0 or 1)
;Returns: A = Joystick Status Bits
; | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
; NES | A | B |SEL|STA|UP |DN |LT |RT |
; SNES | B | Y |SEL|STA|UP |DN |LT |RT |
; X = Joystick Extended Status Bits
; | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
; NES | 0 | 0 | 0 | 0 | 0 | 0 | 0 |KBD|
; SNES | A | X | L | R | 1 | 1 | 1 | 1 |
; Y = Joystick Present
; $00 = Joystick Present
; $FF = Joystick Not Present
;Note: Status Bits will be 0 if Pressed, 1 if Not
JOYGET EQU $FF56 ;Kernal joystick_get Routine

View File

@ -1,3 +1,5 @@
/* Module Development on Hold until R36 */
/* Joystick Functions for Commander X-16 Computer *
* Supports Keyboard, NES, and SNES Controllers *
* A and B on Keyboard and SNES Controller and *
@ -34,10 +36,28 @@
#define JOYNES $01 //NES Controller
#define JOYSNS $02 //SNS Controller
struct joysts {char btnsts, extsts, status;};
struct joysts joy0, joy1;
/* Read Joystick Status *
* Args: j = Joystick Number *
* Returns: char j = Joystick Status *
* $FF = Not Present *
* char b = Extended Status *
* char c = Controller Type */
* char x = Extended Status *
* char t = Controller Type */
char joystk();
/* Get Joystick Raw Status *
* X16 Specific System Routine *
* Args: j = Joystick Number *
* Returns: char j = Joystick Raw Status Bits *
* char x = Extended Raw Status Bits *
* char t = Joystick Status *
* $FF = Not Present */
char joyget();
/* Query Joysticks and Save State *
* X16 Specific System Routine *
* Called by the default interrupt handler */
void joyscn();

View File

@ -15,24 +15,21 @@ MBRGHT EQU $02 ;Right Mouse Button
;Mouse Scaling Constants
;Specific to the X16
MSNONE EQU $00 ;Do Not Change Resolution
MSLOW EQU $02 ;Low Resolution (320x240)
MSHIGH EQU $01 ;High Resolution (640x480)
MSLOW EQU $01 ;Low Resolution (320x240)
MSHIGH EQU $02 ;High Resolution (640x480)
;Mouse Status Variables
MOUSEX EQU $02 ;Mouse X Position (ABI Register R0)
MOUSEY EQU $04 ;Mouse Y Position (ABI Register R1)
MOUSEB EQU $06 ;Mouse Button Status (ABI Register R2L)
;Kernal Internal Mouse Variables
MOUSEV EQU $A021 ;Valid for Kernal Version R37
;mcnfg(mode) - Configure Mouse
;Args: A = Mode
;Affects: X,Y
;Returns: A = Result Code: $00 = Success
MCNFG: LDX #MSLOW ;Set Scale for 320x240 Screen
MCNFGS: JSR $FF68 ;Kernal mouse_config Routine
LDA #0 ;Return Success
MCNFG: LDX #MSLOW ;Set Scale for 320x240 Screen
MCNFGS: JSR $FF68 ;Kernal mouse_config Routine
LDA #0 ;Return Success
RTS
;mread() - Read Mouse

View File

@ -23,19 +23,6 @@ int mousex; //Mouse X Position
int mousey; //Mouse Y Position
char mouseb; //Mouse Button Status
/* Kernal Internal Mouse Variables */
struct mouset {
char msts; //$80=on; 1/2: scale
int xmin; //min x coordinate
int xmax; //max x coordinate
int ymin; //min y coordinate
int ymax; //max y coordinate
int xpos; //x coordinate
int ypos; //y coordinate
char btns; //buttons (1: left, 2: right, 4: third)
};
struct mouset mousev;
/* Configure Mouse *
* Args: char mode - Mouse Mode *
* #MHIDE - Hide Mouse *