Afterall, I decided to not use the fancy new macros, I think pek/pok is more readable than glyphs in the end

This commit is contained in:
neauoire 2021-04-22 20:44:38 -07:00
parent 1b4623be1b
commit 8ca9e6d4de
7 changed files with 155 additions and 185 deletions

View File

@ -32,7 +32,7 @@ else
fi
echo "Assembling.."
./bin/assembler projects/examples/gui.animation.usm bin/boot.rom
./bin/assembler projects/examples/dev.audio.usm bin/boot.rom
echo "Running.."
if [ "${2}" = '--cli' ];

View File

@ -2,11 +2,6 @@
%MOD { DUP2 DIV MUL SUB }
%%^! { .% DEI } %%~! { .% DEO }
%%*! { .% DEI2 } %%=! { .% DEO2 }
%%^ { .% PEK } %%~ { .% POK }
%%* { .% PEK2 } %%= { .% POK2 }
@timer $1
@progress $1
@ -19,41 +14,41 @@
|0100 ( -> )
( set color pallete )
#00ff System/r=!
#0f0f System/g=!
#0ff0 System/b=!
#00ff .System/r DEO2
#0f0f .System/g DEO2
#0ff0 .System/b DEO2
;on-frame Screen/vector=! ( run on-frame every 1/60th of a second )
#ff Audio/vol~! ( set volume to max )
;saw Audio/wave=! ( set waveform to saw for audio engine )
;env Audio/env=! ( set envelope for audio engine )
;on-frame .Screen/vector DEO2 ( run on-frame every 1/60th of a second )
#ff .Audio/vol DEO ( set volume to max )
;saw .Audio/wave DEO2 ( set waveform to saw for audio engine )
;env .Audio/env DEO2 ( set envelope for audio engine )
BRK
@on-frame ( -> )
( incr ) timer^ #01 ADD timer~
( skip ) timer^ #10 EQU ,&play-note JNZ BRK &play-note
( incr ) .timer PEK #01 ADD .timer POK
( skip ) .timer PEK #10 EQU ,&play-note JNZ BRK &play-note
( get note )
;melody #00 progress^ ADD2 GET
;melody #00 .progress PEK ADD2 GET
( play note )
DUP #80 ORA Audio/pitch~!
#01 Audio/play~!
DUP #80 ORA .Audio/pitch DEO
#01 .Audio/play DEO
( erase last note )
#20 Screen/color~!
#20 .Screen/color DEO
( draw note )
#00 SWP #0004 MUL2 #0100 SUB2 Screen/y=!
#00 progress^ #0008 MUL2 Screen/x=!
;dot Screen/addr=!
#21 Screen/color~!
#00 SWP #0004 MUL2 #0100 SUB2 .Screen/y DEO2
#00 .progress PEK #0008 MUL2 .Screen/x DEO2
;dot .Screen/addr DEO2
#21 .Screen/color DEO
( incr ) progress^ #01 ADD #20 MOD progress~
( incr ) .progress PEK #01 ADD #20 MOD .progress POK
#00 timer~
#00 .timer POK
BRK
@ -65,10 +60,10 @@ BRK
@saw ( -> )
#6000 Audio/value=!
#0000 Audio/delay=! ( move to volume #600 after 0 delay )
#0000 Audio/value=!
#ffff Audio/delay=! ( reach volume 0 after the whole note. Interpolated linearly )
#6000 .Audio/value DEO2
#0000 .Audio/delay DEO2 ( move to volume #600 after 0 delay )
#0000 .Audio/value DEO2
#ffff .Audio/delay DEO2 ( reach volume 0 after the whole note. Interpolated linearly )
BRK
@ -76,11 +71,11 @@ BRK
@env ( -> )
#ffff Audio/value=!
#1000 Audio/delay=! ( move pretty quickly to volume #ffff (maximum) )
#0000 Audio/value=!
#4000 Audio/delay=! ( interpolating linearly, move to #0000 after a delay of #4000 where #8000 is half a second )
#00 Audio/finish~! ( end the envelope )
#ffff .Audio/value DEO2
#1000 .Audio/delay DEO2 ( move pretty quickly to volume #ffff (maximum) )
#0000 .Audio/value DEO2
#4000 .Audio/delay DEO2 ( interpolating linearly, move to #0000 after a delay of #4000 where #8000 is half a second )
#00 .Audio/finish DEO ( end the envelope )
BRK

