Mercurial > repos > blastem
comparison zruntime.S @ 508:b976c6d6e5fb
Initial attempt at emulating extended bank area access delays when 68K bus is busy with VDP stuff. Also emulate the extra delay on the second access of a word-wide read to the bank area. Needs work as it seems to break stuff.
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Mon, 03 Feb 2014 09:18:10 -0800 |
parents | cc6030bd04c6 |
children | b3738ee58195 |
comparison
equal
deleted
inserted
replaced
507:cc6030bd04c6 | 508:b976c6d6e5fb |
---|---|
22 movw $0, 164(%rsi) | 22 movw $0, 164(%rsi) |
23 call z80_save_context_scratch | 23 call z80_save_context_scratch |
24 pop %rax /*return address in read/write func*/ | 24 pop %rax /*return address in read/write func*/ |
25 pop 104(%rsi) /*return address in native code*/ | 25 pop 104(%rsi) /*return address in native code*/ |
26 sub $5, %rax /* adjust return addres to point to the call instruction that got us here */ | 26 sub $5, %rax /* adjust return addres to point to the call instruction that got us here */ |
27 mov %rax, (%rsi) | |
28 | |
29 pop %r15 /* restore callee saved regsiters */ | |
30 pop %r14 | |
31 pop %r13 | |
32 pop %r12 | |
33 pop %rbp | |
34 pop %rbx | |
35 ret /* return to caller of z80_run */ | |
36 | |
37 forced_sync: | |
38 movw $0, 164(%rsi) | |
39 call z80_save_context_scratch | |
40 pop %rax /*return address in read/write func*/ | |
41 pop 104(%rsi) /*return address in native code*/ | |
27 mov %rax, (%rsi) | 42 mov %rax, (%rsi) |
28 | 43 |
29 pop %r15 /* restore callee saved regsiters */ | 44 pop %r15 /* restore callee saved regsiters */ |
30 pop %r14 | 45 pop %r14 |
31 pop %r13 | 46 pop %r13 |
105 z80_read_ram: | 120 z80_read_ram: |
106 and $0x1FFF, %r13 | 121 and $0x1FFF, %r13 |
107 mov (%r11, %r13), %r13b | 122 mov (%r11, %r13), %r13b |
108 ret | 123 ret |
109 z80_read_bank: | 124 z80_read_bank: |
110 /* approximation of wait states for 68K bus access */ | 125 push %rsi |
126 mov 144(%rsi), %rsi /* get system context pointer */ | |
127 cmp $0, 120(%rsi) /* check bus busy flag */ | |
128 pop %rsi | |
129 jne bus_busy | |
130 /* approximation of wait states for normal 68K bus access */ | |
111 add $3, %ebp | 131 add $3, %ebp |
132 z80_read_bank_cont: | |
112 and $0x7FFF, %r13 | 133 and $0x7FFF, %r13 |
113 cmp $0, %r12 | 134 cmp $0, %r12 |
114 je slow_bank_read | 135 je slow_bank_read |
115 /* 68K memory is byte swapped */ | 136 /* 68K memory is byte swapped */ |
116 xor $1, %r13 | 137 xor $1, %r13 |
117 mov (%r12, %r13), %r13b | 138 mov (%r12, %r13), %r13b |
118 ret | 139 ret |
119 slow_bank_read: | 140 slow_bank_read: |
120 /* TODO: Call into C to implement this */ | 141 /* TODO: Call into C to implement this */ |
121 ret | 142 ret |
143 bus_busy: | |
144 mov %edi, %ebp | |
145 call forced_sync | |
146 jp z80_read_bank_cont | |
122 z80_read_ym2612: | 147 z80_read_ym2612: |
123 call z80_save_context | 148 call z80_save_context |
124 mov %r13w, %di | 149 mov %r13w, %di |
125 push %rsi | 150 push %rsi |
126 call z80_read_ym | 151 call z80_read_ym |
197 jmp z80_load_context | 222 jmp z80_load_context |
198 | 223 |
199 .global z80_read_word | 224 .global z80_read_word |
200 z80_read_word: | 225 z80_read_word: |
201 call z_inccycles | 226 call z_inccycles |
227 cmp $0x8000, %r13w | |
228 jae z80_read_bank_word | |
202 push %r13 | 229 push %r13 |
203 call z80_read_byte_noinc | 230 call z80_read_byte_noinc |
204 mov %r13b, %r14b | 231 mov %r13b, %r14b |
205 pop %r13 | 232 pop %r13 |
206 inc %r13 | 233 inc %r13 |
207 call z_inccycles | 234 call z_inccycles |
208 call z80_read_byte_noinc | 235 call z80_read_byte_noinc |
209 shl $8, %r13w | 236 shl $8, %r13w |
210 mov %r14b, %r13b | 237 mov %r14b, %r13b |
211 ret | 238 ret |
239 | |
240 z80_read_bank_word: | |
241 push %rsi | |
242 mov 144(%rsi), %rsi /* get system context pointer */ | |
243 cmp $0, 120(%rsi) /* check bus busy flag */ | |
244 pop %rsi | |
245 jne bus_busy_word | |
246 add $3, %ebp /* first read typically has 3 wait states */ | |
247 z80_read_bank_word_cont: | |
248 push %r13 | |
249 call z80_read_bank_cont | |
250 mov %r13b, %r14b | |
251 pop %r13 | |
252 inc %r13 | |
253 call z_inccycles | |
254 push %rsi | |
255 mov 144(%rsi), %rsi /* get system context pointer */ | |
256 cmp $0, 120(%rsi) /* check bus busy flag */ | |
257 pop %rsi | |
258 jne bus_busy_word2 | |
259 add $4, %ebp /* second read typically has 4 wait states */ | |
260 z80_read_bank_word_cont2: | |
261 call z80_read_bank_cont | |
262 shl $8, %r13w | |
263 mov %r14b, %r13b | |
264 ret | |
265 | |
266 bus_busy_word: | |
267 mov %edi, %ebp | |
268 call forced_sync | |
269 jp z80_read_bank_word_cont | |
270 | |
271 bus_busy_word2: | |
272 mov %edi, %ebp | |
273 call forced_sync | |
274 jp z80_read_bank_word_cont2 | |
212 | 275 |
213 .global z80_write_word_highfirst | 276 .global z80_write_word_highfirst |
214 z80_write_word_highfirst: | 277 z80_write_word_highfirst: |
215 call z_inccycles | 278 call z_inccycles |
216 push %r14 | 279 push %r14 |