Mercurial > repos > blastem
comparison runtime.S @ 54:3b79cbcf6846
Get Flavio's color bar demo kind of sort of working
author | Mike Pavone <pavone@retrodev.com> |
---|---|
date | Tue, 18 Dec 2012 02:16:42 -0800 |
parents | 44e661913a51 |
children | bc3bc7a60c4e |
comparison
equal
deleted
inserted
replaced
53:44e661913a51 | 54:3b79cbcf6846 |
---|---|
1 | 1 |
2 .global handle_cycle_limit | 2 .global handle_cycle_limit |
3 handle_cycle_limit: | 3 handle_cycle_limit: |
4 ret | 4 call m68k_save_context |
5 mov %rsi, %rdi | |
6 call sync_components | |
7 mov %rax, %rsi | |
8 call m68k_load_context | |
9 ret | |
10 | |
11 do_vdp_port_write: | |
12 call m68k_save_context | |
13 mov %rcx, %rdx | |
14 call vdp_port_write | |
15 mov %rax, %rsi | |
16 call m68k_load_context | |
17 ret | |
18 | |
19 do_vdp_port_read: | |
20 call m68k_save_context | |
21 call vdp_port_read | |
22 mov %rax, %rsi | |
23 call m68k_load_context | |
24 mov 120(%rsi), %cx | |
25 ret | |
26 | |
27 bad_access_msg: | |
28 .asciz "Program tried to access illegal 68K address %X\n" | |
5 | 29 |
6 .global m68k_write_word | 30 .global m68k_write_word |
31 .global vdp_psg_w | |
7 m68k_write_word: | 32 m68k_write_word: |
8 and $0xFFFFFF, %rdi | 33 and $0xFFFFFF, %rdi |
9 cmp $0x400000, %edi | 34 cmp $0x400000, %edi |
10 jle cart_w | 35 jle cart_w |
11 cmp $0xE00000, %edi | 36 cmp $0xE00000, %edi |
12 jge workram_w | 37 jge workram_w |
38 cmp $0xC00000, %edi | |
39 jge vdp_psg_w | |
13 jmp inccycles | 40 jmp inccycles |
14 workram_w: | 41 workram_w: |
15 and $0xFFFF, %rdi | 42 and $0xFFFF, %rdi |
16 mov %cx, (%r9, %rdi) | 43 mov %cx, (%r9, %rdi) |
17 jmp inccycles | 44 jmp inccycles |
18 cart_w: | 45 cart_w: |
19 mov %cx, (%r8, %rdi) | 46 mov %cx, (%r8, %rdi) |
20 jmp inccycles | 47 jmp inccycles |
48 vdp_psg_w: | |
49 test $0x2700E0, %edi | |
50 jnz crash | |
51 and $0x1F, %edi | |
52 cmp $4, %edi | |
53 jl try_fifo_write | |
54 jmp do_vdp_port_write | |
55 try_fifo_write: | |
56 push %rdx | |
57 push %rbx | |
58 /* fetch VDP context pointer from 68K context */ | |
59 mov 112(%rsi), %rdx | |
60 /* get fifo_cur and compare it to fifo_end */ | |
61 mov (%rdx), %rbx | |
62 cmp %rbx, 8(%rdx) | |
63 /* bail out if fifo is full */ | |
64 je fifo_fallback | |
65 /* populate FIFO entry */ | |
66 mov %cx, 4(%rbx) /* value */ | |
67 movb $0, 6(%rbx) /* partial */ | |
68 mov %eax, %ecx | |
69 shl $3, %ecx /* multiply by 68K cycle by 7 to get MCLK cycle */ | |
70 sub %eax, %ecx | |
71 mov %ecx, (%rbx) /* cycle */ | |
72 /* update fifo_cur and store back in 68K context */ | |
73 add $8, %rbx | |
74 mov %rbx, (%rdx) | |
75 /* clear pending flag */ | |
76 andb $0xEF, 19(%rdx) | |
77 pop %rbx | |
78 pop %rdx | |
79 jmp inccycles | |
80 fifo_fallback: | |
81 pop %rbx | |
82 pop %rdx | |
83 jmp do_vdp_port_write | |
84 crash: | |
85 mov %edi, %esi | |
86 lea bad_access_msg(%rip), %rdi | |
87 call printf | |
88 mov $1, %rdi | |
89 call exit | |
21 | 90 |
22 .global m68k_write_byte | 91 .global m68k_write_byte |
23 m68k_write_byte: | 92 m68k_write_byte: |
24 and $0xFFFFFF, %rdi | 93 and $0xFFFFFF, %rdi |
25 /* deal with byte swapping */ | 94 /* deal with byte swapping */ |
62 and $0xFFFFFF, %rcx | 131 and $0xFFFFFF, %rcx |
63 cmp $0x400000, %ecx | 132 cmp $0x400000, %ecx |
64 jle cart | 133 jle cart |
65 cmp $0xE00000, %ecx | 134 cmp $0xE00000, %ecx |
66 jge workram | 135 jge workram |
136 cmp $0xC00000, %edi | |
137 jge vdp_psg | |
67 xor %cx, %cx | 138 xor %cx, %cx |
139 dec %cx | |
68 jmp inccycles | 140 jmp inccycles |
69 workram: | 141 workram: |
70 and $0xFFFF, %rcx | 142 and $0xFFFF, %rcx |
71 mov (%r9, %rcx), %cx | 143 mov (%r9, %rcx), %cx |
72 jmp inccycles | 144 jmp inccycles |
145 vdp_psg: | |
146 test $0x2700E0, %edi | |
147 jnz crash | |
148 and $0x1F, %edi | |
149 jmp do_vdp_port_read | |
73 cart: | 150 cart: |
74 mov (%r8, %rcx), %cx | 151 mov (%r8, %rcx), %cx |
75 inccycles: | 152 inccycles: |
76 add $4, %rax | 153 add $4, %rax |
77 cmp %rbp, %rax | 154 cmp %rbp, %rax |
78 jge sync | 155 jge handle_cycle_limit |
79 ret | |
80 sync: | |
81 ret | 156 ret |
82 | 157 |
83 .global m68k_read_long_scratch1 | 158 .global m68k_read_long_scratch1 |
84 m68k_read_long_scratch1: | 159 m68k_read_long_scratch1: |
85 push %rcx | 160 push %rcx |
101 cmp $0x400000, %ecx | 176 cmp $0x400000, %ecx |
102 jle cart_b | 177 jle cart_b |
103 cmp $0xE00000, %ecx | 178 cmp $0xE00000, %ecx |
104 jge workram_b | 179 jge workram_b |
105 xor %cl, %cl | 180 xor %cl, %cl |
181 dec %cl | |
106 jmp inccycles | 182 jmp inccycles |
107 workram_b: | 183 workram_b: |
108 and $0xFFFF, %rcx | 184 and $0xFFFF, %rcx |
109 mov (%r9, %rcx), %cl | 185 mov (%r9, %rcx), %cl |
110 jmp inccycles | 186 jmp inccycles |
144 mov %r11d, 12(%rsi) /* d1 */ | 220 mov %r11d, 12(%rsi) /* d1 */ |
145 mov %r12d, 16(%rsi) /* d2 */ | 221 mov %r12d, 16(%rsi) /* d2 */ |
146 mov %r13d, 40(%rsi) /* a0 */ | 222 mov %r13d, 40(%rsi) /* a0 */ |
147 mov %r14d, 44(%rsi) /* a1 */ | 223 mov %r14d, 44(%rsi) /* a1 */ |
148 mov %r15d, 68(%rsi) /* a7 */ | 224 mov %r15d, 68(%rsi) /* a7 */ |
225 mov %eax, 76(%rsi) /* current cycle count */ | |
149 ret | 226 ret |
150 | 227 |
151 .global m68k_load_context | 228 .global m68k_load_context |
152 m68k_load_context: | 229 m68k_load_context: |
153 mov 1(%rsi), %bl /* N Flag */ | 230 mov 1(%rsi), %bl /* N Flag */ |