home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Brotikasten
/
BROTCD01.iso
/
c128
/
c117.d64
/
mouse.sda
/
MOUSE80.SRC
< prev
Wrap
Text File
|
1995-08-09
|
6KB
|
171 lines
;PUT"0:MOUSE80.SRC"
*=$0400
MOUSELOCY = 2000
MOUSELOCX = 2001
MOUSEFIRE = 2002
MOUSEON = 2003
;******************************************
;* CHANGE STANDARD IRQ SERVICE VECTOR *
;******************************************
STARTMOUSE LDA $0314 ;GET OLD VECTOR
LDX $0315
CMP #<MOUSESERVE ;MOUSE IRQ ALREADY ON?
BNE STARTMOUSE1 ; ...NO
CPX #>MOUSESERVE
BNE STARTMOUSE1 ; ...NO
RTS
STARTMOUSE1 SEI ;NO INTERRUPTS
STA EXITVECTOR ;SAVE OLD VECTOR
STX EXITVECTOR+1
LDA #<MOUSESERVE ;ESTABLISH NEW VECTOR
STA $0314
LDA #>MOUSESERVE
STA $0315
LDA #79 ;INITIALIZE VARIABLES
STA MOUSELOCX
LDA #24
STA MOUSELOCY
LDA #16
STA MOUSEFIRE
LDY #$CF
LDX #$0F
STY LOCATION
STY OLDLOCATION
STX LOCATION+1
STX OLDLOCATION+1
LDA #2
STA DELAYCOUNT
CLI ;INTERRUPTS OKAY
RTS
;
;******************************************
;* MOUSE IRQ SERVICE *
;******************************************
MOUSESERVE LDA $A2 ;READ JIFFY CLOCK LOW
AND #1 ;UPDATE EVERY OTHER TICK
BEQ CHECKSWITCHES
UPDATEMOUSE LDA MOUSEON ;MOUSE ENABLED?
BEQ MOUSEEXIT1 ; ...NO
LDA LOCATION ;HAS LOCATION CHANGED?
CMP OLDLOCATION
BNE LOCCHANGE ; ...YES
LDA LOCATION+1
CMP OLDLOCATION+1
BNE LOCCHANGE ; ...YES
MOUSEEXIT1 JMP (EXITVECTOR)
LOCCHANGE SEI ;NO INTERRUPTS DURING
LDY OLDLOCATION ; UPDATE
LDX OLDLOCATION+1
JSR READVDCRAM ;GET ATTRIBUTE
AND #191 ;UN-REVERSE IT
LDY OLDLOCATION
LDX OLDLOCATION+1
JSR WRITEVDCRAM ; AND WRITE IT BACK
LDY LOCATION ;REVERSE NEW LOCATION
LDX LOCATION+1
JSR READVDCRAM ; READ OLD ATTRIBUTE
STA OLDATTRIBUTE ; SAVE OLD ATTRIBUTE
ORA #64 ; SET REVERSE BIT
LDY LOCATION ; AND PUT IT BACK
LDX LOCATION+1
JSR WRITEVDCRAM
LDA LOCATION
STA OLDLOCATION
LDA LOCATION+1
STA OLDLOCATION+1
CLI
MOUSEEXIT2 JMP (EXITVECTOR)
CHECKSWITCHES LDX $DC00 ;CHECK JOYSTICK #2 SW'S
TXA
AND #16 ;FIRE BUTTON FIRST
BNE CHECKUP ; NOT PRESSED
STA MOUSEFIRE
CHECKUP TXA
AND #1
BNE CHECKDOWN ; NOT UP
LDA MOUSELOCY ;ALREADY AT TOP?
BEQ CHECKLEFT ; ...YES
DEC DELAYCOUNT ; ...NO, DELAY DONE?
BNE CHECKLEFT ; ....NO, CHECK LEFT SW
LDA #2 ; ....YES, RE-INIT
STA DELAYCOUNT ; VERTICAL DELAY
DEC MOUSELOCY ;DECREMENT MOUSE Y
LDA LOCATION ;DECREASE MOUSE ATTRIBUTE
SEC ; ADDRESS BY 80
SBC #80
STA LOCATION
BCS CHECKLEFT
DEC LOCATION+1
BCC CHECKLEFT
CHECKDOWN TXA
AND #2
BNE CHECKLEFT ; NOT DOWN
LDA MOUSELOCY ;ALREADY AT BOTTOM?
CMP #24
BEQ CHECKLEFT ; ...YES
DEC DELAYCOUNT ; ...NO, DELAY DONE?
BNE CHECKLEFT ; ....NO, CHECK LEFT SW
LDA #2 ; ....YES, RE-INIT
STA DELAYCOUNT ; VERTICAL DELAY
INC MOUSELOCY ;INCREMENT MOUSE Y
LDA LOCATION ;INCREASE MOUSE ATTRIBUTE
CLC ; ADDRESS BY 80
ADC #80
STA LOCATION
BCC CHECKLEFT
INC LOCATION+1
CHECKLEFT TXA
AND #4
BNE CHECKRIGHT ; NOT LEFT
LDA MOUSELOCX ;ALREADY AT LEFT EDGE?
BEQ MOUSEEXIT3 ; ...YES
DEC MOUSELOCX ;DECREMENT MOUSE X
LDA LOCATION ; AND MOUSE ATTRIBUTE
BNE MOVELEFTNOHI ; ADDRESS
DEC LOCATION+1
MOVELEFTNOHI DEC LOCATION
MOUSEEXIT3 JMP (EXITVECTOR)
CHECKRIGHT TXA
AND #8
BNE MOUSEEXIT3 ; NOT RIGHT EITHER
LDA MOUSELOCX ;ALREADY AT RIGHT EDGE?
CMP #79
BEQ MOUSEEXIT3 ; ...YES
INC MOUSELOCX ;INCREMENT MOUSE X
INC LOCATION ;INCREMENT MOUSE ATTRIBUTE
BNE MOUSEEXIT3 ; ADDRESS
INC LOCATION+1
BNE MOUSEEXIT3
READVDCRAM TXA ;SET ADDRESS HI BYTE IN
LDX #18 ; VDC REGISTER 18
JSR WRITEVDCREG
TYA ;SET ADDRESS LO BYTE IN
INX ; VDC REGISTER 19
JSR WRITEVDCREG
READVDCLOC LDX #31 ;READ DATA REGISTER
READVDCREG STX $D600 ; ...WRITE REG NUMBER
READVDCREG1 BIT $D600 ; ...AND WAIT FOR IT TO
BPL READVDCREG1 ; ...BE ACCEPTED
LDA $D601 ;READ DREG
RTS
WRITEVDCRAM PHA ;HOLD BYTE TO WRITE
TXA ;SET ADDRESS HI BYTE IN
LDX #18 ; VDC REGISTER 18
JSR WRITEVDCREG
TYA ;SET ADDRESS LO BYTE IN
INX ; VDC REGISTER 19
JSR WRITEVDCREG
PLA
WRITEVDCLOC LDX #31 ;WRITE DATA REGISTER
WRITEVDCREG STX $D600 ; ...WRITE REG NUMBER
WRITEVDCREG1 BIT $D600 ; ...AND WAIT FOR IT TO
BPL WRITEVDCREG1 ; ...BE ACCEPTED
STA $D601
RTS
EXITVECTOR .BYT 0,0
LOCATION .BYT 0,0
OLDLOCATION .BYT 0,0
OLDATTRIBUTE .BYT 0
DELAYCOUNT .BYT 0
.END