5 * This work is licensed under the terms of MAME license.
6 * See COPYING file in the top-level directory.
10 * - start in a state as if BIOS ran
11 * - remaining status flags (OVR/COL)
12 * - RAM support in mapper
14 * - SN76496 DAC-like usage
19 #include "sound/sn76496.h"
21 static unsigned char vdp_data_read(void)
23 struct PicoVideo *pv = &Pico.video;
26 d = PicoMem.vramb[pv->addr];
27 pv->addr = (pv->addr + 1) & 0x3fff;
32 static unsigned char vdp_ctl_read(void)
34 struct PicoVideo *pv = &Pico.video;
37 d = pv->status | (pv->pending_ints << 7);
38 pv->pending = pv->pending_ints = 0;
41 elprintf(EL_SR, "VDP sr: %02x", d);
45 static void vdp_data_write(unsigned char d)
47 struct PicoVideo *pv = &Pico.video;
50 PicoMem.cram[pv->addr & 0x1f] = d;
53 PicoMem.vramb[pv->addr] = d;
55 pv->addr = (pv->addr + 1) & 0x3fff;
60 static void vdp_ctl_write(unsigned char d)
62 struct PicoVideo *pv = &Pico.video;
66 pv->reg[d & 0x0f] = pv->addr;
67 elprintf(EL_IO, " VDP r%02x=%02x", d & 0x0f, pv->addr & 0xff);
71 pv->addr |= (d & 0x3f) << 8;
79 static unsigned char z80_sms_in(unsigned short a)
83 elprintf(EL_IO, "z80 port %04x read", a);
92 case 0x40: /* V counter */
93 d = Pico.video.v_counter;
94 elprintf(EL_HVCNT, "V counter read: %02x", d);
97 case 0x41: /* H counter */
99 elprintf(EL_HVCNT, "H counter read: %02x", d);
110 case 0xc0: /* I/O port A and B */
111 d = ~((PicoIn.pad[0] & 0x3f) | (PicoIn.pad[1] << 6));
114 case 0xc1: /* I/O port B and miscellaneous */
115 d = (Pico.ms.io_ctl & 0x80) | ((Pico.ms.io_ctl << 1) & 0x40) | 0x30;
116 d |= ~(PicoIn.pad[1] >> 2) & 0x0f;
120 elprintf(EL_IO, "ret = %02x", d);
124 static void z80_sms_out(unsigned short a, unsigned char d)
126 elprintf(EL_IO, "z80 port %04x write %02x", a, d);
136 if (PicoIn.opt & POPT_EN_PSG)
150 static int bank_mask;
152 static void write_bank(unsigned short a, unsigned char d)
154 elprintf(EL_Z80BNK, "bank %04x %02x @ %04x", a, d, z80_pc());
158 elprintf(EL_STATUS|EL_ANOMALY, "%02x written to control reg!", d);
162 elprintf(EL_STATUS|EL_ANOMALY, "bank0 changed to %d!", d);
166 z80_map_set(z80_read_map, 0x4000, 0x7fff, Pico.rom + (d << 14), 0);
168 Cz80_Set_Fetch(&CZ80, 0x4000, 0x7fff, (FPTR)Pico.rom + (d << 14));
173 z80_map_set(z80_read_map, 0x8000, 0xbfff, Pico.rom + (d << 14), 0);
175 Cz80_Set_Fetch(&CZ80, 0x8000, 0xbfff, (FPTR)Pico.rom + (d << 14));
179 Pico.ms.carthw[a & 0x0f] = d;
182 static void xwrite(unsigned int a, unsigned char d)
184 elprintf(EL_IO, "z80 write [%04x] %02x", a, d);
186 PicoMem.zram[a & 0x1fff] = d;
191 void PicoResetMS(void)
194 PsndReset(); // pal must be known here
197 void PicoPowerMS(void)
201 memset(&PicoMem,0,sizeof(PicoMem));
202 memset(&Pico.video,0,sizeof(Pico.video));
203 memset(&Pico.m,0,sizeof(Pico.m));
206 // calculate a mask for bank writes.
207 // ROM loader has aligned the size for us, so this is safe.
208 s = 0; tmp = Pico.romsize;
209 while ((tmp >>= 1) != 0)
211 if (Pico.romsize > (1 << s))
214 bank_mask = (tmp - 1) >> 14;
216 Pico.ms.carthw[0x0e] = 1;
217 Pico.ms.carthw[0x0f] = 2;
222 void PicoMemSetupMS(void)
224 z80_map_set(z80_read_map, 0x0000, 0xbfff, Pico.rom, 0);
225 z80_map_set(z80_read_map, 0xc000, 0xdfff, PicoMem.zram, 0);
226 z80_map_set(z80_read_map, 0xe000, 0xffff, PicoMem.zram, 0);
228 z80_map_set(z80_write_map, 0x0000, 0xbfff, xwrite, 1);
229 z80_map_set(z80_write_map, 0xc000, 0xdfff, PicoMem.zram, 0);
230 z80_map_set(z80_write_map, 0xe000, 0xffff, xwrite, 1);
233 drZ80.z80_in = z80_sms_in;
234 drZ80.z80_out = z80_sms_out;
237 Cz80_Set_Fetch(&CZ80, 0x0000, 0xbfff, (FPTR)Pico.rom);
238 Cz80_Set_Fetch(&CZ80, 0xc000, 0xdfff, (FPTR)PicoMem.zram);
239 Cz80_Set_Fetch(&CZ80, 0xe000, 0xffff, (FPTR)PicoMem.zram);
240 Cz80_Set_INPort(&CZ80, z80_sms_in);
241 Cz80_Set_OUTPort(&CZ80, z80_sms_out);
245 void PicoStateLoadedMS(void)
247 write_bank(0xfffe, Pico.ms.carthw[0x0e]);
248 write_bank(0xffff, Pico.ms.carthw[0x0f]);
251 void PicoFrameMS(void)
253 struct PicoVideo *pv = &Pico.video;
254 int is_pal = Pico.m.pal;
255 int lines = is_pal ? 313 : 262;
256 int cycles_line = is_pal ? 58020 : 58293; /* (226.6 : 227.7) * 256 */
257 int cycles_done = 0, cycles_aim = 0;
258 int skip = PicoIn.skipFrame;
260 int hint; // Hint counter
266 nmi = (PicoIn.pad[0] >> 7) & 1;
267 if (!Pico.ms.nmi_state && nmi)
269 Pico.ms.nmi_state = nmi;
271 PicoFrameStartMode4();
272 hint = pv->reg[0x0a];
274 for (y = 0; y < lines; y++)
276 pv->v_counter = Pico.m.scanline = y;
278 pv->v_counter = y - 6;
280 if (y < lines_vis && !skip)
287 hint = pv->reg[0x0a];
288 pv->pending_ints |= 2;
289 if (pv->reg[0] & 0x10) {
290 elprintf(EL_INTS, "hint");
295 else if (y == lines_vis + 1) {
296 pv->pending_ints |= 1;
297 if (pv->reg[1] & 0x20) {
298 elprintf(EL_INTS, "vint");
303 cycles_aim += cycles_line;
304 cycles_done += z80_run((cycles_aim - cycles_done) >> 8) << 8;
311 void PicoFrameDrawOnlyMS(void)
316 PicoFrameStartMode4();
318 for (y = 0; y < lines_vis; y++)