Mercurial > repos > blastem
annotate blastem.c @ 529:6a648d944311
Remove defines from blastem.c that had been moved to blastem.h
author | Mike Pavone <pavone@retrodev.com> |
---|---|
date | Wed, 12 Feb 2014 23:21:47 -0800 |
parents | fb39534b6604 |
children | 46a60bb5f785 |
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" |
515
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
510
diff
changeset
|
13 #include "gdb_remote.h" |
451
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
447
diff
changeset
|
14 #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
|
15 #include "util.h" |
88
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
16 #include <stdio.h> |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
17 #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
|
18 #include <string.h> |
88
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
19 |
464 | 20 #define BLASTEM_VERSION "0.1.0" |
21 | |
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
|
22 #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
|
23 #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
|
24 |
88
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
25 #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
|
26 #define MCLKS_PER_YM MCLKS_PER_68K |
260
625f8e4d5fd2
Initial stab at integartiong Z80 core
Mike Pavone <pavone@retrodev.com>
parents:
215
diff
changeset
|
27 #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
|
28 #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
|
29 |
88
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
30 //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
|
31 #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
|
32 #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
|
33 |
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
|
34 #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
|
35 |
342
13f994c88c34
Get frame time correct and frame rate sort of correct for EUR region
Mike Pavone <pavone@retrodev.com>
parents:
341
diff
changeset
|
36 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
|
37 |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
38 uint16_t cart[CARTRIDGE_WORDS]; |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
39 uint16_t ram[RAM_WORDS]; |
153
42c031184e8a
Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents:
149
diff
changeset
|
40 uint8_t z80_ram[Z80_RAM_BYTES]; |
88
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
41 |
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
|
42 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
|
43 int exit_after = 0; |
265
c6d12878ea93
Add -n flag for disabling the Z80 core
Mike Pavone <pavone@retrodev.com>
parents:
264
diff
changeset
|
44 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
|
45 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
|
46 |
430
7f84090ab1cd
Add config file parser and default config file
Mike Pavone <pavone@retrodev.com>
parents:
425
diff
changeset
|
47 tern_node * config; |
7f84090ab1cd
Add config file parser and default config file
Mike Pavone <pavone@retrodev.com>
parents:
425
diff
changeset
|
48 |
88
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
49 #ifndef MIN |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
50 #define MIN(a,b) ((a) < (b) ? (a) : (b)) |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
51 #endif |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
52 |
166 | 53 #define SMD_HEADER_SIZE 512 |
54 #define SMD_MAGIC1 0x03 | |
55 #define SMD_MAGIC2 0xAA | |
56 #define SMD_MAGIC3 0xBB | |
57 #define SMD_BLOCK_SIZE 0x4000 | |
58 | |
59 int load_smd_rom(long filesize, FILE * f) | |
60 { | |
61 uint8_t block[SMD_BLOCK_SIZE]; | |
62 filesize -= SMD_HEADER_SIZE; | |
63 fseek(f, SMD_HEADER_SIZE, SEEK_SET); | |
488
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
64 |
166 | 65 uint16_t * dst = cart; |
66 while (filesize > 0) { | |
67 fread(block, 1, SMD_BLOCK_SIZE, f); | |
68 for (uint8_t *low = block, *high = (block+SMD_BLOCK_SIZE/2), *end = block+SMD_BLOCK_SIZE; high < end; high++, low++) { | |
69 *(dst++) = *high << 8 | *low; | |
70 } | |
71 filesize -= SMD_BLOCK_SIZE; | |
72 } | |
73 return 1; | |
74 } | |
75 | |
88
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
76 int load_rom(char * filename) |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
77 { |
166 | 78 uint8_t header[10]; |
88
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
79 FILE * f = fopen(filename, "rb"); |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
80 if (!f) { |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
81 return 0; |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
82 } |
166 | 83 fread(header, 1, sizeof(header), f); |
88
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
84 fseek(f, 0, SEEK_END); |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
85 long filesize = ftell(f); |
158
a2ab895d9708
Fix predec address mode when used as source
Mike Pavone <pavone@retrodev.com>
parents:
153
diff
changeset
|
86 if (filesize/2 > CARTRIDGE_WORDS) { |
a2ab895d9708
Fix predec address mode when used as source
Mike Pavone <pavone@retrodev.com>
parents:
153
diff
changeset
|
87 //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
|
88 filesize = CARTRIDGE_WORDS*2; |
a2ab895d9708
Fix predec address mode when used as source
Mike Pavone <pavone@retrodev.com>
parents:
153
diff
changeset
|
89 } |
88
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
90 fseek(f, 0, SEEK_SET); |
166 | 91 if (header[1] == SMD_MAGIC1 && header[8] == SMD_MAGIC2 && header[9] == SMD_MAGIC3) { |
92 int i; | |
93 for (i = 3; i < 8; i++) { | |
94 if (header[i] != 0) { | |
95 break; | |
96 } | |
97 } | |
98 if (i == 8) { | |
99 if (header[2]) { | |
100 fprintf(stderr, "%s is a split SMD ROM which is not currently supported", filename); | |
101 exit(1); | |
102 } | |
103 return load_smd_rom(filesize, f); | |
104 } | |
105 } | |
106 fread(cart, 2, filesize/2, f); | |
88
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
107 fclose(f); |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
108 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
|
109 { |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
110 *cur = (*cur >> 8) | (*cur << 8); |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
111 } |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
112 //TODO: Mirror ROM |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
113 return 1; |
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 |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
116 uint16_t read_dma_value(uint32_t address) |
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 //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
|
119 if (address < 0x200000) { |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
120 return cart[address]; |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
121 } else if(address >= 0x700000) { |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
122 return ram[address & 0x7FFF]; |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
123 } |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
124 //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
|
125 return 0; |
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 |
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
|
128 //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
|
129 //#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
|
130 #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
|
131 //#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
|
132 //#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
|
133 |
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
|
134 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
|
135 { |
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
|
136 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
|
137 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
|
138 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
|
139 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
|
140 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
|
141 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
|
142 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
|
143 } |
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 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
|
145 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
|
146 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
|
147 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
|
148 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
|
149 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
|
150 context->int_num = 4; |
488
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
151 |
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
|
152 } |
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 } |
186
02e25abe2dcd
Cleanup VINT code and fix bug in which VINT cycle would be set incorrectly after a VDP control port write
Mike Pavone <pavone@retrodev.com>
parents:
185
diff
changeset
|
154 } |
02e25abe2dcd
Cleanup VINT code and fix bug in which VINT cycle would be set incorrectly after a VDP control port write
Mike Pavone <pavone@retrodev.com>
parents:
185
diff
changeset
|
155 } |
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
|
156 |
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
|
157 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
|
158 /*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
|
159 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
|
160 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
|
161 } |
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
|
162 |
198
209a37eed3e7
Add support for breaking into the debugger while game is running
Mike Pavone <pavone@retrodev.com>
parents:
197
diff
changeset
|
163 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
|
164 int save_state = 0; |
260
625f8e4d5fd2
Initial stab at integartiong Z80 core
Mike Pavone <pavone@retrodev.com>
parents:
215
diff
changeset
|
165 |
625f8e4d5fd2
Initial stab at integartiong Z80 core
Mike Pavone <pavone@retrodev.com>
parents:
215
diff
changeset
|
166 uint8_t reset = 1; |
625f8e4d5fd2
Initial stab at integartiong Z80 core
Mike Pavone <pavone@retrodev.com>
parents:
215
diff
changeset
|
167 uint8_t need_reset = 0; |
625f8e4d5fd2
Initial stab at integartiong Z80 core
Mike Pavone <pavone@retrodev.com>
parents:
215
diff
changeset
|
168 uint8_t busreq = 0; |
625f8e4d5fd2
Initial stab at integartiong Z80 core
Mike Pavone <pavone@retrodev.com>
parents:
215
diff
changeset
|
169 uint8_t busack = 0; |
625f8e4d5fd2
Initial stab at integartiong Z80 core
Mike Pavone <pavone@retrodev.com>
parents:
215
diff
changeset
|
170 uint32_t busack_cycle = CYCLE_NEVER; |
625f8e4d5fd2
Initial stab at integartiong Z80 core
Mike Pavone <pavone@retrodev.com>
parents:
215
diff
changeset
|
171 uint8_t new_busack = 0; |
280 | 172 //#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
|
173 #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
|
174 #define dprintf printf |
271
969ee17471c5
Protect debug prints for busreq/reset regs with appropriate macros
Mike Pavone <pavone@retrodev.com>
parents:
268
diff
changeset
|
175 #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
|
176 #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
|
177 #define dprintf |
271
969ee17471c5
Protect debug prints for busreq/reset regs with appropriate macros
Mike Pavone <pavone@retrodev.com>
parents:
268
diff
changeset
|
178 #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
|
179 #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
|
180 |
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
|
181 #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
|
182 |
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
|
183 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
|
184 { |
265
c6d12878ea93
Add -n flag for disabling the Z80 core
Mike Pavone <pavone@retrodev.com>
parents:
264
diff
changeset
|
185 if (z80_enabled && !reset && !busreq) { |
333 | 186 genesis_context * gen = z_context->system; |
260
625f8e4d5fd2
Initial stab at integartiong Z80 core
Mike Pavone <pavone@retrodev.com>
parents:
215
diff
changeset
|
187 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
|
188 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
|
189 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
|
190 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
|
191 need_reset = 0; |
260
625f8e4d5fd2
Initial stab at integartiong Z80 core
Mike Pavone <pavone@retrodev.com>
parents:
215
diff
changeset
|
192 } |
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
|
193 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
|
194 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
|
195 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
|
196 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
|
197 } |
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 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
|
199 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
|
200 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
|
201 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
|
202 } |
260
625f8e4d5fd2
Initial stab at integartiong Z80 core
Mike Pavone <pavone@retrodev.com>
parents:
215
diff
changeset
|
203 } |
289
1cc0850ab6bc
Hopefully more correct implementation of the Z80 busack status
Mike Pavone <pavone@retrodev.com>
parents:
288
diff
changeset
|
204 } else { |
1cc0850ab6bc
Hopefully more correct implementation of the Z80 busack status
Mike Pavone <pavone@retrodev.com>
parents:
288
diff
changeset
|
205 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
|
206 } |
268
6c2d7e003a55
Sync Z80 on writes to busreq/reset ports. NULL out extra_pc on z80 reset
Mike Pavone <pavone@retrodev.com>
parents:
266
diff
changeset
|
207 } |
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
|
208 |
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
|
209 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
|
210 { |
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 //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
|
212 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
|
213 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
|
214 //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
|
215 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
|
216 //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
|
217 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
|
218 } |
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
|
219 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
|
220 ym_run(gen->ym, target); |
488
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
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 //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
|
223 } |
1c8d74f2ab0b
Make the PSG and YM2612 use the master clock internal with an increment based on clock divider so that they stay perflectly in sync. Run both the PSG and YM2612 whenver one of them needs to be run.
Mike Pavone <pavone@retrodev.com>
parents:
374
diff
changeset
|
224 |
321
146c87616b05
Don't update interrupt mask on non-interrupt exceptions
Mike Pavone <pavone@retrodev.com>
parents:
317
diff
changeset
|
225 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
|
226 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
|
227 { |
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
|
228 //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
|
229 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
|
230 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
|
231 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
|
232 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
|
233 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
|
234 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
|
235 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
|
236 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
|
237 gen->psg->cycles -= mclks_per_frame; |
374 | 238 if (gen->ym->write_cycle != CYCLE_NEVER) { |
239 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; | |
240 } | |
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
|
241 //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
|
242 vdp_run_context(v_context, mclks_per_frame); |
488
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
243 |
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
|
244 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
|
245 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
|
246 } 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
|
247 --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
|
248 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
|
249 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
|
250 } |
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
|
251 } |
321
146c87616b05
Don't update interrupt mask on non-interrupt exceptions
Mike Pavone <pavone@retrodev.com>
parents:
317
diff
changeset
|
252 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
|
253 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
|
254 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
|
255 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
|
256 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
|
257 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
|
258 if (busack_cycle != CYCLE_NEVER) { |
b46771135442
Handle busack across frame boundary
Mike Pavone <pavone@retrodev.com>
parents:
343
diff
changeset
|
259 if (busack_cycle > mclks_per_frame/MCLKS_PER_68K) { |
b46771135442
Handle busack across frame boundary
Mike Pavone <pavone@retrodev.com>
parents:
343
diff
changeset
|
260 busack_cycle -= mclks_per_frame/MCLKS_PER_68K; |
b46771135442
Handle busack across frame boundary
Mike Pavone <pavone@retrodev.com>
parents:
343
diff
changeset
|
261 } else { |
b46771135442
Handle busack across frame boundary
Mike Pavone <pavone@retrodev.com>
parents:
343
diff
changeset
|
262 busack_cycle = CYCLE_NEVER; |
b46771135442
Handle busack across frame boundary
Mike Pavone <pavone@retrodev.com>
parents:
343
diff
changeset
|
263 busack = new_busack; |
b46771135442
Handle busack across frame boundary
Mike Pavone <pavone@retrodev.com>
parents:
343
diff
changeset
|
264 } |
b46771135442
Handle busack across frame boundary
Mike Pavone <pavone@retrodev.com>
parents:
343
diff
changeset
|
265 } |
342
13f994c88c34
Get frame time correct and frame rate sort of correct for EUR region
Mike Pavone <pavone@retrodev.com>
parents:
341
diff
changeset
|
266 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
|
267 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
|
268 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
|
269 } else { |
625f8e4d5fd2
Initial stab at integartiong Z80 core
Mike Pavone <pavone@retrodev.com>
parents:
215
diff
changeset
|
270 z_context->current_cycle = 0; |
625f8e4d5fd2
Initial stab at integartiong Z80 core
Mike Pavone <pavone@retrodev.com>
parents:
215
diff
changeset
|
271 } |
88
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
272 if (mclks) { |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
273 vdp_run_context(v_context, mclks); |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
274 } |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
275 } else { |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
276 //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
|
277 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
|
278 sync_sound(gen, mclks); |
88
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
279 } |
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
|
280 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
|
281 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
|
282 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
|
283 } |
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
|
284 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
|
285 if (address) { |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
447
diff
changeset
|
286 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
|
287 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
|
288 debugger(context, address); |
209a37eed3e7
Add support for breaking into the debugger while game is running
Mike Pavone <pavone@retrodev.com>
parents:
197
diff
changeset
|
289 } |
451
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
447
diff
changeset
|
290 if (save_state) { |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
447
diff
changeset
|
291 save_state = 0; |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
447
diff
changeset
|
292 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
|
293 { |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
447
diff
changeset
|
294 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
|
295 } |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
447
diff
changeset
|
296 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
|
297 } |
198
209a37eed3e7
Add support for breaking into the debugger while game is running
Mike Pavone <pavone@retrodev.com>
parents:
197
diff
changeset
|
298 } |
88
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
299 return context; |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
300 } |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
301 |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
302 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
|
303 { |
343
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
304 if (vdp_port & 0x2700E0) { |
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
305 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
|
306 exit(1); |
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
307 } |
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
308 vdp_port &= 0x1F; |
88
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
309 //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
|
310 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
|
311 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
|
312 genesis_context * gen = context->system; |
88
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
313 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
|
314 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
|
315 uint32_t before_cycle = v_context->cycles; |
88
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
316 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
|
317 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
|
318 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
|
319 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
|
320 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
|
321 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
|
322 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
|
323 //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
|
324 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
|
325 } 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
|
326 --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
|
327 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
|
328 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
|
329 } |
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
|
330 } |
342
13f994c88c34
Get frame time correct and frame rate sort of correct for EUR region
Mike Pavone <pavone@retrodev.com>
parents:
341
diff
changeset
|
331 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
|
332 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
|
333 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
|
334 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
|
335 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
|
336 if (busack_cycle != CYCLE_NEVER) { |
b46771135442
Handle busack across frame boundary
Mike Pavone <pavone@retrodev.com>
parents:
343
diff
changeset
|
337 if (busack_cycle > mclks_per_frame/MCLKS_PER_68K) { |
b46771135442
Handle busack across frame boundary
Mike Pavone <pavone@retrodev.com>
parents:
343
diff
changeset
|
338 busack_cycle -= mclks_per_frame/MCLKS_PER_68K; |
b46771135442
Handle busack across frame boundary
Mike Pavone <pavone@retrodev.com>
parents:
343
diff
changeset
|
339 } else { |
b46771135442
Handle busack across frame boundary
Mike Pavone <pavone@retrodev.com>
parents:
343
diff
changeset
|
340 busack_cycle = CYCLE_NEVER; |
b46771135442
Handle busack across frame boundary
Mike Pavone <pavone@retrodev.com>
parents:
343
diff
changeset
|
341 busack = new_busack; |
b46771135442
Handle busack across frame boundary
Mike Pavone <pavone@retrodev.com>
parents:
343
diff
changeset
|
342 } |
b46771135442
Handle busack across frame boundary
Mike Pavone <pavone@retrodev.com>
parents:
343
diff
changeset
|
343 } |
88
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
344 } |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
345 } |
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
|
346 //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
|
347 } |
139e5dcd6aa3
Make writes to control and data port block when DMA is in progress
Mike Pavone <pavone@retrodev.com>
parents:
144
diff
changeset
|
348 } 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
|
349 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
|
350 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
|
351 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
|
352 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
|
353 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
|
354 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
|
355 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
|
356 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
|
357 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
|
358 } 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
|
359 --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
|
360 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
|
361 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
|
362 } |
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
|
363 } |
342
13f994c88c34
Get frame time correct and frame rate sort of correct for EUR region
Mike Pavone <pavone@retrodev.com>
parents:
341
diff
changeset
|
364 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
|
365 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
|
366 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
|
367 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
|
368 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
|
369 if (busack_cycle != CYCLE_NEVER) { |
b46771135442
Handle busack across frame boundary
Mike Pavone <pavone@retrodev.com>
parents:
343
diff
changeset
|
370 if (busack_cycle > mclks_per_frame/MCLKS_PER_68K) { |
b46771135442
Handle busack across frame boundary
Mike Pavone <pavone@retrodev.com>
parents:
343
diff
changeset
|
371 busack_cycle -= mclks_per_frame/MCLKS_PER_68K; |
b46771135442
Handle busack across frame boundary
Mike Pavone <pavone@retrodev.com>
parents:
343
diff
changeset
|
372 } else { |
b46771135442
Handle busack across frame boundary
Mike Pavone <pavone@retrodev.com>
parents:
343
diff
changeset
|
373 busack_cycle = CYCLE_NEVER; |
b46771135442
Handle busack across frame boundary
Mike Pavone <pavone@retrodev.com>
parents:
343
diff
changeset
|
374 busack = new_busack; |
b46771135442
Handle busack across frame boundary
Mike Pavone <pavone@retrodev.com>
parents:
343
diff
changeset
|
375 } |
b46771135442
Handle busack across frame boundary
Mike Pavone <pavone@retrodev.com>
parents:
343
diff
changeset
|
376 } |
149
139e5dcd6aa3
Make writes to control and data port block when DMA is in progress
Mike Pavone <pavone@retrodev.com>
parents:
144
diff
changeset
|
377 } |
139e5dcd6aa3
Make writes to control and data port block when DMA is in progress
Mike Pavone <pavone@retrodev.com>
parents:
144
diff
changeset
|
378 } |
139e5dcd6aa3
Make writes to control and data port block when DMA is in progress
Mike Pavone <pavone@retrodev.com>
parents:
144
diff
changeset
|
379 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
|
380 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
|
381 } else { |
139e5dcd6aa3
Make writes to control and data port block when DMA is in progress
Mike Pavone <pavone@retrodev.com>
parents:
144
diff
changeset
|
382 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 } |
139e5dcd6aa3
Make writes to control and data port block when DMA is in progress
Mike Pavone <pavone@retrodev.com>
parents:
144
diff
changeset
|
384 } |
88
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
385 } 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
|
386 adjust_int_cycle(context, v_context); |
88
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
387 } |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
388 } else { |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
389 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
|
390 exit(1); |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
391 } |
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
|
392 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
|
393 //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
|
394 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
|
395 } |
88
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
396 } 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
|
397 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
|
398 psg_write(gen->psg, value); |
88
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
399 } else { |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
400 //TODO: Implement undocumented test register(s) |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
401 } |
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
|
402 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
|
403 { |
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
|
404 //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
|
405 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
|
406 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
|
407 } |
88
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
408 return context; |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
409 } |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
410 |
343
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
411 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
|
412 { |
357
fa7ea48be9a9
Allow VDP/PSG writes from Z80
Mike Pavone <pavone@retrodev.com>
parents:
356
diff
changeset
|
413 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
|
414 } |
fa7ea48be9a9
Allow VDP/PSG writes from Z80
Mike Pavone <pavone@retrodev.com>
parents:
356
diff
changeset
|
415 |
fa7ea48be9a9
Allow VDP/PSG writes from Z80
Mike Pavone <pavone@retrodev.com>
parents:
356
diff
changeset
|
416 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
|
417 { |
fa7ea48be9a9
Allow VDP/PSG writes from Z80
Mike Pavone <pavone@retrodev.com>
parents:
356
diff
changeset
|
418 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
|
419 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
|
420 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
|
421 exit(1); |
9498cfa7f7c8
Make Z80 writes to VDP/PSG not potentially crash the emulator
Mike Pavone <pavone@retrodev.com>
parents:
357
diff
changeset
|
422 } |
9498cfa7f7c8
Make Z80 writes to VDP/PSG not potentially crash the emulator
Mike Pavone <pavone@retrodev.com>
parents:
357
diff
changeset
|
423 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
|
424 //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
|
425 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
|
426 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
|
427 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
|
428 } 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
|
429 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
|
430 } else { |
9498cfa7f7c8
Make Z80 writes to VDP/PSG not potentially crash the emulator
Mike Pavone <pavone@retrodev.com>
parents:
357
diff
changeset
|
431 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
|
432 exit(1); |
9498cfa7f7c8
Make Z80 writes to VDP/PSG not potentially crash the emulator
Mike Pavone <pavone@retrodev.com>
parents:
357
diff
changeset
|
433 } |
9498cfa7f7c8
Make Z80 writes to VDP/PSG not potentially crash the emulator
Mike Pavone <pavone@retrodev.com>
parents:
357
diff
changeset
|
434 } 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
|
435 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
|
436 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
|
437 } 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
|
438 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
|
439 } |
357
fa7ea48be9a9
Allow VDP/PSG writes from Z80
Mike Pavone <pavone@retrodev.com>
parents:
356
diff
changeset
|
440 return context; |
343
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
441 } |
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
442 |
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
443 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
|
444 { |
343
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
445 if (vdp_port & 0x2700E0) { |
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
446 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
|
447 exit(1); |
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
448 } |
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
449 vdp_port &= 0x1F; |
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
450 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
|
451 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
|
452 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
|
453 uint32_t before_cycle = v_context->cycles; |
88
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
454 if (vdp_port < 0x10) { |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
455 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
|
456 value = vdp_data_port_read(v_context); |
88
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
457 } 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
|
458 value = vdp_control_port_read(v_context); |
88
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
459 } else { |
343
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
460 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
|
461 //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
|
462 } |
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
|
463 } 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
|
464 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
|
465 exit(1); |
88
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
466 } 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
|
467 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
|
468 } |
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
|
469 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
|
470 //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
|
471 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
|
472 } |
343
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
473 return value; |
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
474 } |
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
475 |
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
476 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
|
477 { |
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
478 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
|
479 if (vdp_port & 1) { |
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
480 return value; |
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
481 } else { |
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
482 return value >> 8; |
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
483 } |
88
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
484 } |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
485 |
279
6be6056735a9
Fix native address lookup in bannked memory area
Mike Pavone <pavone@retrodev.com>
parents:
276
diff
changeset
|
486 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
|
487 #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
|
488 #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
|
489 #define Z80_REQ_BUSY 1 |
1cc0850ab6bc
Hopefully more correct implementation of the Z80 busack status
Mike Pavone <pavone@retrodev.com>
parents:
288
diff
changeset
|
490 #define Z80_REQ_ACK 0 |
1cc0850ab6bc
Hopefully more correct implementation of the Z80 busack status
Mike Pavone <pavone@retrodev.com>
parents:
288
diff
changeset
|
491 #define Z80_RES_BUSACK reset |
279
6be6056735a9
Fix native address lookup in bannked memory area
Mike Pavone <pavone@retrodev.com>
parents:
276
diff
changeset
|
492 |
88
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
493 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
|
494 { |
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
|
495 genesis_context * gen = context->system; |
153
42c031184e8a
Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents:
149
diff
changeset
|
496 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
|
497 if (busack_cycle <= context->current_cycle) { |
153
42c031184e8a
Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents:
149
diff
changeset
|
498 busack = new_busack; |
42c031184e8a
Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents:
149
diff
changeset
|
499 busack_cycle = CYCLE_NEVER; |
42c031184e8a
Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents:
149
diff
changeset
|
500 } |
42c031184e8a
Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents:
149
diff
changeset
|
501 if (!(busack || reset)) { |
42c031184e8a
Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents:
149
diff
changeset
|
502 location &= 0x7FFF; |
42c031184e8a
Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents:
149
diff
changeset
|
503 if (location < 0x4000) { |
42c031184e8a
Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents:
149
diff
changeset
|
504 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
|
505 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
|
506 } 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
|
507 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
|
508 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
|
509 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
|
510 } 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
|
511 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
|
512 } 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
|
513 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
|
514 } |
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
|
515 } 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
|
516 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
|
517 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
|
518 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
|
519 } 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
|
520 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
|
521 } |
395
0b5f93358a93
Add debugger command for saving Z80 RAM to a file
Mike Pavone <pavone@retrodev.com>
parents:
392
diff
changeset
|
522 } else { |
0b5f93358a93
Add debugger command for saving Z80 RAM to a file
Mike Pavone <pavone@retrodev.com>
parents:
392
diff
changeset
|
523 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
|
524 exit(1); |
153
42c031184e8a
Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents:
149
diff
changeset
|
525 } |
88
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
526 } |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
527 } else { |
153
42c031184e8a
Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents:
149
diff
changeset
|
528 location &= 0x1FFF; |
42c031184e8a
Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents:
149
diff
changeset
|
529 if (location < 0x100) { |
42c031184e8a
Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents:
149
diff
changeset
|
530 switch(location/2) |
42c031184e8a
Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents:
149
diff
changeset
|
531 { |
42c031184e8a
Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents:
149
diff
changeset
|
532 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
|
533 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
|
534 break; |
42c031184e8a
Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents:
149
diff
changeset
|
535 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
|
536 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
|
537 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
|
538 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
|
539 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
|
540 break; |
42c031184e8a
Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents:
149
diff
changeset
|
541 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
|
542 gen->ports[0].control = value; |
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 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
|
545 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
|
546 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
|
547 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
|
548 gen->ports[2].control = value; |
153
42c031184e8a
Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents:
149
diff
changeset
|
549 break; |
88
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
550 } |
153
42c031184e8a
Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents:
149
diff
changeset
|
551 } else { |
42c031184e8a
Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents:
149
diff
changeset
|
552 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
|
553 if (busack_cycle <= context->current_cycle) { |
153
42c031184e8a
Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents:
149
diff
changeset
|
554 busack = new_busack; |
42c031184e8a
Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents:
149
diff
changeset
|
555 busack_cycle = CYCLE_NEVER; |
88
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
556 } |
153
42c031184e8a
Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents:
149
diff
changeset
|
557 if (value & 1) { |
271
969ee17471c5
Protect debug prints for busreq/reset regs with appropriate macros
Mike Pavone <pavone@retrodev.com>
parents:
268
diff
changeset
|
558 dputs("bus requesting Z80"); |
488
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
559 |
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
|
560 if(!reset && !busreq) { |
482
4b24260125f3
Theoretically more correct timing of Z80 bus request
Mike Pavone <pavone@retrodev.com>
parents:
471
diff
changeset
|
561 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
|
562 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
|
563 new_busack = Z80_REQ_ACK; |
153
42c031184e8a
Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents:
149
diff
changeset
|
564 } |
364
62177cc39049
Incredibly broken YM2612 support plus a fix to Z80 bus request
Mike Pavone <pavone@retrodev.com>
parents:
362
diff
changeset
|
565 busreq = 1; |
153
42c031184e8a
Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents:
149
diff
changeset
|
566 } else { |
482
4b24260125f3
Theoretically more correct timing of Z80 bus request
Mike Pavone <pavone@retrodev.com>
parents:
471
diff
changeset
|
567 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
|
568 if (busreq) { |
271
969ee17471c5
Protect debug prints for busreq/reset regs with appropriate macros
Mike Pavone <pavone@retrodev.com>
parents:
268
diff
changeset
|
569 dputs("releasing z80 bus"); |
280 | 570 #ifdef DO_DEBUG_PRINT |
279
6be6056735a9
Fix native address lookup in bannked memory area
Mike Pavone <pavone@retrodev.com>
parents:
276
diff
changeset
|
571 char fname[20]; |
6be6056735a9
Fix native address lookup in bannked memory area
Mike Pavone <pavone@retrodev.com>
parents:
276
diff
changeset
|
572 sprintf(fname, "zram-%d", zram_counter++); |
6be6056735a9
Fix native address lookup in bannked memory area
Mike Pavone <pavone@retrodev.com>
parents:
276
diff
changeset
|
573 FILE * f = fopen(fname, "wb"); |
6be6056735a9
Fix native address lookup in bannked memory area
Mike Pavone <pavone@retrodev.com>
parents:
276
diff
changeset
|
574 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
|
575 fclose(f); |
280 | 576 #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
|
577 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
|
578 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
|
579 busreq = 0; |
260
625f8e4d5fd2
Initial stab at integartiong Z80 core
Mike Pavone <pavone@retrodev.com>
parents:
215
diff
changeset
|
580 } |
289
1cc0850ab6bc
Hopefully more correct implementation of the Z80 busack status
Mike Pavone <pavone@retrodev.com>
parents:
288
diff
changeset
|
581 //busack_cycle = CYCLE_NEVER; |
1cc0850ab6bc
Hopefully more correct implementation of the Z80 busack status
Mike Pavone <pavone@retrodev.com>
parents:
288
diff
changeset
|
582 //busack = Z80_REQ_BUSY; |
488
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
583 |
88
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
584 } |
153
42c031184e8a
Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents:
149
diff
changeset
|
585 } 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
|
586 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
|
587 if (value & 1) { |
42c031184e8a
Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents:
149
diff
changeset
|
588 if (reset && busreq) { |
42c031184e8a
Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents:
149
diff
changeset
|
589 new_busack = 0; |
289
1cc0850ab6bc
Hopefully more correct implementation of the Z80 busack status
Mike Pavone <pavone@retrodev.com>
parents:
288
diff
changeset
|
590 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
|
591 } |
260
625f8e4d5fd2
Initial stab at integartiong Z80 core
Mike Pavone <pavone@retrodev.com>
parents:
215
diff
changeset
|
592 //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
|
593 if (reset) { |
625f8e4d5fd2
Initial stab at integartiong Z80 core
Mike Pavone <pavone@retrodev.com>
parents:
215
diff
changeset
|
594 need_reset = 1; |
625f8e4d5fd2
Initial stab at integartiong Z80 core
Mike Pavone <pavone@retrodev.com>
parents:
215
diff
changeset
|
595 //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
|
596 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
|
597 } |
153
42c031184e8a
Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents:
149
diff
changeset
|
598 reset = 0; |
42c031184e8a
Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents:
149
diff
changeset
|
599 } else { |
42c031184e8a
Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents:
149
diff
changeset
|
600 reset = 1; |
42c031184e8a
Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents:
149
diff
changeset
|
601 } |
88
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
602 } |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
603 } |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
604 } |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
605 return context; |
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 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
|
609 { |
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
|
610 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
|
611 return io_write(location, context, value >> 8); |
88
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
612 } 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
|
613 return io_write(location, context, value); |
88
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
614 } |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
615 } |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
616 |
130
0bdbffa9fe90
Make version register return correct value for USA
Mike Pavone <pavone@retrodev.com>
parents:
115
diff
changeset
|
617 #define USA 0x80 |
0bdbffa9fe90
Make version register return correct value for USA
Mike Pavone <pavone@retrodev.com>
parents:
115
diff
changeset
|
618 #define JAP 0x00 |
0bdbffa9fe90
Make version register return correct value for USA
Mike Pavone <pavone@retrodev.com>
parents:
115
diff
changeset
|
619 #define EUR 0xC0 |
0bdbffa9fe90
Make version register return correct value for USA
Mike Pavone <pavone@retrodev.com>
parents:
115
diff
changeset
|
620 #define NO_DISK 0x20 |
0bdbffa9fe90
Make version register return correct value for USA
Mike Pavone <pavone@retrodev.com>
parents:
115
diff
changeset
|
621 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
|
622 |
343
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
623 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
|
624 { |
343
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
625 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
|
626 genesis_context *gen = context->system; |
153
42c031184e8a
Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents:
149
diff
changeset
|
627 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
|
628 if (busack_cycle <= context->current_cycle) { |
153
42c031184e8a
Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents:
149
diff
changeset
|
629 busack = new_busack; |
42c031184e8a
Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents:
149
diff
changeset
|
630 busack_cycle = CYCLE_NEVER; |
42c031184e8a
Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents:
149
diff
changeset
|
631 } |
289
1cc0850ab6bc
Hopefully more correct implementation of the Z80 busack status
Mike Pavone <pavone@retrodev.com>
parents:
288
diff
changeset
|
632 if (!(busack==Z80_REQ_BUSY || reset)) { |
153
42c031184e8a
Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents:
149
diff
changeset
|
633 location &= 0x7FFF; |
42c031184e8a
Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents:
149
diff
changeset
|
634 if (location < 0x4000) { |
343
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
635 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
|
636 } 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
|
637 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
|
638 value = ym_read_status(gen->ym); |
153
42c031184e8a
Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents:
149
diff
changeset
|
639 } else { |
343
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
640 value = 0xFF; |
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
641 } |
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
642 } else { |
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 location &= 0x1FFF; |
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
647 if (location < 0x100) { |
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
648 switch(location/2) |
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
649 { |
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
650 case 0x0: |
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
651 //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
|
652 value = version_reg; |
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
653 break; |
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
654 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
|
655 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
|
656 break; |
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
657 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
|
658 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
|
659 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
|
660 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
|
661 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
|
662 break; |
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
663 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
|
664 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
|
665 break; |
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
666 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
|
667 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
|
668 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
|
669 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
|
670 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
|
671 break; |
343
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
672 default: |
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
673 value = 0xFF; |
153
42c031184e8a
Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents:
149
diff
changeset
|
674 } |
42c031184e8a
Implement access to Z80 RAM
Mike Pavone <pavone@retrodev.com>
parents:
149
diff
changeset
|
675 } else { |
343
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
676 if (location == 0x1100) { |
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
677 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
|
678 busack = new_busack; |
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
679 busack_cycle = CYCLE_NEVER; |
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
680 } |
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
681 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
|
682 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
|
683 } else if (location == 0x1200) { |
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
684 value = !reset; |
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
685 } else { |
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
686 value = 0xFF; |
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
687 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
|
688 } |
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
689 } |
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
690 } |
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
691 return value; |
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 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
|
695 { |
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
|
696 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
|
697 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
|
698 value = value | (value << 8); |
88
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
699 } 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
|
700 value <<= 8; |
88
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
701 } |
343
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
702 return value; |
88
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
703 } |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
704 |
290
171f97e70d85
Implement writes from Z80 to YM-2612
Mike Pavone <pavone@retrodev.com>
parents:
289
diff
changeset
|
705 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
|
706 { |
171f97e70d85
Implement writes from Z80 to YM-2612
Mike Pavone <pavone@retrodev.com>
parents:
289
diff
changeset
|
707 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
|
708 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
|
709 if (location & 1) { |
171f97e70d85
Implement writes from Z80 to YM-2612
Mike Pavone <pavone@retrodev.com>
parents:
289
diff
changeset
|
710 ym_data_write(gen->ym, value); |
171f97e70d85
Implement writes from Z80 to YM-2612
Mike Pavone <pavone@retrodev.com>
parents:
289
diff
changeset
|
711 } else if (location & 2) { |
171f97e70d85
Implement writes from Z80 to YM-2612
Mike Pavone <pavone@retrodev.com>
parents:
289
diff
changeset
|
712 ym_address_write_part2(gen->ym, value); |
171f97e70d85
Implement writes from Z80 to YM-2612
Mike Pavone <pavone@retrodev.com>
parents:
289
diff
changeset
|
713 } else { |
171f97e70d85
Implement writes from Z80 to YM-2612
Mike Pavone <pavone@retrodev.com>
parents:
289
diff
changeset
|
714 ym_address_write_part1(gen->ym, value); |
171f97e70d85
Implement writes from Z80 to YM-2612
Mike Pavone <pavone@retrodev.com>
parents:
289
diff
changeset
|
715 } |
171f97e70d85
Implement writes from Z80 to YM-2612
Mike Pavone <pavone@retrodev.com>
parents:
289
diff
changeset
|
716 return context; |
171f97e70d85
Implement writes from Z80 to YM-2612
Mike Pavone <pavone@retrodev.com>
parents:
289
diff
changeset
|
717 } |
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 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
|
720 { |
171f97e70d85
Implement writes from Z80 to YM-2612
Mike Pavone <pavone@retrodev.com>
parents:
289
diff
changeset
|
721 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
|
722 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
|
723 return ym_read_status(gen->ym); |
171f97e70d85
Implement writes from Z80 to YM-2612
Mike Pavone <pavone@retrodev.com>
parents:
289
diff
changeset
|
724 } |
171f97e70d85
Implement writes from Z80 to YM-2612
Mike Pavone <pavone@retrodev.com>
parents:
289
diff
changeset
|
725 |
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
|
726 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
|
727 { |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
728 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
|
729 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
|
730 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
|
731 { |
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 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
|
733 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
|
734 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
|
735 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
|
736 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
|
737 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
|
738 } |
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 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
|
740 } |
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 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
|
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 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
|
745 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
|
746 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
|
747 { |
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 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
|
749 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
|
750 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
|
751 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
|
752 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
|
753 } 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
|
754 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
|
755 } |
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 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
|
757 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
|
758 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
|
759 } 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
|
760 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
|
761 } |
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 } |
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;//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
|
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 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
|
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 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
|
769 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
|
770 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
|
771 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
|
772 { |
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 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
|
774 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
|
775 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
|
776 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
|
777 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
|
778 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
|
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_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
|
781 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
|
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 } |
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 } |
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 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
|
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 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
|
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 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
|
791 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
|
792 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
|
793 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
|
794 { |
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 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
|
796 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
|
797 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
|
798 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
|
799 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
|
800 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
|
801 } |
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 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
|
803 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
|
804 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
|
805 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
|
806 } |
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 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
|
808 } |
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 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
|
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 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
|
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 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
|
816 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
|
817 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
|
818 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
|
819 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
|
820 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
|
821 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
|
822 } 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
|
823 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
|
824 } |
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 } |
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 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
|
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 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
|
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 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
|
832 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
|
833 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
|
834 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 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
|
836 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
|
837 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
|
838 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
|
839 } 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
|
840 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
|
841 } |
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 } |
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 } |
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 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
|
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 |
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
|
847 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
|
848 { |
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
|
849 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
|
850 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
|
851 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
|
852 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
|
853 } |
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
|
854 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
|
855 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
|
856 } |
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
|
857 |
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
|
858 #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
|
859 #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
|
860 #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
|
861 #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
|
862 #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
|
863 #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
|
864 #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
|
865 |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
866 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
|
867 {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
|
868 NULL, NULL, NULL, NULL}, |
488
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
869 {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
|
870 NULL, NULL, NULL, NULL}, |
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
871 {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
|
872 (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
|
873 (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
|
874 {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
|
875 (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
|
876 (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
|
877 }; |
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
|
878 |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
879 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
|
880 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
|
881 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
|
882 { |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
883 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
|
884 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
|
885 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
|
886 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
|
887 } |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
888 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
|
889 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
|
890 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
|
891 } |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
892 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
|
893 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
|
894 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
|
895 } |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
896 |
515
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
510
diff
changeset
|
897 void init_run_cpu(genesis_context * gen, FILE * address_log, char * statefile, uint8_t * debugger) |
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
|
898 { |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
899 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
|
900 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
|
901 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
|
902 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
|
903 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
|
904 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
|
905 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
|
906 //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
|
907 //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
|
908 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
|
909 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
|
910 //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
|
911 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
|
912 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
|
913 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
|
914 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
|
915 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
|
916 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
|
917 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
|
918 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
|
919 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
|
920 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
|
921 memmap[0].buffer = cart; |
488
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
922 |
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
|
923 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
|
924 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
|
925 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
|
926 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
|
927 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
|
928 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
|
929 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
|
930 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
|
931 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
|
932 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
|
933 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
|
934 } 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
|
935 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
|
936 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
|
937 } |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
938 memmap[1].buffer = gen->save_ram = malloc(size); |
488
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
939 |
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
|
940 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
|
941 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
|
942 } 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
|
943 //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
|
944 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
|
945 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
|
946 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
|
947 memmap[0].buffer = cart; |
488
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
948 |
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
|
949 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
|
950 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
|
951 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
|
952 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
|
953 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
|
954 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
|
955 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
|
956 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
|
957 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
|
958 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
|
959 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
|
960 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
|
961 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
|
962 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
|
963 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
|
964 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
|
965 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
|
966 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
|
967 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
|
968 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
|
969 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
|
970 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
|
971 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
|
972 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
|
973 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
|
974 } |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
975 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
|
976 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
|
977 } |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
978 } 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
|
979 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
|
980 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
|
981 } |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
982 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
|
983 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
|
984 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
|
985 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
|
986 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
|
987 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
|
988 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
|
989 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
|
990 } |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
991 } |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
992 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
|
993 } |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
994 init_x86_68k_opts(&opts, memmap, num_chunks); |
211 | 995 opts.address_log = address_log; |
996 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
|
997 |
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
|
998 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
|
999 context.system = gen; |
211 | 1000 //cartridge ROM |
1001 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
|
1002 context.target_cycle = context.sync_cycle = mclks_per_frame/MCLKS_PER_68K; |
211 | 1003 //work RAM |
1004 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
|
1005 //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
|
1006 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
|
1007 context.mem_pointers[3] = (uint16_t *)gen->save_ram; |
211 | 1008 uint32_t address; |
1009 address = cart[2] << 16 | cart[3]; | |
1010 translate_m68k_stream(address, &context); | |
424
7e8e179116af
Add support for loading GST format savestates
Mike Pavone <pavone@retrodev.com>
parents:
422
diff
changeset
|
1011 if (statefile) { |
7e8e179116af
Add support for loading GST format savestates
Mike Pavone <pavone@retrodev.com>
parents:
422
diff
changeset
|
1012 uint32_t pc = load_gst(gen, statefile); |
7e8e179116af
Add support for loading GST format savestates
Mike Pavone <pavone@retrodev.com>
parents:
422
diff
changeset
|
1013 if (!pc) { |
451
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
447
diff
changeset
|
1014 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
|
1015 exit(1); |
7e8e179116af
Add support for loading GST format savestates
Mike Pavone <pavone@retrodev.com>
parents:
422
diff
changeset
|
1016 } |
451
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
447
diff
changeset
|
1017 printf("Loaded %s\n", statefile); |
515
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
510
diff
changeset
|
1018 if (debugger) { |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
510
diff
changeset
|
1019 insert_breakpoint(&context, pc, debugger); |
424
7e8e179116af
Add support for loading GST format savestates
Mike Pavone <pavone@retrodev.com>
parents:
422
diff
changeset
|
1020 } |
451
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
447
diff
changeset
|
1021 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
|
1022 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
|
1023 start_68k_context(&context, pc); |
7e8e179116af
Add support for loading GST format savestates
Mike Pavone <pavone@retrodev.com>
parents:
422
diff
changeset
|
1024 } else { |
515
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
510
diff
changeset
|
1025 if (debugger) { |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
510
diff
changeset
|
1026 insert_breakpoint(&context, address, debugger); |
424
7e8e179116af
Add support for loading GST format savestates
Mike Pavone <pavone@retrodev.com>
parents:
422
diff
changeset
|
1027 } |
7e8e179116af
Add support for loading GST format savestates
Mike Pavone <pavone@retrodev.com>
parents:
422
diff
changeset
|
1028 m68k_reset(&context); |
211 | 1029 } |
1030 } | |
1031 | |
340
58a085cfc6bd
Set window title based on ROM header name
Mike Pavone <pavone@retrodev.com>
parents:
338
diff
changeset
|
1032 char title[64]; |
58a085cfc6bd
Set window title based on ROM header name
Mike Pavone <pavone@retrodev.com>
parents:
338
diff
changeset
|
1033 |
58a085cfc6bd
Set window title based on ROM header name
Mike Pavone <pavone@retrodev.com>
parents:
338
diff
changeset
|
1034 #define TITLE_START 0x150 |
58a085cfc6bd
Set window title based on ROM header name
Mike Pavone <pavone@retrodev.com>
parents:
338
diff
changeset
|
1035 #define TITLE_END (TITLE_START+48) |
58a085cfc6bd
Set window title based on ROM header name
Mike Pavone <pavone@retrodev.com>
parents:
338
diff
changeset
|
1036 |
58a085cfc6bd
Set window title based on ROM header name
Mike Pavone <pavone@retrodev.com>
parents:
338
diff
changeset
|
1037 void update_title() |
58a085cfc6bd
Set window title based on ROM header name
Mike Pavone <pavone@retrodev.com>
parents:
338
diff
changeset
|
1038 { |
58a085cfc6bd
Set window title based on ROM header name
Mike Pavone <pavone@retrodev.com>
parents:
338
diff
changeset
|
1039 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
|
1040 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
|
1041 { |
58a085cfc6bd
Set window title based on ROM header name
Mike Pavone <pavone@retrodev.com>
parents:
338
diff
changeset
|
1042 last--; |
58a085cfc6bd
Set window title based on ROM header name
Mike Pavone <pavone@retrodev.com>
parents:
338
diff
changeset
|
1043 } |
58a085cfc6bd
Set window title based on ROM header name
Mike Pavone <pavone@retrodev.com>
parents:
338
diff
changeset
|
1044 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
|
1045 char *cur = title; |
58a085cfc6bd
Set window title based on ROM header name
Mike Pavone <pavone@retrodev.com>
parents:
338
diff
changeset
|
1046 char last_char = ' '; |
58a085cfc6bd
Set window title based on ROM header name
Mike Pavone <pavone@retrodev.com>
parents:
338
diff
changeset
|
1047 for (; start != last; start++) |
58a085cfc6bd
Set window title based on ROM header name
Mike Pavone <pavone@retrodev.com>
parents:
338
diff
changeset
|
1048 { |
58a085cfc6bd
Set window title based on ROM header name
Mike Pavone <pavone@retrodev.com>
parents:
338
diff
changeset
|
1049 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
|
1050 *(cur++) = *start >> 8; |
58a085cfc6bd
Set window title based on ROM header name
Mike Pavone <pavone@retrodev.com>
parents:
338
diff
changeset
|
1051 last_char = *start >> 8; |
58a085cfc6bd
Set window title based on ROM header name
Mike Pavone <pavone@retrodev.com>
parents:
338
diff
changeset
|
1052 } |
58a085cfc6bd
Set window title based on ROM header name
Mike Pavone <pavone@retrodev.com>
parents:
338
diff
changeset
|
1053 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
|
1054 *(cur++) = *start; |
58a085cfc6bd
Set window title based on ROM header name
Mike Pavone <pavone@retrodev.com>
parents:
338
diff
changeset
|
1055 last_char = *start & 0xFF; |
58a085cfc6bd
Set window title based on ROM header name
Mike Pavone <pavone@retrodev.com>
parents:
338
diff
changeset
|
1056 } |
58a085cfc6bd
Set window title based on ROM header name
Mike Pavone <pavone@retrodev.com>
parents:
338
diff
changeset
|
1057 } |
58a085cfc6bd
Set window title based on ROM header name
Mike Pavone <pavone@retrodev.com>
parents:
338
diff
changeset
|
1058 *(cur++) = *start >> 8; |
58a085cfc6bd
Set window title based on ROM header name
Mike Pavone <pavone@retrodev.com>
parents:
338
diff
changeset
|
1059 if ((*start & 0xFF) != ' ') { |
58a085cfc6bd
Set window title based on ROM header name
Mike Pavone <pavone@retrodev.com>
parents:
338
diff
changeset
|
1060 *(cur++) = *start; |
58a085cfc6bd
Set window title based on ROM header name
Mike Pavone <pavone@retrodev.com>
parents:
338
diff
changeset
|
1061 } |
58a085cfc6bd
Set window title based on ROM header name
Mike Pavone <pavone@retrodev.com>
parents:
338
diff
changeset
|
1062 strcpy(cur, " - BlastEm"); |
58a085cfc6bd
Set window title based on ROM header name
Mike Pavone <pavone@retrodev.com>
parents:
338
diff
changeset
|
1063 } |
58a085cfc6bd
Set window title based on ROM header name
Mike Pavone <pavone@retrodev.com>
parents:
338
diff
changeset
|
1064 |
341
6ad8e36de685
Support regions other than USA
Mike Pavone <pavone@retrodev.com>
parents:
340
diff
changeset
|
1065 #define REGION_START 0x1F0 |
6ad8e36de685
Support regions other than USA
Mike Pavone <pavone@retrodev.com>
parents:
340
diff
changeset
|
1066 |
6ad8e36de685
Support regions other than USA
Mike Pavone <pavone@retrodev.com>
parents:
340
diff
changeset
|
1067 int detect_specific_region(char region) |
6ad8e36de685
Support regions other than USA
Mike Pavone <pavone@retrodev.com>
parents:
340
diff
changeset
|
1068 { |
346
aff29d50afd5
Fix a region detection bug
Mike Pavone <pavone@retrodev.com>
parents:
345
diff
changeset
|
1069 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
|
1070 } |
6ad8e36de685
Support regions other than USA
Mike Pavone <pavone@retrodev.com>
parents:
340
diff
changeset
|
1071 |
6ad8e36de685
Support regions other than USA
Mike Pavone <pavone@retrodev.com>
parents:
340
diff
changeset
|
1072 void detect_region() |
6ad8e36de685
Support regions other than USA
Mike Pavone <pavone@retrodev.com>
parents:
340
diff
changeset
|
1073 { |
343
467bfa17004a
Mostly working runtime generation of memory map read/write functions
Mike Pavone <pavone@retrodev.com>
parents:
342
diff
changeset
|
1074 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
|
1075 version_reg = NO_DISK | USA; |
6ad8e36de685
Support regions other than USA
Mike Pavone <pavone@retrodev.com>
parents:
340
diff
changeset
|
1076 } else if (detect_specific_region('J')) { |
6ad8e36de685
Support regions other than USA
Mike Pavone <pavone@retrodev.com>
parents:
340
diff
changeset
|
1077 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
|
1078 } 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
|
1079 version_reg = NO_DISK | EUR; |
434
f0631c85a90b
Read default region from config file
Mike Pavone <pavone@retrodev.com>
parents:
433
diff
changeset
|
1080 } else { |
f0631c85a90b
Read default region from config file
Mike Pavone <pavone@retrodev.com>
parents:
433
diff
changeset
|
1081 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
|
1082 if (def_region) { |
f0631c85a90b
Read default region from config file
Mike Pavone <pavone@retrodev.com>
parents:
433
diff
changeset
|
1083 switch(*def_region) |
f0631c85a90b
Read default region from config file
Mike Pavone <pavone@retrodev.com>
parents:
433
diff
changeset
|
1084 { |
f0631c85a90b
Read default region from config file
Mike Pavone <pavone@retrodev.com>
parents:
433
diff
changeset
|
1085 case 'j': |
f0631c85a90b
Read default region from config file
Mike Pavone <pavone@retrodev.com>
parents:
433
diff
changeset
|
1086 case 'J': |
f0631c85a90b
Read default region from config file
Mike Pavone <pavone@retrodev.com>
parents:
433
diff
changeset
|
1087 version_reg = NO_DISK | JAP; |
f0631c85a90b
Read default region from config file
Mike Pavone <pavone@retrodev.com>
parents:
433
diff
changeset
|
1088 break; |
f0631c85a90b
Read default region from config file
Mike Pavone <pavone@retrodev.com>
parents:
433
diff
changeset
|
1089 case 'u': |
f0631c85a90b
Read default region from config file
Mike Pavone <pavone@retrodev.com>
parents:
433
diff
changeset
|
1090 case 'U': |
f0631c85a90b
Read default region from config file
Mike Pavone <pavone@retrodev.com>
parents:
433
diff
changeset
|
1091 version_reg = NO_DISK | USA; |
f0631c85a90b
Read default region from config file
Mike Pavone <pavone@retrodev.com>
parents:
433
diff
changeset
|
1092 break; |
f0631c85a90b
Read default region from config file
Mike Pavone <pavone@retrodev.com>
parents:
433
diff
changeset
|
1093 case 'e': |
f0631c85a90b
Read default region from config file
Mike Pavone <pavone@retrodev.com>
parents:
433
diff
changeset
|
1094 case 'E': |
f0631c85a90b
Read default region from config file
Mike Pavone <pavone@retrodev.com>
parents:
433
diff
changeset
|
1095 version_reg = NO_DISK | EUR; |
f0631c85a90b
Read default region from config file
Mike Pavone <pavone@retrodev.com>
parents:
433
diff
changeset
|
1096 break; |
f0631c85a90b
Read default region from config file
Mike Pavone <pavone@retrodev.com>
parents:
433
diff
changeset
|
1097 } |
f0631c85a90b
Read default region from config file
Mike Pavone <pavone@retrodev.com>
parents:
433
diff
changeset
|
1098 } |
341
6ad8e36de685
Support regions other than USA
Mike Pavone <pavone@retrodev.com>
parents:
340
diff
changeset
|
1099 } |
6ad8e36de685
Support regions other than USA
Mike Pavone <pavone@retrodev.com>
parents:
340
diff
changeset
|
1100 } |
6ad8e36de685
Support regions other than USA
Mike Pavone <pavone@retrodev.com>
parents:
340
diff
changeset
|
1101 |
88
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1102 int main(int argc, char ** argv) |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1103 { |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1104 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
|
1105 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
|
1106 return 1; |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1107 } |
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
|
1108 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
|
1109 config = load_config(); |
341
6ad8e36de685
Support regions other than USA
Mike Pavone <pavone@retrodev.com>
parents:
340
diff
changeset
|
1110 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
|
1111 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
|
1112 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
|
1113 int debug = 0; |
407
c3abc4ada43d
Add support for logging YM2612 channels to WAVE files
Mike Pavone <pavone@retrodev.com>
parents:
405
diff
changeset
|
1114 int ym_log = 0; |
463
a1d298119153
Added -h help text option
Mike Pavone <pavone@retrodev.com>
parents:
458
diff
changeset
|
1115 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
|
1116 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
|
1117 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
|
1118 FILE *address_log = NULL; |
425
8b3ae850d1c4
Forgot to null initialize the statfile pointer
Mike Pavone <pavone@retrodev.com>
parents:
424
diff
changeset
|
1119 char * statefile = NULL; |
515
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
510
diff
changeset
|
1120 uint8_t * debuggerfun = NULL; |
501
e1355aa80f4d
Use OpenGL by default. Add OpenGL switch to help text
Mike Pavone <pavone@retrodev.com>
parents:
496
diff
changeset
|
1121 uint8_t fullscreen = 0, use_gl = 1; |
463
a1d298119153
Added -h help text option
Mike Pavone <pavone@retrodev.com>
parents:
458
diff
changeset
|
1122 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
|
1123 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
|
1124 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
|
1125 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
|
1126 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
|
1127 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
|
1128 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
|
1129 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
|
1130 } |
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
|
1131 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
|
1132 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
|
1133 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
|
1134 case 'd': |
515
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
510
diff
changeset
|
1135 debuggerfun = (uint8_t *)debugger; |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
510
diff
changeset
|
1136 break; |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
510
diff
changeset
|
1137 case 'D': |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
510
diff
changeset
|
1138 gdb_remote_init(); |
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
510
diff
changeset
|
1139 debuggerfun = (uint8_t *)gdb_debug_enter; |
184
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1140 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
|
1141 case 'f': |
444
cc754a309ead
Add fullscreen support and add a keybinding for exiting the emulator
Mike Pavone <pavone@retrodev.com>
parents:
434
diff
changeset
|
1142 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
|
1143 break; |
488
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
1144 case 'g': |
501
e1355aa80f4d
Use OpenGL by default. Add OpenGL switch to help text
Mike Pavone <pavone@retrodev.com>
parents:
496
diff
changeset
|
1145 use_gl = 0; |
488
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
1146 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
|
1147 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
|
1148 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
|
1149 break; |
464 | 1150 case 'v': |
1151 printf("blastem %s\n", BLASTEM_VERSION); | |
1152 return 0; | |
1153 break; | |
265
c6d12878ea93
Add -n flag for disabling the Z80 core
Mike Pavone <pavone@retrodev.com>
parents:
264
diff
changeset
|
1154 case 'n': |
c6d12878ea93
Add -n flag for disabling the Z80 core
Mike Pavone <pavone@retrodev.com>
parents:
264
diff
changeset
|
1155 z80_enabled = 0; |
c6d12878ea93
Add -n flag for disabling the Z80 core
Mike Pavone <pavone@retrodev.com>
parents:
264
diff
changeset
|
1156 break; |
341
6ad8e36de685
Support regions other than USA
Mike Pavone <pavone@retrodev.com>
parents:
340
diff
changeset
|
1157 case 'r': |
6ad8e36de685
Support regions other than USA
Mike Pavone <pavone@retrodev.com>
parents:
340
diff
changeset
|
1158 i++; |
6ad8e36de685
Support regions other than USA
Mike Pavone <pavone@retrodev.com>
parents:
340
diff
changeset
|
1159 if (i >= argc) { |
6ad8e36de685
Support regions other than USA
Mike Pavone <pavone@retrodev.com>
parents:
340
diff
changeset
|
1160 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
|
1161 return 1; |
6ad8e36de685
Support regions other than USA
Mike Pavone <pavone@retrodev.com>
parents:
340
diff
changeset
|
1162 } |
6ad8e36de685
Support regions other than USA
Mike Pavone <pavone@retrodev.com>
parents:
340
diff
changeset
|
1163 switch (argv[i][0]) |
6ad8e36de685
Support regions other than USA
Mike Pavone <pavone@retrodev.com>
parents:
340
diff
changeset
|
1164 { |
6ad8e36de685
Support regions other than USA
Mike Pavone <pavone@retrodev.com>
parents:
340
diff
changeset
|
1165 case 'j': |
6ad8e36de685
Support regions other than USA
Mike Pavone <pavone@retrodev.com>
parents:
340
diff
changeset
|
1166 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
|
1167 force_version = NO_DISK | JAP; |
341
6ad8e36de685
Support regions other than USA
Mike Pavone <pavone@retrodev.com>
parents:
340
diff
changeset
|
1168 break; |
6ad8e36de685
Support regions other than USA
Mike Pavone <pavone@retrodev.com>
parents:
340
diff
changeset
|
1169 case 'u': |
6ad8e36de685
Support regions other than USA
Mike Pavone <pavone@retrodev.com>
parents:
340
diff
changeset
|
1170 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
|
1171 force_version = NO_DISK | USA; |
341
6ad8e36de685
Support regions other than USA
Mike Pavone <pavone@retrodev.com>
parents:
340
diff
changeset
|
1172 break; |
6ad8e36de685
Support regions other than USA
Mike Pavone <pavone@retrodev.com>
parents:
340
diff
changeset
|
1173 case 'e': |
6ad8e36de685
Support regions other than USA
Mike Pavone <pavone@retrodev.com>
parents:
340
diff
changeset
|
1174 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
|
1175 force_version = NO_DISK | EUR; |
341
6ad8e36de685
Support regions other than USA
Mike Pavone <pavone@retrodev.com>
parents:
340
diff
changeset
|
1176 break; |
6ad8e36de685
Support regions other than USA
Mike Pavone <pavone@retrodev.com>
parents:
340
diff
changeset
|
1177 default: |
6ad8e36de685
Support regions other than USA
Mike Pavone <pavone@retrodev.com>
parents:
340
diff
changeset
|
1178 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
|
1179 return 1; |
6ad8e36de685
Support regions other than USA
Mike Pavone <pavone@retrodev.com>
parents:
340
diff
changeset
|
1180 } |
6ad8e36de685
Support regions other than USA
Mike Pavone <pavone@retrodev.com>
parents:
340
diff
changeset
|
1181 break; |
424
7e8e179116af
Add support for loading GST format savestates
Mike Pavone <pavone@retrodev.com>
parents:
422
diff
changeset
|
1182 case 's': |
7e8e179116af
Add support for loading GST format savestates
Mike Pavone <pavone@retrodev.com>
parents:
422
diff
changeset
|
1183 i++; |
7e8e179116af
Add support for loading GST format savestates
Mike Pavone <pavone@retrodev.com>
parents:
422
diff
changeset
|
1184 if (i >= argc) { |
7e8e179116af
Add support for loading GST format savestates
Mike Pavone <pavone@retrodev.com>
parents:
422
diff
changeset
|
1185 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
|
1186 return 1; |
7e8e179116af
Add support for loading GST format savestates
Mike Pavone <pavone@retrodev.com>
parents:
422
diff
changeset
|
1187 } |
7e8e179116af
Add support for loading GST format savestates
Mike Pavone <pavone@retrodev.com>
parents:
422
diff
changeset
|
1188 statefile = argv[i]; |
7e8e179116af
Add support for loading GST format savestates
Mike Pavone <pavone@retrodev.com>
parents:
422
diff
changeset
|
1189 break; |
407
c3abc4ada43d
Add support for logging YM2612 channels to WAVE files
Mike Pavone <pavone@retrodev.com>
parents:
405
diff
changeset
|
1190 case 'y': |
c3abc4ada43d
Add support for logging YM2612 channels to WAVE files
Mike Pavone <pavone@retrodev.com>
parents:
405
diff
changeset
|
1191 ym_log = 1; |
c3abc4ada43d
Add support for logging YM2612 channels to WAVE files
Mike Pavone <pavone@retrodev.com>
parents:
405
diff
changeset
|
1192 break; |
463
a1d298119153
Added -h help text option
Mike Pavone <pavone@retrodev.com>
parents:
458
diff
changeset
|
1193 case 'h': |
a1d298119153
Added -h help text option
Mike Pavone <pavone@retrodev.com>
parents:
458
diff
changeset
|
1194 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
|
1195 "Usage: blastem [OPTIONS] ROMFILE [WIDTH] [HEIGHT]\n" |
463
a1d298119153
Added -h help text option
Mike Pavone <pavone@retrodev.com>
parents:
458
diff
changeset
|
1196 "Options:\n" |
a1d298119153
Added -h help text option
Mike Pavone <pavone@retrodev.com>
parents:
458
diff
changeset
|
1197 " -h Print this help text\n" |
a1d298119153
Added -h help text option
Mike Pavone <pavone@retrodev.com>
parents:
458
diff
changeset
|
1198 " -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
|
1199 " -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
|
1200 " -g Disable OpenGL rendering\n" |
463
a1d298119153
Added -h help text option
Mike Pavone <pavone@retrodev.com>
parents:
458
diff
changeset
|
1201 " -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
|
1202 " -d Enter debugger on startup\n" |
a1d298119153
Added -h help text option
Mike Pavone <pavone@retrodev.com>
parents:
458
diff
changeset
|
1203 " -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
|
1204 " -v Display version number and exit\n" |
463
a1d298119153
Added -h help text option
Mike Pavone <pavone@retrodev.com>
parents:
458
diff
changeset
|
1205 " -l Log 68K code addresses (useful for assemblers)\n" |
a1d298119153
Added -h help text option
Mike Pavone <pavone@retrodev.com>
parents:
458
diff
changeset
|
1206 " -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
|
1207 ); |
a1d298119153
Added -h help text option
Mike Pavone <pavone@retrodev.com>
parents:
458
diff
changeset
|
1208 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
|
1209 default: |
ebcbdd1c4cc8
Fix a bunch of bugs in the CPU core, add a 68K debugger
Mike Pavone <pavone@retrodev.com>
parents:
166
diff
changeset
|
1210 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
|
1211 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
|
1212 } |
463
a1d298119153
Added -h help text option
Mike Pavone <pavone@retrodev.com>
parents:
458
diff
changeset
|
1213 } else if (!loaded) { |
a1d298119153
Added -h help text option
Mike Pavone <pavone@retrodev.com>
parents:
458
diff
changeset
|
1214 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
|
1215 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
|
1216 return 1; |
a1d298119153
Added -h help text option
Mike Pavone <pavone@retrodev.com>
parents:
458
diff
changeset
|
1217 } |
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
|
1218 romfname = argv[i]; |
463
a1d298119153
Added -h help text option
Mike Pavone <pavone@retrodev.com>
parents:
458
diff
changeset
|
1219 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
|
1220 } 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
|
1221 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
|
1222 } 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
|
1223 height = atoi(argv[i]); |
88
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1224 } |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1225 } |
463
a1d298119153
Added -h help text option
Mike Pavone <pavone@retrodev.com>
parents:
458
diff
changeset
|
1226 if (!loaded) { |
a1d298119153
Added -h help text option
Mike Pavone <pavone@retrodev.com>
parents:
458
diff
changeset
|
1227 fputs("You must specify a ROM filename!\n", stderr); |
a1d298119153
Added -h help text option
Mike Pavone <pavone@retrodev.com>
parents:
458
diff
changeset
|
1228 return 1; |
a1d298119153
Added -h help text option
Mike Pavone <pavone@retrodev.com>
parents:
458
diff
changeset
|
1229 } |
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
|
1230 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
|
1231 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
|
1232 } |
340
58a085cfc6bd
Set window title based on ROM header name
Mike Pavone <pavone@retrodev.com>
parents:
338
diff
changeset
|
1233 update_title(); |
433
ed4d0017c041
Read default render width from config file
Mike Pavone <pavone@retrodev.com>
parents:
430
diff
changeset
|
1234 int def_width = 0; |
ed4d0017c041
Read default render width from config file
Mike Pavone <pavone@retrodev.com>
parents:
430
diff
changeset
|
1235 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
|
1236 if (config_width) { |
ed4d0017c041
Read default render width from config file
Mike Pavone <pavone@retrodev.com>
parents:
430
diff
changeset
|
1237 def_width = atoi(config_width); |
ed4d0017c041
Read default render width from config file
Mike Pavone <pavone@retrodev.com>
parents:
430
diff
changeset
|
1238 } |
ed4d0017c041
Read default render width from config file
Mike Pavone <pavone@retrodev.com>
parents:
430
diff
changeset
|
1239 if (!def_width) { |
ed4d0017c041
Read default render width from config file
Mike Pavone <pavone@retrodev.com>
parents:
430
diff
changeset
|
1240 def_width = 640; |
ed4d0017c041
Read default render width from config file
Mike Pavone <pavone@retrodev.com>
parents:
430
diff
changeset
|
1241 } |
ed4d0017c041
Read default render width from config file
Mike Pavone <pavone@retrodev.com>
parents:
430
diff
changeset
|
1242 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
|
1243 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
|
1244 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
|
1245 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
|
1246 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
|
1247 fps = 50; |
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
351
diff
changeset
|
1248 } |
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
351
diff
changeset
|
1249 if (!headless) { |
488
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
1250 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
|
1251 } |
88
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1252 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
|
1253 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
|
1254 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
|
1255 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
|
1256 |
88
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1257 init_vdp_context(&v_context); |
488
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
1258 |
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
|
1259 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
|
1260 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
|
1261 |
354
15dd6418fe67
Initial PSG support. Mostly works, noise channel is borked though.
Mike Pavone <pavone@retrodev.com>
parents:
351
diff
changeset
|
1262 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
|
1263 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
|
1264 |
260
625f8e4d5fd2
Initial stab at integartiong Z80 core
Mike Pavone <pavone@retrodev.com>
parents:
215
diff
changeset
|
1265 z80_context z_context; |
625f8e4d5fd2
Initial stab at integartiong Z80 core
Mike Pavone <pavone@retrodev.com>
parents:
215
diff
changeset
|
1266 x86_z80_options z_opts; |
625f8e4d5fd2
Initial stab at integartiong Z80 core
Mike Pavone <pavone@retrodev.com>
parents:
215
diff
changeset
|
1267 init_x86_z80_opts(&z_opts); |
625f8e4d5fd2
Initial stab at integartiong Z80 core
Mike Pavone <pavone@retrodev.com>
parents:
215
diff
changeset
|
1268 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
|
1269 |
171f97e70d85
Implement writes from Z80 to YM-2612
Mike Pavone <pavone@retrodev.com>
parents:
289
diff
changeset
|
1270 z_context.system = &gen; |
260
625f8e4d5fd2
Initial stab at integartiong Z80 core
Mike Pavone <pavone@retrodev.com>
parents:
215
diff
changeset
|
1271 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
|
1272 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
|
1273 z_context.int_cycle = CYCLE_NEVER; |
625f8e4d5fd2
Initial stab at integartiong Z80 core
Mike Pavone <pavone@retrodev.com>
parents:
215
diff
changeset
|
1274 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
|
1275 |
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
|
1276 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
|
1277 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
|
1278 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
|
1279 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
|
1280 genesis = &gen; |
488
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
1281 |
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
|
1282 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
|
1283 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
|
1284 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
|
1285 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
|
1286 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
|
1287 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
|
1288 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
|
1289 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
|
1290 } |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
1291 } |
2f264d2a60c2
Support for SRAM with SEGA mapper. Half-finished support for SRAM without SEGA mapper.
Mike Pavone <pavone@retrodev.com>
parents:
346
diff
changeset
|
1292 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
|
1293 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
|
1294 } |
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
|
1295 set_keybindings(); |
488
32f053ad9b02
Basic OpenGL rendering is working
Mike Pavone <pavone@retrodev.com>
parents:
487
diff
changeset
|
1296 |
515
1495179d6737
Initial GDB remote debugging support. Lacks some features, but breakpoints and basic inspection of registers and memory work.
Mike Pavone <pavone@retrodev.com>
parents:
510
diff
changeset
|
1297 init_run_cpu(&gen, address_log, statefile, debuggerfun); |
88
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1298 return 0; |
c339559f1d4f
Forgot to add blastem main file earlier
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1299 } |