Mercurial > repos > blastem
annotate coleco.c @ 2468:0ca78837e4d2
Implement ext instruction in new 68K core
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Sat, 24 Feb 2024 22:54:36 -0800 |
parents | 23052186705a |
children |
rev | line source |
---|---|
2415
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1 #include <string.h> |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
2 #include <stdlib.h> |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
3 #include <stddef.h> |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
4 #include "coleco.h" |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
5 #include "render.h" |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
6 #include "io.h" |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
7 #include "blastem.h" |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
8 #include "util.h" |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
9 #include "debug.h" |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
10 #include "bindings.h" |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
11 #include "saves.h" |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
12 |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
13 #ifdef NEW_CORE |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
14 #define Z80_CYCLE cycles |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
15 #define Z80_OPTS opts |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
16 #define z80_handle_code_write(...) |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
17 #else |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
18 #define Z80_CYCLE current_cycle |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
19 #define Z80_OPTS options |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
20 #endif |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
21 |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
22 static void *coleco_select_write(uint32_t location, void *vcontext, uint8_t value) |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
23 { |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
24 z80_context *z80 = vcontext; |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
25 coleco_context *coleco = z80->system; |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
26 location &= 0xFF; |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
27 coleco->controller_select = location >= 0xC0; |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
28 return vcontext; |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
29 } |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
30 |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
31 static uint8_t coleco_controller_read(uint32_t location, void *vcontext) |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
32 { |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
33 z80_context *z80 = vcontext; |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
34 coleco_context *coleco = z80->system; |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
35 |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
36 uint8_t index = coleco->controller_select ? 2 : 0; |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
37 if (location & 2) { |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
38 ++index; |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
39 } |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
40 return coleco->controller_state[index]; |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
41 } |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
42 |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
43 static void update_interrupts(coleco_context *coleco) |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
44 { |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
45 #ifdef NEW_CORE |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
46 if (coleco->z80->nmi_cycle == CYCLE_NEVER) { |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
47 #else |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
48 if (coleco->z80->nmi_start == CYCLE_NEVER) { |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
49 #endif |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
50 uint32_t nmi = vdp_next_vint(coleco->vdp); |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
51 if (nmi != CYCLE_NEVER) { |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
52 z80_assert_nmi(coleco->z80, nmi); |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
53 } |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
54 } |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
55 } |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
56 |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
57 static void *coleco_vdp_write(uint32_t location, void *vcontext, uint8_t value) |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
58 { |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
59 z80_context *z80 = vcontext; |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
60 coleco_context *coleco = z80->system; |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
61 |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
62 vdp_run_context_full(coleco->vdp, z80->Z80_CYCLE); |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
63 if (location & 1) { |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
64 vdp_control_port_write_pbc(coleco->vdp, value); |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
65 update_interrupts(coleco); |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
66 } else { |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
67 vdp_data_port_write_pbc(coleco->vdp, value); |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
68 } |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
69 |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
70 return vcontext; |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
71 } |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
72 |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
73 static uint8_t coleco_vdp_read(uint32_t location, void *vcontext) |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
74 { |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
75 z80_context *z80 = vcontext; |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
76 coleco_context *coleco = z80->system; |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
77 vdp_run_context(coleco->vdp, z80->Z80_CYCLE); |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
78 if (location & 1) { |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
79 uint8_t ret = vdp_control_port_read(coleco->vdp); |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
80 coleco->vdp->flags2 &= ~(FLAG2_VINT_PENDING|FLAG2_HINT_PENDING); |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
81 update_interrupts(coleco); |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
82 return ret; |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
83 } else { |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
84 return vdp_data_port_read_pbc(coleco->vdp); |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
85 } |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
86 } |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
87 |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
88 static void *coleco_psg_write(uint32_t location, void *vcontext, uint8_t value) |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
89 { |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
90 z80_context *z80 = vcontext; |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
91 coleco_context *coleco = z80->system; |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
92 |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
93 psg_run(coleco->psg, z80->Z80_CYCLE); |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
94 psg_write(coleco->psg, value); |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
95 |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
96 return vcontext; |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
97 } |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
98 |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
99 void coleco_serialize(coleco_context *coleco, serialize_buffer *buf) |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
100 { |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
101 start_section(buf, SECTION_Z80); |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
102 z80_serialize(coleco->z80, buf); |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
103 end_section(buf); |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
104 |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
105 start_section(buf, SECTION_VDP); |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
106 vdp_serialize(coleco->vdp, buf); |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
107 end_section(buf); |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
108 |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
109 start_section(buf, SECTION_PSG); |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
110 psg_serialize(coleco->psg, buf); |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
111 end_section(buf); |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
112 |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
113 start_section(buf, SECTION_MAIN_RAM); |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
114 save_int8(buf, sizeof(coleco->ram) / 1024); |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
115 save_buffer8(buf, coleco->ram, sizeof(coleco->ram)); |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
116 end_section(buf); |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
117 |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
118 start_section(buf, SECTION_COLECO_IO); |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
119 save_buffer8(buf, coleco->controller_state, sizeof(coleco->controller_state)); |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
120 save_int8(buf, coleco->controller_select); |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
121 end_section(buf); |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
122 } |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
123 |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
124 static uint8_t *serialize(system_header *sys, size_t *size_out) |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
125 { |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
126 coleco_context *coleco = (coleco_context *)sys; |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
127 serialize_buffer state; |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
128 init_serialize(&state); |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
129 coleco_serialize(coleco, &state); |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
130 if (size_out) { |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
131 *size_out = state.size; |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
132 } |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
133 return state.data; |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
134 } |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
135 |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
136 static void ram_deserialize(deserialize_buffer *buf, void *vcoleco) |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
137 { |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
138 coleco_context *coleco = vcoleco; |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
139 uint32_t ram_size = load_int8(buf) * 1024; |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
140 if (ram_size > sizeof(coleco->ram)) { |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
141 fatal_error("State has a RAM size of %d bytes", ram_size); |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
142 } |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
143 load_buffer8(buf, coleco->ram, ram_size); |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
144 } |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
145 |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
146 static void controller_deserialize(deserialize_buffer *buf, void *vcoleco) |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
147 { |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
148 coleco_context *coleco = vcoleco; |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
149 load_buffer8(buf, coleco->controller_state, sizeof(coleco->controller_state)); |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
150 coleco->controller_select = load_int8(buf); |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
151 } |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
152 |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
153 void coleco_deserialize(deserialize_buffer *buf, coleco_context *coleco) |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
154 { |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
155 register_section_handler(buf, (section_handler){.fun = z80_deserialize, .data = coleco->z80}, SECTION_Z80); |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
156 register_section_handler(buf, (section_handler){.fun = vdp_deserialize, .data = coleco->vdp}, SECTION_VDP); |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
157 register_section_handler(buf, (section_handler){.fun = psg_deserialize, .data = coleco->psg}, SECTION_PSG); |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
158 register_section_handler(buf, (section_handler){.fun = ram_deserialize, .data = coleco}, SECTION_MAIN_RAM); |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
159 register_section_handler(buf, (section_handler){.fun = controller_deserialize, .data = coleco}, SECTION_COLECO_IO); |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
160 while (buf->cur_pos < buf->size) |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
161 { |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
162 load_section(buf); |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
163 } |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
164 z80_invalidate_code_range(coleco->z80, 0x7000, 0x8000); |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
165 free(buf->handlers); |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
166 buf->handlers = NULL; |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
167 } |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
168 |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
169 static void deserialize(system_header *sys, uint8_t *data, size_t size) |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
170 { |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
171 coleco_context *coleco = (coleco_context *)sys; |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
172 deserialize_buffer buffer; |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
173 init_deserialize(&buffer, data, size); |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
174 coleco_deserialize(&buffer, coleco); |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
175 } |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
176 |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
177 static void save_state(coleco_context *coleco, uint8_t slot) |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
178 { |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
179 char *save_path = get_slot_name(&coleco->header, slot, "state"); |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
180 serialize_buffer state; |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
181 init_serialize(&state); |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
182 coleco_serialize(coleco, &state); |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
183 save_to_file(&state, save_path); |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
184 printf("Saved state to %s\n", save_path); |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
185 free(save_path); |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
186 free(state.data); |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
187 } |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
188 |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
189 static uint8_t load_state_path(coleco_context *coleco, char *path) |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
190 { |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
191 deserialize_buffer state; |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
192 uint8_t ret; |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
193 if ((ret = load_from_file(&state, path))) { |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
194 coleco_deserialize(&state, coleco); |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
195 free(state.data); |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
196 printf("Loaded %s\n", path); |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
197 } |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
198 return ret; |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
199 } |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
200 |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
201 static uint8_t load_state(system_header *system, uint8_t slot) |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
202 { |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
203 coleco_context *coleco = (coleco_context *)system; |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
204 char *statepath = get_slot_name(system, slot, "state"); |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
205 uint8_t ret; |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
206 #ifndef NEW_CORE |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
207 if (!coleco->z80->native_pc) { |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
208 ret = get_modification_time(statepath) != 0; |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
209 if (ret) { |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
210 system->delayed_load_slot = slot + 1; |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
211 } |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
212 goto done; |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
213 |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
214 } |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
215 #endif |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
216 ret = load_state_path(coleco, statepath); |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
217 done: |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
218 free(statepath); |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
219 return ret; |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
220 } |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
221 |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
222 static void run_coleco(system_header *system) |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
223 { |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
224 coleco_context *coleco = (coleco_context *)system; |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
225 uint32_t target_cycle = coleco->z80->Z80_CYCLE + 3420*16; |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
226 render_set_video_standard(VID_NTSC); |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
227 |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
228 while (!coleco->should_return) { |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
229 if (system->delayed_load_slot) { |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
230 load_state(system, system->delayed_load_slot - 1); |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
231 system->delayed_load_slot = 0; |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
232 |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
233 } |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
234 if (coleco->vdp->frame != coleco->last_frame) { |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
235 #ifndef IS_LIB |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
236 if (coleco->psg->scope) { |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
237 scope_render(coleco->psg->scope); |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
238 } |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
239 #endif |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
240 uint32_t elapsed = coleco->vdp->frame - coleco->last_frame; |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
241 coleco->last_frame = coleco->vdp->frame; |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
242 if (system->enter_debugger_frames) { |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
243 if (elapsed >= system->enter_debugger_frames) { |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
244 system->enter_debugger_frames = 0; |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
245 system->enter_debugger = 1; |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
246 } else { |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
247 system->enter_debugger_frames -= elapsed; |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
248 } |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
249 } |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
250 |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
251 if(exit_after){ |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
252 if (elapsed >= exit_after) { |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
253 exit(0); |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
254 } else { |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
255 exit_after -= elapsed; |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
256 } |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
257 } |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
258 } |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
259 if (system->enter_debugger && coleco->z80->pc) { |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
260 system->enter_debugger = 0; |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
261 #ifndef IS_LIB |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
262 zdebugger(coleco->z80, coleco->z80->pc); |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
263 #endif |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
264 } |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
265 if (system->enter_debugger) { |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
266 target_cycle = coleco->z80->Z80_CYCLE + 1; |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
267 } |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
268 update_interrupts(coleco); |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
269 z80_run(coleco->z80, target_cycle); |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
270 if (coleco->z80->reset) { |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
271 z80_clear_reset(coleco->z80, coleco->z80->Z80_CYCLE + 3*15); |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
272 } |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
273 target_cycle = coleco->z80->Z80_CYCLE; |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
274 vdp_run_context(coleco->vdp, target_cycle); |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
275 psg_run(coleco->psg, target_cycle); |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
276 if (system->save_state) { |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
277 while (!coleco->z80->pc) { |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
278 //advance Z80 to an instruction boundary |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
279 z80_run(coleco->z80, coleco->z80->Z80_CYCLE + 1); |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
280 } |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
281 save_state(coleco, system->save_state - 1); |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
282 system->save_state = 0; |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
283 } |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
284 |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
285 target_cycle += 3420*16; |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
286 if (target_cycle > 0x40000000) { |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
287 uint32_t adjust = coleco->z80->Z80_CYCLE - 3420*262*2; |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
288 z80_adjust_cycles(coleco->z80, adjust); |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
289 vdp_adjust_cycles(coleco->vdp, adjust); |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
290 coleco->psg->cycles -= adjust; |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
291 target_cycle -= adjust; |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
292 } |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
293 } |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
294 if (coleco->header.force_release || render_should_release_on_exit()) { |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
295 bindings_release_capture(); |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
296 vdp_release_framebuffer(coleco->vdp); |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
297 render_pause_source(coleco->psg->audio); |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
298 } |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
299 coleco->should_return = 0; |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
300 } |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
301 |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
302 static void resume_coleco(system_header *system) |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
303 { |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
304 coleco_context *coleco = (coleco_context *)system; |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
305 if (coleco->header.force_release || render_should_release_on_exit()) { |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
306 coleco->header.force_release = 0; |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
307 bindings_reacquire_capture(); |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
308 vdp_reacquire_framebuffer(coleco->vdp); |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
309 render_resume_source(coleco->psg->audio); |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
310 } |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
311 run_coleco(system); |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
312 } |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
313 |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
314 static void start_coleco(system_header *system, char *statefile) |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
315 { |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
316 coleco_context *coleco = (coleco_context *)system; |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
317 |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
318 z80_assert_reset(coleco->z80, 0); |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
319 z80_clear_reset(coleco->z80, 128*15); |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
320 |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
321 if (statefile) { |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
322 load_state_path(coleco, statefile); |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
323 } |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
324 |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
325 if (system->enter_debugger) { |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
326 system->enter_debugger = 0; |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
327 #ifndef IS_LIB |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
328 zinsert_breakpoint(coleco->z80, coleco->z80->pc, (uint8_t *)zdebugger); |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
329 #endif |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
330 } |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
331 |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
332 run_coleco(system); |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
333 } |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
334 |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
335 static void free_coleco(system_header *system) |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
336 { |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
337 coleco_context *coleco = (coleco_context *)system; |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
338 vdp_free(coleco->vdp); |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
339 z80_options_free(coleco->z80->Z80_OPTS); |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
340 free(coleco->z80); |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
341 psg_free(coleco->psg); |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
342 free(coleco->rom); |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
343 free(coleco->header.info.map); |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
344 free(coleco->header.info.name); |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
345 free(coleco); |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
346 } |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
347 |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
348 static void soft_reset(system_header *system) |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
349 { |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
350 coleco_context *coleco = (coleco_context *)system; |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
351 z80_assert_reset(coleco->z80, coleco->z80->Z80_CYCLE); |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
352 #ifndef NEW_CORE |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
353 coleco->z80->target_cycle = coleco->z80->sync_cycle = coleco->z80->Z80_CYCLE; |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
354 #endif |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
355 } |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
356 |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
357 |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
358 static void set_speed_percent(system_header * system, uint32_t percent) |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
359 { |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
360 coleco_context *coleco = (coleco_context *)system; |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
361 uint32_t old_clock = coleco->master_clock; |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
362 coleco->master_clock = ((uint64_t)coleco->normal_clock * (uint64_t)percent) / 100; |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
363 |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
364 psg_adjust_master_clock(coleco->psg, coleco->master_clock); |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
365 } |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
366 |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
367 static uint16_t get_open_bus_value(system_header *system) |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
368 { |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
369 return 0xFFFF; |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
370 } |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
371 |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
372 static void request_exit(system_header *system) |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
373 { |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
374 coleco_context *coleco = (coleco_context *)system; |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
375 coleco->should_return = 1; |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
376 #ifndef NEW_CORE |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
377 coleco->z80->target_cycle = coleco->z80->sync_cycle = coleco->z80->Z80_CYCLE; |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
378 #endif |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
379 } |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
380 |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
381 static uint8_t button_map[] = { |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
382 [DPAD_UP] = 1, |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
383 [DPAD_DOWN] = 4, |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
384 [DPAD_LEFT] = 8, |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
385 [DPAD_RIGHT] = 2, |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
386 [BUTTON_A] = 0x40, |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
387 [BUTTON_B] = 0x40, |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
388 [BUTTON_C] = 9, //* |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
389 [BUTTON_START] = 6, //# |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
390 [BUTTON_X] = 0xD, //1 |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
391 [BUTTON_Y] = 0x7, //2 |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
392 [BUTTON_Z] = 0xC, //3 |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
393 [BUTTON_MODE] = 0x2 //4 |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
394 }; |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
395 |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
396 static void gamepad_down(system_header *system, uint8_t gamepad_num, uint8_t button) |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
397 { |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
398 if (gamepad_num > 2) { |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
399 return; |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
400 } |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
401 coleco_context *coleco = (coleco_context *)system; |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
402 uint8_t index = gamepad_num - 1; |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
403 if (button < BUTTON_B) { |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
404 index += 2; |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
405 } |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
406 if (button > BUTTON_B) { |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
407 coleco->controller_state[index] &= 0xF0; |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
408 coleco->controller_state[index] |= button_map[button]; |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
409 } else { |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
410 coleco->controller_state[index] &= ~button_map[button]; |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
411 } |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
412 |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
413 } |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
414 |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
415 static void gamepad_up(system_header *system, uint8_t gamepad_num, uint8_t button) |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
416 { |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
417 if (gamepad_num > 2) { |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
418 return; |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
419 } |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
420 coleco_context *coleco = (coleco_context *)system; |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
421 uint8_t index = gamepad_num - 1; |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
422 if (button < BUTTON_B) { |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
423 index += 2; |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
424 } |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
425 if (button > BUTTON_B) { |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
426 coleco->controller_state[index] |= 0xF; |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
427 } else { |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
428 coleco->controller_state[index] |= button_map[button]; |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
429 } |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
430 } |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
431 |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
432 |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
433 static void config_updated(system_header *system) |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
434 { |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
435 coleco_context *coleco = (coleco_context *)system; |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
436 //sample rate may have changed |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
437 psg_adjust_master_clock(coleco->psg, coleco->master_clock); |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
438 } |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
439 |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
440 static void inc_debug_mode(system_header *system) |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
441 { |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
442 coleco_context *coleco = (coleco_context *)system; |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
443 vdp_inc_debug_mode(coleco->vdp); |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
444 } |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
445 |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
446 static void toggle_debug_view(system_header *system, uint8_t debug_view) |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
447 { |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
448 #ifndef IS_LIB |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
449 coleco_context *coleco = (coleco_context *)system; |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
450 if (debug_view < DEBUG_OSCILLOSCOPE) { |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
451 vdp_toggle_debug_view(coleco->vdp, debug_view); |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
452 } else if (debug_view == DEBUG_OSCILLOSCOPE) { |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
453 if (coleco->psg->scope) { |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
454 oscilloscope *scope = coleco->psg->scope; |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
455 coleco->psg->scope = NULL; |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
456 scope_close(scope); |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
457 } else { |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
458 oscilloscope *scope = create_oscilloscope(); |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
459 psg_enable_scope(coleco->psg, scope, coleco->normal_clock); |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
460 } |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
461 } |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
462 #endif |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
463 } |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
464 |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
465 static void load_save(system_header *system) |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
466 { |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
467 //Unclear if any Coleco carts have non-volatile memory |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
468 //but we need a dummy implementation so the save directory gets setup |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
469 } |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
470 |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
471 static void persist_save(system_header *system) |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
472 { |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
473 } |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
474 |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
475 coleco_context *alloc_configure_coleco(system_media *media) |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
476 { |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
477 coleco_context *coleco = calloc(1, sizeof(coleco_context)); |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
478 char *bios_path = tern_find_path_default(config, "system\0coleco_bios_path\0", (tern_val){.ptrval = "colecovision_bios.col"}, TVAL_PTR).ptrval; |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
479 if (is_absolute_path(bios_path)) { |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
480 FILE *f = fopen(bios_path, "rb"); |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
481 if (f) { |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
482 fread(coleco->bios, 1, sizeof(coleco->bios), f); |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
483 fclose(f); |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
484 } else { |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
485 warning("Failed to open Colecovision BIOS from %s\n", bios_path); |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
486 } |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
487 |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
488 } else { |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
489 uint32_t bios_size; |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
490 char *tmp = read_bundled_file(bios_path, &bios_size); |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
491 if (tmp) { |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
492 if (bios_size > sizeof(coleco->bios)) { |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
493 bios_size = sizeof(coleco->bios); |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
494 } |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
495 memcpy(coleco->bios, tmp, bios_size); |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
496 free(tmp); |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
497 } else { |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
498 warning("Failed to open Colecovision BIOS from %s\n", bios_path); |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
499 } |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
500 |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
501 } |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
502 |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
503 coleco->rom = media->buffer; |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
504 coleco->rom_size = media->size; |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
505 const memmap_chunk map[] = { |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
506 {0x0000, 0x2000, sizeof(coleco->bios)-1, .flags = MMAP_READ, .buffer = coleco->bios}, |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
507 {0x8000, 0x10000, nearest_pow2(coleco->rom_size)-1, .flags = MMAP_READ, .buffer = coleco->rom}, |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
508 {0x7000, 0x8000, sizeof(coleco->ram)-1, .flags = MMAP_READ|MMAP_WRITE|MMAP_CODE, .buffer = coleco->ram} |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
509 }; |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
510 static const memmap_chunk io_map[] = { |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
511 {0x80, 0xA0, 0xFF, .write_8 = coleco_select_write}, |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
512 {0xA0, 0xC0, 0xFF, .read_8 = coleco_vdp_read, .write_8 = coleco_vdp_write}, |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
513 {0xC0, 0xE0, 0xFF, .write_8 = coleco_select_write}, |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
514 {0xE0, 0x100, 0xFF, .read_8 = coleco_controller_read, .write_8 = coleco_psg_write} |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
515 }; |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
516 uint32_t rom_size = coleco->header.info.rom_size; |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
517 z80_options *zopts = malloc(sizeof(z80_options)); |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
518 uint32_t num_chunks = sizeof(map)/sizeof(*map); |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
519 memmap_chunk *heap_map = calloc(num_chunks, sizeof(memmap_chunk)); |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
520 memcpy(heap_map, map, sizeof(map)); |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
521 |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
522 //Colecovision appears to use a 7.15909 MHz crystal with a /2 divider, but /15 works better with my VDP implementation |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
523 init_z80_opts(zopts, heap_map, num_chunks, io_map, sizeof(io_map)/sizeof(*io_map), 15, 0xFF); |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
524 coleco->z80 = init_z80_context(zopts); |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
525 coleco->z80->system = coleco; |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
526 coleco->normal_clock = coleco->master_clock = 53693175; |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
527 |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
528 coleco->psg = malloc(sizeof(psg_context)); |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
529 psg_init(coleco->psg, coleco->master_clock, 15*16); |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
530 |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
531 coleco->vdp = init_vdp_context(0, 0, VDP_TMS9918A); |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
532 coleco->vdp->system = &coleco->header; |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
533 |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
534 memset(coleco->controller_state, 0xFF, sizeof(coleco->controller_state)); |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
535 |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
536 coleco->header.info.save_type = SAVE_NONE; |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
537 coleco->header.info.map = heap_map; |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
538 //TODO: copy name from header if present |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
539 coleco->header.info.name = strdup(media->name); |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
540 |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
541 |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
542 coleco->header.has_keyboard = 0; |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
543 coleco->header.set_speed_percent = set_speed_percent; |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
544 coleco->header.start_context = start_coleco; |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
545 coleco->header.resume_context = resume_coleco; |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
546 coleco->header.load_save = load_save; |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
547 coleco->header.persist_save = persist_save; |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
548 coleco->header.load_state = load_state; |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
549 coleco->header.free_context = free_coleco; |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
550 coleco->header.get_open_bus_value = get_open_bus_value; |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
551 coleco->header.request_exit = request_exit; |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
552 coleco->header.soft_reset = soft_reset; |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
553 coleco->header.inc_debug_mode = inc_debug_mode; |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
554 coleco->header.gamepad_down = gamepad_down; |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
555 coleco->header.gamepad_up = gamepad_up; |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
556 //coleco->header.keyboard_down = keyboard_down; |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
557 //coleco->header.keyboard_up = keyboard_up; |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
558 coleco->header.config_updated = config_updated; |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
559 coleco->header.serialize = serialize; |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
560 coleco->header.deserialize = deserialize; |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
561 coleco->header.toggle_debug_view = toggle_debug_view; |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
562 coleco->header.type = SYSTEM_COLECOVISION; |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
563 |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
564 return coleco; |
23052186705a
Forgot to commit the colecovision files
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
565 } |