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