src/gba/gba-io.c (view raw)
1#include "gba-io.h"
2
3#include "gba-video.h"
4
5void GBAIOWrite(struct GBA* gba, uint32_t address, uint16_t value) {
6 switch (address) {
7 case REG_DISPSTAT:
8 GBAVideoWriteDISPSTAT(&gba->video, value);
9 break;
10 case REG_DMA0CNT_LO:
11 GBAMemoryWriteDMACNT_LO(&gba->memory, 0, value);
12 break;
13 case REG_DMA0CNT_HI:
14 value = GBAMemoryWriteDMACNT_HI(&gba->memory, 0, value);
15 break;
16 case REG_DMA1CNT_LO:
17 GBAMemoryWriteDMACNT_LO(&gba->memory, 1, value);
18 break;
19 case REG_DMA1CNT_HI:
20 value = GBAMemoryWriteDMACNT_HI(&gba->memory, 1, value);
21 break;
22 case REG_DMA2CNT_LO:
23 GBAMemoryWriteDMACNT_LO(&gba->memory, 2, value);
24 break;
25 case REG_DMA2CNT_HI:
26 value = GBAMemoryWriteDMACNT_HI(&gba->memory, 2, value);
27 break;
28 case REG_DMA3CNT_LO:
29 GBAMemoryWriteDMACNT_LO(&gba->memory, 3, value);
30 break;
31 case REG_DMA3CNT_HI:
32 value = GBAMemoryWriteDMACNT_HI(&gba->memory, 3, value);
33 break;
34
35 case REG_WAITCNT:
36 GBAAdjustWaitstates(&gba->memory, value);
37 break;
38 case REG_IE:
39 GBAWriteIE(gba, value);
40 break;
41 case REG_IME:
42 GBAWriteIME(gba, value);
43 break;
44 case REG_HALTCNT:
45 value &= 0x80;
46 if (!value) {
47 GBAHalt(gba);
48 } else {
49 GBALog(GBA_LOG_STUB, "Stop unimplemented");
50 }
51 return;
52 default:
53 GBALog(GBA_LOG_STUB, "Stub I/O register write: %03x", address);
54 break;
55 }
56 gba->memory.io[address >> 1] = value;
57}
58
59void GBAIOWrite32(struct GBA* gba, uint32_t address, uint32_t value) {
60 switch (address) {
61 case REG_DMA0SAD_LO:
62 GBAMemoryWriteDMASAD(&gba->memory, 0, value);
63 break;
64 case REG_DMA0DAD_LO:
65 GBAMemoryWriteDMADAD(&gba->memory, 0, value);
66 break;
67 case REG_DMA1SAD_LO:
68 GBAMemoryWriteDMASAD(&gba->memory, 1, value);
69 break;
70 case REG_DMA1DAD_LO:
71 GBAMemoryWriteDMADAD(&gba->memory, 1, value);
72 break;
73 case REG_DMA2SAD_LO:
74 GBAMemoryWriteDMASAD(&gba->memory, 2, value);
75 break;
76 case REG_DMA2DAD_LO:
77 GBAMemoryWriteDMADAD(&gba->memory, 2, value);
78 break;
79 case REG_DMA3SAD_LO:
80 GBAMemoryWriteDMASAD(&gba->memory, 3, value);
81 break;
82 case REG_DMA3DAD_LO:
83 GBAMemoryWriteDMADAD(&gba->memory, 3, value);
84 break;
85 default:
86 GBAIOWrite(gba, address, value & 0xFFFF);
87 GBAIOWrite(gba, address | 2, value >> 16);
88 break;
89 }
90}
91
92uint16_t GBAIORead(struct GBA* gba, uint32_t address) {
93 switch (address) {
94 case REG_DISPSTAT:
95 return GBAVideoReadDISPSTAT(&gba->video);
96 break;
97 case REG_DMA0CNT_LO:
98 case REG_DMA1CNT_LO:
99 case REG_DMA2CNT_LO:
100 case REG_DMA3CNT_LO:
101 // Write-only register
102 return 0;
103 case REG_DMA0CNT_HI:
104 case REG_DMA1CNT_HI:
105 case REG_DMA2CNT_HI:
106 case REG_DMA3CNT_HI:
107 case REG_IE:
108 case REG_WAITCNT:
109 case REG_IME:
110 // Handled transparently by registers
111 break;
112 default:
113 GBALog(GBA_LOG_STUB, "Stub I/O register read: %03x", address);
114 break;
115 }
116 return gba->memory.io[address >> 1];
117}