View File

@ -4,11 +4,6 @@
%-- { #0001 SUB2 }
%2/ { #0002 DIV2 }
%%^! { .% DEI } %%~! { .% DEO }
%%*! { .% DEI2 } %%=! { .% DEO2 }
%%^ { .% PEK } %%~ { .% POK }
%%* { .% PEK2 } %%= { .% POK2 }
( devices )
|00 @System [ &vector $2 &pad $6 &r $2 &g $2 &b $2 ]
@ -26,62 +21,62 @@
|0100 ( -> )
( theme )
#0daf System/r=!
#02ff System/g=!
#035f System/b=!
#0daf .System/r DEO2
#02ff .System/g DEO2
#035f .System/b DEO2
( vectors )
;on-frame Screen/vector=!
;on-frame .Screen/vector DEO2
( set origin )
Screen/width*! 2/ Screen/x=!
Screen/height*! 2/ Screen/y=!
.Screen/width DEI2 2/ .Screen/x DEO2
.Screen/height DEI2 2/ .Screen/y DEO2
;default_icn Screen/addr=!
#31 Screen/color~!
#2a slime~
;default_icn .Screen/addr DEO2
#31 .Screen/color DEO
#2a .slime POK
BRK
@on-frame ( -> )
#2a slime~
;default_icn Screen/addr=!
#2a .slime POK
;default_icn .Screen/addr DEO2
( hold ctrl key to change slime color )
Controller/button^! #0f AND
DUP #01 NEQ ,&no-ctrl JNZ #25 slime~ &no-ctrl
DUP #02 NEQ ,&no-alt JNZ #2f slime~ &no-alt
.Controller/button DEI #0f AND
DUP #01 NEQ ,&no-ctrl JNZ #25 .slime POK &no-ctrl
DUP #02 NEQ ,&no-alt JNZ #2f .slime POK &no-alt
POP
( clear ) #30 Screen/color~!
( clear ) #30 .Screen/color DEO
( detect movement )
Controller/button^! #f0 AND
.Controller/button DEI #f0 AND
DUP #04 SFT #01 AND #01 NEQ ,&no-up JNZ
( move )
Screen/y*! -- Screen/y=!
;up_icn Screen/addr=! &no-up
.Screen/y DEI2 -- .Screen/y DEO2
;up_icn .Screen/addr DEO2 &no-up
DUP #05 SFT #01 AND #01 NEQ ,&no-down JNZ
( move )
Screen/y*! ++ Screen/y=!
;down_icn Screen/addr=! &no-down
.Screen/y DEI2 ++ .Screen/y DEO2
;down_icn .Screen/addr DEO2 &no-down
DUP #06 SFT #01 AND #01 NEQ ,&no-left JNZ
( move )
Screen/x*! -- Screen/x=!
;left_icn Screen/addr=! &no-left
.Screen/x DEI2 -- .Screen/x DEO2
;left_icn .Screen/addr DEO2 &no-left
DUP #07 SFT #01 AND #01 NEQ ,&no-right JNZ
( move )
Screen/x*! ++ Screen/x=!
;right_icn Screen/addr=! &no-right
.Screen/x DEI2 ++ .Screen/x DEO2
;right_icn .Screen/addr DEO2 &no-right
POP
( draw face )
#31 Screen/color~!
#31 .Screen/color DEO
( draw slime )
;slime_icn Screen/addr=!
slime^ Screen/color~!
;slime_icn .Screen/addr DEO2
.slime PEK .Screen/color DEO
BRK

View File

@ -4,11 +4,6 @@
%8+ { #0008 ADD2 }
%8* { #0030 SFT2 }
%%^! { .% DEI } %%~! { .% DEO }
%%*! { .% DEI2 } %%=! { .% DEO2 }
%%^ { .% PEK } %%~ { .% POK }
%%* { .% PEK2 } %%= { .% POK2 }
( devices )
|00 @System [ &vector $2 &pad $6 &r $2 &g $2 &b $2 ]
@ -20,36 +15,36 @@
|0100 ( -> )
( theme )
#0f73 System/r=!
#0fe3 System/g=!
#0fc3 System/b=!
#0f73 .System/r DEO2
#0fe3 .System/g DEO2
#0fc3 .System/b DEO2
( vectors )
;on-button Controller/vector=!
;on-button .Controller/vector DEO2
;draw-cursor JSR2
BRK
@on-button ( -> )
Controller/key^! #00 NEQ ,&skip JNZ BRK &skip
Controller/key^! #0d NEQ ,&no-return JNZ
( draw ) #20 Screen/color~!
( reset ) #0000 Screen/x=!
( incr ) Screen/y*! 8+ Screen/y=!
.Controller/key DEI #00 NEQ ,&skip JNZ BRK &skip
.Controller/key DEI #0d NEQ ,&no-return JNZ
( draw ) #20 .Screen/color DEO
( reset ) #0000 .Screen/x DEO2
( incr ) .Screen/y DEI2 8+ .Screen/y DEO2
;draw-cursor JSR2
BRK
&no-return
;font #00 Controller/key^! 8* ADD2 Screen/addr=!
( draw ) #21 Screen/color~!
( incr ) Screen/x*! 8+ Screen/x=!
;font #00 .Controller/key DEI 8* ADD2 .Screen/addr DEO2
( draw ) #21 .Screen/color DEO
( incr ) .Screen/x DEI2 8+ .Screen/x DEO2
;draw-cursor JSR2
BRK
@draw-cursor ( -- )
;cursor Screen/addr=!
#22 Screen/color~!
;cursor .Screen/addr DEO2
#22 .Screen/color DEO
RTN

View File

@ -3,11 +3,6 @@
%8+ { #0008 ADD2 }
%MEMORY { #1000 }
%%^! { .% DEI } %%~! { .% DEO }
%%*! { .% DEI2 } %%=! { .% DEO2 }
%%^ { .% PEK } %%~ { .% POK }
%%* { .% PEK2 } %%= { .% POK2 }
( devices )
|00 @System [ &vector $2 &pad $6 &r $2 &g $2 &b $2 ]
@ -24,46 +19,46 @@
|0100 ( -> )
( theme )
#0efc System/r=!
#03cc System/g=!
#03ac System/b=!
#0efc .System/r DEO2
#03cc .System/g DEO2
#03ac .System/b DEO2
( load file )
#1000 File/length=!
;srcpath File/name=!
MEMORY File/load=!
#1000 .File/length DEO2
;srcpath .File/name DEO2
MEMORY .File/load DEO2
File/success*! #0000 NEQ2 ;on-success JNZ2
.File/success DEI2 #0000 NEQ2 ;on-success JNZ2
;failedtxt Console/string=!
;failedtxt .Console/string DEO2
BRK
@on-success ( -> )
;successtxt Console/string=!
;successtxt .Console/string DEO2
( draw image )
MEMORY Screen/addr=!
MEMORY .Screen/addr DEO2
#0000 #0080
&ver
( save ) OVR2 Screen/y=!
( save ) OVR2 .Screen/y DEO2
#0000 #0080
&hor
( save ) OVR2 Screen/x=!
( draw ) #41 Screen/color~!
( incr ) Screen/addr*! #0010 ADD2 Screen/addr=!
( save ) OVR2 .Screen/x DEO2
( draw ) #41 .Screen/color DEO
( incr ) .Screen/addr DEI2 #0010 ADD2 .Screen/addr DEO2
( incr ) SWP2 8+ SWP2
OVR2 OVR2 LTH2 ,&hor JNZ
POP2 POP2
( incr ) SWP2 8+ SWP2
OVR2 OVR2 LTH2 ,&ver JNZ
POP2 POP2
( save file )
#1000 File/length=!
;dstpath File/name=!
MEMORY File/save=!
#1000 .File/length DEO2
;dstpath .File/name DEO2
MEMORY .File/save DEO2
BRK

View File

@ -1,12 +1,7 @@
( dev/mouse )
%RTN { JMP2r }
%ABS2 { DUP2 #000f SFT2 EQU #04 JNZ #ffff MUL2 }
%%^! { .% DEI } %%~! { .% DEO }
%%*! { .% DEI2 } %%=! { .% DEO2 }
%%^ { .% PEK } %%~ { .% POK }
%%* { .% PEK2 } %%= { .% POK2 }
%ABS2 { DUP2 #000f SFT2 EQU #04 JNZ #ffff MUL2 }.
( devices )
@ -25,11 +20,11 @@
|0100 ( -> )
( theme )
#f0f0 System/r=!
#f00f System/g=!
#f000 System/b=!
#f0f0 .System/r DEO2
#f00f .System/g DEO2
#f000 .System/b DEO2
( vectors )
;on-mouse Mouse/vector=!
;on-mouse .Mouse/vector DEO2
BRK
@ -37,79 +32,79 @@ BRK
;draw-cursor JSR2
( on down )
Mouse/state^! #00 NEQ pointer/state^ #00 EQU #0101 EQU2 ,on-mouse-down JNZ
.Mouse/state DEI #00 NEQ .pointer/state PEK #00 EQU #0101 EQU2 ,on-mouse-down JNZ
( on drag )
Mouse/state^! #00 NEQ ,on-mouse-drag JNZ
Mouse/state^! pointer/state~
.Mouse/state DEI #00 NEQ ,on-mouse-drag JNZ
.Mouse/state DEI .pointer/state POK
BRK
@on-mouse-down ( -> )
( record start position )
Mouse/x*! DUP2 pointer/x= pointer/lastx=
Mouse/y*! DUP2 pointer/y= pointer/lasty=
Mouse/state^! pointer/state~
.Mouse/x DEI2 DUP2 .pointer/x POK2 .pointer/lastx POK2
.Mouse/y DEI2 DUP2 .pointer/y POK2 .pointer/lasty POK2
.Mouse/state DEI .pointer/state POK
BRK
@on-mouse-drag ( -> )
( draw line )
pointer/lastx*
pointer/lasty*
pointer/x*
pointer/y*
#01 [ Mouse/state^! #10 EQU #02 MUL ADD ]
.pointer/lastx PEK2
.pointer/lasty PEK2
.pointer/x PEK2
.pointer/y PEK2
#01 [ .Mouse/state DEI #10 EQU #02 MUL ADD ]
;draw-line JSR2
( record last position )
Mouse/x*! pointer/lastx=
Mouse/y*! pointer/lasty=
Mouse/state^! pointer/state~
.Mouse/x DEI2 .pointer/lastx POK2
.Mouse/y DEI2 .pointer/lasty POK2
.Mouse/state DEI .pointer/state POK
BRK
@draw-cursor ( -- )
( clear last cursor )
;clear Screen/addr=!
pointer/x* Screen/x=!
pointer/y* Screen/y=!
#30 Screen/color~!
;clear .Screen/addr DEO2
.pointer/x PEK2 .Screen/x DEO2
.pointer/y PEK2 .Screen/y DEO2
#30 .Screen/color DEO
( record pointer positions )
Mouse/x*! pointer/x=
Mouse/y*! pointer/y=
.Mouse/x DEI2 .pointer/x POK2
.Mouse/y DEI2 .pointer/y POK2
( draw new cursor )
;cursor Screen/addr=!
pointer/x* Screen/x=!
pointer/y* Screen/y=!
;cursor .Screen/addr DEO2
.pointer/x PEK2 .Screen/x DEO2
.pointer/y PEK2 .Screen/y DEO2
( colorize on state )
#31 [ Mouse/state^! #00 NEQ ] ADD Screen/color~!
#31 [ .Mouse/state DEI #00 NEQ ] ADD .Screen/color DEO
RTN
@draw-line ( x1 y1 x2 y2 color -- )
( load ) color~ line/y0= line/x0= line/y= line/x=
line/x0* line/x* SUB2 ABS2 line/dx=
line/y0* line/y* SUB2 ABS2 #0000 SWP2 SUB2 line/dy=
#ffff #00 line/x* line/x0* LTS2 #0002 MUL2 ADD2 line/sx=
#ffff #00 line/y* line/y0* LTS2 #0002 MUL2 ADD2 line/sy=
line/dx* line/dy* ADD2 line/e1=
( 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
( draw )
line/x* Screen/x=!
line/y* Screen/y=!
color^ Screen/color~!
line/x* line/x0* EQU2 line/y* line/y0* EQU2 #0101 EQU2 ,&end JNZ
line/e1* #0002 MUL2 line/e2=
line/e2* line/dy* LTS2 ,&skipy JNZ
line/e1* line/dy* ADD2 line/e1=
line/x* line/sx* ADD2 line/x=
.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* line/dx* GTS2 ,&skipx JNZ
line/e1* line/dx* ADD2 line/e1=
line/y* line/sy* ADD2 line/y=
.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

View File

@ -1,10 +1,5 @@
( GUI Animation )
%%^! { .% DEI } %%~! { .% DEO }
%%*! { .% DEI2 } %%=! { .% DEO2 }
%%^ { .% PEK } %%~ { .% POK }
%%* { .% PEK2 } %%= { .% POK2 }
|00 @System [ &vector $2 &pad $6 &r $2 &g $2 &b $2 ]
|20 @Screen [ &vector $2 &width $2 &height $2 &pad $2 &x $2 &y $2 &addr $2 &color $1 ]
@ -17,14 +12,14 @@
|0100 ( -> )
( theme )
#4cfd System/r=!
#4cf3 System/g=!
#dcf2 System/b=!
#4cfd .System/r DEO2
#4cf3 .System/g DEO2
#dcf2 .System/b DEO2
( vectors )
;on-frame Screen/vector=!
;on-frame .Screen/vector DEO2
( starting position )
Screen/width*! #0002 DIV2 dvd/x=
Screen/height*! #0002 DIV2 dvd/y=
.Screen/width DEI2 #0002 DIV2 .dvd/x POK2
.Screen/height DEI2 #0002 DIV2 .dvd/y POK2
#21 ;draw-dvd JSR2
BRK
@ -32,16 +27,16 @@ BRK
@on-frame ( -> )
( clear ) #20 ;draw-dvd JSR2
( case: hit-right ) dvd/x* Screen/width*! #0020 SUB2 EQU2
( case: hit-left ) dvd/x* #0000 EQU2
( case: hit-right ) .dvd/x PEK2 .Screen/width DEI2 #0020 SUB2 EQU2
( case: hit-left ) .dvd/x PEK2 #0000 EQU2
#0000 EQU2 ,&no-flipx JNZ
dvd/dx^ #00 EQU dvd/dx~ &no-flipx
( case: hit-bottom ) dvd/y* Screen/height*! #0010 SUB2 EQU2
( case: hit-top ) dvd/y* #0000 EQU2
.dvd/dx PEK #00 EQU .dvd/dx POK &no-flipx
( case: hit-bottom ) .dvd/y PEK2 .Screen/height DEI2 #0010 SUB2 EQU2
( case: hit-top ) .dvd/y PEK2 #0000 EQU2
#0000 EQU2 ,&no-flipy JNZ
dvd/dy^ #00 EQU dvd/dy~ &no-flipy
( incr ) dvd/x* #0001 #00 dvd/dx^ #00 EQU #fffe MUL2 ADD2 ADD2 dvd/x=
( incr ) dvd/y* #0001 #00 dvd/dy^ #00 EQU #fffe MUL2 ADD2 ADD2 dvd/y=
.dvd/dy PEK #00 EQU .dvd/dy POK &no-flipy
( incr ) .dvd/x PEK2 #0001 #00 .dvd/dx PEK #00 EQU #fffe MUL2 ADD2 ADD2 .dvd/x POK2
( incr ) .dvd/y PEK2 #0001 #00 .dvd/dy PEK #00 EQU #fffe MUL2 ADD2 ADD2 .dvd/y POK2
( draw ) #21 ;draw-dvd JSR2
BRK
@ -49,15 +44,15 @@ BRK
@draw-dvd ( color -- )
( stash ) STH
;dvd_icn Screen/addr=!
dvd/y* [ dvd/y* #0010 ADD2 ]
;dvd_icn .Screen/addr DEO2
.dvd/y PEK2 [ .dvd/y PEK2 #0010 ADD2 ]
&ver
OVR2 Screen/y=!
dvd/x* [ dvd/x* #0020 ADD2 ]
OVR2 .Screen/y DEO2
.dvd/x PEK2 [ .dvd/x PEK2 #0020 ADD2 ]
&hor
OVR2 Screen/x=!
( draw ) DUPr STHr Screen/color~!
( next ) Screen/addr*! #0008 ADD2 Screen/addr=!
OVR2 .Screen/x DEO2
( draw ) DUPr STHr .Screen/color DEO
( next ) .Screen/addr DEI2 #0008 ADD2 .Screen/addr DEO2
( incr ) SWP2 #0008 ADD2 SWP2
OVR2 OVR2 LTH2 ,&hor JNZ
POP2 POP2