1 | 1 |
new file mode 100644 |
... | ... |
@@ -0,0 +1,111 @@ |
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 |
+ #0000 .File/offset-hs DEO2 |
|
15 |
+ #0000 .File/offset-ls DEO2 |
|
16 |
+ |
|
17 |
+ ( return if file can't be found, or zero length ) |
|
18 |
+ #0001 .File/length DEO2 |
|
19 |
+ ;&tmp .File/load DEO2 |
|
20 |
+ .File/success DEI2 ORA JMP JMP2r |
|
21 |
+ |
|
22 |
+ ( clear wst ) |
|
23 |
+ #ab |
|
24 |
+ &wst-loop |
|
25 |
+ POP |
|
26 |
+ .System/wst STH DEIr STHr #01 GTH ,&wst-loop JCN |
|
27 |
+ |
|
28 |
+ ( clear rst ) |
|
29 |
+ LITr ab |
|
30 |
+ &rst-loop |
|
31 |
+ POPr |
|
32 |
+ .System/rst DEI ,&rst-loop JCN |
|
33 |
+ |
|
34 |
+ ( clear screen ) |
|
35 |
+ #01 .Screen/auto DEO |
|
36 |
+ #0000 .Screen/y DEO2 |
|
37 |
+ .Screen/width DEI2 #0007 ADD2 #03 SFT2 #ffff MUL2 STH2 |
|
38 |
+ &screen-yloop |
|
39 |
+ #0000 .Screen/x DEO2 |
|
40 |
+ STH2kr |
|
41 |
+ &screen-xloop-bg |
|
42 |
+ #00 .Screen/sprite DEO |
|
43 |
+ INC2 |
|
44 |
+ ORAk ,&screen-xloop-bg JCN |
|
45 |
+ POP2 |
|
46 |
+ #0000 .Screen/x DEO2 |
|
47 |
+ STH2kr |
|
48 |
+ &screen-xloop-fg |
|
49 |
+ #40 .Screen/sprite DEO |
|
50 |
+ INC2 |
|
51 |
+ ORAk ,&screen-xloop-fg JCN |
|
52 |
+ POP2 |
|
53 |
+ .Screen/y DEI2 #0008 ADD2 |
|
54 |
+ DUP2 .Screen/y DEO2 |
|
55 |
+ .Screen/height DEI2 LTH2 ,&screen-yloop JCN |
|
56 |
+ POP2r |
|
57 |
+ #00 .Screen/auto DEO |
|
58 |
+ |
|
59 |
+ ( reset device vectors ) |
|
60 |
+ LIT2r 0000 #00 |
|
61 |
+ &device-vector-loop |
|
62 |
+ DUP2r STHk DEO2r |
|
63 |
+ #10 ADD |
|
64 |
+ DUP ,&device-vector-loop JCN |
|
65 |
+ POP POP2r |
|
66 |
+ |
|
67 |
+ ( copy the zero-page-loader into f0-ff ) |
|
68 |
+ ;&zero-page-loader LIT2r 00f0 |
|
69 |
+ ©-loop |
|
70 |
+ LDAk STH2kr STA |
|
71 |
+ INC2 INC2r |
|
72 |
+ STHkr ,©-loop JCN |
|
73 |
+ POP2 NIPr ( leave 00 on return stack ) |
|
74 |
+ |
|
75 |
+ ( prepare the stack for the zero-page-loader ) |
|
76 |
+ ( the more we prepare here in advance, the less we'll have to overwrite ) |
|
77 |
+ STHkr DUPk #fe ( arguments for STA2 at ff ) |
|
78 |
+ OVR2 ( argument for JMP at fe (carry on), plus an extra zero ) |
|
79 |
+ DUP2 #fcfe ( arguments for STA2 at fd and JMP (repeat) ) |
|
80 |
+ OVR2 STHkr #fafe ( arguments for STA2 at fd and JMP (repeat) ) |
|
81 |
+ OVR2 STHkr #f8fe ( arguments for STA2 at fd and JMP (repeat) ) |
|
82 |
+ OVR2 STHkr #f6fe ( arguments for STA2 at fd and JMP (repeat) ) |
|
83 |
+ OVR2 STHkr #f4fe ( arguments for STA2 at fd and JMP (repeat) ) |
|
84 |
+ OVR2 STHkr #f2fe ( arguments for STA2 at fd and JMP (repeat) ) |
|
85 |
+ OVR2 STHkr #f001 ( arguments for STA2 at fd, plus an extra 01 ) |
|
86 |
+ STHkr ( first argument for ADD2 ) |
|
87 |
+ .File/success ( argument for DEI2 ) |
|
88 |
+ #0100 .File/load ( arguments for DEO2 ) |
|
89 |
+ #ff00 .File/length DEO2 |
|
90 |
+ #00f0 JMP2 |
|
91 |
+ |
|
92 |
+ &zero-page-loader |
|
93 |
+ ( f0 ) DEO2 |
|
94 |
+ ( f1 ) DEI2 |
|
95 |
+ ( f2 ) ADD2 |
|
96 |
+ ( f3 ) &loop DUPr |
|
97 |
+ ( f4 ) STH2k |
|
98 |
+ ( f5 ) STAr |
|
99 |
+ ( f6 ) INC2 |
|
100 |
+ ( f7 ) NEQ2k |
|
101 |
+ ( f8 ) ,&loop |
|
102 |
+ ( f9 ) |
|
103 |
+ ( fa ) JCN |
|
104 |
+ ( fb ) POPr |
|
105 |
+ ( fc ) POP2 |
|
106 |
+ ( fd ) STA2 ( deletes f0-fd through looping ) |
|
107 |
+ ( fe ) JMP |
|
108 |
+ ( ff ) STA2 ( deletes fe-ff ) |
|
109 |
+ |
|
110 |
+ &tmp $1 |
|
111 |
+ |
... | ... |
@@ -17,9 +17,9 @@ |
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 |
-|20 @Screen &vector $2 &width $2 &height $2 &pad $2 &x $2 &y $2 &addr $2 &pixel $1 &sprite $1 |
|
22 |
+|20 @Screen &vector $2 &width $2 &height $2 &auto $1 &pad $1 &x $2 &y $2 &addr $2 &pixel $1 &sprite $1 |
|
23 | 23 |
|80 @Controller [ &vector $2 &button $1 &key $1 ] |
24 | 24 |
|90 @Mouse [ &vector $2 &x $2 &y $2 &state $1 &wheel $1 ] |
25 | 25 |
|a0 @File &vector $2 &success $2 &offset-hs $2 &offset-ls $2 &name $2 &length $2 &load $2 &save $2 |
... | ... |
@@ -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 |
... | ... |
@@ -158,7 +158,7 @@ redraw(Uxn *u) |
158 | 158 |
SDL_Rect up = gRect; |
159 | 159 |
if(devsystem->dat[0xe]) |
160 | 160 |
inspect(&ppu, u->wst.dat, u->wst.ptr, u->rst.ptr, u->ram.dat); |
161 |
- if(ppu.redraw) { |
|
161 |
+ if(!reqdraw && ppu.redraw) { |
|
162 | 162 |
y0 = ppu.i0 / ppu.stride; |
163 | 163 |
y1 = ppu.i1 / ppu.stride + 1; |
164 | 164 |
up.y += y0; |