Pico PCM, only one hardcoded mode for now
[picodrive.git] / Pico / Pico / Pico.c
... / ...
CommitLineData
1#include "../PicoInt.h"
2
3// x: 0x03c - 0x19d
4// y: 0x1fc - 0x2f7
5// 0x2f8 - 0x3f3
6picohw_state PicoPicohw;
7
8static int prev_line_cnt_irq3 = 0, prev_line_cnt_irq5 = 0;
9static int fifo_bytes_line = (16000<<16)/60/262/2; // fifo bytes/line. FIXME: other rates, modes
10
11static void PicoLinePico(int count)
12{
13 PicoPicohw.line_counter += count;
14
15#if 1
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");
20 SekInterrupt(3);
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;
30 }
31#endif
32
33 if (PicoPicohw.fifo_bytes > 0)
34 {
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 }
42 }
43 else
44 PicoPicohw.fifo_line_bytes = 0;
45
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}
54
55static void PicoResetPico(void)
56{
57 PicoPicoPCMReset();
58 PicoPicohw.xpcm_ptr = PicoPicohw.xpcm_buffer;
59}
60
61PICO_INTERNAL int PicoInitPico(void)
62{
63 elprintf(EL_STATUS, "Pico detected");
64 PicoLineHook = PicoLinePico;
65 PicoResetHook = PicoResetPico;
66
67 PicoAHW = PAHW_PICO;
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;
72
73 // map version register
74 PicoDetectRegion();
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
82 return 0;
83}
84