Mercurial > repos > blastem
annotate blastem.c @ 401:f54af24aad1d
Fix DI
author | Mike Pavone <pavone@retrodev.com> |
---|---|
date | Sat, 15 Jun 2013 23:10:48 -0700 |
parents | c26e48a93fa3 |
children | de2c085ce174 |
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 |
398
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
395
diff
changeset
|
991 enum { |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
395
diff
changeset
|
992 BIND_NONE, |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
395
diff
changeset
|
993 BIND_GAMEPAD1, |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
395
diff
changeset
|
994 BIND_GAMEPAD2, |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
395
diff
changeset
|
995 BIND_UI |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
395
diff
changeset
|
996 }; |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
395
diff
changeset
|
997 |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
395
diff
changeset
|
998 typedef enum { |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
395
diff
changeset
|
999 UI_DEBUG_MODE_INC, |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
395
diff
changeset
|
1000 UI_DEBUG_PAL_INC, |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
395
diff
changeset
|
1001 UI_ENTER_DEBUGGER |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
395
diff
changeset
|
1002 } ui_action; |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
395
diff
changeset
|
1003 |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
395
diff
changeset
|
1004 typedef struct { |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
395
diff
changeset
|
1005 uint8_t bind_type; |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
395
diff
changeset
|
1006 uint8_t subtype_a; |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
395
diff
changeset
|
1007 uint8_t subtype_b; |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
395
diff
changeset
|
1008 uint8_t value; |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
395
diff
changeset
|
1009 } keybinding; |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
395
diff
changeset
|
1010 |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
395
diff
changeset
|
1011 keybinding * bindings[256]; |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
395
diff
changeset
|
1012 |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
395
diff
changeset
|
1013 void bind_key(int keycode, uint8_t bind_type, uint8_t subtype_a, uint8_t subtype_b, uint8_t value) |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
395
diff
changeset
|
1014 { |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
395
diff
changeset
|
1015 int bucket = keycode >> 8 & 0xFF; |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
395
diff
changeset
|
1016 if (!bindings[bucket]) { |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
395
diff
changeset
|
1017 bindings[bucket] = malloc(sizeof(keybinding) * 256); |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
395
diff
changeset
|
1018 memset(bindings[bucket], 0, sizeof(keybinding) * 256); |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
395
diff
changeset
|
1019 } |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
395
diff
changeset
|
1020 int idx = keycode & 0xFF; |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
395
diff
changeset
|
1021 bindings[bucket][idx].bind_type = bind_type; |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
395
diff
changeset
|
1022 bindings[bucket][idx].subtype_a = subtype_a; |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
395
diff
changeset
|
1023 bindings[bucket][idx].subtype_b = subtype_b; |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
395
diff
changeset
|
1024 bindings[bucket][idx].value = value; |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
395
diff
changeset
|
1025 } |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
395
diff
changeset
|
1026 |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
395
diff
changeset
|
1027 #define GAMEPAD_BUTTON(PRI_SLOT, SEC_SLOT, VALUE) (PRI_SLOT << 12 | SEC_SLOT << 8 | VALUE) |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
395
diff
changeset
|
1028 |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
395
diff
changeset
|
1029 #define DPAD_UP GAMEPAD_BUTTON(GAMEPAD_TH0, GAMEPAD_TH1, 0x01) |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
395
diff
changeset
|
1030 #define BUTTON_Z GAMEPAD_BUTTON(GAMEPAD_EXTRA, GAMEPAD_NONE, 0x01) |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
395
diff
changeset
|
1031 #define DPAD_DOWN GAMEPAD_BUTTON(GAMEPAD_TH0, GAMEPAD_TH1, 0x02) |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
395
diff
changeset
|
1032 #define BUTTON_Y GAMEPAD_BUTTON(GAMEPAD_EXTRA, GAMEPAD_NONE, 0x02) |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
395
diff
changeset
|
1033 #define DPAD_LEFT GAMEPAD_BUTTON(GAMEPAD_TH1, GAMEPAD_NONE, 0x04) |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
395
diff
changeset
|
1034 #define BUTTON_X GAMEPAD_BUTTON(GAMEPAD_EXTRA, GAMEPAD_NONE, 0x04) |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
395
diff
changeset
|
1035 #define DPAD_RIGHT GAMEPAD_BUTTON(GAMEPAD_TH1, GAMEPAD_NONE, 0x08) |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
395
diff
changeset
|
1036 #define BUTTON_MODE GAMEPAD_BUTTON(GAMEPAD_EXTRA, GAMEPAD_NONE, 0x08) |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
395
diff
changeset
|
1037 #define BUTTON_A GAMEPAD_BUTTON(GAMEPAD_TH0, GAMEPAD_NONE, 0x10) |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
395
diff
changeset
|
1038 #define BUTTON_B GAMEPAD_BUTTON(GAMEPAD_TH1, GAMEPAD_NONE, 0x10) |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
395
diff
changeset
|
1039 #define BUTTON_START GAMEPAD_BUTTON(GAMEPAD_TH0, GAMEPAD_NONE, 0x20) |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
395
diff
changeset
|
1040 #define BUTTON_C GAMEPAD_BUTTON(GAMEPAD_TH1, GAMEPAD_NONE, 0x20) |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
395
diff
changeset
|
1041 |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
395
diff
changeset
|
1042 void bind_gamepad(int keycode, int gamepadnum, int button) |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
395
diff
changeset
|
1043 { |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
395
diff
changeset
|
1044 |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
395
diff
changeset
|
1045 if (gamepadnum < 1 || gamepadnum > 2) { |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
395
diff
changeset
|
1046 return; |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
395
diff
changeset
|
1047 } |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
395
diff
changeset
|
1048 uint8_t bind_type = gamepadnum - 1 + BIND_GAMEPAD1; |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
395
diff
changeset
|
1049 bind_key(keycode, bind_type, button >> 12, button >> 8 & 0xF, button & 0xFF); |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
395
diff
changeset
|
1050 } |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
395
diff
changeset
|
1051 |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
395
diff
changeset
|
1052 void bind_ui(int keycode, ui_action action) |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
395
diff
changeset
|
1053 { |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
395
diff
changeset
|
1054 bind_key(keycode, BIND_UI, action, 0, 0); |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
395
diff
changeset
|
1055 } |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
395
diff
changeset
|
1056 |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
395
diff
changeset
|
1057 void handle_keydown(int keycode) |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
395
diff
changeset
|
1058 { |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
395
diff
changeset
|
1059 int bucket = keycode >> 8 & 0xFF; |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
395
diff
changeset
|
1060 if (!bindings[bucket]) { |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
395
diff
changeset
|
1061 return; |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
395
diff
changeset
|
1062 } |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
395
diff
changeset
|
1063 int idx = keycode & 0xFF; |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
395
diff
changeset
|
1064 keybinding * binding = bindings[bucket] + idx; |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
395
diff
changeset
|
1065 switch(binding->bind_type) |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
395
diff
changeset
|
1066 { |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
395
diff
changeset
|
1067 case BIND_GAMEPAD1: |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
395
diff
changeset
|
1068 if (binding->subtype_a <= GAMEPAD_EXTRA) { |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
395
diff
changeset
|
1069 gamepad_1.input[binding->subtype_a] |= binding->value; |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
395
diff
changeset
|
1070 } |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
395
diff
changeset
|
1071 if (binding->subtype_b <= GAMEPAD_EXTRA) { |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
395
diff
changeset
|
1072 gamepad_1.input[binding->subtype_b] |= binding->value; |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
395
diff
changeset
|
1073 } |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
395
diff
changeset
|
1074 break; |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
395
diff
changeset
|
1075 case BIND_GAMEPAD2: |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
395
diff
changeset
|
1076 if (binding->subtype_a <= GAMEPAD_EXTRA) { |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
395
diff
changeset
|
1077 gamepad_2.input[binding->subtype_a] |= binding->value; |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
395
diff
changeset
|
1078 } |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
395
diff
changeset
|
1079 if (binding->subtype_b <= GAMEPAD_EXTRA) { |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
395
diff
changeset
|
1080 gamepad_2.input[binding->subtype_b] |= binding->value; |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
395
diff
changeset
|
1081 } |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
395
diff
changeset
|
1082 break; |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
395
diff
changeset
|
1083 } |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
395
diff
changeset
|
1084 } |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
395
diff
changeset
|
1085 |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
395
diff
changeset
|
1086 uint8_t ui_debug_mode = 0; |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
395
diff
changeset
|
1087 uint8_t ui_debug_pal = 0; |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
395
diff
changeset
|
1088 |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
395
diff
changeset
|
1089 void handle_keyup(int keycode) |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
395
diff
changeset
|
1090 { |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
395
diff
changeset
|
1091 int bucket = keycode >> 8 & 0xFF; |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
395
diff
changeset
|
1092 if (!bindings[bucket]) { |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
395
diff
changeset
|
1093 return; |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
395
diff
changeset
|
1094 } |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
395
diff
changeset
|
1095 int idx = keycode & 0xFF; |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
395
diff
changeset
|
1096 keybinding * binding = bindings[bucket] + idx; |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
395
diff
changeset
|
1097 switch(binding->bind_type) |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
395
diff
changeset
|
1098 { |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
395
diff
changeset
|
1099 case BIND_GAMEPAD1: |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
395
diff
changeset
|
1100 if (binding->subtype_a <= GAMEPAD_EXTRA) { |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
395
diff
changeset
|
1101 gamepad_1.input[binding->subtype_a] &= ~binding->value; |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
395
diff
changeset
|
1102 } |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
395
diff
changeset
|
1103 if (binding->subtype_b <= GAMEPAD_EXTRA) { |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
395
diff
changeset
|
1104 gamepad_1.input[binding->subtype_b] &= ~binding->value; |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
395
diff
changeset
|
1105 } |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
395
diff
changeset
|
1106 break; |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
395
diff
changeset
|
1107 case BIND_GAMEPAD2: |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
395
diff
changeset
|
1108 if (binding->subtype_a <= GAMEPAD_EXTRA) { |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
395
diff
changeset
|
1109 gamepad_2.input[binding->subtype_a] &= ~binding->value; |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
395
diff
changeset
|
1110 } |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
395
diff
changeset
|
1111 if (binding->subtype_b <= GAMEPAD_EXTRA) { |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
395
diff
changeset
|
1112 gamepad_2.input[binding->subtype_b] &= ~binding->value; |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
395
diff
changeset
|
1113 } |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
395
diff
changeset
|
1114 break; |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
395
diff
changeset
|
1115 case BIND_UI: |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
395
diff
changeset
|
1116 switch (binding->subtype_a) |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
395
diff
changeset
|
1117 { |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
395
diff
changeset
|
1118 case UI_DEBUG_MODE_INC: |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
395
diff
changeset
|
1119 ui_debug_mode++; |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
395
diff
changeset
|
1120 if (ui_debug_mode == 4) { |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
395
diff
changeset
|
1121 ui_debug_mode = 0; |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
395
diff
changeset
|
1122 } |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
395
diff
changeset
|
1123 render_debug_mode(ui_debug_mode); |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
395
diff
changeset
|
1124 break; |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
395
diff
changeset
|
1125 case UI_DEBUG_PAL_INC: |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
395
diff
changeset
|
1126 ui_debug_pal++; |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
395
diff
changeset
|
1127 if (ui_debug_pal == 4) { |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
395
diff
changeset
|
1128 ui_debug_pal = 0; |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
395
diff
changeset
|
1129 } |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
395
diff
changeset
|
1130 render_debug_pal(ui_debug_pal); |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
395
diff
changeset
|
1131 break; |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
395
diff
changeset
|
1132 case UI_ENTER_DEBUGGER: |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
395
diff
changeset
|
1133 break_on_sync = 1; |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
395
diff
changeset
|
1134 break; |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
395
diff
changeset
|
1135 } |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
395
diff
changeset
|
1136 break; |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
395
diff
changeset
|
1137 } |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
395
diff
changeset
|
1138 } |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
395
diff
changeset
|
1139 |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
395
diff
changeset
|
1140 void set_keybindings() |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
395
diff
changeset
|
1141 { |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
395
diff
changeset
|
1142 bind_gamepad(RENDERKEY_UP, 1, DPAD_UP); |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
395
diff
changeset
|
1143 bind_gamepad(RENDERKEY_DOWN, 1, DPAD_DOWN); |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
395
diff
changeset
|
1144 bind_gamepad(RENDERKEY_LEFT, 1, DPAD_LEFT); |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
395
diff
changeset
|
1145 bind_gamepad(RENDERKEY_RIGHT, 1, DPAD_RIGHT); |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
395
diff
changeset
|
1146 bind_gamepad('a', 1, BUTTON_A); |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
395
diff
changeset
|
1147 bind_gamepad('s', 1, BUTTON_B); |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
395
diff
changeset
|
1148 bind_gamepad('d', 1, BUTTON_C); |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
395
diff
changeset
|
1149 bind_gamepad('q', 1, BUTTON_X); |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
395
diff
changeset
|
1150 bind_gamepad('w', 1, BUTTON_Y); |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
395
diff
changeset
|
1151 bind_gamepad('e', 1, BUTTON_Z); |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
395
diff
changeset
|
1152 bind_gamepad('\r', 1, BUTTON_START); |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
395
diff
changeset
|
1153 bind_gamepad('f', 1, BUTTON_MODE); |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
395
diff
changeset
|
1154 bind_ui('[', UI_DEBUG_MODE_INC); |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
395
diff
changeset
|
1155 bind_ui(']', UI_DEBUG_PAL_INC); |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
395
diff
changeset
|
1156 bind_ui('u', UI_ENTER_DEBUGGER); |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
395
diff
changeset
|
1157 } |
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
395
diff
changeset
|
1158 |
184
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1159 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
|
1160 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
|
1161 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
|
1162 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
|
1163 } 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
|
1164 |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1165 bp_def * breakpoints = NULL; |
366
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1166 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
|
1167 uint32_t bp_index = 0; |
366
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1168 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
|
1169 |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1170 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
|
1171 { |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1172 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
|
1173 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
|
1174 break; |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1175 } |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1176 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
|
1177 } |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1178 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
|
1179 } |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1180 |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1181 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
|
1182 { |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1183 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
|
1184 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
|
1185 break; |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1186 } |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1187 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
|
1188 } |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1189 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
|
1190 } |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1191 |
372
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1192 typedef struct disp_def { |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1193 struct disp_def * next; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1194 char * param; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1195 uint32_t index; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1196 char format_char; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1197 } disp_def; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1198 |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1199 disp_def * displays = NULL; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1200 disp_def * zdisplays = NULL; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1201 uint32_t disp_index = 0; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1202 uint32_t zdisp_index = 0; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1203 |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1204 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
|
1205 { |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1206 disp_def * ndisp = malloc(sizeof(*ndisp)); |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1207 ndisp->format_char = format_char; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1208 ndisp->param = strdup(param); |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1209 ndisp->next = *head; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1210 ndisp->index = *index++; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1211 *head = ndisp; |
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 |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1214 void remove_display(disp_def ** head, uint32_t index) |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1215 { |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1216 while (*head) { |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1217 if ((*head)->index == index) { |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1218 disp_def * del_disp = *head; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1219 *head = del_disp->next; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1220 free(del_disp->param); |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1221 free(del_disp); |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1222 } else { |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1223 head = &(*head)->next; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1224 } |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1225 } |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1226 } |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1227 |
184
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1228 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
|
1229 { |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1230 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
|
1231 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
|
1232 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
|
1233 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
|
1234 } |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1235 } |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1236 } |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1237 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
|
1238 } |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1239 |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1240 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
|
1241 { |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1242 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
|
1243 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
|
1244 *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
|
1245 return; |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1246 } |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1247 } |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1248 } |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1249 |
372
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1250 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
|
1251 { |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1252 uint32_t value; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1253 char format[8]; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1254 strcpy(format, "%s: %d\n"); |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1255 switch (format_char) |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1256 { |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1257 case 'x': |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1258 case 'X': |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1259 case 'd': |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1260 case 'c': |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1261 format[5] = format_char; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1262 break; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1263 case '\0': |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1264 break; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1265 default: |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1266 fprintf(stderr, "Unrecognized format character: %c\n", format_char); |
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 switch (param[0]) |
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 case 'a': |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1271 if (param[1] == 'f') { |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1272 if(param[2] == '\'') { |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1273 value = context->alt_regs[Z80_A] << 8; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1274 value |= context->alt_flags[ZF_S] << 7; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1275 value |= context->alt_flags[ZF_Z] << 6; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1276 value |= context->alt_flags[ZF_H] << 4; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1277 value |= context->alt_flags[ZF_PV] << 2; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1278 value |= context->alt_flags[ZF_N] << 1; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1279 value |= context->alt_flags[ZF_C]; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1280 } else { |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1281 value = context->regs[Z80_A] << 8; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1282 value |= context->flags[ZF_S] << 7; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1283 value |= context->flags[ZF_Z] << 6; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1284 value |= context->flags[ZF_H] << 4; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1285 value |= context->flags[ZF_PV] << 2; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1286 value |= context->flags[ZF_N] << 1; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1287 value |= context->flags[ZF_C]; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1288 } |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1289 } else if(param[1] == '\'') { |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1290 value = context->alt_regs[Z80_A]; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1291 } else { |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1292 value = context->regs[Z80_A]; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1293 } |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1294 break; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1295 case 'b': |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1296 if (param[1] == 'c') { |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1297 if(param[2] == '\'') { |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1298 value = context->alt_regs[Z80_B] << 8; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1299 value |= context->alt_regs[Z80_C]; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1300 } else { |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1301 value = context->regs[Z80_B] << 8; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1302 value |= context->regs[Z80_C]; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1303 } |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1304 } else if(param[1] == '\'') { |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1305 value = context->alt_regs[Z80_B]; |
392
1b80b90399da
Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
380
diff
changeset
|
1306 } else if(param[1] == 'a') { |
1b80b90399da
Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
380
diff
changeset
|
1307 value = context->bank_reg << 15; |
372
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1308 } else { |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1309 value = context->regs[Z80_B]; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1310 } |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1311 break; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1312 case 'c': |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1313 if(param[1] == '\'') { |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1314 value = context->alt_regs[Z80_C]; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1315 } else if(param[1] == 'y') { |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1316 value = context->current_cycle; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1317 } else { |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1318 value = context->regs[Z80_C]; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1319 } |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1320 break; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1321 case 'd': |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1322 if (param[1] == 'e') { |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1323 if(param[2] == '\'') { |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1324 value = context->alt_regs[Z80_D] << 8; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1325 value |= context->alt_regs[Z80_E]; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1326 } else { |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1327 value = context->regs[Z80_D] << 8; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1328 value |= context->regs[Z80_E]; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1329 } |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1330 } else if(param[1] == '\'') { |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1331 value = context->alt_regs[Z80_D]; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1332 } else { |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1333 value = context->regs[Z80_D]; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1334 } |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1335 break; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1336 case 'e': |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1337 if(param[1] == '\'') { |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1338 value = context->alt_regs[Z80_E]; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1339 } else { |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1340 value = context->regs[Z80_E]; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1341 } |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1342 break; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1343 case 'f': |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1344 if(param[2] == '\'') { |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1345 value = context->alt_flags[ZF_S] << 7; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1346 value |= context->alt_flags[ZF_Z] << 6; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1347 value |= context->alt_flags[ZF_H] << 4; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1348 value |= context->alt_flags[ZF_PV] << 2; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1349 value |= context->alt_flags[ZF_N] << 1; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1350 value |= context->alt_flags[ZF_C]; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1351 } else { |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1352 value = context->flags[ZF_S] << 7; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1353 value |= context->flags[ZF_Z] << 6; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1354 value |= context->flags[ZF_H] << 4; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1355 value |= context->flags[ZF_PV] << 2; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1356 value |= context->flags[ZF_N] << 1; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1357 value |= context->flags[ZF_C]; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1358 } |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1359 break; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1360 case 'h': |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1361 if (param[1] == 'l') { |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1362 if(param[2] == '\'') { |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1363 value = context->alt_regs[Z80_H] << 8; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1364 value |= context->alt_regs[Z80_L]; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1365 } else { |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1366 value = context->regs[Z80_H] << 8; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1367 value |= context->regs[Z80_L]; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1368 } |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1369 } else if(param[1] == '\'') { |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1370 value = context->alt_regs[Z80_H]; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1371 } else { |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1372 value = context->regs[Z80_H]; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1373 } |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1374 break; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1375 case 'l': |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1376 if(param[1] == '\'') { |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1377 value = context->alt_regs[Z80_L]; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1378 } else { |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1379 value = context->regs[Z80_L]; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1380 } |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1381 break; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1382 case 'i': |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1383 if(param[1] == 'x') { |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1384 if (param[2] == 'h') { |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1385 value = context->regs[Z80_IXH]; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1386 } else if(param[2] == 'l') { |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1387 value = context->regs[Z80_IXL]; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1388 } else { |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1389 value = context->regs[Z80_IXH] << 8; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1390 value |= context->regs[Z80_IXL]; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1391 } |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1392 } else if(param[1] == 'y') { |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1393 if (param[2] == 'h') { |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1394 value = context->regs[Z80_IYH]; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1395 } else if(param[2] == 'l') { |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1396 value = context->regs[Z80_IYL]; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1397 } else { |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1398 value = context->regs[Z80_IYH] << 8; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1399 value |= context->regs[Z80_IYL]; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1400 } |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1401 } else if(param[1] == 'n') { |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1402 value = context->int_cycle; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1403 } 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
|
1404 value = context->iff1; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1405 } 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
|
1406 value = context->iff2; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1407 } else { |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1408 value = context->im; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1409 } |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1410 break; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1411 case 's': |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1412 if (param[1] == 'p') { |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1413 value = context->sp; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1414 } |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1415 break; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1416 case '0': |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1417 if (param[1] == 'x') { |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1418 uint16_t p_addr = strtol(param+2, NULL, 16); |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1419 if (p_addr < 0x4000) { |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1420 value = z80_ram[p_addr & 0x1FFF]; |
392
1b80b90399da
Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
380
diff
changeset
|
1421 } else if(p_addr >= 0x8000) { |
1b80b90399da
Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
380
diff
changeset
|
1422 uint32_t v_addr = context->bank_reg << 15; |
1b80b90399da
Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
380
diff
changeset
|
1423 v_addr += p_addr & 0x7FFF; |
1b80b90399da
Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
380
diff
changeset
|
1424 if (v_addr < 0x400000) { |
1b80b90399da
Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
380
diff
changeset
|
1425 value = cart[v_addr/2]; |
1b80b90399da
Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
380
diff
changeset
|
1426 } else if(v_addr > 0xE00000) { |
1b80b90399da
Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
380
diff
changeset
|
1427 value = ram[(v_addr & 0xFFFF)/2]; |
1b80b90399da
Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
380
diff
changeset
|
1428 } |
1b80b90399da
Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
380
diff
changeset
|
1429 if (v_addr & 1) { |
1b80b90399da
Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
380
diff
changeset
|
1430 value &= 0xFF; |
1b80b90399da
Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
380
diff
changeset
|
1431 } else { |
1b80b90399da
Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
380
diff
changeset
|
1432 value >>= 8; |
1b80b90399da
Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
380
diff
changeset
|
1433 } |
372
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1434 } |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1435 } |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1436 break; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1437 } |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1438 printf(format, param, value); |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1439 } |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1440 |
366
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1441 z80_context * zdebugger(z80_context * context, uint16_t address) |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1442 { |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1443 static char last_cmd[1024]; |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1444 char input_buf[1024]; |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1445 static uint16_t branch_t; |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1446 static uint16_t branch_f; |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1447 z80inst inst; |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1448 //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
|
1449 bp_def ** this_bp = find_breakpoint(&zbreakpoints, address); |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1450 if (*this_bp) { |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1451 printf("Z80 Breakpoint %d hit\n", (*this_bp)->index); |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1452 } else { |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1453 zremove_breakpoint(context, address); |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1454 } |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1455 uint8_t * pc; |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1456 if (address < 0x4000) { |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1457 pc = z80_ram + (address & 0x1FFF); |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1458 } else if (address >= 0x8000) { |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1459 if (context->bank_reg < (0x400000 >> 15)) { |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1460 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
|
1461 exit(1); |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1462 } else { |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1463 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
|
1464 exit(1); |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1465 } |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1466 } else { |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1467 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
|
1468 exit(1); |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1469 } |
372
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1470 for (disp_def * cur = zdisplays; cur; cur = cur->next) { |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1471 zdebugger_print(context, cur->format_char, cur->param); |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1472 } |
366
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1473 uint8_t * after_pc = z80_decode(pc, &inst); |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1474 z80_disasm(&inst, input_buf, address); |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1475 printf("%X:\t%s\n", address, input_buf); |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1476 uint16_t after = address + (after_pc-pc); |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1477 int debugging = 1; |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1478 while(debugging) { |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1479 fputs(">", stdout); |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1480 if (!fgets(input_buf, sizeof(input_buf), stdin)) { |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1481 fputs("fgets failed", stderr); |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1482 break; |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1483 } |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1484 strip_nl(input_buf); |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1485 //hitting enter repeats last command |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1486 if (input_buf[0]) { |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1487 strcpy(last_cmd, input_buf); |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1488 } else { |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1489 strcpy(input_buf, last_cmd); |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1490 } |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1491 char * param; |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1492 char format[8]; |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1493 uint32_t value; |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1494 bp_def * new_bp; |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1495 switch(input_buf[0]) |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1496 { |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1497 case 'a': |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1498 param = find_param(input_buf); |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1499 if (!param) { |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1500 fputs("a command requires a parameter\n", stderr); |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1501 break; |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1502 } |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1503 value = strtol(param, NULL, 16); |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1504 zinsert_breakpoint(context, value, (uint8_t *)zdebugger); |
392
1b80b90399da
Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
380
diff
changeset
|
1505 debugging = 0; |
366
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1506 break; |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1507 case 'b': |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1508 param = find_param(input_buf); |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1509 if (!param) { |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1510 fputs("b command requires a parameter\n", stderr); |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1511 break; |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1512 } |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1513 value = strtol(param, NULL, 16); |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1514 zinsert_breakpoint(context, value, (uint8_t *)zdebugger); |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1515 new_bp = malloc(sizeof(bp_def)); |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1516 new_bp->next = zbreakpoints; |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1517 new_bp->address = value; |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1518 new_bp->index = zbp_index++; |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1519 zbreakpoints = new_bp; |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1520 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
|
1521 break; |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1522 case 'c': |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1523 puts("Continuing"); |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1524 debugging = 0; |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1525 break; |
372
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1526 case 'd': |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1527 if (input_buf[1] == 'i') { |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1528 char format_char = 0; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1529 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
|
1530 if (input_buf[i] == '/') { |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1531 format_char = input_buf[i+1]; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1532 break; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1533 } |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1534 } |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1535 param = find_param(input_buf); |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1536 if (!param) { |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1537 fputs("display command requires a parameter\n", stderr); |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1538 break; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1539 } |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1540 zdebugger_print(context, format_char, param); |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1541 add_display(&zdisplays, &zdisp_index, format_char, param); |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1542 } else if (input_buf[1] == 'e' || input_buf[1] == ' ') { |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1543 param = find_param(input_buf); |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1544 if (!param) { |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1545 fputs("delete command requires a parameter\n", stderr); |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1546 break; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1547 } |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1548 if (param[0] >= '0' && param[0] <= '9') { |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1549 value = atoi(param); |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1550 this_bp = find_breakpoint_idx(&zbreakpoints, value); |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1551 if (!*this_bp) { |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1552 fprintf(stderr, "Breakpoint %d does not exist\n", value); |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1553 break; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1554 } |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1555 new_bp = *this_bp; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1556 zremove_breakpoint(context, new_bp->address); |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1557 *this_bp = new_bp->next; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1558 free(new_bp); |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1559 } else if (param[0] == 'd') { |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1560 param = find_param(param); |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1561 if (!param) { |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1562 fputs("delete display command requires a parameter\n", stderr); |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1563 break; |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1564 } |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1565 remove_display(&zdisplays, atoi(param)); |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1566 } |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1567 } |
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1568 break; |
366
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1569 case 'n': |
392
1b80b90399da
Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
380
diff
changeset
|
1570 //TODO: Handle conditional branch instructions |
1b80b90399da
Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
380
diff
changeset
|
1571 if (inst.op == Z80_JP) { |
1b80b90399da
Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
380
diff
changeset
|
1572 if (inst.addr_mode == Z80_IMMED) { |
1b80b90399da
Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
380
diff
changeset
|
1573 after = inst.immed; |
1b80b90399da
Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
380
diff
changeset
|
1574 } else if (inst.ea_reg == Z80_HL) { |
1b80b90399da
Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
380
diff
changeset
|
1575 after = context->regs[Z80_H] << 8 | context->regs[Z80_L]; |
1b80b90399da
Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
380
diff
changeset
|
1576 } else if (inst.ea_reg == Z80_IX) { |
1b80b90399da
Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
380
diff
changeset
|
1577 after = context->regs[Z80_IXH] << 8 | context->regs[Z80_IXL]; |
1b80b90399da
Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
380
diff
changeset
|
1578 } else if (inst.ea_reg == Z80_IY) { |
1b80b90399da
Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
380
diff
changeset
|
1579 after = context->regs[Z80_IYH] << 8 | context->regs[Z80_IYL]; |
1b80b90399da
Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
380
diff
changeset
|
1580 } |
1b80b90399da
Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
380
diff
changeset
|
1581 } else if(inst.op == Z80_JR) { |
1b80b90399da
Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
380
diff
changeset
|
1582 after += inst.immed; |
1b80b90399da
Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
380
diff
changeset
|
1583 } else if(inst.op == Z80_RET) { |
1b80b90399da
Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
380
diff
changeset
|
1584 if (context->sp < 0x4000) { |
1b80b90399da
Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
380
diff
changeset
|
1585 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
|
1586 } |
1b80b90399da
Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
380
diff
changeset
|
1587 } |
366
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1588 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
|
1589 debugging = 0; |
366
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1590 break; |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1591 case 'p': |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1592 param = find_param(input_buf); |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1593 if (!param) { |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1594 fputs("p command requires a parameter\n", stderr); |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1595 break; |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1596 } |
372
5dcf7551bb36
Bunch of Z80 debugger improvements
Mike Pavone <pavone@retrodev.com>
parents:
368
diff
changeset
|
1597 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
|
1598 break; |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1599 case 'q': |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1600 puts("Quitting"); |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1601 exit(0); |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1602 break; |
395
0b5f93358a93
Add debugger command for saving Z80 RAM to a file
Mike Pavone <pavone@retrodev.com>
parents:
392
diff
changeset
|
1603 case 's': { |
0b5f93358a93
Add debugger command for saving Z80 RAM to a file
Mike Pavone <pavone@retrodev.com>
parents:
392
diff
changeset
|
1604 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
|
1605 if (!param) { |
0b5f93358a93
Add debugger command for saving Z80 RAM to a file
Mike Pavone <pavone@retrodev.com>
parents:
392
diff
changeset
|
1606 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
|
1607 break; |
0b5f93358a93
Add debugger command for saving Z80 RAM to a file
Mike Pavone <pavone@retrodev.com>
parents:
392
diff
changeset
|
1608 } |
0b5f93358a93
Add debugger command for saving Z80 RAM to a file
Mike Pavone <pavone@retrodev.com>
parents:
392
diff
changeset
|
1609 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
|
1610 if (f) { |
0b5f93358a93
Add debugger command for saving Z80 RAM to a file
Mike Pavone <pavone@retrodev.com>
parents:
392
diff
changeset
|
1611 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
|
1612 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
|
1613 } |
0b5f93358a93
Add debugger command for saving Z80 RAM to a file
Mike Pavone <pavone@retrodev.com>
parents:
392
diff
changeset
|
1614 fclose(f); |
0b5f93358a93
Add debugger command for saving Z80 RAM to a file
Mike Pavone <pavone@retrodev.com>
parents:
392
diff
changeset
|
1615 } else { |
0b5f93358a93
Add debugger command for saving Z80 RAM to a file
Mike Pavone <pavone@retrodev.com>
parents:
392
diff
changeset
|
1616 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
|
1617 } |
0b5f93358a93
Add debugger command for saving Z80 RAM to a file
Mike Pavone <pavone@retrodev.com>
parents:
392
diff
changeset
|
1618 break; |
0b5f93358a93
Add debugger command for saving Z80 RAM to a file
Mike Pavone <pavone@retrodev.com>
parents:
392
diff
changeset
|
1619 } |
366
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1620 default: |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1621 fprintf(stderr, "Unrecognized debugger command %s\n", input_buf); |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1622 break; |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1623 } |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1624 } |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1625 return context; |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1626 } |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1627 |
184
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1628 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
|
1629 { |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1630 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
|
1631 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
|
1632 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
|
1633 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
|
1634 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
|
1635 //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
|
1636 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
|
1637 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
|
1638 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
|
1639 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
|
1640 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
|
1641 } |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1642 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
|
1643 } 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
|
1644 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
|
1645 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
|
1646 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
|
1647 } |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1648 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
|
1649 } |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1650 //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
|
1651 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
|
1652 if (*this_bp) { |
366
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1653 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
|
1654 } else { |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1655 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
|
1656 } |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1657 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
|
1658 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
|
1659 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
|
1660 } 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
|
1661 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
|
1662 } else { |
366
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1663 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
|
1664 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
|
1665 } |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1666 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
|
1667 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
|
1668 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
|
1669 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
|
1670 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
|
1671 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
|
1672 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
|
1673 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
|
1674 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
|
1675 break; |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1676 } |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1677 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
|
1678 //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
|
1679 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
|
1680 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
|
1681 } else { |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1682 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
|
1683 } |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1684 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
|
1685 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
|
1686 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
|
1687 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
|
1688 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
|
1689 { |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1690 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
|
1691 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
|
1692 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
|
1693 break; |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1694 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
|
1695 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
|
1696 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
|
1697 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
|
1698 break; |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1699 } |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1700 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
|
1701 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
|
1702 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
|
1703 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
|
1704 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
|
1705 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
|
1706 breakpoints = new_bp; |
366
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1707 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
|
1708 break; |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1709 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
|
1710 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
|
1711 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
|
1712 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
|
1713 break; |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1714 } |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1715 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
|
1716 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
|
1717 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
|
1718 break; |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1719 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
|
1720 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
|
1721 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
|
1722 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
|
1723 break; |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1724 } |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1725 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
|
1726 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
|
1727 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
|
1728 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
|
1729 break; |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1730 } |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1731 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
|
1732 *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
|
1733 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
|
1734 break; |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1735 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
|
1736 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
|
1737 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
|
1738 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
|
1739 { |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1740 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
|
1741 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
|
1742 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
|
1743 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
|
1744 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
|
1745 break; |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1746 default: |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1747 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
|
1748 } |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1749 } |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1750 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
|
1751 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
|
1752 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
|
1753 break; |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1754 } |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1755 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
|
1756 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
|
1757 } 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
|
1758 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
|
1759 } 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
|
1760 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
|
1761 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
|
1762 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
|
1763 } |
185
b204fbed4efe
Add ability to print out current 68K cycle in debugger
Mike Pavone <pavone@retrodev.com>
parents:
184
diff
changeset
|
1764 } 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
|
1765 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
|
1766 } 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
|
1767 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
|
1768 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
|
1769 } else { |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1770 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
|
1771 break; |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1772 } |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1773 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
|
1774 break; |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1775 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
|
1776 //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
|
1777 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
|
1778 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
|
1779 } 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
|
1780 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
|
1781 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
|
1782 } else { |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1783 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
|
1784 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
|
1785 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
|
1786 } |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1787 } |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1788 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
|
1789 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
|
1790 break; |
327
1b00258b1f29
Added some basic VDP debugging features to debugger. Fixed DMA enable bug
Mike Pavone <pavone@retrodev.com>
parents:
321
diff
changeset
|
1791 case 'v': { |
1b00258b1f29
Added some basic VDP debugging features to debugger. Fixed DMA enable bug
Mike Pavone <pavone@retrodev.com>
parents:
321
diff
changeset
|
1792 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
|
1793 //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
|
1794 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
|
1795 { |
1b00258b1f29
Added some basic VDP debugging features to debugger. Fixed DMA enable bug
Mike Pavone <pavone@retrodev.com>
parents:
321
diff
changeset
|
1796 case 's': |
1b00258b1f29
Added some basic VDP debugging features to debugger. Fixed DMA enable bug
Mike Pavone <pavone@retrodev.com>
parents:
321
diff
changeset
|
1797 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
|
1798 break; |
1b00258b1f29
Added some basic VDP debugging features to debugger. Fixed DMA enable bug
Mike Pavone <pavone@retrodev.com>
parents:
321
diff
changeset
|
1799 case 'r': |
1b00258b1f29
Added some basic VDP debugging features to debugger. Fixed DMA enable bug
Mike Pavone <pavone@retrodev.com>
parents:
321
diff
changeset
|
1800 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
|
1801 break; |
1b00258b1f29
Added some basic VDP debugging features to debugger. Fixed DMA enable bug
Mike Pavone <pavone@retrodev.com>
parents:
321
diff
changeset
|
1802 } |
1b00258b1f29
Added some basic VDP debugging features to debugger. Fixed DMA enable bug
Mike Pavone <pavone@retrodev.com>
parents:
321
diff
changeset
|
1803 break; |
1b00258b1f29
Added some basic VDP debugging features to debugger. Fixed DMA enable bug
Mike Pavone <pavone@retrodev.com>
parents:
321
diff
changeset
|
1804 } |
366
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1805 case 'z': { |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1806 genesis_context * gen = context->system; |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1807 //Z80 debug commands |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1808 switch(input_buf[1]) |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1809 { |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1810 case 'b': |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1811 param = find_param(input_buf); |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1812 if (!param) { |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1813 fputs("zb command requires a parameter\n", stderr); |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1814 break; |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1815 } |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1816 value = strtol(param, NULL, 16); |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1817 zinsert_breakpoint(gen->z80, value, (uint8_t *)zdebugger); |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1818 new_bp = malloc(sizeof(bp_def)); |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1819 new_bp->next = zbreakpoints; |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1820 new_bp->address = value; |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1821 new_bp->index = zbp_index++; |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1822 zbreakpoints = new_bp; |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1823 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
|
1824 break; |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1825 } |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1826 break; |
836585d389b8
Partial implementation of Z80 debugger
Mike Pavone <pavone@retrodev.com>
parents:
364
diff
changeset
|
1827 } |
184
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1828 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
|
1829 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
|
1830 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
|
1831 break; |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1832 default: |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1833 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
|
1834 break; |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1835 } |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1836 } |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1837 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
|
1838 } |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1839 |
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
|
1840 #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
|
1841 #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
|
1842 #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
|
1843 #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
|
1844 #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
|
1845 #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
|
1846 #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
|
1847 |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
1848 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
|
1849 {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
|
1850 NULL, NULL, NULL, NULL}, |
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
1851 {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
|
1852 NULL, NULL, NULL, NULL}, |
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
1853 {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
|
1854 (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
|
1855 (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
|
1856 {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
|
1857 (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
|
1858 (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
|
1859 }; |
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
|
1860 |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
1861 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
|
1862 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
|
1863 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
|
1864 { |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
1865 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
|
1866 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
|
1867 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
|
1868 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
|
1869 } |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
1870 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
|
1871 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
|
1872 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
|
1873 } |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
1874 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
|
1875 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
|
1876 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
|
1877 } |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
1878 |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
1879 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
|
1880 { |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
1881 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
|
1882 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
|
1883 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
|
1884 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
|
1885 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
|
1886 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
|
1887 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
|
1888 //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
|
1889 //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
|
1890 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
|
1891 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
|
1892 //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
|
1893 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
|
1894 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
|
1895 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
|
1896 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
|
1897 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
|
1898 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
|
1899 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
|
1900 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
|
1901 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
|
1902 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
|
1903 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
|
1904 |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
1905 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
|
1906 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
|
1907 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
|
1908 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
|
1909 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
|
1910 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
|
1911 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
|
1912 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
|
1913 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
|
1914 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
|
1915 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
|
1916 } 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
|
1917 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
|
1918 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
|
1919 } |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
1920 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
|
1921 |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
1922 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
|
1923 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
|
1924 } 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
|
1925 //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
|
1926 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
|
1927 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
|
1928 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
|
1929 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
|
1930 |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
1931 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
|
1932 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
|
1933 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
|
1934 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
|
1935 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
|
1936 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
|
1937 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
|
1938 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
|
1939 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
|
1940 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
|
1941 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
|
1942 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
|
1943 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
|
1944 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
|
1945 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
|
1946 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
|
1947 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
|
1948 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
|
1949 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
|
1950 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
|
1951 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
|
1952 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
|
1953 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
|
1954 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
|
1955 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
|
1956 } |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
1957 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
|
1958 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
|
1959 } |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
1960 } 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
|
1961 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
|
1962 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
|
1963 } |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
1964 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
|
1965 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
|
1966 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
|
1967 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
|
1968 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
|
1969 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
|
1970 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
|
1971 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
|
1972 } |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
1973 } |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
1974 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
|
1975 } |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
1976 init_x86_68k_opts(&opts, memmap, num_chunks); |
211 | 1977 opts.address_log = address_log; |
1978 init_68k_context(&context, opts.native_code_map, &opts); | |
1979 | |
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
|
1980 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
|
1981 context.system = gen; |
211 | 1982 //cartridge ROM |
1983 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
|
1984 context.target_cycle = context.sync_cycle = mclks_per_frame/MCLKS_PER_68K; |
211 | 1985 //work RAM |
1986 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
|
1987 //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
|
1988 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
|
1989 context.mem_pointers[3] = (uint16_t *)gen->save_ram; |
211 | 1990 uint32_t address; |
1991 address = cart[2] << 16 | cart[3]; | |
1992 translate_m68k_stream(address, &context); | |
1993 if (debug) { | |
1994 insert_breakpoint(&context, address, (uint8_t *)debugger); | |
1995 } | |
1996 m68k_reset(&context); | |
1997 } | |
1998 | |
340
58a085cfc6bd
Set window title based on ROM header name
Mike Pavone <pavone@retrodev.com>
parents:
338
diff
changeset
|
1999 char title[64]; |
58a085cfc6bd
Set window title based on ROM header name
Mike Pavone <pavone@retrodev.com>
parents:
338
diff
changeset
|
2000 |
58a085cfc6bd
Set window title based on ROM header name
Mike Pavone <pavone@retrodev.com>
parents:
338
diff
changeset
|
2001 #define TITLE_START 0x150 |
58a085cfc6bd
Set window title based on ROM header name
Mike Pavone <pavone@retrodev.com>
parents:
338
diff
changeset
|
2002 #define TITLE_END (TITLE_START+48) |
58a085cfc6bd
Set window title based on ROM header name
Mike Pavone <pavone@retrodev.com>
parents:
338
diff
changeset
|
2003 |
58a085cfc6bd
Set window title based on ROM header name
Mike Pavone <pavone@retrodev.com>
parents:
338
diff
changeset
|
2004 void update_title() |
58a085cfc6bd
Set window title based on ROM header name
Mike Pavone <pavone@retrodev.com>
parents:
338
diff
changeset
|
2005 { |
58a085cfc6bd
Set window title based on ROM header name
Mike Pavone <pavone@retrodev.com>
parents:
338
diff
changeset
|
2006 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
|
2007 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
|
2008 { |
58a085cfc6bd
Set window title based on ROM header name
Mike Pavone <pavone@retrodev.com>
parents:
338
diff
changeset
|
2009 last--; |
58a085cfc6bd
Set window title based on ROM header name
Mike Pavone <pavone@retrodev.com>
parents:
338
diff
changeset
|
2010 } |
58a085cfc6bd
Set window title based on ROM header name
Mike Pavone <pavone@retrodev.com>
parents:
338
diff
changeset
|
2011 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
|
2012 char *cur = title; |
58a085cfc6bd
Set window title based on ROM header name
Mike Pavone <pavone@retrodev.com>
parents:
338
diff
changeset
|
2013 char last_char = ' '; |
58a085cfc6bd
Set window title based on ROM header name
Mike Pavone <pavone@retrodev.com>
parents:
338
diff
changeset
|
2014 for (; start != last; start++) |
58a085cfc6bd
Set window title based on ROM header name
Mike Pavone <pavone@retrodev.com>
parents:
338
diff
changeset
|
2015 { |
58a085cfc6bd
Set window title based on ROM header name
Mike Pavone <pavone@retrodev.com>
parents:
338
diff
changeset
|
2016 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
|
2017 *(cur++) = *start >> 8; |
58a085cfc6bd
Set window title based on ROM header name
Mike Pavone <pavone@retrodev.com>
parents:
338
diff
changeset
|
2018 last_char = *start >> 8; |
58a085cfc6bd
Set window title based on ROM header name
Mike Pavone <pavone@retrodev.com>
parents:
338
diff
changeset
|
2019 } |
58a085cfc6bd
Set window title based on ROM header name
Mike Pavone <pavone@retrodev.com>
parents:
338
diff
changeset
|
2020 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
|
2021 *(cur++) = *start; |
58a085cfc6bd
Set window title based on ROM header name
Mike Pavone <pavone@retrodev.com>
parents:
338
diff
changeset
|
2022 last_char = *start & 0xFF; |
58a085cfc6bd
Set window title based on ROM header name
Mike Pavone <pavone@retrodev.com>
parents:
338
diff
changeset
|
2023 } |
58a085cfc6bd
Set window title based on ROM header name
Mike Pavone <pavone@retrodev.com>
parents:
338
diff
changeset
|
2024 } |
58a085cfc6bd
Set window title based on ROM header name
Mike Pavone <pavone@retrodev.com>
parents:
338
diff
changeset
|
2025 *(cur++) = *start >> 8; |
58a085cfc6bd
Set window title based on ROM header name
Mike Pavone <pavone@retrodev.com>
parents:
338
diff
changeset
|
2026 if ((*start & 0xFF) != ' ') { |
58a085cfc6bd
Set window title based on ROM header name
Mike Pavone <pavone@retrodev.com>
parents:
338
diff
changeset
|
2027 *(cur++) = *start; |
58a085cfc6bd
Set window title based on ROM header name
Mike Pavone <pavone@retrodev.com>
parents:
338
diff
changeset
|
2028 } |
58a085cfc6bd
Set window title based on ROM header name
Mike Pavone <pavone@retrodev.com>
parents:
338
diff
changeset
|
2029 strcpy(cur, " - BlastEm"); |
58a085cfc6bd
Set window title based on ROM header name
Mike Pavone <pavone@retrodev.com>
parents:
338
diff
changeset
|
2030 } |
58a085cfc6bd
Set window title based on ROM header name
Mike Pavone <pavone@retrodev.com>
parents:
338
diff
changeset
|
2031 |
341
6ad8e36de685
Support regions other than USA
Mike Pavone <pavone@retrodev.com>
parents:
340
diff
changeset
|
2032 #define REGION_START 0x1F0 |
6ad8e36de685
Support regions other than USA
Mike Pavone <pavone@retrodev.com>
parents:
340
diff
changeset
|
2033 |
6ad8e36de685
Support regions other than USA
Mike Pavone <pavone@retrodev.com>
parents:
340
diff
changeset
|
2034 int detect_specific_region(char region) |
6ad8e36de685
Support regions other than USA
Mike Pavone <pavone@retrodev.com>
parents:
340
diff
changeset
|
2035 { |
346
aff29d50afd5
Fix a region detection bug
Mike Pavone <pavone@retrodev.com>
parents:
345
diff
changeset
|
2036 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
|
2037 } |
6ad8e36de685
Support regions other than USA
Mike Pavone <pavone@retrodev.com>
parents:
340
diff
changeset
|
2038 |
6ad8e36de685
Support regions other than USA
Mike Pavone <pavone@retrodev.com>
parents:
340
diff
changeset
|
2039 void detect_region() |
6ad8e36de685
Support regions other than USA
Mike Pavone <pavone@retrodev.com>
parents:
340
diff
changeset
|
2040 { |
343
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
2041 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
|
2042 version_reg = NO_DISK | USA; |
6ad8e36de685
Support regions other than USA
Mike Pavone <pavone@retrodev.com>
parents:
340
diff
changeset
|
2043 } else if (detect_specific_region('J')) { |
6ad8e36de685
Support regions other than USA
Mike Pavone <pavone@retrodev.com>
parents:
340
diff
changeset
|
2044 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
|
2045 } 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
|
2046 version_reg = NO_DISK | EUR; |
6ad8e36de685
Support regions other than USA
Mike Pavone <pavone@retrodev.com>
parents:
340
diff
changeset
|
2047 } |
6ad8e36de685
Support regions other than USA
Mike Pavone <pavone@retrodev.com>
parents:
340
diff
changeset
|
2048 } |
6ad8e36de685
Support regions other than USA
Mike Pavone <pavone@retrodev.com>
parents:
340
diff
changeset
|
2049 |
88
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
2050 int main(int argc, char ** argv) |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
2051 { |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
2052 if (argc < 2) { |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
2053 fputs("Usage: blastem FILENAME\n", stderr); |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
2054 return 1; |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
2055 } |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
2056 if(!load_rom(argv[1])) { |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
2057 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
|
2058 return 1; |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
2059 } |
341
6ad8e36de685
Support regions other than USA
Mike Pavone <pavone@retrodev.com>
parents:
340
diff
changeset
|
2060 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
|
2061 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
|
2062 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
|
2063 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
|
2064 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
|
2065 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
|
2066 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
|
2067 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
|
2068 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
|
2069 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
|
2070 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
|
2071 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
|
2072 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
|
2073 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
|
2074 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
|
2075 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
|
2076 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
|
2077 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
|
2078 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
|
2079 break; |
265
c6d12878ea93
Add -n flag for disabling the Z80 core
Mike Pavone <pavone@retrodev.com>
parents:
264
diff
changeset
|
2080 case 'n': |
c6d12878ea93
Add -n flag for disabling the Z80 core
Mike Pavone <pavone@retrodev.com>
parents:
264
diff
changeset
|
2081 z80_enabled = 0; |
c6d12878ea93
Add -n flag for disabling the Z80 core
Mike Pavone <pavone@retrodev.com>
parents:
264
diff
changeset
|
2082 break; |
341
6ad8e36de685
Support regions other than USA
Mike Pavone <pavone@retrodev.com>
parents:
340
diff
changeset
|
2083 case 'r': |
6ad8e36de685
Support regions other than USA
Mike Pavone <pavone@retrodev.com>
parents:
340
diff
changeset
|
2084 i++; |
6ad8e36de685
Support regions other than USA
Mike Pavone <pavone@retrodev.com>
parents:
340
diff
changeset
|
2085 if (i >= argc) { |
6ad8e36de685
Support regions other than USA
Mike Pavone <pavone@retrodev.com>
parents:
340
diff
changeset
|
2086 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
|
2087 return 1; |
6ad8e36de685
Support regions other than USA
Mike Pavone <pavone@retrodev.com>
parents:
340
diff
changeset
|
2088 } |
6ad8e36de685
Support regions other than USA
Mike Pavone <pavone@retrodev.com>
parents:
340
diff
changeset
|
2089 switch (argv[i][0]) |
6ad8e36de685
Support regions other than USA
Mike Pavone <pavone@retrodev.com>
parents:
340
diff
changeset
|
2090 { |
6ad8e36de685
Support regions other than USA
Mike Pavone <pavone@retrodev.com>
parents:
340
diff
changeset
|
2091 case 'j': |
6ad8e36de685
Support regions other than USA
Mike Pavone <pavone@retrodev.com>
parents:
340
diff
changeset
|
2092 case 'J': |
6ad8e36de685
Support regions other than USA
Mike Pavone <pavone@retrodev.com>
parents:
340
diff
changeset
|
2093 version_reg = NO_DISK | JAP; |
6ad8e36de685
Support regions other than USA
Mike Pavone <pavone@retrodev.com>
parents:
340
diff
changeset
|
2094 break; |
6ad8e36de685
Support regions other than USA
Mike Pavone <pavone@retrodev.com>
parents:
340
diff
changeset
|
2095 case 'u': |
6ad8e36de685
Support regions other than USA
Mike Pavone <pavone@retrodev.com>
parents:
340
diff
changeset
|
2096 case 'U': |
6ad8e36de685
Support regions other than USA
Mike Pavone <pavone@retrodev.com>
parents:
340
diff
changeset
|
2097 version_reg = NO_DISK | USA; |
6ad8e36de685
Support regions other than USA
Mike Pavone <pavone@retrodev.com>
parents:
340
diff
changeset
|
2098 break; |
6ad8e36de685
Support regions other than USA
Mike Pavone <pavone@retrodev.com>
parents:
340
diff
changeset
|
2099 case 'e': |
6ad8e36de685
Support regions other than USA
Mike Pavone <pavone@retrodev.com>
parents:
340
diff
changeset
|
2100 case 'E': |
6ad8e36de685
Support regions other than USA
Mike Pavone <pavone@retrodev.com>
parents:
340
diff
changeset
|
2101 version_reg = NO_DISK | EUR; |
6ad8e36de685
Support regions other than USA
Mike Pavone <pavone@retrodev.com>
parents:
340
diff
changeset
|
2102 break; |
6ad8e36de685
Support regions other than USA
Mike Pavone <pavone@retrodev.com>
parents:
340
diff
changeset
|
2103 default: |
6ad8e36de685
Support regions other than USA
Mike Pavone <pavone@retrodev.com>
parents:
340
diff
changeset
|
2104 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
|
2105 return 1; |
6ad8e36de685
Support regions other than USA
Mike Pavone <pavone@retrodev.com>
parents:
340
diff
changeset
|
2106 } |
6ad8e36de685
Support regions other than USA
Mike Pavone <pavone@retrodev.com>
parents:
340
diff
changeset
|
2107 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
|
2108 default: |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
2109 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
|
2110 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
|
2111 } |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
2112 } 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
|
2113 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
|
2114 } 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
|
2115 height = atoi(argv[i]); |
88
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
2116 } |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
2117 } |
340
58a085cfc6bd
Set window title based on ROM header name
Mike Pavone <pavone@retrodev.com>
parents:
338
diff
changeset
|
2118 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
|
2119 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
|
2120 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
|
2121 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
|
2122 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
|
2123 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
|
2124 fps = 50; |
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
351
diff
changeset
|
2125 } |
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
351
diff
changeset
|
2126 if (!headless) { |
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
351
diff
changeset
|
2127 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
|
2128 } |
88
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
2129 vdp_context v_context; |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
2130 |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
2131 init_vdp_context(&v_context); |
260
625f8e4d5fd2
Initial stab at integartiong Z80 core
Mike Pavone <pavone@retrodev.com>
parents:
215
diff
changeset
|
2132 |
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
|
2133 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
|
2134 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
|
2135 |
354
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
351
diff
changeset
|
2136 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
|
2137 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
|
2138 |
260
625f8e4d5fd2
Initial stab at integartiong Z80 core
Mike Pavone <pavone@retrodev.com>
parents:
215
diff
changeset
|
2139 z80_context z_context; |
625f8e4d5fd2
Initial stab at integartiong Z80 core
Mike Pavone <pavone@retrodev.com>
parents:
215
diff
changeset
|
2140 x86_z80_options z_opts; |
625f8e4d5fd2
Initial stab at integartiong Z80 core
Mike Pavone <pavone@retrodev.com>
parents:
215
diff
changeset
|
2141 init_x86_z80_opts(&z_opts); |
625f8e4d5fd2
Initial stab at integartiong Z80 core
Mike Pavone <pavone@retrodev.com>
parents:
215
diff
changeset
|
2142 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
|
2143 |
171f97e70d85
Implement writes from Z80 to YM-2612
Mike Pavone <pavone@retrodev.com>
parents:
289
diff
changeset
|
2144 genesis_context gen; |
171f97e70d85
Implement writes from Z80 to YM-2612
Mike Pavone <pavone@retrodev.com>
parents:
289
diff
changeset
|
2145 |
171f97e70d85
Implement writes from Z80 to YM-2612
Mike Pavone <pavone@retrodev.com>
parents:
289
diff
changeset
|
2146 z_context.system = &gen; |
260
625f8e4d5fd2
Initial stab at integartiong Z80 core
Mike Pavone <pavone@retrodev.com>
parents:
215
diff
changeset
|
2147 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
|
2148 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
|
2149 z_context.int_cycle = CYCLE_NEVER; |
625f8e4d5fd2
Initial stab at integartiong Z80 core
Mike Pavone <pavone@retrodev.com>
parents:
215
diff
changeset
|
2150 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
|
2151 |
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
|
2152 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
|
2153 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
|
2154 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
|
2155 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
|
2156 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
|
2157 |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
2158 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
|
2159 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
|
2160 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
|
2161 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
|
2162 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
|
2163 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
|
2164 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
|
2165 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
|
2166 } |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
2167 } |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
2168 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
|
2169 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
|
2170 } |
398
c26e48a93fa3
Make keybindings data driven so they can be populated from a config file later
Mike Pavone <pavone@retrodev.com>
parents:
395
diff
changeset
|
2171 set_keybindings(); |
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
|
2172 |
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
|
2173 init_run_cpu(&gen, debug, address_log); |
88
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
2174 return 0; |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
2175 } |