Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
alexbevi
GitHub Repository: alexbevi/BizHawk
Path: blob/master/lynx/susie.h
2 views
1
//
2
// Copyright (c) 2004 K. Wilkins
3
//
4
// This software is provided 'as-is', without any express or implied warranty.
5
// In no event will the authors be held liable for any damages arising from
6
// the use of this software.
7
//
8
// Permission is granted to anyone to use this software for any purpose,
9
// including commercial applications, and to alter it and redistribute it
10
// freely, subject to the following restrictions:
11
//
12
// 1. The origin of this software must not be misrepresented; you must not
13
// claim that you wrote the original software. If you use this software
14
// in a product, an acknowledgment in the product documentation would be
15
// appreciated but is not required.
16
//
17
// 2. Altered source versions must be plainly marked as such, and must not
18
// be misrepresented as being the original software.
19
//
20
// 3. This notice may not be removed or altered from any source distribution.
21
//
22
23
//////////////////////////////////////////////////////////////////////////////
24
// Handy - An Atari Lynx Emulator //
25
// Copyright (c) 1996,1997 //
26
// K. Wilkins //
27
//////////////////////////////////////////////////////////////////////////////
28
// Susie object header file //
29
//////////////////////////////////////////////////////////////////////////////
30
// //
31
// This header file provides the interface definition for the Suzy class //
32
// which provides math and sprite support to the emulator //
33
// //
34
// K. Wilkins //
35
// August 1997 //
36
// //
37
//////////////////////////////////////////////////////////////////////////////
38
// Revision History: //
39
// ----------------- //
40
// //
41
// 01Aug1997 KW Document header added & class documented. //
42
// //
43
//////////////////////////////////////////////////////////////////////////////
44
45
#ifndef SUSIE_H
46
#define SUSIE_H
47
48
#ifdef TRACE_SUSIE
49
50
#define TRACE_SUSIE0(msg) _RPT1(_CRT_WARN,"CSusie::"msg" (Time=%012d)\n",gSystemCycleCount)
51
#define TRACE_SUSIE1(msg,arg1) _RPT2(_CRT_WARN,"CSusie::"msg" (Time=%012d)\n",arg1,gSystemCycleCount)
52
#define TRACE_SUSIE2(msg,arg1,arg2) _RPT3(_CRT_WARN,"CSusie::"msg" (Time=%012d)\n",arg1,arg2,gSystemCycleCount)
53
#define TRACE_SUSIE3(msg,arg1,arg2,arg3) _RPT4(_CRT_WARN,"CSusie::"msg" (Time=%012d)\n",arg1,arg2,arg3,gSystemCycleCount)
54
55
#else
56
57
#define TRACE_SUSIE0(msg)
58
#define TRACE_SUSIE1(msg,arg1)
59
#define TRACE_SUSIE2(msg,arg1,arg2)
60
#define TRACE_SUSIE3(msg,arg1,arg2,arg3)
61
62
#endif
63
64
class CSystem;
65
66
#define SUSIE_START 0xfc00
67
#define SUSIE_SIZE 0x100
68
69
#define SCREEN_WIDTH 160
70
#define SCREEN_HEIGHT 102
71
72
#define LINE_END 0x80
73
74
//
75
// Define button values
76
//
77
78
#define BUTTON_A 0x0001
79
#define BUTTON_B 0x0002
80
#define BUTTON_OPT2 0x0004
81
#define BUTTON_OPT1 0x0008
82
#define BUTTON_LEFT 0x0010
83
#define BUTTON_RIGHT 0x0020
84
#define BUTTON_UP 0x0040
85
#define BUTTON_DOWN 0x0080
86
#define BUTTON_PAUSE 0x0100
87
88
89
enum {line_error=0,line_abs_literal,line_literal,line_packed};
90
enum {math_finished=0,math_divide,math_multiply,math_init_divide,math_init_multiply};
91
92
enum {sprite_background_shadow=0,
93
sprite_background_noncollide,
94
sprite_boundary_shadow,
95
sprite_boundary,
96
sprite_normal,
97
sprite_noncollide,
98
sprite_xor_shadow,
99
sprite_shadow};
100
101
typedef struct
102
{
103
union
104
{
105
struct
106
{
107
#ifdef MSB_FIRST
108
uint8 Fc1:1;
109
uint8 Fc2:1;
110
uint8 Fc3:1;
111
uint8 reserved:1;
112
uint8 Ac1:1;
113
uint8 Ac2:1;
114
uint8 Ac3:1;
115
uint8 Ac4:1;
116
#else
117
uint8 Ac4:1;
118
uint8 Ac3:1;
119
uint8 Ac2:1;
120
uint8 Ac1:1;
121
uint8 reserved:1;
122
uint8 Fc3:1;
123
uint8 Fc2:1;
124
uint8 Fc1:1;
125
#endif
126
}Bits;
127
uint8 Byte;
128
};
129
}TSPRINIT;
130
131
typedef struct
132
{
133
union
134
{
135
struct
136
{
137
#ifdef MSB_FIRST
138
uint8 Up:1;
139
uint8 Down:1;
140
uint8 Left:1;
141
uint8 Right:1;
142
uint8 Option1:1;
143
uint8 Option2:1;
144
uint8 Inside:1;
145
uint8 Outside:1;
146
#else
147
uint8 Outside:1;
148
uint8 Inside:1;
149
uint8 Option2:1;
150
uint8 Option1:1;
151
uint8 Right:1;
152
uint8 Left:1;
153
uint8 Down:1;
154
uint8 Up:1;
155
#endif
156
}Bits;
157
uint8 Byte;
158
};
159
}TJOYSTICK;
160
161
typedef struct
162
{
163
union
164
{
165
struct
166
{
167
#ifdef MSB_FIRST
168
uint8 spare:5;
169
uint8 Cart1IO:1;
170
uint8 Cart0IO:1;
171
uint8 Pause:1;
172
#else
173
uint8 Pause:1;
174
uint8 Cart0IO:1;
175
uint8 Cart1IO:1;
176
uint8 spare:5;
177
#endif
178
}Bits;
179
uint8 Byte;
180
};
181
}TSWITCHES;
182
183
typedef struct
184
{
185
union
186
{
187
struct
188
{
189
#ifdef MSB_FIRST
190
uint8 A;
191
uint8 B;
192
uint8 C;
193
uint8 D;
194
#else
195
uint8 D;
196
uint8 C;
197
uint8 B;
198
uint8 A;
199
#endif
200
}Bytes;
201
struct
202
{
203
#ifdef MSB_FIRST
204
uint16 AB;
205
uint16 CD;
206
#else
207
uint16 CD;
208
uint16 AB;
209
#endif
210
}Words;
211
uint32 Long;
212
};
213
}TMATHABCD;
214
215
typedef struct
216
{
217
union
218
{
219
struct
220
{
221
#ifdef MSB_FIRST
222
uint8 E;
223
uint8 F;
224
uint8 G;
225
uint8 H;
226
#else
227
uint8 H;
228
uint8 G;
229
uint8 F;
230
uint8 E;
231
#endif
232
}Bytes;
233
struct
234
{
235
#ifdef MSB_FIRST
236
uint16 EF;
237
uint16 GH;
238
#else
239
uint16 GH;
240
uint16 EF;
241
#endif
242
}Words;
243
uint32 Long;
244
};
245
}TMATHEFGH;
246
247
typedef struct
248
{
249
union
250
{
251
struct
252
{
253
#ifdef MSB_FIRST
254
uint8 J;
255
uint8 K;
256
uint8 L;
257
uint8 M;
258
#else
259
uint8 M;
260
uint8 L;
261
uint8 K;
262
uint8 J;
263
#endif
264
}Bytes;
265
struct
266
{
267
#ifdef MSB_FIRST
268
uint16 JK;
269
uint16 LM;
270
#else
271
uint16 LM;
272
uint16 JK;
273
#endif
274
}Words;
275
uint32 Long;
276
};
277
}TMATHJKLM;
278
279
typedef struct
280
{
281
union
282
{
283
struct
284
{
285
#ifdef MSB_FIRST
286
uint8 xx2;
287
uint8 xx1;
288
uint8 N;
289
uint8 P;
290
#else
291
uint8 P;
292
uint8 N;
293
uint8 xx1;
294
uint8 xx2;
295
#endif
296
}Bytes;
297
struct
298
{
299
#ifdef MSB_FIRST
300
uint16 xx1;
301
uint16 NP;
302
#else
303
uint16 NP;
304
uint16 xx1;
305
#endif
306
}Words;
307
uint32 Long;
308
};
309
}TMATHNP;
310
311
312
class CSusie : public CLynxBase
313
{
314
public:
315
CSusie(CSystem& parent) MDFN_COLD;
316
~CSusie() MDFN_COLD;
317
318
void Reset(void) MDFN_COLD;
319
320
uint8 Peek(uint32 addr);
321
void Poke(uint32 addr,uint8 data);
322
uint32 ReadCycle(void) {return 9;};
323
uint32 WriteCycle(void) {return 5;};
324
uint32 ObjectSize(void) {return SUSIE_SIZE;};
325
326
void SetButtonData(uint32 data) {mJOYSTICK.Byte=(uint8)data;mSWITCHES.Byte=(uint8)(data>>8);};
327
// uint32 GetButtonData(void) {return mJOYSTICK.Byte+(mSWITCHES.Byte<<8);};
328
329
uint32 PaintSprites(void);
330
bool lagged; // set to false whenever joystick/switches are read
331
332
template<bool isReader>void SyncState(NewState *ns);
333
334
private:
335
void DoMathDivide(void);
336
void DoMathMultiply(void);
337
uint32 LineInit(uint32 voff);
338
uint32 LineGetPixel(void);
339
uint32 LineGetBits(uint32 bits);
340
341
void ProcessPixel(uint32 hoff,uint32 pixel);
342
void WritePixel(uint32 hoff,uint32 pixel);
343
uint32 ReadPixel(uint32 hoff);
344
void WriteCollision(uint32 hoff,uint32 pixel);
345
uint32 ReadCollision(uint32 hoff);
346
347
private:
348
CSystem& mSystem;
349
350
uint32 cycles_used;
351
352
Uuint16 mTMPADR; // ENG
353
Uuint16 mTILTACUM; // ENG
354
Uuint16 mHOFF; // CPU
355
Uuint16 mVOFF; // CPU
356
Uuint16 mVIDBAS; // CPU
357
Uuint16 mCOLLBAS; // CPU
358
Uuint16 mVIDADR; // ENG
359
Uuint16 mCOLLADR; // ENG
360
Uuint16 mSCBNEXT; // SCB
361
Uuint16 mSPRDLINE; // SCB
362
Uuint16 mHPOSSTRT; // SCB
363
Uuint16 mVPOSSTRT; // SCB
364
Uuint16 mSPRHSIZ; // SCB
365
Uuint16 mSPRVSIZ; // SCB
366
Uuint16 mSTRETCH; // ENG
367
Uuint16 mTILT; // ENG
368
Uuint16 mSPRDOFF; // ENG
369
Uuint16 mSPRVPOS; // ENG
370
Uuint16 mCOLLOFF; // CPU
371
Uuint16 mVSIZACUM; // ENG
372
Uuint16 mHSIZACUM; // K.s creation
373
Uuint16 mHSIZOFF; // CPU
374
Uuint16 mVSIZOFF; // CPU
375
Uuint16 mSCBADR; // ENG
376
Uuint16 mPROCADR; // ENG
377
378
TMATHABCD mMATHABCD; // ENG
379
TMATHEFGH mMATHEFGH; // ENG
380
TMATHJKLM mMATHJKLM; // ENG
381
TMATHNP mMATHNP; // ENG
382
int mMATHAB_sign;
383
int mMATHCD_sign;
384
int mMATHEFGH_sign;
385
386
int mSPRCTL0_Type; // SCB
387
int mSPRCTL0_Vflip;
388
int mSPRCTL0_Hflip;
389
int mSPRCTL0_PixelBits;
390
391
int mSPRCTL1_StartLeft; // SCB
392
int mSPRCTL1_StartUp;
393
int mSPRCTL1_SkipSprite;
394
int mSPRCTL1_ReloadPalette;
395
int mSPRCTL1_ReloadDepth;
396
int mSPRCTL1_Sizing;
397
int mSPRCTL1_Literal;
398
399
int mSPRCOLL_Number; //CPU
400
int mSPRCOLL_Collide;
401
402
int mSPRSYS_StopOnCurrent; //CPU
403
int mSPRSYS_LeftHand;
404
int mSPRSYS_VStretch;
405
int mSPRSYS_NoCollide;
406
int mSPRSYS_Accumulate;
407
int mSPRSYS_SignedMath;
408
int mSPRSYS_Status;
409
int mSPRSYS_UnsafeAccess;
410
int mSPRSYS_LastCarry;
411
int mSPRSYS_Mathbit;
412
int mSPRSYS_MathInProgress;
413
414
uint32 mSUZYBUSEN; // CPU
415
416
TSPRINIT mSPRINIT; // CPU
417
418
uint32 mSPRGO; // CPU
419
int mEVERON;
420
421
uint8 mPenIndex[16]; // SCB
422
423
// Line rendering related variables
424
425
uint32 mLineType;
426
uint32 mLineShiftRegCount;
427
uint32 mLineShiftReg;
428
uint32 mLineRepeatCount;
429
uint32 mLinePixel;
430
uint32 mLinePacketBitsLeft;
431
432
int mCollision;
433
434
uint8 *mRamPointer;
435
436
uint32 mLineBaseAddress;
437
uint32 mLineCollisionAddress;
438
439
int hquadoff, vquadoff;
440
441
// Joystick switches
442
443
TJOYSTICK mJOYSTICK;
444
TSWITCHES mSWITCHES;
445
};
446
447
#endif
448
449
450