Hackfix and re-enable strtoull and wcstoull, see bug #3798.
[sdcc.git] / sdcc-extra / emu / rrz80 / cpu / z80.c
blob024a8e357e30a9d57d97d45c0e980b21ffdb129c
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 <string.h>
26 #include <time.h>
28 Z80 PRNM(proc);
30 byte PRNM(inports)[PORTNUM];
31 byte PRNM(outports)[PORTNUM];
34 #ifdef SPECT_MEM
35 #define NUM64KSEGS 3
36 #endif
38 #ifndef NUM64KSEGS
39 #define NUM64KSEGS 1
40 #endif
42 static byte *a64kmalloc(int num64ksegs)
44 byte *bigmem;
46 bigmem = (byte *) malloc((unsigned) (0x10000 * (num64ksegs + 1)));
47 if(bigmem == NULL) {
48 fprintf(stderr, "Out of memory!\n");
49 exit(1);
52 return (byte *) (( (long) bigmem & ~((long) 0xFFFF)) + 0x10000);
57 void PRNM(init)(void)
59 qbyte i;
61 DANM(mem) = a64kmalloc(NUM64KSEGS);
63 srand((unsigned int) time(NULL));
64 #if RAND_FILL_MEM
65 for(i = 0; i < 0x10000; i++) DANM(mem)[i] = (byte) rand();
66 #elif CLEAR_MEM
67 memset(DANM(mem), 0, 0x10000);
68 #endif
70 for(i = 0; i < NUMDREGS; i++) {
71 DANM(nr)[i].p = DANM(mem);
72 DANM(nr)[i].d.d = (dbyte) rand();
75 for(i = 0; i < BACKDREGS; i++) {
76 DANM(br)[i].p = DANM(mem);
77 DANM(br)[i].d.d = (dbyte) rand();
80 for(i = 0; i < PORTNUM; i++) PRNM(inports)[i] = PRNM(outports)[i] = 0;
82 PRNM(local_init)();
84 return;
87 /* TODO: no interrupt immediately afer EI (not important for spectrum) */
89 void PRNM(nmi)(void)
91 DANM(iff2) = DANM(iff1);
92 DANM(iff1) = 0;
94 DANM(haltstate) = 0;
95 PRNM(pushpc)();
97 PC = 0x0066;
100 /* TODO: IM 0 emulation */
102 void PRNM(interrupt)(int data)
104 if(DANM(iff1)) {
106 DANM(haltstate) = 0;
107 DANM(iff1) = DANM(iff2) = 0;
109 switch(DANM(it_mode)) {
110 case 0:
111 PRNM(pushpc)();
112 PC = 0x0038;
113 break;
114 case 1:
115 PRNM(pushpc)();
116 PC = 0x0038;
117 break;
118 case 2:
119 PRNM(pushpc)();
120 PCL = DANM(mem)[(dbyte) (((int) RI << 8) + (data & 0xFF))];
121 PCH = DANM(mem)[(dbyte) (((int) RI << 8) + (data & 0xFF) + 1)];
122 break;
128 void PRNM(reset)(void)
130 DANM(haltstate) = 0;
131 DANM(iff1) = DANM(iff2) = 0;
132 DANM(it_mode) = 0;
133 RI = 0;
134 RR = 0;
135 PC = 0;