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; // fifo bytes/line. FIXME: other rates, modes
11 static void PicoLinePico(int count)
13 PicoPicohw.line_counter += count;
16 if ((PicoPicohw.r12 & 0x4003) && PicoPicohw.line_counter - prev_line_cnt_irq3 > 200) {
17 prev_line_cnt_irq3 = PicoPicohw.line_counter;
18 // just a guess/hack, allows 101 Dalmantians to boot
19 elprintf(EL_ANOMALY, "irq3");
24 if (PicoPicohw.fifo_bytes == 16) {
25 prev_line_cnt_irq3 = PicoPicohw.line_counter;
26 elprintf(EL_ANOMALY, "irq3, fb=%i", PicoPicohw.fifo_bytes);
28 PicoPicohw.fifo_bytes--;
33 if (PicoPicohw.fifo_bytes > 0)
35 PicoPicohw.fifo_line_bytes += fifo_bytes_line * count;
36 if (PicoPicohw.fifo_line_bytes >= (1<<16)) {
37 PicoPicohw.fifo_bytes -= PicoPicohw.fifo_line_bytes >> 16;
38 PicoPicohw.fifo_line_bytes &= 0xffff;
39 if (PicoPicohw.fifo_bytes < 0)
40 PicoPicohw.fifo_bytes = 0;
44 PicoPicohw.fifo_line_bytes = 0;
47 if (PicoPicohw.line_counter - prev_line_cnt_irq5 > 512) {
48 prev_line_cnt_irq5 = PicoPicohw.line_counter;
49 elprintf(EL_ANOMALY, "irq5");
55 static void PicoResetPico(void)
58 PicoPicohw.xpcm_ptr = PicoPicohw.xpcm_buffer;
61 PICO_INTERNAL int PicoInitPico(void)
63 elprintf(EL_STATUS, "Pico detected");
64 PicoLineHook = PicoLinePico;
65 PicoResetHook = PicoResetPico;
68 memset(&PicoPicohw, 0, sizeof(PicoPicohw));
69 PicoPicohw.pen_pos[0] = 0x03c + 352/2;
70 PicoPicohw.pen_pos[1] = 0x200 + 252/2;
71 prev_line_cnt_irq3 = prev_line_cnt_irq5 = 0;
73 // map version register
75 switch (Pico.m.hardware >> 6) {
76 case 0: PicoPicohw.r1 = 0x00; break;
77 case 1: PicoPicohw.r1 = 0x00; break;
78 case 2: PicoPicohw.r1 = 0x40; break;
79 case 3: PicoPicohw.r1 = 0x20; break;