uxn

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

commit 00df90c47e0778d9cb3129ec2e2376af2a935d7e
parent e5f2c2bbd2579ea3f7cb3449bbaebc4da3da86de
Author: Andrew Alderwick <andrew@alderwick.co.uk>
Date:   Mon, 24 May 2021 22:36:15 +0100

Optimised DIV2 by powers of 2 to SFT2

Diffstat:
Mprojects/demos/bifurcan.usm | 5+++--
Mprojects/demos/drum-rack.usm | 8++++----
Mprojects/demos/life.usm | 7++++---
Mprojects/demos/musictracker.usm | 8++++----
Mprojects/demos/piano.usm | 27+++++++++++++++------------
Mprojects/demos/polycat.usm | 6++++--
Mprojects/demos/theme.usm | 19++++++++++---------
Mprojects/examples/devices/controller.buttons.usm | 5+++--
Mprojects/examples/devices/datetime.usm | 19+++++++++++--------
Mprojects/examples/devices/screen.usm | 5+++--
Mprojects/examples/gui/animation.usm | 8++++++--
Mprojects/examples/gui/label.usm | 7++++---
Mprojects/software/neralie.usm | 4++--
Mprojects/software/orca.usm | 2+-
14 files changed, 74 insertions(+), 56 deletions(-)

