summaryrefslogtreecommitdiff
path: root/zruntime.S
diff options
context:
space:
mode:
authorMichael Pavone <pavone@retrodev.com>2014-02-03 09:18:10 -0800
committerMichael Pavone <pavone@retrodev.com>2014-02-03 09:18:10 -0800
commite14e901df89aa1823b1479366b58196247c16bd2 (patch)
tree14e076b4b2a409974b73dd15278c8394833ad89c /zruntime.S
parentefcdc09b1c58be04a53fa84ea34981d4231c1a78 (diff)
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.
Diffstat (limited to 'zruntime.S')
-rw-r--r--zruntime.S65
1 files changed, 64 insertions, 1 deletions
diff --git a/zruntime.S b/zruntime.S
index 122f058..fa803fe 100644
--- a/zruntime.S
+++ b/zruntime.S
@@ -34,6 +34,21 @@ sync_io:
pop %rbx
ret /* return to caller of z80_run */
+forced_sync:
+ movw $0, 164(%rsi)
+ call z80_save_context_scratch
+ pop %rax /*return address in read/write func*/
+ pop 104(%rsi) /*return address in native code*/
+ mov %rax, (%rsi)
+
+ pop %r15 /* restore callee saved regsiters */
+ pop %r14
+ pop %r13
+ pop %r12
+ pop %rbp
+ pop %rbx
+ ret /* return to caller of z80_run */
+
.global z80_handle_cycle_limit_int
z80_handle_cycle_limit_int:
cmp 116(%rsi), %ebp
@@ -107,8 +122,14 @@ z80_read_ram:
mov (%r11, %r13), %r13b
ret
z80_read_bank:
- /* approximation of wait states for 68K bus access */
+ push %rsi
+ mov 144(%rsi), %rsi /* get system context pointer */
+ cmp $0, 120(%rsi) /* check bus busy flag */
+ pop %rsi
+ jne bus_busy
+ /* approximation of wait states for normal 68K bus access */
add $3, %ebp
+z80_read_bank_cont:
and $0x7FFF, %r13
cmp $0, %r12
je slow_bank_read
@@ -119,6 +140,10 @@ z80_read_bank:
slow_bank_read:
/* TODO: Call into C to implement this */
ret
+bus_busy:
+ mov %edi, %ebp
+ call forced_sync
+ jp z80_read_bank_cont
z80_read_ym2612:
call z80_save_context
mov %r13w, %di
@@ -199,6 +224,8 @@ z80_write_vdp:
.global z80_read_word
z80_read_word:
call z_inccycles
+ cmp $0x8000, %r13w
+ jae z80_read_bank_word
push %r13
call z80_read_byte_noinc
mov %r13b, %r14b
@@ -210,6 +237,42 @@ z80_read_word:
mov %r14b, %r13b
ret
+z80_read_bank_word:
+ push %rsi
+ mov 144(%rsi), %rsi /* get system context pointer */
+ cmp $0, 120(%rsi) /* check bus busy flag */
+ pop %rsi
+ jne bus_busy_word
+ add $3, %ebp /* first read typically has 3 wait states */
+z80_read_bank_word_cont:
+ push %r13
+ call z80_read_bank_cont
+ mov %r13b, %r14b
+ pop %r13
+ inc %r13
+ call z_inccycles
+ push %rsi
+ mov 144(%rsi), %rsi /* get system context pointer */
+ cmp $0, 120(%rsi) /* check bus busy flag */
+ pop %rsi
+ jne bus_busy_word2
+ add $4, %ebp /* second read typically has 4 wait states */
+z80_read_bank_word_cont2:
+ call z80_read_bank_cont
+ shl $8, %r13w
+ mov %r14b, %r13b
+ ret
+
+bus_busy_word:
+ mov %edi, %ebp
+ call forced_sync
+ jp z80_read_bank_word_cont
+
+bus_busy_word2:
+ mov %edi, %ebp
+ call forced_sync
+ jp z80_read_bank_word_cont2
+
.global z80_write_word_highfirst
z80_write_word_highfirst:
call z_inccycles