uxn

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

load-rom.tal (1969B)


      1 @load-rom ( filename* -- )
      2 (
      3 	Attempts to load the ROM from filename* and executes it. If the file exists
      4 	and has non-zero length, this function does not return, because the new ROM
      5 	is executing in its place.
      6 
      7 	The screen and both stacks are cleared and all the device vectors are
      8 	written to zero as a convenience. All other device bytes are left
      9 	untouched, so they could introduce a device state to the next ROM that
     10 	it's not expecting.
     11 )
     12 
     13 	.File/name DEO2
     14 
     15 	( clear wst )
     16 	#ab
     17 	&wst-loop
     18 	POP
     19 	.System/wst STH DEIr STHr ,&wst-loop JCN
     20 
     21 	( clear rst )
     22 	LITr ab
     23 	&rst-loop
     24 	POPr
     25 	.System/rst DEI ,&rst-loop JCN
     26 
     27 	( clear screen )
     28 	#0000 DUP2 .Screen/x DEO2 .Screen/y DEO2
     29 	#80 .Screen/pixel DEO
     30 	#c0 .Screen/pixel DEO
     31 
     32 	( reset device vectors )
     33 	LIT2r 0000 #00
     34 	&device-vector-loop
     35 	DUP2r STHk DEO2r
     36 	#10 ADD
     37 	DUP ,&device-vector-loop JCN
     38 	POP POP2r
     39 
     40 	( copy the zero-page-loader into f0-ff )
     41 	;&zero-page-loader LITr f0
     42 	&copy-loop
     43 	LDAk STHkr STZ
     44 	INC2 INCr
     45 	STHkr ,&copy-loop JCN
     46 	POP2 ( leave 00 on return stack )
     47 
     48 	( prepare the stack for the zero-page-loader )
     49 	( the more we prepare here in advance, the less we'll have to overwrite )
     50 	STHkr #00fe ( arguments for STZ2 at ff )
     51 	STHkr ( argument for JMP at fe (carry on) )
     52 	DUPk #fcfe ( arguments for STZ2 at fd and JMP (repeat) )
     53 	OVR2 #fafe ( arguments for STZ2 at fd and JMP (repeat) )
     54 	OVR2 #f8fe ( arguments for STZ2 at fd and JMP (repeat) )
     55 	OVR2 #f6fe ( arguments for STZ2 at fd and JMP (repeat) )
     56 	OVR2 #f401 ( arguments for STZ2 at fd, plus an extra 01 )
     57 	STHkr ( first argument for ADD2 )
     58 	.File/success ( argument for DEI2 )
     59 	#0100 .File/read ( arguments for DEO2 )
     60 	#ff00 .File/length DEO2
     61 	#00f0 JMP2
     62 
     63 	&zero-page-loader
     64 	( f0 ) DEO2
     65 	( f1 ) DEI2
     66 	( f2 ) ADD2
     67 	( f3 ) &loop DUPr
     68 	( f4 ) STH2k
     69 	( f5 ) STAr
     70 	( f6 ) INC2
     71 	( f7 ) NEQ2k
     72 	( f8 ) ,&loop
     73 	( f9 )
     74 	( fa ) JCN
     75 	( fb ) POPr
     76 	( fc ) POP2
     77 	( fd ) STZ2 ( deletes f4-fd through looping )
     78 	( fe ) JMP
     79 	( ff ) STZ2 ( deletes fe-ff )
     80 
     81 	&tmp $1
     82