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.sms_io_ctl & 0x80) | ((Pico.sms_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));
172 static void xwrite(unsigned int a, unsigned char d)
174 elprintf(EL_IO, "z80 write [%04x] %02x", a, d);
176 Pico.zram[a & 0x1fff] = d;
181 void PicoResetMS(void)
184 PsndReset(); // pal must be known here
187 void PicoPowerMS(void)
191 memset(&Pico.ram,0,(unsigned char *)&Pico.rom - Pico.ram);
192 memset(&Pico.video,0,sizeof(Pico.video));
193 memset(&Pico.m,0,sizeof(Pico.m));
196 // calculate a mask for bank writes.
197 // ROM loader has aligned the size for us, so this is safe.
198 s = 0; tmp = Pico.romsize;
199 while ((tmp >>= 1) != 0)
201 if (Pico.romsize > (1 << s))
204 bank_mask = (tmp - 1) >> 14;
209 void PicoMemSetupMS(void)
211 z80_map_set(z80_read_map, 0x0000, 0xbfff, Pico.rom, 0);
212 z80_map_set(z80_read_map, 0xc000, 0xdfff, Pico.zram, 0);
213 z80_map_set(z80_read_map, 0xe000, 0xffff, Pico.zram, 0);
215 z80_map_set(z80_write_map, 0x0000, 0xbfff, xwrite, 1);
216 z80_map_set(z80_write_map, 0xc000, 0xdfff, Pico.zram, 0);
217 z80_map_set(z80_write_map, 0xe000, 0xffff, xwrite, 1);
220 drZ80.z80_in = z80_sms_in;
221 drZ80.z80_out = z80_sms_out;
224 Cz80_Set_Fetch(&CZ80, 0x0000, 0xbfff, (FPTR)Pico.rom);
225 Cz80_Set_Fetch(&CZ80, 0xc000, 0xdfff, (FPTR)Pico.zram);
226 Cz80_Set_Fetch(&CZ80, 0xe000, 0xffff, (FPTR)Pico.zram);
227 Cz80_Set_INPort(&CZ80, z80_sms_in);
228 Cz80_Set_OUTPort(&CZ80, z80_sms_out);
232 void PicoFrameMS(void)
234 struct PicoVideo *pv = &Pico.video;
235 int is_pal = Pico.m.pal;
236 int lines = is_pal ? 313 : 262;
237 int cycles_line = is_pal ? 58020 : 58293; /* (226.6 : 227.7) * 256 */
238 int cycles_done = 0, cycles_aim = 0;
239 int skip = PicoSkipFrame;
241 int hint; // Hint counter
244 PicoFrameStartMode4();
245 hint = pv->reg[0x0a];
247 for (y = 0; y < lines; y++)
249 pv->v_counter = Pico.m.scanline = y;
251 if (y < lines_vis && !skip)
258 hint = pv->reg[0x0a];
259 pv->pending_ints |= 2;
260 if (pv->reg[0] & 0x10) {
261 elprintf(EL_INTS, "hint");
266 else if (y == lines_vis + 1) {
267 pv->pending_ints |= 1;
268 if (pv->reg[1] & 0x20) {
269 elprintf(EL_INTS, "vint");
274 cycles_aim += cycles_line;
275 cycles_done += z80_run((cycles_aim - cycles_done) >> 8) << 8;
282 void PicoFrameDrawOnlyMS(void)
287 PicoFrameStartMode4();
289 for (y = 0; y < lines_vis; y++)