2 #include "sound/sn76496.h"
4 static unsigned char vdp_data_read(void)
6 struct PicoVideo *pv = &Pico.video;
9 d = Pico.vramb[pv->addr];
10 pv->addr = (pv->addr + 1) & 0x3fff;
15 static unsigned char vdp_ctl_read(void)
17 unsigned char d = Pico.video.pending_ints << 7;
18 Pico.video.pending = 0;
19 Pico.video.pending_ints = 0;
21 elprintf(EL_SR, "VDP sr: %02x", d);
25 static void vdp_data_write(unsigned char d)
27 struct PicoVideo *pv = &Pico.video;
30 Pico.cram[pv->addr & 0x1f] = d;
32 Pico.vramb[pv->addr] = d;
34 pv->addr = (pv->addr + 1) & 0x3fff;
35 elprintf(EL_ANOMALY, " addr=%04x", pv->addr);
40 static void vdp_ctl_write(unsigned char d)
42 struct PicoVideo *pv = &Pico.video;
46 pv->reg[d & 0x0f] = pv->addr;
47 elprintf(EL_ANOMALY, " VDP r%02x=%02x", d & 0x0f, pv->addr & 0xff);
51 pv->addr |= (d & 0x3f) << 8;
59 static unsigned char z80_sms_in(unsigned short a)
63 elprintf(EL_ANOMALY, "z80 port %04x read", a);
72 case 0x40: /* V counter */
73 d = Pico.video.v_counter;
76 case 0x41: /* H counter */
88 case 0xc0: /* I/O port A and B */
89 d = ~((PicoPad[0] & 0x3f) | (PicoPad[1] << 6));
92 case 0xc1: /* I/O port B and miscellaneous */
93 d = (Pico.sms_io_ctl & 0x80) | ((Pico.sms_io_ctl << 1) & 0x40) | 0x30;
94 d |= ~(PicoPad[1] >> 2) & 0x0f;
98 elprintf(EL_ANOMALY, "ret = %02x", d);
102 static void z80_sms_out(unsigned short a, unsigned char d)
104 elprintf(EL_ANOMALY, "z80 port %04x write %02x", a, d);
114 if (PicoOpt & POPT_EN_PSG)
128 static void write_bank(unsigned short a, unsigned char d)
137 elprintf(EL_STATUS|EL_ANOMALY, "bank0 changed to %d!", d);
140 z80_map_set(z80_read_map, 0x4000, 0x7fff, Pico.rom + (d << 14), 0);
142 Cz80_Set_Fetch(&CZ80, 0x4000, 0x7fff, (UINT32)Pico.rom + (d << 14));
146 z80_map_set(z80_read_map, 0x8000, 0xbfff, Pico.rom + (d << 14), 0);
148 Cz80_Set_Fetch(&CZ80, 0x8000, 0xbfff, (UINT32)Pico.rom + (d << 14));
154 static unsigned char MEMH_FUNC xread(unsigned short a)
156 elprintf(EL_ANOMALY, "z80 read [%04x]", a);
157 return Pico.zram[a & 0x1fff];
160 static void MEMH_FUNC xwrite(unsigned int a, unsigned char d)
162 elprintf(EL_ANOMALY, "z80 write [%04x] %02x", a, d);
164 Pico.zram[a & 0x1fff] = d;
169 void PicoResetMS(void)
172 PsndReset(); // pal must be known here
175 void PicoPowerMS(void)
177 memset(&Pico.ram,0,(unsigned int)&Pico.rom-(unsigned int)&Pico.ram);
178 memset(&Pico.video,0,sizeof(Pico.video));
179 memset(&Pico.m,0,sizeof(Pico.m));
185 void PicoMemSetupMS(void)
187 z80_map_set(z80_read_map, 0x0000, 0xbfff, Pico.rom, 0);
188 z80_map_set(z80_read_map, 0xc000, 0xdfff, Pico.zram, 0);
189 z80_map_set(z80_read_map, 0xe000, 0xffff, xread, 1);
191 z80_map_set(z80_write_map, 0x0000, 0xbfff, xwrite, 1);
192 z80_map_set(z80_write_map, 0xc000, 0xdfff, Pico.zram, 0);
193 z80_map_set(z80_write_map, 0xe000, 0xffff, xwrite, 1);
196 drZ80.z80_in = z80_sms_in;
197 drZ80.z80_out = z80_sms_out;
200 Cz80_Set_Fetch(&CZ80, 0x0000, 0xbfff, (UINT32)Pico.rom);
201 Cz80_Set_Fetch(&CZ80, 0xc000, 0xdfff, (UINT32)Pico.zram);
202 Cz80_Set_Fetch(&CZ80, 0xe000, 0xffff, (UINT32)Pico.zram);
203 Cz80_Set_INPort(&CZ80, z80_sms_in);
204 Cz80_Set_OUTPort(&CZ80, z80_sms_out);
208 void PicoFrameMS(void)
210 struct PicoVideo *pv = &Pico.video;
211 int is_pal = Pico.m.pal;
212 int lines = is_pal ? 313 : 262;
213 int cycles_line = is_pal ? 58020 : 58293; /* (226.6 : 227.7) * 256 */
214 int cycles_done = 0, cycles_aim = 0;
218 for (y = 0; y < lines; y++)
220 pv->v_counter = Pico.m.scanline = y;
222 if (y == lines_vis + 1) {
223 Pico.video.pending_ints |= 1;
224 if (Pico.video.reg[1] & 0x20) {
225 elprintf(EL_INTS, "vint");
230 cycles_aim += cycles_line;
231 cycles_done += z80_run((cycles_aim - cycles_done) >> 8) << 8;
235 elprintf(EL_ANOMALY, "frame end");