| 1 | 1 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,87 @@ |
| 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 |
+ Both stacks are cleared and all the device vectors are written to zero as a |
|
| 8 |
+ convenience, but the screen is not cleared. All ROMs that use the screen |
|
| 9 |
+ define the palette (usually in the reset vector) so that should clear the |
|
| 10 |
+ screen anyway. All other device bytes are left untouched, so they could |
|
| 11 |
+ introduce a device state to the next ROM that it's not expecting. |
|
| 12 |
+) |
|
| 13 |
+ |
|
| 14 |
+ .File/name DEO2 |
|
| 15 |
+ #0000 .File/offset-hs DEO2 |
|
| 16 |
+ #0000 .File/offset-ls DEO2 |
|
| 17 |
+ |
|
| 18 |
+ ( return if file can't be found, or zero length ) |
|
| 19 |
+ #0001 .File/length DEO2 |
|
| 20 |
+ ;&tmp .File/load DEO2 |
|
| 21 |
+ .File/success DEI2 ORA JMP JMP2r |
|
| 22 |
+ |
|
| 23 |
+ ( clear wst ) |
|
| 24 |
+ #ab |
|
| 25 |
+ &wst-loop |
|
| 26 |
+ POP |
|
| 27 |
+ .System/wst STH DEIr STHr #01 GTH ,&wst-loop JCN |
|
| 28 |
+ |
|
| 29 |
+ ( clear rst ) |
|
| 30 |
+ LITr ab |
|
| 31 |
+ &rst-loop |
|
| 32 |
+ POPr |
|
| 33 |
+ .System/rst DEI ,&rst-loop JCN |
|
| 34 |
+ |
|
| 35 |
+ ( reset device vectors ) |
|
| 36 |
+ LIT2r 0000 #00 |
|
| 37 |
+ &device-vector-loop |
|
| 38 |
+ DUP2r STHk DEO2r |
|
| 39 |
+ #10 ADD |
|
| 40 |
+ DUP ,&device-vector-loop JCN |
|
| 41 |
+ POP POP2r |
|
| 42 |
+ |
|
| 43 |
+ ( copy the zero-page-loader into f0-ff ) |
|
| 44 |
+ ;&zero-page-loader LIT2r 00f0 |
|
| 45 |
+ ©-loop |
|
| 46 |
+ LDAk STH2kr STA |
|
| 47 |
+ INC2 INC2r |
|
| 48 |
+ STHkr ,©-loop JCN |
|
| 49 |
+ POP2 NIPr ( leave 00 on return stack ) |
|
| 50 |
+ |
|
| 51 |
+ ( prepare the stack for the zero-page-loader ) |
|
| 52 |
+ ( the more we prepare here in advance, the less we'll have to overwrite ) |
|
| 53 |
+ STHkr DUPk #fe ( arguments for STA2 at ff ) |
|
| 54 |
+ OVR2 ( argument for JMP at fe (carry on), plus an extra zero ) |
|
| 55 |
+ DUP2 #fcfe ( arguments for STA2 at fd and JMP (repeat) ) |
|
| 56 |
+ OVR2 STHkr #fafe ( arguments for STA2 at fd and JMP (repeat) ) |
|
| 57 |
+ OVR2 STHkr #f8fe ( arguments for STA2 at fd and JMP (repeat) ) |
|
| 58 |
+ OVR2 STHkr #f6fe ( arguments for STA2 at fd and JMP (repeat) ) |
|
| 59 |
+ OVR2 STHkr #f4fe ( arguments for STA2 at fd and JMP (repeat) ) |
|
| 60 |
+ OVR2 STHkr #f2fe ( arguments for STA2 at fd and JMP (repeat) ) |
|
| 61 |
+ OVR2 STHkr #f001 ( arguments for STA2 at fd, plus an extra 01 ) |
|
| 62 |
+ STHkr ( first argument for ADD2 ) |
|
| 63 |
+ .File/success ( argument for DEI2 ) |
|
| 64 |
+ #0100 .File/load ( arguments for DEO2 ) |
|
| 65 |
+ #ff00 .File/length DEO2 |
|
| 66 |
+ #00f0 JMP2 |
|
| 67 |
+ |
|
| 68 |
+ &zero-page-loader |
|
| 69 |
+ ( f0 ) DEO2 |
|
| 70 |
+ ( f1 ) DEI2 |
|
| 71 |
+ ( f2 ) ADD2 |
|
| 72 |
+ ( f3 ) &loop DUPr |
|
| 73 |
+ ( f4 ) STH2k |
|
| 74 |
+ ( f5 ) STAr |
|
| 75 |
+ ( f6 ) INC2 |
|
| 76 |
+ ( f7 ) NEQ2k |
|
| 77 |
+ ( f8 ) ,&loop |
|
| 78 |
+ ( f9 ) |
|
| 79 |
+ ( fa ) JCN |
|
| 80 |
+ ( fb ) POPr |
|
| 81 |
+ ( fc ) POP2 |
|
| 82 |
+ ( fd ) STA2 ( deletes f0-fd through looping ) |
|
| 83 |
+ ( fe ) JMP |
|
| 84 |
+ ( ff ) STA2 ( deletes fe-ff ) |
|
| 85 |
+ |
|
| 86 |
+ &tmp $1 |
|
| 87 |
+ |
| ... | ... |
@@ -17,7 +17,7 @@ |
| 17 | 17 |
|
| 18 | 18 |
( devices ) |
| 19 | 19 |
|
| 20 |
-|00 @System &vector $2 &pad $6 &r $2 &g $2 &b $2 |
|
| 20 |
+|00 @System [ &vector $2 &wst $1 &rst $1 &pad $4 &r $2 &g $2 &b $2 &debug $1 &halt $1 ] |
|
| 21 | 21 |
|10 @Console [ &vector $2 &read $1 &pad $5 &write $1 &error $1 ] |
| 22 | 22 |
|20 @Screen &vector $2 &width $2 &height $2 &pad $2 &x $2 &y $2 &addr $2 &pixel $1 &sprite $1 |
| 23 | 23 |
|80 @Controller [ &vector $2 &button $1 &key $1 ] |
| ... | ... |
@@ -106,7 +106,7 @@ BRK |
| 106 | 106 |
RTN |
| 107 | 107 |
|
| 108 | 108 |
&validate ( -- ) |
| 109 |
- ;input ;launch JSR2 |
|
| 109 |
+ ;input ;load-rom JSR2 |
|
| 110 | 110 |
#00 ,&draw JSR |
| 111 | 111 |
( null ) #0000 ;input STA2 |
| 112 | 112 |
RTN |
| ... | ... |
@@ -134,14 +134,6 @@ BRK |
| 134 | 134 |
|
| 135 | 135 |
RTN |
| 136 | 136 |
|
| 137 |
-@launch ( path* -- ) |
|
| 138 |
- |
|
| 139 |
- POP2 |
|
| 140 |
- |
|
| 141 |
- #0020 #00e0 ;error-txt #08 ;draw-label JSR2 |
|
| 142 |
- |
|
| 143 |
-RTN |
|
| 144 |
- |
|
| 145 | 137 |
@redraw ( -- ) |
| 146 | 138 |
|
| 147 | 139 |
#0018 #0020 #0040 #0040 ;logo-icn #03 ;draw-icn JSR2 |
| ... | ... |
@@ -277,6 +269,8 @@ RTN |
| 277 | 269 |
|
| 278 | 270 |
RTN |
| 279 | 271 |
|
| 272 |
+include projects/library/load-rom.tal |
|
| 273 |
+ |
|
| 280 | 274 |
@welcome-txt |
| 281 | 275 |
"Welcome 20 "to 20 "your 20 "UXN 20 "Ordinator $1 |
| 282 | 276 |
@today-txt |