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; |
ef4eb506 |
9 | static int fifo_bytes_line = (16000<<16)/60/262/2; // fifo bytes/line. FIXME: other rates, modes |
d49b10c2 |
10 | |
ef4eb506 |
11 | static void PicoLinePico(int count) |
d49b10c2 |
12 | { |
d49b10c2 |
13 | PicoPicohw.line_counter += count; |
d49b10c2 |
14 | |
1e6b5e39 |
15 | #if 1 |
16 | if ((PicoPicohw.r12 & 0x4003) && PicoPicohw.line_counter - prev_line_cnt_irq3 > 200) { |
d49b10c2 |
17 | prev_line_cnt_irq3 = PicoPicohw.line_counter; |
18 | // just a guess/hack, allows 101 Dalmantians to boot |
19 | elprintf(EL_ANOMALY, "irq3"); |
20 | SekInterrupt(3); |
1e6b5e39 |
21 | return; |
22 | } |
23 | |
24 | if (PicoPicohw.fifo_bytes == 16) { |
25 | prev_line_cnt_irq3 = PicoPicohw.line_counter; |
26 | elprintf(EL_ANOMALY, "irq3, fb=%i", PicoPicohw.fifo_bytes); |
27 | SekInterrupt(3); |
28 | PicoPicohw.fifo_bytes--; |
29 | return; |
d49b10c2 |
30 | } |
31 | #endif |
32 | |
ef4eb506 |
33 | if (PicoPicohw.fifo_bytes > 0) |
1e6b5e39 |
34 | { |
ef4eb506 |
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; |
41 | } |
1e6b5e39 |
42 | } |
ef4eb506 |
43 | else |
44 | PicoPicohw.fifo_line_bytes = 0; |
1e6b5e39 |
45 | |
d49b10c2 |
46 | #if 0 |
47 | if (PicoPicohw.line_counter - prev_line_cnt_irq5 > 512) { |
48 | prev_line_cnt_irq5 = PicoPicohw.line_counter; |
49 | elprintf(EL_ANOMALY, "irq5"); |
50 | SekInterrupt(5); |
51 | } |
52 | #endif |
53 | } |
406c96c5 |
54 | |
ef4eb506 |
55 | static void PicoResetPico(void) |
56 | { |
57 | PicoPicoPCMReset(); |
58 | PicoPicohw.xpcm_ptr = PicoPicohw.xpcm_buffer; |
59 | } |
60 | |
9037e45d |
61 | PICO_INTERNAL int PicoInitPico(void) |
62 | { |
63 | elprintf(EL_STATUS, "Pico detected"); |
ef4eb506 |
64 | PicoLineHook = PicoLinePico; |
65 | PicoResetHook = PicoResetPico; |
d49b10c2 |
66 | |
9037e45d |
67 | PicoAHW = PAHW_PICO; |
d49b10c2 |
68 | memset(&PicoPicohw, 0, sizeof(PicoPicohw)); |
69 | PicoPicohw.pen_pos[0] = 0x03c + 352/2; |
70 | PicoPicohw.pen_pos[1] = 0x200 + 252/2; |
ef4eb506 |
71 | prev_line_cnt_irq3 = prev_line_cnt_irq5 = 0; |
9037e45d |
72 | |
1e6b5e39 |
73 | // map version register |
74 | PicoDetectRegion(); |
1e6b5e39 |
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; |
80 | } |
81 | |
9037e45d |
82 | return 0; |
83 | } |
84 | |