Mercurial > repos > blastem
annotate zruntime.S @ 730:38e9bee03749
More bugfixes for the 32-bit build of the Z80 core
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Sun, 24 May 2015 15:05:18 -0700 |
parents | e13f4fd9cf6d |
children |
rev | line source |
---|---|
284
ed7098f717d7
Implement IN and OUT (untested)
Mike Pavone <pavone@retrodev.com>
parents:
281
diff
changeset
|
1 z_inccycles_io: |
ed7098f717d7
Implement IN and OUT (untested)
Mike Pavone <pavone@retrodev.com>
parents:
281
diff
changeset
|
2 cmp %edi, %ebp |
ed7098f717d7
Implement IN and OUT (untested)
Mike Pavone <pavone@retrodev.com>
parents:
281
diff
changeset
|
3 jnb do_limit |
ed7098f717d7
Implement IN and OUT (untested)
Mike Pavone <pavone@retrodev.com>
parents:
281
diff
changeset
|
4 no_sync_io: |
ed7098f717d7
Implement IN and OUT (untested)
Mike Pavone <pavone@retrodev.com>
parents:
281
diff
changeset
|
5 add $4, %ebp |
ed7098f717d7
Implement IN and OUT (untested)
Mike Pavone <pavone@retrodev.com>
parents:
281
diff
changeset
|
6 ret |
ed7098f717d7
Implement IN and OUT (untested)
Mike Pavone <pavone@retrodev.com>
parents:
281
diff
changeset
|
7 do_limit_io: |
ed7098f717d7
Implement IN and OUT (untested)
Mike Pavone <pavone@retrodev.com>
parents:
281
diff
changeset
|
8 cmp 112(%rsi), %ebp |
ed7098f717d7
Implement IN and OUT (untested)
Mike Pavone <pavone@retrodev.com>
parents:
281
diff
changeset
|
9 jb no_sync_io |
ed7098f717d7
Implement IN and OUT (untested)
Mike Pavone <pavone@retrodev.com>
parents:
281
diff
changeset
|
10 jmp sync_io |
ed7098f717d7
Implement IN and OUT (untested)
Mike Pavone <pavone@retrodev.com>
parents:
281
diff
changeset
|
11 |
249
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
12 z_inccycles: |
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
13 cmp %edi, %ebp |
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
14 jnb do_limit |
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
15 no_sync: |
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
16 add $3, %ebp |
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
17 ret |
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
18 do_limit: |
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
19 cmp 112(%rsi), %ebp |
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
20 jb no_sync |
284
ed7098f717d7
Implement IN and OUT (untested)
Mike Pavone <pavone@retrodev.com>
parents:
281
diff
changeset
|
21 sync_io: |
451
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
393
diff
changeset
|
22 movw $0, 164(%rsi) |
249
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
23 call z80_save_context_scratch |
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
24 pop %rax /*return address in read/write func*/ |
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
25 pop 104(%rsi) /*return address in native code*/ |
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
26 sub $5, %rax /* adjust return addres to point to the call instruction that got us here */ |
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
27 mov %rax, (%rsi) |
451
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
393
diff
changeset
|
28 |
249
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
29 pop %r15 /* restore callee saved regsiters */ |
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
30 pop %r14 |
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
31 pop %r13 |
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
32 pop %r12 |
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
33 pop %rbp |
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
34 pop %rbx |
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
35 ret /* return to caller of z80_run */ |
451
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
393
diff
changeset
|
36 |
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.
Michael Pavone <pavone@retrodev.com>
parents:
507
diff
changeset
|
37 forced_sync: |
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.
Michael Pavone <pavone@retrodev.com>
parents:
507
diff
changeset
|
38 movw $0, 164(%rsi) |
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.
Michael Pavone <pavone@retrodev.com>
parents:
507
diff
changeset
|
39 call z80_save_context_scratch |
509
b3738ee58195
Fix accidental use of the conditional jump instruction jp instead of jmp
Michael Pavone <pavone@retrodev.com>
parents:
508
diff
changeset
|
40 pop (%rsi) /*return address in read/write func*/ |
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.
Michael Pavone <pavone@retrodev.com>
parents:
507
diff
changeset
|
41 pop 104(%rsi) /*return address in native code*/ |
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.
Michael Pavone <pavone@retrodev.com>
parents:
507
diff
changeset
|
42 |
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.
Michael Pavone <pavone@retrodev.com>
parents:
507
diff
changeset
|
43 pop %r15 /* restore callee saved regsiters */ |
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.
Michael Pavone <pavone@retrodev.com>
parents:
507
diff
changeset
|
44 pop %r14 |
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.
Michael Pavone <pavone@retrodev.com>
parents:
507
diff
changeset
|
45 pop %r13 |
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.
Michael Pavone <pavone@retrodev.com>
parents:
507
diff
changeset
|
46 pop %r12 |
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.
Michael Pavone <pavone@retrodev.com>
parents:
507
diff
changeset
|
47 pop %rbp |
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.
Michael Pavone <pavone@retrodev.com>
parents:
507
diff
changeset
|
48 pop %rbx |
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.
Michael Pavone <pavone@retrodev.com>
parents:
507
diff
changeset
|
49 ret /* return to caller of z80_run */ |
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.
Michael Pavone <pavone@retrodev.com>
parents:
507
diff
changeset
|
50 |
249
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
51 .global z80_handle_cycle_limit_int |
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
52 z80_handle_cycle_limit_int: |
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
53 cmp 116(%rsi), %ebp |
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
54 jb zskip_int |
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
55 mov 112(%rsi), %ebp /* set cycle limit to sync cycle */ |
375
134ffb72d7a1
Clear IFF1 and IFF2 when an interrupt is taken on the Z80
Mike Pavone <pavone@retrodev.com>
parents:
357
diff
changeset
|
56 /* not sure this is really necessary now that IFF1 and IFF2 are geting cleared */ |
335 | 57 movl $0xFFFFFFFF, 116(%rsi) /* make sure the interrupt doesn't fire more than once */ |
375
134ffb72d7a1
Clear IFF1 and IFF2 when an interrupt is taken on the Z80
Mike Pavone <pavone@retrodev.com>
parents:
357
diff
changeset
|
58 /* disable interrupts */ |
134ffb72d7a1
Clear IFF1 and IFF2 when an interrupt is taken on the Z80
Mike Pavone <pavone@retrodev.com>
parents:
357
diff
changeset
|
59 movb $0, 96(%rsi) |
134ffb72d7a1
Clear IFF1 and IFF2 when an interrupt is taken on the Z80
Mike Pavone <pavone@retrodev.com>
parents:
357
diff
changeset
|
60 movb $0, 97(%rsi) |
249
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
61 add $7, %ebp |
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
62 sub $2, %r9w |
259
d9417261366f
Fix a remaining z80_write reg swap bug. Properly initialize the native map slots. Reset appropriate regs when z80_reset is called.
Mike Pavone <pavone@retrodev.com>
parents:
253
diff
changeset
|
63 mov %r9w, %r14w |
249
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
64 call z_inccycles |
259
d9417261366f
Fix a remaining z80_write reg swap bug. Properly initialize the native map slots. Reset appropriate regs when z80_reset is called.
Mike Pavone <pavone@retrodev.com>
parents:
253
diff
changeset
|
65 push %r13 |
249
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
66 call z80_write_byte_noinc |
259
d9417261366f
Fix a remaining z80_write reg swap bug. Properly initialize the native map slots. Reset appropriate regs when z80_reset is called.
Mike Pavone <pavone@retrodev.com>
parents:
253
diff
changeset
|
67 pop %r13 |
d9417261366f
Fix a remaining z80_write reg swap bug. Properly initialize the native map slots. Reset appropriate regs when z80_reset is called.
Mike Pavone <pavone@retrodev.com>
parents:
253
diff
changeset
|
68 mov %r9w, %r14w |
d9417261366f
Fix a remaining z80_write reg swap bug. Properly initialize the native map slots. Reset appropriate regs when z80_reset is called.
Mike Pavone <pavone@retrodev.com>
parents:
253
diff
changeset
|
69 add $1, %r14w |
d9417261366f
Fix a remaining z80_write reg swap bug. Properly initialize the native map slots. Reset appropriate regs when z80_reset is called.
Mike Pavone <pavone@retrodev.com>
parents:
253
diff
changeset
|
70 shr $8, %r13w |
249
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
71 call z_inccycles |
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
72 call z80_write_byte_noinc |
276
eec7072189a1
Fix crash bug in Z80 interrupt support
Mike Pavone <pavone@retrodev.com>
parents:
261
diff
changeset
|
73 pop %r14 /*dispose of return address */ |
249
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
74 /* TODO: Support interrupt mode 0 and 2 */ |
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
75 mov $0x38, %r13w |
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
76 call z80_native_addr |
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
77 jmp *%r13 |
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
78 zskip_int: |
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
79 cmp 112(%rsi), %ebp |
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
80 jb zskip_sync |
451
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
393
diff
changeset
|
81 mov %r13w, 164(%rsi) |
249
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
82 .global z80_do_sync |
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
83 z80_do_sync: |
281
44f0bbf57b4f
Save context in z80_do_sync
Mike Pavone <pavone@retrodev.com>
parents:
280
diff
changeset
|
84 call z80_save_context |
249
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
85 pop (%rsi) /*return address in native code*/ |
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
86 pop %r15 /* restore callee saved regsiters */ |
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
87 pop %r14 |
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
88 pop %r13 |
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
89 pop %r12 |
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
90 pop %rbp |
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
91 pop %rbx |
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
92 zskip_sync: |
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
93 ret |
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
94 |
285
021aeb6df19b
Implement HALT (sort of tested)
Mike Pavone <pavone@retrodev.com>
parents:
284
diff
changeset
|
95 .global z80_halt |
021aeb6df19b
Implement HALT (sort of tested)
Mike Pavone <pavone@retrodev.com>
parents:
284
diff
changeset
|
96 z80_halt: |
021aeb6df19b
Implement HALT (sort of tested)
Mike Pavone <pavone@retrodev.com>
parents:
284
diff
changeset
|
97 mov %edi, %r14d |
021aeb6df19b
Implement HALT (sort of tested)
Mike Pavone <pavone@retrodev.com>
parents:
284
diff
changeset
|
98 sub %ebp, %r14d |
021aeb6df19b
Implement HALT (sort of tested)
Mike Pavone <pavone@retrodev.com>
parents:
284
diff
changeset
|
99 and $0xFFFFFFFC, %r14d |
021aeb6df19b
Implement HALT (sort of tested)
Mike Pavone <pavone@retrodev.com>
parents:
284
diff
changeset
|
100 add %r14d, %ebp |
021aeb6df19b
Implement HALT (sort of tested)
Mike Pavone <pavone@retrodev.com>
parents:
284
diff
changeset
|
101 cmp %edi, %ebp |
021aeb6df19b
Implement HALT (sort of tested)
Mike Pavone <pavone@retrodev.com>
parents:
284
diff
changeset
|
102 jnb z80_handle_cycle_limit_int |
021aeb6df19b
Implement HALT (sort of tested)
Mike Pavone <pavone@retrodev.com>
parents:
284
diff
changeset
|
103 add $4, %ebp |
021aeb6df19b
Implement HALT (sort of tested)
Mike Pavone <pavone@retrodev.com>
parents:
284
diff
changeset
|
104 jmp z80_handle_cycle_limit_int |
021aeb6df19b
Implement HALT (sort of tested)
Mike Pavone <pavone@retrodev.com>
parents:
284
diff
changeset
|
105 |
249
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
106 .global z80_read_byte |
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
107 z80_read_byte: |
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
108 call z_inccycles |
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
109 z80_read_byte_noinc: |
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
110 cmp $0x4000, %r13w |
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
111 jb z80_read_ram |
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
112 cmp $0x8000, %r13w |
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
113 jae z80_read_bank |
290
171f97e70d85
Implement writes from Z80 to YM-2612
Mike Pavone <pavone@retrodev.com>
parents:
285
diff
changeset
|
114 cmp $0x6000, %r13w |
171f97e70d85
Implement writes from Z80 to YM-2612
Mike Pavone <pavone@retrodev.com>
parents:
285
diff
changeset
|
115 jb z80_read_ym2612 |
249
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
116 /* TODO: Bank reg, YM-2612, PSG/VDP */ |
280 | 117 mov $0xFF, %r13b |
249
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
118 ret |
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
119 z80_read_ram: |
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
120 and $0x1FFF, %r13 |
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
121 mov (%r11, %r13), %r13b |
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
122 ret |
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
123 z80_read_bank: |
509
b3738ee58195
Fix accidental use of the conditional jump instruction jp instead of jmp
Michael Pavone <pavone@retrodev.com>
parents:
508
diff
changeset
|
124 /* approximation of wait states for normal 68K bus access */ |
b3738ee58195
Fix accidental use of the conditional jump instruction jp instead of jmp
Michael Pavone <pavone@retrodev.com>
parents:
508
diff
changeset
|
125 add $3, %ebp |
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.
Michael Pavone <pavone@retrodev.com>
parents:
507
diff
changeset
|
126 push %rsi |
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.
Michael Pavone <pavone@retrodev.com>
parents:
507
diff
changeset
|
127 mov 144(%rsi), %rsi /* get system context pointer */ |
559
6b248602ab84
blastem builds and almost works on OS X now
Mike Pavone <pavone@retrodev.com>
parents:
509
diff
changeset
|
128 cmpb $0, 120(%rsi) /* check bus busy flag */ |
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.
Michael Pavone <pavone@retrodev.com>
parents:
507
diff
changeset
|
129 pop %rsi |
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.
Michael Pavone <pavone@retrodev.com>
parents:
507
diff
changeset
|
130 jne bus_busy |
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.
Michael Pavone <pavone@retrodev.com>
parents:
507
diff
changeset
|
131 z80_read_bank_cont: |
249
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
132 and $0x7FFF, %r13 |
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
133 cmp $0, %r12 |
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
134 je slow_bank_read |
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
135 /* 68K memory is byte swapped */ |
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
136 xor $1, %r13 |
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
137 mov (%r12, %r13), %r13b |
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
138 ret |
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
139 slow_bank_read: |
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
140 /* TODO: Call into C to implement this */ |
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
141 ret |
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.
Michael Pavone <pavone@retrodev.com>
parents:
507
diff
changeset
|
142 bus_busy: |
509
b3738ee58195
Fix accidental use of the conditional jump instruction jp instead of jmp
Michael Pavone <pavone@retrodev.com>
parents:
508
diff
changeset
|
143 cmp %ebp, %edi |
b3738ee58195
Fix accidental use of the conditional jump instruction jp instead of jmp
Michael Pavone <pavone@retrodev.com>
parents:
508
diff
changeset
|
144 jbe no_adjust |
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.
Michael Pavone <pavone@retrodev.com>
parents:
507
diff
changeset
|
145 mov %edi, %ebp |
509
b3738ee58195
Fix accidental use of the conditional jump instruction jp instead of jmp
Michael Pavone <pavone@retrodev.com>
parents:
508
diff
changeset
|
146 no_adjust: |
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.
Michael Pavone <pavone@retrodev.com>
parents:
507
diff
changeset
|
147 call forced_sync |
509
b3738ee58195
Fix accidental use of the conditional jump instruction jp instead of jmp
Michael Pavone <pavone@retrodev.com>
parents:
508
diff
changeset
|
148 jmp z80_read_bank_cont |
290
171f97e70d85
Implement writes from Z80 to YM-2612
Mike Pavone <pavone@retrodev.com>
parents:
285
diff
changeset
|
149 z80_read_ym2612: |
171f97e70d85
Implement writes from Z80 to YM-2612
Mike Pavone <pavone@retrodev.com>
parents:
285
diff
changeset
|
150 call z80_save_context |
171f97e70d85
Implement writes from Z80 to YM-2612
Mike Pavone <pavone@retrodev.com>
parents:
285
diff
changeset
|
151 mov %r13w, %di |
171f97e70d85
Implement writes from Z80 to YM-2612
Mike Pavone <pavone@retrodev.com>
parents:
285
diff
changeset
|
152 push %rsi |
562
e13f4fd9cf6d
Ensure proper stack alignment when the Z80 calls into C code. This fixes a crash in optimized builds on OSX
Mike Pavone <pavone@retrodev.com>
parents:
559
diff
changeset
|
153 test $8, %rsp |
e13f4fd9cf6d
Ensure proper stack alignment when the Z80 calls into C code. This fixes a crash in optimized builds on OSX
Mike Pavone <pavone@retrodev.com>
parents:
559
diff
changeset
|
154 jnz 0f |
290
171f97e70d85
Implement writes from Z80 to YM-2612
Mike Pavone <pavone@retrodev.com>
parents:
285
diff
changeset
|
155 call z80_read_ym |
562
e13f4fd9cf6d
Ensure proper stack alignment when the Z80 calls into C code. This fixes a crash in optimized builds on OSX
Mike Pavone <pavone@retrodev.com>
parents:
559
diff
changeset
|
156 jmp 1f |
e13f4fd9cf6d
Ensure proper stack alignment when the Z80 calls into C code. This fixes a crash in optimized builds on OSX
Mike Pavone <pavone@retrodev.com>
parents:
559
diff
changeset
|
157 0: |
e13f4fd9cf6d
Ensure proper stack alignment when the Z80 calls into C code. This fixes a crash in optimized builds on OSX
Mike Pavone <pavone@retrodev.com>
parents:
559
diff
changeset
|
158 sub $8, %rsp |
e13f4fd9cf6d
Ensure proper stack alignment when the Z80 calls into C code. This fixes a crash in optimized builds on OSX
Mike Pavone <pavone@retrodev.com>
parents:
559
diff
changeset
|
159 call z80_read_ym |
e13f4fd9cf6d
Ensure proper stack alignment when the Z80 calls into C code. This fixes a crash in optimized builds on OSX
Mike Pavone <pavone@retrodev.com>
parents:
559
diff
changeset
|
160 add $8, %rsp |
e13f4fd9cf6d
Ensure proper stack alignment when the Z80 calls into C code. This fixes a crash in optimized builds on OSX
Mike Pavone <pavone@retrodev.com>
parents:
559
diff
changeset
|
161 1: |
290
171f97e70d85
Implement writes from Z80 to YM-2612
Mike Pavone <pavone@retrodev.com>
parents:
285
diff
changeset
|
162 pop %rsi |
171f97e70d85
Implement writes from Z80 to YM-2612
Mike Pavone <pavone@retrodev.com>
parents:
285
diff
changeset
|
163 mov %al, %r13b |
171f97e70d85
Implement writes from Z80 to YM-2612
Mike Pavone <pavone@retrodev.com>
parents:
285
diff
changeset
|
164 call z80_load_context |
171f97e70d85
Implement writes from Z80 to YM-2612
Mike Pavone <pavone@retrodev.com>
parents:
285
diff
changeset
|
165 ret |
249
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
166 |
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
167 .global z80_write_byte |
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
168 z80_write_byte: |
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
169 call z_inccycles |
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
170 z80_write_byte_noinc: |
253
3b34deba4ca0
Squashing some bugs introduced when I switched the register assignments for z80_write_byte around.
Mike Pavone <pavone@retrodev.com>
parents:
252
diff
changeset
|
171 cmp $0x4000, %r14w |
249
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
172 jb z80_write_ram |
253
3b34deba4ca0
Squashing some bugs introduced when I switched the register assignments for z80_write_byte around.
Mike Pavone <pavone@retrodev.com>
parents:
252
diff
changeset
|
173 cmp $0x8000, %r14w |
249
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
174 jae z80_write_bank |
253
3b34deba4ca0
Squashing some bugs introduced when I switched the register assignments for z80_write_byte around.
Mike Pavone <pavone@retrodev.com>
parents:
252
diff
changeset
|
175 cmp $0x6000, %r14w |
290
171f97e70d85
Implement writes from Z80 to YM-2612
Mike Pavone <pavone@retrodev.com>
parents:
285
diff
changeset
|
176 jb z80_write_ym2612 |
171f97e70d85
Implement writes from Z80 to YM-2612
Mike Pavone <pavone@retrodev.com>
parents:
285
diff
changeset
|
177 cmp $0x6100, %r14w |
171f97e70d85
Implement writes from Z80 to YM-2612
Mike Pavone <pavone@retrodev.com>
parents:
285
diff
changeset
|
178 jb z80_write_bank_reg |
357
fa7ea48be9a9
Allow VDP/PSG writes from Z80
Mike Pavone <pavone@retrodev.com>
parents:
335
diff
changeset
|
179 cmp $0x7F00, %r14w |
fa7ea48be9a9
Allow VDP/PSG writes from Z80
Mike Pavone <pavone@retrodev.com>
parents:
335
diff
changeset
|
180 jae z80_write_vdp |
249
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
181 ret |
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
182 z80_write_ram: |
253
3b34deba4ca0
Squashing some bugs introduced when I switched the register assignments for z80_write_byte around.
Mike Pavone <pavone@retrodev.com>
parents:
252
diff
changeset
|
183 and $0x1FFF, %r14 |
3b34deba4ca0
Squashing some bugs introduced when I switched the register assignments for z80_write_byte around.
Mike Pavone <pavone@retrodev.com>
parents:
252
diff
changeset
|
184 mov %r13b, (%r11, %r14) |
3b34deba4ca0
Squashing some bugs introduced when I switched the register assignments for z80_write_byte around.
Mike Pavone <pavone@retrodev.com>
parents:
252
diff
changeset
|
185 mov %r14d, %r13d |
3b34deba4ca0
Squashing some bugs introduced when I switched the register assignments for z80_write_byte around.
Mike Pavone <pavone@retrodev.com>
parents:
252
diff
changeset
|
186 shr $7, %r13d |
3b34deba4ca0
Squashing some bugs introduced when I switched the register assignments for z80_write_byte around.
Mike Pavone <pavone@retrodev.com>
parents:
252
diff
changeset
|
187 bt %r13d, 152(%rsi) |
252
63b9a500a00b
Implement retranslating code when written to. Possibly broken, need to fix some other bugs before a proper test.
Mike Pavone <pavone@retrodev.com>
parents:
249
diff
changeset
|
188 jnc not_code |
63b9a500a00b
Implement retranslating code when written to. Possibly broken, need to fix some other bugs before a proper test.
Mike Pavone <pavone@retrodev.com>
parents:
249
diff
changeset
|
189 call z80_save_context |
253
3b34deba4ca0
Squashing some bugs introduced when I switched the register assignments for z80_write_byte around.
Mike Pavone <pavone@retrodev.com>
parents:
252
diff
changeset
|
190 mov %r14d, %edi |
252
63b9a500a00b
Implement retranslating code when written to. Possibly broken, need to fix some other bugs before a proper test.
Mike Pavone <pavone@retrodev.com>
parents:
249
diff
changeset
|
191 call z80_handle_code_write |
63b9a500a00b
Implement retranslating code when written to. Possibly broken, need to fix some other bugs before a proper test.
Mike Pavone <pavone@retrodev.com>
parents:
249
diff
changeset
|
192 mov %rax, %rsi |
261
f0c53a4bbfa3
Implement LDIR and fix a bug in which context was not restored after a call to z80_handle_code_write
Mike Pavone <pavone@retrodev.com>
parents:
259
diff
changeset
|
193 call z80_load_context |
252
63b9a500a00b
Implement retranslating code when written to. Possibly broken, need to fix some other bugs before a proper test.
Mike Pavone <pavone@retrodev.com>
parents:
249
diff
changeset
|
194 not_code: |
249
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
195 ret |
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
196 z80_write_bank: |
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
197 slow_bank_write: |
507
cc6030bd04c6
Add 3 wait states to Z80 access to bank area since that seems to be roughly the average in normal usage
Michael Pavone <pavone@retrodev.com>
parents:
451
diff
changeset
|
198 /* approximation of wait states for 68K bus access */ |
cc6030bd04c6
Add 3 wait states to Z80 access to bank area since that seems to be roughly the average in normal usage
Michael Pavone <pavone@retrodev.com>
parents:
451
diff
changeset
|
199 add $3, %ebp |
249
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
200 /* TODO: Call into C to implement this */ |
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
201 ret |
290
171f97e70d85
Implement writes from Z80 to YM-2612
Mike Pavone <pavone@retrodev.com>
parents:
285
diff
changeset
|
202 z80_write_ym2612: |
171f97e70d85
Implement writes from Z80 to YM-2612
Mike Pavone <pavone@retrodev.com>
parents:
285
diff
changeset
|
203 and $0x3, %r14w |
171f97e70d85
Implement writes from Z80 to YM-2612
Mike Pavone <pavone@retrodev.com>
parents:
285
diff
changeset
|
204 call z80_save_context |
171f97e70d85
Implement writes from Z80 to YM-2612
Mike Pavone <pavone@retrodev.com>
parents:
285
diff
changeset
|
205 mov %r14w, %di |
171f97e70d85
Implement writes from Z80 to YM-2612
Mike Pavone <pavone@retrodev.com>
parents:
285
diff
changeset
|
206 mov %r13b, %dl |
562
e13f4fd9cf6d
Ensure proper stack alignment when the Z80 calls into C code. This fixes a crash in optimized builds on OSX
Mike Pavone <pavone@retrodev.com>
parents:
559
diff
changeset
|
207 test $8, %rsp |
e13f4fd9cf6d
Ensure proper stack alignment when the Z80 calls into C code. This fixes a crash in optimized builds on OSX
Mike Pavone <pavone@retrodev.com>
parents:
559
diff
changeset
|
208 jnz 0f |
290
171f97e70d85
Implement writes from Z80 to YM-2612
Mike Pavone <pavone@retrodev.com>
parents:
285
diff
changeset
|
209 call z80_write_ym |
562
e13f4fd9cf6d
Ensure proper stack alignment when the Z80 calls into C code. This fixes a crash in optimized builds on OSX
Mike Pavone <pavone@retrodev.com>
parents:
559
diff
changeset
|
210 jmp 1f |
e13f4fd9cf6d
Ensure proper stack alignment when the Z80 calls into C code. This fixes a crash in optimized builds on OSX
Mike Pavone <pavone@retrodev.com>
parents:
559
diff
changeset
|
211 0: |
e13f4fd9cf6d
Ensure proper stack alignment when the Z80 calls into C code. This fixes a crash in optimized builds on OSX
Mike Pavone <pavone@retrodev.com>
parents:
559
diff
changeset
|
212 sub $8, %rsp |
e13f4fd9cf6d
Ensure proper stack alignment when the Z80 calls into C code. This fixes a crash in optimized builds on OSX
Mike Pavone <pavone@retrodev.com>
parents:
559
diff
changeset
|
213 call z80_write_ym |
e13f4fd9cf6d
Ensure proper stack alignment when the Z80 calls into C code. This fixes a crash in optimized builds on OSX
Mike Pavone <pavone@retrodev.com>
parents:
559
diff
changeset
|
214 add $8, %rsp |
e13f4fd9cf6d
Ensure proper stack alignment when the Z80 calls into C code. This fixes a crash in optimized builds on OSX
Mike Pavone <pavone@retrodev.com>
parents:
559
diff
changeset
|
215 1: |
290
171f97e70d85
Implement writes from Z80 to YM-2612
Mike Pavone <pavone@retrodev.com>
parents:
285
diff
changeset
|
216 mov %rax, %rsi |
357
fa7ea48be9a9
Allow VDP/PSG writes from Z80
Mike Pavone <pavone@retrodev.com>
parents:
335
diff
changeset
|
217 jmp z80_load_context |
249
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
218 z80_write_bank_reg: |
253
3b34deba4ca0
Squashing some bugs introduced when I switched the register assignments for z80_write_byte around.
Mike Pavone <pavone@retrodev.com>
parents:
252
diff
changeset
|
219 and $1, %r13w |
280 | 220 shr %r15w |
221 shl $8, %r13w | |
222 xor %r12, %r12 | |
253
3b34deba4ca0
Squashing some bugs introduced when I switched the register assignments for z80_write_byte around.
Mike Pavone <pavone@retrodev.com>
parents:
252
diff
changeset
|
223 or %r13w, %r15w |
249
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
224 and $0x1FF, %r15w |
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
225 cmp $0x80, %r15w |
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
226 jb update_bank_ptr |
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
227 ret |
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
228 update_bank_ptr: |
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
229 mov %r15w, %r12w |
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
230 shl $15, %r12 |
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
231 add 80(%rsi), %r12 |
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
232 ret |
357
fa7ea48be9a9
Allow VDP/PSG writes from Z80
Mike Pavone <pavone@retrodev.com>
parents:
335
diff
changeset
|
233 z80_write_vdp: |
fa7ea48be9a9
Allow VDP/PSG writes from Z80
Mike Pavone <pavone@retrodev.com>
parents:
335
diff
changeset
|
234 and $0xFF, %r14w |
fa7ea48be9a9
Allow VDP/PSG writes from Z80
Mike Pavone <pavone@retrodev.com>
parents:
335
diff
changeset
|
235 call z80_save_context |
fa7ea48be9a9
Allow VDP/PSG writes from Z80
Mike Pavone <pavone@retrodev.com>
parents:
335
diff
changeset
|
236 mov %r14w, %di |
fa7ea48be9a9
Allow VDP/PSG writes from Z80
Mike Pavone <pavone@retrodev.com>
parents:
335
diff
changeset
|
237 mov %r13b, %dl |
562
e13f4fd9cf6d
Ensure proper stack alignment when the Z80 calls into C code. This fixes a crash in optimized builds on OSX
Mike Pavone <pavone@retrodev.com>
parents:
559
diff
changeset
|
238 test $8, %rsp |
e13f4fd9cf6d
Ensure proper stack alignment when the Z80 calls into C code. This fixes a crash in optimized builds on OSX
Mike Pavone <pavone@retrodev.com>
parents:
559
diff
changeset
|
239 jnz 0f |
357
fa7ea48be9a9
Allow VDP/PSG writes from Z80
Mike Pavone <pavone@retrodev.com>
parents:
335
diff
changeset
|
240 call z80_vdp_port_write |
562
e13f4fd9cf6d
Ensure proper stack alignment when the Z80 calls into C code. This fixes a crash in optimized builds on OSX
Mike Pavone <pavone@retrodev.com>
parents:
559
diff
changeset
|
241 jmp 1f |
e13f4fd9cf6d
Ensure proper stack alignment when the Z80 calls into C code. This fixes a crash in optimized builds on OSX
Mike Pavone <pavone@retrodev.com>
parents:
559
diff
changeset
|
242 0: |
e13f4fd9cf6d
Ensure proper stack alignment when the Z80 calls into C code. This fixes a crash in optimized builds on OSX
Mike Pavone <pavone@retrodev.com>
parents:
559
diff
changeset
|
243 sub $8, %rsp |
e13f4fd9cf6d
Ensure proper stack alignment when the Z80 calls into C code. This fixes a crash in optimized builds on OSX
Mike Pavone <pavone@retrodev.com>
parents:
559
diff
changeset
|
244 call z80_vdp_port_write |
e13f4fd9cf6d
Ensure proper stack alignment when the Z80 calls into C code. This fixes a crash in optimized builds on OSX
Mike Pavone <pavone@retrodev.com>
parents:
559
diff
changeset
|
245 add $8, %rsp |
e13f4fd9cf6d
Ensure proper stack alignment when the Z80 calls into C code. This fixes a crash in optimized builds on OSX
Mike Pavone <pavone@retrodev.com>
parents:
559
diff
changeset
|
246 1: |
357
fa7ea48be9a9
Allow VDP/PSG writes from Z80
Mike Pavone <pavone@retrodev.com>
parents:
335
diff
changeset
|
247 mov %rax, %rsi |
fa7ea48be9a9
Allow VDP/PSG writes from Z80
Mike Pavone <pavone@retrodev.com>
parents:
335
diff
changeset
|
248 jmp z80_load_context |
249
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
249 |
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
250 .global z80_read_word |
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
251 z80_read_word: |
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
252 call z_inccycles |
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.
Michael Pavone <pavone@retrodev.com>
parents:
507
diff
changeset
|
253 cmp $0x8000, %r13w |
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.
Michael Pavone <pavone@retrodev.com>
parents:
507
diff
changeset
|
254 jae z80_read_bank_word |
249
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
255 push %r13 |
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
256 call z80_read_byte_noinc |
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
257 mov %r13b, %r14b |
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
258 pop %r13 |
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
259 inc %r13 |
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
260 call z_inccycles |
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
261 call z80_read_byte_noinc |
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
262 shl $8, %r13w |
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
263 mov %r14b, %r13b |
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
264 ret |
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
265 |
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.
Michael Pavone <pavone@retrodev.com>
parents:
507
diff
changeset
|
266 z80_read_bank_word: |
509
b3738ee58195
Fix accidental use of the conditional jump instruction jp instead of jmp
Michael Pavone <pavone@retrodev.com>
parents:
508
diff
changeset
|
267 add $3, %ebp /* first read typically has 3 wait states */ |
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.
Michael Pavone <pavone@retrodev.com>
parents:
507
diff
changeset
|
268 push %rsi |
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.
Michael Pavone <pavone@retrodev.com>
parents:
507
diff
changeset
|
269 mov 144(%rsi), %rsi /* get system context pointer */ |
559
6b248602ab84
blastem builds and almost works on OS X now
Mike Pavone <pavone@retrodev.com>
parents:
509
diff
changeset
|
270 cmpb $0, 120(%rsi) /* check bus busy flag */ |
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.
Michael Pavone <pavone@retrodev.com>
parents:
507
diff
changeset
|
271 pop %rsi |
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.
Michael Pavone <pavone@retrodev.com>
parents:
507
diff
changeset
|
272 jne bus_busy_word |
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.
Michael Pavone <pavone@retrodev.com>
parents:
507
diff
changeset
|
273 z80_read_bank_word_cont: |
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.
Michael Pavone <pavone@retrodev.com>
parents:
507
diff
changeset
|
274 push %r13 |
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.
Michael Pavone <pavone@retrodev.com>
parents:
507
diff
changeset
|
275 call z80_read_bank_cont |
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.
Michael Pavone <pavone@retrodev.com>
parents:
507
diff
changeset
|
276 mov %r13b, %r14b |
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.
Michael Pavone <pavone@retrodev.com>
parents:
507
diff
changeset
|
277 pop %r13 |
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.
Michael Pavone <pavone@retrodev.com>
parents:
507
diff
changeset
|
278 inc %r13 |
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.
Michael Pavone <pavone@retrodev.com>
parents:
507
diff
changeset
|
279 call z_inccycles |
509
b3738ee58195
Fix accidental use of the conditional jump instruction jp instead of jmp
Michael Pavone <pavone@retrodev.com>
parents:
508
diff
changeset
|
280 add $4, %ebp /* second read typically has 4 wait states */ |
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.
Michael Pavone <pavone@retrodev.com>
parents:
507
diff
changeset
|
281 push %rsi |
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.
Michael Pavone <pavone@retrodev.com>
parents:
507
diff
changeset
|
282 mov 144(%rsi), %rsi /* get system context pointer */ |
559
6b248602ab84
blastem builds and almost works on OS X now
Mike Pavone <pavone@retrodev.com>
parents:
509
diff
changeset
|
283 cmpb $0, 120(%rsi) /* check bus busy flag */ |
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.
Michael Pavone <pavone@retrodev.com>
parents:
507
diff
changeset
|
284 pop %rsi |
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.
Michael Pavone <pavone@retrodev.com>
parents:
507
diff
changeset
|
285 jne bus_busy_word2 |
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.
Michael Pavone <pavone@retrodev.com>
parents:
507
diff
changeset
|
286 z80_read_bank_word_cont2: |
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.
Michael Pavone <pavone@retrodev.com>
parents:
507
diff
changeset
|
287 call z80_read_bank_cont |
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.
Michael Pavone <pavone@retrodev.com>
parents:
507
diff
changeset
|
288 shl $8, %r13w |
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.
Michael Pavone <pavone@retrodev.com>
parents:
507
diff
changeset
|
289 mov %r14b, %r13b |
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.
Michael Pavone <pavone@retrodev.com>
parents:
507
diff
changeset
|
290 ret |
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.
Michael Pavone <pavone@retrodev.com>
parents:
507
diff
changeset
|
291 |
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.
Michael Pavone <pavone@retrodev.com>
parents:
507
diff
changeset
|
292 bus_busy_word: |
509
b3738ee58195
Fix accidental use of the conditional jump instruction jp instead of jmp
Michael Pavone <pavone@retrodev.com>
parents:
508
diff
changeset
|
293 cmp %ebp, %edi |
b3738ee58195
Fix accidental use of the conditional jump instruction jp instead of jmp
Michael Pavone <pavone@retrodev.com>
parents:
508
diff
changeset
|
294 jb no_adjust_word |
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.
Michael Pavone <pavone@retrodev.com>
parents:
507
diff
changeset
|
295 mov %edi, %ebp |
509
b3738ee58195
Fix accidental use of the conditional jump instruction jp instead of jmp
Michael Pavone <pavone@retrodev.com>
parents:
508
diff
changeset
|
296 no_adjust_word: |
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.
Michael Pavone <pavone@retrodev.com>
parents:
507
diff
changeset
|
297 call forced_sync |
509
b3738ee58195
Fix accidental use of the conditional jump instruction jp instead of jmp
Michael Pavone <pavone@retrodev.com>
parents:
508
diff
changeset
|
298 jmp z80_read_bank_word_cont |
b3738ee58195
Fix accidental use of the conditional jump instruction jp instead of jmp
Michael Pavone <pavone@retrodev.com>
parents:
508
diff
changeset
|
299 |
b3738ee58195
Fix accidental use of the conditional jump instruction jp instead of jmp
Michael Pavone <pavone@retrodev.com>
parents:
508
diff
changeset
|
300 foofoo: |
b3738ee58195
Fix accidental use of the conditional jump instruction jp instead of jmp
Michael Pavone <pavone@retrodev.com>
parents:
508
diff
changeset
|
301 jmp foofoo |
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.
Michael Pavone <pavone@retrodev.com>
parents:
507
diff
changeset
|
302 |
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.
Michael Pavone <pavone@retrodev.com>
parents:
507
diff
changeset
|
303 bus_busy_word2: |
509
b3738ee58195
Fix accidental use of the conditional jump instruction jp instead of jmp
Michael Pavone <pavone@retrodev.com>
parents:
508
diff
changeset
|
304 cmp %ebp, %edi |
b3738ee58195
Fix accidental use of the conditional jump instruction jp instead of jmp
Michael Pavone <pavone@retrodev.com>
parents:
508
diff
changeset
|
305 jb no_adjust_word2 |
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.
Michael Pavone <pavone@retrodev.com>
parents:
507
diff
changeset
|
306 mov %edi, %ebp |
509
b3738ee58195
Fix accidental use of the conditional jump instruction jp instead of jmp
Michael Pavone <pavone@retrodev.com>
parents:
508
diff
changeset
|
307 no_adjust_word2: |
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.
Michael Pavone <pavone@retrodev.com>
parents:
507
diff
changeset
|
308 call forced_sync |
509
b3738ee58195
Fix accidental use of the conditional jump instruction jp instead of jmp
Michael Pavone <pavone@retrodev.com>
parents:
508
diff
changeset
|
309 jmp z80_read_bank_word_cont2 |
b3738ee58195
Fix accidental use of the conditional jump instruction jp instead of jmp
Michael Pavone <pavone@retrodev.com>
parents:
508
diff
changeset
|
310 blahblah: |
b3738ee58195
Fix accidental use of the conditional jump instruction jp instead of jmp
Michael Pavone <pavone@retrodev.com>
parents:
508
diff
changeset
|
311 jmp blahblah |
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.
Michael Pavone <pavone@retrodev.com>
parents:
507
diff
changeset
|
312 |
249
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
313 .global z80_write_word_highfirst |
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
314 z80_write_word_highfirst: |
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
315 call z_inccycles |
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
316 push %r14 |
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
317 push %r13 |
253
3b34deba4ca0
Squashing some bugs introduced when I switched the register assignments for z80_write_byte around.
Mike Pavone <pavone@retrodev.com>
parents:
252
diff
changeset
|
318 add $1, %r14w |
3b34deba4ca0
Squashing some bugs introduced when I switched the register assignments for z80_write_byte around.
Mike Pavone <pavone@retrodev.com>
parents:
252
diff
changeset
|
319 shr $8, %r13w |
249
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
320 call z80_write_byte_noinc |
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
321 pop %r13 |
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
322 pop %r14 |
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
323 call z_inccycles |
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
324 call z80_write_byte_noinc |
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
325 ret |
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
326 |
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
327 .global z80_write_word_lowfirst |
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
328 z80_write_word_lowfirst: |
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
329 call z_inccycles |
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
330 push %r14 |
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
331 push %r13 |
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
332 call z80_write_byte_noinc |
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
333 pop %r13 |
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
334 pop %r14 |
253
3b34deba4ca0
Squashing some bugs introduced when I switched the register assignments for z80_write_byte around.
Mike Pavone <pavone@retrodev.com>
parents:
252
diff
changeset
|
335 add $1, %r14w |
3b34deba4ca0
Squashing some bugs introduced when I switched the register assignments for z80_write_byte around.
Mike Pavone <pavone@retrodev.com>
parents:
252
diff
changeset
|
336 shr $8, %r13w |
249
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
337 call z_inccycles |
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
338 call z80_write_byte_noinc |
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
339 ret |
284
ed7098f717d7
Implement IN and OUT (untested)
Mike Pavone <pavone@retrodev.com>
parents:
281
diff
changeset
|
340 |
ed7098f717d7
Implement IN and OUT (untested)
Mike Pavone <pavone@retrodev.com>
parents:
281
diff
changeset
|
341 .global z80_io_read |
ed7098f717d7
Implement IN and OUT (untested)
Mike Pavone <pavone@retrodev.com>
parents:
281
diff
changeset
|
342 z80_io_read: |
ed7098f717d7
Implement IN and OUT (untested)
Mike Pavone <pavone@retrodev.com>
parents:
281
diff
changeset
|
343 call z_inccycles_io |
ed7098f717d7
Implement IN and OUT (untested)
Mike Pavone <pavone@retrodev.com>
parents:
281
diff
changeset
|
344 /* genesis Z80 has no IO port hardware and always returns FF */ |
ed7098f717d7
Implement IN and OUT (untested)
Mike Pavone <pavone@retrodev.com>
parents:
281
diff
changeset
|
345 mov $0xFF, %r13 |
ed7098f717d7
Implement IN and OUT (untested)
Mike Pavone <pavone@retrodev.com>
parents:
281
diff
changeset
|
346 ret |
ed7098f717d7
Implement IN and OUT (untested)
Mike Pavone <pavone@retrodev.com>
parents:
281
diff
changeset
|
347 |
ed7098f717d7
Implement IN and OUT (untested)
Mike Pavone <pavone@retrodev.com>
parents:
281
diff
changeset
|
348 .global z80_io_write |
ed7098f717d7
Implement IN and OUT (untested)
Mike Pavone <pavone@retrodev.com>
parents:
281
diff
changeset
|
349 z80_io_write: |
ed7098f717d7
Implement IN and OUT (untested)
Mike Pavone <pavone@retrodev.com>
parents:
281
diff
changeset
|
350 call z_inccycles_io |
ed7098f717d7
Implement IN and OUT (untested)
Mike Pavone <pavone@retrodev.com>
parents:
281
diff
changeset
|
351 /* genesis Z80 has no IO port hardware and writes have no effect */ |
ed7098f717d7
Implement IN and OUT (untested)
Mike Pavone <pavone@retrodev.com>
parents:
281
diff
changeset
|
352 ret |
451
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
393
diff
changeset
|
353 |
252
63b9a500a00b
Implement retranslating code when written to. Possibly broken, need to fix some other bugs before a proper test.
Mike Pavone <pavone@retrodev.com>
parents:
249
diff
changeset
|
354 .global z80_retrans_stub |
63b9a500a00b
Implement retranslating code when written to. Possibly broken, need to fix some other bugs before a proper test.
Mike Pavone <pavone@retrodev.com>
parents:
249
diff
changeset
|
355 z80_retrans_stub: |
390
561fe3ea3fc8
Use a call instruction to figure out the original native address when retranslating so that it does not get lost when the byte transforms from a instruction word to extension word
Mike Pavone <pavone@retrodev.com>
parents:
375
diff
changeset
|
356 pop %r14 |
252
63b9a500a00b
Implement retranslating code when written to. Possibly broken, need to fix some other bugs before a proper test.
Mike Pavone <pavone@retrodev.com>
parents:
249
diff
changeset
|
357 call z80_save_context |
390
561fe3ea3fc8
Use a call instruction to figure out the original native address when retranslating so that it does not get lost when the byte transforms from a instruction word to extension word
Mike Pavone <pavone@retrodev.com>
parents:
375
diff
changeset
|
358 /* adjust for mov and call instructions */ |
393
30c250a41629
Fix address adjustement in z80_retrans_stub
Mike Pavone <pavone@retrodev.com>
parents:
390
diff
changeset
|
359 sub $11, %r14 |
252
63b9a500a00b
Implement retranslating code when written to. Possibly broken, need to fix some other bugs before a proper test.
Mike Pavone <pavone@retrodev.com>
parents:
249
diff
changeset
|
360 mov %r13d, %edi |
390
561fe3ea3fc8
Use a call instruction to figure out the original native address when retranslating so that it does not get lost when the byte transforms from a instruction word to extension word
Mike Pavone <pavone@retrodev.com>
parents:
375
diff
changeset
|
361 mov %r14, %rdx |
252
63b9a500a00b
Implement retranslating code when written to. Possibly broken, need to fix some other bugs before a proper test.
Mike Pavone <pavone@retrodev.com>
parents:
249
diff
changeset
|
362 push %rsi |
63b9a500a00b
Implement retranslating code when written to. Possibly broken, need to fix some other bugs before a proper test.
Mike Pavone <pavone@retrodev.com>
parents:
249
diff
changeset
|
363 call z80_retranslate_inst |
63b9a500a00b
Implement retranslating code when written to. Possibly broken, need to fix some other bugs before a proper test.
Mike Pavone <pavone@retrodev.com>
parents:
249
diff
changeset
|
364 pop %rsi |
63b9a500a00b
Implement retranslating code when written to. Possibly broken, need to fix some other bugs before a proper test.
Mike Pavone <pavone@retrodev.com>
parents:
249
diff
changeset
|
365 mov %rax, %r13 |
63b9a500a00b
Implement retranslating code when written to. Possibly broken, need to fix some other bugs before a proper test.
Mike Pavone <pavone@retrodev.com>
parents:
249
diff
changeset
|
366 call z80_load_context |
63b9a500a00b
Implement retranslating code when written to. Possibly broken, need to fix some other bugs before a proper test.
Mike Pavone <pavone@retrodev.com>
parents:
249
diff
changeset
|
367 jmp *%r13 |
249
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
368 |
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
369 .global z80_native_addr |
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
370 z80_native_addr: |
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
371 call z80_save_context |
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
372 push %rsi |
451
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
393
diff
changeset
|
373 mov %rsi, %rdi |
249
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
374 movzx %r13w, %esi |
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
375 call z80_get_native_address_trans |
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
376 mov %rax, %r13 |
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
377 pop %rsi |
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
378 call z80_load_context |
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
379 ret |
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
380 |
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
381 z80_save_context_scratch: |
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
382 mov %r13w, 98(%rsi) /* scratch1 */ |
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
383 mov %r14w, 100(%rsi) /* scratch2 */ |
451
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
393
diff
changeset
|
384 |
249
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
385 .global z80_save_context |
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
386 z80_save_context: |
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
387 mov %r9w, 8(%rsi) /* SP */ |
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
388 mov %r15w, 16(%rsi) /* bank register */ |
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
389 mov %bx, 18(%rsi) /* BC */ |
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
390 mov %cx, 20(%rsi) /* DE */ |
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
391 mov %ax, 22(%rsi) /* HL */ |
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
392 mov %dx, 24(%rsi) /* IX */ |
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
393 mov %r8w, 26(%rsi) /* IY */ |
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
394 mov %r10b, 30(%rsi) /* A */ |
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
395 mov %edi, 48(%rsi) /* target_cycle */ |
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
396 mov %ebp, 52(%rsi) /* current_cycle */ |
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
397 mov %r12, 72(%rsi) /* cartridge bank pointer */ |
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
398 ret |
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
399 |
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
400 |
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
401 z80_load_context_scratch: |
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
402 mov 98(%rsi), %r13w /* scratch1 */ |
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
403 mov 100(%rsi), %r14w /* scratch2 */ |
451
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
393
diff
changeset
|
404 |
249
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
405 .global z80_load_context |
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
406 z80_load_context: |
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
407 mov 8(%rsi), %r9w /* SP */ |
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
408 mov 16(%rsi), %r15w /* bank register */ |
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
409 mov 18(%rsi), %bx /* BC */ |
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
410 mov 20(%rsi), %cx /* DE */ |
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
411 mov 22(%rsi), %ax /* HL */ |
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
412 mov 24(%rsi), %dx /* IX */ |
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
413 mov 26(%rsi), %r8w /* IY */ |
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
414 mov 30(%rsi), %r10b /* A */ |
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
415 mov 48(%rsi), %edi /* target_cycle */ |
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
416 mov 52(%rsi), %ebp /* current_cycle */ |
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
417 mov 64(%rsi), %r11 /* z80 RAM */ |
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
418 mov 72(%rsi), %r12 /* cartridge bank pointer */ |
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
419 ret |
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
420 |
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
421 .global z80_run |
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
422 z80_run: |
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
423 push %rbx |
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
424 push %rbp |
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
425 push %r12 |
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
426 push %r13 |
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
427 push %r14 |
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
428 push %r15 |
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
429 mov %rdi, %rsi |
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
430 call z80_load_context_scratch |
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
431 cmpq $0, 104(%rsi) |
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
432 je no_extra |
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
433 push 104(%rsi) |
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
434 movq $0, 104(%rsi) |
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
435 no_extra: |
d94e6cd5a8a5
Forgot to commit zruntime a while back, adding it now.
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
436 jmp *(%rsi) |
451
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
393
diff
changeset
|
437 |