mirror of
https://git.sr.ht/~rabbits/uxn
synced 2024-11-05 05:45:05 +00:00
Minor optimizations to examples
This commit is contained in:
parent
250aecc920
commit
370c3a60c9
4 changed files with 54 additions and 52 deletions
|
@ -14,7 +14,7 @@
|
|||
|
||||
|0100
|
||||
( variables )
|
||||
#01 .direction STZ
|
||||
[ LIT2 01 -direction ] STZ
|
||||
( vectors )
|
||||
;on-frame .Screen/vector DEO2
|
||||
( theme )
|
||||
|
@ -89,7 +89,7 @@ JMP2r
|
|||
.timer LDZk INC DUP ROT STZ #06 EQU ?&pull
|
||||
|
||||
!&pass
|
||||
&pull #00 .timer STZ .ball/vy LDZ2k INC2 STH2k ROT STZ2 !&end
|
||||
&pull [ LIT2 00 -timer ] STZ .ball/vy LDZ2k INC2 STH2k ROT STZ2 !&end
|
||||
&pass .ball/vy LDZ2k STH2k ROT STZ2 !&end
|
||||
&end .ball/y LDZ2k STH2r ADD2 check-flip-vy ROT STZ2
|
||||
|
||||
|
|
|
@ -83,8 +83,8 @@
|
|||
|
||||
@<cover-pattern> ( addr* -- )
|
||||
.Screen/addr DEO2
|
||||
.Screen/height DEI2 #03 SFT2 NIP ,&h STR
|
||||
.Screen/width DEI2 #03 SFT2 NIP ,&w STR
|
||||
.Screen/height DEI2 #03 SFT2 ,&h STR POP
|
||||
.Screen/width DEI2 #03 SFT2 ,&w STR POP
|
||||
[ LIT &h $1 ] #00
|
||||
&ver ( -- )
|
||||
#00 OVR #30 SFT2 .Screen/y DEO2
|
||||
|
@ -103,6 +103,7 @@
|
|||
.Mouse/x DEI2 ,<draw-cursor>/x STR2
|
||||
.Mouse/y DEI2 ,<draw-cursor>/y STR2
|
||||
.Screen/addr DEO2
|
||||
( >> )
|
||||
|
||||
@<draw-cursor> ( color -- )
|
||||
[ LIT2 &x $2 ] .Screen/x DEO2
|
||||
|
|
|
@ -2,14 +2,13 @@
|
|||
|
||||
|00 @System &vector $2 &wst $1 &rst $1 &eaddr $2 &ecode $1 &pad $1 &r $2 &g $2 &b $2 &debug $1 &halt $1
|
||||
|20 @Screen &vector $2 &width $2 &height $2 &auto $1 &pad $1 &x $2 &y $2 &addr $2 &pixel $1 &sprite $1
|
||||
|000
|
||||
|
||||
|0000
|
||||
|
||||
@timer $1
|
||||
@cube &v0 $8 &v4 $8
|
||||
@center &x $2 &y $2
|
||||
@timer $1
|
||||
|
||||
|0100
|
||||
|100
|
||||
|
||||
@on-reset ( -> )
|
||||
( | theme )
|
||||
|
@ -23,43 +22,45 @@
|
|||
;on-frame .Screen/vector DEO2
|
||||
|
||||
@on-frame ( -> )
|
||||
[ LIT &f $1 ] INCk ,&f STR
|
||||
DUP #01 AND ?{ POP BRK }
|
||||
#01 SFT .timer STZ
|
||||
( | clear )
|
||||
#0000 DUP2 .Screen/x DEO2
|
||||
.Screen/y DEO2
|
||||
[ LIT2 80 -Screen/pixel ] DEO
|
||||
( | draw )
|
||||
.timer LDZk INC SWP STZ
|
||||
<draw-cube>
|
||||
BRK
|
||||
|
||||
@<draw-cube> ( frame -- )
|
||||
( | create box )
|
||||
#0800
|
||||
&loop ( -- )
|
||||
&>loop ( -- )
|
||||
STHk [ LIT2 00 -timer ] LDZ #00 STHkr INC #07 AND #60 SFT ADD2 #00ff AND2 ;table ADD2 LDA #01 SFT #00 .timer LDZ #00 STHkr #60 SFT ADD2 #00ff AND2 ;table ADD2 LDA #02 SFT #00 STHkr #62 SFT2 ADD2 .cube/v0 STHr DUP ADD ADD STZ2
|
||||
INC GTHk ?&loop
|
||||
INC GTHk ?&>loop
|
||||
POP2
|
||||
( | vertices )
|
||||
#0800
|
||||
&ver-loop ( -- )
|
||||
DUP DUP ADD .cube ADD LDZ2 <draw-vertex>
|
||||
INC GTHk ?&ver-loop
|
||||
&>ver-loop ( -- )
|
||||
DUP DUP ADD LDZ2 <draw-vertex>
|
||||
INC GTHk ?&>ver-loop
|
||||
POP2
|
||||
( lines ) #0400
|
||||
&line-loop ( -- )
|
||||
&>line-loop ( -- )
|
||||
STHk .cube/v0 STHkr DUP ADD ADD .cube/v0 STHkr INC #03 AND DUP ADD ADD <draw-edge>
|
||||
.cube/v0 STHkr DUP ADD ADD .cube/v4 STHkr DUP ADD ADD <draw-edge>
|
||||
.cube/v4 STHkr DUP ADD ADD .cube/v4 STHr INC #03 AND DUP ADD ADD <draw-edge>
|
||||
INC GTHk ?&line-loop
|
||||
INC GTHk ?&>line-loop
|
||||
POP2 JMP2r
|
||||
|
||||
@<draw-edge> ( a b -- )
|
||||
STH STH
|
||||
STH
|
||||
STH
|
||||
( ) #00 STHkr LDZ .center/x LDZ2 ADD2
|
||||
( ) #00 STHr INC LDZ .center/y LDZ2 ADD2
|
||||
( ) #00 STHkr LDZ .center/x LDZ2 ADD2
|
||||
( ) #00 STHr INC LDZ .center/y LDZ2 ADD2 #05 <draw-line>
|
||||
JMP2r
|
||||
( ) #00 STHr INC LDZ .center/y LDZ2 ADD2 #05 !<draw-line>
|
||||
|
||||
@<draw-vertex> ( x y -- )
|
||||
#00 SWP #0004 SUB2 .center/y LDZ2 ADD2 .Screen/y DEO2
|
||||
|
@ -86,10 +87,12 @@
|
|||
[ LIT2 &y $2 ] EQU2 [ LIT2 &color $1 -Screen/pixel ] DEO
|
||||
AND ?&end
|
||||
STH2kr DUP2 ADD2 DUP2 ,&dy LDR2 lts2 ?&skipy
|
||||
STH2r ,&dy LDR2 ADD2 STH2 ,&x2 LDR2 [ LIT2 &sx $2 ] ADD2 ,&x2 STR2
|
||||
STH2r ,&dy LDR2 ADD2 STH2
|
||||
,&x2 LDR2 [ LIT2 &sx $2 ] ADD2 ,&x2 STR2
|
||||
&skipy ( -- )
|
||||
,&dx LDR2 gts2 ?&while
|
||||
STH2r ,&dx LDR2 ADD2 STH2 ,&y2 LDR2 [ LIT2 &sy $2 ] ADD2 ,&y2 STR2
|
||||
STH2r ,&dx LDR2 ADD2 STH2
|
||||
,&y2 LDR2 [ LIT2 &sy $2 ] ADD2 ,&y2 STR2
|
||||
!&while
|
||||
&end POP2r JMP2r
|
||||
|
||||
|
|
|
@ -3,12 +3,11 @@
|
|||
|00 @System &vector $2 &pad $6 &r $2 &g $2 &b $2
|
||||
|20 @Screen &vector $2 &width $2 &height $2 &auto $1 &pad $1 &x $2 &y $2 &addr $2 &pixel $1 &sprite $1
|
||||
|80 @Controller &vector $2 &button $1 &key $1
|
||||
|
||||
|0000
|
||||
|000
|
||||
|
||||
@hello &x $2 &y $2
|
||||
|
||||
|0100
|
||||
|100
|
||||
|
||||
@on-reset ( -> )
|
||||
( | theme )
|
||||
|
@ -17,41 +16,40 @@
|
|||
#c0f7 .System/b DEO2
|
||||
( | vectors )
|
||||
;on-frame .Screen/vector DEO2
|
||||
( | set origin ) .Screen/width DEI2 #01 SFT2 .hello/x STZ2
|
||||
( | set origin )
|
||||
.Screen/width DEI2 #01 SFT2 .hello/x STZ2
|
||||
.Screen/height DEI2 #01 SFT2 .hello/y STZ2
|
||||
[ LIT2 16 -Screen/auto ] DEO
|
||||
#00 on-frame/draw BRK
|
||||
#00 !on-frame/draw
|
||||
|
||||
@on-frame ( -> )
|
||||
.Controller/button DEI DUP ?{ POP BRK }
|
||||
( | clear )
|
||||
[ LIT2 40 -Screen/sprite ] DEO
|
||||
( flip ) #ff EOR
|
||||
( | movement )
|
||||
DUP #10 AND #00 EQU ?{
|
||||
DUP #10 AND ?{
|
||||
.hello/y LDZ2k #0001 SUB2 ROT STZ2 }
|
||||
DUP #20 AND #00 EQU ?{
|
||||
DUP #20 AND ?{
|
||||
.hello/y LDZ2k INC2 ROT STZ2 }
|
||||
DUP #40 AND #00 EQU ?{
|
||||
DUP #40 AND ?{
|
||||
.hello/x LDZ2k #0001 SUB2 ROT STZ2 }
|
||||
DUP #80 AND #00 EQU ?{
|
||||
DUP #80 AND ?{
|
||||
.hello/x LDZ2k INC2 ROT STZ2 }
|
||||
&draw ( button -> )
|
||||
.hello/x LDZ2 STH2k .Screen/x DEO2
|
||||
.hello/y LDZ2 STH2k .Screen/y DEO2
|
||||
;hello-chr .Screen/addr DEO2
|
||||
[ LIT2 c1 -Screen/sprite ] DEOk
|
||||
DEO
|
||||
( draw slime ) STH2r .Screen/y DEO2
|
||||
STH2r .Screen/x DEO2
|
||||
[ LIT2 c1 -Screen/sprite ] DEOk DEO
|
||||
( | draw slime )
|
||||
[ LITr -Screen/y ] DEO2r
|
||||
[ LITr -Screen/x ] DEO2r
|
||||
;slime-icn .Screen/addr DEO2
|
||||
get-slime .Screen/sprite DEOk
|
||||
DEO
|
||||
get-slime .Screen/sprite DEOk DEO
|
||||
BRK
|
||||
|
||||
@get-slime ( button -- color )
|
||||
#0f AND DUP #01 NEQ ?{ POP #05 JMP2r }
|
||||
DUP #02 NEQ ?{ POP #0a JMP2r }
|
||||
POP #0f JMP2r
|
||||
DUP #01 AND ?{ POP #05 JMP2r }
|
||||
#02 AND ?{ #0a JMP2r }
|
||||
#0f JMP2r
|
||||
|
||||
@hello-chr [
|
||||
0007 1820 2040 4044 0000 071f 1f3f 3f3b
|
||||
|
|
Loading…
Reference in a new issue