uxn

Varvara Ordinator, written in ANSI C(SDL2)
git clone https://git.eamoncaddigan.net/uxn.git
Log | Files | Refs | README | LICENSE

commit b752f5f2bc775f7ba2a4b9f0a401d6f9152e222e
parent c653e974de24a0e57f92f32e0ffc081b76d0c36a
Author: neauoire <aliceffekt@gmail.com>
Date:   Thu, 22 Apr 2021 11:08:06 -0700

Added drawing to the mouse example

Diffstat:
Mbuild.sh | 2+-
Metc/usm.sublime-syntax | 10+++++++---
Mprojects/examples/dev.audio.usm | 9++++-----
Mprojects/examples/dev.mouse.usm | 76++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----
4 files changed, 84 insertions(+), 13 deletions(-)

diff --git a/build.sh b/build.sh @@ -32,7 +32,7 @@ else fi echo "Assembling.." -./bin/assembler projects/examples/dev.audio.usm bin/boot.rom +./bin/assembler projects/examples/dev.mouse.usm bin/boot.rom echo "Running.." if [ "${2}" = '--cli' ]; diff --git a/etc/usm.sublime-syntax b/etc/usm.sublime-syntax @@ -14,6 +14,10 @@ contexts: - match: '\@(\S+)\s?' scope: string.control pop: true + + - match: '\&(\S+)\s?' + scope: string.control + pop: true # jump - match: '\|(\S+)\s?' scope: variable.control @@ -26,15 +30,15 @@ contexts: # Special - - match: '\&(\S+)\s?' - scope: entity.name.type - pop: true # Pushing to stack - match: '\#(\S+)\s?' scope: keyword.control pop: true + - match: '\"(\S+)\s?' + scope: entity.control + pop: true # Addressing - match: '\.(\S+)\s?' # zero-page diff --git a/projects/examples/dev.audio.usm b/projects/examples/dev.audio.usm @@ -20,10 +20,9 @@ |0100 ( -> ) ( set color pallete ) - #0fff DUP2 DUP2 - .System/r DEO2 - .System/g DEO2 - .System/b DEO2 + #00ff .System/r DEO2 + #0f0f .System/g DEO2 + #0ff0 .System/b DEO2 ;on-frame .Screen/vector DEO2 ( run on-frame every 1/60th of a second ) #ff .Audio/vol DEO ( set volume to max ) @@ -35,7 +34,7 @@ BRK @on-frame ( -> ) ( incr ) .timer PEK #01 ADD .timer POK - ( skip ) .timer PEK #10 NEQ ;silence JNZ2 + ( skip ) .timer PEK #10 EQU ,&play-note JNZ BRK &play-note ( get note ) ;melody #00 .progress PEK ADD2 GET ( -- note ) diff --git a/projects/examples/dev.mouse.usm b/projects/examples/dev.mouse.usm @@ -4,6 +4,7 @@ %8+ { #0008 ADD2 } %++ { #0001 ADD2 } %-- { #0001 SUB2 } +%ABS2 { DUP2 #000f SFT2 EQU #04 JNZ #ffff MUL2 } ( devices ) @@ -15,27 +16,69 @@ |0000 -@pointer [ &x $2 &y $2 ] +@line [ &x0 $2 &y0 $2 &x $2 &y $2 &sx $2 &sy $2 &dx $2 &dy $2 &e1 $2 &e2 $2 ] + +@pointer [ &x $2 &y $2 &lastx $2 &lasty $2 &state $1 ] +@color $1 ( program ) |0100 ( -> ) ( theme ) - #03fd .System/r DEO2 - #0ef3 .System/g DEO2 - #0bf2 .System/b DEO2 + #0ffd .System/r DEO2 + #0f03 .System/g DEO2 + #0f02 .System/b DEO2 ( vectors ) ;on-mouse .Mouse/vector DEO2 + #0010 #0030 #0050 #0070 #01 ;hairline JSR2 + #0000 #0000 #0020 #0090 #01 ;hairline JSR2 + BRK @on-mouse ( -> ) ;draw-cursor JSR2 + ( on down ) + .Mouse/state DEI #00 NEQ + .pointer/state PEK #00 EQU + #0101 EQU2 ,on-mouse-down JNZ + + ( on drag ) + .Mouse/state DEI + #00 NEQ ,on-mouse-drag JNZ + + .Mouse/state DEI .pointer/state POK + BRK +@on-mouse-down ( -> ) + + ( record last position ) + .Mouse/x DEI2 .pointer/x POK2 + .Mouse/y DEI2 .pointer/y POK2 + + .Mouse/x DEI2 .pointer/lastx POK2 + .Mouse/y DEI2 .pointer/lasty POK2 + + .Mouse/state DEI .pointer/state POK + +BRK + +@on-mouse-drag ( -> ) + + .pointer/lastx PEK2 .pointer/lasty PEK2 .pointer/x PEK2 .pointer/y PEK2 #01 .Mouse/state DEI #10 EQU #02 MUL ADD ;hairline JSR2 + + ( record last position ) + .Mouse/x DEI2 .pointer/lastx POK2 + .Mouse/y DEI2 .pointer/lasty POK2 + + .Mouse/state DEI .pointer/state POK + +BRK + @draw-cursor ( -- ) ( clear last cursor ) @@ -59,5 +102,30 @@ BRK RTN +@hairline ( x1 y1 x2 y2 color -- ) + + ( load ) .color POK .line/y0 POK2 .line/x0 POK2 .line/y POK2 .line/x POK2 + .line/x0 PEK2 .line/x PEK2 SUB2 ABS2 .line/dx POK2 + .line/y0 PEK2 .line/y PEK2 SUB2 ABS2 #0000 SWP2 SUB2 .line/dy POK2 + #ffff #00 .line/x PEK2 .line/x0 PEK2 LTS2 #0002 MUL2 ADD2 .line/sx POK2 + #ffff #00 .line/y PEK2 .line/y0 PEK2 LTS2 #0002 MUL2 ADD2 .line/sy POK2 + .line/dx PEK2 .line/dy PEK2 ADD2 .line/e1 POK2 + &loop + .line/x PEK2 .Screen/x DEO2 .line/y PEK2 .Screen/y DEO2 .color PEK .Screen/color DEO + .line/x PEK2 .line/x0 PEK2 EQU2 .line/y PEK2 .line/y0 PEK2 EQU2 #0101 EQU2 ,&end JNZ + .line/e1 PEK2 #0002 MUL2 .line/e2 POK2 + .line/e2 PEK2 .line/dy PEK2 LTS2 ,&skipy JNZ + .line/e1 PEK2 .line/dy PEK2 ADD2 .line/e1 POK2 + .line/x PEK2 .line/sx PEK2 ADD2 .line/x POK2 + &skipy + .line/e2 PEK2 .line/dx PEK2 GTS2 ,&skipx JNZ + .line/e1 PEK2 .line/dx PEK2 ADD2 .line/e1 POK2 + .line/y PEK2 .line/sy PEK2 ADD2 .line/y POK2 + &skipx + ,&loop JMP + &end + +RTN + @clear [ 0000 0000 0000 0000 ] @cursor [ 80c0 e0f0 f8e0 1000 ]