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