uxn

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

commit 708148bb1d9438481fbe8f647354bee58c9c1bd9
parent 3cdabb9d8093c561ec9c83099d4b8b9aafe37ee7
Author: neauoire <aliceffekt@gmail.com>
Date:   Tue, 29 Mar 2022 09:49:30 -0700

(amiga.tal) Added bounce

Diffstat:
Mprojects/examples/demos/amiga.tal | 110+++++++++++++++++++++++++++++++++++++++++++++++--------------------------------
Aprojects/examples/demos/bunnymark.tal | 275+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 341 insertions(+), 44 deletions(-)

diff --git a/projects/examples/demos/amiga.tal b/projects/examples/demos/amiga.tal @@ -5,7 +5,7 @@ |0000 - @ball &x $2 &y $2 + @ball &x $2 &y $2 &vx $2 &vy $2 @timer $1 @frame $1 @@ -13,9 +13,9 @@ ( vectors ) ;on-frame .Screen/vector DEO2 - ( theme ) - #aff0 .System/r DEO2 - #af00 .System/g DEO2 + ( theme ) + #aff0 .System/r DEO2 + #af00 .System/g DEO2 #af00 .System/b DEO2 ( screen size ) #0140 .Screen/width DEO2 @@ -23,11 +23,12 @@ ( inital position ) #0020 .ball/x STZ2 #0020 .ball/y STZ2 - + ( initial velocity ) + #0002 .ball/vx STZ2 + #0000 .ball/vy STZ2 + ( once ) ;make-shadow JSR2 - ;draw-background JSR2 - ;draw-shadow JSR2 BRK @@ -39,44 +40,54 @@ BRK #00 .timer STZ ( 12 frames animation ) .frame LDZ INC DUP #0c NEQ MUL .frame STZ - ;move-ball JSR2 + ,move-ball JSR BRK -@make-shadow ( -- ) +@clear-ball ( -- ) - ;bg ;shadow #0188 ;mcpy JSR2 - #0188 #0000 - &loop - DUP2 ;shadow ADD2 LDA2k #aa55 AND2 SWP2 STA2 - INC2 INC2 GTH2k ,&loop JCN - POP2 POP2 + .ball/x LDZ2 .Screen/x DEO2 + .ball/y LDZ2 .Screen/y DEO2 + #76 .Screen/auto DEO + #0800 + &loop-bg + #40 .Screen/sprite DEO + INC GTHk ,&loop-bg JCN + POP2 JMP2r @move-ball ( -- ) - ( .ball/x LDZ2k INC2 INC2 ROT STZ2 ) - ;draw-ball JSR2 + ,clear-ball JSR + .ball/vy LDZ2k INC2 STH2k ROT STZ2 + .ball/y LDZ2k STH2r ADD2 ,check-flip-vy JSR ROT STZ2 + ,draw-ball JSR JMP2r -@draw-shadow ( -- ) +@check-flip-vy ( y -- y ) + + DUP2 #0028 ADD2 + .Screen/height DEI2 #0028 SUB2 + GTH2 ,&flip JCN ,&else JMP + &flip .ball/vy LDZ2k #ffff EOR2 ( INC2 ) ROT STZ2 + &else + +JMP2r + +@draw-ball ( -- ) + ( shadow ) .ball/x LDZ2 #0008 ADD2 .Screen/x DEO2 .ball/y LDZ2 #0008 ADD2 .Screen/y DEO2 ;shadow .Screen/addr DEO2 #66 .Screen/auto DEO #0700 - &loop-bg - #0f .Screen/sprite DEO - INC GTHk ,&loop-bg JCN + &loop-shadow + #4f .Screen/sprite DEO + INC GTHk ,&loop-shadow JCN POP2 - -JMP2r - -@draw-ball ( -- ) - .frame LDZ ( bg ) DUP #06 DIV INC #05 MUL #40 ADD STH @@ -111,33 +122,44 @@ JMP2r #01 .Screen/auto DEO ;hor-icn .Screen/addr DEO2 .Screen/height DEI2 #04 SFT2 NIP #04 SUB #00 - &ver + &horver #0020 .Screen/x DEO2 #00 OVR #40 SFT2 #0020 ADD2 .Screen/y DEO2 .Screen/width DEI2 #03 SFT2 NIP #08 SUB #00 - &hor + &horhor #0f .Screen/sprite DEO - INC GTHk ,&hor JCN + INC GTHk ,&horhor JCN POP2 - INC GTHk ,&ver JCN + INC GTHk ,&horver JCN POP2 ( ver lines ) #02 .Screen/auto DEO ;ver-icn .Screen/addr DEO2 .Screen/width DEI2 #04 SFT2 NIP #03 SUB #00 - &ver2 + &verver #0027 .Screen/y DEO2 #00 OVR #40 SFT2 #0019 ADD2 .Screen/x DEO2 .Screen/height DEI2 #03 SFT2 NIP #0a SUB #00 - &hor2 + &verhor #0f .Screen/sprite DEO - INC GTHk ,&hor2 JCN + INC GTHk ,&verhor JCN POP2 - INC GTHk ,&ver2 JCN + INC GTHk ,&verver JCN POP2 JMP2r +@make-shadow ( -- ) + + ;bg ;shadow #0188 ;mcpy JSR2 + #0188 #0000 + &loop + DUP2 ;shadow ADD2 LDA2k #aa55 AND2 SWP2 STA2 + INC2 INC2 GTH2k ,&loop JCN + POP2 POP2 + +JMP2r + @mcpy ( src* dst* len* -- ) SWP2 STH2 @@ -150,9 +172,9 @@ JMP2r JMP2r -@hor-icn +@hor-icn 0000 0000 0000 00ff -@ver-icn +@ver-icn 0101 0101 0101 0101 @ball-icn ( 56 x 56 ) @@ -166,10 +188,10 @@ JMP2r e0e0 e000 3c3f 7f7f 0303 0707 0787 fff1 fefe fefc fcfc fcfc 1804 0606 0e0e 0e0e 3e1e 1e1e 1e0e 0f0f fe1c 0003 0303 0303 0000 0080 f1ff fefe 7fff ffff ffff 3f07 f0e0 e0e0 c0c0 8080 3800 070f 0f1f 1f3f 0e0c 0cfc e0c0 c080 0f09 0400 0001 0000 - 0303 c37b 3c3c 9e1e fcfc fcfc f818 040f 0000 0101 0303 078f 80e0 feff fffe fcf8 + 0303 c37b 3c3c 9e1e fcfc fcfc f818 040f 0000 0101 0303 078f 80e0 feff fffe fcf8 3f7f 7f3e 0603 070e 8000 0000 0000 0000 0000 0000 0000 0000 0e1e 0500 0000 0000 0f0f 0f4f 2703 0200 ffe1 c080 030f 1e00 f0e0 00f9 f8c0 0000 3c70 e0c0 0000 0000 - 0000 0000 0000 0000 + 0000 0000 0000 0000 ( 01 ) 0000 0000 0000 0000 0000 0000 0204 0800 0001 0f7c 101c 3fff 00e7 8307 0f3f ff0f 0040 0cdc c083 8101 0000 0000 80a0 c0e4 0000 0000 0000 0000 0000 0003 0103 0307 @@ -183,7 +205,7 @@ JMP2r 0707 c7ff 7838 bc1c f8f8 f0f0 f010 1c1f 0103 0307 070f 0f9f 00e0 fefe fcf8 f0e0 7ffe fe3c 0407 0f1e 0000 0000 4000 0000 0000 0000 0000 0000 0c1e 0400 0000 0000 1f1f 1fdf 2607 0200 cfc1 8001 071f 1c00 e0c0 41fb f080 0000 38f0 e0c0 0000 0000 - 0000 0000 0000 0000 + 0000 0000 0000 0000 ( 02 ) 0000 0000 0000 0000 0000 0000 0000 0001 0001 1ff8 003c fefe 00e7 030f 3f7f 7f0e 0000 1cd8 8003 0303 0000 0000 80c0 c0c4 0000 0000 0000 0000 0000 0103 0307 070f @@ -197,7 +219,7 @@ JMP2r 0f0f cff7 7078 3818 e0e0 e0e0 e020 3c3f 0707 0f0f 1f1f 3fbf 01e1 fdf8 f0f0 e0c0 fefc fc38 000f 1e3c 1000 2000 4000 0000 0000 0000 0000 0000 1c1c 0400 0000 0000 3f3f 3ffe 6407 0300 8f01 0103 0f3f 1800 8080 c3ff e008 0000 78f0 c080 0000 0000 - 0000 0000 0000 0000 + 0000 0000 0000 0000 ( 03 ) 0000 0000 0000 0000 0000 0000 0000 0003 0001 1ef0 207d fcf8 00c7 071f 7ffe 7c0c 0080 1c9a 0407 0707 0000 0000 80c0 80cc 0000 0000 0000 0000 0000 0103 0307 070f @@ -211,7 +233,7 @@ JMP2r 1f1f dfe7 e070 3038 c0c0 c080 8060 7c7f 1f1f 3f3f 3f7f 7f7f 07e7 f1f0 e0c0 8080 fcf8 f830 081f 3e7c 1020 2040 4080 0000 0000 0000 0000 0000 181c 0200 0000 0000 7f7e 3efc 440f 0100 0f00 030f 1f3e 1800 0003 c7f7 c108 0000 f8e0 c080 0000 0000 - 0000 0000 0000 0000 + 0000 0000 0000 0000 ( 04 ) 0000 0000 0000 0000 0000 0000 0000 0103 0001 1ce0 60ff f8f0 0087 0f3f fefc 7800 0080 3c1a 0d0f 0f0f 0000 0000 8040 808c 0000 0000 0000 0000 0000 0103 0307 070e @@ -225,7 +247,7 @@ JMP2r 3f3f ffc7 e060 7030 0000 0000 00e0 fdfe 3f7f 7fff ffff ff7e 0fff e1c0 8080 0001 f8f0 f020 387f fcf8 3020 6040 c080 0000 0000 0000 0000 0000 1818 0200 0000 0000 7c7c 7cb8 400f 0100 0e02 0f1f 3f7c d000 0307 cfe7 0318 8000 f0e0 c000 0000 0000 - 0000 0000 0000 0000 + 0000 0000 0000 0000 ( 05 ) 0000 0000 0000 0000 0000 0000 0001 0307 0001 18c0 e1fb f0e0 0087 1f7e fcf8 7010 0080 7012 0d1f 1f1f 0000 0000 0040 100c 0000 0000 0000 0000 0000 0103 0306 060c @@ -239,7 +261,7 @@ JMP2r 7e7e bec6 c1e1 6130 0000 0101 01e3 fffc ffff ffff fffe fe7c 3fdf 8100 0000 0103 e0e0 c000 79fe fcf0 3060 60c0 c080 0000 0000 0000 0000 0000 3008 0200 0000 0000 f8f8 f8b0 480e 0100 080e 1f3f 7ef8 e100 070f df87 0318 8000 e0c0 8000 0000 0000 - 0000 0000 0000 0000 + 0000 0000 0000 0000 @bg 0000 0000 0000 0000 0000 0000 0307 0f3f @@ -266,6 +288,6 @@ JMP2r 0000 0000 0000 0000 3f1f 0701 0000 0000 ffff ffff 7f3f 0300 ffff ffff ffff ff00 ffff ffff fff8 8000 fcf0 e0c0 0000 0000 - 0000 0000 0000 0000 + 0000 0000 0000 0000 @shadow $0188 diff --git a/projects/examples/demos/bunnymark.tal b/projects/examples/demos/bunnymark.tal @@ -0,0 +1,275 @@ +( bunnymark.tal ) + +( November 2021, Kira Oakley ) +( March 2022, Devine Lu Linvega ) + +|00 @System &vector $2 &pad $6 &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 +|90 @Mouse &vector $2 &x $2 &y $2 &state $1 &wheel $1 +|b0 @Date &year $2 &month $1 &day $1 &hour $1 &minute $1 &second $1 &dotw $1 &doty $2 &isdst $1 + +|0000 + + @frames $2 + @last $1 + +|0100 ( -> ) + + ( set system colors ) + #2ce9 .System/r DEO2 + #01c0 .System/g DEO2 + #2ce5 .System/b DEO2 + + ( interrupts ) + ;on-frame .Screen/vector DEO2 + + ( draw "FPS:" and "BUNNIES:" and instructions labels ) + .Screen/width DEI2 #0046 SUB2 #0008 ;text/fps #42 ;draw-str JSR2 + #0004 #0008 ;text/bunnies #42 ;draw-str JSR2 + .Screen/width DEI2 #0002 DIV2 #0050 SUB2 #0008 ;text/instructions #43 ;draw-str JSR2 + #0028 #0008 #0000 ;draw-dec JSR2 + + ( seed prng ) + #04 ;rand/a STA + +BRK + +@on-frame ( -> ) + + + ( frames++ ) + .frames LDZ2k INC2 ROT STZ2 + .Date/second DEI .last LDZ EQU ,&post-fps-update JCN + ( fps update ) + ( update last-secs ) .Date/second DEI .last STZ + ( update fps label ) .Screen/width DEI2 #002b SUB2 #0008 .frames LDZ2 ;draw-dec JSR2 + ( reset frames counter ) #0000 .frames STZ2 + + &post-fps-update + ( mouse input to add/remove bunnies ) + .Mouse/state DEI #01 EQU ,&add JCN + .Mouse/state DEI #01 GTH ,&remove JCN + ,&done JMP + &add + ;add-bunny JSR2 ,&done JMP + &remove + ;remove-bunny JSR2 ,&done JMP + &done + + ( loop from 0 to ;sprite/length to make all ;draw-bunny calls ) + [ ;sprite/length LDA2 ] #0000 + &loop + EQU2k ,&bail JCN + DUP2 ,draw-bunny JSR + INC2 ,&loop JMP + &bail + POP2 POP2 + +BRK + +@draw-bunny ( idx -- ) + + ( compute the offset to the beginning of this bunny's data ) + [ #30 SFT2 ;sprite/array ADD2 ] + + ( clear the old sprite location ) + ( top ) + [ LDA2k ] #05 SFT2 .Screen/x DEO2 + [ DUP2 #0002 ADD2 LDA2 ] #05 SFT2 .Screen/y DEO2 + #00 ;draw-sprite JSR2 + + ( move the sprite by its velocity ) + [ LDA2k ] [ OVR2 #0004 ADD2 LDA2 ] ADD2 OVR2 STA2 + [ DUP2 #0002 ADD2 LDA2 ] [ OVR2 #0006 ADD2 LDA2 ] ADD2 OVR2 #0002 ADD2 STA2 + + ( check for right wall collision + bounce x ) + [ DUP2 #0004 ADD2 LDA2 ] #0f SFT2 #0001 EQU2 ,&skip-max-x JCN + [ LDA2k ] #05 SFT2 #0008 ADD2 [ .Screen/width DEI2 ] LTH2 ,&skip-max-x JCN + [ DUP2 #0004 ADD2 LDA2 ] #ffff MUL2 [ OVR2 #0004 ADD2 STA2 ] + &skip-max-x + ( check for bottom wall collision + bounce y ) + [ DUP2 #0006 ADD2 LDA2 ] #0f SFT2 #0001 EQU2 ,&skip-max-y JCN + [ DUP2 #0002 ADD2 LDA2 ] #05 SFT2 #0008 ADD2 [ .Screen/height DEI2 ] LTH2 ,&skip-max-y JCN + [ DUP2 #0006 ADD2 LDA2 ] #ffff MUL2 [ OVR2 #0006 ADD2 STA2 ] + &skip-max-y + ( check for left wall collision + bounce x ) + [ LDA2k ] #0f SFT2 #0000 EQU2 ,&skip-min-x JCN + [ DUP2 #0004 ADD2 LDA2 ] #ffff MUL2 [ OVR2 #0004 ADD2 STA2 ] + &skip-min-x + ( check for top wall collision + bounce x ) + [ DUP2 #0002 ADD2 LDA2 ] #0f SFT2 #0000 EQU2 ,&skip-min-y JCN + [ DUP2 #0006 ADD2 LDA2 ] #ffff MUL2 [ OVR2 #0006 ADD2 STA2 ] + &skip-min-y + + ( ( apply gravity ) ) + [ DUP2 #0006 ADD2 LDA2 ] #0004 ADD2 OVR2 #0006 ADD2 STA2 + + ( draw the sprite ) + ( top ) + [ LDA2k ] #05 SFT2 .Screen/x DEO2 + [ #0002 ADD2 LDA2 ] #05 SFT2 .Screen/y DEO2 + #85 ,draw-sprite JSR + +JMP2r + +@draw-sprite ( color -- ) + + #15 .Screen/auto DEO + ;bunny-chr .Screen/addr DEO2 + .Screen/sprite DEO + #00 .Screen/auto DEO + +JMP2r + +@add-bunny ( -- ) + + ;sprite/length LDA2 + ( cap bunny count at 65535 ) + DUP2 #ffff EQU2 ,&bail JCN + ( compute the offset to the beginning of this new bunny's data ) + DUP2 #30 SFT2 ;sprite/array ADD2 + ( populate the new bunny's x/y/xvel/yvel with random values ) + #00 [ ;rand JSR2 ] OVR2 STA2 + [ ;rand JSR2 #1f AND ] [ ;rand JSR2 ] OVR2 #0002 ADD2 STA2 + #00 [ ;rand JSR2 #7f AND ] OVR2 #0004 ADD2 STA2 + #00 [ ;rand JSR2 #7f AND ] OVR2 #0006 ADD2 STA2 + ( pop ptr to bunny data ) POP2 + ( write new increased array length ) + INC2 DUP2 ;sprite/length STA2 + ( update label ) + STH2k #0028 #0008 STH2r ;draw-dec JSR2 + &bail + ( pop sprite/length ) POP2 + +JMP2r + +@draw-str ( x* y* text* color -- ) + + #01 .Screen/auto DEO + STH + SWP2 .Screen/y DEO2 + SWP2 .Screen/x DEO2 + &loop + LDAk #20 SUB #00 SWP #30 SFT2 ;font ADD2 .Screen/addr DEO2 + STHkr .Screen/sprite DEO + INC2 LDAk ,&loop JCN + POP2 + STHr POP + #00 .Screen/auto DEO + +JMP2r + +@draw-dec ( x* y* num* -- ) + + #01 .Screen/auto DEO + SWP2 .Screen/y DEO2 + SWP2 .Screen/x DEO2 + #2710 DIV2k DUP2 NIP ,&digit JSR MUL2 SUB2 + #03e8 DIV2k DUP2 NIP ,&digit JSR MUL2 SUB2 + #0064 DIV2k DUP2 NIP ,&digit JSR MUL2 SUB2 NIP + #0a DIVk DUP ,&digit JSR MUL SUB + ,&digit JSR + #00 .Screen/auto DEO + +JMP2r + &digit ( num -- ) + #30 SFT #00 SWP ;font/num ADD2 .Screen/addr DEO2 + #41 .Screen/sprite DEO + JMP2r + +@remove-bunny ( -- ) + + ;sprite/length LDA2 + ( don't let length go below 0 ) + DUP2 #0000 EQU2 ,&bail JCN + ( clear the old sprite location ) + DUP2 #0001 SUB2 #30 SFT2 ;sprite/array ADD2 + ( top ) + [ LDA2k ] #05 SFT2 .Screen/x DEO2 + [ DUP2 #0002 ADD2 LDA2 ] #05 SFT2 .Screen/y DEO2 + ( clear ) + #00 ;draw-sprite JSR2 + POP2 + #0001 SUB2 DUP2 ;sprite/length STA2 + ( update label ) + STH2k #0028 #0008 STH2r ;draw-dec JSR2 + &bail + POP2 + +JMP2r + +( PRNG code taken from flappy.tal -- thanks! ) + +@rand ( -- number ) + + ( local vars ) + #04 JMP + &x $1 &y $1 &z $1 &a $1 + ( 8-bit PRNG https://github.com/edrosten/8bit_rng ) + ( t = x ^ (x << 4) ) + ,&x LDR DUP #40 SFT EOR + ( x = y ) + ,&y LDR ,&x STR + ( y = z ) + ,&z LDR ,&y STR + ( z = a ) + ,&a LDR DUP ,&z STR + ( a = z ^ t ^ (z >> 1) ^ (t << 1) ) + DUP #10 SFT EOR SWP DUP #01 SFT EOR EOR + DUP ,&a STR + +JMP2r + +( static string data ) + +@text + &fps "FPS: 00 + &bunnies "BUNS: 00 + &instructions "CLICK 20 "TO 20 "ADD 20 "BUNNIES! 00 + +@font ( atari8.uf1 ) + 0000 0000 0000 0000 6060 6060 6000 6000 + 6666 6600 0000 0000 006c fe6c 6cfe 6c00 + 183e 603c 067c 1800 0066 6c18 3066 4600 + 386c 3870 decc 7600 6060 6000 0000 0000 + 0e1c 1818 181c 0e00 7038 1818 1838 7000 + 0066 3cff 3c66 0000 0018 187e 1818 0000 + 0000 0000 0030 3060 0000 007e 0000 0000 + 0000 0000 0018 1800 0206 0c18 3060 4000 + &num + 3c66 6e76 6666 3c00 1838 1818 1818 7e00 + 3c66 060c 1830 7e00 7e0c 180c 0666 3c00 + 0c1c 3c6c 7e0c 0c00 7e60 7c06 0666 3c00 + 3c60 607c 6666 3c00 7e06 0c18 3030 3000 + 3c66 663c 6666 3c00 3c66 663e 060c 3800 + 0060 6000 6060 0000 0030 3000 3030 6000 + 0c18 3060 3018 0c00 0000 7e00 007e 0000 + 6030 180c 1830 6000 3c66 060c 1800 1800 + 3c66 6e6a 6e60 3e00 183c 6666 7e66 6600 + 7c66 667c 6666 7c00 3c66 6060 6066 3c00 + 786c 6666 666c 7800 7e60 607c 6060 7e00 + 7e60 607c 6060 6000 3e60 606e 6666 3e00 + 6666 667e 6666 6600 7830 3030 3030 7800 + 0606 0606 0666 3c00 666c 7870 786c 6600 + 6060 6060 6060 7e00 c6ee fed6 c6c6 c600 + 6676 7e7e 6e66 6600 3c66 6666 6666 3c00 + 7c66 667c 6060 6000 3c66 6666 766c 3600 + 7c66 667c 6c66 6600 3c66 603c 0666 3c00 + 7e18 1818 1818 1800 6666 6666 6666 3e00 + 6666 6666 663c 1800 c6c6 c6d6 feee c600 + 6666 3c18 3c66 6600 6666 663c 1818 1800 + 7e06 0c18 3060 7e00 7860 6060 6060 7800 + +@bunny-chr + 2466 6600 2424 003c 4200 007e 7e7e 7e7e + 1818 3c3c 1800 0000 ff66 4242 667e 4242 + +( beginning of sprite pixel data + array ) + +@sprite + &length $2 + &array + &x 0600 + &y 0500 + &xvel 0060 + &yvel 0010