9037e45d |
1 | #include "../PicoInt.h" |
2 | |
406c96c5 |
3 | // x: 0x03c - 0x19d |
4 | // y: 0x1fc - 0x2f7 |
5 | // 0x2f8 - 0x3f3 |
d49b10c2 |
6 | picohw_state PicoPicohw; |
7 | |
8 | static int prev_line_cnt_irq3 = 0, prev_line_cnt_irq5 = 0; |
213c16ad |
9 | static int fifo_bytes_line = (16000<<16)/60/262/2; |
d49b10c2 |
10 | |
ed367a3f |
11 | PICO_INTERNAL void PicoReratePico(void) |
12 | { |
213c16ad |
13 | int rate = (PicoPicohw.r12 & 0xf) ? 16000 : 8000; |
ed367a3f |
14 | if (Pico.m.pal) |
213c16ad |
15 | fifo_bytes_line = (rate<<16)/50/312/2; |
16 | else fifo_bytes_line = (rate<<16)/60/262/2; |
17 | PicoPicoPCMRerate(rate); |
ed367a3f |
18 | } |
19 | |
ef4eb506 |
20 | static void PicoLinePico(int count) |
d49b10c2 |
21 | { |
d49b10c2 |
22 | PicoPicohw.line_counter += count; |
d49b10c2 |
23 | |
1e6b5e39 |
24 | #if 1 |
25 | if ((PicoPicohw.r12 & 0x4003) && PicoPicohw.line_counter - prev_line_cnt_irq3 > 200) { |
d49b10c2 |
26 | prev_line_cnt_irq3 = PicoPicohw.line_counter; |
27 | // just a guess/hack, allows 101 Dalmantians to boot |
28 | elprintf(EL_ANOMALY, "irq3"); |
29 | SekInterrupt(3); |
1e6b5e39 |
30 | return; |
31 | } |
32 | |
33 | if (PicoPicohw.fifo_bytes == 16) { |
34 | prev_line_cnt_irq3 = PicoPicohw.line_counter; |
35 | elprintf(EL_ANOMALY, "irq3, fb=%i", PicoPicohw.fifo_bytes); |
36 | SekInterrupt(3); |
37 | PicoPicohw.fifo_bytes--; |
38 | return; |
d49b10c2 |
39 | } |
40 | #endif |
41 | |
ef4eb506 |
42 | if (PicoPicohw.fifo_bytes > 0) |
1e6b5e39 |
43 | { |
ef4eb506 |
44 | PicoPicohw.fifo_line_bytes += fifo_bytes_line * count; |
45 | if (PicoPicohw.fifo_line_bytes >= (1<<16)) { |
46 | PicoPicohw.fifo_bytes -= PicoPicohw.fifo_line_bytes >> 16; |
47 | PicoPicohw.fifo_line_bytes &= 0xffff; |
48 | if (PicoPicohw.fifo_bytes < 0) |
49 | PicoPicohw.fifo_bytes = 0; |
50 | } |
1e6b5e39 |
51 | } |
ef4eb506 |
52 | else |
53 | PicoPicohw.fifo_line_bytes = 0; |
1e6b5e39 |
54 | |
d49b10c2 |
55 | #if 0 |
56 | if (PicoPicohw.line_counter - prev_line_cnt_irq5 > 512) { |
57 | prev_line_cnt_irq5 = PicoPicohw.line_counter; |
58 | elprintf(EL_ANOMALY, "irq5"); |
59 | SekInterrupt(5); |
60 | } |
61 | #endif |
62 | } |
406c96c5 |
63 | |
ef4eb506 |
64 | static void PicoResetPico(void) |
65 | { |
66 | PicoPicoPCMReset(); |
67 | PicoPicohw.xpcm_ptr = PicoPicohw.xpcm_buffer; |
68 | } |
69 | |
9037e45d |
70 | PICO_INTERNAL int PicoInitPico(void) |
71 | { |
72 | elprintf(EL_STATUS, "Pico detected"); |
ef4eb506 |
73 | PicoLineHook = PicoLinePico; |
74 | PicoResetHook = PicoResetPico; |
d49b10c2 |
75 | |
9037e45d |
76 | PicoAHW = PAHW_PICO; |
d49b10c2 |
77 | memset(&PicoPicohw, 0, sizeof(PicoPicohw)); |
213c16ad |
78 | PicoPicohw.pen_pos[0] = 0x03c + 320/2; |
79 | PicoPicohw.pen_pos[1] = 0x200 + 240/2; |
ef4eb506 |
80 | prev_line_cnt_irq3 = prev_line_cnt_irq5 = 0; |
9037e45d |
81 | |
1e6b5e39 |
82 | // map version register |
83 | PicoDetectRegion(); |
1e6b5e39 |
84 | switch (Pico.m.hardware >> 6) { |
85 | case 0: PicoPicohw.r1 = 0x00; break; |
86 | case 1: PicoPicohw.r1 = 0x00; break; |
87 | case 2: PicoPicohw.r1 = 0x40; break; |
88 | case 3: PicoPicohw.r1 = 0x20; break; |
89 | } |
90 | |
9037e45d |
91 | return 0; |
92 | } |
93 | |