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 = Pico.vramb[pv->addr];
27 pv->addr = (pv->addr + 1) & 0x3fff;
32 static unsigned char vdp_ctl_read(void)
34 unsigned char d = Pico.video.pending_ints << 7;
35 Pico.video.pending = 0;
36 Pico.video.pending_ints = 0;
38 elprintf(EL_SR, "VDP sr: %02x", d);
42 static void vdp_data_write(unsigned char d)
44 struct PicoVideo *pv = &Pico.video;
47 Pico.cram[pv->addr & 0x1f] = d;
50 Pico.vramb[pv->addr] = d;
52 pv->addr = (pv->addr + 1) & 0x3fff;
57 static void vdp_ctl_write(unsigned char d)
59 struct PicoVideo *pv = &Pico.video;
63 pv->reg[d & 0x0f] = pv->addr;
64 elprintf(EL_IO, " VDP r%02x=%02x", d & 0x0f, pv->addr & 0xff);
68 pv->addr |= (d & 0x3f) << 8;
76 static unsigned char z80_sms_in(unsigned short a)
80 elprintf(EL_IO, "z80 port %04x read", a);
89 case 0x40: /* V counter */
90 d = Pico.video.v_counter;
91 elprintf(EL_HVCNT, "V counter read: %02x", d);
94 case 0x41: /* H counter */
96 elprintf(EL_HVCNT, "H counter read: %02x", d);
107 case 0xc0: /* I/O port A and B */
108 d = ~((PicoPad[0] & 0x3f) | (PicoPad[1] << 6));
111 case 0xc1: /* I/O port B and miscellaneous */
112 d = (Pico.ms.io_ctl & 0x80) | ((Pico.ms.io_ctl << 1) & 0x40) | 0x30;
113 d |= ~(PicoPad[1] >> 2) & 0x0f;
117 elprintf(EL_IO, "ret = %02x", d);
121 static void z80_sms_out(unsigned short a, unsigned char d)
123 elprintf(EL_IO, "z80 port %04x write %02x", a, d);
133 if (PicoOpt & POPT_EN_PSG)
147 static int bank_mask;
149 static void write_bank(unsigned short a, unsigned char d)
151 elprintf(EL_Z80BNK, "bank %04x %02x @ %04x", a, d, z80_pc());
155 elprintf(EL_STATUS|EL_ANOMALY, "%02x written to control reg!", d);
159 elprintf(EL_STATUS|EL_ANOMALY, "bank0 changed to %d!", d);
163 z80_map_set(z80_read_map, 0x4000, 0x7fff, Pico.rom + (d << 14), 0);
165 Cz80_Set_Fetch(&CZ80, 0x4000, 0x7fff, (FPTR)Pico.rom + (d << 14));
170 z80_map_set(z80_read_map, 0x8000, 0xbfff, Pico.rom + (d << 14), 0);
172 Cz80_Set_Fetch(&CZ80, 0x8000, 0xbfff, (FPTR)Pico.rom + (d << 14));
176 Pico.ms.carthw[a & 0x0f] = d;
179 static void xwrite(unsigned int a, unsigned char d)
181 elprintf(EL_IO, "z80 write [%04x] %02x", a, d);
183 Pico.zram[a & 0x1fff] = d;
188 void PicoResetMS(void)
191 PsndReset(); // pal must be known here
194 void PicoPowerMS(void)
198 memset(&Pico.ram,0,(unsigned char *)&Pico.rom - Pico.ram);
199 memset(&Pico.video,0,sizeof(Pico.video));
200 memset(&Pico.m,0,sizeof(Pico.m));
203 // calculate a mask for bank writes.
204 // ROM loader has aligned the size for us, so this is safe.
205 s = 0; tmp = Pico.romsize;
206 while ((tmp >>= 1) != 0)
208 if (Pico.romsize > (1 << s))
211 bank_mask = (tmp - 1) >> 14;
213 Pico.ms.carthw[0x0e] = 1;
214 Pico.ms.carthw[0x0f] = 2;
219 void PicoMemSetupMS(void)
221 z80_map_set(z80_read_map, 0x0000, 0xbfff, Pico.rom, 0);
222 z80_map_set(z80_read_map, 0xc000, 0xdfff, Pico.zram, 0);
223 z80_map_set(z80_read_map, 0xe000, 0xffff, Pico.zram, 0);
225 z80_map_set(z80_write_map, 0x0000, 0xbfff, xwrite, 1);
226 z80_map_set(z80_write_map, 0xc000, 0xdfff, Pico.zram, 0);
227 z80_map_set(z80_write_map, 0xe000, 0xffff, xwrite, 1);
230 drZ80.z80_in = z80_sms_in;
231 drZ80.z80_out = z80_sms_out;
234 Cz80_Set_Fetch(&CZ80, 0x0000, 0xbfff, (FPTR)Pico.rom);
235 Cz80_Set_Fetch(&CZ80, 0xc000, 0xdfff, (FPTR)Pico.zram);
236 Cz80_Set_Fetch(&CZ80, 0xe000, 0xffff, (FPTR)Pico.zram);
237 Cz80_Set_INPort(&CZ80, z80_sms_in);
238 Cz80_Set_OUTPort(&CZ80, z80_sms_out);
242 void PicoStateLoadedMS(void)
244 write_bank(0xfffe, Pico.ms.carthw[0x0e]);
245 write_bank(0xffff, Pico.ms.carthw[0x0f]);
248 void PicoFrameMS(void)
250 struct PicoVideo *pv = &Pico.video;
251 int is_pal = Pico.m.pal;
252 int lines = is_pal ? 313 : 262;
253 int cycles_line = is_pal ? 58020 : 58293; /* (226.6 : 227.7) * 256 */
254 int cycles_done = 0, cycles_aim = 0;
255 int skip = PicoSkipFrame;
257 int hint; // Hint counter
261 nmi = (PicoPad[0] >> 7) & 1;
262 if (!Pico.ms.nmi_state && nmi)
264 Pico.ms.nmi_state = nmi;
266 PicoFrameStartMode4();
267 hint = pv->reg[0x0a];
269 for (y = 0; y < lines; y++)
271 pv->v_counter = Pico.m.scanline = y;
273 pv->v_counter = y - 6;
275 if (y < lines_vis && !skip)
282 hint = pv->reg[0x0a];
283 pv->pending_ints |= 2;
284 if (pv->reg[0] & 0x10) {
285 elprintf(EL_INTS, "hint");
290 else if (y == lines_vis + 1) {
291 pv->pending_ints |= 1;
292 if (pv->reg[1] & 0x20) {
293 elprintf(EL_INTS, "vint");
298 cycles_aim += cycles_line;
299 cycles_done += z80_run((cycles_aim - cycles_done) >> 8) << 8;
306 void PicoFrameDrawOnlyMS(void)
311 PicoFrameStartMode4();
313 for (y = 0; y < lines_vis; y++)