3 * - start in a state as if BIOS ran
4 * - remaining status flags (OVR/COL)
5 * - RAM support in mapper
8 * - SN76496 DAC-like usage
13 #include "sound/sn76496.h"
15 static unsigned char vdp_data_read(void)
17 struct PicoVideo *pv = &Pico.video;
20 d = Pico.vramb[pv->addr];
21 pv->addr = (pv->addr + 1) & 0x3fff;
26 static unsigned char vdp_ctl_read(void)
28 unsigned char d = Pico.video.pending_ints << 7;
29 Pico.video.pending = 0;
30 Pico.video.pending_ints = 0;
32 elprintf(EL_SR, "VDP sr: %02x", d);
36 static void vdp_data_write(unsigned char d)
38 struct PicoVideo *pv = &Pico.video;
41 Pico.cram[pv->addr & 0x1f] = d;
44 Pico.vramb[pv->addr] = d;
46 pv->addr = (pv->addr + 1) & 0x3fff;
51 static void vdp_ctl_write(unsigned char d)
53 struct PicoVideo *pv = &Pico.video;
57 pv->reg[d & 0x0f] = pv->addr;
58 elprintf(EL_IO, " VDP r%02x=%02x", d & 0x0f, pv->addr & 0xff);
62 pv->addr |= (d & 0x3f) << 8;
70 static unsigned char z80_sms_in(unsigned short a)
74 elprintf(EL_IO, "z80 port %04x read", a);
83 case 0x40: /* V counter */
84 d = Pico.video.v_counter;
85 elprintf(EL_HVCNT, "V counter read: %02x", d);
88 case 0x41: /* H counter */
90 elprintf(EL_HVCNT, "H counter read: %02x", d);
101 case 0xc0: /* I/O port A and B */
102 d = ~((PicoPad[0] & 0x3f) | (PicoPad[1] << 6));
105 case 0xc1: /* I/O port B and miscellaneous */
106 d = (Pico.ms.io_ctl & 0x80) | ((Pico.ms.io_ctl << 1) & 0x40) | 0x30;
107 d |= ~(PicoPad[1] >> 2) & 0x0f;
111 elprintf(EL_IO, "ret = %02x", d);
115 static void z80_sms_out(unsigned short a, unsigned char d)
117 elprintf(EL_IO, "z80 port %04x write %02x", a, d);
127 if (PicoOpt & POPT_EN_PSG)
141 static int bank_mask;
143 static void write_bank(unsigned short a, unsigned char d)
145 elprintf(EL_Z80BNK, "bank %04x %02x @ %04x", a, d, z80_pc());
149 elprintf(EL_STATUS|EL_ANOMALY, "%02x written to control reg!", d);
153 elprintf(EL_STATUS|EL_ANOMALY, "bank0 changed to %d!", d);
157 z80_map_set(z80_read_map, 0x4000, 0x7fff, Pico.rom + (d << 14), 0);
159 Cz80_Set_Fetch(&CZ80, 0x4000, 0x7fff, (FPTR)Pico.rom + (d << 14));
164 z80_map_set(z80_read_map, 0x8000, 0xbfff, Pico.rom + (d << 14), 0);
166 Cz80_Set_Fetch(&CZ80, 0x8000, 0xbfff, (FPTR)Pico.rom + (d << 14));
170 Pico.ms.carthw[a & 0x0f] = d;
173 static void xwrite(unsigned int a, unsigned char d)
175 elprintf(EL_IO, "z80 write [%04x] %02x", a, d);
177 Pico.zram[a & 0x1fff] = d;
182 void PicoResetMS(void)
185 PsndReset(); // pal must be known here
188 void PicoPowerMS(void)
192 memset(&Pico.ram,0,(unsigned char *)&Pico.rom - Pico.ram);
193 memset(&Pico.video,0,sizeof(Pico.video));
194 memset(&Pico.m,0,sizeof(Pico.m));
197 // calculate a mask for bank writes.
198 // ROM loader has aligned the size for us, so this is safe.
199 s = 0; tmp = Pico.romsize;
200 while ((tmp >>= 1) != 0)
202 if (Pico.romsize > (1 << s))
205 bank_mask = (tmp - 1) >> 14;
207 Pico.ms.carthw[0x0e] = 1;
208 Pico.ms.carthw[0x0f] = 2;
213 void PicoMemSetupMS(void)
215 z80_map_set(z80_read_map, 0x0000, 0xbfff, Pico.rom, 0);
216 z80_map_set(z80_read_map, 0xc000, 0xdfff, Pico.zram, 0);
217 z80_map_set(z80_read_map, 0xe000, 0xffff, Pico.zram, 0);
219 z80_map_set(z80_write_map, 0x0000, 0xbfff, xwrite, 1);
220 z80_map_set(z80_write_map, 0xc000, 0xdfff, Pico.zram, 0);
221 z80_map_set(z80_write_map, 0xe000, 0xffff, xwrite, 1);
224 drZ80.z80_in = z80_sms_in;
225 drZ80.z80_out = z80_sms_out;
228 Cz80_Set_Fetch(&CZ80, 0x0000, 0xbfff, (FPTR)Pico.rom);
229 Cz80_Set_Fetch(&CZ80, 0xc000, 0xdfff, (FPTR)Pico.zram);
230 Cz80_Set_Fetch(&CZ80, 0xe000, 0xffff, (FPTR)Pico.zram);
231 Cz80_Set_INPort(&CZ80, z80_sms_in);
232 Cz80_Set_OUTPort(&CZ80, z80_sms_out);
236 void PicoStateLoadedMS(void)
238 write_bank(0xfffe, Pico.ms.carthw[0x0e]);
239 write_bank(0xffff, Pico.ms.carthw[0x0f]);
242 void PicoFrameMS(void)
244 struct PicoVideo *pv = &Pico.video;
245 int is_pal = Pico.m.pal;
246 int lines = is_pal ? 313 : 262;
247 int cycles_line = is_pal ? 58020 : 58293; /* (226.6 : 227.7) * 256 */
248 int cycles_done = 0, cycles_aim = 0;
249 int skip = PicoSkipFrame;
251 int hint; // Hint counter
254 PicoFrameStartMode4();
255 hint = pv->reg[0x0a];
257 for (y = 0; y < lines; y++)
259 pv->v_counter = Pico.m.scanline = y;
261 pv->v_counter = y - 6;
263 if (y < lines_vis && !skip)
270 hint = pv->reg[0x0a];
271 pv->pending_ints |= 2;
272 if (pv->reg[0] & 0x10) {
273 elprintf(EL_INTS, "hint");
278 else if (y == lines_vis + 1) {
279 pv->pending_ints |= 1;
280 if (pv->reg[1] & 0x20) {
281 elprintf(EL_INTS, "vint");
286 cycles_aim += cycles_line;
287 cycles_done += z80_run((cycles_aim - cycles_done) >> 8) << 8;
294 void PicoFrameDrawOnlyMS(void)
299 PicoFrameStartMode4();
301 for (y = 0; y < lines_vis; y++)