summaryrefslogtreecommitdiff
path: root/runtime.S
diff options
context:
space:
mode:
Diffstat (limited to 'runtime.S')
-rw-r--r--runtime.S83
1 files changed, 80 insertions, 3 deletions
diff --git a/runtime.S b/runtime.S
index c4530c0..b9c91a0 100644
--- a/runtime.S
+++ b/runtime.S
@@ -1,15 +1,42 @@
.global handle_cycle_limit
handle_cycle_limit:
+ call m68k_save_context
+ mov %rsi, %rdi
+ call sync_components
+ mov %rax, %rsi
+ call m68k_load_context
+ ret
+
+do_vdp_port_write:
+ call m68k_save_context
+ mov %rcx, %rdx
+ call vdp_port_write
+ mov %rax, %rsi
+ call m68k_load_context
+ ret
+
+do_vdp_port_read:
+ call m68k_save_context
+ call vdp_port_read
+ mov %rax, %rsi
+ call m68k_load_context
+ mov 120(%rsi), %cx
ret
+bad_access_msg:
+ .asciz "Program tried to access illegal 68K address %X\n"
+
.global m68k_write_word
+ .global vdp_psg_w
m68k_write_word:
and $0xFFFFFF, %rdi
cmp $0x400000, %edi
jle cart_w
cmp $0xE00000, %edi
jge workram_w
+ cmp $0xC00000, %edi
+ jge vdp_psg_w
jmp inccycles
workram_w:
and $0xFFFF, %rdi
@@ -18,6 +45,48 @@ workram_w:
cart_w:
mov %cx, (%r8, %rdi)
jmp inccycles
+vdp_psg_w:
+ test $0x2700E0, %edi
+ jnz crash
+ and $0x1F, %edi
+ cmp $4, %edi
+ jl try_fifo_write
+ jmp do_vdp_port_write
+try_fifo_write:
+ push %rdx
+ push %rbx
+ /* fetch VDP context pointer from 68K context */
+ mov 112(%rsi), %rdx
+ /* get fifo_cur and compare it to fifo_end */
+ mov (%rdx), %rbx
+ cmp %rbx, 8(%rdx)
+ /* bail out if fifo is full */
+ je fifo_fallback
+ /* populate FIFO entry */
+ mov %cx, 4(%rbx) /* value */
+ movb $0, 6(%rbx) /* partial */
+ mov %eax, %ecx
+ shl $3, %ecx /* multiply by 68K cycle by 7 to get MCLK cycle */
+ sub %eax, %ecx
+ mov %ecx, (%rbx) /* cycle */
+ /* update fifo_cur and store back in 68K context */
+ add $8, %rbx
+ mov %rbx, (%rdx)
+ /* clear pending flag */
+ andb $0xEF, 19(%rdx)
+ pop %rbx
+ pop %rdx
+ jmp inccycles
+fifo_fallback:
+ pop %rbx
+ pop %rdx
+ jmp do_vdp_port_write
+crash:
+ mov %edi, %esi
+ lea bad_access_msg(%rip), %rdi
+ call printf
+ mov $1, %rdi
+ call exit
.global m68k_write_byte
m68k_write_byte:
@@ -64,20 +133,26 @@ m68k_read_word_scratch1:
jle cart
cmp $0xE00000, %ecx
jge workram
+ cmp $0xC00000, %edi
+ jge vdp_psg
xor %cx, %cx
+ dec %cx
jmp inccycles
workram:
and $0xFFFF, %rcx
mov (%r9, %rcx), %cx
jmp inccycles
+vdp_psg:
+ test $0x2700E0, %edi
+ jnz crash
+ and $0x1F, %edi
+ jmp do_vdp_port_read
cart:
mov (%r8, %rcx), %cx
inccycles:
add $4, %rax
cmp %rbp, %rax
- jge sync
- ret
-sync:
+ jge handle_cycle_limit
ret
.global m68k_read_long_scratch1
@@ -103,6 +178,7 @@ m68k_read_byte_scratch1:
cmp $0xE00000, %ecx
jge workram_b
xor %cl, %cl
+ dec %cl
jmp inccycles
workram_b:
and $0xFFFF, %rcx
@@ -146,6 +222,7 @@ m68k_save_context:
mov %r13d, 40(%rsi) /* a0 */
mov %r14d, 44(%rsi) /* a1 */
mov %r15d, 68(%rsi) /* a7 */
+ mov %eax, 76(%rsi) /* current cycle count */
ret
.global m68k_load_context