1 #include "../PicoInt.h"
6 picohw_state PicoPicohw;
8 static int prev_line_cnt_irq3 = 0, prev_line_cnt_irq5 = 0;
9 static int fifo_bytes_line = (16000<<16)/60/262/2;
11 static const int guessed_rates[] = { 8000, 14000, 12000, 14000, 16000, 18000, 16000, 16000 }; // ?
13 #define PICOHW_FIFO_IRQ_THRESHOLD 12
15 PICO_INTERNAL void PicoReratePico(void)
17 int rate = guessed_rates[PicoPicohw.r12 & 7];
19 fifo_bytes_line = (rate<<16)/50/312/2;
20 else fifo_bytes_line = (rate<<16)/60/262/2;
21 PicoPicoPCMRerate(rate);
24 static void PicoLinePico(void)
26 PicoPicohw.line_counter++;
29 if ((PicoPicohw.r12 & 0x4003) && PicoPicohw.line_counter - prev_line_cnt_irq3 > 200) {
30 prev_line_cnt_irq3 = PicoPicohw.line_counter;
31 // just a guess/hack, allows 101 Dalmantians to boot
32 elprintf(EL_PICOHW, "irq3");
38 if (PicoPicohw.fifo_bytes > 0)
40 PicoPicohw.fifo_line_bytes += fifo_bytes_line;
41 if (PicoPicohw.fifo_line_bytes >= (1<<16)) {
42 PicoPicohw.fifo_bytes -= PicoPicohw.fifo_line_bytes >> 16;
43 PicoPicohw.fifo_line_bytes &= 0xffff;
44 if (PicoPicohw.fifo_bytes < 0)
45 PicoPicohw.fifo_bytes = 0;
49 PicoPicohw.fifo_line_bytes = 0;
52 if (PicoPicohw.fifo_bytes_prev >= PICOHW_FIFO_IRQ_THRESHOLD &&
53 PicoPicohw.fifo_bytes < PICOHW_FIFO_IRQ_THRESHOLD) {
54 prev_line_cnt_irq3 = PicoPicohw.line_counter; // ?
55 elprintf(EL_PICOHW, "irq3, fb=%i", PicoPicohw.fifo_bytes);
58 PicoPicohw.fifo_bytes_prev = PicoPicohw.fifo_bytes;
62 if (PicoPicohw.line_counter - prev_line_cnt_irq5 > 512) {
63 prev_line_cnt_irq5 = PicoPicohw.line_counter;
64 elprintf(EL_PICOHW, "irq5");
70 static void PicoResetPico(void)
73 PicoPicohw.xpcm_ptr = PicoPicohw.xpcm_buffer;
76 PICO_INTERNAL void PicoInitPico(void)
78 elprintf(EL_STATUS, "Pico detected");
79 PicoLineHook = PicoLinePico;
80 PicoResetHook = PicoResetPico;
83 memset(&PicoPicohw, 0, sizeof(PicoPicohw));
84 PicoPicohw.pen_pos[0] = 0x03c + 320/2;
85 PicoPicohw.pen_pos[1] = 0x200 + 240/2;
86 prev_line_cnt_irq3 = prev_line_cnt_irq5 = 0;
88 // map version register
90 switch (Pico.m.hardware >> 6) {
91 case 0: PicoPicohw.r1 = 0x00; break;
92 case 1: PicoPicohw.r1 = 0x00; break;
93 case 2: PicoPicohw.r1 = 0x40; break;
94 case 3: PicoPicohw.r1 = 0x20; break;