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 * - Pause button (NMI)
15 * - SN76496 DAC-like usage
20 #include "sound/sn76496.h"
22 static unsigned char vdp_data_read(void)
24 struct PicoVideo *pv = &Pico.video;
27 d = Pico.vramb[pv->addr];
28 pv->addr = (pv->addr + 1) & 0x3fff;
33 static unsigned char vdp_ctl_read(void)
35 unsigned char d = Pico.video.pending_ints << 7;
36 Pico.video.pending = 0;
37 Pico.video.pending_ints = 0;
39 elprintf(EL_SR, "VDP sr: %02x", d);
43 static void vdp_data_write(unsigned char d)
45 struct PicoVideo *pv = &Pico.video;
48 Pico.cram[pv->addr & 0x1f] = d;
51 Pico.vramb[pv->addr] = d;
53 pv->addr = (pv->addr + 1) & 0x3fff;
58 static void vdp_ctl_write(unsigned char d)
60 struct PicoVideo *pv = &Pico.video;
64 pv->reg[d & 0x0f] = pv->addr;
65 elprintf(EL_IO, " VDP r%02x=%02x", d & 0x0f, pv->addr & 0xff);
69 pv->addr |= (d & 0x3f) << 8;
77 static unsigned char z80_sms_in(unsigned short a)
81 elprintf(EL_IO, "z80 port %04x read", a);
90 case 0x40: /* V counter */
91 d = Pico.video.v_counter;
92 elprintf(EL_HVCNT, "V counter read: %02x", d);
95 case 0x41: /* H counter */
97 elprintf(EL_HVCNT, "H counter read: %02x", d);
108 case 0xc0: /* I/O port A and B */
109 d = ~((PicoPad[0] & 0x3f) | (PicoPad[1] << 6));
112 case 0xc1: /* I/O port B and miscellaneous */
113 d = (Pico.ms.io_ctl & 0x80) | ((Pico.ms.io_ctl << 1) & 0x40) | 0x30;
114 d |= ~(PicoPad[1] >> 2) & 0x0f;
118 elprintf(EL_IO, "ret = %02x", d);
122 static void z80_sms_out(unsigned short a, unsigned char d)
124 elprintf(EL_IO, "z80 port %04x write %02x", a, d);
134 if (PicoOpt & POPT_EN_PSG)
148 static int bank_mask;
150 static void write_bank(unsigned short a, unsigned char d)
152 elprintf(EL_Z80BNK, "bank %04x %02x @ %04x", a, d, z80_pc());
156 elprintf(EL_STATUS|EL_ANOMALY, "%02x written to control reg!", d);
160 elprintf(EL_STATUS|EL_ANOMALY, "bank0 changed to %d!", d);
164 z80_map_set(z80_read_map, 0x4000, 0x7fff, Pico.rom + (d << 14), 0);
166 Cz80_Set_Fetch(&CZ80, 0x4000, 0x7fff, (FPTR)Pico.rom + (d << 14));
171 z80_map_set(z80_read_map, 0x8000, 0xbfff, Pico.rom + (d << 14), 0);
173 Cz80_Set_Fetch(&CZ80, 0x8000, 0xbfff, (FPTR)Pico.rom + (d << 14));
177 Pico.ms.carthw[a & 0x0f] = d;
180 static void xwrite(unsigned int a, unsigned char d)
182 elprintf(EL_IO, "z80 write [%04x] %02x", a, d);
184 Pico.zram[a & 0x1fff] = d;
189 void PicoResetMS(void)
192 PsndReset(); // pal must be known here
195 void PicoPowerMS(void)
199 memset(&Pico.ram,0,(unsigned char *)&Pico.rom - Pico.ram);
200 memset(&Pico.video,0,sizeof(Pico.video));
201 memset(&Pico.m,0,sizeof(Pico.m));
204 // calculate a mask for bank writes.
205 // ROM loader has aligned the size for us, so this is safe.
206 s = 0; tmp = Pico.romsize;
207 while ((tmp >>= 1) != 0)
209 if (Pico.romsize > (1 << s))
212 bank_mask = (tmp - 1) >> 14;
214 Pico.ms.carthw[0x0e] = 1;
215 Pico.ms.carthw[0x0f] = 2;
220 void PicoMemSetupMS(void)
222 z80_map_set(z80_read_map, 0x0000, 0xbfff, Pico.rom, 0);
223 z80_map_set(z80_read_map, 0xc000, 0xdfff, Pico.zram, 0);
224 z80_map_set(z80_read_map, 0xe000, 0xffff, Pico.zram, 0);
226 z80_map_set(z80_write_map, 0x0000, 0xbfff, xwrite, 1);
227 z80_map_set(z80_write_map, 0xc000, 0xdfff, Pico.zram, 0);
228 z80_map_set(z80_write_map, 0xe000, 0xffff, xwrite, 1);
231 drZ80.z80_in = z80_sms_in;
232 drZ80.z80_out = z80_sms_out;
235 Cz80_Set_Fetch(&CZ80, 0x0000, 0xbfff, (FPTR)Pico.rom);
236 Cz80_Set_Fetch(&CZ80, 0xc000, 0xdfff, (FPTR)Pico.zram);
237 Cz80_Set_Fetch(&CZ80, 0xe000, 0xffff, (FPTR)Pico.zram);
238 Cz80_Set_INPort(&CZ80, z80_sms_in);
239 Cz80_Set_OUTPort(&CZ80, z80_sms_out);
243 void PicoStateLoadedMS(void)
245 write_bank(0xfffe, Pico.ms.carthw[0x0e]);
246 write_bank(0xffff, Pico.ms.carthw[0x0f]);
249 void PicoFrameMS(void)
251 struct PicoVideo *pv = &Pico.video;
252 int is_pal = Pico.m.pal;
253 int lines = is_pal ? 313 : 262;
254 int cycles_line = is_pal ? 58020 : 58293; /* (226.6 : 227.7) * 256 */
255 int cycles_done = 0, cycles_aim = 0;
256 int skip = PicoSkipFrame;
258 int hint; // Hint counter
261 PicoFrameStartMode4();
262 hint = pv->reg[0x0a];
264 for (y = 0; y < lines; y++)
266 pv->v_counter = Pico.m.scanline = y;
268 pv->v_counter = y - 6;
270 if (y < lines_vis && !skip)
277 hint = pv->reg[0x0a];
278 pv->pending_ints |= 2;
279 if (pv->reg[0] & 0x10) {
280 elprintf(EL_INTS, "hint");
285 else if (y == lines_vis + 1) {
286 pv->pending_ints |= 1;
287 if (pv->reg[1] & 0x20) {
288 elprintf(EL_INTS, "vint");
293 cycles_aim += cycles_line;
294 cycles_done += z80_run((cycles_aim - cycles_done) >> 8) << 8;
301 void PicoFrameDrawOnlyMS(void)
306 PicoFrameStartMode4();
308 for (y = 0; y < lines_vis; y++)