uxn

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

bunnymark.tal (6685B)


      1 ( bunnymark.tal )
      2 	( November 2021, Kira Oakley )
      3 	( March 2022, Devine Lu Linvega )
      4 
      5 |00 @System &vector $2 &pad $6 &r $2 &g $2 &b $2 &debug $1 &halt $1
      6 |20 @Screen &vector $2 &width $2 &height $2 &auto $1 &pad $1 &x $2 &y $2 &addr $2 &pixel $1 &sprite $1
      7 |80 @Controller &vector $2 &button $1 &key $1
      8 |90 @Mouse &vector $2 &x $2 &y $2 &state $1 &wheel $1
      9 |c0 @DateTime &year $2 &month $1 &day $1 &hour $1 &minute $1 &second $1 &dotw $1 &doty $2 &isdst $1
     10 
     11 |0000
     12 
     13 	@frames $2
     14 	@last $1
     15 
     16 |0100
     17 
     18 @on-reset ( -> )
     19 	( | theme )
     20 	#2ce9 .System/r DEO2
     21 	#01c0 .System/g DEO2
     22 	#2ce5 .System/b DEO2
     23 	( | interrupts )
     24 	;on-frame .Screen/vector DEO2
     25 	( | fps label )
     26 	.Screen/width DEI2 #0046 SUB2 .Screen/x DEO2
     27 	#0008 .Screen/y DEO2
     28 	;text/fps #42 <draw-str>
     29 	( | bunnies label )
     30 	#0004 .Screen/x DEO2
     31 	;text/bunnies #42 <draw-str>
     32 	( | instructions label )
     33 	.Screen/width DEI2 #01 SFT2 #0050 SUB2 .Screen/x DEO2
     34 	;text/instructions #43 <draw-str>
     35 	#0028 #0008 #0000 <draw-dec>
     36 	( | seed prng )
     37 	prng-init BRK
     38 
     39 @on-frame ( -> )
     40 	.frames LDZ2k INC2 ROT STZ2
     41 	.DateTime/second DEI .last LDZ EQU ?{
     42 		.DateTime/second DEI .last STZ
     43 		.Screen/width DEI2 #002b SUB2 #0008 .frames LDZ2 <draw-dec>
     44 		#0000 .frames STZ2 }
     45 	( | mouse handling )
     46 	.Mouse/state DEI
     47 	( ) DUP #01 NEQ ?{ add-bunny }
     48 	( ) #02 LTH ?{ remove-bunny }
     49 	( | controller handling )
     50 	.Controller/button DEI
     51 	( ) DUP #01 NEQ ?{ add-bunny }
     52 	( ) #02 LTH ?{ remove-bunny }
     53 	( | clear )
     54 	#0000 DUP2 .Screen/x DEO2
     55 	.Screen/y DEO2
     56 	[ LIT2 80 -Screen/pixel ] DEO
     57 	;sprite/length LDA2 #0000
     58 	&loop ( -- )
     59 		EQU2k ?&bail
     60 		DUP2 <draw-bunny>
     61 		INC2 !&loop
     62 	&bail ( -- )
     63 		POP2 POP2 BRK
     64 
     65 @add-bunny ( -- )
     66 	;sprite/length LDA2
     67 	( | cap bunny count at 65535 )
     68 	DUP2 #ffff EQU2 ?&bail
     69 	( | compute the offset to the beginning of this new bunny's data )
     70 	DUP2 #30 SFT2 ;sprite/array ADD2
     71 	( | populate the new bunny's x/y/xvel/yvel with random values )
     72 	#00 rand OVR2 STA2
     73 	rand #1f AND rand OVR2 INC2 INC2 STA2
     74 	#00 rand #7f AND OVR2 #0004 ADD2 STA2
     75 	#00 rand #7f AND OVR2 #0006 ADD2 STA2
     76 	( | pop ptr to bunny data )
     77 	POP2
     78 	( | write new increased array length )
     79 	INC2 DUP2 ;sprite/length STA2
     80 	( | update label )
     81 	STH2k #0028 #0008 STH2r <draw-dec>
     82 	&bail ( pop sprite/length )
     83 		POP2 JMP2r
     84 
     85 @remove-bunny ( -- )
     86 	;sprite/length LDA2
     87 	( don't let length go below 0 ) ORAk #00 EQU ?&bail
     88 	#0001 SUB2 DUP2 ;sprite/length STA2
     89 	( update label ) STH2k #0028 #0008 STH2r <draw-dec>
     90 	&bail POP2 JMP2r
     91 
     92 (
     93 @|drawing )
     94 
     95 @<draw-bunny> ( idx -- )
     96 	( | compute the offset to the beginning of this bunny's data )
     97 	#30 SFT2 ;sprite/array ADD2
     98 	( | move the sprite by its velocity )
     99 	LDA2k OVR2 #0004 ADD2 LDA2 ADD2 OVR2 STA2
    100 	INC2k INC2 LDA2 OVR2 #0006 ADD2 LDA2 ADD2 OVR2 INC2 INC2 STA2
    101 	( | check for right wall collision + bounce x )
    102 	DUP2 #0004 ADD2 LDA2 #0f SFT2 #0001 EQU2 ?&skip-max-x
    103 	LDA2k #05 SFT2 #0008 ADD2 .Screen/width DEI2 LTH2 ?&skip-max-x
    104 	DUP2 #0004 ADD2 LDA2 #ffff MUL2 OVR2 #0004 ADD2 STA2
    105 	&skip-max-x ( check for left wall collision + bounce x )
    106 		LDA2k #0f SFT2 #0000 EQU2 ?&skip-min-x
    107 		DUP2 #0004 ADD2 LDA2 #ffff MUL2 OVR2 #0004 ADD2 STA2
    108 	&skip-min-x ( check for bottom wall collision + bounce y )
    109 		DUP2 #0006 ADD2 LDA2 #0f SFT2 #0001 EQU2 ?&skip-max-y
    110 		INC2k INC2 LDA2 #05 SFT2 #0010 ADD2 .Screen/height DEI2 LTH2 ?&skip-max-y
    111 		DUP2 #0006 ADD2 LDA2 #ffff MUL2 OVR2 #0006 ADD2 STA2
    112 		!&skip-gravity
    113 	&skip-max-y ( check for top wall collision + bounce x )
    114 		INC2k INC2 LDA2 #0f SFT2 #0000 EQU2 ?&skip-min-y
    115 		DUP2 #0006 ADD2 LDA2 #ffff MUL2 OVR2 #0006 ADD2 STA2
    116 		!&skip-gravity
    117 	&skip-min-y ( apply gravity )
    118 		DUP2 #0006 ADD2 LDA2 #0004 ADD2 OVR2 #0006 ADD2 STA2
    119 	&skip-gravity ( draw the sprite )
    120 		( top ) LDA2k #05 SFT2 .Screen/x DEO2
    121 		INC2 INC2 LDA2 #05 SFT2 .Screen/y DEO2
    122 		( draw ) [ LIT2 15 -Screen/auto ] DEO
    123 		;bunny-chr .Screen/addr DEO2
    124 		[ LIT2 85 -Screen/sprite ] DEO
    125 		[ LIT2 00 -Screen/auto ] DEO
    126 		JMP2r
    127 
    128 @<draw-str> ( x* y* text* color -- )
    129 	,&t STR
    130 	[ LIT2 01 -Screen/auto ] DEO
    131 	&loop ( -- )
    132 		LDAk #20 SUB #00 SWP #30 SFT2 ;font ADD2 .Screen/addr DEO2
    133 		[ LIT2 &t $1 -Screen/sprite ] DEO
    134 		INC2 LDAk ?&loop
    135 	POP2 JMP2r
    136 
    137 @<draw-dec> ( x* y* num* -- )
    138 	[ LIT2 01 -Screen/auto ] DEO
    139 	SWP2 .Screen/y DEO2
    140 	SWP2 .Screen/x DEO2
    141 	#2710 DIV2k DUP <draw-digit>
    142 	MUL2 SUB2 #03e8 DIV2k DUP <draw-digit>
    143 	MUL2 SUB2 #0064 DIV2k DUP <draw-digit>
    144 	MUL2 SUB2 NIP #0a DIVk DUP <draw-digit>
    145 	MUL SUB <draw-digit>
    146 	[ LIT2 00 -Screen/auto ] DEO
    147 	JMP2r
    148 
    149 @<draw-digit> ( num -- )
    150 	#30 SFT #00 SWP ;font/num ADD2 .Screen/addr DEO2
    151 	[ LIT2 41 -Screen/sprite ] DEO
    152 	JMP2r
    153 
    154 (
    155 @|random )
    156 
    157 @prng-init ( -- )
    158 	[ LIT2 00 -DateTime/second ] DEI [ LIT2 00 -DateTime/minute ] DEI #60 SFT2 EOR2 [ LIT2 00 -DateTime/hour ] DEI #c0 SFT2 EOR2 ,prng/x STR2
    159 	[ LIT2 00 -DateTime/hour ] DEI #04 SFT2 [ LIT2 00 -DateTime/day ] DEI #10 SFT2 EOR2 [ LIT2 00 -DateTime/month ] DEI #60 SFT2 EOR2 .DateTime/year DEI2 #a0 SFT2 EOR2 ,prng/y STR2
    160 	JMP2r
    161 
    162 @prng ( -- number* )
    163 	[ LIT2 &x $2 ] DUP2 #50 SFT2 EOR2 DUP2 #03 SFT2 EOR2 [ LIT2 &y $2 ] DUP2 ,&x STR2
    164 	DUP2 #01 SFT2 EOR2 EOR2 ,&y STR2k POP JMP2r
    165 
    166 @rand ( -- number )
    167 	prng ADD JMP2r
    168 	( static string data )
    169 
    170 (
    171 @|assets )
    172 
    173 @text &fps "FPS: $1
    174 	&bunnies "BUNS: $1
    175 	&instructions "CLICK 20 "TO 20 "ADD 20 "BUNNIES! $1
    176 
    177 @font ( atari8.uf1 )
    178 	[
    179 	0000 0000 0000 0000 6060 6060 6000 6000
    180 	6666 6600 0000 0000 006c fe6c 6cfe 6c00
    181 	183e 603c 067c 1800 0066 6c18 3066 4600
    182 	386c 3870 decc 7600 6060 6000 0000 0000
    183 	0e1c 1818 181c 0e00 7038 1818 1838 7000
    184 	0066 3cff 3c66 0000 0018 187e 1818 0000
    185 	0000 0000 0030 3060 0000 007e 0000 0000
    186 	0000 0000 0018 1800 0206 0c18 3060 4000 ] &num [
    187 	3c66 6e76 6666 3c00 1838 1818 1818 7e00
    188 	3c66 060c 1830 7e00 7e0c 180c 0666 3c00
    189 	0c1c 3c6c 7e0c 0c00 7e60 7c06 0666 3c00
    190 	3c60 607c 6666 3c00 7e06 0c18 3030 3000
    191 	3c66 663c 6666 3c00 3c66 663e 060c 3800
    192 	0060 6000 6060 0000 0030 3000 3030 6000
    193 	0c18 3060 3018 0c00 0000 7e00 007e 0000
    194 	6030 180c 1830 6000 3c66 060c 1800 1800
    195 	3c66 6e6a 6e60 3e00 183c 6666 7e66 6600
    196 	7c66 667c 6666 7c00 3c66 6060 6066 3c00
    197 	786c 6666 666c 7800 7e60 607c 6060 7e00
    198 	7e60 607c 6060 6000 3e60 606e 6666 3e00
    199 	6666 667e 6666 6600 7830 3030 3030 7800
    200 	0606 0606 0666 3c00 666c 7870 786c 6600
    201 	6060 6060 6060 7e00 c6ee fed6 c6c6 c600
    202 	6676 7e7e 6e66 6600 3c66 6666 6666 3c00
    203 	7c66 667c 6060 6000 3c66 6666 766c 3600
    204 	7c66 667c 6c66 6600 3c66 603c 0666 3c00
    205 	7e18 1818 1818 1800 6666 6666 6666 3e00
    206 	6666 6666 663c 1800 c6c6 c6d6 feee c600
    207 	6666 3c18 3c66 6600 6666 663c 1818 1800
    208 	7e06 0c18 3060 7e00 7860 6060 6060 7800 ]
    209 
    210 @fill-icn [ ffff ffff ffff ffff ]
    211 
    212 @bunny-chr [
    213 	2466 6600 2424 003c 4200 007e 7e7e 7e7e
    214 	1818 3c3c 1800 0000 ff66 4242 667e 4242 ]
    215 
    216 (
    217 @|memory )
    218 
    219 @sprite &length $2
    220 	&array &x 0600 &y 0500 &xvel 0060 &yvel 0010
    221