Rev 1854 | Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1814 | yogev_ezra | 1 | |
2 | #include "system/stdlib.h" |
||
3 | #include "system/string.h" |
||
4 | #include "z80/z80.h" |
||
5 | #include "48.h" |
||
6 | |||
7 | |||
8 | |||
9 | |||
10 | |||
11 | |||
12 | #define TYPE_SNA 1 |
||
13 | #define TYPE_Z80 2 |
||
14 | |||
15 | |||
16 | |||
17 | |||
18 | |||
19 | |||
20 | extern char KOL_PATH[256]; |
||
21 | |||
22 | |||
23 | char szScreen[256]; |
||
24 | |||
25 | |||
26 | int main_tecla, hay_tecla; |
||
27 | int SSCS = 0; |
||
28 | |||
29 | |||
30 | int frame_counter; |
||
31 | int target_cycle; |
||
32 | Z80Regs spectrumZ80; |
||
33 | |||
34 | |||
35 | unsigned screen_w, screen_h; |
||
36 | #define screen_a_w 512 |
||
37 | #define screen_a_h 384 |
||
38 | int flash = 0; |
||
39 | unsigned time = 0; |
||
40 | |||
41 | |||
42 | |||
43 | |||
44 | |||
45 | |||
46 | |||
47 | |||
48 | { |
||
49 | |||
50 | |||
51 | } |
||
52 | |||
53 | |||
54 | |||
55 | |||
56 | { |
||
57 | kol_struct70 file; |
||
58 | |||
59 | |||
60 | file.p04 = 0; |
||
61 | file.p08 = 0; |
||
62 | file.p12 = 64*1024; |
||
63 | file.p16 = (unsigned)(regs->RAM); |
||
64 | file.p20 = 0; |
||
65 | file.p21 = filename; |
||
66 | |||
67 | |||
68 | } |
||
69 | |||
70 | |||
71 | |||
72 | |||
73 | |||
74 | { |
||
75 | kol_struct70 file; |
||
76 | |||
77 | |||
78 | file.p04 = 0; |
||
79 | file.p08 = 0; |
||
80 | file.p12 = sizeof (Z80Regs); |
||
81 | file.p16 = (unsigned)regs; |
||
82 | file.p20 = 0; |
||
83 | file.p21 = filename; |
||
84 | |||
85 | |||
86 | } |
||
87 | |||
88 | |||
89 | |||
90 | |||
91 | { |
||
92 | |||
93 | |||
94 | |||
95 | |||
96 | { |
||
97 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
||
98 | 0xB0, 0x00, 0x00, 0xB0, 0x00, 0x00, |
||
99 | 0x00, 0x00, 0xB0, 0x00, 0x00, 0xB0, |
||
100 | 0xB0, 0x00, 0xB0, 0xB0, 0x00, 0xB0, |
||
101 | 0x00, 0xB0, 0x00, 0x00, 0xB0, 0x00, |
||
102 | 0xB0, 0xB0, 0x00, 0xB0, 0xB0, 0x00, |
||
103 | 0x00, 0xB0, 0xB0, 0x00, 0xB0, 0xB0, |
||
104 | 0xB0, 0xB0, 0xB0, 0xB0, 0xB0, 0xB0, |
||
105 | |||
106 | |||
107 | 0xFF, 0x00, 0x00, 0xFF, 0x00, 0x00, |
||
108 | 0x00, 0x00, 0xFF, 0x00, 0x00, 0xFF, |
||
109 | 0xFF, 0x00, 0xFF, 0xFF, 0x00, 0xFF, |
||
110 | 0x00, 0xFF, 0x00, 0x00, 0xFF, 0x00, |
||
111 | 0xFF, 0xFF, 0x00, 0xFF, 0xFF, 0x00, |
||
112 | 0x00, 0xFF, 0xFF, 0x00, 0xFF, 0xFF, |
||
113 | 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF |
||
114 | }; |
||
115 | |||
116 | |||
117 | char *atr; |
||
118 | |||
119 | |||
120 | int i, j, k, l, m; |
||
121 | unsigned bri; |
||
122 | char *color; |
||
123 | char *addr; |
||
124 | int n = 0; |
||
125 | int z = 0; |
||
126 | int x, y; |
||
127 | |||
128 | |||
129 | atr = malloc(768); |
||
130 | |||
131 | |||
132 | memcpy(atr, regs->RAM + 0x5800 , 768); |
||
133 | |||
134 | |||
135 | for (i = 0; i < 8; i++) |
||
136 | for (k = 0; k < 8; k++) |
||
137 | for (l = 0; l < 32; l++) |
||
138 | { |
||
139 | c = scr[j*2048 + k*256 + i*32 + l]; |
||
140 | for (m = 0; m < 8; m++) |
||
141 | { |
||
142 | s = (c & 128) >> 7; |
||
143 | a = atr[j*256 + i*32 + l]; |
||
144 | |||
145 | |||
146 | bri = 8; |
||
147 | else |
||
148 | bri = 0; |
||
149 | |||
150 | |||
151 | { |
||
152 | if (!(flash && (128 == (a&128)))) |
||
153 | color = &palette[6*(bri+((a>>3)&7))]; |
||
154 | else |
||
155 | color = &palette[6*(bri+(a&7))]; |
||
156 | |||
157 | |||
158 | |||
159 | |||
160 | memcpy( addr + y*screen_a_w*3, |
||
161 | color, 6); |
||
162 | } |
||
163 | else |
||
164 | { |
||
165 | if (!(flash && (128 == (a&128)))) |
||
166 | color = &palette[6*(bri+(a&7))]; |
||
167 | else |
||
168 | color = &palette[6*(bri+((a>>3)&7))]; |
||
169 | |||
170 | |||
171 | |||
172 | |||
173 | memcpy( addr + y*screen_a_w*3, |
||
174 | color, 6); |
||
175 | } |
||
176 | |||
177 | |||
178 | if (256 == n) |
||
179 | { |
||
180 | n = 0; |
||
181 | z++; |
||
182 | } |
||
183 | |||
184 | |||
185 | } |
||
186 | } |
||
187 | |||
188 | |||
189 | { |
||
190 | if (0 == flash) |
||
191 | flash = 1; |
||
192 | else |
||
193 | flash = 0; |
||
194 | time = kol_time_tick(); |
||
195 | } |
||
196 | |||
197 | |||
198 | free(atr); |
||
199 | |||
200 | |||
201 | |||
202 | |||
203 | |||
204 | |||
205 | { |
||
206 | char header[30]; |
||
207 | kol_struct70 file; |
||
208 | |||
209 | |||
210 | file.p04 = 0; |
||
211 | file.p08 = 0; |
||
212 | file.p12 = 30; |
||
213 | file.p16 = (unsigned) header; |
||
214 | file.p20 = 0; |
||
215 | file.p21 = filename; |
||
216 | } |
||
217 | |||
218 | |||
219 | |||
220 | |||
221 | { |
||
222 | char buffer[27]; |
||
223 | kol_struct70 file; |
||
224 | |||
225 | |||
226 | file.p04 = 0; |
||
227 | file.p08 = 0; |
||
228 | file.p12 = 27; |
||
229 | file.p16 = (unsigned) buffer; |
||
230 | file.p20 = 0; |
||
231 | file.p21 = filename; |
||
232 | |||
233 | |||
234 | |||
235 | |||
236 | regs->HLs.B.l = buffer[ 1]; |
||
237 | regs->HLs.B.h = buffer[ 2]; |
||
238 | regs->DEs.B.l = buffer[ 3]; |
||
239 | regs->DEs.B.h = buffer[ 4]; |
||
240 | regs->BCs.B.l = buffer[ 5]; |
||
241 | regs->BCs.B.h = buffer[ 6]; |
||
242 | regs->AFs.B.l = buffer[ 7]; |
||
243 | regs->AFs.B.h = buffer[ 8]; |
||
244 | regs->HL.B.l = buffer[ 9]; |
||
245 | regs->HL.B.h = buffer[10]; |
||
246 | regs->DE.B.l = buffer[11]; |
||
247 | regs->DE.B.h = buffer[12]; |
||
248 | regs->BC.B.l = buffer[13]; |
||
249 | regs->BC.B.h = buffer[14]; |
||
250 | regs->IY.B.l = buffer[15]; |
||
251 | regs->IY.B.h = buffer[16]; |
||
252 | regs->IX.B.l = buffer[17]; |
||
253 | regs->IX.B.h = buffer[18]; |
||
254 | regs->IFF1 = regs->IFF2 = (buffer[19]&0x04) >>2; |
||
255 | regs->R.W = buffer[20]; |
||
256 | regs->AF.B.l = buffer[21]; |
||
257 | regs->AF.B.h = buffer[22]; |
||
258 | regs->SP.B.l =buffer[23]; |
||
259 | regs->SP.B.h =buffer[24]; |
||
260 | regs->IM = buffer[25]; |
||
261 | regs->BorderColor = buffer[26]; |
||
262 | |||
263 | |||
264 | file.p04 = 27; |
||
265 | file.p08 = 0; |
||
266 | file.p12 = 0x4000*3; |
||
267 | file.p16 = (unsigned) regs->RAM+16384; |
||
268 | file.p20 = 0; |
||
269 | file.p21 = filename; |
||
270 | |||
271 | |||
272 | |||
273 | |||
274 | regs->SP.W++; |
||
275 | regs->PC.B.h = Z80MemRead(regs->SP.W, regs); |
||
276 | regs->SP.W++; |
||
277 | |||
278 | |||
279 | |||
280 | |||
281 | |||
282 | |||
283 | |||
284 | { |
||
285 | char buffer[27]; |
||
286 | unsigned char sptmpl, sptmph; |
||
287 | kol_struct70 file; |
||
288 | |||
289 | |||
290 | buffer[ 1] = regs->HLs.B.l; |
||
291 | buffer[ 2] = regs->HLs.B.h; |
||
292 | buffer[ 3] = regs->DEs.B.l; |
||
293 | buffer[ 4] = regs->DEs.B.h; |
||
294 | buffer[ 5] = regs->BCs.B.l; |
||
295 | buffer[ 6] = regs->BCs.B.h; |
||
296 | buffer[ 7] = regs->AFs.B.l; |
||
297 | buffer[ 8] = regs->AFs.B.h; |
||
298 | buffer[ 9] = regs->HL.B.l; |
||
299 | buffer[10] = regs->HL.B.h; |
||
300 | buffer[11] = regs->DE.B.l; |
||
301 | buffer[12] = regs->DE.B.h; |
||
302 | buffer[13] = regs->BC.B.l; |
||
303 | buffer[14] = regs->BC.B.h; |
||
304 | buffer[15] = regs->IY.B.l; |
||
305 | buffer[16] = regs->IY.B.h; |
||
306 | buffer[17] = regs->IX.B.l; |
||
307 | buffer[18] = regs->IX.B.h; |
||
308 | buffer[19] = regs->IFF1 << 2; |
||
309 | buffer[20] = regs->R.W & 0xFF; |
||
310 | buffer[21] = regs->AF.B.l; |
||
311 | buffer[22] = regs->AF.B.h; |
||
312 | |||
313 | |||
314 | sptmph = Z80MemRead( regs->SP.W-2, regs ); |
||
315 | |||
316 | |||
317 | Z80MemWrite( --(regs->SP.W), regs->PC.B.l, regs); |
||
318 | |||
319 | |||
320 | buffer[24] = regs->SP.B.h; |
||
321 | buffer[25] = regs->IM; |
||
322 | buffer[26] = regs->BorderColor; |
||
323 | |||
324 | |||
325 | file.p04 = 0; |
||
326 | file.p08 = 0; |
||
327 | file.p12 = 27; |
||
328 | file.p16 = (unsigned) buffer; |
||
329 | file.p20 = 0; |
||
330 | file.p21 = filename; |
||
331 | |||
332 | |||
333 | |||
334 | |||
335 | file.p04 = 27; |
||
336 | file.p08 = 0; |
||
337 | file.p12 = 0x4000*3; |
||
338 | file.p16 = (unsigned) regs->RAM+16384; |
||
339 | file.p20 = 0; |
||
340 | file.p21 = filename; |
||
341 | |||
342 | |||
343 | |||
344 | |||
345 | Z80MemWrite( regs->SP.W-1, sptmpl, regs ); |
||
346 | Z80MemWrite( regs->SP.W-2, sptmph, regs ); |
||
347 | |||
348 | |||
349 | |||
350 | |||
351 | |||
352 | |||
353 | |||
354 | { |
||
355 | kol_struct70 file; |
||
356 | |||
357 | |||
358 | |||
359 | file.p04 = 0x4000; |
||
360 | file.p08 = 0; |
||
361 | file.p12 = 6912; |
||
362 | file.p16 = (unsigned) regs->RAM+16384; |
||
363 | file.p20 = 0; |
||
364 | file.p21 = filename; |
||
365 | |||
366 | |||
367 | |||
368 | |||
369 | |||
370 | |||
371 | |||
372 | |||
373 | |||
374 | { |
||
375 | kol_paint_start(); |
||
376 | kol_wnd_define( (screen_w-540)/2, (screen_h-440)/2, 540, 440, 0x34b0b0b0); |
||
377 | kol_wnd_caption(WND_CAPTION); |
||
378 | screen_print(&spectrumZ80); |
||
379 | kol_paint_image((540 - screen_a_w)/2-5, |
||
380 | (440 - screen_a_h-kol_skin_height())/2, |
||
381 | screen_a_w, screen_a_h, screen); |
||
382 | kol_paint_end(); |
||
383 | } |
||
384 | |||
385 | |||
386 | |||
387 | |||
388 | { |
||
389 | |||
390 | |||
391 | unsigned key; |
||
392 | |||
393 | |||
394 | if ( '/' == KOL_PATH[event] ) |
||
395 | { |
||
396 | KOL_PATH[event+1]=0; |
||
397 | break; |
||
398 | } |
||
399 | |||
400 | |||
401 | strcpy(szScreen, KOL_PATH); |
||
402 | strcat(szBackup, "backup.sna"); |
||
403 | strcat(szScreen, "screen.scr"); |
||
404 | |||
405 | |||
406 | |||
407 | |||
408 | spectrumZ80.RAM = (char*) malloc(64*1024); |
||
409 | memcpy(spectrumZ80.RAM, BIOS48, 16*1024); |
||
410 | |||
411 | |||
412 | Z80FlagTables(); |
||
413 | |||
414 | |||
415 | fila[4][1] = fila[3][1] = fila[2][1] = 0xFF; |
||
416 | |||
417 | |||
418 | |||
419 | |||
420 | { |
||
421 | int type = get_ext(KOL_PARAM); |
||
422 | |||
423 | |||
424 | memory_load_sna(&spectrumZ80, KOL_PARAM); |
||
425 | } |
||
426 | |||
427 | |||
428 | //keyboard_process(0); |
||
429 | |||
430 | |||
431 | |||
432 | |||
433 | { |
||
434 | |||
435 | |||
436 | event = kol_event_wait_time(1); |
||
437 | |||
438 | |||
439 | { |
||
440 | |||
441 | |||
442 | wnd_draw(); |
||
443 | break; |
||
444 | |||
445 | |||
446 | key = (kol_key_get()>>8)&0xff; |
||
447 | |||
448 | |||
449 | { |
||
450 | case 60: // F2 |
||
451 | if ( IDOK == MessageBox("Save snapshot?", |
||
452 | WND_CAPTION, MB_OKCANCEL) ) |
||
453 | memory_save_sna(&spectrumZ80, |
||
454 | szBackup); |
||
455 | break; |
||
456 | |||
457 | |||
458 | if ( IDOK == MessageBox("Load snapshot?", |
||
459 | WND_CAPTION, MB_OKCANCEL) ) |
||
460 | memory_load_sna(&spectrumZ80, |
||
461 | szBackup); |
||
462 | break; |
||
463 | |||
464 | |||
465 | if ( IDOK == MessageBox("Save screenshot?", |
||
466 | WND_CAPTION, MB_OKCANCEL) ) |
||
467 | memory_save_scr(&spectrumZ80, |
||
468 | szScreen); |
||
469 | break; |
||
470 | |||
471 | |||
472 | if ( IDOK == MessageBox("Reset?", |
||
473 | WND_CAPTION, MB_OKCANCEL) ) |
||
474 | { |
||
475 | Z80Reset( &spectrumZ80, 69888 ); |
||
476 | Z80FlagTables(); |
||
477 | fila[1][1] = fila[1][2] = |
||
478 | fila[2][2] = fila[3][2] = |
||
479 | fila[4][2] = fila[4][1] = |
||
480 | fila[3][1] = fila[2][1] = 0xFF; |
||
481 | } |
||
482 | break; |
||
483 | |||
484 | |||
485 | keyboard_process(key); |
||
486 | }; |
||
487 | |||
488 | |||
489 | |||
490 | |||
491 | if ( 1 == (kol_btn_get() & 0xff00)>>8 ) |
||
492 | { |
||
493 | free(screen); |
||
494 | free(spectrumZ80.RAM); |
||
495 | kol_exit(); |
||
496 | } |
||
497 | break; |
||
498 | |||
499 | |||
500 | if (0 == debug) |
||
501 | { |
||
502 | |||
503 | |||
504 | for( scanl=0; scanl<192; scanl++ ) |
||
505 | Z80Run( &spectrumZ80, 224 ); |
||
506 | |||
507 | |||
508 | |||
509 | |||
510 | { |
||
511 | screen_print(&spectrumZ80); |
||
512 | kol_screen_wait_rr(); |
||
513 | kol_paint_image((540 - screen_a_w)/2-5, |
||
514 | (440 - screen_a_h-kol_skin_height())/2, |
||
515 | screen_a_w, screen_a_h, screen); |
||
516 | } |
||
517 | |||
518 | |||
519 | { |
||
520 | target_cycle--; |
||
521 | frame_counter++; |
||
522 | } |
||
523 | } |
||
524 | break; |
||
525 | |||
526 | |||
527 | |||
528 | |||
529 | |||
530 | |||
531 | |||
532 | |||
533 |