diff options
Diffstat (limited to 'apps/plugins/rockboy/hw.c')
-rw-r--r-- | apps/plugins/rockboy/hw.c | 204 |
1 files changed, 99 insertions, 105 deletions
diff --git a/apps/plugins/rockboy/hw.c b/apps/plugins/rockboy/hw.c index 794e4e4516..05cdfbc156 100644 --- a/apps/plugins/rockboy/hw.c +++ b/apps/plugins/rockboy/hw.c | |||
@@ -11,7 +11,7 @@ | |||
11 | #include "fastmem.h" | 11 | #include "fastmem.h" |
12 | 12 | ||
13 | 13 | ||
14 | struct hw hw; | 14 | struct hw hw IBSS_ATTR; |
15 | 15 | ||
16 | 16 | ||
17 | 17 | ||
@@ -24,17 +24,17 @@ struct hw hw; | |||
24 | 24 | ||
25 | void hw_interrupt(byte i, byte mask) | 25 | void hw_interrupt(byte i, byte mask) |
26 | { | 26 | { |
27 | byte oldif = R_IF; | 27 | byte oldif = R_IF; |
28 | i &= 0x1F & mask; | 28 | i &= 0x1F & mask; |
29 | R_IF |= i & (hw.ilines ^ i); | 29 | R_IF |= i & (hw.ilines ^ i); |
30 | 30 | ||
31 | /* FIXME - is this correct? not sure the docs understand... */ | 31 | /* FIXME - is this correct? not sure the docs understand... */ |
32 | if ((R_IF & (R_IF ^ oldif) & R_IE) && cpu.ime) cpu.halt = 0; | 32 | if ((R_IF & (R_IF ^ oldif) & R_IE) && cpu.ime) cpu.halt = 0; |
33 | /* if ((i & (hw.ilines ^ i) & R_IE) && cpu.ime) cpu.halt = 0; */ | 33 | /* if ((i & (hw.ilines ^ i) & R_IE) && cpu.ime) cpu.halt = 0; */ |
34 | /* if ((i & R_IE) && cpu.ime) cpu.halt = 0; */ | 34 | /* if ((i & R_IE) && cpu.ime) cpu.halt = 0; */ |
35 | 35 | ||
36 | hw.ilines &= ~mask; | 36 | hw.ilines &= ~mask; |
37 | hw.ilines |= i; | 37 | hw.ilines |= i; |
38 | } | 38 | } |
39 | 39 | ||
40 | 40 | ||
@@ -47,64 +47,65 @@ void hw_interrupt(byte i, byte mask) | |||
47 | 47 | ||
48 | void hw_dma(byte b) | 48 | void hw_dma(byte b) |
49 | { | 49 | { |
50 | int i; | 50 | int i; |
51 | addr a; | 51 | addr a; |
52 | 52 | ||
53 | a = ((addr)b) << 8; | 53 | a = ((addr)b) << 8; |
54 | for (i = 0; i < 160; i++, a++) | 54 | for (i = 0; i < 160; i++, a++) |
55 | lcd.oam.mem[i] = readb(a); | 55 | lcd.oam.mem[i] = readb(a); |
56 | } | 56 | } |
57 | 57 | ||
58 | 58 | void hw_hdma(void) | |
59 | |||
60 | void hw_hdma_cmd(byte c) | ||
61 | { | 59 | { |
62 | int cnt; | 60 | int cnt; |
63 | addr sa; | 61 | addr sa; |
64 | int da; | 62 | int da; |
65 | 63 | ||
66 | /* Begin or cancel HDMA */ | 64 | sa = ((addr)R_HDMA1 << 8) | (R_HDMA2&0xf0); |
67 | if ((hw.hdma|c) & 0x80) | 65 | da = 0x8000 | ((int)(R_HDMA3&0x1f) << 8) | (R_HDMA4&0xf0); |
68 | { | 66 | cnt = 16; |
69 | hw.hdma = c; | 67 | while (cnt--) |
70 | R_HDMA5 = c & 0x7f; | 68 | writeb(da++, readb(sa++)); |
71 | return; | 69 | cpu_timers(16); |
72 | } | 70 | R_HDMA1 = sa >> 8; |
73 | 71 | R_HDMA2 = sa & 0xF0; | |
74 | /* Perform GDMA */ | 72 | R_HDMA3 = 0x1F & (da >> 8); |
75 | sa = ((addr)R_HDMA1 << 8) | (R_HDMA2&0xf0); | 73 | R_HDMA4 = da & 0xF0; |
76 | da = 0x8000 | ((int)(R_HDMA3&0x1f) << 8) | (R_HDMA4&0xf0); | 74 | R_HDMA5--; |
77 | cnt = ((int)c)+1; | 75 | hw.hdma--; |
78 | /* FIXME - this should use cpu time! */ | ||
79 | /*cpu_timers(102 * cnt);*/ | ||
80 | cnt <<= 4; | ||
81 | while (cnt--) | ||
82 | writeb(da++, readb(sa++)); | ||
83 | R_HDMA1 = sa >> 8; | ||
84 | R_HDMA2 = sa & 0xF0; | ||
85 | R_HDMA3 = 0x1F & (da >> 8); | ||
86 | R_HDMA4 = da & 0xF0; | ||
87 | R_HDMA5 = 0xFF; | ||
88 | } | 76 | } |
89 | 77 | ||
90 | 78 | void hw_hdma_cmd(byte c) | |
91 | void hw_hdma(void) | ||
92 | { | 79 | { |
93 | int cnt; | 80 | int cnt; |
94 | addr sa; | 81 | addr sa; |
95 | int da; | 82 | int da; |
96 | 83 | ||
97 | sa = ((addr)R_HDMA1 << 8) | (R_HDMA2&0xf0); | 84 | /* Begin or cancel HDMA */ |
98 | da = 0x8000 | ((int)(R_HDMA3&0x1f) << 8) | (R_HDMA4&0xf0); | 85 | if ((hw.hdma|c) & 0x80) |
99 | cnt = 16; | 86 | { |
100 | while (cnt--) | 87 | hw.hdma = c; |
101 | writeb(da++, readb(sa++)); | 88 | R_HDMA5 = c & 0x7f; |
102 | R_HDMA1 = sa >> 8; | 89 | if ((R_STAT&0x03) == 0x00) hw_hdma(); |
103 | R_HDMA2 = sa & 0xF0; | 90 | return; |
104 | R_HDMA3 = 0x1F & (da >> 8); | 91 | } |
105 | R_HDMA4 = da & 0xF0; | 92 | |
106 | R_HDMA5--; | 93 | /* Perform GDMA */ |
107 | hw.hdma--; | 94 | sa = ((addr)R_HDMA1 << 8) | (R_HDMA2&0xf0); |
95 | da = 0x8000 | ((int)(R_HDMA3&0x1f) << 8) | (R_HDMA4&0xf0); | ||
96 | cnt = ((int)c)+1; | ||
97 | /* FIXME - this should use cpu time! */ | ||
98 | /*cpu_timers(102 * cnt);*/ | ||
99 | cpu_timers((460>>cpu.speed)+cnt*16); /*dalias*/ | ||
100 | /*cpu_timers(228 + (16*cnt));*/ /* this should be right according to no$ */ | ||
101 | cnt <<= 4; | ||
102 | while (cnt--) | ||
103 | writeb(da++, readb(sa++)); | ||
104 | R_HDMA1 = sa >> 8; | ||
105 | R_HDMA2 = sa & 0xF0; | ||
106 | R_HDMA3 = 0x1F & (da >> 8); | ||
107 | R_HDMA4 = da & 0xF0; | ||
108 | R_HDMA5 = 0xFF; | ||
108 | } | 109 | } |
109 | 110 | ||
110 | 111 | ||
@@ -116,20 +117,20 @@ void hw_hdma(void) | |||
116 | 117 | ||
117 | void pad_refresh() | 118 | void pad_refresh() |
118 | { | 119 | { |
119 | byte oldp1; | 120 | byte oldp1; |
120 | oldp1 = R_P1; | 121 | oldp1 = R_P1; |
121 | R_P1 &= 0x30; | 122 | R_P1 &= 0x30; |
122 | R_P1 |= 0xc0; | 123 | R_P1 |= 0xc0; |
123 | if (!(R_P1 & 0x10)) | 124 | if (!(R_P1 & 0x10)) |
124 | R_P1 |= (hw.pad & 0x0F); | 125 | R_P1 |= (hw.pad & 0x0F); |
125 | if (!(R_P1 & 0x20)) | 126 | if (!(R_P1 & 0x20)) |
126 | R_P1 |= (hw.pad >> 4); | 127 | R_P1 |= (hw.pad >> 4); |
127 | R_P1 ^= 0x0F; | 128 | R_P1 ^= 0x0F; |
128 | if (oldp1 & ~R_P1 & 0x0F) | 129 | if (oldp1 & ~R_P1 & 0x0F) |
129 | { | 130 | { |
130 | hw_interrupt(IF_PAD, IF_PAD); | 131 | hw_interrupt(IF_PAD, IF_PAD); |
131 | hw_interrupt(0, IF_PAD); | 132 | hw_interrupt(0, IF_PAD); |
132 | } | 133 | } |
133 | } | 134 | } |
134 | 135 | ||
135 | 136 | ||
@@ -140,44 +141,37 @@ void pad_refresh() | |||
140 | 141 | ||
141 | void pad_press(byte k) | 142 | void pad_press(byte k) |
142 | { | 143 | { |
143 | if (hw.pad & k) | 144 | if (hw.pad & k) |
144 | return; | 145 | return; |
145 | hw.pad |= k; | 146 | hw.pad |= k; |
146 | pad_refresh(); | 147 | pad_refresh(); |
147 | } | 148 | } |
148 | 149 | ||
149 | void pad_release(byte k) | 150 | void pad_release(byte k) |
150 | { | 151 | { |
151 | if (!(hw.pad & k)) | 152 | if (!(hw.pad & k)) |
152 | return; | 153 | return; |
153 | hw.pad &= ~k; | 154 | hw.pad &= ~k; |
154 | pad_refresh(); | 155 | pad_refresh(); |
155 | } | 156 | } |
156 | 157 | ||
157 | void pad_set(byte k, int st) | 158 | void pad_set(byte k, int st) |
158 | { | 159 | { |
159 | st ? pad_press(k) : pad_release(k); | 160 | st ? pad_press(k) : pad_release(k); |
160 | } | 161 | } |
161 | 162 | ||
162 | void hw_reset() | 163 | void hw_reset() |
163 | { | 164 | { |
164 | hw.ilines = hw.pad = 0; | 165 | hw.ilines = hw.pad = 0; |
165 | 166 | ||
166 | memset(ram.hi, 0, sizeof ram.hi); | 167 | memset(ram.hi, 0, sizeof ram.hi); |
167 | 168 | ||
168 | R_P1 = 0xFF; | 169 | R_P1 = 0xFF; |
169 | R_LCDC = 0x91; | 170 | R_LCDC = 0x91; |
170 | R_BGP = 0xFC; | 171 | R_BGP = 0xFC; |
171 | R_OBP0 = 0xFF; | 172 | R_OBP0 = 0xFF; |
172 | R_OBP1 = 0xFF; | 173 | R_OBP1 = 0xFF; |
173 | R_SVBK = 0x01; | 174 | R_SVBK = 0x01; |
174 | R_HDMA5 = 0xFF; | 175 | R_HDMA5 = 0xFF; |
175 | R_VBK = 0xFE; | 176 | R_VBK = 0xFE; |
176 | } | 177 | } |
177 | |||
178 | |||
179 | |||
180 | |||
181 | |||
182 | |||
183 | |||