uxn

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

launcher.tal (10653B)


      1 ( launcher )
      2 
      3 |00 @System     &vector $2 &wst      $1 &rst    $1 &pad    $4 &r      $2 &g      $2 &b    $2 &debug  $1 &halt $1
      4 |10 @Console    &vector $2 &read     $1 &pad    $5 &write  $1 &error  $1
      5 |20 @Screen     &vector $2 &width    $2 &height $2 &auto   $1 &pad $1 &x      $2 &y      $2 &addr $2 &pixel $1 &sprite $1
      6 |30 @Audio0     &vector $2 &position $2 &output $1 &pad    $3 &adsr   $2 &length $2 &addr $2 &volume $1 &pitch $1
      7 |80 @Controller &vector $2 &button   $1 &key    $1
      8 |90 @Mouse      &vector $2 &x        $2 &y      $2 &state  $1 &pad    $3 &scrollx $2 &scrolly $2
      9 |a0 @File       &vector $2 &success  $2 &stat   $2 &delete $1 &append $1 &name $2 &length $2 &read $2 &write $2
     10 |c0 @DateTime   &year   $2 &month    $1 &day    $1 &hour   $1 &minute $1 &second $1 &dotw $1 &doty $2 &isdst $1
     11 
     12 ( variables )
     13 
     14 |0000
     15 
     16 @pointer
     17 	&x  $2 &y  $2
     18 @browser
     19 	&x $2 &y $2 &x2 $2 &y2 $2
     20 	&sel $1 &last $1 &scroll $1
     21 	&lines $1
     22 
     23 ( init )
     24 
     25 |0100 ( -> )
     26 
     27 	( theme )
     28 	#f079 .System/r DEO2
     29 	#f0c2 .System/g DEO2
     30 	#f0a4 .System/b DEO2
     31 
     32 	( vectors )
     33 	;on-frame .Screen/vector DEO2
     34 	;on-button .Controller/vector DEO2
     35 	;on-mouse .Mouse/vector DEO2
     36 
     37 	( resize )
     38 	#0200 .Screen/width DEO2
     39 	#0140 .Screen/height DEO2
     40 
     41 	( asma debugger )
     42 	#0d ;asma/log-level STA
     43 
     44 	;asma-heap ;heap STA2
     45 
     46 	( setup synth )
     47 	#0102 .Audio0/adsr DEO2
     48 	;sin-pcm .Audio0/addr DEO2
     49 	#0100 .Audio0/length DEO2
     50 	#dd .Audio0/volume DEO ( TODO: turn ON )
     51 
     52 	( place )
     53 	#0088 .browser/x STZ2
     54 	#0010 .browser/y STZ2
     55 	.Screen/height DEI2 #33 SFT2 #0011 SUB2 .browser/y2 STZ2
     56 
     57 	( theme support )
     58 	;load-theme JSR2
     59 
     60 	( draw mascot )
     61 	#0010 #0010 #0060 #0060 ;mascot-icn #01 ;draw-icn JSR2
     62 
     63 	;load-dir JSR2
     64 
     65 	( force selection )
     66 	#ff .browser/last STZ
     67 	#00 ;select-file JSR2
     68 
     69 BRK
     70 
     71 @on-frame ( -> )
     72 
     73 	( unused )
     74 
     75 BRK
     76 
     77 @on-mouse ( -> )
     78 
     79 	;pointer-icn .Screen/addr DEO2
     80 	( clear last cursor )
     81 	.pointer/x LDZ2 .Screen/x DEO2
     82 	.pointer/y LDZ2 .Screen/y DEO2
     83 	#40 .Screen/sprite DEO
     84 
     85 	( draw new cursor )
     86 	.Mouse/x DEI2 DUP2 .pointer/x STZ2 .Screen/x DEO2
     87 	.Mouse/y DEI2 DUP2 .pointer/y STZ2 .Screen/y DEO2
     88 	#41 .Mouse/state DEI #01 EQU ADD .Screen/sprite DEO
     89 
     90 	( wheel )
     91 	.Mouse/scrolly INC DEI
     92 	DUP #ff NEQ ,&no-up JCN
     93 		.browser/scroll LDZ #00 EQU ,&no-up JCN
     94 		DUP .browser/scroll LDZ ADD ;scroll-to JSR2
     95 		&no-up
     96 	DUP #01 NEQ ,&no-down JCN
     97 		.browser/scroll LDZ .browser/lines LDZ EQU ,&no-down JCN
     98 		DUP .browser/scroll LDZ ADD ;scroll-to JSR2
     99 		&no-down
    100 	POP
    101 
    102 	( within browser )
    103 	.Mouse/y DEI2 .browser/y LDZ2 LTH2 ,&outside JCN
    104 	.Mouse/y DEI2 .browser/y2 LDZ2 #0010 SUB2 GTH2 ,&outside JCN
    105 	( select choice )
    106 	.Mouse/y DEI2 .browser/y LDZ2 SUB2
    107 		#04 SFT2 NIP .browser/scroll LDZ ADD ;select-file JSR2
    108 	( run choice )
    109 	.Mouse/state DEI #00 EQU ,&no-click JCN
    110 		.browser/sel LDZ ;run-file JSR2
    111 		&no-click
    112 	&outside
    113 
    114 BRK
    115 
    116 @on-button ( -> )
    117 
    118 	( controller )
    119 	.Controller/button DEI
    120 	DUP #10 NEQ ,&no-up JCN
    121 		.browser/sel LDZ #00 EQU ,&no-up JCN
    122 		.browser/sel LDZ #01 SUB ;select-file JSR2
    123 		;follow-selection JSR2
    124 		POP BRK
    125 		&no-up
    126 	DUP #20 NEQ ,&no-down JCN
    127 		.browser/sel LDZ INC .browser/lines LDZ EQU ,&no-down JCN
    128 		.browser/sel LDZ INC ;select-file JSR2
    129 		;follow-selection JSR2
    130 		POP BRK
    131 		&no-down
    132 	DUP #01 NEQ ,&no-a JCN
    133 		.browser/sel LDZ ;run-file JSR2
    134 		POP BRK
    135 		&no-a
    136 	POP
    137 	( keyboard )
    138 	.Controller/key DEI
    139 	DUP #0d NEQ ,&no-enter JCN
    140 		.browser/sel LDZ ;run-file JSR2
    141 		POP BRK
    142 		&no-enter
    143 	POP
    144 
    145 BRK
    146 
    147 @load-dir ( -- )
    148 
    149 	;dir/path .File/name DEO2
    150 	#1000 .File/length DEO2
    151 	;dir/data .File/read DEO2
    152 	.File/success DEI2 ;dir/length STA2
    153 	#00 .browser/lines STZ
    154 
    155 	( split with null-char )
    156 	;dir/data
    157 	&while
    158 		LDAk #1f GTH ,&no-lb JCN
    159 			( split ) STH2k #00 STH2r STA
    160 			( count lines ) .browser/lines LDZk INC SWP STZ
    161 			&no-lb
    162 		INC2 LDAk ,&while JCN
    163 	POP2
    164 
    165 JMP2r
    166 
    167 @select-file ( id -- )
    168 
    169 	( has changed )
    170 	DUP .browser/last LDZ NEQ ,&has-changed JCN
    171 		POP JMP2r
    172 		&has-changed
    173 	( beyond )
    174 	DUP .browser/lines LDZ LTH ,&valid JCN
    175 		POP JMP2r
    176 		&valid
    177 
    178 	clear-browser
    179 	DUP .browser/sel STZ
    180 	DUP .browser/last STZ
    181 		#30 ADD .Audio0/pitch DEO
    182 	draw-browser
    183 
    184 	( draw mascot )
    185 	#0010 #0010 #0060 #0060
    186 	;mascot-icn .browser/sel LDZ #03 AND #00 SWP #0480 MUL2 ADD2 #01
    187 		;draw-icn JSR2
    188 
    189 	( draw position )
    190 	#06 .Screen/auto DEO
    191 	#0010 .Screen/x DEO2
    192 	#0080 .Screen/y DEO2
    193 	.browser/sel LDZ #02 ;draw-byte JSR2
    194 	LIT "/ #02 ;draw-char JSR2
    195 	.browser/lines LDZ #01 SUB #02 ;draw-byte JSR2
    196 	#00 .Screen/auto DEO
    197 
    198 JMP2r
    199 
    200 @follow-selection ( -- )
    201 
    202 	.browser/y2 LDZ2 .browser/y LDZ2 SUB2 #04 SFT2 NIP .browser/sel LDZ .browser/scroll LDZ SUB
    203 	GTHk ,&no-down JCN
    204 		.browser/scroll LDZ INC ,scroll-to JSR
    205 		&no-down
    206 	DUP2 SWP LTH ,&no-up JCN
    207 		.browser/sel LDZ ,scroll-to JSR
    208 		&no-up
    209 	POP2
    210 
    211 JMP2r
    212 
    213 @scroll-to ( line -- )
    214 
    215 	STH
    216 	( more lines than visible )
    217 	.browser/lines LDZ .browser/y2 LDZ2 .browser/y LDZ2 SUB2 #04 SFT2 NIP
    218 	GTHk ,&can-scroll JCN
    219 		POPr POP2 JMP2r
    220 		&can-scroll
    221 	( less than max scroll )
    222 	SUB INC STHkr GTH ,&valid-scroll JCN
    223 		POPr JMP2r
    224 		&valid-scroll
    225 	clear-browser
    226 	STHr .browser/scroll STZ
    227 	draw-browser
    228 
    229 JMP2r
    230 
    231 @run-file ( id -- )
    232 
    233 	( release inputs )
    234 	#0000 .Controller/button DEO2
    235 	#00 .Mouse/state DEO
    236 
    237 	;get-entry JSR2 LDA2k LIT2 "?? NEQ2 ?&size-ok
    238 		POP2 ;error-txt !pstr
    239 		&size-ok
    240 	#0005 ADD2
    241 	DUP2 ;check-rom JSR2 ,&valid JCN
    242 		( check if tal file )
    243 		DUP2 ;scap JSR2 #0004 SUB2 ;&tal-ext ;scmp JSR2 #01 NEQ ,&no-tal JCN
    244 			( assemble tal file )
    245 			DUP2 ;&output-path ;scpy JSR2
    246 			;&rom-ext ;&output-path ;scat JSR2
    247 			;&output-path ;asma-assemble-file JSR2
    248 			;load-dir JSR2
    249 			;redraw JSR2
    250 			JMP2r
    251 			&no-tal
    252 		POP2 JMP2r
    253 		&valid
    254 	;load-rom JSR2
    255 
    256 JMP2r
    257 	&tal-ext ".tal $1
    258 	&rom-ext ".rom $1
    259 	&output-path $20
    260 
    261 @redraw ( -- )
    262 
    263 	( force selection )
    264 	#ff .browser/last STZ
    265 	#00 ;select-file JSR2
    266 
    267 JMP2r
    268 
    269 @clear-browser ( -- )
    270 
    271 	#0000
    272 	DUP2 .Screen/x DEO2
    273 	.Screen/y DEO2
    274 	#80 .Screen/pixel DEO
    275 
    276 JMP2r
    277 
    278 @draw-browser ( mask -- )
    279 
    280 	( when empty )
    281 	.browser/lines LDZ #01 EQU ;draw-browser-empty JCN2
    282 
    283 	( draw hand )
    284 	.browser/x LDZ2 #0018 SUB2 .browser/y LDZ2
    285 	.browser/sel LDZ .browser/scroll LDZ SUB #00 SWP #40 SFT2 ADD2
    286 	#0010 #0010 ;hand-icn #02 ;draw-icn JSR2
    287 	( draw files )
    288 	.browser/y2 LDZ2 .browser/y LDZ2 SUB2 #04 SFT2 NIP #00
    289 	&loop
    290 		( reached end )
    291 		INCk .browser/lines LDZ GTH ,&end JCN
    292 		( has file )
    293 		.browser/x LDZ2 .Screen/x DEO2
    294 		#00 OVR #40 SFT2 .browser/y LDZ2 ADD2 .Screen/y DEO2
    295 		DUP .browser/scroll LDZ ADD ;get-entry JSR2
    296 			DUP2 ;get-type JSR2 ;draw-type JSR2
    297 			#01 ;draw-str JSR2
    298 		INC GTHk ,&loop JCN
    299 		&end
    300 	POP2
    301 
    302 JMP2r
    303 
    304 @draw-browser-empty ( mask -- )
    305 
    306 	POP
    307 	.browser/x LDZ2 .Screen/x DEO2
    308 	.browser/y LDZ2 .Screen/y DEO2
    309 	;&empty-txt #01 ;draw-str JSR2
    310 
    311 JMP2r
    312 	&empty-txt "Empty 20 "Folder $1
    313 
    314 @get-type ( line* -- type )
    315 
    316 	;scap JSR2 #0004 SUB2 ;&rom-ext ;scmp JSR2
    317 
    318 JMP2r
    319 	&rom-ext ".rom $1
    320 
    321 @get-entry ( id -- addr* )
    322 
    323 	( limit ) STH
    324 	( counter ) LITr 00
    325 	;dir/length LDA2 #0000
    326 	&loop
    327 		EQUkr STHr #00 EQU ,&no-reached JCN
    328 			POP2r NIP2 ;dir/data ADD2 JMP2r
    329 			&no-reached
    330 		DUP2 ;dir/data ADD2 LDA ,&no-lb JCN
    331 			INCr
    332 			&no-lb
    333 		INC2 GTH2k ,&loop JCN
    334 	POP2 POP2
    335 	POP2r
    336 	;dir/data
    337 
    338 JMP2r
    339 
    340 @draw-type ( type -- )
    341 
    342 	STHk #00 SWP #50 SFT2 ;file-icns ADD2 .Screen/addr DEO2
    343 	#05 .Screen/auto DEO
    344 	#02 STHkr SUB .Screen/sprite DEOk DEO
    345 
    346 	.Screen/x DEI2k #0010 SUB2 ROT DEO2
    347 	.Screen/y DEI2k #0008 ADD2 ROT DEO2
    348 	
    349 	#02 STHr SUB .Screen/sprite DEOk DEO
    350 
    351 	.Screen/x DEI2k #0008 ADD2 ROT DEO2
    352 	.Screen/y DEI2k #0008 SUB2 ROT DEO2
    353 	#00 .Screen/auto DEO
    354 
    355 JMP2r
    356 
    357 @draw-icn ( x* y* width* height* addr* color  -- )
    358 	
    359 	#05 .Screen/auto DEO
    360 	( load ) STH .Screen/addr DEO2 ,&height STR2 ,&width STR2 ,&y STR2 ,&x STR2
    361 	,&height LDR2 #0000
    362 	&ver
    363 		( save ) DUP2 ,&y LDR2 ADD2 .Screen/y DEO2
    364 		,&x LDR2 .Screen/x DEO2
    365 		,&width LDR2 #0000
    366 		&hor
    367 			( draw ) STHkr .Screen/sprite DEO
    368 			#0008 ADD2 GTH2k ,&hor JCN
    369 		POP2 POP2
    370 		#0008 ADD2 GTH2k ,&ver JCN
    371 	POP2 POP2
    372 	POPr
    373 	#00 .Screen/auto DEO
    374 
    375 JMP2r
    376 	&x $2 &y $2 &width $2 &height $2
    377 
    378 @draw-str ( text* color -- )
    379 
    380 	#06 .Screen/auto DEO
    381 	STH
    382 	&while
    383 		LDAk STHkr ,draw-char JSR
    384 		INC2 LDAk ,&while JCN
    385 	POP2
    386 	POPr
    387 
    388 JMP2r
    389 
    390 @draw-byte ( byte color -- )
    391 
    392 	STH
    393 	DUP #04 SFT ,&parse JSR STHkr ,draw-char JSR
    394 	#0f AND ,&parse JSR STHr ,draw-char JSR
    395 
    396 JMP2r
    397 	&parse ( byte -- char ) DUP #09 GTH ,&above JCN #30 ADD JMP2r
    398 	&above #57 ADD JMP2r
    399 
    400 @draw-char ( char color -- )
    401 
    402 	SWP
    403 	#15 .Screen/auto DEO
    404 	#20 SUB #00 SWP #40 SFT2 ;font ADD2 .Screen/addr DEO2
    405 	.Screen/sprite DEO
    406 
    407 JMP2r
    408 
    409 ( theme )
    410 
    411 @theme-txt ".theme $1
    412 
    413 @load-theme ( -- )
    414 
    415 	;theme-txt .File/name DEO2
    416 	#0006 .File/length DEO2
    417 	#fffa .File/read DEO2
    418 
    419 	.File/success DEI2 #0006 NEQ2 ,&ignore JCN
    420 		#fffa LDA2 .System/r DEO2
    421 		#fffc LDA2 .System/g DEO2
    422 		#fffe LDA2 .System/b DEO2
    423 		&ignore
    424 
    425 JMP2r
    426 
    427 ( 
    428 @|stdlib )
    429 
    430 @scmp ( a* b* -- flag )
    431 
    432 	STH2
    433 	&loop
    434 		LDAk LDAkr STHr NEQ ,&end JCN
    435 		LDAk LDAkr STHr ORA ,&not-end JCN
    436 			POP2 POP2r #01 JMP2r
    437 			&not-end
    438 		INC2 INC2r ,&loop JMP
    439 	&end
    440 	POP2 POP2r #00
    441 
    442 JMP2r
    443 
    444 @scat ( src* dst* -- )
    445 
    446 	DUP2 ,slen JSR ADD2
    447 
    448 @scpy ( src* dst* -- )
    449 
    450 	STH2
    451 	&while
    452 		LDAk STH2kr STA INC2r
    453 		INC2 LDAk ,&while JCN
    454 	POP2
    455 	#00 STH2r STA
    456 
    457 JMP2r
    458 
    459 @slen ( str* -- len* )
    460 
    461 	DUP2 ,scap JSR SWP2 SUB2
    462 
    463 JMP2r
    464 
    465 @scap ( str* -- str-end* )
    466 
    467 	( clamp ) LDAk #00 NEQ JMP JMP2r
    468 	&while INC2 LDAk ,&while JCN
    469 
    470 JMP2r
    471 
    472 @pstr ( str* -- ) LDAk ?&w POP2 JMP2r &w LDAk #19 DEO INC2 LDAk ?&w POP2 JMP2r
    473 
    474 @error-txt 
    475 	"Error: 20 "Extra-large 20 "ROM, 20 "open 20 "file 20 "outside 20 "of 20 "launcher. 0a $1
    476 
    477 @pointer-icn [
    478 	80c0 e0f0 f8e0 1000 ]
    479 @hand-icn [
    480 	000c 0a0a 1224 4780
    481 	0000 0000 0000 fc02
    482 	8180 8080 8040 3f00
    483 	fc20 c020 c020 c000 ]
    484 @file-icns [
    485 	003f 3f30 3f30 3f30
    486 	00fc fc0c fc0c fc0c
    487 	3f33 3f3f 3f3f 3f00
    488 	fcfc fcc4 c8d0 e000
    489 	003f 3f30 3132 3231
    490 	00fc fc0c 8c4c 4c8c
    491 	303f 3f3f 3f3f 3f00
    492 	0cfc fcc4 c8d0 e000 ]
    493 @sin-pcm [
    494 	8083 8689 8c8f 9295 989b 9ea1 a4a7 aaad
    495 	b0b3 b6b9 bbbe c1c3 c6c9 cbce d0d2 d5d7
    496 	d9db dee0 e2e4 e6e7 e9eb ecee f0f1 f2f4
    497 	f5f6 f7f8 f9fa fbfb fcfd fdfe fefe fefe
    498 	fffe fefe fefe fdfd fcfb fbfa f9f8 f7f6
    499 	f5f4 f2f1 f0ee eceb e9e7 e6e4 e2e0 dedb
    500 	d9d7 d5d2 d0ce cbc9 c6c3 c1be bbb9 b6b3
    501 	b0ad aaa7 a4a1 9e9b 9895 928f 8c89 8683
    502 	807d 7a77 7471 6e6b 6865 625f 5c59 5653
    503 	504d 4a47 4542 3f3d 3a37 3532 302e 2b29
    504 	2725 2220 1e1c 1a19 1715 1412 100f 0e0c
    505 	0b0a 0908 0706 0505 0403 0302 0202 0202
    506 	0102 0202 0202 0303 0405 0506 0708 090a
    507 	0b0c 0e0f 1012 1415 1719 1a1c 1e20 2225
    508 	2729 2b2e 3032 3537 3a3d 3f42 4547 4a4d
    509 	5053 5659 5c5f 6265 686b 6e71 7477 7a7d ]
    510 
    511 ~projects/library/check-rom.tal
    512 ~projects/library/load-rom.tal
    513 ~projects/assets/mascot0cx0c.tal
    514 ~projects/assets/msx01x02.tal
    515 
    516 ( directory memory )
    517 @dir
    518 	&path ". $1
    519 	&length $2
    520 	&data $1000
    521 
    522 ( assembler memory )
    523 
    524 ~projects/library/asma.tal
    525 
    526 @asma-heap
    527 |e000 &end @asma-read-buffer
    528 |f800 &end @asma-write-buffer
    529 |ffff &end