-
Notifications
You must be signed in to change notification settings - Fork 6
/
emu-mem-io.c
179 lines (131 loc) · 2.87 KB
/
emu-mem-io.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
#include "emu-mem-io.h"
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
// Memory status
byte_t mem_stat [MEM_MAX];
byte_t code_stat [MEM_MAX];
// TODO: implement data status
// byte_t data_stat [MEM_MAX];
byte_t _break_data_flag = 0;
addr_t _break_data_addr = 0x100000;
// Memory access
void * mem_get_addr (addr_t a)
{
if (a >= MEM_MAX)
{
printf ("\nwarning: accessing out of memory @ %lXh\n", a);
}
a &= (MEM_MAX - 1);
// Data breakpoint test
// Will break the main execution loop later
if (a == _break_data_addr)
_break_data_flag = 1;
return (mem_stat + a);
}
byte_t mem_read_byte_0 (addr_t a)
{
byte_t * p = (byte_t *) mem_get_addr (a);
return *p;
}
word_t mem_read_word_0 (addr_t a)
{
word_t * p = (word_t *) mem_get_addr (a);
return *p;
}
int mem_write_byte_0 (addr_t a, byte_t b, byte_t init)
{
int err = 0;
if (a >= ROM_BASE && !init) // Protect ROM
{
printf ("\nerror: writing byte into ROM @ %lXh\n", a);
err = -1;
}
else
{
byte_t * p = (byte_t *) mem_get_addr (a);
*p = b;
// No more traced instruction here
code_stat [a] = 0;
}
return err;
}
int mem_write_word_0 (addr_t a, word_t w, byte_t init)
{
int err = 0;
if (a >= (ROM_BASE - 1) && !init) // Protect ROM
{
printf ("\nerror: writing word into ROM @ %lxh\n", a);
err = -1;
}
else
{
word_t * p = (word_t *) mem_get_addr (a);
*p = w;
// No more traced instruction here
code_stat [a] = 0;
code_stat [a + 1] = 0;
}
return err;
}
//-------------------------------------------------------------------------------
// Memory reset
void mem_io_reset ()
{
// No or uninitialized memory: all bits to 1
// Used to check if interrupt vector is initialized in op_int()
memset (mem_stat, 0xFF, sizeof mem_stat);
// No traced instruction for now
memset (code_stat, 0x00, sizeof code_stat);
}
//-------------------------------------------------------------------------------
int io_read_byte_0 (word_t p, byte_t * b)
{
int err = 0;
switch (p)
{
default:
printf ("\nerror: I/O read byte from unmapped %hXh", p);
err = -1;
}
return err;
}
int io_write_byte_0 (word_t p, byte_t b)
{
int err = 0;
switch (p)
{
default:
printf ("\nerror: I/O write byte %hhXh to unmapped %hXh", b, p);
err = -1;
}
return err;
}
int io_read_word_0 (word_t p, word_t * w)
{
int err;
if (p & 0x0001) {
printf ("\nerror: I/O read word unaligned %hXh", p);
err = -1;
}
else {
printf ("\nerror: I/O read word from unmapped %hXh", p);
err = -1;
}
return err;
}
int io_write_word_0 (word_t p, word_t w)
{
int err;
if (p & 0x0001) {
printf ("\nerror: I/O write word %hXh unaligned %hXh", w, p);
err = -1;
}
else {
// no port
printf ("\nerror: I/O write word %hXh to unmapped %hXh", w, p);
err = -1;
}
return err;
}
//-------------------------------------------------------------------------------