-
Notifications
You must be signed in to change notification settings - Fork 3
/
cpu_write.c
90 lines (80 loc) · 2.35 KB
/
cpu_write.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
#include "cpu_write.h"
#include "sim.h"
#include "memory_map.h"
#include "input_device.h"
#include "output_device.h"
extern unsigned int g_fc;
extern unsigned char g_ram[];
/* Write data to RAM or a device */
void cpu_write_byte(unsigned int address, unsigned int value)
{
if (g_fc & 2) /* Program */
exit_error("Attempted to write %02x to ROM address %08x", value & 0xff, address);
/* Otherwise it's data space */
if (address >= INPUT_ADDRESS_LO && address <= INPUT_ADDRESS_HI)
{
input_device_write(value & 0xff);
return;
}
else if (address >= OUTPUT_ADDRESS_LO && address <= OUTPUT_ADDRESS_HI)
{
output_device_write(value & 0xff);
return;
}
else if (address >= LED_ADDRESS_LO && address <= LED_ADDRESS_HI)
{
led_write(value & 0xff);
return;
}
if (address > MAX_RAM)
exit_error("Attempted to write %02x to RAM address %08x", value & 0xff, address);
WRITE_BYTE(g_ram, address, value);
}
void cpu_write_word(unsigned int address, unsigned int value)
{
if (g_fc & 2) /* Program */
exit_error("Attempted to write %04x to ROM address %08x", value & 0xffff, address);
/* Otherwise it's data space */
if (address >= INPUT_ADDRESS_LO && address <= INPUT_ADDRESS_HI)
{
input_device_write(value & 0xffff);
return;
}
else if (address >= OUTPUT_ADDRESS_LO && address <= OUTPUT_ADDRESS_HI)
{
output_device_write(value & 0xffff);
return;
}
else if (address >= LED_ADDRESS_LO && address <= LED_ADDRESS_HI)
{
led_write(value & 0xffff);
return;
}
if (address > MAX_RAM)
exit_error("Attempted to write %04x to RAM address %08x", value & 0xffff, address);
WRITE_WORD(g_ram, address, value);
}
void cpu_write_long(unsigned int address, unsigned int value)
{
if (g_fc & 2) /* Program */
exit_error("Attempted to write %08x to ROM address %08x", value, address);
/* Otherwise it's data space */
if (address >= INPUT_ADDRESS_LO && address <= INPUT_ADDRESS_HI)
{
input_device_write(value);
return;
}
else if (address >= OUTPUT_ADDRESS_LO && address <= OUTPUT_ADDRESS_HI)
{
output_device_write(value);
return;
}
else if (address >= LED_ADDRESS_LO && address <= LED_ADDRESS_HI)
{
led_write(value);
return;
}
if (address > MAX_RAM)
exit_error("Attempted to write %08x to RAM address %08x", value, address);
WRITE_LONG(g_ram, address, value);
}