-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSystem.h
More file actions
339 lines (280 loc) · 10.9 KB
/
Copy pathSystem.h
File metadata and controls
339 lines (280 loc) · 10.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
//
// Copyright (c) 2004 K. Wilkins
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from
// the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it
// freely, subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented; you must not
// claim that you wrote the original software. If you use this software
// in a product, an acknowledgment in the product documentation would be
// appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such, and must not
// be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
//////////////////////////////////////////////////////////////////////////////
// Handy - An Atari Lynx Emulator //
// Copyright (c) 1996,1997 //
// K. Wilkins //
//////////////////////////////////////////////////////////////////////////////
// System object header file //
//////////////////////////////////////////////////////////////////////////////
// //
// This header file provides the interface definition and inline code for //
// the system object, this object if what binds together all of the Handy //
// hardware enmulation objects, its the glue that holds the system together //
// //
// K. Wilkins //
// August 1997 //
// //
//////////////////////////////////////////////////////////////////////////////
// Revision History: //
// ----------------- //
// //
// 01Aug1997 KW Document header added & class documented. //
// //
//////////////////////////////////////////////////////////////////////////////
#ifndef SYSTEM_H
#define SYSTEM_H
#ifdef _WINDOWS
#pragma inline_depth (255)
#pragma inline_recursion (on)
#endif
#ifdef _LYNXDBG
//#ifdef _DEBUG
//#define new DEBUG_NEW
//#undef THIS_FILE
//static char THIS_FILE[] = __FILE__;
//#endif
#endif
#include "Machine.h"
#ifndef HANDY_AUDIO_SAMPLE_FREQ
#define HANDY_AUDIO_SAMPLE_FREQ 22050
#endif
#define HANDY_SYSTEM_FREQ 16000000
#define HANDY_TIMER_FREQ 20
#define HANDY_AUDIO_SAMPLE_PERIOD (HANDY_SYSTEM_FREQ/HANDY_AUDIO_SAMPLE_FREQ)
#define HANDY_AUDIO_WAVESHAPER_TABLE_LENGTH 0x200000
#ifndef HANDY_AUDIO_BUFFER_SIZE
#ifdef LINUX_PATCH
#define HANDY_AUDIO_BUFFER_SIZE 4096 // Needed forSDL
#else // LINUX_PATCH
#define HANDY_AUDIO_BUFFER_SIZE (HANDY_AUDIO_SAMPLE_FREQ/4)
#endif // else LINUX_PATCH
#endif // HANDY_AUDIO_BUFFER_SIZE
#ifndef __min
#define __min(x, y) (((x) < (y)) ? (x) : (y))
#endif
#ifndef __max
#define __max(x, y) (((x) > (y)) ? (x) : (y))
#endif
#define HANDY_FILETYPE_LNX 0
#define HANDY_FILETYPE_HOMEBREW 1
#define HANDY_FILETYPE_SNAPSHOT 2
#define HANDY_FILETYPE_ILLEGAL 3
#define HANDY_SCREEN_WIDTH 160
#define HANDY_SCREEN_HEIGHT 102
//
// Define the global variable list
//
#ifdef SYSTEM_CPP
ULONG gSystemCycleCount=0;
ULONG gNextTimerEvent=0;
ULONG gCPUWakeupTime=0;
ULONG gIRQEntryCycle=0;
ULONG gCPUBootAddress=0;
ULONG gBreakpointHit=FALSE;
ULONG gSingleStepMode=FALSE;
ULONG gSingleStepModeSprites=FALSE;
ULONG gSystemIRQ=FALSE;
ULONG gSystemNMI=FALSE;
ULONG gSystemCPUSleep=FALSE;
ULONG gSystemCPUSleep_Saved=FALSE;
ULONG gSystemHalt=FALSE;
ULONG gThrottleMaxPercentage=100;
ULONG gThrottleLastTimerCount=0;
ULONG gThrottleNextCycleCheckpoint=0;
volatile ULONG gTimerCount=0;
ULONG gAudioEnabled=FALSE;
UBYTE gAudioBuffer[HANDY_AUDIO_BUFFER_SIZE];
ULONG gAudioBufferPointer=0;
ULONG gAudioLastUpdateCycle=0;
CErrorInterface *gError=NULL;
#else
extern ULONG gSystemCycleCount;
extern ULONG gNextTimerEvent;
extern ULONG gCPUWakeupTime;
extern ULONG gIRQEntryCycle;
extern ULONG gCPUBootAddress;
extern ULONG gBreakpointHit;
extern ULONG gSingleStepMode;
extern ULONG gSingleStepModeSprites;
extern ULONG gSystemIRQ;
extern ULONG gSystemNMI;
extern ULONG gSystemCPUSleep;
extern ULONG gSystemCPUSleep_Saved;
extern ULONG gSystemHalt;
extern ULONG gThrottleMaxPercentage;
extern ULONG gThrottleLastTimerCount;
extern ULONG gThrottleNextCycleCheckpoint;
extern volatile ULONG gTimerCount;
extern ULONG gAudioEnabled;
extern UBYTE gAudioBuffer[HANDY_AUDIO_BUFFER_SIZE];
extern ULONG gAudioBufferPointer;
extern ULONG gAudioLastUpdateCycle;
extern CErrorInterface *gError;
#endif
typedef struct lssfile
{
UBYTE *memptr;
ULONG index;
ULONG index_limit;
} LSS_FILE;
int lss_read(void* dest,int varsize, int varcount,LSS_FILE *fp);
//
// Define the interfaces before we start pulling in the classes
// as many classes look for articles from the interfaces to
// allow compilation
#include "sysbase.h"
class CSystem;
//
// Now pull in the parts that build the system
//
#include "lynxbase.h"
#include "Memfault.h"
#include "Ram.h"
#include "Rom.h"
#include "Memmap.h"
#include "Cart.h"
#include "Susie.h"
#include "Mikie.h"
#include "C65c02.h"
#define TOP_START 0xfc00
#define TOP_MASK 0x03ff
#define TOP_SIZE 0x400
#define SYSTEM_SIZE 65536
#define LSS_VERSION_OLD "LSS2"
#define LSS_VERSION "LSS3"
class CSystem : public CSystemBase
{
public:
CSystem(char* gamefile,char* romfile);
~CSystem();
private:
bool ContextLoad(UBYTE *filememory, ULONG filesize);
public:
void Reset(void);
bool ContextSave(char *context);
bool ContextSave(FILE *fp);
bool ContextLoad(char *context);
bool ContextLoad(FILE *fp);
bool IsZip(char *filename);
inline void Update(void)
{
//
// Only update if there is a predicted timer event
//
if(gSystemCycleCount>=gNextTimerEvent)
{
mMikie->Update();
}
//
// Step the processor through 1 instruction
//
mCpu->Update();
#ifdef _LYNXDBG
// Check breakpoint
static ULONG lastcycle=0;
if(lastcycle<mCycleCountBreakpoint && gSystemCycleCount>=mCycleCountBreakpoint) gBreakpointHit=TRUE;
lastcycle=gSystemCycleCount;
// Check single step mode
if(gSingleStepMode) gBreakpointHit=TRUE;
#endif
//
// If the CPU is asleep then skip to the next timer event
//
if(gSystemCPUSleep)
{
gSystemCycleCount=gNextTimerEvent;
}
}
//
// We MUST have separate CPU & RAM peek & poke handlers as all CPU accesses must
// go thru the address generator at $FFF9
//
// BUT, Mikie video refresh & Susie see the whole system as RAM
//
// Complete and utter wankers, its taken me 1 week to find the 2 lines
// in all the documentation that mention this fact, the mother of all
// bugs has been found and FIXED.......
//
// CPU
//
inline void Poke_CPU(ULONG addr, UBYTE data) { mMemoryHandlers[addr]->Poke(addr,data);};
inline UBYTE Peek_CPU(ULONG addr) { return mMemoryHandlers[addr]->Peek(addr);};
inline void PokeW_CPU(ULONG addr,UWORD data) { mMemoryHandlers[addr]->Poke(addr,data&0xff);addr++;mMemoryHandlers[addr]->Poke(addr,data>>8);};
inline UWORD PeekW_CPU(ULONG addr) {return ((mMemoryHandlers[addr]->Peek(addr))+(mMemoryHandlers[addr]->Peek(addr+1)<<8));};
//
// RAM
//
inline void Poke_RAM(ULONG addr, UBYTE data) { mRam->Poke(addr,data);};
inline UBYTE Peek_RAM(ULONG addr) { return mRam->Peek(addr);};
inline void PokeW_RAM(ULONG addr,UWORD data) { mRam->Poke(addr,data&0xff);addr++;mRam->Poke(addr,data>>8);};
inline UWORD PeekW_RAM(ULONG addr) {return ((mRam->Peek(addr))+(mRam->Peek(addr+1)<<8));};
// High level cart access for debug etc
inline void Poke_CART(ULONG addr, UBYTE data) {mCart->Poke(addr,data);};
inline UBYTE Peek_CART(ULONG addr) {return mCart->Peek(addr);};
inline void CartBank(EMMODE bank) {mCart->BankSelect(bank);};
inline ULONG CartSize(void) {return mCart->ObjectSize();};
inline const char* CartGetName(void) { return mCart->CartGetName();};
inline const char* CartGetManufacturer(void) { return mCart->CartGetManufacturer();};
inline ULONG CartGetRotate(void) {return mCart->CartGetRotate();};
// Low level cart access for Suzy, Mikey
inline void Poke_CARTB0(UBYTE data) {mCart->Poke0(data);};
inline void Poke_CARTB1(UBYTE data) {mCart->Poke1(data);};
inline UBYTE Peek_CARTB0(void) {return mCart->Peek0();}
inline UBYTE Peek_CARTB1(void) {return mCart->Peek1();}
inline void CartAddressStrobe(bool strobe) {mCart->CartAddressStrobe(strobe);};
inline void CartAddressData(bool data) {mCart->CartAddressData(data);};
// Low level CPU access
void SetRegs(C6502_REGS ®s) {mCpu->SetRegs(regs);};
void GetRegs(C6502_REGS ®s) {mCpu->GetRegs(regs);};
// Mikey system interfacing
void DisplaySetAttributes(ULONG Rotate,ULONG Format,ULONG Pitch,UBYTE* (*DisplayCallback)(ULONG objref),ULONG objref) { mMikie->DisplaySetAttributes(Rotate,Format,Pitch,DisplayCallback,objref); };
ULONG DisplayGetRotation() { return mMikie->DisplayGetRotation(); }
void ComLynxCable(int status) { mMikie->ComLynxCable(status); };
void ComLynxRxData(int data) { mMikie->ComLynxRxData(data); };
void ComLynxTxCallback(void (*function)(int data,ULONG objref),ULONG objref) { mMikie->ComLynxTxCallback(function,objref); };
// Suzy system interfacing
ULONG PaintSprites(void) {return mSusie->PaintSprites();};
// Miscellaneous
void SetButtonData(ULONG data) {mSusie->SetButtonData(data);};
ULONG GetButtonData(void) {return mSusie->GetButtonData();};
void SetCycleBreakpoint(ULONG breakpoint) {mCycleCountBreakpoint=breakpoint;};
UBYTE* GetRamPointer(void) {return mRam->GetRamPointer();};
#ifdef _LYNXDBG
void DebugTrace(int address);
void DebugSetCallback(void (*function)(ULONG objref, char *message),ULONG objref);
void (*mpDebugCallback)(ULONG objref, char *message);
ULONG mDebugCallbackObject;
#endif
public:
ULONG mCycleCountBreakpoint;
CLynxBase *mMemoryHandlers[SYSTEM_SIZE];
CCart *mCart;
CRom *mRom;
CMemMap *mMemMap;
CRam *mRam;
C65C02 *mCpu;
CMikie *mMikie;
CSusie *mSusie;
ULONG mFileType;
};
#endif