more properly handling new haa semantics
[drnoksnes] / memmap.h
1 /*
2  * Snes9x - Portable Super Nintendo Entertainment System (TM) emulator.
3  *
4  * (c) Copyright 1996 - 2001 Gary Henderson (gary.henderson@ntlworld.com) and
5  *                           Jerremy Koot (jkoot@snes9x.com)
6  *
7  * Super FX C emulator code 
8  * (c) Copyright 1997 - 1999 Ivar (ivar@snes9x.com) and
9  *                           Gary Henderson.
10  * Super FX assembler emulator code (c) Copyright 1998 zsKnight and _Demo_.
11  *
12  * DSP1 emulator code (c) Copyright 1998 Ivar, _Demo_ and Gary Henderson.
13  * C4 asm and some C emulation code (c) Copyright 2000 zsKnight and _Demo_.
14  * C4 C code (c) Copyright 2001 Gary Henderson (gary.henderson@ntlworld.com).
15  *
16  * DOS port code contains the works of other authors. See headers in
17  * individual files.
18  *
19  * Snes9x homepage: http://www.snes9x.com
20  *
21  * Permission to use, copy, modify and distribute Snes9x in both binary and
22  * source form, for non-commercial purposes, is hereby granted without fee,
23  * providing that this license information and copyright notice appear with
24  * all copies and any derived work.
25  *
26  * This software is provided 'as-is', without any express or implied
27  * warranty. In no event shall the authors be held liable for any damages
28  * arising from the use of this software.
29  *
30  * Snes9x is freeware for PERSONAL USE only. Commercial users should
31  * seek permission of the copyright holders first. Commercial use includes
32  * charging money for Snes9x or software derived from Snes9x.
33  *
34  * The copyright holders request that bug fixes and improvements to the code
35  * should be forwarded to them so everyone can benefit from the modifications
36  * in future versions.
37  *
38  * Super NES and Super Nintendo Entertainment System are trademarks of
39  * Nintendo Co., Limited and its subsidiary companies.
40  */
41 #ifndef _MEMMAP_H_
42 #define _MEMMAP_H_
43
44 #include "snes9x.h"
45
46 #ifdef FAST_LSB_WORD_ACCESS
47 #define READ_WORD(s) (*(uint16 *) (s))
48 #define READ_DWORD(s) (*(uint32 *) (s))
49 #define WRITE_WORD(s, d) (*(uint16 *) (s) = (d)
50 #define WRITE_DWORD(s, d) (*(uint32 *) (s) = (d)
51 #else
52 #define READ_WORD(s) ( *(uint8 *) (s) |\
53                       (*((uint8 *) (s) + 1) << 8))
54 #define READ_DWORD(s) ( *(uint8 *) (s) |\
55                        (*((uint8 *) (s) + 1) << 8) |\
56                        (*((uint8 *) (s) + 2) << 16) |\
57                        (*((uint8 *) (s) + 3) << 24))
58 #define WRITE_WORD(s, d) *(uint8 *) (s) = (d), \
59                          *((uint8 *) (s) + 1) = (d) >> 8
60 #define WRITE_DWORD(s, d) *(uint8 *) (s) = (uint8) (d), \
61                           *((uint8 *) (s) + 1) = (uint8) ((d) >> 8),\
62                           *((uint8 *) (s) + 2) = (uint8) ((d) >> 16),\
63                           *((uint8 *) (s) + 3) = (uint8) ((d) >> 24)
64 #define WRITE_3WORD(s, d) *(uint8 *) (s) = (uint8) (d), \
65                           *((uint8 *) (s) + 1) = (uint8) ((d) >> 8),\
66                           *((uint8 *) (s) + 2) = (uint8) ((d) >> 16)
67 #define READ_3WORD(s) ( *(uint8 *) (s) |\
68                        (*((uint8 *) (s) + 1) << 8) |\
69                        (*((uint8 *) (s) + 2) << 16))
70                           
71 #endif
72
73 #define MEMMAP_BLOCK_SIZE (0x1000)
74 #define MEMMAP_NUM_BLOCKS (0x1000000 / MEMMAP_BLOCK_SIZE)
75 #define MEMMAP_BLOCKS_PER_BANK (0x10000 / MEMMAP_BLOCK_SIZE)
76 #define MEMMAP_SHIFT 12
77 #define MEMMAP_MASK (MEMMAP_BLOCK_SIZE - 1)
78 #define MEMMAP_MAX_SDD1_LOGGED_ENTRIES (0x10000 / 8)
79
80 class CMemory {
81 public:
82     bool8_32 LoadROM (const char *);
83     void  InitROM (bool8_32);
84     bool8_32 LoadSRAM (const char *);
85     bool8_32 SaveSRAM (const char *);
86     bool8_32 Init ();
87     void  Deinit ();
88     void  FreeSDD1Data ();
89     
90     void WriteProtectROM ();
91     void FixROMSpeed ();
92     void MapRAM ();
93     void MapExtraRAM ();
94     char *Safe (const char *);
95     
96     void LoROMMap ();
97     void LoROM24MBSMap ();
98     void SRAM512KLoROMMap ();
99     void SRAM1024KLoROMMap ();
100     void SufamiTurboLoROMMap ();
101     void HiROMMap ();
102     void SuperFXROMMap ();
103     void TalesROMMap (bool8_32);
104     void AlphaROMMap ();
105     void SA1ROMMap ();
106     void BSHiROMMap ();
107     bool8_32 AllASCII (uint8 *b, int size);
108     int  ScoreHiROM (bool8_32 skip_header);
109     int  ScoreLoROM (bool8_32 skip_header);
110     void ApplyROMFixes ();
111     void CheckForIPSPatch (const char *rom_filename, bool8_32 header,
112                            int32 &rom_size);
113     
114     const char *TVStandard ();
115     const char *Speed ();
116     const char *StaticRAMSize ();
117     const char *MapType ();
118     const char *MapMode ();
119     const char *KartContents ();
120     const char *Size ();
121     const char *Headers ();
122     const char *ROMID ();
123     const char *CompanyID ();
124     
125     enum {
126         MAP_PPU, MAP_CPU, MAP_DSP, MAP_LOROM_SRAM, MAP_HIROM_SRAM,
127         MAP_NONE, MAP_DEBUG, MAP_C4, MAP_BWRAM, MAP_BWRAM_BITMAP,
128         MAP_BWRAM_BITMAP2, MAP_SA1RAM, MAP_LAST
129     };
130     enum { MAX_ROM_SIZE = 0x600000 };
131     
132     uint8 *RAM;
133     uint8 *ROM;
134     uint8 *VRAM;
135     uint8 *SRAM;
136     uint8 *BWRAM;
137     uint8 *FillRAM;
138     uint8 *C4RAM;
139     bool8_32 HiROM;
140     bool8_32 LoROM;
141     uint16 SRAMMask;
142     uint8 SRAMSize;
143     uint8 *Map [MEMMAP_NUM_BLOCKS];
144     uint8 *WriteMap [MEMMAP_NUM_BLOCKS];
145     uint8 MemorySpeed [MEMMAP_NUM_BLOCKS];
146     uint8 BlockIsRAM [MEMMAP_NUM_BLOCKS];
147     uint8 BlockIsROM [MEMMAP_NUM_BLOCKS];
148     char  ROMName [ROM_NAME_LEN];
149     char  ROMId [5];
150     char  CompanyId [3];
151     uint8 ROMSpeed;
152     uint8 ROMType;
153     uint8 ROMSize;
154     int32 ROMFramesPerSecond;
155     int32 HeaderCount;
156     uint32 CalculatedSize;
157     uint32 CalculatedChecksum;
158     uint32 ROMChecksum;
159     uint32 ROMComplementChecksum;
160     uint8  *SDD1Index;
161     uint8  *SDD1Data;
162     uint32 SDD1Entries;
163     uint32 SDD1LoggedDataCountPrev;
164     uint32 SDD1LoggedDataCount;
165     uint8  SDD1LoggedData [MEMMAP_MAX_SDD1_LOGGED_ENTRIES];
166 #ifndef _SNESPPC
167     char ROMFilename [_MAX_PATH];
168 #else
169     char ROMFilename [1024];
170 #endif
171 };
172
173 START_EXTERN_C
174 extern CMemory Memory;
175 extern uint8 *SRAM;
176 extern uint8 *ROM;
177 extern uint8 *RegRAM;
178 void S9xDeinterleaveMode2 ();
179 void S9xSaveSRAM(void);
180 void S9xAutoSaveSRAM();
181 END_EXTERN_C
182
183 #ifdef NO_INLINE_SET_GET
184 uint8 S9xGetByte (uint32 Address);
185 uint16 S9xGetWord (uint32 Address);
186 void S9xSetByte (uint8 Byte, uint32 Address);
187 void S9xSetWord (uint16 Byte, uint32 Address);
188 void S9xSetPCBase (uint32 Address);
189 uint8 *S9xGetMemPointer (uint32 Address);
190 uint8 *GetBasePointer (uint32 Address);
191 #else
192 #include "getset.h"
193 #endif
194
195 #endif // _MEMMAP_H_