1 /*  Copyright 2003-2005 Guillaume Duhamel
2     Copyright 2004-2006 Theo Berkau
3 
4     This file is part of Yabause.
5 
6     Yabause is free software; you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation; either version 2 of the License, or
9     (at your option) any later version.
10 
11     Yabause is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.
15 
16     You should have received a copy of the GNU General Public License
17     along with Yabause; if not, write to the Free Software
18     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
19 */
20 
21 #ifndef SMPC_H
22 #define SMPC_H
23 
24 #include "memory.h"
25 
26 #define REGION_AUTODETECT               0
27 #define REGION_JAPAN                    1
28 #define REGION_ASIANTSC                 2
29 #define REGION_NORTHAMERICA             4
30 #define REGION_CENTRALSOUTHAMERICANTSC  5
31 #define REGION_KOREA                    6
32 #define REGION_ASIAPAL                  10
33 #define REGION_EUROPE                   12
34 #define REGION_CENTRALSOUTHAMERICAPAL   13
35 
36 typedef struct {
37         u8 IREG[7];
38         u8 padding[8];
39 	u8 COMREG;
40         u8 OREG[32];
41 	u8 SR;
42 	u8 SF;
43         u8 padding2[8];
44         u8 PDR[2];
45         u8 DDR[2];
46         u8 IOSEL;
47         u8 EXLE;
48 } Smpc;
49 
50 extern Smpc * SmpcRegs;
51 extern u8 * SmpcRegsT;
52 
53 typedef struct
54 {
55    int offset;
56    int size;
57    u8 data[256];
58 } PortData_struct;
59 
60 typedef struct {
61    u8 dotsel; // 0 -> 320 | 1 -> 352
62    u8 mshnmi;
63    u8 sndres;
64    u8 cdres;
65    u8 sysres;
66    u8 resb;
67    u8 ste;
68    u8 resd;
69    u8 intback;
70    u8 intbackIreg0;
71    u8 firstPeri;
72    u8 regionid;
73    u8 regionsetting;
74    u8 SMEM[4];
75    s32 timing;
76    PortData_struct port1;
77    PortData_struct port2;
78    u8 clocksync;
79    u32 basetime;  // Safe until early 2106.  After that you're on your own (:
80 } SmpcInternal;
81 
82 extern SmpcInternal * SmpcInternalVars;
83 
84 int SmpcInit(u8 regionid, int clocksync, u32 basetime);
85 void SmpcDeInit(void);
86 void SmpcRecheckRegion(void);
87 void SmpcReset(void);
88 void SmpcResetButton(void);
89 void SmpcExec(s32 t);
90 void SmpcINTBACKEnd(void);
91 void SmpcCKCHG320(void);
92 void SmpcCKCHG352(void);
93 
94 u8 FASTCALL	SmpcReadByte(SH2_struct *, u32);
95 u16 FASTCALL	SmpcReadWord(SH2_struct *, u32);
96 u32 FASTCALL	SmpcReadLong(SH2_struct *, u32);
97 void FASTCALL	SmpcWriteByte(SH2_struct *, u32, u8);
98 void FASTCALL	SmpcWriteWord(SH2_struct *, u32, u16);
99 void FASTCALL	SmpcWriteLong(SH2_struct *, u32, u32);
100 
101 int SmpcSaveState(FILE *fp);
102 int SmpcLoadState(FILE *fp, int version, int size);
103 #endif
104