summaryrefslogtreecommitdiff
path: root/apps/plugins/zxbox/z80.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/plugins/zxbox/z80.c')
-rw-r--r--apps/plugins/zxbox/z80.c132
1 files changed, 132 insertions, 0 deletions
diff --git a/apps/plugins/zxbox/z80.c b/apps/plugins/zxbox/z80.c
new file mode 100644
index 0000000000..90b41c93d3
--- /dev/null
+++ b/apps/plugins/zxbox/z80.c
@@ -0,0 +1,132 @@
1/*
2 * Copyright (C) 1996-1998 Szeredi Miklos
3 * Email: mszeredi@inf.bme.hu
4 *
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.
9 *
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.
14 *
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.
18 *
19 */
20
21#include "z80.h"
22
23#include <stdio.h>
24#include <stdlib.h>
25#include <time.h>
26#include "zxconfig.h"
27#include "helpers.h"
28Z80 PRNM(proc);
29
30byte PRNM(inports)[PORTNUM];
31byte PRNM(outports)[PORTNUM];
32
33
34#ifdef SPECT_MEM
35#define NUM64KSEGS 3
36#endif
37
38#ifndef NUM64KSEGS
39#define NUM64KSEGS 1
40#endif
41
42static byte *a64kmalloc(int num64ksegs)
43{
44 byte *bigmem;
45
46 bigmem = (byte *) my_malloc((unsigned) (0x10000 * (num64ksegs + 1)));
47 if(bigmem == NULL) {
48 /*fprintf(stderr, "Out of memory!\n");*/
49 /*exit(1);*/
50 }
51
52 return (byte *) (( (long) bigmem & ~((long) 0xFFFF)) + 0x10000);
53}
54
55
56
57void PRNM(init)(void)
58{
59 qbyte i;
60
61 DANM(mem) = a64kmalloc(NUM64KSEGS);
62
63 rb->srand((unsigned int)( rb->get_time()->tm_sec+rb->get_time()->tm_min*60 + rb->get_time()->tm_hour*3600));
64 for(i = 0; i < 0x10000; i++) DANM(mem)[i] = (byte) rb->rand();
65
66 for(i = 0; i < NUMDREGS; i++) {
67 DANM(nr)[i].p = DANM(mem);
68 DANM(nr)[i].d.d = (dbyte) rb->rand();
69 }
70
71 for(i = 0; i < BACKDREGS; i++) {
72 DANM(br)[i].p = DANM(mem);
73 DANM(br)[i].d.d = (dbyte) rb->rand();
74 }
75
76 for(i = 0; i < PORTNUM; i++) PRNM(inports)[i] = PRNM(outports)[i] = 0;
77
78 PRNM(local_init)();
79
80 return;
81}
82
83/* TODO: no interrupt immediately afer EI (not important for spectrum) */
84
85void PRNM(nmi)(void)
86{
87 DANM(iff2) = DANM(iff1);
88 DANM(iff1) = 0;
89
90 DANM(haltstate) = 0;
91 PRNM(pushpc)();
92
93 PC = 0x0066;
94}
95
96/* TODO: IM 0 emulation */
97
98void PRNM(interrupt)(int data)
99{
100 if(DANM(iff1)) {
101
102 DANM(haltstate) = 0;
103 DANM(iff1) = DANM(iff2) = 0;
104
105 switch(DANM(it_mode)) {
106 case 0:
107 PRNM(pushpc)();
108 PC = 0x0038;
109 break;
110 case 1:
111 PRNM(pushpc)();
112 PC = 0x0038;
113 break;
114 case 2:
115 PRNM(pushpc)();
116 PCL = DANM(mem)[(dbyte) (((int) RI << 8) + (data & 0xFF))];
117 PCH = DANM(mem)[(dbyte) (((int) RI << 8) + (data & 0xFF) + 1)];
118 break;
119 }
120 }
121}
122
123
124void PRNM(reset)(void)
125{
126 DANM(haltstate) = 0;
127 DANM(iff1) = DANM(iff2) = 0;
128 DANM(it_mode) = 0;
129 RI = 0;
130 RR = 0;
131 PC = 0;
132}