new plugin: FS#10559 - lrcplayer: a plugin to view .lrc file.
[kugel-rb.git] / apps / plugins / zxbox / z80.c
blobf6f1de746879c7335c1ef1f4eaf6f1fa6dc0fec9
1 /*
2 * Copyright (C) 1996-1998 Szeredi Miklos
3 * Email: mszeredi@inf.bme.hu
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version. See the file COPYING.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 #include "z80.h"
23 #include <stdio.h>
24 #include <stdlib.h>
25 #include <time.h>
26 #include "zxconfig.h"
27 #include "helpers.h"
28 Z80 PRNM(proc) IBSS_ATTR;
30 byte PRNM(inports)[PORTNUM] IBSS_ATTR;
31 byte PRNM(outports)[PORTNUM] IBSS_ATTR;
33 #ifdef SPECT_MEM
34 #define NUM64KSEGS 3
35 #endif
37 #ifndef NUM64KSEGS
38 #define NUM64KSEGS 1
39 #endif
41 static byte *a64kmalloc(int num64ksegs)
43 byte *bigmem;
45 bigmem = (byte *) my_malloc((unsigned) (0x10000 * (num64ksegs + 1)));
46 if(bigmem == NULL) {
47 /*fprintf(stderr, "Out of memory!\n");*/
48 /*exit(1);*/
51 return (byte *) (( (long) bigmem & ~((long) 0xFFFF)) + 0x10000);
56 void PRNM(init)(void)
58 qbyte i;
60 DANM(mem) = a64kmalloc(NUM64KSEGS);
62 rb->srand((unsigned int)( rb->get_time()->tm_sec+rb->get_time()->tm_min*60 + rb->get_time()->tm_hour*3600));
63 for(i = 0; i < 0x10000; i++) DANM(mem)[i] = (byte) rb->rand();
65 for(i = 0; i < NUMDREGS; i++) {
66 DANM(nr)[i].p = DANM(mem);
67 DANM(nr)[i].d.d = (dbyte) rb->rand();
70 for(i = 0; i < BACKDREGS; i++) {
71 DANM(br)[i].p = DANM(mem);
72 DANM(br)[i].d.d = (dbyte) rb->rand();
75 for(i = 0; i < PORTNUM; i++) PRNM(inports)[i] = PRNM(outports)[i] = 0;
77 PRNM(local_init)();
79 return;
82 /* TODO: no interrupt immediately afer EI (not important for spectrum) */
84 void PRNM(nmi)(void)
86 DANM(iff2) = DANM(iff1);
87 DANM(iff1) = 0;
89 DANM(haltstate) = 0;
90 PRNM(pushpc)();
92 PC = 0x0066;
95 /* TODO: IM 0 emulation */
97 void PRNM(interrupt)(int data)
99 if(DANM(iff1)) {
101 DANM(haltstate) = 0;
102 DANM(iff1) = DANM(iff2) = 0;
104 switch(DANM(it_mode)) {
105 case 0:
106 PRNM(pushpc)();
107 PC = 0x0038;
108 break;
109 case 1:
110 PRNM(pushpc)();
111 PC = 0x0038;
112 break;
113 case 2:
114 PRNM(pushpc)();
115 PCL = DANM(mem)[(dbyte) (((int) RI << 8) + (data & 0xFF))];
116 PCH = DANM(mem)[(dbyte) (((int) RI << 8) + (data & 0xFF) + 1)];
117 break;
123 void PRNM(reset)(void)
125 DANM(haltstate) = 0;
126 DANM(iff1) = DANM(iff2) = 0;
127 DANM(it_mode) = 0;
128 RI = 0;
129 RR = 0;
130 PC = 0;