1 /******************************************************************************/
2 /* Mednafen Sega Saturn Emulation Module                                      */
3 /******************************************************************************/
4 /* cart.h - Expansion cart emulation
5 **  Copyright (C) 2016-2017 Mednafen Team
6 **
7 ** This program is free software; you can redistribute it and/or
8 ** modify it under the terms of the GNU General Public License
9 ** as published by the Free Software Foundation; either version 2
10 ** of the License, or (at your option) any later version.
11 **
12 ** This program is distributed in the hope that it will be useful,
13 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
14 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 ** GNU General Public License for more details.
16 **
17 ** You should have received a copy of the GNU General Public License
18 ** along with this program; if not, write to the Free Software Foundation, Inc.,
19 ** 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
20 */
21 
22 #ifndef __MDFN_SS_CART_H
23 #define __MDFN_SS_CART_H
24 
25 #include "../state.h"
26 
27 struct CartInfo
28 {
29  void (*Reset)(bool powering_up);
30  void (*Kill)(void);
31 
32  void (*GetNVInfo)(const char** ext, void** nv_ptr, bool* nv16, uint64* nv_size);
33  bool (*GetClearNVDirty)(void);
34 
35  void (*StateAction)(StateMem* sm, const unsigned load, const bool data_only);
36 
37  void (*AdjustTS)(const int32 delta);
38 
39  // For calculating clock ratios.
40  void (*SetCPUClock)(const int32 master_clock, const int32 cpu_divider);
41 
42  ss_event_handler EventHandler;
43 
44  // A >> 20
45  struct
46  {
47   void (*Read16)(uint32 A, uint16* DB);
48   void (*Write8)(uint32 A, uint16* DB);
49   void (*Write16)(uint32 A, uint16* DB);
50  } CS01_RW[0x30];
51 
52  struct
53  {
54   void (*Read16)(uint32 A, uint16* DB);
55   void (*Write8)(uint32 A, uint16* DB);
56   void (*Write16)(uint32 A, uint16* DB);
57  } CS2M_RW[0x20];
58 
59  void CS01_SetRW8W16(uint32 Astart, uint32 Aend, void (*r16)(uint32 A, uint16* DB), void (*w8)(uint32 A, uint16* DB) = nullptr, void (*w16)(uint32 A, uint16* DB) = nullptr);
60  void CS2M_SetRW8W16(uint8 Ostart, uint8 Oend, void (*r16)(uint32 A, uint16* DB), void (*w8)(uint32 A, uint16* DB) = nullptr, void (*w16)(uint32 A, uint16* DB) = nullptr);
61 };
62 
CART_CS01_Read16_DB(uint32 A,uint16 * DB)63 static INLINE void CART_CS01_Read16_DB(uint32 A, uint16* DB)  { extern CartInfo Cart; Cart.CS01_RW[(size_t)(A >> 20) - (0x02000000 >> 20)].Read16 (A, DB); }
CART_CS01_Write8_DB(uint32 A,uint16 * DB)64 static INLINE void CART_CS01_Write8_DB(uint32 A, uint16* DB)  { extern CartInfo Cart; Cart.CS01_RW[(size_t)(A >> 20) - (0x02000000 >> 20)].Write8 (A, DB); }
CART_CS01_Write16_DB(uint32 A,uint16 * DB)65 static INLINE void CART_CS01_Write16_DB(uint32 A, uint16* DB) { extern CartInfo Cart; Cart.CS01_RW[(size_t)(A >> 20) - (0x02000000 >> 20)].Write16(A, DB); }
66 
CART_CS2_Read16_DB(uint32 A,uint16 * DB)67 static INLINE void CART_CS2_Read16_DB(uint32 A, uint16* DB)  { extern CartInfo Cart; Cart.CS2M_RW[(A >> 1) & 0x1F].Read16 (A, DB); }
CART_CS2_Write8_DB(uint32 A,uint16 * DB)68 static INLINE void CART_CS2_Write8_DB(uint32 A, uint16* DB)  { extern CartInfo Cart; Cart.CS2M_RW[(A >> 1) & 0x1F].Write8 (A, DB); }
CART_CS2_Write16_DB(uint32 A,uint16 * DB)69 static INLINE void CART_CS2_Write16_DB(uint32 A, uint16* DB) { extern CartInfo Cart; Cart.CS2M_RW[(A >> 1) & 0x1F].Write16(A, DB); }
70 
71 enum
72 {
73  CART__RESERVED = -1,
74  CART_NONE = 0,
75  CART_BACKUP_MEM,
76  CART_EXTRAM_1M,
77  CART_EXTRAM_4M,
78 
79  CART_KOF95,
80  CART_ULTRAMAN,
81 
82  CART_AR4MP,
83 
84  CART_CS1RAM_16M,
85 
86  CART_NLMODEM,
87 
88  CART_MDFN_DEBUG
89 };
90 
91 void CART_Init(const int cart_type) MDFN_COLD;
CART_GetEventHandler(void)92 static INLINE ss_event_handler CART_GetEventHandler(void) { extern CartInfo Cart; return Cart.EventHandler; }
CART_AdjustTS(const int32 delta)93 static INLINE void CART_AdjustTS(const int32 delta) { extern CartInfo Cart; Cart.AdjustTS(delta); }
CART_SetCPUClock(const int32 master_clock,const int32 cpu_divider)94 static INLINE void CART_SetCPUClock(const int32 master_clock, const int32 cpu_divider) { extern CartInfo Cart; Cart.SetCPUClock(master_clock, cpu_divider); }
CART_Kill(void)95 static INLINE void CART_Kill(void) { extern CartInfo Cart; if(Cart.Kill) { Cart.Kill(); Cart.Kill = nullptr; } }
CART_StateAction(StateMem * sm,const unsigned load,const bool data_only)96 static INLINE void CART_StateAction(StateMem* sm, const unsigned load, const bool data_only) { extern CartInfo Cart; Cart.StateAction(sm, load, data_only); }
CART_GetNVInfo(const char ** ext,void ** nv_ptr,bool * nv16,uint64 * nv_size)97 static INLINE void CART_GetNVInfo(const char** ext, void** nv_ptr, bool* nv16, uint64* nv_size) { extern CartInfo Cart; Cart.GetNVInfo(ext, nv_ptr, nv16, nv_size); }
CART_GetClearNVDirty(void)98 static INLINE bool CART_GetClearNVDirty(void) { extern CartInfo Cart; return Cart.GetClearNVDirty(); }
CART_Reset(bool powering_up)99 static INLINE void CART_Reset(bool powering_up) { extern CartInfo Cart; Cart.Reset(powering_up); }
100 
101 #endif
102