1
0
mirror of https://github.com/RevCurtisP/C02.git synced 2024-11-21 10:32:08 +00:00

Updated x16 mouse module

This commit is contained in:
Curtis F Kaylor 2020-03-29 14:56:57 -04:00
parent 31622c3480
commit 00ab9ae53b
3 changed files with 220 additions and 0 deletions

53
include/x16/mouse.a02 Normal file
View File

@ -0,0 +1,53 @@
;Mouse Control Assembly Language Routines for Commander x16 computer
SUBROUTINE _MOUSE
;Mouse Mode Constants for MCNFG Routine
MHIDE EQU $00 ;Hide Mouse
MSHOW EQU $01 ;Show Mouse
MCSTM EQU $FF ;Show Mouse - Custom Sprite
;Mouse Button Bitmasks
MBLEFT EQU $01 ;Left Mouse Button
MBMIDL EQU $04 ;Middle Mouse Button
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)
;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
RTS
;mread() - Read Mouse
;Sets: MOUSEX, MOUSEY, MOUSEB
;Affects: X
;Returns: A = Result Code: $00 = Success
MREAD: LDX #MOUSEX ;Set Data Address
JSR $FF6B ;Execute Kernal mouse_get Routine
STA MOUSEB ;Store Mouse Button Status
LDA #0 ;Return Success
RTS
;mscan() - Scan Mouse
;Retrieves mouse state for subsequent mread()
;This is called during the default interrupt
;handler so should only be called if the interrupt
;routine is entirey replaced.
MSCAN EQU $FF71 ;Aliased to Kernal mouse_scan routine

72
include/x16/mouse.h02 Normal file
View File

@ -0,0 +1,72 @@
/* Mouse Control Functions *
* for Commander X16 Computer */
/* Mouse Mode constants for mcnfg() */
#define MHIDE $00 //Hide Mouse
#define MSHOW $01 //Show Mouse - Default Cursor
#define MCSTM $FF //Show Mouse - Custom Cursor
/* Mouse Button bitmasks for mouseb *
* 0 means button not supported */
#define MBLEFT $01 //Left Mouse Button
#define MBMIDL $03 //Middle Mouse Button
#define MBRGHT $02 //Right Mouse Button
/* Mouse Scale Factor constants for mcnfgs() */
#define MSNONE $00 //Do Not Change Resolution
#define MSLOW $01 //Low Resolution (320x240)
#define MSHIGH $02 //High Resolution (640x480)
/* Mouse Status Variables *
* Set by mread() */
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 *
* #MSHOW - Show Mouse *
* #MCSTM - Show (Custom) *
* Returns: $00 - Success *
* $FF - Mouse Not Present */
char mcnfg();
/* Configure Mouse and Select Scale *
* Args: char mode - Mouse Mode *
* #MHIDE - Hide Mouse *
* #MSHOW - Show Mouse *
* #MCSTM - Show (Custom) *
* char scale - Scale Factor *
* #MSNONE - No Change *
* #MSLOW - 320x200 *
* #MSHIGH - 640x480 *
* Returns: $00 - Success *
* $FF - Mouse Not Present */
char mcnfgs();
/* Read Mouse *
* Sets: mousex, mousey, mouseb *
* Returns: $00 - Success *
* $FF - Mouse Not Present */
char mread();
/* Scan Mouse *
* Retrieves mouse state for mread() *
* Does not need to be called unless *
* the entire default interrupt *
* routine is replaced. */
char mscan();

95
x16/mousetst.c02 Normal file
View File

@ -0,0 +1,95 @@
/********************************
* MOUSETST - Test mouse module *
* for Commander X16 computer *
********************************/
//use -h option on command line
#include <screen.h02>
#include <mouse.h02>
alias char rambnk = $9F61; //RAM Bank Select Register
char i,j,r;
char aa,yy,xx;
int yx;
char key; //Last Keypress
char scale; //Mouse Scaling Factor
void prtbtn(aa,yy,xx) {
putchr(' ');
if (aa & yy) xx = '*';
putchr(xx);
}
void prtbyt(aa) {
putchr('$');
prbyte(aa);
}
void prtwrd(.,yy,xx) {
putchr('$');
prbyte(yy);
prbyte(xx);
}
/* Print Kernal Mouse Status */
void prtsts() {
putstr("MSTS: "); prtbyt(mousev.msts);
if (mousev.msts:-) putstr(" ON"); else putstr(" OFF");
putstr(" SCALE: "); prhex(mousev.msts);
}
/* Print Kernal Mouse Variables */
void prtkmv() {
push rambnk; //Save RAM Bank
rambnk = 0; //Set RAM Bank to Kernal Variables
newlin(); //Skip a Line
prtsts(); newlin();
putstr("XMIN: "); prtwrd(mousev.xmin); newlin();
putstr("XMAX: "); prtwrd(mousev.xmax); newlin();
putstr("XMIN: "); prtwrd(mousev.ymin); newlin();
putstr("XMAX: "); prtwrd(mousev.ymax); newlin();
putstr("XPOS: "); prtwrd(mousev.xpos); newlin();
putstr("XPOS: "); prtwrd(mousev.xpos); newlin();
putstr("BTNS: "); prtwrd(mousev.btns); newlin();
pop rambnk; //Retore RAM Bank
}
void error() {
putstr();
newlin();
goto exit;
}
main:
scale = #MSLOW; //Set to mcnfg() default
//Enable Mouse
if (mcnfg(#MSHOW)) error("ERROR ENABLING MOUSE");
while() {
key = getkey();
if (key == #ESCKEY) break;
if (key == ' ') {
scale = (scale == #MSLOW) ? #MSHIGH : #MSLOW;
mcnfg(#MHIDE); //Disable, then Enable with
mcnfgs(#MSHOW, scale); //New Scaling
}
if (mread()) error("ERROR READING MOUSE");
crsrhm();
putstr("SCALE: "); prhex(scale); newlin();
putstr("MOUSEX: "); prtwrd(mousex); newlin();
putstr("MOUSEY: "); prtwrd(mousey); newlin();
putstr("MOUSEB: "); prtbyt(mouseb);
prtbtn(mouseb, #MBLEFT, 'L');
prtbtn(mouseb, #MBMIDL, 'M');
prtbtn(mouseb, #MBRGHT, 'R'); newlin();
//prtkmv(); //Print Kernal Mouse Variables
}
mcnfg(#MHIDE); //Hide Mouse
goto exit;