5 * This work is licensed under the terms of MAME license.
6 * See COPYING file in the top-level directory.
8 #include "../pico_int.h"
13 picohw_state PicoPicohw;
15 static int prev_line_cnt_irq3 = 0, prev_line_cnt_irq5 = 0;
16 static int fifo_bytes_line = (16000<<16)/60/262/2;
18 static const int guessed_rates[] = { 8000, 14000, 12000, 14000, 16000, 18000, 16000, 16000 }; // ?
20 #define PICOHW_FIFO_IRQ_THRESHOLD 12
22 PICO_INTERNAL void PicoReratePico(void)
24 int rate = guessed_rates[PicoPicohw.r12 & 7];
26 fifo_bytes_line = (rate<<16)/50/313/2;
27 else fifo_bytes_line = (rate<<16)/60/262/2;
28 PicoPicoPCMRerate(rate);
31 static void PicoLinePico(void)
33 PicoPicohw.line_counter++;
36 if ((PicoPicohw.r12 & 0x4003) && PicoPicohw.line_counter - prev_line_cnt_irq3 > 200) {
37 prev_line_cnt_irq3 = PicoPicohw.line_counter;
38 // just a guess/hack, allows 101 Dalmantians to boot
39 elprintf(EL_PICOHW, "irq3");
45 if (PicoPicohw.fifo_bytes > 0)
47 PicoPicohw.fifo_line_bytes += fifo_bytes_line;
48 if (PicoPicohw.fifo_line_bytes >= (1<<16)) {
49 PicoPicohw.fifo_bytes -= PicoPicohw.fifo_line_bytes >> 16;
50 PicoPicohw.fifo_line_bytes &= 0xffff;
51 if (PicoPicohw.fifo_bytes < 0)
52 PicoPicohw.fifo_bytes = 0;
56 PicoPicohw.fifo_line_bytes = 0;
59 if (PicoPicohw.fifo_bytes_prev >= PICOHW_FIFO_IRQ_THRESHOLD &&
60 PicoPicohw.fifo_bytes < PICOHW_FIFO_IRQ_THRESHOLD) {
61 prev_line_cnt_irq3 = PicoPicohw.line_counter; // ?
62 elprintf(EL_PICOHW, "irq3, fb=%i", PicoPicohw.fifo_bytes);
65 PicoPicohw.fifo_bytes_prev = PicoPicohw.fifo_bytes;
69 if (PicoPicohw.line_counter - prev_line_cnt_irq5 > 512) {
70 prev_line_cnt_irq5 = PicoPicohw.line_counter;
71 elprintf(EL_PICOHW, "irq5");
77 static void PicoResetPico(void)
80 PicoPicohw.xpcm_ptr = PicoPicohw.xpcm_buffer;
83 PICO_INTERNAL void PicoInitPico(void)
85 elprintf(EL_STATUS, "Pico startup");
86 PicoLineHook = PicoLinePico;
87 PicoResetHook = PicoResetPico;
90 memset(&PicoPicohw, 0, sizeof(PicoPicohw));
91 PicoPicohw.pen_pos[0] = 0x03c + 320/2;
92 PicoPicohw.pen_pos[1] = 0x200 + 240/2;
93 prev_line_cnt_irq3 = prev_line_cnt_irq5 = 0;
95 // map version register
97 switch (Pico.m.hardware >> 6) {
98 case 0: PicoPicohw.r1 = 0x00; break;
99 case 1: PicoPicohw.r1 = 0x00; break;
100 case 2: PicoPicohw.r1 = 0x40; break;
101 case 3: PicoPicohw.r1 = 0x20; break;