diff --git a/projects/demos/bifurcan.usm b/projects/demos/bifurcan.usm @@ -6,6 +6,7 @@ %RTN { JMP2r } %MOD { DUP2 DIV MUL SUB } %TOS { #00 SWP } +%2// { #01 SFT2 } ( devices ) @@ -38,8 +39,8 @@ ;on-mouse .Mouse/vector DEO2 ( find center ) - .Screen/width DEI2 #0002 DIV2 .center/x STZ2 - .Screen/height DEI2 #0002 DIV2 .center/y STZ2 + .Screen/width DEI2 2// .center/x STZ2 + .Screen/height DEI2 2// .center/y STZ2 ( background ) ;tiles ;cover-pattern JSR2 diff --git a/projects/demos/drum-rack.usm b/projects/demos/drum-rack.usm @@ -4,10 +4,10 @@ - When selecting a pad, should highlight note in octave ) -%+ { ADD } %- { SUB } %* { MUL } %/ { DIV } -%< { LTH } %> { GTH } %= { EQU } %! { NEQ } -%++ { ADD2 } %-- { SUB2 } %** { MUL2 } %// { DIV2 } -%<< { LTH2 } %>> { GTH2 } %== { EQU2 } %!! { NEQ2 } +%+ { ADD } %- { SUB } %* { MUL } %/ { DIV } +%< { LTH } %> { GTH } %= { EQU } %! { NEQ } +%++ { ADD2 } %-- { SUB2 } %** { MUL2 } %// { DIV2 } +%<< { LTH2 } %>> { GTH2 } %== { EQU2 } %!! { NEQ2 } %TOB { SWP POP } %TOS { #00 SWP } %RTN { JMP2r } diff --git a/projects/demos/life.usm b/projects/demos/life.usm @@ -15,11 +15,12 @@ %RTN { JMP2r } %MOD { DUP2 / * - } %MOD8 { #07 AND } %MOD2 { #01 AND } %SFL { #40 SFT SFT } +%2// { #01 SFT2 } %8// { #03 SFT2 } %WIDTH { #40 } %HEIGHT { #40 } %BANK1 { #8000 } %BANK2 { #a000 } -%GET-SIZE { WIDTH TOS #0008 // HEIGHT TOS ** } +%GET-SIZE { WIDTH TOS 8// HEIGHT TOS ** } %GET-ITERATORS { SWP2k POP SWP POP } ( devices ) @@ -58,8 +59,8 @@ #07 #05 ;set-cell JSR2 #06 #05 ;set-cell JSR2 - .Screen/width DEI2 #0002 // WIDTH TOS -- .anchor/x STZ2 - .Screen/height DEI2 #0002 // HEIGHT TOS -- .anchor/y STZ2 + .Screen/width DEI2 2// WIDTH TOS -- .anchor/x STZ2 + .Screen/height DEI2 2// HEIGHT TOS -- .anchor/y STZ2 #01 .world/paused STZ diff --git a/projects/demos/musictracker.usm b/projects/demos/musictracker.usm @@ -2,8 +2,8 @@ %RTN { JMP2r } %8++ { #0008 ADD2 } %8-- { #0008 SUB2 } -%8** { #0008 MUL2 } %8// { #0008 DIV2 } -%++ { #0001 ADD2 } +%8** { #0008 MUL2 } %8// { #03 SFT2 } +%++ { #0001 ADD2 } %2// { #01 SFT2 } %MOD8 { #07 AND } %TRACK { ;track/ch1 #00 .track/active LDZ #0020 MUL2 ADD2 } @@ -43,9 +43,9 @@ ( vectors ) ;on-mouse .Mouse/vector DEO2 ( vectors ) ;on-button .Controller/vector DEO2 - .Screen/width DEI2 #0002 DIV2 DUP2 #0080 SUB2 .trkframe/x1 STZ2 + .Screen/width DEI2 2// DUP2 #0080 SUB2 .trkframe/x1 STZ2 #0080 ADD2 .trkframe/x2 STZ2 - .Screen/height DEI2 #0002 DIV2 DUP2 #0038 SUB2 #0010 SUB2 .trkframe/y1 STZ2 + .Screen/height DEI2 2// DUP2 #0038 SUB2 #0010 SUB2 .trkframe/y1 STZ2 #0038 ADD2 #0010 SUB2 .trkframe/y2 STZ2 .trkframe/x1 LDZ2 .chnframe/x1 STZ2 .trkframe/y2 LDZ2 .chnframe/y1 STZ2 diff --git a/projects/demos/piano.usm b/projects/demos/piano.usm @@ -1,9 +1,9 @@ ( piano ) -%+ { ADD } %- { SUB } %* { MUL } %/ { DIV } -%< { LTH } %> { GTH } %= { EQU } %! { NEQ } -%++ { ADD2 } %-- { SUB2 } %** { MUL2 } %// { DIV2 } -%<< { LTH2 } %>> { GTH2 } %== { EQU2 } %!! { NEQ2 } +%+ { ADD } %- { SUB } %* { MUL } %/ { DIV } +%< { LTH } %> { GTH } %= { EQU } %! { NEQ } +%++ { ADD2 } %-- { SUB2 } %** { MUL2 } %// { DIV2 } +%<< { LTH2 } %>> { GTH2 } %== { EQU2 } %!! { NEQ2 } %RTN { JMP2r } %TOS { #00 SWP } @@ -11,6 +11,9 @@ %LTS2 { #8000 ++ SWP2 #8000 ++ >> } %GTS2 { #8000 ++ SWP2 #8000 ++ << } %INCR { SWP #01 + SWP } +%2// { #01 SFT2 } +%4// { #02 SFT2 } +%8// { #03 SFT2 } %WAVEFORM { #1000 } @@ -62,8 +65,8 @@ ;saw-path .File/name DEO2 #0100 .File/length DEO2 WAVEFORM #0500 ++ .File/load DEO2 ( find center ) - .Screen/width DEI2 #0002 // .center/x STZ2 - .Screen/height DEI2 #0002 // .center/y STZ2 + .Screen/width DEI2 2// .center/x STZ2 + .Screen/height DEI2 2// .center/y STZ2 ( place octave ) .center/x LDZ2 #0080 -- .octave-view/x1 STZ2 @@ -191,8 +194,8 @@ BRK @on-touch-octave-view ( -> ) - .Mouse/x DEI2 .octave-view/x1 LDZ2 -- #0008 // SWP POP #09 ! ,&no-mod JCN - .Mouse/y DEI2 .octave-view/y1 LDZ2 -- #0008 // SWP POP + .Mouse/x DEI2 .octave-view/x1 LDZ2 -- 8// SWP POP #09 ! ,&no-mod JCN + .Mouse/y DEI2 .octave-view/y1 LDZ2 -- 8// SWP POP DUP #00 ! ,&no-incr JCN .octave LDZ #01 + .octave STZ &no-incr DUP #02 ! ,&no-decr JCN @@ -203,8 +206,8 @@ BRK BRK &no-mod - .Mouse/x DEI2 .octave-view/x1 LDZ2 -- #0008 // SWP POP #06 > ,&no-key JCN - .Mouse/x DEI2 .octave-view/x1 LDZ2 -- #0008 // DUP2 SWP POP .last-note STZ ;notes ++ LDA ;play JSR2 + .Mouse/x DEI2 .octave-view/x1 LDZ2 -- 8// SWP POP #06 > ,&no-key JCN + .Mouse/x DEI2 .octave-view/x1 LDZ2 -- 8// DUP2 SWP POP .last-note STZ ;notes ++ LDA ;play JSR2 ( release ) #00 .Mouse/state DEO ;draw-octave JSR2 &no-key @@ -213,7 +216,7 @@ BRK @on-touch-adsr-view ( -> ) - .Mouse/x DEI2 .adsr-view/x1 LDZ2 -- #0008 // SWP POP #03 / + .Mouse/x DEI2 .adsr-view/x1 LDZ2 -- 8// SWP POP #03 / DUP #00 ! ,&no-a JCN .Audio0/adsr DEI #10 .Mouse/state DEI #10 = #e0 * + + @@ -363,7 +366,7 @@ RTN &no-dot OVR TOS .Audio0/addr DEI2 ++ LDA #02 / - TOS #0004 // .wave-view/y1 LDZ2 ++ .Screen/y DEO2 + TOS 4// .wave-view/y1 LDZ2 ++ .Screen/y DEO2 .Screen/x DEI2 #0001 ++ .Screen/x DEO2 ( draw ) OVR .Audio0/length DEI2 SWP POP > #02 * #01 + .Screen/color DEO ( incr ) INCR diff --git a/projects/demos/polycat.usm b/projects/demos/polycat.usm @@ -1,6 +1,8 @@ ( polycat ) %RTN { JMP2r } +%2// { #01 SFT2 } +%4// { #02 SFT2 } ( devices ) @@ -25,8 +27,8 @@ #0caf .System/b DEO2 ( find center ) - .Screen/width DEI2 #0002 DIV2 #0008 SUB2 .cat/x STZ2 - .Screen/height DEI2 #0004 DIV2 #0003 MUL2 #0018 SUB2 .cat/y STZ2 + .Screen/width DEI2 2// #0008 SUB2 .cat/x STZ2 + .Screen/height DEI2 4// #0003 MUL2 #0018 SUB2 .cat/y STZ2 ( vectors ) ;on-mouse .Mouse/vector DEO2 diff --git a/projects/demos/theme.usm b/projects/demos/theme.usm @@ -2,7 +2,8 @@ %RTN { JMP2r } %++ { #0001 ADD2 } -%2/ { #01 SFT2 } +%2// { #01 SFT2 } +%4// { #02 SFT2 } %8+ { #0008 ADD2 } %STEP8 { #33 SFT2 } @@ -48,8 +49,8 @@ #0050 .window/h STZ2 ( center window ) - .Screen/width DEI2 2/ .window/w LDZ2 2/ SUB2 .window/x1 STZ2 - .Screen/height DEI2 2/ .window/h LDZ2 2/ SUB2 .window/y1 STZ2 + .Screen/width DEI2 2// .window/w LDZ2 2// SUB2 .window/x1 STZ2 + .Screen/height DEI2 2// .window/h LDZ2 2// SUB2 .window/y1 STZ2 #01 .theme/r1 STZ #02 .theme/g1 STZ #03 .theme/b1 STZ #04 .theme/r2 STZ #06 .theme/g2 STZ #07 .theme/b2 STZ @@ -57,8 +58,8 @@ #0c .theme/r4 STZ #0b .theme/g4 STZ #0d .theme/b4 STZ ( find screen center ) - .Screen/width DEI2 2/ .center/x STZ2 - .Screen/height DEI2 2/ .center/y STZ2 + .Screen/width DEI2 2// .center/x STZ2 + .Screen/height DEI2 2// .center/y STZ2 ;update-theme JSR2 ;draw-background JSR2 @@ -76,22 +77,22 @@ BRK DUP2 #0010 NEQ2 ,&no-touch-red JCN .Mouse/x DEI2 .window/x1 LDZ2 #0060 ADD2 LTH2 ,&no-touch-red JCN .Mouse/x DEI2 .window/x1 LDZ2 #009c ADD2 GTH2 ,&no-touch-red JCN - ( get new value ) .Mouse/x DEI2 .window/x1 LDZ2 SUB2 #0060 SUB2 #0004 DIV2 SWP POP ;theme/r1 #00 .selection LDZ ADD2 STA + ( get new value ) .Mouse/x DEI2 .window/x1 LDZ2 SUB2 #0060 SUB2 4// SWP POP ;theme/r1 #00 .selection LDZ ADD2 STA &no-touch-red DUP2 #0020 NEQ2 ,&no-touch-green JCN .Mouse/x DEI2 .window/x1 LDZ2 #0060 ADD2 LTH2 ,&no-touch-green JCN .Mouse/x DEI2 .window/x1 LDZ2 #009c ADD2 GTH2 ,&no-touch-green JCN - ( get new value ) .Mouse/x DEI2 .window/x1 LDZ2 SUB2 #0060 SUB2 #0004 DIV2 SWP POP ;theme/g1 #00 .selection LDZ ADD2 STA + ( get new value ) .Mouse/x DEI2 .window/x1 LDZ2 SUB2 #0060 SUB2 4// SWP POP ;theme/g1 #00 .selection LDZ ADD2 STA &no-touch-green DUP2 #0030 NEQ2 ,&no-touch-blue JCN .Mouse/x DEI2 .window/x1 LDZ2 #0060 ADD2 LTH2 ,&no-touch-blue JCN .Mouse/x DEI2 .window/x1 LDZ2 #009c ADD2 GTH2 ,&no-touch-blue JCN - ( get new value ) .Mouse/x DEI2 .window/x1 LDZ2 SUB2 #0060 SUB2 #0004 DIV2 SWP POP ;theme/b1 #00 .selection LDZ ADD2 STA + ( get new value ) .Mouse/x DEI2 .window/x1 LDZ2 SUB2 #0060 SUB2 4// SWP POP ;theme/b1 #00 .selection LDZ ADD2 STA &no-touch-blue DUP2 #0040 NEQ2 ,&no-touch-radio JCN .Mouse/x DEI2 .window/x1 LDZ2 #0050 ADD2 LTH2 ,&no-touch-radio JCN .Mouse/x DEI2 .window/x1 LDZ2 #008c ADD2 GTH2 ,&no-touch-radio JCN - .Mouse/x DEI2 .window/x1 LDZ2 SUB2 #0050 SUB2 STEP8 2/ #0008 DIV2 SWP POP .selection STZ + .Mouse/x DEI2 .window/x1 LDZ2 SUB2 #0050 SUB2 STEP8 2// #0008 DIV2 SWP POP .selection STZ &no-touch-radio POP2 diff --git a/projects/examples/devices/controller.buttons.usm b/projects/examples/devices/controller.buttons.usm @@ -2,6 +2,7 @@ %++ { #0001 ADD2 } %-- { #0001 SUB2 } +%2// { #01 SFT2 } ( devices ) @@ -28,8 +29,8 @@ ;on-frame .Screen/vector DEO2 ( set origin ) - .Screen/width DEI2 #0002 DIV2 .Screen/x DEO2 - .Screen/height DEI2 #0002 DIV2 .Screen/y DEO2 + .Screen/width DEI2 2// .Screen/x DEO2 + .Screen/height DEI2 2// .Screen/y DEO2 ;default_icn .Screen/addr DEO2 #31 .Screen/color DEO diff --git a/projects/examples/devices/datetime.usm b/projects/examples/devices/datetime.usm @@ -1,10 +1,13 @@ ( Dev/Time ) +%2// { #01 SFT2 } +%4// { #02 SFT2 } + %RTN { JMP2r } %MOD { DUP2 DIV MUL SUB } %ABS2 { DUP2 #0f SFT2 EQU #04 JCN #ffff MUL2 } -%SCALEX { #0002 DIV2 .Screen/width DEI2 #0002 DIV2 ADD2 #0040 SUB2 } -%SCALEY { #0002 DIV2 .Screen/height DEI2 #0002 DIV2 ADD2 #0040 SUB2 } +%SCALEX { 2// .Screen/width DEI2 2// ADD2 #0040 SUB2 } +%SCALEY { 2// .Screen/height DEI2 2// ADD2 #0040 SUB2 } %12HOURS { DUP #0c GTH #0c MUL SUB } %LTS2 { #8000 ADD2 SWP2 #8000 ADD2 GTH2 } %GTS2 { #8000 ADD2 SWP2 #8000 ADD2 LTH2 } @@ -55,11 +58,11 @@ BRK #00 SWP SCALEY .needles/sy STZ2 #00 SWP SCALEX .needles/sx STZ2 #00 .DateTime/minute DEI #0002 MUL2 ;table ADD2 LDA2 - #00 SWP #0004 DIV2 #0003 MUL2 #0020 ADD2 SCALEY .needles/my STZ2 - #00 SWP #0004 DIV2 #0003 MUL2 #0020 ADD2 SCALEX .needles/mx STZ2 + #00 SWP 4// #0003 MUL2 #0020 ADD2 SCALEY .needles/my STZ2 + #00 SWP 4// #0003 MUL2 #0020 ADD2 SCALEX .needles/mx STZ2 #00 .DateTime/hour DEI 12HOURS #05 MUL #0002 MUL2 ;table ADD2 LDA2 - #00 SWP #0002 DIV2 #0040 ADD2 SCALEY .needles/hy STZ2 - #00 SWP #0002 DIV2 #0040 ADD2 SCALEX .needles/hx STZ2 + #00 SWP 2// #0040 ADD2 SCALEY .needles/hy STZ2 + #00 SWP 2// #0040 ADD2 SCALEX .needles/hx STZ2 ( needles ) #0080 SCALEX #0080 SCALEY .needles/sx LDZ2 .needles/sy LDZ2 #02 ;draw-line JSR2 @@ -83,8 +86,8 @@ BRK @draw-display ( -- ) - .Screen/height DEI2 #0002 DIV2 #0048 ADD2 .Screen/y DEO2 - .Screen/width DEI2 #0002 DIV2 + .Screen/height DEI2 2// #0048 ADD2 .Screen/y DEO2 + .Screen/width DEI2 2// DUP2 #0020 SUB2 .Screen/x DEO2 ;font-hex #00 .DateTime/hour DEI #0a DIV #08 MUL ADD2 .Screen/addr DEO2 #22 .Screen/color DEO diff --git a/projects/examples/devices/screen.usm b/projects/examples/devices/screen.usm @@ -2,6 +2,7 @@ %RTN { JMP2r } %MOD { DUP2 DIV MUL SUB } +%2// { #01 SFT2 } ( devices ) @@ -24,8 +25,8 @@ #0da4 .System/b DEO2 ( find screen center ) - .Screen/width DEI2 #0002 DIV2 .center/x STZ2 - .Screen/height DEI2 #0002 DIV2 .center/y STZ2 + .Screen/width DEI2 2// .center/x STZ2 + .Screen/height DEI2 2// .center/y STZ2 ( draw ) ;draw-table JSR2 diff --git a/projects/examples/gui/animation.usm b/projects/examples/gui/animation.usm @@ -1,5 +1,9 @@ ( GUI Animation ) +%2// { #01 SFT2 } + +( devices ) + |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 ] @@ -20,8 +24,8 @@ ;on-frame .Screen/vector DEO2 ( starting position ) - .Screen/width DEI2 #0002 DIV2 .dvd/x STZ2 - .Screen/height DEI2 #0002 DIV2 .dvd/y STZ2 + .Screen/width DEI2 2// .dvd/x STZ2 + .Screen/height DEI2 2// .dvd/y STZ2 #21 ;draw-dvd JSR2 diff --git a/projects/examples/gui/label.usm b/projects/examples/gui/label.usm @@ -1,6 +1,7 @@ ( GUI Labels ) %RTN { JMP2r } +%2// { #01 SFT2 } ( devices ) @@ -27,8 +28,8 @@ BRK @draw ( -- ) ( find screen center ) - .Screen/width DEI2 #0002 DIV2 .center/x STZ2 - .Screen/height DEI2 #0002 DIV2 .center/y STZ2 + .Screen/width DEI2 2// .center/x STZ2 + .Screen/height DEI2 2// .center/y STZ2 ( draw ver line ) .center/x LDZ2 .Screen/x DEO2 #0000 .Screen/y DEO2 @@ -61,7 +62,7 @@ RTN @draw-label-middle ( x y color addr -- ) ( load ) .label/addr STZ2 .label/color STZ .Screen/y DEO2 - ( align ) .label/addr LDZ2 ;get-text-length JSR2 #0008 MUL2 #0002 DIV2 SUB2 .Screen/x DEO2 + ( align ) .label/addr LDZ2 ;get-text-length JSR2 #0008 MUL2 2// SUB2 .Screen/x DEO2 .label/addr LDZ2 &loop ( draw ) DUP2 LDA #00 SWP #0008 MUL2 ;font ADD2 .Screen/addr DEO2 .label/color LDZ .Screen/color DEO diff --git a/projects/software/neralie.usm b/projects/software/neralie.usm @@ -85,7 +85,7 @@ JMP2r @arvelie-text ( -- ) - .Screen/width DEI2 #0002 DIV2 #0034 SUB2 .Screen/x DEO2 + .Screen/width DEI2 #01 SFT2 #0034 SUB2 .Screen/x DEO2 .Screen/height DEI2 #0008 SUB2 .Screen/y DEO2 .DateTime/year DEI2 #07d6 SUB2 #000a ;modf JSR2 ;digit JSR2 @@ -97,7 +97,7 @@ JMP2r @neralie-text ( -- ) - .Screen/width DEI2 #0002 DIV2 #0004 SUB2 .Screen/x DEO2 + .Screen/width DEI2 #01 SFT2 #0004 SUB2 .Screen/x DEO2 .neralie/n0123 LDZ2 #03e8 ;modf JSR2 ,digit JSR #0064 ;modf JSR2 ,digit JSR diff --git a/projects/software/orca.usm b/projects/software/orca.usm @@ -14,7 +14,7 @@ %RTN { JMP2r } %++ { #01 ADD } %-- { #01 SUB } %8+ { #0008 ADD2 } -%8* { #0008 MUL2 } %8/ { #0008 DIV2 } +%8* { #0008 MUL2 } %8/ { #03 SFT2 } %MOD { DUP2 DIV MUL SUB } %MOD8 { #07 AND } %MOD2 { #01 AND }