diff --git a/basic/scripts/tokens.py b/basic/scripts/tokens.py index 756cc79d1..ef7b74944 100644 --- a/basic/scripts/tokens.py +++ b/basic/scripts/tokens.py @@ -96,7 +96,7 @@ def create(self): self.add(0x80,""" !!STR $ ( RAND( RND( JOYPAD( INT( TIME( EVENT( INKEY$( ASC( CHR$( POINT( LEN( ABS( SGN( HIT( SPOINT( - MID$( LEFT$( RIGHT$( TRUE FALSE INSTR( !!UN5 !!UN6 !!UN7 + MID$( LEFT$( RIGHT$( TRUE FALSE INSTR( MOUSE( !!UN6 !!UN7 KEY( PEEK( DEEK( ALLOC( MAX( MIN( """,48) # @@ -128,7 +128,7 @@ def create(self): HOME LOCALE CURSOR RENUMBER DELETE EDIT MON OLD ON ERROR PIN OUTPUT WAIT IWRITE ANALOG ISEND SSEND IRECEIVE SRECEIVE ITRANSMIT STRANSMIT NEAL LIBRARY - USEND URECEIVE UTRANSMIT UCONFIG MOS + USEND URECEIVE UTRANSMIT UCONFIG MOS MOUSE SHOW """) # # Keyword tokens (assembler) diff --git a/basic/sources/arithmetic/unary/hardware/mouse.asm b/basic/sources/arithmetic/unary/hardware/mouse.asm new file mode 100644 index 000000000..df7c23e5e --- /dev/null +++ b/basic/sources/arithmetic/unary/hardware/mouse.asm @@ -0,0 +1,106 @@ + ; ************************************************************************************************ +; ************************************************************************************************ +; +; Name: mouse.asm +; Purpose: Return mouse state +; Created: 9th April 2024 +; Reviewed: No +; Author: Paul Robson (paul@robsons.org.uk) +; +; ************************************************************************************************ +; ************************************************************************************************ + +; ************************************************************************************************ +; +; MOUSE(x,y) Sets X,Y to mouse position, returns buttons (bit 0 left, bit 1 right) +; MOUSE(x,y,s) Same but returns scroll wheel. +; +; ************************************************************************************************ + + .section code + +EXPUnaryMouse: ;; [mouse(] + jsr EvaluateTerm ; first parameter. + jsr ERRCheckComma + inx + jsr EvaluateTerm ; second parameter. + inx + lda #$FF ; default 3rd parameter (don't use if $FF) + sta XSControl,x + + lda (codePtr),y ; , follows ? + cmp #KWD_COMMA ; we have three parameters + bne _EUMNoScroll + iny ; consume it + jsr EvaluateTerm ; third parameter +_EUMNoScroll: + dex ; restore stack position. + dex + jsr ERRCheckRParen ; check closing ) + + .DoSendMessage ; read the mouse state + .byte 11,3 + .DoWaitMessage + + phx ; save stack pos + phy ; save code pos + + ldy #0 ; control parameter 0,1 + jsr EMOCopyToVariable ; copy to first + + ldy #2 ; control parameter 2,3 + inx ; copy to second + jsr EMOCopyToVariable + + inx ; check third reference exists + lda XSControl,x + cmp #$FF + beq _EUMNoScroll2 + stz ControlParameters+6 ; it's in 5, make it 16 bit value + ldy #5 ; copy to third + jsr EMOCopyToVariable +_EUMNoScroll2: + ply + plx ; restore stack pos. + lda ControlParameters+4 ; get the button bits. + jmp EXPUnaryReturnA ; and return that value. + +EMOCopyToVariable: + lda XSControl,x ; check integer variable reference + and #(XS_TYPEBIT|XS_ISVARIABLE) + cmp #XS_ISVARIABLE + bne _EMOCTJError + + lda XSNumber0,x ; make zTemp0 point to the variable + sta zTemp0 + lda XSNumber1,x + sta zTemp0+1 + + phy ; copy the value over + lda ControlParameters,y + sta (zTemp0) + lda ControlParameters+1,y + ldy #1 + sta (zTemp0),y + ply + + rts + +_EMOCTJError: + .error_type + + + .send code + + +; ************************************************************************************************ +; +; Changes and Updates +; +; ************************************************************************************************ +; +; Date Notes +; ==== ===== +; +; ************************************************************************************************ + diff --git a/basic/sources/commands/hardware/mouse.asm b/basic/sources/commands/hardware/mouse.asm new file mode 100644 index 000000000..fd7da2ab7 --- /dev/null +++ b/basic/sources/commands/hardware/mouse.asm @@ -0,0 +1,87 @@ +; ************************************************************************************************ +; ************************************************************************************************ +; +; Name: mouse.asm +; Purpose: Control Mouse +; Created: 9th April 2024 +; Reviewed: No +; Author: Paul Robson (paul@robsons.org.uk) +; +; ************************************************************************************************ +; ************************************************************************************************ + +; ************************************************************************************************ +; +; MOUSE Command +; +; ************************************************************************************************ + + .section code + +Command_Mouse: ;; [mouse] + lda (codePtr),y ; check for TO. + cmp #KWD_TO + beq _MOTo + ; + ; MOUSE SHOW|HIDE + ; + cmp #KWD_SYS_SH1 ; check for SHOW and HIDE, shifted + bne _MOError + iny + lda (codePtr),y ; check SHOW/HIDE + iny + cmp #KWD_SHOW-$100 + beq _MOControl + cmp #KWD_HIDE-$100 + beq _MOControl +_MOError: + .error_syntax + +_MOControl: + eor #KWD_HIDE-$100 ; 0 HIDE <>0 SHOW + sta ControlParameters+0 + .DoSendMessage ; set mouse visibility + .byte 11,2 + .DoWaitMessage + + rts + + ; + ; MOUSE TO x,y + ; +_MOTo: + iny ; get coordinates + ldx #0 + jsr EXPEvalInteger16 + inx + jsr ERRCheckComma + jsr EXPEvalInteger16 + + lda XSNumber0 ; set up for call. + sta ControlParameters+0 + lda XSNumber1 + sta ControlParameters+1 + lda XSNumber0+1 + sta ControlParameters+2 + lda XSNumber1+2 + sta ControlParameters+3 + + .DoSendMessage ; set mouse position. + .byte 11,1 + .DoWaitMessage + + rts + + .send code + +; ************************************************************************************************ +; +; Changes and Updates +; +; ************************************************************************************************ +; +; Date Notes +; ==== ===== +; +; ************************************************************************************************ + diff --git a/basic/test.bsc b/basic/test.bsc index c8de86796..6e8ab1b51 100644 --- a/basic/test.bsc +++ b/basic/test.bsc @@ -1,38 +1,16 @@ -0 ' library #1 -0 ' library #2 -edit -dim j0w(1,1) -dim w7u$(2) -print "This line" -dim a7h$(5,4) -dim f9$(1) -dim j(7) -dim g6(6) -dim f5$(1) -dim u1b(3) -dim u6h8b(1) -dim x6e9(4) -dim u2$(4,3) -dim r2$(4) -dim v1u4v(1) -dim h2i(4,2) -dim m7p0i$(5) -dim g2y(5,3) -dim y3d0v$(5,4) -dim w6(4,4) -dim j$(3) -dim k9e8h(4) -w7u$(2) = "K" -x6e9(2) = -377 -g6(1) = 310.58 -j0w(0,1) = 492 -a7h$(1,3) = "CFFS" -f5$(0) = "SBTCRBKC" -j$(3) = "MMNPJTR" -r2$(0) = "YMMACX" -h2i(4,1) = -29.41 -j0w(0,1) = 846.3 -u2$(0,2) = "TNVDWXI" -y3d0v$(3,0) = "ZZJYUF" -k9e8h(0) = 742 -u2$(1,3) = "QKPC" +' +' BASIC Mouse cursor manipulation +' +mouse show +mouse to 260,180 +repeat + b = mouse(x,y,s) + print chr$(20);x;" ";y;" ";b;" ";s;" " +until false +end +' +proc send.message(g,f) + while peek($FF00):wend + poke $FF01,f:poke $FF00,g + while peek($FF00):wend +endproc \ No newline at end of file diff --git a/documents/release/basic.odt b/documents/release/basic.odt index 4296b3a5f..03d1110be 100644 Binary files a/documents/release/basic.odt and b/documents/release/basic.odt differ diff --git a/emulator/basic-examples/graphics.gfx b/emulator/basic-examples/graphics.gfx deleted file mode 100644 index 5617a175b..000000000 Binary files a/emulator/basic-examples/graphics.gfx and /dev/null differ diff --git a/examples/basic/demos/mouse-cursor-api.bas b/examples/basic/examples/mouse-cursor-api.bas similarity index 100% rename from examples/basic/demos/mouse-cursor-api.bas rename to examples/basic/examples/mouse-cursor-api.bas diff --git a/examples/basic/demos/mouse-cursor-api.bsc b/examples/basic/examples/mouse-cursor-api.bsc similarity index 100% rename from examples/basic/demos/mouse-cursor-api.bsc rename to examples/basic/examples/mouse-cursor-api.bsc diff --git a/examples/basic/examples/mouse-cursor-basic.bas b/examples/basic/examples/mouse-cursor-basic.bas new file mode 100644 index 000000000..141a4d3a4 Binary files /dev/null and b/examples/basic/examples/mouse-cursor-basic.bas differ diff --git a/examples/basic/examples/mouse-cursor-basic.bsc b/examples/basic/examples/mouse-cursor-basic.bsc new file mode 100644 index 000000000..6e8ab1b51 --- /dev/null +++ b/examples/basic/examples/mouse-cursor-basic.bsc @@ -0,0 +1,16 @@ +' +' BASIC Mouse cursor manipulation +' +mouse show +mouse to 260,180 +repeat + b = mouse(x,y,s) + print chr$(20);x;" ";y;" ";b;" ";s;" " +until false +end +' +proc send.message(g,f) + while peek($FF00):wend + poke $FF01,f:poke $FF00,g + while peek($FF00):wend +endproc \ No newline at end of file