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
12 #include "sound/sn76496.h"
14 static unsigned char vdp_data_read(void)
16 struct PicoVideo *pv = &Pico.video;
19 d = Pico.vramb[pv->addr];
20 pv->addr = (pv->addr + 1) & 0x3fff;
25 static unsigned char vdp_ctl_read(void)
27 unsigned char d = Pico.video.pending_ints << 7;
28 Pico.video.pending = 0;
29 Pico.video.pending_ints = 0;
31 elprintf(EL_SR, "VDP sr: %02x", d);
35 static void vdp_data_write(unsigned char d)
37 struct PicoVideo *pv = &Pico.video;
40 Pico.cram[pv->addr & 0x1f] = d;
43 Pico.vramb[pv->addr] = d;
45 pv->addr = (pv->addr + 1) & 0x3fff;
50 static void vdp_ctl_write(unsigned char d)
52 struct PicoVideo *pv = &Pico.video;
56 pv->reg[d & 0x0f] = pv->addr;
57 elprintf(EL_IO, " VDP r%02x=%02x", d & 0x0f, pv->addr & 0xff);
61 pv->addr |= (d & 0x3f) << 8;
69 static unsigned char z80_sms_in(unsigned short a)
73 elprintf(EL_IO, "z80 port %04x read", a);
82 case 0x40: /* V counter */
83 d = Pico.video.v_counter;
84 elprintf(EL_HVCNT, "V counter read: %02x", d);
87 case 0x41: /* H counter */
89 elprintf(EL_HVCNT, "H counter read: %02x", d);
100 case 0xc0: /* I/O port A and B */
101 d = ~((PicoPad[0] & 0x3f) | (PicoPad[1] << 6));
104 case 0xc1: /* I/O port B and miscellaneous */
105 d = (Pico.sms_io_ctl & 0x80) | ((Pico.sms_io_ctl << 1) & 0x40) | 0x30;
106 d |= ~(PicoPad[1] >> 2) & 0x0f;
110 elprintf(EL_IO, "ret = %02x", d);
114 static void z80_sms_out(unsigned short a, unsigned char d)
116 elprintf(EL_IO, "z80 port %04x write %02x", a, d);
126 if (PicoOpt & POPT_EN_PSG)
140 static int bank_mask;
142 static void write_bank(unsigned short a, unsigned char d)
144 elprintf(EL_Z80BNK, "bank %04x %02x @ %04x", a, d, z80_pc());
148 elprintf(EL_STATUS|EL_ANOMALY, "%02x written to control reg!", d);
152 elprintf(EL_STATUS|EL_ANOMALY, "bank0 changed to %d!", d);
156 z80_map_set(z80_read_map, 0x4000, 0x7fff, Pico.rom + (d << 14), 0);
158 Cz80_Set_Fetch(&CZ80, 0x4000, 0x7fff, (UINT32)Pico.rom + (d << 14));
163 z80_map_set(z80_read_map, 0x8000, 0xbfff, Pico.rom + (d << 14), 0);
165 Cz80_Set_Fetch(&CZ80, 0x8000, 0xbfff, (UINT32)Pico.rom + (d << 14));
171 static void MEMH_FUNC xwrite(unsigned int a, unsigned char d)
173 elprintf(EL_IO, "z80 write [%04x] %02x", a, d);
175 Pico.zram[a & 0x1fff] = d;
180 void PicoResetMS(void)
183 PsndReset(); // pal must be known here
186 void PicoPowerMS(void)
190 memset(&Pico.ram,0,(unsigned int)&Pico.rom-(unsigned int)&Pico.ram);
191 memset(&Pico.video,0,sizeof(Pico.video));
192 memset(&Pico.m,0,sizeof(Pico.m));
195 // calculate a mask for bank writes.
196 // ROM loader has aligned the size for us, so this is safe.
197 s = 0; tmp = Pico.romsize;
198 while ((tmp >>= 1) != 0)
200 if (Pico.romsize > (1 << s))
203 bank_mask = (tmp - 1) >> 14;
208 void PicoMemSetupMS(void)
210 z80_map_set(z80_read_map, 0x0000, 0xbfff, Pico.rom, 0);
211 z80_map_set(z80_read_map, 0xc000, 0xdfff, Pico.zram, 0);
212 z80_map_set(z80_read_map, 0xe000, 0xffff, Pico.zram, 0);
214 z80_map_set(z80_write_map, 0x0000, 0xbfff, xwrite, 1);
215 z80_map_set(z80_write_map, 0xc000, 0xdfff, Pico.zram, 0);
216 z80_map_set(z80_write_map, 0xe000, 0xffff, xwrite, 1);
219 drZ80.z80_in = z80_sms_in;
220 drZ80.z80_out = z80_sms_out;
223 Cz80_Set_Fetch(&CZ80, 0x0000, 0xbfff, (UINT32)Pico.rom);
224 Cz80_Set_Fetch(&CZ80, 0xc000, 0xdfff, (UINT32)Pico.zram);
225 Cz80_Set_Fetch(&CZ80, 0xe000, 0xffff, (UINT32)Pico.zram);
226 Cz80_Set_INPort(&CZ80, z80_sms_in);
227 Cz80_Set_OUTPort(&CZ80, z80_sms_out);
231 void PicoFrameMS(void)
233 struct PicoVideo *pv = &Pico.video;
234 int is_pal = Pico.m.pal;
235 int lines = is_pal ? 313 : 262;
236 int cycles_line = is_pal ? 58020 : 58293; /* (226.6 : 227.7) * 256 */
237 int cycles_done = 0, cycles_aim = 0;
238 int skip = PicoSkipFrame;
240 int hint; // Hint counter
243 PicoFrameStartMode4();
244 hint = pv->reg[0x0a];
246 for (y = 0; y < lines; y++)
248 pv->v_counter = Pico.m.scanline = y;
250 if (y < lines_vis && !skip)
257 hint = pv->reg[0x0a];
258 pv->pending_ints |= 2;
259 if (pv->reg[0] & 0x10) {
260 elprintf(EL_INTS, "hint");
265 else if (y == lines_vis + 1) {
266 pv->pending_ints |= 1;
267 if (pv->reg[1] & 0x20) {
268 elprintf(EL_INTS, "vint");
273 cycles_aim += cycles_line;
274 cycles_done += z80_run((cycles_aim - cycles_done) >> 8) << 8;
281 void PicoFrameDrawOnlyMS(void)
286 PicoFrameStartMode4();
288 for (y = 0; y < lines_vis; y++)