; event.asm, version 1.2 ; Written by Stuart Brady ; This is public domain software ; Changelog: ; ; event (1.2) ; ; * Renamed to "event". ; * Added mouse support. ; ; -- Stuart Brady 2005-08-07 22:09:14 BST ; ; keyb (1.1) ; ; * Minor cleanups. ; ; -- Stuart Brady 2005-08-05 19:49:28 BST ; ; keyb (1.0) ; ; * Initial Release. ; ; -- Stuart Brady 2005-08-03 23:37:14 BST LD A,#06 ; switch to stream 6 CALL jsetstrm LD BC,8 ; clear the lastscan buffer LD HL,lastscan LD A,#FF LD (HL),A LD D,H LD E,L INC DE LDIR DI CALL mreset LD HL,butstat ; clear the mouse button status LD (HL),0 EI LD HL,lastbut ; clear the last button status LD (HL),0 mainloop:CALL scan ; contiuously check the keyboard CALL test CALL mouse ; and check the mouse LD B,20 ; a delay to compensate for key bounce delay1:LD C,B LD B,0 delay2:DJNZ delay2 LD B,C DJNZ delay1 JR mainloop scan:LD HL,scanbuf ; output buffer LD B,%11111110 ; first scan line scanloop:LD C,hikey ; high-order 3 bits of scan line IN A,(C) AND %11100000 LD (HL),A LD C,lokey ; low-order 5 bits of scan line IN A,(C) AND %00011111 OR (HL) LD (HL),A ; save the scan line INC HL ; next scan line SCF RL B JR C,scanloop IN A,(C) ; last scan line (RDMSEL) OR %11100000 ; low-order 5 bits only LD (HL),A RET test:LD HL,scanbuf ; test each scan line LD DE,lastscan LD B,9 ; 9 scan lines testloop:LD A,(DE) LD C,(HL) ; B is always 0 - no need to save it CP C JP Z,testnext ; skip this if the scan line has not changed LD A,C LD (DE),A ; update this scan line in the lastscan buffer LD A,9 ; print the scan line number that has changed SUB B CALL print LD A,#2C ; print a comma RST #10 LD A,(DE) ; print the value of the scan line CALL print LD A,#0D ; print a \r RST #10 testnext:INC HL ; test the next scan line INC DE DJNZ testloop RET mouse:DI ; disable interrupts LD E,0 LD A,(mxcrd) LD B,A ; save the X coordinate LD A,128 CP B ; check whether the X coordinate has changed JP Z,mousey LD E,1 ; mouse status has changed? mousey:LD A,(mycrd) LD C,A ; save the Y coordinate LD A,96 CP C ; check whether the Y coordinate has changed JP Z,mousebut LD E,1 ; mouse status has changed? mousebut:LD A,(butstat) LD D,A ; save the button status LD A,(lastbut) CP D ; check whether the button status has changed JP Z,mousetest LD E,1 ; mouse status has changed? mousetest:LD A,0 CP E JP NZ,mousesend ; if the mouse status has changed, print the new status EI ; enable interrupts RET mousesend:CALL mreset ; reset the mouse status EI ; enable interrupts LD A,#6D ; print an 'm' RST #10 LD A,B ; print the X coordinate CALL print LD A,#2C ; print a comma RST #10 LD A,C ; print the Y coordinate CALL print LD A,#3A ; print a colon RST #10 LD A,D ; print the button status CALL print LD A,#0D ; print a \r RST #10 LD HL,lastbut ; save the button status LD (HL),D RET print:PUSH AF ; print the value held in A PUSH BC PUSH DE PUSH HL LD D,A LD C,0 LD E,0 LD A,0 CALL jstkstore ; place the value on the calculator stack CALL jstrs ; convert the number to a string CALL #0013 ; print the resulting string POP HL POP DE POP BC POP AF RET mreset:LD HL,mxcrd ; set the mouse's X coordinate to 128 LD (HL),128 INC HL LD (HL),0 LD HL,mycrd ; set the mouse's Y coordinate to 96 LD (HL),96 INC HL LD (HL),0 RET jsetstrm:EQU #0112 ; rom routines jstkstore:EQU #0127 jstrs:EQU #017E butstat:EQU #5B8F ; system variables mxcrd:EQU #5B96 mycrd:EQU #5B98 hikey:EQU #F9 ; I/O ports lokey:EQU #FE scanbuf:DS 9 ; buffers lastscan:DS 9 lastbut:BS 1