Mercurial > repos > blastem
annotate blastem.c @ 396:09328dbe6700
Fix output of algorithm 4 and make some other minor YM2612 core improvements
author | Mike Pavone <pavone@retrodev.com> |
---|---|
date | Tue, 11 Jun 2013 23:36:18 -0700 |
parents | 0b5f93358a93 |
children | c26e48a93fa3 |
rev | line source |
---|---|
88
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1 #include "68kinst.h" |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
2 #include "m68k_to_x86.h" |
260
625f8e4d5fd2
Initial stab at integartiong Z80 core
Mike Pavone <pavone@retrodev.com>
parents:
215
diff
changeset
|
3 #include "z80_to_x86.h" |
88
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
4 #include "mem.h" |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
5 #include "vdp.h" |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
6 #include "render.h" |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
7 #include "blastem.h" |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
8 #include <stdio.h> |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
9 #include <stdlib.h> |
184
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
10 #include <string.h> |
88
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
11 |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
12 #define CARTRIDGE_WORDS 0x200000 |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
13 #define RAM_WORDS 32 * 1024 |
153
42c031184e8a
Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents:
149
diff
changeset
|
14 #define Z80_RAM_BYTES 8 * 1024 |
380
1c8d74f2ab0b
Make the PSG and YM2612 use the master clock internal with an increment based on clock divider so that they stay perflectly in sync. Run both the PSG and YM2612 whenver one of them needs to be run.
Mike Pavone <pavone@retrodev.com>
parents:
374
diff
changeset
|
15 |
1c8d74f2ab0b
Make the PSG and YM2612 use the master clock internal with an increment based on clock divider so that they stay perflectly in sync. Run both the PSG and YM2612 whenver one of them needs to be run.
Mike Pavone <pavone@retrodev.com>
parents:
374
diff
changeset
|
16 #define MCLKS_NTSC 53693175 |
1c8d74f2ab0b
Make the PSG and YM2612 use the master clock internal with an increment based on clock divider so that they stay perflectly in sync. Run both the PSG and YM2612 whenver one of them needs to be run.
Mike Pavone <pavone@retrodev.com>
parents:
374
diff
changeset
|
17 #define MCLKS_PAL 53203395 |
1c8d74f2ab0b
Make the PSG and YM2612 use the master clock internal with an increment based on clock divider so that they stay perflectly in sync. Run both the PSG and YM2612 whenver one of them needs to be run.
Mike Pavone <pavone@retrodev.com>
parents:
374
diff
changeset
|
18 |
88
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
19 #define MCLKS_PER_68K 7 |
380
1c8d74f2ab0b
Make the PSG and YM2612 use the master clock internal with an increment based on clock divider so that they stay perflectly in sync. Run both the PSG and YM2612 whenver one of them needs to be run.
Mike Pavone <pavone@retrodev.com>
parents:
374
diff
changeset
|
20 #define MCLKS_PER_YM MCLKS_PER_68K |
260
625f8e4d5fd2
Initial stab at integartiong Z80 core
Mike Pavone <pavone@retrodev.com>
parents:
215
diff
changeset
|
21 #define MCLKS_PER_Z80 15 |
354
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
351
diff
changeset
|
22 #define MCLKS_PER_PSG (MCLKS_PER_Z80*16) |
380
1c8d74f2ab0b
Make the PSG and YM2612 use the master clock internal with an increment based on clock divider so that they stay perflectly in sync. Run both the PSG and YM2612 whenver one of them needs to be run.
Mike Pavone <pavone@retrodev.com>
parents:
374
diff
changeset
|
23 |
88
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
24 //TODO: Figure out the exact value for this |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
25 #define CYCLE_NEVER 0xFFFFFFFF |
342
13f994c88c34
Get frame time correct and frame rate sort of correct for EUR region
Mike Pavone <pavone@retrodev.com>
parents:
341
diff
changeset
|
26 #define LINES_NTSC 262 |
13f994c88c34
Get frame time correct and frame rate sort of correct for EUR region
Mike Pavone <pavone@retrodev.com>
parents:
341
diff
changeset
|
27 #define LINES_PAL 312 |
13f994c88c34
Get frame time correct and frame rate sort of correct for EUR region
Mike Pavone <pavone@retrodev.com>
parents:
341
diff
changeset
|
28 |
13f994c88c34
Get frame time correct and frame rate sort of correct for EUR region
Mike Pavone <pavone@retrodev.com>
parents:
341
diff
changeset
|
29 uint32_t mclks_per_frame = MCLKS_LINE*LINES_NTSC; |
88
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
30 |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
31 uint16_t cart[CARTRIDGE_WORDS]; |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
32 uint16_t ram[RAM_WORDS]; |
153
42c031184e8a
Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents:
149
diff
changeset
|
33 uint8_t z80_ram[Z80_RAM_BYTES]; |
88
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
34 |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
35 io_port gamepad_1; |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
36 io_port gamepad_2; |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
37 |
215
2b1c2c28b261
Added headless flag to avoid initializing SDL and opening a window when running tests.
Mike Pavone <pavone@retrodev.com>
parents:
211
diff
changeset
|
38 int headless = 0; |
265
c6d12878ea93
Add -n flag for disabling the Z80 core
Mike Pavone <pavone@retrodev.com>
parents:
264
diff
changeset
|
39 int z80_enabled = 1; |
356
79e4b466e7d0
Get rid of debug puts and limit based on audio rather than frame rate by default.
Mike Pavone <pavone@retrodev.com>
parents:
354
diff
changeset
|
40 int frame_limit = 0; |
215
2b1c2c28b261
Added headless flag to avoid initializing SDL and opening a window when running tests.
Mike Pavone <pavone@retrodev.com>
parents:
211
diff
changeset
|
41 |
88
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
42 #ifndef MIN |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
43 #define MIN(a,b) ((a) < (b) ? (a) : (b)) |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
44 #endif |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
45 |
166 | 46 #define SMD_HEADER_SIZE 512 |
47 #define SMD_MAGIC1 0x03 | |
48 #define SMD_MAGIC2 0xAA | |
49 #define SMD_MAGIC3 0xBB | |
50 #define SMD_BLOCK_SIZE 0x4000 | |
51 | |
52 int load_smd_rom(long filesize, FILE * f) | |
53 { | |
54 uint8_t block[SMD_BLOCK_SIZE]; | |
55 filesize -= SMD_HEADER_SIZE; | |
56 fseek(f, SMD_HEADER_SIZE, SEEK_SET); | |
57 | |
58 uint16_t * dst = cart; | |
59 while (filesize > 0) { | |
60 fread(block, 1, SMD_BLOCK_SIZE, f); | |
61 for (uint8_t *low = block, *high = (block+SMD_BLOCK_SIZE/2), *end = block+SMD_BLOCK_SIZE; high < end; high++, low++) { | |
62 *(dst++) = *high << 8 | *low; | |
63 } | |
64 filesize -= SMD_BLOCK_SIZE; | |
65 } | |
66 return 1; | |
67 } | |
68 | |
88
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
69 int load_rom(char * filename) |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
70 { |
166 | 71 uint8_t header[10]; |
88
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
72 FILE * f = fopen(filename, "rb"); |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
73 if (!f) { |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
74 return 0; |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
75 } |
166 | 76 fread(header, 1, sizeof(header), f); |
88
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
77 fseek(f, 0, SEEK_END); |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
78 long filesize = ftell(f); |
158
a2ab895d9708
Fix predec address mode when used as source
Mike Pavone <pavone@retrodev.com>
parents:
153
diff
changeset
|
79 if (filesize/2 > CARTRIDGE_WORDS) { |
a2ab895d9708
Fix predec address mode when used as source
Mike Pavone <pavone@retrodev.com>
parents:
153
diff
changeset
|
80 //carts bigger than 4MB not currently supported |
a2ab895d9708
Fix predec address mode when used as source
Mike Pavone <pavone@retrodev.com>
parents:
153
diff
changeset
|
81 filesize = CARTRIDGE_WORDS*2; |
a2ab895d9708
Fix predec address mode when used as source
Mike Pavone <pavone@retrodev.com>
parents:
153
diff
changeset
|
82 } |
88
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
83 fseek(f, 0, SEEK_SET); |
166 | 84 if (header[1] == SMD_MAGIC1 && header[8] == SMD_MAGIC2 && header[9] == SMD_MAGIC3) { |
85 int i; | |
86 for (i = 3; i < 8; i++) { | |
87 if (header[i] != 0) { | |
88 break; | |
89 } | |
90 } | |
91 if (i == 8) { | |
92 if (header[2]) { | |
93 fprintf(stderr, "%s is a split SMD ROM which is not currently supported", filename); | |
94 exit(1); | |
95 } | |
96 return load_smd_rom(filesize, f); | |
97 } | |
98 } | |
99 fread(cart, 2, filesize/2, f); | |
88
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
100 fclose(f); |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
101 for(unsigned short * cur = cart; cur - cart < (filesize/2); ++cur) |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
102 { |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
103 *cur = (*cur >> 8) | (*cur << 8); |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
104 } |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
105 //TODO: Mirror ROM |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
106 return 1; |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
107 } |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
108 |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
109 uint16_t read_dma_value(uint32_t address) |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
110 { |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
111 //addresses here are word addresses (i.e. bit 0 corresponds to A1), so no need to do div by 2 |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
112 if (address < 0x200000) { |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
113 return cart[address]; |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
114 } else if(address >= 0x700000) { |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
115 return ram[address & 0x7FFF]; |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
116 } |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
117 //TODO: Figure out what happens when you try to DMA from weird adresses like IO or banked Z80 area |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
118 return 0; |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
119 } |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
120 |
317
e5e8b48ad157
Initial stab at horizontal interrupts and improving accuracy of vertical interrupts. Also added the VINT pending flag to status port.
Mike Pavone <pavone@retrodev.com>
parents:
290
diff
changeset
|
121 //TODO: Make these dependent on the video mode |
e5e8b48ad157
Initial stab at horizontal interrupts and improving accuracy of vertical interrupts. Also added the VINT pending flag to status port.
Mike Pavone <pavone@retrodev.com>
parents:
290
diff
changeset
|
122 //#define VINT_CYCLE ((MCLKS_LINE * 225 + (148 + 40) * 4)/MCLKS_PER_68K) |
e5e8b48ad157
Initial stab at horizontal interrupts and improving accuracy of vertical interrupts. Also added the VINT pending flag to status port.
Mike Pavone <pavone@retrodev.com>
parents:
290
diff
changeset
|
123 #define ZVINT_CYCLE ((MCLKS_LINE * 225 + (148 + 40) * 4)/MCLKS_PER_Z80) |
e5e8b48ad157
Initial stab at horizontal interrupts and improving accuracy of vertical interrupts. Also added the VINT pending flag to status port.
Mike Pavone <pavone@retrodev.com>
parents:
290
diff
changeset
|
124 //#define VINT_CYCLE ((MCLKS_LINE * 226)/MCLKS_PER_68K) |
e5e8b48ad157
Initial stab at horizontal interrupts and improving accuracy of vertical interrupts. Also added the VINT pending flag to status port.
Mike Pavone <pavone@retrodev.com>
parents:
290
diff
changeset
|
125 //#define ZVINT_CYCLE ((MCLKS_LINE * 226)/MCLKS_PER_Z80) |
88
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
126 |
186
02e25abe2dcd
Cleanup VINT code and fix bug in which VINT cycle would be set incorrectly after a VDP control port write
Mike Pavone <pavone@retrodev.com>
parents:
185
diff
changeset
|
127 void adjust_int_cycle(m68k_context * context, vdp_context * v_context) |
02e25abe2dcd
Cleanup VINT code and fix bug in which VINT cycle would be set incorrectly after a VDP control port write
Mike Pavone <pavone@retrodev.com>
parents:
185
diff
changeset
|
128 { |
317
e5e8b48ad157
Initial stab at horizontal interrupts and improving accuracy of vertical interrupts. Also added the VINT pending flag to status port.
Mike Pavone <pavone@retrodev.com>
parents:
290
diff
changeset
|
129 context->int_cycle = CYCLE_NEVER; |
e5e8b48ad157
Initial stab at horizontal interrupts and improving accuracy of vertical interrupts. Also added the VINT pending flag to status port.
Mike Pavone <pavone@retrodev.com>
parents:
290
diff
changeset
|
130 if ((context->status & 0x7) < 6) { |
e5e8b48ad157
Initial stab at horizontal interrupts and improving accuracy of vertical interrupts. Also added the VINT pending flag to status port.
Mike Pavone <pavone@retrodev.com>
parents:
290
diff
changeset
|
131 uint32_t next_vint = vdp_next_vint(v_context); |
e5e8b48ad157
Initial stab at horizontal interrupts and improving accuracy of vertical interrupts. Also added the VINT pending flag to status port.
Mike Pavone <pavone@retrodev.com>
parents:
290
diff
changeset
|
132 if (next_vint != CYCLE_NEVER) { |
e5e8b48ad157
Initial stab at horizontal interrupts and improving accuracy of vertical interrupts. Also added the VINT pending flag to status port.
Mike Pavone <pavone@retrodev.com>
parents:
290
diff
changeset
|
133 next_vint /= MCLKS_PER_68K; |
e5e8b48ad157
Initial stab at horizontal interrupts and improving accuracy of vertical interrupts. Also added the VINT pending flag to status port.
Mike Pavone <pavone@retrodev.com>
parents:
290
diff
changeset
|
134 context->int_cycle = next_vint; |
e5e8b48ad157
Initial stab at horizontal interrupts and improving accuracy of vertical interrupts. Also added the VINT pending flag to status port.
Mike Pavone <pavone@retrodev.com>
parents:
290
diff
changeset
|
135 context->int_num = 6; |
e5e8b48ad157
Initial stab at horizontal interrupts and improving accuracy of vertical interrupts. Also added the VINT pending flag to status port.
Mike Pavone <pavone@retrodev.com>
parents:
290
diff
changeset
|
136 } |
e5e8b48ad157
Initial stab at horizontal interrupts and improving accuracy of vertical interrupts. Also added the VINT pending flag to status port.
Mike Pavone <pavone@retrodev.com>
parents:
290
diff
changeset
|
137 if ((context->status & 0x7) < 4) { |
e5e8b48ad157
Initial stab at horizontal interrupts and improving accuracy of vertical interrupts. Also added the VINT pending flag to status port.
Mike Pavone <pavone@retrodev.com>
parents:
290
diff
changeset
|
138 uint32_t next_hint = vdp_next_hint(v_context); |
e5e8b48ad157
Initial stab at horizontal interrupts and improving accuracy of vertical interrupts. Also added the VINT pending flag to status port.
Mike Pavone <pavone@retrodev.com>
parents:
290
diff
changeset
|
139 if (next_hint != CYCLE_NEVER) { |
e5e8b48ad157
Initial stab at horizontal interrupts and improving accuracy of vertical interrupts. Also added the VINT pending flag to status port.
Mike Pavone <pavone@retrodev.com>
parents:
290
diff
changeset
|
140 next_hint /= MCLKS_PER_68K; |
e5e8b48ad157
Initial stab at horizontal interrupts and improving accuracy of vertical interrupts. Also added the VINT pending flag to status port.
Mike Pavone <pavone@retrodev.com>
parents:
290
diff
changeset
|
141 if (next_hint < context->int_cycle) { |
e5e8b48ad157
Initial stab at horizontal interrupts and improving accuracy of vertical interrupts. Also added the VINT pending flag to status port.
Mike Pavone <pavone@retrodev.com>
parents:
290
diff
changeset
|
142 context->int_cycle = next_hint; |
e5e8b48ad157
Initial stab at horizontal interrupts and improving accuracy of vertical interrupts. Also added the VINT pending flag to status port.
Mike Pavone <pavone@retrodev.com>
parents:
290
diff
changeset
|
143 context->int_num = 4; |
e5e8b48ad157
Initial stab at horizontal interrupts and improving accuracy of vertical interrupts. Also added the VINT pending flag to status port.
Mike Pavone <pavone@retrodev.com>
parents:
290
diff
changeset
|
144 |
e5e8b48ad157
Initial stab at horizontal interrupts and improving accuracy of vertical interrupts. Also added the VINT pending flag to status port.
Mike Pavone <pavone@retrodev.com>
parents:
290
diff
changeset
|
145 } |
e5e8b48ad157
Initial stab at horizontal interrupts and improving accuracy of vertical interrupts. Also added the VINT pending flag to status port.
Mike Pavone <pavone@retrodev.com>
parents:
290
diff
changeset
|
146 } |
186
02e25abe2dcd
Cleanup VINT code and fix bug in which VINT cycle would be set incorrectly after a VDP control port write
Mike Pavone <pavone@retrodev.com>
parents:
185
diff
changeset
|
147 } |
02e25abe2dcd
Cleanup VINT code and fix bug in which VINT cycle would be set incorrectly after a VDP control port write
Mike Pavone <pavone@retrodev.com>
parents:
185
diff
changeset
|
148 } |
317
e5e8b48ad157
Initial stab at horizontal interrupts and improving accuracy of vertical interrupts. Also added the VINT pending flag to status port.
Mike Pavone <pavone@retrodev.com>
parents:
290
diff
changeset
|
149 |
e5e8b48ad157
Initial stab at horizontal interrupts and improving accuracy of vertical interrupts. Also added the VINT pending flag to status port.
Mike Pavone <pavone@retrodev.com>
parents:
290
diff
changeset
|
150 context->target_cycle = context->int_cycle < context->sync_cycle ? context->int_cycle : context->sync_cycle; |
e5e8b48ad157
Initial stab at horizontal interrupts and improving accuracy of vertical interrupts. Also added the VINT pending flag to status port.
Mike Pavone <pavone@retrodev.com>
parents:
290
diff
changeset
|
151 /*printf("Cyc: %d, Trgt: %d, Int Cyc: %d, Int: %d, Mask: %X, V: %d, H: %d, HICount: %d, HReg: %d, Line: %d\n", |
e5e8b48ad157
Initial stab at horizontal interrupts and improving accuracy of vertical interrupts. Also added the VINT pending flag to status port.
Mike Pavone <pavone@retrodev.com>
parents:
290
diff
changeset
|
152 context->current_cycle, context->target_cycle, context->int_cycle, context->int_num, (context->status & 0x7), |
e5e8b48ad157
Initial stab at horizontal interrupts and improving accuracy of vertical interrupts. Also added the VINT pending flag to status port.
Mike Pavone <pavone@retrodev.com>
parents:
290
diff
changeset
|
153 v_context->regs[REG_MODE_2] & 0x20, v_context->regs[REG_MODE_1] & 0x10, v_context->hint_counter, v_context->regs[REG_HINT], v_context->cycles / MCLKS_LINE);*/ |
186
02e25abe2dcd
Cleanup VINT code and fix bug in which VINT cycle would be set incorrectly after a VDP control port write
Mike Pavone <pavone@retrodev.com>
parents:
185
diff
changeset
|
154 } |
02e25abe2dcd
Cleanup VINT code and fix bug in which VINT cycle would be set incorrectly after a VDP control port write
Mike Pavone <pavone@retrodev.com>
parents:
185
diff
changeset
|
155 |
198
209a37eed3e7
Add support for breaking into the debugger while game is running
Mike Pavone <pavone@retrodev.com>
parents:
197
diff
changeset
|
156 int break_on_sync = 0; |
260
625f8e4d5fd2
Initial stab at integartiong Z80 core
Mike Pavone <pavone@retrodev.com>
parents:
215
diff
changeset
|
157 |
625f8e4d5fd2
Initial stab at integartiong Z80 core
Mike Pavone <pavone@retrodev.com>
parents:
215
diff
changeset
|
158 uint8_t reset = 1; |
625f8e4d5fd2
Initial stab at integartiong Z80 core
Mike Pavone <pavone@retrodev.com>
parents:
215
diff
changeset
|
159 uint8_t need_reset = 0; |
625f8e4d5fd2
Initial stab at integartiong Z80 core
Mike Pavone <pavone@retrodev.com>
parents:
215
diff
changeset
|
160 uint8_t busreq = 0; |
625f8e4d5fd2
Initial stab at integartiong Z80 core
Mike Pavone <pavone@retrodev.com>
parents:
215
diff
changeset
|
161 uint8_t busack = 0; |
625f8e4d5fd2
Initial stab at integartiong Z80 core
Mike Pavone <pavone@retrodev.com>
parents:
215
diff
changeset
|
162 uint32_t busack_cycle = CYCLE_NEVER; |
625f8e4d5fd2
Initial stab at integartiong Z80 core
Mike Pavone <pavone@retrodev.com>
parents:
215
diff
changeset
|
163 uint8_t new_busack = 0; |
280 | 164 //#define DO_DEBUG_PRINT |
268
6c2d7e003a55
Sync Z80 on writes to busreq/reset ports. NULL out extra_pc on z80 reset
Mike Pavone <pavone@retrodev.com>
parents:
266
diff
changeset
|
165 #ifdef DO_DEBUG_PRINT |
6c2d7e003a55
Sync Z80 on writes to busreq/reset ports. NULL out extra_pc on z80 reset
Mike Pavone <pavone@retrodev.com>
parents:
266
diff
changeset
|
166 #define dprintf printf |
271
969ee17471c5
Protect debug prints for busreq/reset regs with appropriate macros
Mike Pavone <pavone@retrodev.com>
parents:
268
diff
changeset
|
167 #define dputs puts |
268
6c2d7e003a55
Sync Z80 on writes to busreq/reset ports. NULL out extra_pc on z80 reset
Mike Pavone <pavone@retrodev.com>
parents:
266
diff
changeset
|
168 #else |
6c2d7e003a55
Sync Z80 on writes to busreq/reset ports. NULL out extra_pc on z80 reset
Mike Pavone <pavone@retrodev.com>
parents:
266
diff
changeset
|
169 #define dprintf |
271
969ee17471c5
Protect debug prints for busreq/reset regs with appropriate macros
Mike Pavone <pavone@retrodev.com>
parents:
268
diff
changeset
|
170 #define dputs |
268
6c2d7e003a55
Sync Z80 on writes to busreq/reset ports. NULL out extra_pc on z80 reset
Mike Pavone <pavone@retrodev.com>
parents:
266
diff
changeset
|
171 #endif |
6c2d7e003a55
Sync Z80 on writes to busreq/reset ports. NULL out extra_pc on z80 reset
Mike Pavone <pavone@retrodev.com>
parents:
266
diff
changeset
|
172 |
6c2d7e003a55
Sync Z80 on writes to busreq/reset ports. NULL out extra_pc on z80 reset
Mike Pavone <pavone@retrodev.com>
parents:
266
diff
changeset
|
173 void sync_z80(z80_context * z_context, uint32_t mclks) |
88
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
174 { |
265
c6d12878ea93
Add -n flag for disabling the Z80 core
Mike Pavone <pavone@retrodev.com>
parents:
264
diff
changeset
|
175 if (z80_enabled && !reset && !busreq) { |
333 | 176 genesis_context * gen = z_context->system; |
260
625f8e4d5fd2
Initial stab at integartiong Z80 core
Mike Pavone <pavone@retrodev.com>
parents:
215
diff
changeset
|
177 if (need_reset) { |
625f8e4d5fd2
Initial stab at integartiong Z80 core
Mike Pavone <pavone@retrodev.com>
parents:
215
diff
changeset
|
178 z80_reset(z_context); |
625f8e4d5fd2
Initial stab at integartiong Z80 core
Mike Pavone <pavone@retrodev.com>
parents:
215
diff
changeset
|
179 need_reset = 0; |
625f8e4d5fd2
Initial stab at integartiong Z80 core
Mike Pavone <pavone@retrodev.com>
parents:
215
diff
changeset
|
180 } |
625f8e4d5fd2
Initial stab at integartiong Z80 core
Mike Pavone <pavone@retrodev.com>
parents:
215
diff
changeset
|
181 z_context->sync_cycle = mclks / MCLKS_PER_Z80; |
333 | 182 uint32_t vint_cycle = vdp_next_vint_z80(gen->vdp) / MCLKS_PER_Z80; |
260
625f8e4d5fd2
Initial stab at integartiong Z80 core
Mike Pavone <pavone@retrodev.com>
parents:
215
diff
changeset
|
183 while (z_context->current_cycle < z_context->sync_cycle) { |
335 | 184 if (z_context->iff1 && z_context->current_cycle < vint_cycle) { |
185 z_context->int_cycle = vint_cycle < z_context->int_enable_cycle ? z_context->int_enable_cycle : vint_cycle; | |
260
625f8e4d5fd2
Initial stab at integartiong Z80 core
Mike Pavone <pavone@retrodev.com>
parents:
215
diff
changeset
|
186 } |
625f8e4d5fd2
Initial stab at integartiong Z80 core
Mike Pavone <pavone@retrodev.com>
parents:
215
diff
changeset
|
187 z_context->target_cycle = z_context->sync_cycle < z_context->int_cycle ? z_context->sync_cycle : z_context->int_cycle; |
268
6c2d7e003a55
Sync Z80 on writes to busreq/reset ports. NULL out extra_pc on z80 reset
Mike Pavone <pavone@retrodev.com>
parents:
266
diff
changeset
|
188 dprintf("Running Z80 from cycle %d to cycle %d. Native PC: %p\n", z_context->current_cycle, z_context->sync_cycle, z_context->native_pc); |
260
625f8e4d5fd2
Initial stab at integartiong Z80 core
Mike Pavone <pavone@retrodev.com>
parents:
215
diff
changeset
|
189 z80_run(z_context); |
268
6c2d7e003a55
Sync Z80 on writes to busreq/reset ports. NULL out extra_pc on z80 reset
Mike Pavone <pavone@retrodev.com>
parents:
266
diff
changeset
|
190 dprintf("Z80 ran to cycle %d\n", z_context->current_cycle); |
260
625f8e4d5fd2
Initial stab at integartiong Z80 core
Mike Pavone <pavone@retrodev.com>
parents:
215
diff
changeset
|
191 } |
289
1cc0850ab6bc
Hopefully more correct implementation of the Z80 busack status
Mike Pavone <pavone@retrodev.com>
parents:
288
diff
changeset
|
192 } else { |
1cc0850ab6bc
Hopefully more correct implementation of the Z80 busack status
Mike Pavone <pavone@retrodev.com>
parents:
288
diff
changeset
|
193 z_context->current_cycle = mclks / MCLKS_PER_Z80; |
260
625f8e4d5fd2
Initial stab at integartiong Z80 core
Mike Pavone <pavone@retrodev.com>
parents:
215
diff
changeset
|
194 } |
268
6c2d7e003a55
Sync Z80 on writes to busreq/reset ports. NULL out extra_pc on z80 reset
Mike Pavone <pavone@retrodev.com>
parents:
266
diff
changeset
|
195 } |
380
1c8d74f2ab0b
Make the PSG and YM2612 use the master clock internal with an increment based on clock divider so that they stay perflectly in sync. Run both the PSG and YM2612 whenver one of them needs to be run.
Mike Pavone <pavone@retrodev.com>
parents:
374
diff
changeset
|
196 |
1c8d74f2ab0b
Make the PSG and YM2612 use the master clock internal with an increment based on clock divider so that they stay perflectly in sync. Run both the PSG and YM2612 whenver one of them needs to be run.
Mike Pavone <pavone@retrodev.com>
parents:
374
diff
changeset
|
197 void sync_sound(genesis_context * gen, uint32_t target) |
1c8d74f2ab0b
Make the PSG and YM2612 use the master clock internal with an increment based on clock divider so that they stay perflectly in sync. Run both the PSG and YM2612 whenver one of them needs to be run.
Mike Pavone <pavone@retrodev.com>
parents:
374
diff
changeset
|
198 { |
1c8d74f2ab0b
Make the PSG and YM2612 use the master clock internal with an increment based on clock divider so that they stay perflectly in sync. Run both the PSG and YM2612 whenver one of them needs to be run.
Mike Pavone <pavone@retrodev.com>
parents:
374
diff
changeset
|
199 //printf("YM | Cycle: %d, bpos: %d, PSG | Cycle: %d, bpos: %d\n", gen->ym->current_cycle, gen->ym->buffer_pos, gen->psg->cycles, gen->psg->buffer_pos * 2); |
1c8d74f2ab0b
Make the PSG and YM2612 use the master clock internal with an increment based on clock divider so that they stay perflectly in sync. Run both the PSG and YM2612 whenver one of them needs to be run.
Mike Pavone <pavone@retrodev.com>
parents:
374
diff
changeset
|
200 psg_run(gen->psg, target); |
1c8d74f2ab0b
Make the PSG and YM2612 use the master clock internal with an increment based on clock divider so that they stay perflectly in sync. Run both the PSG and YM2612 whenver one of them needs to be run.
Mike Pavone <pavone@retrodev.com>
parents:
374
diff
changeset
|
201 ym_run(gen->ym, target); |
1c8d74f2ab0b
Make the PSG and YM2612 use the master clock internal with an increment based on clock divider so that they stay perflectly in sync. Run both the PSG and YM2612 whenver one of them needs to be run.
Mike Pavone <pavone@retrodev.com>
parents:
374
diff
changeset
|
202 |
1c8d74f2ab0b
Make the PSG and YM2612 use the master clock internal with an increment based on clock divider so that they stay perflectly in sync. Run both the PSG and YM2612 whenver one of them needs to be run.
Mike Pavone <pavone@retrodev.com>
parents:
374
diff
changeset
|
203 //printf("Target: %d, YM bufferpos: %d, PSG bufferpos: %d\n", target, gen->ym->buffer_pos, gen->psg->buffer_pos * 2); |
1c8d74f2ab0b
Make the PSG and YM2612 use the master clock internal with an increment based on clock divider so that they stay perflectly in sync. Run both the PSG and YM2612 whenver one of them needs to be run.
Mike Pavone <pavone@retrodev.com>
parents:
374
diff
changeset
|
204 } |
1c8d74f2ab0b
Make the PSG and YM2612 use the master clock internal with an increment based on clock divider so that they stay perflectly in sync. Run both the PSG and YM2612 whenver one of them needs to be run.
Mike Pavone <pavone@retrodev.com>
parents:
374
diff
changeset
|
205 |
321
146c87616b05
Don't update interrupt mask on non-interrupt exceptions
Mike Pavone <pavone@retrodev.com>
parents:
317
diff
changeset
|
206 uint32_t frame=0; |
268
6c2d7e003a55
Sync Z80 on writes to busreq/reset ports. NULL out extra_pc on z80 reset
Mike Pavone <pavone@retrodev.com>
parents:
266
diff
changeset
|
207 m68k_context * sync_components(m68k_context * context, uint32_t address) |
6c2d7e003a55
Sync Z80 on writes to busreq/reset ports. NULL out extra_pc on z80 reset
Mike Pavone <pavone@retrodev.com>
parents:
266
diff
changeset
|
208 { |
6c2d7e003a55
Sync Z80 on writes to busreq/reset ports. NULL out extra_pc on z80 reset
Mike Pavone <pavone@retrodev.com>
parents:
266
diff
changeset
|
209 //TODO: Handle sync targets smaller than a single frame |
288
a8ee7934a1f8
Add a YM2612 stub implementation with just timers and status registers so that games that depend on it can run.
Mike Pavone <pavone@retrodev.com>
parents:
280
diff
changeset
|
210 genesis_context * gen = context->system; |
a8ee7934a1f8
Add a YM2612 stub implementation with just timers and status registers so that games that depend on it can run.
Mike Pavone <pavone@retrodev.com>
parents:
280
diff
changeset
|
211 vdp_context * v_context = gen->vdp; |
a8ee7934a1f8
Add a YM2612 stub implementation with just timers and status registers so that games that depend on it can run.
Mike Pavone <pavone@retrodev.com>
parents:
280
diff
changeset
|
212 z80_context * z_context = gen->z80; |
268
6c2d7e003a55
Sync Z80 on writes to busreq/reset ports. NULL out extra_pc on z80 reset
Mike Pavone <pavone@retrodev.com>
parents:
266
diff
changeset
|
213 uint32_t mclks = context->current_cycle * MCLKS_PER_68K; |
6c2d7e003a55
Sync Z80 on writes to busreq/reset ports. NULL out extra_pc on z80 reset
Mike Pavone <pavone@retrodev.com>
parents:
266
diff
changeset
|
214 sync_z80(z_context, mclks); |
342
13f994c88c34
Get frame time correct and frame rate sort of correct for EUR region
Mike Pavone <pavone@retrodev.com>
parents:
341
diff
changeset
|
215 if (mclks >= mclks_per_frame) { |
380
1c8d74f2ab0b
Make the PSG and YM2612 use the master clock internal with an increment based on clock divider so that they stay perflectly in sync. Run both the PSG and YM2612 whenver one of them needs to be run.
Mike Pavone <pavone@retrodev.com>
parents:
374
diff
changeset
|
216 sync_sound(gen, mclks); |
1c8d74f2ab0b
Make the PSG and YM2612 use the master clock internal with an increment based on clock divider so that they stay perflectly in sync. Run both the PSG and YM2612 whenver one of them needs to be run.
Mike Pavone <pavone@retrodev.com>
parents:
374
diff
changeset
|
217 gen->ym->current_cycle -= mclks_per_frame; |
1c8d74f2ab0b
Make the PSG and YM2612 use the master clock internal with an increment based on clock divider so that they stay perflectly in sync. Run both the PSG and YM2612 whenver one of them needs to be run.
Mike Pavone <pavone@retrodev.com>
parents:
374
diff
changeset
|
218 gen->psg->cycles -= mclks_per_frame; |
374 | 219 if (gen->ym->write_cycle != CYCLE_NEVER) { |
220 gen->ym->write_cycle = gen->ym->write_cycle >= mclks_per_frame/MCLKS_PER_68K ? gen->ym->write_cycle - mclks_per_frame/MCLKS_PER_68K : 0; | |
221 } | |
88
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
222 //printf("reached frame end | 68K Cycles: %d, MCLK Cycles: %d\n", context->current_cycle, mclks); |
342
13f994c88c34
Get frame time correct and frame rate sort of correct for EUR region
Mike Pavone <pavone@retrodev.com>
parents:
341
diff
changeset
|
223 vdp_run_context(v_context, mclks_per_frame); |
380
1c8d74f2ab0b
Make the PSG and YM2612 use the master clock internal with an increment based on clock divider so that they stay perflectly in sync. Run both the PSG and YM2612 whenver one of them needs to be run.
Mike Pavone <pavone@retrodev.com>
parents:
374
diff
changeset
|
224 |
215
2b1c2c28b261
Added headless flag to avoid initializing SDL and opening a window when running tests.
Mike Pavone <pavone@retrodev.com>
parents:
211
diff
changeset
|
225 if (!headless) { |
338
5c34a9c39394
Re-enable frame limit, but add a command line flag to disable it
Mike Pavone <pavone@retrodev.com>
parents:
336
diff
changeset
|
226 break_on_sync |= wait_render_frame(v_context, frame_limit); |
215
2b1c2c28b261
Added headless flag to avoid initializing SDL and opening a window when running tests.
Mike Pavone <pavone@retrodev.com>
parents:
211
diff
changeset
|
227 } |
321
146c87616b05
Don't update interrupt mask on non-interrupt exceptions
Mike Pavone <pavone@retrodev.com>
parents:
317
diff
changeset
|
228 frame++; |
342
13f994c88c34
Get frame time correct and frame rate sort of correct for EUR region
Mike Pavone <pavone@retrodev.com>
parents:
341
diff
changeset
|
229 mclks -= mclks_per_frame; |
13f994c88c34
Get frame time correct and frame rate sort of correct for EUR region
Mike Pavone <pavone@retrodev.com>
parents:
341
diff
changeset
|
230 vdp_adjust_cycles(v_context, mclks_per_frame); |
13f994c88c34
Get frame time correct and frame rate sort of correct for EUR region
Mike Pavone <pavone@retrodev.com>
parents:
341
diff
changeset
|
231 io_adjust_cycles(&gamepad_1, context->current_cycle, mclks_per_frame/MCLKS_PER_68K); |
13f994c88c34
Get frame time correct and frame rate sort of correct for EUR region
Mike Pavone <pavone@retrodev.com>
parents:
341
diff
changeset
|
232 io_adjust_cycles(&gamepad_2, context->current_cycle, mclks_per_frame/MCLKS_PER_68K); |
344
b46771135442
Handle busack across frame boundary
Mike Pavone <pavone@retrodev.com>
parents:
343
diff
changeset
|
233 if (busack_cycle != CYCLE_NEVER) { |
b46771135442
Handle busack across frame boundary
Mike Pavone <pavone@retrodev.com>
parents:
343
diff
changeset
|
234 if (busack_cycle > mclks_per_frame/MCLKS_PER_68K) { |
b46771135442
Handle busack across frame boundary
Mike Pavone <pavone@retrodev.com>
parents:
343
diff
changeset
|
235 busack_cycle -= mclks_per_frame/MCLKS_PER_68K; |
b46771135442
Handle busack across frame boundary
Mike Pavone <pavone@retrodev.com>
parents:
343
diff
changeset
|
236 } else { |
b46771135442
Handle busack across frame boundary
Mike Pavone <pavone@retrodev.com>
parents:
343
diff
changeset
|
237 busack_cycle = CYCLE_NEVER; |
b46771135442
Handle busack across frame boundary
Mike Pavone <pavone@retrodev.com>
parents:
343
diff
changeset
|
238 busack = new_busack; |
b46771135442
Handle busack across frame boundary
Mike Pavone <pavone@retrodev.com>
parents:
343
diff
changeset
|
239 } |
b46771135442
Handle busack across frame boundary
Mike Pavone <pavone@retrodev.com>
parents:
343
diff
changeset
|
240 } |
342
13f994c88c34
Get frame time correct and frame rate sort of correct for EUR region
Mike Pavone <pavone@retrodev.com>
parents:
341
diff
changeset
|
241 context->current_cycle -= mclks_per_frame/MCLKS_PER_68K; |
13f994c88c34
Get frame time correct and frame rate sort of correct for EUR region
Mike Pavone <pavone@retrodev.com>
parents:
341
diff
changeset
|
242 if (z_context->current_cycle >= mclks_per_frame/MCLKS_PER_Z80) { |
13f994c88c34
Get frame time correct and frame rate sort of correct for EUR region
Mike Pavone <pavone@retrodev.com>
parents:
341
diff
changeset
|
243 z_context->current_cycle -= mclks_per_frame/MCLKS_PER_Z80; |
260
625f8e4d5fd2
Initial stab at integartiong Z80 core
Mike Pavone <pavone@retrodev.com>
parents:
215
diff
changeset
|
244 } else { |
625f8e4d5fd2
Initial stab at integartiong Z80 core
Mike Pavone <pavone@retrodev.com>
parents:
215
diff
changeset
|
245 z_context->current_cycle = 0; |
625f8e4d5fd2
Initial stab at integartiong Z80 core
Mike Pavone <pavone@retrodev.com>
parents:
215
diff
changeset
|
246 } |
88
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
247 if (mclks) { |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
248 vdp_run_context(v_context, mclks); |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
249 } |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
250 } else { |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
251 //printf("running VDP for %d cycles\n", mclks - v_context->cycles); |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
252 vdp_run_context(v_context, mclks); |
380
1c8d74f2ab0b
Make the PSG and YM2612 use the master clock internal with an increment based on clock divider so that they stay perflectly in sync. Run both the PSG and YM2612 whenver one of them needs to be run.
Mike Pavone <pavone@retrodev.com>
parents:
374
diff
changeset
|
253 sync_sound(gen, mclks); |
88
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
254 } |
317
e5e8b48ad157
Initial stab at horizontal interrupts and improving accuracy of vertical interrupts. Also added the VINT pending flag to status port.
Mike Pavone <pavone@retrodev.com>
parents:
290
diff
changeset
|
255 if (context->int_ack) { |
e5e8b48ad157
Initial stab at horizontal interrupts and improving accuracy of vertical interrupts. Also added the VINT pending flag to status port.
Mike Pavone <pavone@retrodev.com>
parents:
290
diff
changeset
|
256 vdp_int_ack(v_context, context->int_ack); |
e5e8b48ad157
Initial stab at horizontal interrupts and improving accuracy of vertical interrupts. Also added the VINT pending flag to status port.
Mike Pavone <pavone@retrodev.com>
parents:
290
diff
changeset
|
257 context->int_ack = 0; |
e5e8b48ad157
Initial stab at horizontal interrupts and improving accuracy of vertical interrupts. Also added the VINT pending flag to status port.
Mike Pavone <pavone@retrodev.com>
parents:
290
diff
changeset
|
258 } |
186
02e25abe2dcd
Cleanup VINT code and fix bug in which VINT cycle would be set incorrectly after a VDP control port write
Mike Pavone <pavone@retrodev.com>
parents:
185
diff
changeset
|
259 adjust_int_cycle(context, v_context); |
198
209a37eed3e7
Add support for breaking into the debugger while game is running
Mike Pavone <pavone@retrodev.com>
parents:
197
diff
changeset
|
260 if (break_on_sync && address) { |
209a37eed3e7
Add support for breaking into the debugger while game is running
Mike Pavone <pavone@retrodev.com>
parents:
197
diff
changeset
|
261 break_on_sync = 0; |
209a37eed3e7
Add support for breaking into the debugger while game is running
Mike Pavone <pavone@retrodev.com>
parents:
197
diff
changeset
|
262 debugger(context, address); |
209a37eed3e7
Add support for breaking into the debugger while game is running
Mike Pavone <pavone@retrodev.com>
parents:
197
diff
changeset
|
263 } |
88
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
264 return context; |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
265 } |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
266 |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
267 m68k_context * vdp_port_write(uint32_t vdp_port, m68k_context * context, uint16_t value) |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
268 { |
343
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
269 if (vdp_port & 0x2700E0) { |
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
270 printf("machine freeze due to write to address %X\n", 0xC00000 | vdp_port); |
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
271 exit(1); |
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
272 } |
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
273 vdp_port &= 0x1F; |
88
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
274 //printf("vdp_port write: %X, value: %X, cycle: %d\n", vdp_port, value, context->current_cycle); |
198
209a37eed3e7
Add support for breaking into the debugger while game is running
Mike Pavone <pavone@retrodev.com>
parents:
197
diff
changeset
|
275 sync_components(context, 0); |
263
2989ed7b8608
Add a second context pointer to m68k_context so that try_fifo_write can still have easy access to the VDP. Handle writes to Z80 code addresses from the 68K.
Mike Pavone <pavone@retrodev.com>
parents:
260
diff
changeset
|
276 vdp_context * v_context = context->video_context; |
88
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
277 if (vdp_port < 0x10) { |
149
139e5dcd6aa3
Make writes to control and data port block when DMA is in progress
Mike Pavone <pavone@retrodev.com>
parents:
144
diff
changeset
|
278 int blocked; |
345
29d2ca563499
Don't sync the 68K clock to the VDP clock unless the 68K had to wait for the VDP. This unfortunately breaks the direct color DMA demos, but should be more correct overall.
Mike Pavone <pavone@retrodev.com>
parents:
344
diff
changeset
|
279 uint32_t before_cycle = v_context->cycles; |
88
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
280 if (vdp_port < 4) { |
149
139e5dcd6aa3
Make writes to control and data port block when DMA is in progress
Mike Pavone <pavone@retrodev.com>
parents:
144
diff
changeset
|
281 while (vdp_data_port_write(v_context, value) < 0) { |
88
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
282 while(v_context->flags & FLAG_DMA_RUN) { |
342
13f994c88c34
Get frame time correct and frame rate sort of correct for EUR region
Mike Pavone <pavone@retrodev.com>
parents:
341
diff
changeset
|
283 vdp_run_dma_done(v_context, mclks_per_frame); |
13f994c88c34
Get frame time correct and frame rate sort of correct for EUR region
Mike Pavone <pavone@retrodev.com>
parents:
341
diff
changeset
|
284 if (v_context->cycles >= mclks_per_frame) { |
215
2b1c2c28b261
Added headless flag to avoid initializing SDL and opening a window when running tests.
Mike Pavone <pavone@retrodev.com>
parents:
211
diff
changeset
|
285 if (!headless) { |
338
5c34a9c39394
Re-enable frame limit, but add a command line flag to disable it
Mike Pavone <pavone@retrodev.com>
parents:
336
diff
changeset
|
286 wait_render_frame(v_context, frame_limit); |
215
2b1c2c28b261
Added headless flag to avoid initializing SDL and opening a window when running tests.
Mike Pavone <pavone@retrodev.com>
parents:
211
diff
changeset
|
287 } |
342
13f994c88c34
Get frame time correct and frame rate sort of correct for EUR region
Mike Pavone <pavone@retrodev.com>
parents:
341
diff
changeset
|
288 vdp_adjust_cycles(v_context, mclks_per_frame); |
13f994c88c34
Get frame time correct and frame rate sort of correct for EUR region
Mike Pavone <pavone@retrodev.com>
parents:
341
diff
changeset
|
289 io_adjust_cycles(&gamepad_1, v_context->cycles/MCLKS_PER_68K, mclks_per_frame/MCLKS_PER_68K); |
13f994c88c34
Get frame time correct and frame rate sort of correct for EUR region
Mike Pavone <pavone@retrodev.com>
parents:
341
diff
changeset
|
290 io_adjust_cycles(&gamepad_2, v_context->cycles/MCLKS_PER_68K, mclks_per_frame/MCLKS_PER_68K); |
344
b46771135442
Handle busack across frame boundary
Mike Pavone <pavone@retrodev.com>
parents:
343
diff
changeset
|
291 if (busack_cycle != CYCLE_NEVER) { |
b46771135442
Handle busack across frame boundary
Mike Pavone <pavone@retrodev.com>
parents:
343
diff
changeset
|
292 if (busack_cycle > mclks_per_frame/MCLKS_PER_68K) { |
b46771135442
Handle busack across frame boundary
Mike Pavone <pavone@retrodev.com>
parents:
343
diff
changeset
|
293 busack_cycle -= mclks_per_frame/MCLKS_PER_68K; |
b46771135442
Handle busack across frame boundary
Mike Pavone <pavone@retrodev.com>
parents:
343
diff
changeset
|
294 } else { |
b46771135442
Handle busack across frame boundary
Mike Pavone <pavone@retrodev.com>
parents:
343
diff
changeset
|
295 busack_cycle = CYCLE_NEVER; |
b46771135442
Handle busack across frame boundary
Mike Pavone <pavone@retrodev.com>
parents:
343
diff
changeset
|
296 busack = new_busack; |
b46771135442
Handle busack across frame boundary
Mike Pavone <pavone@retrodev.com>
parents:
343
diff
changeset
|
297 } |
b46771135442
Handle busack across frame boundary
Mike Pavone <pavone@retrodev.com>
parents:
343
diff
changeset
|
298 } |
88
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
299 } |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
300 } |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
301 context->current_cycle = v_context->cycles / MCLKS_PER_68K; |
149
139e5dcd6aa3
Make writes to control and data port block when DMA is in progress
Mike Pavone <pavone@retrodev.com>
parents:
144
diff
changeset
|
302 } |
139e5dcd6aa3
Make writes to control and data port block when DMA is in progress
Mike Pavone <pavone@retrodev.com>
parents:
144
diff
changeset
|
303 } else if(vdp_port < 8) { |
139e5dcd6aa3
Make writes to control and data port block when DMA is in progress
Mike Pavone <pavone@retrodev.com>
parents:
144
diff
changeset
|
304 blocked = vdp_control_port_write(v_context, value); |
139e5dcd6aa3
Make writes to control and data port block when DMA is in progress
Mike Pavone <pavone@retrodev.com>
parents:
144
diff
changeset
|
305 if (blocked) { |
139e5dcd6aa3
Make writes to control and data port block when DMA is in progress
Mike Pavone <pavone@retrodev.com>
parents:
144
diff
changeset
|
306 while (blocked) { |
139e5dcd6aa3
Make writes to control and data port block when DMA is in progress
Mike Pavone <pavone@retrodev.com>
parents:
144
diff
changeset
|
307 while(v_context->flags & FLAG_DMA_RUN) { |
342
13f994c88c34
Get frame time correct and frame rate sort of correct for EUR region
Mike Pavone <pavone@retrodev.com>
parents:
341
diff
changeset
|
308 vdp_run_dma_done(v_context, mclks_per_frame); |
13f994c88c34
Get frame time correct and frame rate sort of correct for EUR region
Mike Pavone <pavone@retrodev.com>
parents:
341
diff
changeset
|
309 if (v_context->cycles >= mclks_per_frame) { |
215
2b1c2c28b261
Added headless flag to avoid initializing SDL and opening a window when running tests.
Mike Pavone <pavone@retrodev.com>
parents:
211
diff
changeset
|
310 if (!headless) { |
338
5c34a9c39394
Re-enable frame limit, but add a command line flag to disable it
Mike Pavone <pavone@retrodev.com>
parents:
336
diff
changeset
|
311 wait_render_frame(v_context, frame_limit); |
215
2b1c2c28b261
Added headless flag to avoid initializing SDL and opening a window when running tests.
Mike Pavone <pavone@retrodev.com>
parents:
211
diff
changeset
|
312 } |
342
13f994c88c34
Get frame time correct and frame rate sort of correct for EUR region
Mike Pavone <pavone@retrodev.com>
parents:
341
diff
changeset
|
313 vdp_adjust_cycles(v_context, mclks_per_frame); |
13f994c88c34
Get frame time correct and frame rate sort of correct for EUR region
Mike Pavone <pavone@retrodev.com>
parents:
341
diff
changeset
|
314 io_adjust_cycles(&gamepad_1, v_context->cycles/MCLKS_PER_68K, mclks_per_frame/MCLKS_PER_68K); |
13f994c88c34
Get frame time correct and frame rate sort of correct for EUR region
Mike Pavone <pavone@retrodev.com>
parents:
341
diff
changeset
|
315 io_adjust_cycles(&gamepad_2, v_context->cycles/MCLKS_PER_68K, mclks_per_frame/MCLKS_PER_68K); |
344
b46771135442
Handle busack across frame boundary
Mike Pavone <pavone@retrodev.com>
parents:
343
diff
changeset
|
316 if (busack_cycle != CYCLE_NEVER) { |
b46771135442
Handle busack across frame boundary
Mike Pavone <pavone@retrodev.com>
parents:
343
diff
changeset
|
317 if (busack_cycle > mclks_per_frame/MCLKS_PER_68K) { |
b46771135442
Handle busack across frame boundary
Mike Pavone <pavone@retrodev.com>
parents:
343
diff
changeset
|
318 busack_cycle -= mclks_per_frame/MCLKS_PER_68K; |
b46771135442
Handle busack across frame boundary
Mike Pavone <pavone@retrodev.com>
parents:
343
diff
changeset
|
319 } else { |
b46771135442
Handle busack across frame boundary
Mike Pavone <pavone@retrodev.com>
parents:
343
diff
changeset
|
320 busack_cycle = CYCLE_NEVER; |
b46771135442
Handle busack across frame boundary
Mike Pavone <pavone@retrodev.com>
parents:
343
diff
changeset
|
321 busack = new_busack; |
b46771135442
Handle busack across frame boundary
Mike Pavone <pavone@retrodev.com>
parents:
343
diff
changeset
|
322 } |
b46771135442
Handle busack across frame boundary
Mike Pavone <pavone@retrodev.com>
parents:
343
diff
changeset
|
323 } |
149
139e5dcd6aa3
Make writes to control and data port block when DMA is in progress
Mike Pavone <pavone@retrodev.com>
parents:
144
diff
changeset
|
324 } |
139e5dcd6aa3
Make writes to control and data port block when DMA is in progress
Mike Pavone <pavone@retrodev.com>
parents:
144
diff
changeset
|
325 } |
139e5dcd6aa3
Make writes to control and data port block when DMA is in progress
Mike Pavone <pavone@retrodev.com>
parents:
144
diff
changeset
|
326 if (blocked < 0) { |
139e5dcd6aa3
Make writes to control and data port block when DMA is in progress
Mike Pavone <pavone@retrodev.com>
parents:
144
diff
changeset
|
327 blocked = vdp_control_port_write(v_context, value); |
139e5dcd6aa3
Make writes to control and data port block when DMA is in progress
Mike Pavone <pavone@retrodev.com>
parents:
144
diff
changeset
|
328 } else { |
139e5dcd6aa3
Make writes to control and data port block when DMA is in progress
Mike Pavone <pavone@retrodev.com>
parents:
144
diff
changeset
|
329 blocked = 0; |
139e5dcd6aa3
Make writes to control and data port block when DMA is in progress
Mike Pavone <pavone@retrodev.com>
parents:
144
diff
changeset
|
330 } |
139e5dcd6aa3
Make writes to control and data port block when DMA is in progress
Mike Pavone <pavone@retrodev.com>
parents:
144
diff
changeset
|
331 } |
139e5dcd6aa3
Make writes to control and data port block when DMA is in progress
Mike Pavone <pavone@retrodev.com>
parents:
144
diff
changeset
|
332 context->current_cycle = v_context->cycles / MCLKS_PER_68K; |
88
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
333 } else { |
186
02e25abe2dcd
Cleanup VINT code and fix bug in which VINT cycle would be set incorrectly after a VDP control port write
Mike Pavone <pavone@retrodev.com>
parents:
185
diff
changeset
|
334 adjust_int_cycle(context, v_context); |
88
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
335 } |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
336 } else { |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
337 printf("Illegal write to HV Counter port %X\n", vdp_port); |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
338 exit(1); |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
339 } |
345
29d2ca563499
Don't sync the 68K clock to the VDP clock unless the 68K had to wait for the VDP. This unfortunately breaks the direct color DMA demos, but should be more correct overall.
Mike Pavone <pavone@retrodev.com>
parents:
344
diff
changeset
|
340 if (v_context->cycles != before_cycle) { |
29d2ca563499
Don't sync the 68K clock to the VDP clock unless the 68K had to wait for the VDP. This unfortunately breaks the direct color DMA demos, but should be more correct overall.
Mike Pavone <pavone@retrodev.com>
parents:
344
diff
changeset
|
341 context->current_cycle = v_context->cycles / MCLKS_PER_68K; |
29d2ca563499
Don't sync the 68K clock to the VDP clock unless the 68K had to wait for the VDP. This unfortunately breaks the direct color DMA demos, but should be more correct overall.
Mike Pavone <pavone@retrodev.com>
parents:
344
diff
changeset
|
342 } |
88
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
343 } else if (vdp_port < 0x18) { |
354
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
351
diff
changeset
|
344 genesis_context * gen = context->system; |
380
1c8d74f2ab0b
Make the PSG and YM2612 use the master clock internal with an increment based on clock divider so that they stay perflectly in sync. Run both the PSG and YM2612 whenver one of them needs to be run.
Mike Pavone <pavone@retrodev.com>
parents:
374
diff
changeset
|
345 sync_sound(gen, context->current_cycle * MCLKS_PER_68K); |
354
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
351
diff
changeset
|
346 psg_write(gen->psg, value); |
88
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
347 } else { |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
348 //TODO: Implement undocumented test register(s) |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
349 } |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
350 return context; |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
351 } |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
352 |
343
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
353 m68k_context * vdp_port_write_b(uint32_t vdp_port, m68k_context * context, uint8_t value) |
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
354 { |
357
fa7ea48be9a9
Allow VDP/PSG writes from Z80
Mike Pavone <pavone@retrodev.com>
parents:
356
diff
changeset
|
355 return vdp_port_write(vdp_port, context, vdp_port < 0x10 ? value | value << 8 : ((vdp_port & 1) ? value : 0)); |
fa7ea48be9a9
Allow VDP/PSG writes from Z80
Mike Pavone <pavone@retrodev.com>
parents:
356
diff
changeset
|
356 } |
fa7ea48be9a9
Allow VDP/PSG writes from Z80
Mike Pavone <pavone@retrodev.com>
parents:
356
diff
changeset
|
357 |
fa7ea48be9a9
Allow VDP/PSG writes from Z80
Mike Pavone <pavone@retrodev.com>
parents:
356
diff
changeset
|
358 z80_context * z80_vdp_port_write(uint16_t vdp_port, z80_context * context, uint8_t value) |
fa7ea48be9a9
Allow VDP/PSG writes from Z80
Mike Pavone <pavone@retrodev.com>
parents:
356
diff
changeset
|
359 { |
fa7ea48be9a9
Allow VDP/PSG writes from Z80
Mike Pavone <pavone@retrodev.com>
parents:
356
diff
changeset
|
360 genesis_context * gen = context->system; |
358
9498cfa7f7c8
Make Z80 writes to VDP/PSG not potentially crash the emulator
Mike Pavone <pavone@retrodev.com>
parents:
357
diff
changeset
|
361 if (vdp_port & 0xE0) { |
9498cfa7f7c8
Make Z80 writes to VDP/PSG not potentially crash the emulator
Mike Pavone <pavone@retrodev.com>
parents:
357
diff
changeset
|
362 printf("machine freeze due to write to Z80 address %X\n", 0x7F00 | vdp_port); |
9498cfa7f7c8
Make Z80 writes to VDP/PSG not potentially crash the emulator
Mike Pavone <pavone@retrodev.com>
parents:
357
diff
changeset
|
363 exit(1); |
9498cfa7f7c8
Make Z80 writes to VDP/PSG not potentially crash the emulator
Mike Pavone <pavone@retrodev.com>
parents:
357
diff
changeset
|
364 } |
9498cfa7f7c8
Make Z80 writes to VDP/PSG not potentially crash the emulator
Mike Pavone <pavone@retrodev.com>
parents:
357
diff
changeset
|
365 if (vdp_port < 0x10) { |
9498cfa7f7c8
Make Z80 writes to VDP/PSG not potentially crash the emulator
Mike Pavone <pavone@retrodev.com>
parents:
357
diff
changeset
|
366 //These probably won't currently interact well with the 68K accessing the VDP |
9498cfa7f7c8
Make Z80 writes to VDP/PSG not potentially crash the emulator
Mike Pavone <pavone@retrodev.com>
parents:
357
diff
changeset
|
367 vdp_run_context(gen->vdp, context->current_cycle * MCLKS_PER_Z80); |
9498cfa7f7c8
Make Z80 writes to VDP/PSG not potentially crash the emulator
Mike Pavone <pavone@retrodev.com>
parents:
357
diff
changeset
|
368 if (vdp_port < 4) { |
9498cfa7f7c8
Make Z80 writes to VDP/PSG not potentially crash the emulator
Mike Pavone <pavone@retrodev.com>
parents:
357
diff
changeset
|
369 vdp_data_port_write(gen->vdp, value << 8 | value); |
9498cfa7f7c8
Make Z80 writes to VDP/PSG not potentially crash the emulator
Mike Pavone <pavone@retrodev.com>
parents:
357
diff
changeset
|
370 } else if (vdp_port < 8) { |
9498cfa7f7c8
Make Z80 writes to VDP/PSG not potentially crash the emulator
Mike Pavone <pavone@retrodev.com>
parents:
357
diff
changeset
|
371 vdp_control_port_write(gen->vdp, value << 8 | value); |
9498cfa7f7c8
Make Z80 writes to VDP/PSG not potentially crash the emulator
Mike Pavone <pavone@retrodev.com>
parents:
357
diff
changeset
|
372 } else { |
9498cfa7f7c8
Make Z80 writes to VDP/PSG not potentially crash the emulator
Mike Pavone <pavone@retrodev.com>
parents:
357
diff
changeset
|
373 printf("Illegal write to HV Counter port %X\n", vdp_port); |
9498cfa7f7c8
Make Z80 writes to VDP/PSG not potentially crash the emulator
Mike Pavone <pavone@retrodev.com>
parents:
357
diff
changeset
|
374 exit(1); |
9498cfa7f7c8
Make Z80 writes to VDP/PSG not potentially crash the emulator
Mike Pavone <pavone@retrodev.com>
parents:
357
diff
changeset
|
375 } |
9498cfa7f7c8
Make Z80 writes to VDP/PSG not potentially crash the emulator
Mike Pavone <pavone@retrodev.com>
parents:
357
diff
changeset
|
376 } else if (vdp_port < 0x18) { |
380
1c8d74f2ab0b
Make the PSG and YM2612 use the master clock internal with an increment based on clock divider so that they stay perflectly in sync. Run both the PSG and YM2612 whenver one of them needs to be run.
Mike Pavone <pavone@retrodev.com>
parents:
374
diff
changeset
|
377 sync_sound(gen, context->current_cycle * MCLKS_PER_Z80); |
358
9498cfa7f7c8
Make Z80 writes to VDP/PSG not potentially crash the emulator
Mike Pavone <pavone@retrodev.com>
parents:
357
diff
changeset
|
378 psg_write(gen->psg, value); |
9498cfa7f7c8
Make Z80 writes to VDP/PSG not potentially crash the emulator
Mike Pavone <pavone@retrodev.com>
parents:
357
diff
changeset
|
379 } else { |
9498cfa7f7c8
Make Z80 writes to VDP/PSG not potentially crash the emulator
Mike Pavone <pavone@retrodev.com>
parents:
357
diff
changeset
|
380 //TODO: Implement undocumented test register(s) |
9498cfa7f7c8
Make Z80 writes to VDP/PSG not potentially crash the emulator
Mike Pavone <pavone@retrodev.com>
parents:
357
diff
changeset
|
381 } |
357
fa7ea48be9a9
Allow VDP/PSG writes from Z80
Mike Pavone <pavone@retrodev.com>
parents:
356
diff
changeset
|
382 return context; |
343
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
383 } |
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
384 |
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
385 uint16_t vdp_port_read(uint32_t vdp_port, m68k_context * context) |
88
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
386 { |
343
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
387 if (vdp_port & 0x2700E0) { |
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
388 printf("machine freeze due to read from address %X\n", 0xC00000 | vdp_port); |
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
389 exit(1); |
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
390 } |
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
391 vdp_port &= 0x1F; |
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
392 uint16_t value; |
198
209a37eed3e7
Add support for breaking into the debugger while game is running
Mike Pavone <pavone@retrodev.com>
parents:
197
diff
changeset
|
393 sync_components(context, 0); |
263
2989ed7b8608
Add a second context pointer to m68k_context so that try_fifo_write can still have easy access to the VDP. Handle writes to Z80 code addresses from the 68K.
Mike Pavone <pavone@retrodev.com>
parents:
260
diff
changeset
|
394 vdp_context * v_context = context->video_context; |
88
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
395 if (vdp_port < 0x10) { |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
396 if (vdp_port < 4) { |
343
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
397 value = vdp_data_port_read(v_context); |
88
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
398 } else if(vdp_port < 8) { |
343
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
399 value = vdp_control_port_read(v_context); |
88
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
400 } else { |
343
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
401 value = vdp_hv_counter_read(v_context); |
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
402 //printf("HV Counter: %X at cycle %d\n", value, v_context->cycles); |
88
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
403 } |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
404 context->current_cycle = v_context->cycles/MCLKS_PER_68K; |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
405 } else { |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
406 printf("Illegal read from PSG or test register port %X\n", vdp_port); |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
407 exit(1); |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
408 } |
343
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
409 return value; |
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
410 } |
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
411 |
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
412 uint8_t vdp_port_read_b(uint32_t vdp_port, m68k_context * context) |
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
413 { |
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
414 uint16_t value = vdp_port_read(vdp_port, context); |
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
415 if (vdp_port & 1) { |
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
416 return value; |
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
417 } else { |
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
418 return value >> 8; |
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
419 } |
88
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
420 } |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
421 |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
422 #define TH 0x40 |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
423 #define TH_TIMEOUT 8000 |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
424 |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
425 void io_adjust_cycles(io_port * pad, uint32_t current_cycle, uint32_t deduction) |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
426 { |
89
9757b4c6c33f
Minor joypad fix and commeount out some debug printfs
Mike Pavone <pavone@retrodev.com>
parents:
88
diff
changeset
|
427 /*uint8_t control = pad->control | 0x80; |
88
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
428 uint8_t th = control & pad->output; |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
429 if (pad->input[GAMEPAD_TH0] || pad->input[GAMEPAD_TH1]) { |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
430 printf("adjust_cycles | control: %X, TH: %X, GAMEPAD_TH0: %X, GAMEPAD_TH1: %X, TH Counter: %d, Timeout: %d, Cycle: %d\n", control, th, pad->input[GAMEPAD_TH0], pad->input[GAMEPAD_TH1], pad->th_counter,pad->timeout_cycle, current_cycle); |
89
9757b4c6c33f
Minor joypad fix and commeount out some debug printfs
Mike Pavone <pavone@retrodev.com>
parents:
88
diff
changeset
|
431 }*/ |
88
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
432 if (current_cycle >= pad->timeout_cycle) { |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
433 pad->th_counter = 0; |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
434 } else { |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
435 pad->timeout_cycle -= deduction; |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
436 } |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
437 if (busack_cycle < CYCLE_NEVER && current_cycle < busack_cycle) { |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
438 busack_cycle -= deduction; |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
439 } |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
440 } |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
441 |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
442 void io_data_write(io_port * pad, m68k_context * context, uint8_t value) |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
443 { |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
444 if (pad->control & TH) { |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
445 //check if TH has changed |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
446 if ((pad->output & TH) ^ (value & TH)) { |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
447 if (context->current_cycle >= pad->timeout_cycle) { |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
448 pad->th_counter = 0; |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
449 } |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
450 if (!(value & TH)) { |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
451 pad->th_counter++; |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
452 } |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
453 pad->timeout_cycle = context->current_cycle + TH_TIMEOUT; |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
454 } |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
455 } |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
456 pad->output = value; |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
457 } |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
458 |
343
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
459 uint8_t io_data_read(io_port * pad, m68k_context * context) |
88
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
460 { |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
461 uint8_t control = pad->control | 0x80; |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
462 uint8_t th = control & pad->output; |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
463 uint8_t input; |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
464 if (context->current_cycle >= pad->timeout_cycle) { |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
465 pad->th_counter = 0; |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
466 } |
89
9757b4c6c33f
Minor joypad fix and commeount out some debug printfs
Mike Pavone <pavone@retrodev.com>
parents:
88
diff
changeset
|
467 /*if (pad->input[GAMEPAD_TH0] || pad->input[GAMEPAD_TH1]) { |
88
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
468 printf("io_data_read | control: %X, TH: %X, GAMEPAD_TH0: %X, GAMEPAD_TH1: %X, TH Counter: %d, Timeout: %d, Cycle: %d\n", control, th, pad->input[GAMEPAD_TH0], pad->input[GAMEPAD_TH1], pad->th_counter,pad->timeout_cycle, context->current_cycle); |
89
9757b4c6c33f
Minor joypad fix and commeount out some debug printfs
Mike Pavone <pavone@retrodev.com>
parents:
88
diff
changeset
|
469 }*/ |
88
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
470 if (th) { |
195
c615061f7914
Fix 6-button controller emulation
Mike Pavone <pavone@retrodev.com>
parents:
186
diff
changeset
|
471 if (pad->th_counter == 3) { |
88
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
472 input = pad->input[GAMEPAD_EXTRA]; |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
473 } else { |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
474 input = pad->input[GAMEPAD_TH1]; |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
475 } |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
476 } else { |
195
c615061f7914
Fix 6-button controller emulation
Mike Pavone <pavone@retrodev.com>
parents:
186
diff
changeset
|
477 if (pad->th_counter == 3) { |
88
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
478 input = pad->input[GAMEPAD_TH0] | 0xF; |
195
c615061f7914
Fix 6-button controller emulation
Mike Pavone <pavone@retrodev.com>
parents:
186
diff
changeset
|
479 } else if(pad->th_counter == 4) { |
88
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
480 input = pad->input[GAMEPAD_TH0] & 0x30; |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
481 } else { |
89
9757b4c6c33f
Minor joypad fix and commeount out some debug printfs
Mike Pavone <pavone@retrodev.com>
parents:
88
diff
changeset
|
482 input = pad->input[GAMEPAD_TH0] | 0xC; |
88
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
483 } |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
484 } |
343
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
485 uint8_t value = ((~input) & (~control)) | (pad->output & control); |
88
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
486 /*if (pad->input[GAMEPAD_TH0] || pad->input[GAMEPAD_TH1]) { |
343
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
487 printf ("value: %X\n", value); |
88
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
488 }*/ |
343
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
489 return value; |
88
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
490 } |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
491 |
279
6be6056735a9
Fix native address lookup in bannked memory area
Mike Pavone <pavone@retrodev.com>
parents:
276
diff
changeset
|
492 uint32_t zram_counter = 0; |
289
1cc0850ab6bc
Hopefully more correct implementation of the Z80 busack status
Mike Pavone <pavone@retrodev.com>
parents:
288
diff
changeset
|
493 #define Z80_ACK_DELAY 3 |
336
87b65e5ce1ab
Fix a stupid bug in z80 busreq acknowledge delay code and make some small improvements there too
Mike Pavone <pavone@retrodev.com>
parents:
335
diff
changeset
|
494 #define Z80_BUSY_DELAY 1//TODO: Find the actual value for this |
289
1cc0850ab6bc
Hopefully more correct implementation of the Z80 busack status
Mike Pavone <pavone@retrodev.com>
parents:
288
diff
changeset
|
495 #define Z80_REQ_BUSY 1 |
1cc0850ab6bc
Hopefully more correct implementation of the Z80 busack status
Mike Pavone <pavone@retrodev.com>
parents:
288
diff
changeset
|
496 #define Z80_REQ_ACK 0 |
1cc0850ab6bc
Hopefully more correct implementation of the Z80 busack status
Mike Pavone <pavone@retrodev.com>
parents:
288
diff
changeset
|
497 #define Z80_RES_BUSACK reset |
279
6be6056735a9
Fix native address lookup in bannked memory area
Mike Pavone <pavone@retrodev.com>
parents:
276
diff
changeset
|
498 |
88
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
499 m68k_context * io_write(uint32_t location, m68k_context * context, uint8_t value) |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
500 { |
288
a8ee7934a1f8
Add a YM2612 stub implementation with just timers and status registers so that games that depend on it can run.
Mike Pavone <pavone@retrodev.com>
parents:
280
diff
changeset
|
501 genesis_context * gen = context->system; |
153
42c031184e8a
Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents:
149
diff
changeset
|
502 if (location < 0x10000) { |
336
87b65e5ce1ab
Fix a stupid bug in z80 busreq acknowledge delay code and make some small improvements there too
Mike Pavone <pavone@retrodev.com>
parents:
335
diff
changeset
|
503 if (busack_cycle <= context->current_cycle) { |
153
42c031184e8a
Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents:
149
diff
changeset
|
504 busack = new_busack; |
42c031184e8a
Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents:
149
diff
changeset
|
505 busack_cycle = CYCLE_NEVER; |
42c031184e8a
Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents:
149
diff
changeset
|
506 } |
42c031184e8a
Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents:
149
diff
changeset
|
507 if (!(busack || reset)) { |
42c031184e8a
Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents:
149
diff
changeset
|
508 location &= 0x7FFF; |
42c031184e8a
Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents:
149
diff
changeset
|
509 if (location < 0x4000) { |
42c031184e8a
Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents:
149
diff
changeset
|
510 z80_ram[location & 0x1FFF] = value; |
288
a8ee7934a1f8
Add a YM2612 stub implementation with just timers and status registers so that games that depend on it can run.
Mike Pavone <pavone@retrodev.com>
parents:
280
diff
changeset
|
511 z80_handle_code_write(location & 0x1FFF, gen->z80); |
a8ee7934a1f8
Add a YM2612 stub implementation with just timers and status registers so that games that depend on it can run.
Mike Pavone <pavone@retrodev.com>
parents:
280
diff
changeset
|
512 } else if (location < 0x6000) { |
380
1c8d74f2ab0b
Make the PSG and YM2612 use the master clock internal with an increment based on clock divider so that they stay perflectly in sync. Run both the PSG and YM2612 whenver one of them needs to be run.
Mike Pavone <pavone@retrodev.com>
parents:
374
diff
changeset
|
513 sync_sound(gen, context->current_cycle * MCLKS_PER_68K); |
288
a8ee7934a1f8
Add a YM2612 stub implementation with just timers and status registers so that games that depend on it can run.
Mike Pavone <pavone@retrodev.com>
parents:
280
diff
changeset
|
514 if (location & 1) { |
a8ee7934a1f8
Add a YM2612 stub implementation with just timers and status registers so that games that depend on it can run.
Mike Pavone <pavone@retrodev.com>
parents:
280
diff
changeset
|
515 ym_data_write(gen->ym, value); |
a8ee7934a1f8
Add a YM2612 stub implementation with just timers and status registers so that games that depend on it can run.
Mike Pavone <pavone@retrodev.com>
parents:
280
diff
changeset
|
516 } else if(location & 2) { |
a8ee7934a1f8
Add a YM2612 stub implementation with just timers and status registers so that games that depend on it can run.
Mike Pavone <pavone@retrodev.com>
parents:
280
diff
changeset
|
517 ym_address_write_part2(gen->ym, value); |
a8ee7934a1f8
Add a YM2612 stub implementation with just timers and status registers so that games that depend on it can run.
Mike Pavone <pavone@retrodev.com>
parents:
280
diff
changeset
|
518 } else { |
a8ee7934a1f8
Add a YM2612 stub implementation with just timers and status registers so that games that depend on it can run.
Mike Pavone <pavone@retrodev.com>
parents:
280
diff
changeset
|
519 ym_address_write_part1(gen->ym, value); |
a8ee7934a1f8
Add a YM2612 stub implementation with just timers and status registers so that games that depend on it can run.
Mike Pavone <pavone@retrodev.com>
parents:
280
diff
changeset
|
520 } |
395
0b5f93358a93
Add debugger command for saving Z80 RAM to a file
Mike Pavone <pavone@retrodev.com>
parents:
392
diff
changeset
|
521 } else { |
0b5f93358a93
Add debugger command for saving Z80 RAM to a file
Mike Pavone <pavone@retrodev.com>
parents:
392
diff
changeset
|
522 printf("68K write to unhandled Z80 address %X\n", location); |
0b5f93358a93
Add debugger command for saving Z80 RAM to a file
Mike Pavone <pavone@retrodev.com>
parents:
392
diff
changeset
|
523 exit(1); |
153
42c031184e8a
Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents:
149
diff
changeset
|
524 } |
88
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
525 } |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
526 } else { |
153
42c031184e8a
Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents:
149
diff
changeset
|
527 location &= 0x1FFF; |
42c031184e8a
Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents:
149
diff
changeset
|
528 if (location < 0x100) { |
42c031184e8a
Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents:
149
diff
changeset
|
529 switch(location/2) |
42c031184e8a
Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents:
149
diff
changeset
|
530 { |
42c031184e8a
Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents:
149
diff
changeset
|
531 case 0x1: |
42c031184e8a
Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents:
149
diff
changeset
|
532 io_data_write(&gamepad_1, context, value); |
42c031184e8a
Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents:
149
diff
changeset
|
533 break; |
42c031184e8a
Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents:
149
diff
changeset
|
534 case 0x2: |
42c031184e8a
Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents:
149
diff
changeset
|
535 io_data_write(&gamepad_2, context, value); |
42c031184e8a
Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents:
149
diff
changeset
|
536 break; |
42c031184e8a
Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents:
149
diff
changeset
|
537 case 0x3://PORT C Data |
42c031184e8a
Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents:
149
diff
changeset
|
538 break; |
42c031184e8a
Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents:
149
diff
changeset
|
539 case 0x4: |
42c031184e8a
Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents:
149
diff
changeset
|
540 gamepad_1.control = value; |
42c031184e8a
Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents:
149
diff
changeset
|
541 break; |
42c031184e8a
Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents:
149
diff
changeset
|
542 case 0x5: |
42c031184e8a
Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents:
149
diff
changeset
|
543 gamepad_2.control = value; |
42c031184e8a
Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents:
149
diff
changeset
|
544 break; |
88
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
545 } |
153
42c031184e8a
Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents:
149
diff
changeset
|
546 } else { |
42c031184e8a
Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents:
149
diff
changeset
|
547 if (location == 0x1100) { |
288
a8ee7934a1f8
Add a YM2612 stub implementation with just timers and status registers so that games that depend on it can run.
Mike Pavone <pavone@retrodev.com>
parents:
280
diff
changeset
|
548 sync_z80(gen->z80, context->current_cycle * MCLKS_PER_68K); |
336
87b65e5ce1ab
Fix a stupid bug in z80 busreq acknowledge delay code and make some small improvements there too
Mike Pavone <pavone@retrodev.com>
parents:
335
diff
changeset
|
549 if (busack_cycle <= context->current_cycle) { |
153
42c031184e8a
Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents:
149
diff
changeset
|
550 busack = new_busack; |
42c031184e8a
Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents:
149
diff
changeset
|
551 busack_cycle = CYCLE_NEVER; |
88
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
552 } |
153
42c031184e8a
Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents:
149
diff
changeset
|
553 if (value & 1) { |
271
969ee17471c5
Protect debug prints for busreq/reset regs with appropriate macros
Mike Pavone <pavone@retrodev.com>
parents:
268
diff
changeset
|
554 dputs("bus requesting Z80"); |
336
87b65e5ce1ab
Fix a stupid bug in z80 busreq acknowledge delay code and make some small improvements there too
Mike Pavone <pavone@retrodev.com>
parents:
335
diff
changeset
|
555 |
87b65e5ce1ab
Fix a stupid bug in z80 busreq acknowledge delay code and make some small improvements there too
Mike Pavone <pavone@retrodev.com>
parents:
335
diff
changeset
|
556 if(!reset && !busreq) { |
289
1cc0850ab6bc
Hopefully more correct implementation of the Z80 busack status
Mike Pavone <pavone@retrodev.com>
parents:
288
diff
changeset
|
557 busack_cycle = ((gen->z80->current_cycle + Z80_ACK_DELAY) * MCLKS_PER_Z80) / MCLKS_PER_68K;//context->current_cycle + Z80_ACK_DELAY; |
1cc0850ab6bc
Hopefully more correct implementation of the Z80 busack status
Mike Pavone <pavone@retrodev.com>
parents:
288
diff
changeset
|
558 new_busack = Z80_REQ_ACK; |
153
42c031184e8a
Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents:
149
diff
changeset
|
559 } |
364
62177cc39049
Incredibly broken YM2612 support plus a fix to Z80 bus request
Mike Pavone <pavone@retrodev.com>
parents:
362
diff
changeset
|
560 busreq = 1; |
153
42c031184e8a
Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents:
149
diff
changeset
|
561 } else { |
260
625f8e4d5fd2
Initial stab at integartiong Z80 core
Mike Pavone <pavone@retrodev.com>
parents:
215
diff
changeset
|
562 if (busreq) { |
271
969ee17471c5
Protect debug prints for busreq/reset regs with appropriate macros
Mike Pavone <pavone@retrodev.com>
parents:
268
diff
changeset
|
563 dputs("releasing z80 bus"); |
280 | 564 #ifdef DO_DEBUG_PRINT |
279
6be6056735a9
Fix native address lookup in bannked memory area
Mike Pavone <pavone@retrodev.com>
parents:
276
diff
changeset
|
565 char fname[20]; |
6be6056735a9
Fix native address lookup in bannked memory area
Mike Pavone <pavone@retrodev.com>
parents:
276
diff
changeset
|
566 sprintf(fname, "zram-%d", zram_counter++); |
6be6056735a9
Fix native address lookup in bannked memory area
Mike Pavone <pavone@retrodev.com>
parents:
276
diff
changeset
|
567 FILE * f = fopen(fname, "wb"); |
6be6056735a9
Fix native address lookup in bannked memory area
Mike Pavone <pavone@retrodev.com>
parents:
276
diff
changeset
|
568 fwrite(z80_ram, 1, sizeof(z80_ram), f); |
6be6056735a9
Fix native address lookup in bannked memory area
Mike Pavone <pavone@retrodev.com>
parents:
276
diff
changeset
|
569 fclose(f); |
280 | 570 #endif |
336
87b65e5ce1ab
Fix a stupid bug in z80 busreq acknowledge delay code and make some small improvements there too
Mike Pavone <pavone@retrodev.com>
parents:
335
diff
changeset
|
571 busack_cycle = ((gen->z80->current_cycle + Z80_BUSY_DELAY) * MCLKS_PER_Z80) / MCLKS_PER_68K; |
87b65e5ce1ab
Fix a stupid bug in z80 busreq acknowledge delay code and make some small improvements there too
Mike Pavone <pavone@retrodev.com>
parents:
335
diff
changeset
|
572 new_busack = Z80_REQ_BUSY; |
87b65e5ce1ab
Fix a stupid bug in z80 busreq acknowledge delay code and make some small improvements there too
Mike Pavone <pavone@retrodev.com>
parents:
335
diff
changeset
|
573 busreq = 0; |
260
625f8e4d5fd2
Initial stab at integartiong Z80 core
Mike Pavone <pavone@retrodev.com>
parents:
215
diff
changeset
|
574 } |
289
1cc0850ab6bc
Hopefully more correct implementation of the Z80 busack status
Mike Pavone <pavone@retrodev.com>
parents:
288
diff
changeset
|
575 //busack_cycle = CYCLE_NEVER; |
1cc0850ab6bc
Hopefully more correct implementation of the Z80 busack status
Mike Pavone <pavone@retrodev.com>
parents:
288
diff
changeset
|
576 //busack = Z80_REQ_BUSY; |
336
87b65e5ce1ab
Fix a stupid bug in z80 busreq acknowledge delay code and make some small improvements there too
Mike Pavone <pavone@retrodev.com>
parents:
335
diff
changeset
|
577 |
88
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
578 } |
153
42c031184e8a
Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents:
149
diff
changeset
|
579 } else if (location == 0x1200) { |
288
a8ee7934a1f8
Add a YM2612 stub implementation with just timers and status registers so that games that depend on it can run.
Mike Pavone <pavone@retrodev.com>
parents:
280
diff
changeset
|
580 sync_z80(gen->z80, context->current_cycle * MCLKS_PER_68K); |
153
42c031184e8a
Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents:
149
diff
changeset
|
581 if (value & 1) { |
42c031184e8a
Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents:
149
diff
changeset
|
582 if (reset && busreq) { |
42c031184e8a
Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents:
149
diff
changeset
|
583 new_busack = 0; |
289
1cc0850ab6bc
Hopefully more correct implementation of the Z80 busack status
Mike Pavone <pavone@retrodev.com>
parents:
288
diff
changeset
|
584 busack_cycle = ((gen->z80->current_cycle + Z80_ACK_DELAY) * MCLKS_PER_Z80) / MCLKS_PER_68K;//context->current_cycle + Z80_ACK_DELAY; |
153
42c031184e8a
Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents:
149
diff
changeset
|
585 } |
260
625f8e4d5fd2
Initial stab at integartiong Z80 core
Mike Pavone <pavone@retrodev.com>
parents:
215
diff
changeset
|
586 //TODO: Deal with the scenario in which reset is not asserted long enough |
625f8e4d5fd2
Initial stab at integartiong Z80 core
Mike Pavone <pavone@retrodev.com>
parents:
215
diff
changeset
|
587 if (reset) { |
625f8e4d5fd2
Initial stab at integartiong Z80 core
Mike Pavone <pavone@retrodev.com>
parents:
215
diff
changeset
|
588 need_reset = 1; |
625f8e4d5fd2
Initial stab at integartiong Z80 core
Mike Pavone <pavone@retrodev.com>
parents:
215
diff
changeset
|
589 //TODO: Add necessary delay between release of reset and start of execution |
288
a8ee7934a1f8
Add a YM2612 stub implementation with just timers and status registers so that games that depend on it can run.
Mike Pavone <pavone@retrodev.com>
parents:
280
diff
changeset
|
590 gen->z80->current_cycle = (context->current_cycle * MCLKS_PER_68K) / MCLKS_PER_Z80; |
260
625f8e4d5fd2
Initial stab at integartiong Z80 core
Mike Pavone <pavone@retrodev.com>
parents:
215
diff
changeset
|
591 } |
153
42c031184e8a
Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents:
149
diff
changeset
|
592 reset = 0; |
42c031184e8a
Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents:
149
diff
changeset
|
593 } else { |
42c031184e8a
Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents:
149
diff
changeset
|
594 reset = 1; |
42c031184e8a
Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents:
149
diff
changeset
|
595 } |
88
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
596 } |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
597 } |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
598 } |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
599 return context; |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
600 } |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
601 |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
602 m68k_context * io_write_w(uint32_t location, m68k_context * context, uint16_t value) |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
603 { |
288
a8ee7934a1f8
Add a YM2612 stub implementation with just timers and status registers so that games that depend on it can run.
Mike Pavone <pavone@retrodev.com>
parents:
280
diff
changeset
|
604 genesis_context * gen = context->system; |
153
42c031184e8a
Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents:
149
diff
changeset
|
605 if (location < 0x10000) { |
336
87b65e5ce1ab
Fix a stupid bug in z80 busreq acknowledge delay code and make some small improvements there too
Mike Pavone <pavone@retrodev.com>
parents:
335
diff
changeset
|
606 if (busack_cycle <= context->current_cycle) { |
153
42c031184e8a
Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents:
149
diff
changeset
|
607 busack = new_busack; |
42c031184e8a
Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents:
149
diff
changeset
|
608 busack_cycle = CYCLE_NEVER; |
42c031184e8a
Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents:
149
diff
changeset
|
609 } |
42c031184e8a
Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents:
149
diff
changeset
|
610 if (!(busack || reset)) { |
42c031184e8a
Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents:
149
diff
changeset
|
611 location &= 0x7FFF; |
42c031184e8a
Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents:
149
diff
changeset
|
612 if (location < 0x4000) { |
42c031184e8a
Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents:
149
diff
changeset
|
613 z80_ram[location & 0x1FFE] = value >> 8; |
288
a8ee7934a1f8
Add a YM2612 stub implementation with just timers and status registers so that games that depend on it can run.
Mike Pavone <pavone@retrodev.com>
parents:
280
diff
changeset
|
614 z80_handle_code_write(location & 0x1FFE, gen->z80); |
a8ee7934a1f8
Add a YM2612 stub implementation with just timers and status registers so that games that depend on it can run.
Mike Pavone <pavone@retrodev.com>
parents:
280
diff
changeset
|
615 } else if (location < 0x6000) { |
380
1c8d74f2ab0b
Make the PSG and YM2612 use the master clock internal with an increment based on clock divider so that they stay perflectly in sync. Run both the PSG and YM2612 whenver one of them needs to be run.
Mike Pavone <pavone@retrodev.com>
parents:
374
diff
changeset
|
616 sync_sound(gen, context->current_cycle * MCLKS_PER_68K); |
288
a8ee7934a1f8
Add a YM2612 stub implementation with just timers and status registers so that games that depend on it can run.
Mike Pavone <pavone@retrodev.com>
parents:
280
diff
changeset
|
617 if (location & 1) { |
a8ee7934a1f8
Add a YM2612 stub implementation with just timers and status registers so that games that depend on it can run.
Mike Pavone <pavone@retrodev.com>
parents:
280
diff
changeset
|
618 ym_data_write(gen->ym, value >> 8); |
a8ee7934a1f8
Add a YM2612 stub implementation with just timers and status registers so that games that depend on it can run.
Mike Pavone <pavone@retrodev.com>
parents:
280
diff
changeset
|
619 } else if(location & 2) { |
a8ee7934a1f8
Add a YM2612 stub implementation with just timers and status registers so that games that depend on it can run.
Mike Pavone <pavone@retrodev.com>
parents:
280
diff
changeset
|
620 ym_address_write_part2(gen->ym, value >> 8); |
a8ee7934a1f8
Add a YM2612 stub implementation with just timers and status registers so that games that depend on it can run.
Mike Pavone <pavone@retrodev.com>
parents:
280
diff
changeset
|
621 } else { |
a8ee7934a1f8
Add a YM2612 stub implementation with just timers and status registers so that games that depend on it can run.
Mike Pavone <pavone@retrodev.com>
parents:
280
diff
changeset
|
622 ym_address_write_part1(gen->ym, value >> 8); |
a8ee7934a1f8
Add a YM2612 stub implementation with just timers and status registers so that games that depend on it can run.
Mike Pavone <pavone@retrodev.com>
parents:
280
diff
changeset
|
623 } |
153
42c031184e8a
Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents:
149
diff
changeset
|
624 } |
88
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
625 } |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
626 } else { |
153
42c031184e8a
Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents:
149
diff
changeset
|
627 location &= 0x1FFF; |
42c031184e8a
Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents:
149
diff
changeset
|
628 if (location < 0x100) { |
42c031184e8a
Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents:
149
diff
changeset
|
629 switch(location/2) |
42c031184e8a
Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents:
149
diff
changeset
|
630 { |
42c031184e8a
Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents:
149
diff
changeset
|
631 case 0x1: |
42c031184e8a
Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents:
149
diff
changeset
|
632 io_data_write(&gamepad_1, context, value); |
42c031184e8a
Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents:
149
diff
changeset
|
633 break; |
42c031184e8a
Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents:
149
diff
changeset
|
634 case 0x2: |
42c031184e8a
Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents:
149
diff
changeset
|
635 io_data_write(&gamepad_2, context, value); |
42c031184e8a
Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents:
149
diff
changeset
|
636 break; |
42c031184e8a
Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents:
149
diff
changeset
|
637 case 0x3://PORT C Data |
42c031184e8a
Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents:
149
diff
changeset
|
638 break; |
42c031184e8a
Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents:
149
diff
changeset
|
639 case 0x4: |
42c031184e8a
Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents:
149
diff
changeset
|
640 gamepad_1.control = value; |
42c031184e8a
Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents:
149
diff
changeset
|
641 break; |
42c031184e8a
Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents:
149
diff
changeset
|
642 case 0x5: |
42c031184e8a
Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents:
149
diff
changeset
|
643 gamepad_2.control = value; |
42c031184e8a
Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents:
149
diff
changeset
|
644 break; |
88
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
645 } |
153
42c031184e8a
Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents:
149
diff
changeset
|
646 } else { |
42c031184e8a
Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents:
149
diff
changeset
|
647 //printf("IO Write of %X to %X @ %d\n", value, location, context->current_cycle); |
42c031184e8a
Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents:
149
diff
changeset
|
648 if (location == 0x1100) { |
288
a8ee7934a1f8
Add a YM2612 stub implementation with just timers and status registers so that games that depend on it can run.
Mike Pavone <pavone@retrodev.com>
parents:
280
diff
changeset
|
649 sync_z80(gen->z80, context->current_cycle * MCLKS_PER_68K); |
336
87b65e5ce1ab
Fix a stupid bug in z80 busreq acknowledge delay code and make some small improvements there too
Mike Pavone <pavone@retrodev.com>
parents:
335
diff
changeset
|
650 if (busack_cycle <= context->current_cycle) { |
153
42c031184e8a
Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents:
149
diff
changeset
|
651 busack = new_busack; |
42c031184e8a
Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents:
149
diff
changeset
|
652 busack_cycle = CYCLE_NEVER; |
88
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
653 } |
153
42c031184e8a
Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents:
149
diff
changeset
|
654 if (value & 0x100) { |
271
969ee17471c5
Protect debug prints for busreq/reset regs with appropriate macros
Mike Pavone <pavone@retrodev.com>
parents:
268
diff
changeset
|
655 dprintf("bus requesting Z80 @ %d\n", (context->current_cycle * MCLKS_PER_68K) / MCLKS_PER_Z80); |
336
87b65e5ce1ab
Fix a stupid bug in z80 busreq acknowledge delay code and make some small improvements there too
Mike Pavone <pavone@retrodev.com>
parents:
335
diff
changeset
|
656 |
87b65e5ce1ab
Fix a stupid bug in z80 busreq acknowledge delay code and make some small improvements there too
Mike Pavone <pavone@retrodev.com>
parents:
335
diff
changeset
|
657 if(!reset && !busreq) { |
289
1cc0850ab6bc
Hopefully more correct implementation of the Z80 busack status
Mike Pavone <pavone@retrodev.com>
parents:
288
diff
changeset
|
658 busack_cycle = ((gen->z80->current_cycle + Z80_ACK_DELAY) * MCLKS_PER_Z80) / MCLKS_PER_68K;//context->current_cycle + Z80_ACK_DELAY; |
1cc0850ab6bc
Hopefully more correct implementation of the Z80 busack status
Mike Pavone <pavone@retrodev.com>
parents:
288
diff
changeset
|
659 new_busack = Z80_REQ_ACK; |
153
42c031184e8a
Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents:
149
diff
changeset
|
660 } |
364
62177cc39049
Incredibly broken YM2612 support plus a fix to Z80 bus request
Mike Pavone <pavone@retrodev.com>
parents:
362
diff
changeset
|
661 busreq = 1; |
153
42c031184e8a
Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents:
149
diff
changeset
|
662 } else { |
260
625f8e4d5fd2
Initial stab at integartiong Z80 core
Mike Pavone <pavone@retrodev.com>
parents:
215
diff
changeset
|
663 if (busreq) { |
271
969ee17471c5
Protect debug prints for busreq/reset regs with appropriate macros
Mike Pavone <pavone@retrodev.com>
parents:
268
diff
changeset
|
664 dprintf("releasing Z80 bus @ %d\n", (context->current_cycle * MCLKS_PER_68K) / MCLKS_PER_Z80); |
280 | 665 #ifdef DO_DEBUG_PRINT |
279
6be6056735a9
Fix native address lookup in bannked memory area
Mike Pavone <pavone@retrodev.com>
parents:
276
diff
changeset
|
666 char fname[20]; |
6be6056735a9
Fix native address lookup in bannked memory area
Mike Pavone <pavone@retrodev.com>
parents:
276
diff
changeset
|
667 sprintf(fname, "zram-%d", zram_counter++); |
6be6056735a9
Fix native address lookup in bannked memory area
Mike Pavone <pavone@retrodev.com>
parents:
276
diff
changeset
|
668 FILE * f = fopen(fname, "wb"); |
6be6056735a9
Fix native address lookup in bannked memory area
Mike Pavone <pavone@retrodev.com>
parents:
276
diff
changeset
|
669 fwrite(z80_ram, 1, sizeof(z80_ram), f); |
6be6056735a9
Fix native address lookup in bannked memory area
Mike Pavone <pavone@retrodev.com>
parents:
276
diff
changeset
|
670 fclose(f); |
280 | 671 #endif |
336
87b65e5ce1ab
Fix a stupid bug in z80 busreq acknowledge delay code and make some small improvements there too
Mike Pavone <pavone@retrodev.com>
parents:
335
diff
changeset
|
672 busack_cycle = ((gen->z80->current_cycle + Z80_BUSY_DELAY) * MCLKS_PER_Z80) / MCLKS_PER_68K; |
87b65e5ce1ab
Fix a stupid bug in z80 busreq acknowledge delay code and make some small improvements there too
Mike Pavone <pavone@retrodev.com>
parents:
335
diff
changeset
|
673 new_busack = Z80_REQ_BUSY; |
87b65e5ce1ab
Fix a stupid bug in z80 busreq acknowledge delay code and make some small improvements there too
Mike Pavone <pavone@retrodev.com>
parents:
335
diff
changeset
|
674 busreq = 0; |
260
625f8e4d5fd2
Initial stab at integartiong Z80 core
Mike Pavone <pavone@retrodev.com>
parents:
215
diff
changeset
|
675 } |
289
1cc0850ab6bc
Hopefully more correct implementation of the Z80 busack status
Mike Pavone <pavone@retrodev.com>
parents:
288
diff
changeset
|
676 //busack_cycle = CYCLE_NEVER; |
1cc0850ab6bc
Hopefully more correct implementation of the Z80 busack status
Mike Pavone <pavone@retrodev.com>
parents:
288
diff
changeset
|
677 //busack = Z80_REQ_BUSY; |
88
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
678 } |
153
42c031184e8a
Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents:
149
diff
changeset
|
679 } else if (location == 0x1200) { |
288
a8ee7934a1f8
Add a YM2612 stub implementation with just timers and status registers so that games that depend on it can run.
Mike Pavone <pavone@retrodev.com>
parents:
280
diff
changeset
|
680 sync_z80(gen->z80, context->current_cycle * MCLKS_PER_68K); |
153
42c031184e8a
Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents:
149
diff
changeset
|
681 if (value & 0x100) { |
42c031184e8a
Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents:
149
diff
changeset
|
682 if (reset && busreq) { |
42c031184e8a
Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents:
149
diff
changeset
|
683 new_busack = 0; |
289
1cc0850ab6bc
Hopefully more correct implementation of the Z80 busack status
Mike Pavone <pavone@retrodev.com>
parents:
288
diff
changeset
|
684 busack_cycle = ((gen->z80->current_cycle + Z80_ACK_DELAY) * MCLKS_PER_Z80) / MCLKS_PER_68K;//context->current_cycle + Z80_ACK_DELAY; |
153
42c031184e8a
Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents:
149
diff
changeset
|
685 } |
260
625f8e4d5fd2
Initial stab at integartiong Z80 core
Mike Pavone <pavone@retrodev.com>
parents:
215
diff
changeset
|
686 //TODO: Deal with the scenario in which reset is not asserted long enough |
625f8e4d5fd2
Initial stab at integartiong Z80 core
Mike Pavone <pavone@retrodev.com>
parents:
215
diff
changeset
|
687 if (reset) { |
625f8e4d5fd2
Initial stab at integartiong Z80 core
Mike Pavone <pavone@retrodev.com>
parents:
215
diff
changeset
|
688 need_reset = 1; |
625f8e4d5fd2
Initial stab at integartiong Z80 core
Mike Pavone <pavone@retrodev.com>
parents:
215
diff
changeset
|
689 //TODO: Add necessary delay between release of reset and start of execution |
336
87b65e5ce1ab
Fix a stupid bug in z80 busreq acknowledge delay code and make some small improvements there too
Mike Pavone <pavone@retrodev.com>
parents:
335
diff
changeset
|
690 gen->z80->current_cycle = (context->current_cycle * MCLKS_PER_68K) / MCLKS_PER_Z80; |
260
625f8e4d5fd2
Initial stab at integartiong Z80 core
Mike Pavone <pavone@retrodev.com>
parents:
215
diff
changeset
|
691 } |
153
42c031184e8a
Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents:
149
diff
changeset
|
692 reset = 0; |
42c031184e8a
Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents:
149
diff
changeset
|
693 } else { |
42c031184e8a
Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents:
149
diff
changeset
|
694 reset = 1; |
42c031184e8a
Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents:
149
diff
changeset
|
695 } |
88
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
696 } |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
697 } |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
698 } |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
699 return context; |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
700 } |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
701 |
130
0bdbffa9fe90
Make version register return correct value for USA
Mike Pavone <pavone@retrodev.com>
parents:
115
diff
changeset
|
702 #define USA 0x80 |
0bdbffa9fe90
Make version register return correct value for USA
Mike Pavone <pavone@retrodev.com>
parents:
115
diff
changeset
|
703 #define JAP 0x00 |
0bdbffa9fe90
Make version register return correct value for USA
Mike Pavone <pavone@retrodev.com>
parents:
115
diff
changeset
|
704 #define EUR 0xC0 |
0bdbffa9fe90
Make version register return correct value for USA
Mike Pavone <pavone@retrodev.com>
parents:
115
diff
changeset
|
705 #define NO_DISK 0x20 |
0bdbffa9fe90
Make version register return correct value for USA
Mike Pavone <pavone@retrodev.com>
parents:
115
diff
changeset
|
706 uint8_t version_reg = NO_DISK | USA; |
0bdbffa9fe90
Make version register return correct value for USA
Mike Pavone <pavone@retrodev.com>
parents:
115
diff
changeset
|
707 |
343
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
708 uint8_t io_read(uint32_t location, m68k_context * context) |
88
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
709 { |
343
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
710 uint8_t value; |
288
a8ee7934a1f8
Add a YM2612 stub implementation with just timers and status registers so that games that depend on it can run.
Mike Pavone <pavone@retrodev.com>
parents:
280
diff
changeset
|
711 genesis_context *gen = context->system; |
153
42c031184e8a
Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents:
149
diff
changeset
|
712 if (location < 0x10000) { |
336
87b65e5ce1ab
Fix a stupid bug in z80 busreq acknowledge delay code and make some small improvements there too
Mike Pavone <pavone@retrodev.com>
parents:
335
diff
changeset
|
713 if (busack_cycle <= context->current_cycle) { |
153
42c031184e8a
Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents:
149
diff
changeset
|
714 busack = new_busack; |
42c031184e8a
Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents:
149
diff
changeset
|
715 busack_cycle = CYCLE_NEVER; |
42c031184e8a
Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents:
149
diff
changeset
|
716 } |
289
1cc0850ab6bc
Hopefully more correct implementation of the Z80 busack status
Mike Pavone <pavone@retrodev.com>
parents:
288
diff
changeset
|
717 if (!(busack==Z80_REQ_BUSY || reset)) { |
153
42c031184e8a
Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents:
149
diff
changeset
|
718 location &= 0x7FFF; |
42c031184e8a
Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents:
149
diff
changeset
|
719 if (location < 0x4000) { |
343
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
720 value = z80_ram[location & 0x1FFF]; |
288
a8ee7934a1f8
Add a YM2612 stub implementation with just timers and status registers so that games that depend on it can run.
Mike Pavone <pavone@retrodev.com>
parents:
280
diff
changeset
|
721 } else if (location < 0x6000) { |
380
1c8d74f2ab0b
Make the PSG and YM2612 use the master clock internal with an increment based on clock divider so that they stay perflectly in sync. Run both the PSG and YM2612 whenver one of them needs to be run.
Mike Pavone <pavone@retrodev.com>
parents:
374
diff
changeset
|
722 sync_sound(gen, context->current_cycle * MCLKS_PER_68K); |
343
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
723 value = ym_read_status(gen->ym); |
153
42c031184e8a
Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents:
149
diff
changeset
|
724 } else { |
343
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
725 value = 0xFF; |
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
726 } |
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
727 } else { |
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
728 value = 0xFF; |
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
729 } |
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
730 } else { |
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
731 location &= 0x1FFF; |
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
732 if (location < 0x100) { |
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
733 switch(location/2) |
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
734 { |
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
735 case 0x0: |
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
736 //version bits should be 0 for now since we're not emulating TMSS |
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
737 value = version_reg; |
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
738 break; |
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
739 case 0x1: |
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
740 value = io_data_read(&gamepad_1, context); |
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
741 break; |
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
742 case 0x2: |
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
743 value = io_data_read(&gamepad_2, context); |
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
744 break; |
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
745 case 0x3://PORT C Data |
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
746 break; |
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
747 case 0x4: |
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
748 value = gamepad_1.control; |
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
749 break; |
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
750 case 0x5: |
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
751 value = gamepad_2.control; |
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
752 break; |
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
753 default: |
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
754 value = 0xFF; |
153
42c031184e8a
Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents:
149
diff
changeset
|
755 } |
42c031184e8a
Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents:
149
diff
changeset
|
756 } else { |
343
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
757 if (location == 0x1100) { |
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
758 if (busack_cycle <= context->current_cycle) { |
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
759 busack = new_busack; |
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
760 busack_cycle = CYCLE_NEVER; |
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
761 } |
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
762 value = Z80_RES_BUSACK || busack; |
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
763 dprintf("Byte read of BUSREQ returned %d @ %d (reset: %d, busack: %d, busack_cycle %d)\n", value, context->current_cycle, reset, busack, busack_cycle); |
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
764 } else if (location == 0x1200) { |
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
765 value = !reset; |
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
766 } else { |
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
767 value = 0xFF; |
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
768 printf("Byte read of unknown IO location: %X\n", location); |
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
769 } |
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
770 } |
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
771 } |
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
772 return value; |
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
773 } |
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
774 |
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
775 uint16_t io_read_w(uint32_t location, m68k_context * context) |
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
776 { |
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
777 uint16_t value; |
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
778 genesis_context * gen = context->system; |
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
779 if (location < 0x10000) { |
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
780 if (busack_cycle <= context->current_cycle) { |
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
781 busack = new_busack; |
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
782 busack_cycle = CYCLE_NEVER; |
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
783 } |
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
784 if (!(busack==Z80_REQ_BUSY || reset)) { |
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
785 location &= 0x7FFF; |
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
786 if (location < 0x4000) { |
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
787 value = z80_ram[location & 0x1FFE]; |
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
788 } else if (location < 0x6000) { |
380
1c8d74f2ab0b
Make the PSG and YM2612 use the master clock internal with an increment based on clock divider so that they stay perflectly in sync. Run both the PSG and YM2612 whenver one of them needs to be run.
Mike Pavone <pavone@retrodev.com>
parents:
374
diff
changeset
|
789 sync_sound(gen, context->current_cycle * MCLKS_PER_68K); |
343
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
790 value = ym_read_status(gen->ym); |
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
791 } else { |
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
792 value = 0xFF; |
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
793 } |
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
794 value = value | (value << 8); |
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
795 } else { |
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
796 value = 0xFFFF; |
88
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
797 } |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
798 } else { |
153
42c031184e8a
Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents:
149
diff
changeset
|
799 location &= 0x1FFF; |
42c031184e8a
Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents:
149
diff
changeset
|
800 if (location < 0x100) { |
42c031184e8a
Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents:
149
diff
changeset
|
801 switch(location/2) |
42c031184e8a
Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents:
149
diff
changeset
|
802 { |
42c031184e8a
Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents:
149
diff
changeset
|
803 case 0x0: |
42c031184e8a
Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents:
149
diff
changeset
|
804 //version bits should be 0 for now since we're not emulating TMSS |
42c031184e8a
Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents:
149
diff
changeset
|
805 //Not sure about the other bits |
343
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
806 value = version_reg; |
153
42c031184e8a
Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents:
149
diff
changeset
|
807 break; |
42c031184e8a
Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents:
149
diff
changeset
|
808 case 0x1: |
343
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
809 value = io_data_read(&gamepad_1, context); |
153
42c031184e8a
Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents:
149
diff
changeset
|
810 break; |
42c031184e8a
Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents:
149
diff
changeset
|
811 case 0x2: |
343
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
812 value = io_data_read(&gamepad_2, context); |
153
42c031184e8a
Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents:
149
diff
changeset
|
813 break; |
42c031184e8a
Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents:
149
diff
changeset
|
814 case 0x3://PORT C Data |
42c031184e8a
Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents:
149
diff
changeset
|
815 break; |
42c031184e8a
Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents:
149
diff
changeset
|
816 case 0x4: |
343
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
817 value = gamepad_1.control; |
153
42c031184e8a
Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents:
149
diff
changeset
|
818 break; |
42c031184e8a
Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents:
149
diff
changeset
|
819 case 0x5: |
343
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
820 value = gamepad_2.control; |
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
821 break; |
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
822 case 0x6: |
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
823 //PORT C Control |
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
824 value = 0; |
153
42c031184e8a
Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents:
149
diff
changeset
|
825 break; |
343
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
826 default: |
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
827 value = 0; |
88
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
828 } |
343
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
829 value = value | (value << 8); |
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
830 //printf("Word read to %X returned %d\n", location, value); |
88
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
831 } else { |
153
42c031184e8a
Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents:
149
diff
changeset
|
832 if (location == 0x1100) { |
336
87b65e5ce1ab
Fix a stupid bug in z80 busreq acknowledge delay code and make some small improvements there too
Mike Pavone <pavone@retrodev.com>
parents:
335
diff
changeset
|
833 if (busack_cycle <= context->current_cycle) { |
153
42c031184e8a
Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents:
149
diff
changeset
|
834 busack = new_busack; |
42c031184e8a
Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents:
149
diff
changeset
|
835 busack_cycle = CYCLE_NEVER; |
42c031184e8a
Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents:
149
diff
changeset
|
836 } |
343
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
837 value = (Z80_RES_BUSACK || busack) << 8; |
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
838 //printf("Word read of BUSREQ returned %d\n", value); |
153
42c031184e8a
Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents:
149
diff
changeset
|
839 } else if (location == 0x1200) { |
343
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
840 value = (!reset) << 8; |
153
42c031184e8a
Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents:
149
diff
changeset
|
841 } else { |
42c031184e8a
Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents:
149
diff
changeset
|
842 printf("Word read of unknown IO location: %X\n", location); |
42c031184e8a
Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents:
149
diff
changeset
|
843 } |
88
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
844 } |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
845 } |
343
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
846 return value; |
88
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
847 } |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
848 |
290
171f97e70d85
Implement writes from Z80 to YM-2612
Mike Pavone <pavone@retrodev.com>
parents:
289
diff
changeset
|
849 z80_context * z80_write_ym(uint16_t location, z80_context * context, uint8_t value) |
171f97e70d85
Implement writes from Z80 to YM-2612
Mike Pavone <pavone@retrodev.com>
parents:
289
diff
changeset
|
850 { |
171f97e70d85
Implement writes from Z80 to YM-2612
Mike Pavone <pavone@retrodev.com>
parents:
289
diff
changeset
|
851 genesis_context * gen = context->system; |
380
1c8d74f2ab0b
Make the PSG and YM2612 use the master clock internal with an increment based on clock divider so that they stay perflectly in sync. Run both the PSG and YM2612 whenver one of them needs to be run.
Mike Pavone <pavone@retrodev.com>
parents:
374
diff
changeset
|
852 sync_sound(gen, context->current_cycle * MCLKS_PER_Z80); |
290
171f97e70d85
Implement writes from Z80 to YM-2612
Mike Pavone <pavone@retrodev.com>
parents:
289
diff
changeset
|
853 if (location & 1) { |
171f97e70d85
Implement writes from Z80 to YM-2612
Mike Pavone <pavone@retrodev.com>
parents:
289
diff
changeset
|
854 ym_data_write(gen->ym, value); |
171f97e70d85
Implement writes from Z80 to YM-2612
Mike Pavone <pavone@retrodev.com>
parents:
289
diff
changeset
|
855 } else if (location & 2) { |
171f97e70d85
Implement writes from Z80 to YM-2612
Mike Pavone <pavone@retrodev.com>
parents:
289
diff
changeset
|
856 ym_address_write_part2(gen->ym, value); |
171f97e70d85
Implement writes from Z80 to YM-2612
Mike Pavone <pavone@retrodev.com>
parents:
289
diff
changeset
|
857 } else { |
171f97e70d85
Implement writes from Z80 to YM-2612
Mike Pavone <pavone@retrodev.com>
parents:
289
diff
changeset
|
858 ym_address_write_part1(gen->ym, value); |
171f97e70d85
Implement writes from Z80 to YM-2612
Mike Pavone <pavone@retrodev.com>
parents:
289
diff
changeset
|
859 } |
171f97e70d85
Implement writes from Z80 to YM-2612
Mike Pavone <pavone@retrodev.com>
parents:
289
diff
changeset
|
860 return context; |
171f97e70d85
Implement writes from Z80 to YM-2612
Mike Pavone <pavone@retrodev.com>
parents:
289
diff
changeset
|
861 } |
171f97e70d85
Implement writes from Z80 to YM-2612
Mike Pavone <pavone@retrodev.com>
parents:
289
diff
changeset
|
862 |
171f97e70d85
Implement writes from Z80 to YM-2612
Mike Pavone <pavone@retrodev.com>
parents:
289
diff
changeset
|
863 uint8_t z80_read_ym(uint16_t location, z80_context * context) |
171f97e70d85
Implement writes from Z80 to YM-2612
Mike Pavone <pavone@retrodev.com>
parents:
289
diff
changeset
|
864 { |
171f97e70d85
Implement writes from Z80 to YM-2612
Mike Pavone <pavone@retrodev.com>
parents:
289
diff
changeset
|
865 genesis_context * gen = context->system; |
380
1c8d74f2ab0b
Make the PSG and YM2612 use the master clock internal with an increment based on clock divider so that they stay perflectly in sync. Run both the PSG and YM2612 whenver one of them needs to be run.
Mike Pavone <pavone@retrodev.com>
parents:
374
diff
changeset
|
866 sync_sound(gen, context->current_cycle * MCLKS_PER_Z80); |
290
171f97e70d85
Implement writes from Z80 to YM-2612
Mike Pavone <pavone@retrodev.com>
parents:
289
diff
changeset
|
867 return ym_read_status(gen->ym); |
171f97e70d85
Implement writes from Z80 to YM-2612
Mike Pavone <pavone@retrodev.com>
parents:
289
diff
changeset
|
868 } |
171f97e70d85
Implement writes from Z80 to YM-2612
Mike Pavone <pavone@retrodev.com>
parents:
289
diff
changeset
|
869 |
351
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
870 uint16_t read_sram_w(uint32_t address, m68k_context * context) |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
871 { |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
872 genesis_context * gen = context->system; |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
873 address &= gen->save_ram_mask; |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
874 switch(gen->save_flags) |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
875 { |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
876 case RAM_FLAG_BOTH: |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
877 return gen->save_ram[address] << 8 | gen->save_ram[address+1]; |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
878 case RAM_FLAG_EVEN: |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
879 return gen->save_ram[address >> 1] << 8 | 0xFF; |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
880 case RAM_FLAG_ODD: |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
881 return gen->save_ram[address >> 1] | 0xFF00; |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
882 } |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
883 return 0xFFFF;//We should never get here |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
884 } |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
885 |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
886 uint8_t read_sram_b(uint32_t address, m68k_context * context) |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
887 { |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
888 genesis_context * gen = context->system; |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
889 address &= gen->save_ram_mask; |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
890 switch(gen->save_flags) |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
891 { |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
892 case RAM_FLAG_BOTH: |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
893 return gen->save_ram[address]; |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
894 case RAM_FLAG_EVEN: |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
895 if (address & 1) { |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
896 return 0xFF; |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
897 } else { |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
898 return gen->save_ram[address >> 1]; |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
899 } |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
900 case RAM_FLAG_ODD: |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
901 if (address & 1) { |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
902 return gen->save_ram[address >> 1]; |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
903 } else { |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
904 return 0xFF; |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
905 } |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
906 } |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
907 return 0xFF;//We should never get here |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
908 } |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
909 |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
910 m68k_context * write_sram_area_w(uint32_t address, m68k_context * context, uint16_t value) |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
911 { |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
912 genesis_context * gen = context->system; |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
913 if ((gen->bank_regs[0] & 0x3) == 1) { |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
914 address &= gen->save_ram_mask; |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
915 switch(gen->save_flags) |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
916 { |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
917 case RAM_FLAG_BOTH: |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
918 gen->save_ram[address] = value >> 8; |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
919 gen->save_ram[address+1] = value; |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
920 break; |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
921 case RAM_FLAG_EVEN: |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
922 gen->save_ram[address >> 1] = value >> 8; |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
923 break; |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
924 case RAM_FLAG_ODD: |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
925 gen->save_ram[address >> 1] = value; |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
926 break; |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
927 } |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
928 } |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
929 return context; |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
930 } |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
931 |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
932 m68k_context * write_sram_area_b(uint32_t address, m68k_context * context, uint8_t value) |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
933 { |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
934 genesis_context * gen = context->system; |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
935 if ((gen->bank_regs[0] & 0x3) == 1) { |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
936 address &= gen->save_ram_mask; |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
937 switch(gen->save_flags) |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
938 { |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
939 case RAM_FLAG_BOTH: |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
940 gen->save_ram[address] = value; |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
941 break; |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
942 case RAM_FLAG_EVEN: |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
943 if (!(address & 1)) { |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
944 gen->save_ram[address >> 1] = value; |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
945 } |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
946 break; |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
947 case RAM_FLAG_ODD: |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
948 if (address & 1) { |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
949 gen->save_ram[address >> 1] = value; |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
950 } |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
951 break; |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
952 } |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
953 } |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
954 return context; |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
955 } |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
956 |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
957 m68k_context * write_bank_reg_w(uint32_t address, m68k_context * context, uint16_t value) |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
958 { |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
959 genesis_context * gen = context->system; |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
960 address &= 0xE; |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
961 address >>= 1; |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
962 gen->bank_regs[address] = value; |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
963 if (!address) { |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
964 if (value & 1) { |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
965 context->mem_pointers[2] = NULL; |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
966 } else { |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
967 context->mem_pointers[2] = cart + 0x200000/2; |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
968 } |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
969 } |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
970 return context; |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
971 } |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
972 |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
973 m68k_context * write_bank_reg_b(uint32_t address, m68k_context * context, uint8_t value) |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
974 { |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
975 if (address & 1) { |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
976 genesis_context * gen = context->system; |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
977 address &= 0xE; |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
978 address >>= 1; |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
979 gen->bank_regs[address] = value; |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
980 if (!address) { |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
981 if (value & 1) { |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
982 context->mem_pointers[2] = NULL; |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
983 } else { |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
984 context->mem_pointers[2] = cart + 0x200000/2; |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
985 } |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
986 } |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
987 } |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
988 return context; |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
989 } |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
990 |
184
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
991 typedef struct bp_def { |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
992 struct bp_def * next; |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
993 uint32_t address; |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
994 uint32_t index; |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
995 } bp_def; |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
996 |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
997 bp_def * breakpoints = NULL; |
366
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
998 bp_def * zbreakpoints = NULL; |
184
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
999 uint32_t bp_index = 0; |
366
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1000 uint32_t zbp_index = 0; |
184
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1001 |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1002 bp_def ** find_breakpoint(bp_def ** cur, uint32_t address) |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1003 { |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1004 while (*cur) { |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1005 if ((*cur)->address == address) { |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1006 break; |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1007 } |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1008 cur = &((*cur)->next); |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1009 } |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1010 return cur; |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1011 } |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1012 |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1013 bp_def ** find_breakpoint_idx(bp_def ** cur, uint32_t index) |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1014 { |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1015 while (*cur) { |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1016 if ((*cur)->index == index) { |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1017 break; |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1018 } |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1019 cur = &((*cur)->next); |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1020 } |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1021 return cur; |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1022 } |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1023 |
372
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1024 typedef struct disp_def { |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1025 struct disp_def * next; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1026 char * param; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1027 uint32_t index; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1028 char format_char; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1029 } disp_def; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1030 |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1031 disp_def * displays = NULL; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1032 disp_def * zdisplays = NULL; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1033 uint32_t disp_index = 0; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1034 uint32_t zdisp_index = 0; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1035 |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1036 void add_display(disp_def ** head, uint32_t *index, char format_char, char * param) |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1037 { |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1038 disp_def * ndisp = malloc(sizeof(*ndisp)); |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1039 ndisp->format_char = format_char; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1040 ndisp->param = strdup(param); |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1041 ndisp->next = *head; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1042 ndisp->index = *index++; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1043 *head = ndisp; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1044 } |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1045 |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1046 void remove_display(disp_def ** head, uint32_t index) |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1047 { |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1048 while (*head) { |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1049 if ((*head)->index == index) { |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1050 disp_def * del_disp = *head; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1051 *head = del_disp->next; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1052 free(del_disp->param); |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1053 free(del_disp); |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1054 } else { |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1055 head = &(*head)->next; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1056 } |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1057 } |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1058 } |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1059 |
184
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1060 char * find_param(char * buf) |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1061 { |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1062 for (; *buf; buf++) { |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1063 if (*buf == ' ') { |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1064 if (*(buf+1)) { |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1065 return buf+1; |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1066 } |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1067 } |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1068 } |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1069 return NULL; |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1070 } |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1071 |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1072 void strip_nl(char * buf) |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1073 { |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1074 for(; *buf; buf++) { |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1075 if (*buf == '\n') { |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1076 *buf = 0; |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1077 return; |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1078 } |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1079 } |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1080 } |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1081 |
372
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1082 void zdebugger_print(z80_context * context, char format_char, char * param) |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1083 { |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1084 uint32_t value; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1085 char format[8]; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1086 strcpy(format, "%s: %d\n"); |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1087 switch (format_char) |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1088 { |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1089 case 'x': |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1090 case 'X': |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1091 case 'd': |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1092 case 'c': |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1093 format[5] = format_char; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1094 break; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1095 case '\0': |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1096 break; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1097 default: |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1098 fprintf(stderr, "Unrecognized format character: %c\n", format_char); |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1099 } |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1100 switch (param[0]) |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1101 { |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1102 case 'a': |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1103 if (param[1] == 'f') { |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1104 if(param[2] == '\'') { |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1105 value = context->alt_regs[Z80_A] << 8; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1106 value |= context->alt_flags[ZF_S] << 7; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1107 value |= context->alt_flags[ZF_Z] << 6; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1108 value |= context->alt_flags[ZF_H] << 4; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1109 value |= context->alt_flags[ZF_PV] << 2; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1110 value |= context->alt_flags[ZF_N] << 1; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1111 value |= context->alt_flags[ZF_C]; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1112 } else { |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1113 value = context->regs[Z80_A] << 8; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1114 value |= context->flags[ZF_S] << 7; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1115 value |= context->flags[ZF_Z] << 6; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1116 value |= context->flags[ZF_H] << 4; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1117 value |= context->flags[ZF_PV] << 2; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1118 value |= context->flags[ZF_N] << 1; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1119 value |= context->flags[ZF_C]; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1120 } |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1121 } else if(param[1] == '\'') { |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1122 value = context->alt_regs[Z80_A]; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1123 } else { |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1124 value = context->regs[Z80_A]; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1125 } |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1126 break; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1127 case 'b': |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1128 if (param[1] == 'c') { |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1129 if(param[2] == '\'') { |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1130 value = context->alt_regs[Z80_B] << 8; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1131 value |= context->alt_regs[Z80_C]; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1132 } else { |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1133 value = context->regs[Z80_B] << 8; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1134 value |= context->regs[Z80_C]; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1135 } |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1136 } else if(param[1] == '\'') { |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1137 value = context->alt_regs[Z80_B]; |
392
1b80b90399da
Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
380
diff
changeset
|
1138 } else if(param[1] == 'a') { |
1b80b90399da
Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
380
diff
changeset
|
1139 value = context->bank_reg << 15; |
372
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1140 } else { |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1141 value = context->regs[Z80_B]; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1142 } |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1143 break; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1144 case 'c': |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1145 if(param[1] == '\'') { |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1146 value = context->alt_regs[Z80_C]; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1147 } else if(param[1] == 'y') { |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1148 value = context->current_cycle; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1149 } else { |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1150 value = context->regs[Z80_C]; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1151 } |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1152 break; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1153 case 'd': |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1154 if (param[1] == 'e') { |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1155 if(param[2] == '\'') { |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1156 value = context->alt_regs[Z80_D] << 8; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1157 value |= context->alt_regs[Z80_E]; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1158 } else { |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1159 value = context->regs[Z80_D] << 8; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1160 value |= context->regs[Z80_E]; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1161 } |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1162 } else if(param[1] == '\'') { |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1163 value = context->alt_regs[Z80_D]; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1164 } else { |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1165 value = context->regs[Z80_D]; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1166 } |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1167 break; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1168 case 'e': |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1169 if(param[1] == '\'') { |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1170 value = context->alt_regs[Z80_E]; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1171 } else { |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1172 value = context->regs[Z80_E]; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1173 } |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1174 break; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1175 case 'f': |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1176 if(param[2] == '\'') { |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1177 value = context->alt_flags[ZF_S] << 7; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1178 value |= context->alt_flags[ZF_Z] << 6; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1179 value |= context->alt_flags[ZF_H] << 4; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1180 value |= context->alt_flags[ZF_PV] << 2; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1181 value |= context->alt_flags[ZF_N] << 1; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1182 value |= context->alt_flags[ZF_C]; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1183 } else { |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1184 value = context->flags[ZF_S] << 7; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1185 value |= context->flags[ZF_Z] << 6; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1186 value |= context->flags[ZF_H] << 4; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1187 value |= context->flags[ZF_PV] << 2; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1188 value |= context->flags[ZF_N] << 1; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1189 value |= context->flags[ZF_C]; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1190 } |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1191 break; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1192 case 'h': |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1193 if (param[1] == 'l') { |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1194 if(param[2] == '\'') { |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1195 value = context->alt_regs[Z80_H] << 8; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1196 value |= context->alt_regs[Z80_L]; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1197 } else { |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1198 value = context->regs[Z80_H] << 8; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1199 value |= context->regs[Z80_L]; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1200 } |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1201 } else if(param[1] == '\'') { |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1202 value = context->alt_regs[Z80_H]; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1203 } else { |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1204 value = context->regs[Z80_H]; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1205 } |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1206 break; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1207 case 'l': |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1208 if(param[1] == '\'') { |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1209 value = context->alt_regs[Z80_L]; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1210 } else { |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1211 value = context->regs[Z80_L]; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1212 } |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1213 break; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1214 case 'i': |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1215 if(param[1] == 'x') { |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1216 if (param[2] == 'h') { |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1217 value = context->regs[Z80_IXH]; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1218 } else if(param[2] == 'l') { |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1219 value = context->regs[Z80_IXL]; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1220 } else { |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1221 value = context->regs[Z80_IXH] << 8; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1222 value |= context->regs[Z80_IXL]; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1223 } |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1224 } else if(param[1] == 'y') { |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1225 if (param[2] == 'h') { |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1226 value = context->regs[Z80_IYH]; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1227 } else if(param[2] == 'l') { |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1228 value = context->regs[Z80_IYL]; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1229 } else { |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1230 value = context->regs[Z80_IYH] << 8; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1231 value |= context->regs[Z80_IYL]; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1232 } |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1233 } else if(param[1] == 'n') { |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1234 value = context->int_cycle; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1235 } else if(param[1] == 'f' && param[2] == 'f' && param[3] == '1') { |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1236 value = context->iff1; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1237 } else if(param[1] == 'f' && param[2] == 'f' && param[3] == '2') { |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1238 value = context->iff2; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1239 } else { |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1240 value = context->im; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1241 } |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1242 break; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1243 case 's': |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1244 if (param[1] == 'p') { |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1245 value = context->sp; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1246 } |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1247 break; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1248 case '0': |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1249 if (param[1] == 'x') { |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1250 uint16_t p_addr = strtol(param+2, NULL, 16); |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1251 if (p_addr < 0x4000) { |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1252 value = z80_ram[p_addr & 0x1FFF]; |
392
1b80b90399da
Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
380
diff
changeset
|
1253 } else if(p_addr >= 0x8000) { |
1b80b90399da
Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
380
diff
changeset
|
1254 uint32_t v_addr = context->bank_reg << 15; |
1b80b90399da
Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
380
diff
changeset
|
1255 v_addr += p_addr & 0x7FFF; |
1b80b90399da
Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
380
diff
changeset
|
1256 if (v_addr < 0x400000) { |
1b80b90399da
Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
380
diff
changeset
|
1257 value = cart[v_addr/2]; |
1b80b90399da
Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
380
diff
changeset
|
1258 } else if(v_addr > 0xE00000) { |
1b80b90399da
Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
380
diff
changeset
|
1259 value = ram[(v_addr & 0xFFFF)/2]; |
1b80b90399da
Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
380
diff
changeset
|
1260 } |
1b80b90399da
Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
380
diff
changeset
|
1261 if (v_addr & 1) { |
1b80b90399da
Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
380
diff
changeset
|
1262 value &= 0xFF; |
1b80b90399da
Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
380
diff
changeset
|
1263 } else { |
1b80b90399da
Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
380
diff
changeset
|
1264 value >>= 8; |
1b80b90399da
Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
380
diff
changeset
|
1265 } |
372
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1266 } |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1267 } |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1268 break; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1269 } |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1270 printf(format, param, value); |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1271 } |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1272 |
366
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1273 z80_context * zdebugger(z80_context * context, uint16_t address) |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1274 { |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1275 static char last_cmd[1024]; |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1276 char input_buf[1024]; |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1277 static uint16_t branch_t; |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1278 static uint16_t branch_f; |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1279 z80inst inst; |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1280 //Check if this is a user set breakpoint, or just a temporary one |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1281 bp_def ** this_bp = find_breakpoint(&zbreakpoints, address); |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1282 if (*this_bp) { |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1283 printf("Z80 Breakpoint %d hit\n", (*this_bp)->index); |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1284 } else { |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1285 zremove_breakpoint(context, address); |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1286 } |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1287 uint8_t * pc; |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1288 if (address < 0x4000) { |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1289 pc = z80_ram + (address & 0x1FFF); |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1290 } else if (address >= 0x8000) { |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1291 if (context->bank_reg < (0x400000 >> 15)) { |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1292 fprintf(stderr, "Entered Z80 debugger in banked memory address %X, which is not yet supported\n", address); |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1293 exit(1); |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1294 } else { |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1295 fprintf(stderr, "Entered Z80 debugger in banked memory address %X, but the bank is not pointed to a cartridge address\n", address); |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1296 exit(1); |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1297 } |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1298 } else { |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1299 fprintf(stderr, "Entered Z80 debugger at address %X\n", address); |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1300 exit(1); |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1301 } |
372
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1302 for (disp_def * cur = zdisplays; cur; cur = cur->next) { |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1303 zdebugger_print(context, cur->format_char, cur->param); |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1304 } |
366
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1305 uint8_t * after_pc = z80_decode(pc, &inst); |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1306 z80_disasm(&inst, input_buf, address); |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1307 printf("%X:\t%s\n", address, input_buf); |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1308 uint16_t after = address + (after_pc-pc); |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1309 int debugging = 1; |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1310 while(debugging) { |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1311 fputs(">", stdout); |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1312 if (!fgets(input_buf, sizeof(input_buf), stdin)) { |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1313 fputs("fgets failed", stderr); |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1314 break; |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1315 } |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1316 strip_nl(input_buf); |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1317 //hitting enter repeats last command |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1318 if (input_buf[0]) { |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1319 strcpy(last_cmd, input_buf); |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1320 } else { |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1321 strcpy(input_buf, last_cmd); |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1322 } |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1323 char * param; |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1324 char format[8]; |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1325 uint32_t value; |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1326 bp_def * new_bp; |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1327 switch(input_buf[0]) |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1328 { |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1329 case 'a': |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1330 param = find_param(input_buf); |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1331 if (!param) { |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1332 fputs("a command requires a parameter\n", stderr); |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1333 break; |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1334 } |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1335 value = strtol(param, NULL, 16); |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1336 zinsert_breakpoint(context, value, (uint8_t *)zdebugger); |
392
1b80b90399da
Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
380
diff
changeset
|
1337 debugging = 0; |
366
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1338 break; |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1339 case 'b': |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1340 param = find_param(input_buf); |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1341 if (!param) { |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1342 fputs("b command requires a parameter\n", stderr); |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1343 break; |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1344 } |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1345 value = strtol(param, NULL, 16); |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1346 zinsert_breakpoint(context, value, (uint8_t *)zdebugger); |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1347 new_bp = malloc(sizeof(bp_def)); |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1348 new_bp->next = zbreakpoints; |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1349 new_bp->address = value; |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1350 new_bp->index = zbp_index++; |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1351 zbreakpoints = new_bp; |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1352 printf("Z80 Breakpoint %d set at %X\n", new_bp->index, value); |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1353 break; |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1354 case 'c': |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1355 puts("Continuing"); |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1356 debugging = 0; |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1357 break; |
372
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1358 case 'd': |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1359 if (input_buf[1] == 'i') { |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1360 char format_char = 0; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1361 for(int i = 2; input_buf[i] != 0 && input_buf[i] != ' '; i++) { |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1362 if (input_buf[i] == '/') { |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1363 format_char = input_buf[i+1]; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1364 break; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1365 } |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1366 } |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1367 param = find_param(input_buf); |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1368 if (!param) { |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1369 fputs("display command requires a parameter\n", stderr); |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1370 break; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1371 } |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1372 zdebugger_print(context, format_char, param); |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1373 add_display(&zdisplays, &zdisp_index, format_char, param); |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1374 } else if (input_buf[1] == 'e' || input_buf[1] == ' ') { |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1375 param = find_param(input_buf); |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1376 if (!param) { |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1377 fputs("delete command requires a parameter\n", stderr); |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1378 break; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1379 } |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1380 if (param[0] >= '0' && param[0] <= '9') { |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1381 value = atoi(param); |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1382 this_bp = find_breakpoint_idx(&zbreakpoints, value); |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1383 if (!*this_bp) { |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1384 fprintf(stderr, "Breakpoint %d does not exist\n", value); |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1385 break; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1386 } |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1387 new_bp = *this_bp; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1388 zremove_breakpoint(context, new_bp->address); |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1389 *this_bp = new_bp->next; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1390 free(new_bp); |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1391 } else if (param[0] == 'd') { |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1392 param = find_param(param); |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1393 if (!param) { |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1394 fputs("delete display command requires a parameter\n", stderr); |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1395 break; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1396 } |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1397 remove_display(&zdisplays, atoi(param)); |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1398 } |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1399 } |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1400 break; |
366
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1401 case 'n': |
392
1b80b90399da
Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
380
diff
changeset
|
1402 //TODO: Handle conditional branch instructions |
1b80b90399da
Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
380
diff
changeset
|
1403 if (inst.op == Z80_JP) { |
1b80b90399da
Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
380
diff
changeset
|
1404 if (inst.addr_mode == Z80_IMMED) { |
1b80b90399da
Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
380
diff
changeset
|
1405 after = inst.immed; |
1b80b90399da
Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
380
diff
changeset
|
1406 } else if (inst.ea_reg == Z80_HL) { |
1b80b90399da
Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
380
diff
changeset
|
1407 after = context->regs[Z80_H] << 8 | context->regs[Z80_L]; |
1b80b90399da
Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
380
diff
changeset
|
1408 } else if (inst.ea_reg == Z80_IX) { |
1b80b90399da
Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
380
diff
changeset
|
1409 after = context->regs[Z80_IXH] << 8 | context->regs[Z80_IXL]; |
1b80b90399da
Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
380
diff
changeset
|
1410 } else if (inst.ea_reg == Z80_IY) { |
1b80b90399da
Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
380
diff
changeset
|
1411 after = context->regs[Z80_IYH] << 8 | context->regs[Z80_IYL]; |
1b80b90399da
Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
380
diff
changeset
|
1412 } |
1b80b90399da
Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
380
diff
changeset
|
1413 } else if(inst.op == Z80_JR) { |
1b80b90399da
Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
380
diff
changeset
|
1414 after += inst.immed; |
1b80b90399da
Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
380
diff
changeset
|
1415 } else if(inst.op == Z80_RET) { |
1b80b90399da
Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
380
diff
changeset
|
1416 if (context->sp < 0x4000) { |
1b80b90399da
Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
380
diff
changeset
|
1417 after = z80_ram[context->sp & 0x1FFF] | z80_ram[(context->sp+1) & 0x1FFF] << 8; |
1b80b90399da
Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
380
diff
changeset
|
1418 } |
1b80b90399da
Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
380
diff
changeset
|
1419 } |
366
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1420 zinsert_breakpoint(context, after, (uint8_t *)zdebugger); |
368
c9d2a2371f5e
Make the n command in the Z80 debugger actually run the next instruction without needing a c command
Mike Pavone <pavone@retrodev.com>
parents:
366
diff
changeset
|
1421 debugging = 0; |
366
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1422 break; |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1423 case 'p': |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1424 param = find_param(input_buf); |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1425 if (!param) { |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1426 fputs("p command requires a parameter\n", stderr); |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1427 break; |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1428 } |
372
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1429 zdebugger_print(context, input_buf[1] == '/' ? input_buf[2] : 0, param); |
366
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1430 break; |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1431 case 'q': |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1432 puts("Quitting"); |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1433 exit(0); |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1434 break; |
395
0b5f93358a93
Add debugger command for saving Z80 RAM to a file
Mike Pavone <pavone@retrodev.com>
parents:
392
diff
changeset
|
1435 case 's': { |
0b5f93358a93
Add debugger command for saving Z80 RAM to a file
Mike Pavone <pavone@retrodev.com>
parents:
392
diff
changeset
|
1436 param = find_param(input_buf); |
0b5f93358a93
Add debugger command for saving Z80 RAM to a file
Mike Pavone <pavone@retrodev.com>
parents:
392
diff
changeset
|
1437 if (!param) { |
0b5f93358a93
Add debugger command for saving Z80 RAM to a file
Mike Pavone <pavone@retrodev.com>
parents:
392
diff
changeset
|
1438 fputs("s command requires a file name\n", stderr); |
0b5f93358a93
Add debugger command for saving Z80 RAM to a file
Mike Pavone <pavone@retrodev.com>
parents:
392
diff
changeset
|
1439 break; |
0b5f93358a93
Add debugger command for saving Z80 RAM to a file
Mike Pavone <pavone@retrodev.com>
parents:
392
diff
changeset
|
1440 } |
0b5f93358a93
Add debugger command for saving Z80 RAM to a file
Mike Pavone <pavone@retrodev.com>
parents:
392
diff
changeset
|
1441 FILE * f = fopen(param, "wb"); |
0b5f93358a93
Add debugger command for saving Z80 RAM to a file
Mike Pavone <pavone@retrodev.com>
parents:
392
diff
changeset
|
1442 if (f) { |
0b5f93358a93
Add debugger command for saving Z80 RAM to a file
Mike Pavone <pavone@retrodev.com>
parents:
392
diff
changeset
|
1443 if(fwrite(z80_ram, 1, sizeof(z80_ram), f) != sizeof(z80_ram)) { |
0b5f93358a93
Add debugger command for saving Z80 RAM to a file
Mike Pavone <pavone@retrodev.com>
parents:
392
diff
changeset
|
1444 fputs("Error writing file\n", stderr); |
0b5f93358a93
Add debugger command for saving Z80 RAM to a file
Mike Pavone <pavone@retrodev.com>
parents:
392
diff
changeset
|
1445 } |
0b5f93358a93
Add debugger command for saving Z80 RAM to a file
Mike Pavone <pavone@retrodev.com>
parents:
392
diff
changeset
|
1446 fclose(f); |
0b5f93358a93
Add debugger command for saving Z80 RAM to a file
Mike Pavone <pavone@retrodev.com>
parents:
392
diff
changeset
|
1447 } else { |
0b5f93358a93
Add debugger command for saving Z80 RAM to a file
Mike Pavone <pavone@retrodev.com>
parents:
392
diff
changeset
|
1448 fprintf(stderr, "Could not open %s for writing\n", param); |
0b5f93358a93
Add debugger command for saving Z80 RAM to a file
Mike Pavone <pavone@retrodev.com>
parents:
392
diff
changeset
|
1449 } |
0b5f93358a93
Add debugger command for saving Z80 RAM to a file
Mike Pavone <pavone@retrodev.com>
parents:
392
diff
changeset
|
1450 break; |
0b5f93358a93
Add debugger command for saving Z80 RAM to a file
Mike Pavone <pavone@retrodev.com>
parents:
392
diff
changeset
|
1451 } |
366
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1452 default: |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1453 fprintf(stderr, "Unrecognized debugger command %s\n", input_buf); |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1454 break; |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1455 } |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1456 } |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1457 return context; |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1458 } |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1459 |
184
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1460 m68k_context * debugger(m68k_context * context, uint32_t address) |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1461 { |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1462 static char last_cmd[1024]; |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1463 char input_buf[1024]; |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1464 static uint32_t branch_t; |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1465 static uint32_t branch_f; |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1466 m68kinst inst; |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1467 //probably not necessary, but let's play it safe |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1468 address &= 0xFFFFFF; |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1469 if (address == branch_t) { |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1470 bp_def ** f_bp = find_breakpoint(&breakpoints, branch_f); |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1471 if (!*f_bp) { |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1472 remove_breakpoint(context, branch_f); |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1473 } |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1474 branch_t = branch_f = 0; |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1475 } else if(address == branch_f) { |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1476 bp_def ** t_bp = find_breakpoint(&breakpoints, branch_t); |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1477 if (!*t_bp) { |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1478 remove_breakpoint(context, branch_t); |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1479 } |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1480 branch_t = branch_f = 0; |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1481 } |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1482 //Check if this is a user set breakpoint, or just a temporary one |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1483 bp_def ** this_bp = find_breakpoint(&breakpoints, address); |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1484 if (*this_bp) { |
366
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1485 printf("68K Breakpoint %d hit\n", (*this_bp)->index); |
184
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1486 } else { |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1487 remove_breakpoint(context, address); |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1488 } |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1489 uint16_t * pc; |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1490 if (address < 0x400000) { |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1491 pc = cart + address/2; |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1492 } else if(address > 0xE00000) { |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1493 pc = ram + (address & 0xFFFF)/2; |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1494 } else { |
366
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1495 fprintf(stderr, "Entered 68K debugger at address %X\n", address); |
184
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1496 exit(1); |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1497 } |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1498 uint16_t * after_pc = m68k_decode(pc, &inst, address); |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1499 m68k_disasm(&inst, input_buf); |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1500 printf("%X: %s\n", address, input_buf); |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1501 uint32_t after = address + (after_pc-pc)*2; |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1502 int debugging = 1; |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1503 while (debugging) { |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1504 fputs(">", stdout); |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1505 if (!fgets(input_buf, sizeof(input_buf), stdin)) { |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1506 fputs("fgets failed", stderr); |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1507 break; |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1508 } |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1509 strip_nl(input_buf); |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1510 //hitting enter repeats last command |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1511 if (input_buf[0]) { |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1512 strcpy(last_cmd, input_buf); |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1513 } else { |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1514 strcpy(input_buf, last_cmd); |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1515 } |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1516 char * param; |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1517 char format[8]; |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1518 uint32_t value; |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1519 bp_def * new_bp; |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1520 switch(input_buf[0]) |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1521 { |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1522 case 'c': |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1523 puts("Continuing"); |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1524 debugging = 0; |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1525 break; |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1526 case 'b': |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1527 param = find_param(input_buf); |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1528 if (!param) { |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1529 fputs("b command requires a parameter\n", stderr); |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1530 break; |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1531 } |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1532 value = strtol(param, NULL, 16); |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1533 insert_breakpoint(context, value, (uint8_t *)debugger); |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1534 new_bp = malloc(sizeof(bp_def)); |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1535 new_bp->next = breakpoints; |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1536 new_bp->address = value; |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1537 new_bp->index = bp_index++; |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1538 breakpoints = new_bp; |
366
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1539 printf("68K Breakpoint %d set at %X\n", new_bp->index, value); |
184
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1540 break; |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1541 case 'a': |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1542 param = find_param(input_buf); |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1543 if (!param) { |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1544 fputs("a command requires a parameter\n", stderr); |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1545 break; |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1546 } |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1547 value = strtol(param, NULL, 16); |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1548 insert_breakpoint(context, value, (uint8_t *)debugger); |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1549 debugging = 0; |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1550 break; |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1551 case 'd': |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1552 param = find_param(input_buf); |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1553 if (!param) { |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1554 fputs("b command requires a parameter\n", stderr); |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1555 break; |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1556 } |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1557 value = atoi(param); |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1558 this_bp = find_breakpoint_idx(&breakpoints, value); |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1559 if (!*this_bp) { |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1560 fprintf(stderr, "Breakpoint %d does not exist\n", value); |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1561 break; |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1562 } |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1563 new_bp = *this_bp; |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1564 *this_bp = (*this_bp)->next; |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1565 free(new_bp); |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1566 break; |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1567 case 'p': |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1568 strcpy(format, "%s: %d\n"); |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1569 if (input_buf[1] == '/') { |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1570 switch (input_buf[2]) |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1571 { |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1572 case 'x': |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1573 case 'X': |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1574 case 'd': |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1575 case 'c': |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1576 format[5] = input_buf[2]; |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1577 break; |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1578 default: |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1579 fprintf(stderr, "Unrecognized format character: %c\n", input_buf[2]); |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1580 } |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1581 } |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1582 param = find_param(input_buf); |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1583 if (!param) { |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1584 fputs("p command requires a parameter\n", stderr); |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1585 break; |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1586 } |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1587 if (param[0] == 'd' && param[1] >= '0' && param[1] <= '7') { |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1588 value = context->dregs[param[1]-'0']; |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1589 } else if (param[0] == 'a' && param[1] >= '0' && param[1] <= '7') { |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1590 value = context->aregs[param[1]-'0']; |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1591 } else if (param[0] == 'S' && param[1] == 'R') { |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1592 value = (context->status << 8); |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1593 for (int flag = 0; flag < 5; flag++) { |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1594 value |= context->flags[flag] << (4-flag); |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1595 } |
185
b204fbed4efe
Add ability to print out current 68K cycle in debugger
Mike Pavone <pavone@retrodev.com>
parents:
184
diff
changeset
|
1596 } else if(param[0] == 'c') { |
b204fbed4efe
Add ability to print out current 68K cycle in debugger
Mike Pavone <pavone@retrodev.com>
parents:
184
diff
changeset
|
1597 value = context->current_cycle; |
184
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1598 } else if (param[0] == '0' && param[1] == 'x') { |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1599 uint32_t p_addr = strtol(param+2, NULL, 16); |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1600 value = read_dma_value(p_addr/2); |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1601 } else { |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1602 fprintf(stderr, "Unrecognized parameter to p: %s\n", param); |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1603 break; |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1604 } |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1605 printf(format, param, value); |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1606 break; |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1607 case 'n': |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1608 //TODO: Deal with jmp, dbcc, rtr and rte |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1609 if (inst.op == M68K_RTS) { |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1610 after = (read_dma_value(context->aregs[7]/2) << 16) | read_dma_value(context->aregs[7]/2 + 1); |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1611 } else if(inst.op == M68K_BCC && inst.extra.cond != COND_FALSE) { |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1612 if (inst.extra.cond = COND_TRUE) { |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1613 after = inst.address + 2 + inst.src.params.immed; |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1614 } else { |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1615 branch_f = after; |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1616 branch_t = inst.address + 2 + inst.src.params.immed; |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1617 insert_breakpoint(context, branch_t, (uint8_t *)debugger); |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1618 } |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1619 } |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1620 insert_breakpoint(context, after, (uint8_t *)debugger); |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1621 debugging = 0; |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1622 break; |
327
1b00258b1f29
Added some basic VDP debugging features to debugger. Fixed DMA enable bug
Mike Pavone <pavone@retrodev.com>
parents:
321
diff
changeset
|
1623 case 'v': { |
1b00258b1f29
Added some basic VDP debugging features to debugger. Fixed DMA enable bug
Mike Pavone <pavone@retrodev.com>
parents:
321
diff
changeset
|
1624 genesis_context * gen = context->system; |
1b00258b1f29
Added some basic VDP debugging features to debugger. Fixed DMA enable bug
Mike Pavone <pavone@retrodev.com>
parents:
321
diff
changeset
|
1625 //VDP debug commands |
1b00258b1f29
Added some basic VDP debugging features to debugger. Fixed DMA enable bug
Mike Pavone <pavone@retrodev.com>
parents:
321
diff
changeset
|
1626 switch(input_buf[1]) |
1b00258b1f29
Added some basic VDP debugging features to debugger. Fixed DMA enable bug
Mike Pavone <pavone@retrodev.com>
parents:
321
diff
changeset
|
1627 { |
1b00258b1f29
Added some basic VDP debugging features to debugger. Fixed DMA enable bug
Mike Pavone <pavone@retrodev.com>
parents:
321
diff
changeset
|
1628 case 's': |
1b00258b1f29
Added some basic VDP debugging features to debugger. Fixed DMA enable bug
Mike Pavone <pavone@retrodev.com>
parents:
321
diff
changeset
|
1629 vdp_print_sprite_table(gen->vdp); |
1b00258b1f29
Added some basic VDP debugging features to debugger. Fixed DMA enable bug
Mike Pavone <pavone@retrodev.com>
parents:
321
diff
changeset
|
1630 break; |
1b00258b1f29
Added some basic VDP debugging features to debugger. Fixed DMA enable bug
Mike Pavone <pavone@retrodev.com>
parents:
321
diff
changeset
|
1631 case 'r': |
1b00258b1f29
Added some basic VDP debugging features to debugger. Fixed DMA enable bug
Mike Pavone <pavone@retrodev.com>
parents:
321
diff
changeset
|
1632 vdp_print_reg_explain(gen->vdp); |
1b00258b1f29
Added some basic VDP debugging features to debugger. Fixed DMA enable bug
Mike Pavone <pavone@retrodev.com>
parents:
321
diff
changeset
|
1633 break; |
1b00258b1f29
Added some basic VDP debugging features to debugger. Fixed DMA enable bug
Mike Pavone <pavone@retrodev.com>
parents:
321
diff
changeset
|
1634 } |
1b00258b1f29
Added some basic VDP debugging features to debugger. Fixed DMA enable bug
Mike Pavone <pavone@retrodev.com>
parents:
321
diff
changeset
|
1635 break; |
1b00258b1f29
Added some basic VDP debugging features to debugger. Fixed DMA enable bug
Mike Pavone <pavone@retrodev.com>
parents:
321
diff
changeset
|
1636 } |
366
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1637 case 'z': { |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1638 genesis_context * gen = context->system; |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1639 //Z80 debug commands |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1640 switch(input_buf[1]) |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1641 { |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1642 case 'b': |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1643 param = find_param(input_buf); |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1644 if (!param) { |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1645 fputs("zb command requires a parameter\n", stderr); |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1646 break; |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1647 } |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1648 value = strtol(param, NULL, 16); |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1649 zinsert_breakpoint(gen->z80, value, (uint8_t *)zdebugger); |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1650 new_bp = malloc(sizeof(bp_def)); |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1651 new_bp->next = zbreakpoints; |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1652 new_bp->address = value; |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1653 new_bp->index = zbp_index++; |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1654 zbreakpoints = new_bp; |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1655 printf("Z80 Breakpoint %d set at %X\n", new_bp->index, value); |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1656 break; |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1657 } |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1658 break; |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1659 } |
184
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1660 case 'q': |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1661 puts("Quitting"); |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1662 exit(0); |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1663 break; |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1664 default: |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1665 fprintf(stderr, "Unrecognized debugger command %s\n", input_buf); |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1666 break; |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1667 } |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1668 } |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1669 return context; |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1670 } |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1671 |
351
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
1672 #define ROM_END 0x1A4 |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
1673 #define RAM_ID 0x1B0 |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
1674 #define RAM_FLAGS 0x1B2 |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
1675 #define RAM_START 0x1B4 |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
1676 #define RAM_END 0x1B8 |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
1677 #define MAX_MAP_CHUNKS (4+7+1) |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
1678 #define RAM_FLAG_MASK 0x1800 |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
1679 |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
1680 const memmap_chunk static_map[] = { |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
1681 {0, 0x400000, 0xFFFFFF, 0, MMAP_READ, cart, |
343
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
1682 NULL, NULL, NULL, NULL}, |
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
1683 {0xE00000, 0x1000000, 0xFFFF, 0, MMAP_READ | MMAP_WRITE | MMAP_CODE, ram, |
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
1684 NULL, NULL, NULL, NULL}, |
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
1685 {0xC00000, 0xE00000, 0x1FFFFF, 0, 0, NULL, |
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
1686 (read_16_fun)vdp_port_read, (write_16_fun)vdp_port_write, |
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
1687 (read_8_fun)vdp_port_read_b, (write_8_fun)vdp_port_write_b}, |
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
1688 {0xA00000, 0xA12000, 0x1FFFF, 0, 0, NULL, |
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
1689 (read_16_fun)io_read_w, (write_16_fun)io_write_w, |
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
1690 (read_8_fun)io_read, (write_8_fun)io_write} |
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
1691 }; |
351
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
1692 |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
1693 char * sram_filename; |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
1694 genesis_context * genesis; |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
1695 void save_sram() |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
1696 { |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
1697 FILE * f = fopen(sram_filename, "wb"); |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
1698 if (!f) { |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
1699 fprintf(stderr, "Failed to open SRAM file %s for writing\n", sram_filename); |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
1700 return; |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
1701 } |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
1702 uint32_t size = genesis->save_ram_mask+1; |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
1703 if (genesis->save_flags != RAM_FLAG_BOTH) { |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
1704 size/= 2; |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
1705 } |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
1706 fwrite(genesis->save_ram, 1, size, f); |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
1707 fclose(f); |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
1708 printf("Saved SRAM to %s\n", sram_filename); |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
1709 } |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
1710 |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
1711 void init_run_cpu(genesis_context * gen, int debug, FILE * address_log) |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
1712 { |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
1713 m68k_context context; |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
1714 x86_68k_options opts; |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
1715 gen->m68k = &context; |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
1716 memmap_chunk memmap[MAX_MAP_CHUNKS]; |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
1717 uint32_t num_chunks; |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
1718 void * initial_mapped = NULL; |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
1719 gen->save_ram = NULL; |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
1720 //TODO: Handle carts larger than 4MB |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
1721 //TODO: Handle non-standard mappers |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
1722 uint32_t size; |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
1723 if ((cart[RAM_ID/2] & 0xFF) == 'A' && (cart[RAM_ID/2] >> 8) == 'R') { |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
1724 //Cart has save RAM |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
1725 uint32_t rom_end = ((cart[ROM_END/2] << 16) | cart[ROM_END/2+1]) + 1; |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
1726 uint32_t ram_start = (cart[RAM_START/2] << 16) | cart[RAM_START/2+1]; |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
1727 uint32_t ram_end = (cart[RAM_END/2] << 16) | cart[RAM_END/2+1]; |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
1728 uint16_t ram_flags = cart[RAM_FLAGS/2]; |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
1729 gen->save_flags = ram_flags & RAM_FLAG_MASK; |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
1730 memset(memmap, 0, sizeof(memmap_chunk)*2); |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
1731 if (ram_start >= rom_end) { |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
1732 memmap[0].end = rom_end; |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
1733 memmap[0].mask = 0xFFFFFF; |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
1734 memmap[0].flags = MMAP_READ; |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
1735 memmap[0].buffer = cart; |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
1736 |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
1737 ram_start &= 0xFFFFFE; |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
1738 ram_end |= 1; |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
1739 memmap[1].start = ram_start; |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
1740 gen->save_ram_mask = memmap[1].mask = ram_end-ram_start; |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
1741 ram_end += 1; |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
1742 memmap[1].end = ram_end; |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
1743 memmap[1].flags = MMAP_READ | MMAP_WRITE; |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
1744 size = ram_end-ram_start; |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
1745 if ((ram_flags & RAM_FLAG_MASK) == RAM_FLAG_ODD) { |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
1746 memmap[1].flags |= MMAP_ONLY_ODD; |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
1747 size /= 2; |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
1748 } else if((ram_flags & RAM_FLAG_MASK) == RAM_FLAG_EVEN) { |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
1749 memmap[1].flags |= MMAP_ONLY_EVEN; |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
1750 size /= 2; |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
1751 } |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
1752 memmap[1].buffer = gen->save_ram = malloc(size); |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
1753 |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
1754 memcpy(memmap+2, static_map+1, sizeof(static_map)-sizeof(static_map[0])); |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
1755 num_chunks = sizeof(static_map)/sizeof(memmap_chunk)+1; |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
1756 } else { |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
1757 //Assume the standard Sega mapper for now |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
1758 memmap[0].end = 0x200000; |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
1759 memmap[0].mask = 0xFFFFFF; |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
1760 memmap[0].flags = MMAP_READ; |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
1761 memmap[0].buffer = cart; |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
1762 |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
1763 memmap[1].start = 0x200000; |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
1764 memmap[1].end = 0x400000; |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
1765 memmap[1].mask = 0x1FFFFF; |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
1766 ram_start &= 0xFFFFFE; |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
1767 ram_end |= 1; |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
1768 gen->save_ram_mask = ram_end-ram_start; |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
1769 memmap[1].flags = MMAP_READ | MMAP_PTR_IDX | MMAP_FUNC_NULL; |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
1770 memmap[1].ptr_index = 2; |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
1771 memmap[1].read_16 = (read_16_fun)read_sram_w;//these will only be called when mem_pointers[2] == NULL |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
1772 memmap[1].read_8 = (read_8_fun)read_sram_b; |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
1773 memmap[1].write_16 = (write_16_fun)write_sram_area_w;//these will be called all writes to the area |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
1774 memmap[1].write_8 = (write_8_fun)write_sram_area_b; |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
1775 memcpy(memmap+2, static_map+1, sizeof(static_map)-sizeof(static_map[0])); |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
1776 num_chunks = sizeof(static_map)/sizeof(memmap_chunk)+1; |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
1777 memset(memmap+num_chunks, 0, sizeof(memmap[num_chunks])); |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
1778 memmap[num_chunks].start = 0xA13000; |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
1779 memmap[num_chunks].end = 0xA13100; |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
1780 memmap[num_chunks].mask = 0xFF; |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
1781 memmap[num_chunks].write_16 = (write_16_fun)write_bank_reg_w; |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
1782 memmap[num_chunks].write_8 = (write_8_fun)write_bank_reg_b; |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
1783 num_chunks++; |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
1784 ram_end++; |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
1785 size = ram_end-ram_start; |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
1786 if ((ram_flags & RAM_FLAG_MASK) != RAM_FLAG_BOTH) { |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
1787 size /= 2; |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
1788 } |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
1789 gen->save_ram = malloc(size); |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
1790 memmap[1].buffer = initial_mapped = cart + 0x200000/2; |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
1791 } |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
1792 } else { |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
1793 memcpy(memmap, static_map, sizeof(static_map)); |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
1794 num_chunks = sizeof(static_map)/sizeof(memmap_chunk); |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
1795 } |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
1796 if (gen->save_ram) { |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
1797 memset(gen->save_ram, 0, size); |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
1798 FILE * f = fopen(sram_filename, "rb"); |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
1799 if (f) { |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
1800 uint32_t read = fread(gen->save_ram, 1, size, f); |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
1801 fclose(f); |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
1802 if (read > 0) { |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
1803 printf("Loaded SRAM from %s\n", sram_filename); |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
1804 } |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
1805 } |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
1806 atexit(save_sram); |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
1807 } |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
1808 init_x86_68k_opts(&opts, memmap, num_chunks); |
211 | 1809 opts.address_log = address_log; |
1810 init_68k_context(&context, opts.native_code_map, &opts); | |
1811 | |
288
a8ee7934a1f8
Add a YM2612 stub implementation with just timers and status registers so that games that depend on it can run.
Mike Pavone <pavone@retrodev.com>
parents:
280
diff
changeset
|
1812 context.video_context = gen->vdp; |
a8ee7934a1f8
Add a YM2612 stub implementation with just timers and status registers so that games that depend on it can run.
Mike Pavone <pavone@retrodev.com>
parents:
280
diff
changeset
|
1813 context.system = gen; |
211 | 1814 //cartridge ROM |
1815 context.mem_pointers[0] = cart; | |
342
13f994c88c34
Get frame time correct and frame rate sort of correct for EUR region
Mike Pavone <pavone@retrodev.com>
parents:
341
diff
changeset
|
1816 context.target_cycle = context.sync_cycle = mclks_per_frame/MCLKS_PER_68K; |
211 | 1817 //work RAM |
1818 context.mem_pointers[1] = ram; | |
351
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
1819 //save RAM/map |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
1820 context.mem_pointers[2] = initial_mapped; |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
1821 context.mem_pointers[3] = (uint16_t *)gen->save_ram; |
211 | 1822 uint32_t address; |
1823 address = cart[2] << 16 | cart[3]; | |
1824 translate_m68k_stream(address, &context); | |
1825 if (debug) { | |
1826 insert_breakpoint(&context, address, (uint8_t *)debugger); | |
1827 } | |
1828 m68k_reset(&context); | |
1829 } | |
1830 | |
340
58a085cfc6bd
Set window title based on ROM header name
Mike Pavone <pavone@retrodev.com>
parents:
338
diff
changeset
|
1831 char title[64]; |
58a085cfc6bd
Set window title based on ROM header name
Mike Pavone <pavone@retrodev.com>
parents:
338
diff
changeset
|
1832 |
58a085cfc6bd
Set window title based on ROM header name
Mike Pavone <pavone@retrodev.com>
parents:
338
diff
changeset
|
1833 #define TITLE_START 0x150 |
58a085cfc6bd
Set window title based on ROM header name
Mike Pavone <pavone@retrodev.com>
parents:
338
diff
changeset
|
1834 #define TITLE_END (TITLE_START+48) |
58a085cfc6bd
Set window title based on ROM header name
Mike Pavone <pavone@retrodev.com>
parents:
338
diff
changeset
|
1835 |
58a085cfc6bd
Set window title based on ROM header name
Mike Pavone <pavone@retrodev.com>
parents:
338
diff
changeset
|
1836 void update_title() |
58a085cfc6bd
Set window title based on ROM header name
Mike Pavone <pavone@retrodev.com>
parents:
338
diff
changeset
|
1837 { |
58a085cfc6bd
Set window title based on ROM header name
Mike Pavone <pavone@retrodev.com>
parents:
338
diff
changeset
|
1838 uint16_t *last = cart + TITLE_END/2 - 1; |
58a085cfc6bd
Set window title based on ROM header name
Mike Pavone <pavone@retrodev.com>
parents:
338
diff
changeset
|
1839 while(last > cart + TITLE_START/2 && *last == 0x2020) |
58a085cfc6bd
Set window title based on ROM header name
Mike Pavone <pavone@retrodev.com>
parents:
338
diff
changeset
|
1840 { |
58a085cfc6bd
Set window title based on ROM header name
Mike Pavone <pavone@retrodev.com>
parents:
338
diff
changeset
|
1841 last--; |
58a085cfc6bd
Set window title based on ROM header name
Mike Pavone <pavone@retrodev.com>
parents:
338
diff
changeset
|
1842 } |
58a085cfc6bd
Set window title based on ROM header name
Mike Pavone <pavone@retrodev.com>
parents:
338
diff
changeset
|
1843 uint16_t *start = cart + TITLE_START/2; |
58a085cfc6bd
Set window title based on ROM header name
Mike Pavone <pavone@retrodev.com>
parents:
338
diff
changeset
|
1844 char *cur = title; |
58a085cfc6bd
Set window title based on ROM header name
Mike Pavone <pavone@retrodev.com>
parents:
338
diff
changeset
|
1845 char last_char = ' '; |
58a085cfc6bd
Set window title based on ROM header name
Mike Pavone <pavone@retrodev.com>
parents:
338
diff
changeset
|
1846 for (; start != last; start++) |
58a085cfc6bd
Set window title based on ROM header name
Mike Pavone <pavone@retrodev.com>
parents:
338
diff
changeset
|
1847 { |
58a085cfc6bd
Set window title based on ROM header name
Mike Pavone <pavone@retrodev.com>
parents:
338
diff
changeset
|
1848 if ((last_char != ' ' || (*start >> 8) != ' ') && (*start >> 8) < 0x80) { |
58a085cfc6bd
Set window title based on ROM header name
Mike Pavone <pavone@retrodev.com>
parents:
338
diff
changeset
|
1849 *(cur++) = *start >> 8; |
58a085cfc6bd
Set window title based on ROM header name
Mike Pavone <pavone@retrodev.com>
parents:
338
diff
changeset
|
1850 last_char = *start >> 8; |
58a085cfc6bd
Set window title based on ROM header name
Mike Pavone <pavone@retrodev.com>
parents:
338
diff
changeset
|
1851 } |
58a085cfc6bd
Set window title based on ROM header name
Mike Pavone <pavone@retrodev.com>
parents:
338
diff
changeset
|
1852 if (last_char != ' ' || (*start & 0xFF) != ' ' && (*start & 0xFF) < 0x80) { |
58a085cfc6bd
Set window title based on ROM header name
Mike Pavone <pavone@retrodev.com>
parents:
338
diff
changeset
|
1853 *(cur++) = *start; |
58a085cfc6bd
Set window title based on ROM header name
Mike Pavone <pavone@retrodev.com>
parents:
338
diff
changeset
|
1854 last_char = *start & 0xFF; |
58a085cfc6bd
Set window title based on ROM header name
Mike Pavone <pavone@retrodev.com>
parents:
338
diff
changeset
|
1855 } |
58a085cfc6bd
Set window title based on ROM header name
Mike Pavone <pavone@retrodev.com>
parents:
338
diff
changeset
|
1856 } |
58a085cfc6bd
Set window title based on ROM header name
Mike Pavone <pavone@retrodev.com>
parents:
338
diff
changeset
|
1857 *(cur++) = *start >> 8; |
58a085cfc6bd
Set window title based on ROM header name
Mike Pavone <pavone@retrodev.com>
parents:
338
diff
changeset
|
1858 if ((*start & 0xFF) != ' ') { |
58a085cfc6bd
Set window title based on ROM header name
Mike Pavone <pavone@retrodev.com>
parents:
338
diff
changeset
|
1859 *(cur++) = *start; |
58a085cfc6bd
Set window title based on ROM header name
Mike Pavone <pavone@retrodev.com>
parents:
338
diff
changeset
|
1860 } |
58a085cfc6bd
Set window title based on ROM header name
Mike Pavone <pavone@retrodev.com>
parents:
338
diff
changeset
|
1861 strcpy(cur, " - BlastEm"); |
58a085cfc6bd
Set window title based on ROM header name
Mike Pavone <pavone@retrodev.com>
parents:
338
diff
changeset
|
1862 } |
58a085cfc6bd
Set window title based on ROM header name
Mike Pavone <pavone@retrodev.com>
parents:
338
diff
changeset
|
1863 |
341
6ad8e36de685
Support regions other than USA
Mike Pavone <pavone@retrodev.com>
parents:
340
diff
changeset
|
1864 #define REGION_START 0x1F0 |
6ad8e36de685
Support regions other than USA
Mike Pavone <pavone@retrodev.com>
parents:
340
diff
changeset
|
1865 |
6ad8e36de685
Support regions other than USA
Mike Pavone <pavone@retrodev.com>
parents:
340
diff
changeset
|
1866 int detect_specific_region(char region) |
6ad8e36de685
Support regions other than USA
Mike Pavone <pavone@retrodev.com>
parents:
340
diff
changeset
|
1867 { |
346
aff29d50afd5
Fix a region detection bug
Mike Pavone <pavone@retrodev.com>
parents:
345
diff
changeset
|
1868 return (cart[REGION_START/2] & 0xFF) == region || (cart[REGION_START/2] >> 8) == region || (cart[REGION_START/2+1] & 0xFF) == region; |
341
6ad8e36de685
Support regions other than USA
Mike Pavone <pavone@retrodev.com>
parents:
340
diff
changeset
|
1869 } |
6ad8e36de685
Support regions other than USA
Mike Pavone <pavone@retrodev.com>
parents:
340
diff
changeset
|
1870 |
6ad8e36de685
Support regions other than USA
Mike Pavone <pavone@retrodev.com>
parents:
340
diff
changeset
|
1871 void detect_region() |
6ad8e36de685
Support regions other than USA
Mike Pavone <pavone@retrodev.com>
parents:
340
diff
changeset
|
1872 { |
343
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
1873 if (detect_specific_region('U')|| detect_specific_region('B') || detect_specific_region('4')) { |
341
6ad8e36de685
Support regions other than USA
Mike Pavone <pavone@retrodev.com>
parents:
340
diff
changeset
|
1874 version_reg = NO_DISK | USA; |
6ad8e36de685
Support regions other than USA
Mike Pavone <pavone@retrodev.com>
parents:
340
diff
changeset
|
1875 } else if (detect_specific_region('J')) { |
6ad8e36de685
Support regions other than USA
Mike Pavone <pavone@retrodev.com>
parents:
340
diff
changeset
|
1876 version_reg = NO_DISK | JAP; |
343
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
1877 } else if (detect_specific_region('E') || detect_specific_region('A')) { |
341
6ad8e36de685
Support regions other than USA
Mike Pavone <pavone@retrodev.com>
parents:
340
diff
changeset
|
1878 version_reg = NO_DISK | EUR; |
6ad8e36de685
Support regions other than USA
Mike Pavone <pavone@retrodev.com>
parents:
340
diff
changeset
|
1879 } |
6ad8e36de685
Support regions other than USA
Mike Pavone <pavone@retrodev.com>
parents:
340
diff
changeset
|
1880 } |
6ad8e36de685
Support regions other than USA
Mike Pavone <pavone@retrodev.com>
parents:
340
diff
changeset
|
1881 |
88
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1882 int main(int argc, char ** argv) |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1883 { |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1884 if (argc < 2) { |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1885 fputs("Usage: blastem FILENAME\n", stderr); |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1886 return 1; |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1887 } |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1888 if(!load_rom(argv[1])) { |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1889 fprintf(stderr, "Failed to open %s for reading\n", argv[1]); |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1890 return 1; |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1891 } |
341
6ad8e36de685
Support regions other than USA
Mike Pavone <pavone@retrodev.com>
parents:
340
diff
changeset
|
1892 detect_region(); |
184
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1893 int width = -1; |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1894 int height = -1; |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1895 int debug = 0; |
197
7c227a8ec53d
Add instruction address logging to translator and support for reading an address log to the disassembler
Mike Pavone <pavone@retrodev.com>
parents:
195
diff
changeset
|
1896 FILE *address_log = NULL; |
184
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1897 for (int i = 2; i < argc; i++) { |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1898 if (argv[i][0] == '-') { |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1899 switch(argv[i][1]) { |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1900 case 'd': |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1901 debug = 1; |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1902 break; |
338
5c34a9c39394
Re-enable frame limit, but add a command line flag to disable it
Mike Pavone <pavone@retrodev.com>
parents:
336
diff
changeset
|
1903 case 'f': |
356
79e4b466e7d0
Get rid of debug puts and limit based on audio rather than frame rate by default.
Mike Pavone <pavone@retrodev.com>
parents:
354
diff
changeset
|
1904 frame_limit = 1; |
338
5c34a9c39394
Re-enable frame limit, but add a command line flag to disable it
Mike Pavone <pavone@retrodev.com>
parents:
336
diff
changeset
|
1905 break; |
197
7c227a8ec53d
Add instruction address logging to translator and support for reading an address log to the disassembler
Mike Pavone <pavone@retrodev.com>
parents:
195
diff
changeset
|
1906 case 'l': |
7c227a8ec53d
Add instruction address logging to translator and support for reading an address log to the disassembler
Mike Pavone <pavone@retrodev.com>
parents:
195
diff
changeset
|
1907 address_log = fopen("address.log", "w"); |
7c227a8ec53d
Add instruction address logging to translator and support for reading an address log to the disassembler
Mike Pavone <pavone@retrodev.com>
parents:
195
diff
changeset
|
1908 break; |
215
2b1c2c28b261
Added headless flag to avoid initializing SDL and opening a window when running tests.
Mike Pavone <pavone@retrodev.com>
parents:
211
diff
changeset
|
1909 case 'v': |
2b1c2c28b261
Added headless flag to avoid initializing SDL and opening a window when running tests.
Mike Pavone <pavone@retrodev.com>
parents:
211
diff
changeset
|
1910 headless = 1; |
2b1c2c28b261
Added headless flag to avoid initializing SDL and opening a window when running tests.
Mike Pavone <pavone@retrodev.com>
parents:
211
diff
changeset
|
1911 break; |
265
c6d12878ea93
Add -n flag for disabling the Z80 core
Mike Pavone <pavone@retrodev.com>
parents:
264
diff
changeset
|
1912 case 'n': |
c6d12878ea93
Add -n flag for disabling the Z80 core
Mike Pavone <pavone@retrodev.com>
parents:
264
diff
changeset
|
1913 z80_enabled = 0; |
c6d12878ea93
Add -n flag for disabling the Z80 core
Mike Pavone <pavone@retrodev.com>
parents:
264
diff
changeset
|
1914 break; |
341
6ad8e36de685
Support regions other than USA
Mike Pavone <pavone@retrodev.com>
parents:
340
diff
changeset
|
1915 case 'r': |
6ad8e36de685
Support regions other than USA
Mike Pavone <pavone@retrodev.com>
parents:
340
diff
changeset
|
1916 i++; |
6ad8e36de685
Support regions other than USA
Mike Pavone <pavone@retrodev.com>
parents:
340
diff
changeset
|
1917 if (i >= argc) { |
6ad8e36de685
Support regions other than USA
Mike Pavone <pavone@retrodev.com>
parents:
340
diff
changeset
|
1918 fputs("-r must be followed by region (J, U or E)\n", stderr); |
6ad8e36de685
Support regions other than USA
Mike Pavone <pavone@retrodev.com>
parents:
340
diff
changeset
|
1919 return 1; |
6ad8e36de685
Support regions other than USA
Mike Pavone <pavone@retrodev.com>
parents:
340
diff
changeset
|
1920 } |
6ad8e36de685
Support regions other than USA
Mike Pavone <pavone@retrodev.com>
parents:
340
diff
changeset
|
1921 switch (argv[i][0]) |
6ad8e36de685
Support regions other than USA
Mike Pavone <pavone@retrodev.com>
parents:
340
diff
changeset
|
1922 { |
6ad8e36de685
Support regions other than USA
Mike Pavone <pavone@retrodev.com>
parents:
340
diff
changeset
|
1923 case 'j': |
6ad8e36de685
Support regions other than USA
Mike Pavone <pavone@retrodev.com>
parents:
340
diff
changeset
|
1924 case 'J': |
6ad8e36de685
Support regions other than USA
Mike Pavone <pavone@retrodev.com>
parents:
340
diff
changeset
|
1925 version_reg = NO_DISK | JAP; |
6ad8e36de685
Support regions other than USA
Mike Pavone <pavone@retrodev.com>
parents:
340
diff
changeset
|
1926 break; |
6ad8e36de685
Support regions other than USA
Mike Pavone <pavone@retrodev.com>
parents:
340
diff
changeset
|
1927 case 'u': |
6ad8e36de685
Support regions other than USA
Mike Pavone <pavone@retrodev.com>
parents:
340
diff
changeset
|
1928 case 'U': |
6ad8e36de685
Support regions other than USA
Mike Pavone <pavone@retrodev.com>
parents:
340
diff
changeset
|
1929 version_reg = NO_DISK | USA; |
6ad8e36de685
Support regions other than USA
Mike Pavone <pavone@retrodev.com>
parents:
340
diff
changeset
|
1930 break; |
6ad8e36de685
Support regions other than USA
Mike Pavone <pavone@retrodev.com>
parents:
340
diff
changeset
|
1931 case 'e': |
6ad8e36de685
Support regions other than USA
Mike Pavone <pavone@retrodev.com>
parents:
340
diff
changeset
|
1932 case 'E': |
6ad8e36de685
Support regions other than USA
Mike Pavone <pavone@retrodev.com>
parents:
340
diff
changeset
|
1933 version_reg = NO_DISK | EUR; |
6ad8e36de685
Support regions other than USA
Mike Pavone <pavone@retrodev.com>
parents:
340
diff
changeset
|
1934 break; |
6ad8e36de685
Support regions other than USA
Mike Pavone <pavone@retrodev.com>
parents:
340
diff
changeset
|
1935 default: |
6ad8e36de685
Support regions other than USA
Mike Pavone <pavone@retrodev.com>
parents:
340
diff
changeset
|
1936 fprintf(stderr, "'%c' is not a valid region character for the -r option\n", argv[i][0]); |
6ad8e36de685
Support regions other than USA
Mike Pavone <pavone@retrodev.com>
parents:
340
diff
changeset
|
1937 return 1; |
6ad8e36de685
Support regions other than USA
Mike Pavone <pavone@retrodev.com>
parents:
340
diff
changeset
|
1938 } |
6ad8e36de685
Support regions other than USA
Mike Pavone <pavone@retrodev.com>
parents:
340
diff
changeset
|
1939 break; |
184
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1940 default: |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1941 fprintf(stderr, "Unrecognized switch %s\n", argv[i]); |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1942 return 1; |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1943 } |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1944 } else if (width < 0) { |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1945 width = atoi(argv[i]); |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1946 } else if (height < 0) { |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1947 height = atoi(argv[i]); |
88
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1948 } |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1949 } |
340
58a085cfc6bd
Set window title based on ROM header name
Mike Pavone <pavone@retrodev.com>
parents:
338
diff
changeset
|
1950 update_title(); |
184
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1951 width = width < 320 ? 320 : width; |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1952 height = height < 240 ? (width/320) * 240 : height; |
354
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
351
diff
changeset
|
1953 uint32_t fps = 60; |
342
13f994c88c34
Get frame time correct and frame rate sort of correct for EUR region
Mike Pavone <pavone@retrodev.com>
parents:
341
diff
changeset
|
1954 if (version_reg & 0x40) { |
13f994c88c34
Get frame time correct and frame rate sort of correct for EUR region
Mike Pavone <pavone@retrodev.com>
parents:
341
diff
changeset
|
1955 mclks_per_frame = MCLKS_LINE * LINES_PAL; |
354
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
351
diff
changeset
|
1956 fps = 50; |
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
351
diff
changeset
|
1957 } |
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
351
diff
changeset
|
1958 if (!headless) { |
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
351
diff
changeset
|
1959 render_init(width, height, title, fps); |
342
13f994c88c34
Get frame time correct and frame rate sort of correct for EUR region
Mike Pavone <pavone@retrodev.com>
parents:
341
diff
changeset
|
1960 } |
88
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1961 vdp_context v_context; |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1962 |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1963 init_vdp_context(&v_context); |
260
625f8e4d5fd2
Initial stab at integartiong Z80 core
Mike Pavone <pavone@retrodev.com>
parents:
215
diff
changeset
|
1964 |
288
a8ee7934a1f8
Add a YM2612 stub implementation with just timers and status registers so that games that depend on it can run.
Mike Pavone <pavone@retrodev.com>
parents:
280
diff
changeset
|
1965 ym2612_context y_context; |
380
1c8d74f2ab0b
Make the PSG and YM2612 use the master clock internal with an increment based on clock divider so that they stay perflectly in sync. Run both the PSG and YM2612 whenver one of them needs to be run.
Mike Pavone <pavone@retrodev.com>
parents:
374
diff
changeset
|
1966 ym_init(&y_context, render_sample_rate(), fps == 60 ? MCLKS_NTSC : MCLKS_PAL, MCLKS_PER_YM, render_audio_buffer()); |
288
a8ee7934a1f8
Add a YM2612 stub implementation with just timers and status registers so that games that depend on it can run.
Mike Pavone <pavone@retrodev.com>
parents:
280
diff
changeset
|
1967 |
354
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
351
diff
changeset
|
1968 psg_context p_context; |
380
1c8d74f2ab0b
Make the PSG and YM2612 use the master clock internal with an increment based on clock divider so that they stay perflectly in sync. Run both the PSG and YM2612 whenver one of them needs to be run.
Mike Pavone <pavone@retrodev.com>
parents:
374
diff
changeset
|
1969 psg_init(&p_context, render_sample_rate(), fps == 60 ? MCLKS_NTSC : MCLKS_PAL, MCLKS_PER_PSG, render_audio_buffer()); |
354
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
351
diff
changeset
|
1970 |
260
625f8e4d5fd2
Initial stab at integartiong Z80 core
Mike Pavone <pavone@retrodev.com>
parents:
215
diff
changeset
|
1971 z80_context z_context; |
625f8e4d5fd2
Initial stab at integartiong Z80 core
Mike Pavone <pavone@retrodev.com>
parents:
215
diff
changeset
|
1972 x86_z80_options z_opts; |
625f8e4d5fd2
Initial stab at integartiong Z80 core
Mike Pavone <pavone@retrodev.com>
parents:
215
diff
changeset
|
1973 init_x86_z80_opts(&z_opts); |
625f8e4d5fd2
Initial stab at integartiong Z80 core
Mike Pavone <pavone@retrodev.com>
parents:
215
diff
changeset
|
1974 init_z80_context(&z_context, &z_opts); |
290
171f97e70d85
Implement writes from Z80 to YM-2612
Mike Pavone <pavone@retrodev.com>
parents:
289
diff
changeset
|
1975 |
171f97e70d85
Implement writes from Z80 to YM-2612
Mike Pavone <pavone@retrodev.com>
parents:
289
diff
changeset
|
1976 genesis_context gen; |
171f97e70d85
Implement writes from Z80 to YM-2612
Mike Pavone <pavone@retrodev.com>
parents:
289
diff
changeset
|
1977 |
171f97e70d85
Implement writes from Z80 to YM-2612
Mike Pavone <pavone@retrodev.com>
parents:
289
diff
changeset
|
1978 z_context.system = &gen; |
260
625f8e4d5fd2
Initial stab at integartiong Z80 core
Mike Pavone <pavone@retrodev.com>
parents:
215
diff
changeset
|
1979 z_context.mem_pointers[0] = z80_ram; |
342
13f994c88c34
Get frame time correct and frame rate sort of correct for EUR region
Mike Pavone <pavone@retrodev.com>
parents:
341
diff
changeset
|
1980 z_context.sync_cycle = z_context.target_cycle = mclks_per_frame/MCLKS_PER_Z80; |
260
625f8e4d5fd2
Initial stab at integartiong Z80 core
Mike Pavone <pavone@retrodev.com>
parents:
215
diff
changeset
|
1981 z_context.int_cycle = CYCLE_NEVER; |
625f8e4d5fd2
Initial stab at integartiong Z80 core
Mike Pavone <pavone@retrodev.com>
parents:
215
diff
changeset
|
1982 z_context.mem_pointers[1] = z_context.mem_pointers[2] = (uint8_t *)cart; |
625f8e4d5fd2
Initial stab at integartiong Z80 core
Mike Pavone <pavone@retrodev.com>
parents:
215
diff
changeset
|
1983 |
288
a8ee7934a1f8
Add a YM2612 stub implementation with just timers and status registers so that games that depend on it can run.
Mike Pavone <pavone@retrodev.com>
parents:
280
diff
changeset
|
1984 gen.z80 = &z_context; |
a8ee7934a1f8
Add a YM2612 stub implementation with just timers and status registers so that games that depend on it can run.
Mike Pavone <pavone@retrodev.com>
parents:
280
diff
changeset
|
1985 gen.vdp = &v_context; |
a8ee7934a1f8
Add a YM2612 stub implementation with just timers and status registers so that games that depend on it can run.
Mike Pavone <pavone@retrodev.com>
parents:
280
diff
changeset
|
1986 gen.ym = &y_context; |
354
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
351
diff
changeset
|
1987 gen.psg = &p_context; |
351
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
1988 genesis = &gen; |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
1989 |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
1990 int fname_size = strlen(argv[1]); |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
1991 sram_filename = malloc(fname_size+6); |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
1992 memcpy(sram_filename, argv[1], fname_size); |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
1993 int i; |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
1994 for (i = fname_size-1; fname_size >= 0; --i) { |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
1995 if (sram_filename[i] == '.') { |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
1996 strcpy(sram_filename + i + 1, "sram"); |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
1997 break; |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
1998 } |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
1999 } |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
2000 if (i < 0) { |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
2001 strcpy(sram_filename + fname_size, ".sram"); |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
2002 } |
288
a8ee7934a1f8
Add a YM2612 stub implementation with just timers and status registers so that games that depend on it can run.
Mike Pavone <pavone@retrodev.com>
parents:
280
diff
changeset
|
2003 |
a8ee7934a1f8
Add a YM2612 stub implementation with just timers and status registers so that games that depend on it can run.
Mike Pavone <pavone@retrodev.com>
parents:
280
diff
changeset
|
2004 init_run_cpu(&gen, debug, address_log); |
88
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
2005 return 0; |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
2006 } |