Skip to content

Commit

Permalink
Merge pull request #433 from paulscottrobson/mouse
Browse files Browse the repository at this point in the history
Added Mouse commands to BASIC
  • Loading branch information
paulscottrobson authored Apr 9, 2024
2 parents 5699945 + 4fe4f3c commit 15802e3
Show file tree
Hide file tree
Showing 10 changed files with 227 additions and 40 deletions.
4 changes: 2 additions & 2 deletions basic/scripts/tokens.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
#
Expand Down Expand Up @@ -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)
Expand Down
106 changes: 106 additions & 0 deletions basic/sources/arithmetic/unary/hardware/mouse.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
; ************************************************************************************************
; ************************************************************************************************
;
; Name: mouse.asm
; Purpose: Return mouse state
; Created: 9th April 2024
; Reviewed: No
; Author: Paul Robson ([email protected])
;
; ************************************************************************************************
; ************************************************************************************************

; ************************************************************************************************
;
; 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
; ==== =====
;
; ************************************************************************************************

87 changes: 87 additions & 0 deletions basic/sources/commands/hardware/mouse.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
; ************************************************************************************************
; ************************************************************************************************
;
; Name: mouse.asm
; Purpose: Control Mouse
; Created: 9th April 2024
; Reviewed: No
; Author: Paul Robson ([email protected])
;
; ************************************************************************************************
; ************************************************************************************************

; ************************************************************************************************
;
; 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
; ==== =====
;
; ************************************************************************************************

54 changes: 16 additions & 38 deletions basic/test.bsc
Original file line number Diff line number Diff line change
@@ -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
Binary file modified documents/release/basic.odt
Binary file not shown.
Binary file removed emulator/basic-examples/graphics.gfx
Binary file not shown.
File renamed without changes.
File renamed without changes.
Binary file added examples/basic/examples/mouse-cursor-basic.bas
Binary file not shown.
16 changes: 16 additions & 0 deletions examples/basic/examples/mouse-cursor-basic.bsc
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 15802e3

Please sign in to comment.