Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
alexbevi
GitHub Repository: alexbevi/BizHawk
Path: blob/master/lynx/mikie.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
// Mikey class header file //
29
//////////////////////////////////////////////////////////////////////////////
30
// //
31
// This header file provides the interface definition and some of the code //
32
// for the Mikey chip within the Lynx. The most crucial code is the //
33
// Update() function which as you can probably guess updates all of the //
34
// Mikey hardware counters and screen DMA from the prevous time it was //
35
// called. Yes I know how to spell Mikey but I cant be bothered to change //
36
// it everywhere. //
37
// //
38
// K. Wilkins //
39
// August 1997 //
40
// //
41
//////////////////////////////////////////////////////////////////////////////
42
// Revision History: //
43
// ----------------- //
44
// //
45
// 01Aug1997 KW Document header added & class documented. //
46
// //
47
//////////////////////////////////////////////////////////////////////////////
48
49
#ifndef MIKIE_H
50
#define MIKIE_H
51
52
//#include <crtdbg.h>
53
//#define TRACE_MIKIE
54
#include <math.h>
55
56
#ifdef TRACE_MIKIE
57
58
#define TRACE_MIKIE0(msg) _RPT1(_CRT_WARN,"CMikie::"msg" (Time=%012d)\n",gSystemCycleCount)
59
#define TRACE_MIKIE1(msg,arg1) _RPT2(_CRT_WARN,"CMikie::"msg" (Time=%012d)\n",arg1,gSystemCycleCount)
60
#define TRACE_MIKIE2(msg,arg1,arg2) _RPT3(_CRT_WARN,"CMikie::"msg" (Time=%012d)\n",arg1,arg2,gSystemCycleCount)
61
#define TRACE_MIKIE3(msg,arg1,arg2,arg3) _RPT4(_CRT_WARN,"CMikie::"msg" (Time=%012d)\n",arg1,arg2,arg3,gSystemCycleCount)
62
63
#else
64
65
#define TRACE_MIKIE0(msg)
66
#define TRACE_MIKIE1(msg,arg1)
67
#define TRACE_MIKIE2(msg,arg1,arg2)
68
#define TRACE_MIKIE3(msg,arg1,arg2,arg3)
69
70
#endif
71
72
class CSystem;
73
74
#define MIKIE_START 0xfd00
75
#define MIKIE_SIZE 0x100
76
77
//
78
// Define counter types and defines
79
//
80
81
#define CTRL_A_IRQEN 0x80
82
#define CTRL_A_RTD 0x40
83
#define CTRL_A_RELOAD 0x10
84
#define CTRL_A_COUNT 0x08
85
#define CTRL_A_DIVIDE 0x07
86
87
#define CTRL_B_TDONE 0x08
88
#define CTRL_B_LASTCK 0x04
89
#define CTRL_B_CIN 0x02
90
#define CTRL_B_COUT 0x01
91
92
#define LINE_TIMER 0x00
93
#define SCREEN_TIMER 0x02
94
95
#define LINE_WIDTH 160
96
#define LINE_SIZE 80
97
98
#define UART_TX_INACTIVE 0x80000000
99
#define UART_RX_INACTIVE 0x80000000
100
#define UART_BREAK_CODE 0x00008000
101
#define UART_MAX_RX_QUEUE 32
102
#define UART_TX_TIME_PERIOD (11)
103
#define UART_RX_TIME_PERIOD (11)
104
#define UART_RX_NEXT_DELAY (44)
105
106
typedef struct
107
{
108
union
109
{
110
struct
111
{
112
#ifdef MSB_FIRST
113
uint8 unused:4;
114
uint8 Colour:1;
115
uint8 FourColour:1;
116
uint8 Flip:1;
117
uint8 DMAEnable:1;
118
#else
119
120
uint8 DMAEnable:1;
121
uint8 Flip:1;
122
uint8 FourColour:1;
123
uint8 Colour:1;
124
uint8 unused:4;
125
#endif
126
}Bits;
127
uint8 Byte;
128
};
129
}TDISPCTL;
130
131
typedef struct
132
{
133
union
134
{
135
struct
136
{
137
#ifdef MSB_FIRST
138
uint8 unused:8;
139
uint8 unused2:8;
140
uint8 unused3:4;
141
uint8 Blue:4;
142
uint8 Red:4;
143
uint8 Green:4;
144
#else
145
uint8 Green:4;
146
uint8 Red:4;
147
uint8 Blue:4;
148
#endif
149
}Colours;
150
uint32 Index;
151
};
152
}TPALETTE;
153
154
155
//
156
// Emumerated types for possible mikie windows independant modes
157
//
158
enum
159
{
160
MIKIE_BAD_MODE=0,
161
MIKIE_NO_ROTATE,
162
MIKIE_ROTATE_L,
163
MIKIE_ROTATE_R
164
};
165
166
/*
167
enum
168
{
169
MIKIE_PIXEL_FORMAT_8BPP=0,
170
MIKIE_PIXEL_FORMAT_16BPP_555,
171
MIKIE_PIXEL_FORMAT_16BPP_565,
172
MIKIE_PIXEL_FORMAT_24BPP,
173
MIKIE_PIXEL_FORMAT_32BPP,
174
};
175
*/
176
177
#include "sound/Stereo_Buffer.h"
178
179
typedef Blip_Synth<blip_good_quality, 256 * 4> Synth;
180
181
class CMikie : public CLynxBase
182
{
183
public:
184
CMikie(CSystem& parent) MDFN_COLD;
185
~CMikie() MDFN_COLD;
186
187
uint32 startTS;
188
Synth miksynth;
189
Stereo_Buffer mikbuf;
190
191
void Reset() MDFN_COLD;
192
193
uint8 Peek(uint32 addr);
194
void Poke(uint32 addr,uint8 data);
195
uint32 ReadCycle() {return 5;};
196
uint32 WriteCycle() {return 5;};
197
uint32 ObjectSize() {return MIKIE_SIZE;};
198
void PresetForHomebrew();
199
uint32 GetLfsrNext(uint32 current);
200
201
void ComLynxCable(int status);
202
void ComLynxRxData(int data);
203
void ComLynxTxLoopback(int data);
204
void ComLynxTxCallback(void (*function)(int data,uint32 objref),uint32 objref);
205
206
void DisplaySetAttributes();
207
208
void BlowOut();
209
210
uint32 DisplayRenderLine();
211
uint32 DisplayEndOfFrame();
212
213
inline void SetCPUSleep();
214
inline void ClearCPUSleep();
215
216
void CombobulateSound(uint32 teatime);
217
void Update();
218
void CheckWrap();
219
220
uint32 mpDisplayCurrentLine;
221
uint32 framebuffer[SCREEN_WIDTH * SCREEN_HEIGHT];
222
223
template<bool isReader>void SyncState(NewState *ns);
224
225
private:
226
CSystem &mSystem;
227
228
int last_lsample;
229
int last_rsample;
230
231
// Hardware storage
232
233
uint32 mDisplayAddress;
234
uint32 mAudioInputComparator;
235
uint32 mTimerStatusFlags;
236
uint32 mTimerInterruptMask;
237
238
TPALETTE mPalette[16];
239
uint32 mColourMap[4096];
240
241
uint32 mIODAT;
242
uint32 mIODIR;
243
uint32 mIODAT_REST_SIGNAL;
244
245
uint32 mDISPCTL_DMAEnable;
246
uint32 mDISPCTL_Flip;
247
uint32 mDISPCTL_FourColour;
248
uint32 mDISPCTL_Colour;
249
250
uint32 mTIM_0_BKUP;
251
uint32 mTIM_0_ENABLE_RELOAD;
252
uint32 mTIM_0_ENABLE_COUNT;
253
uint32 mTIM_0_LINKING;
254
uint32 mTIM_0_CURRENT;
255
uint32 mTIM_0_TIMER_DONE;
256
uint32 mTIM_0_LAST_CLOCK;
257
uint32 mTIM_0_BORROW_IN;
258
uint32 mTIM_0_BORROW_OUT;
259
uint32 mTIM_0_LAST_LINK_CARRY;
260
uint32 mTIM_0_LAST_COUNT;
261
262
uint32 mTIM_1_BKUP;
263
uint32 mTIM_1_ENABLE_RELOAD;
264
uint32 mTIM_1_ENABLE_COUNT;
265
uint32 mTIM_1_LINKING;
266
uint32 mTIM_1_CURRENT;
267
uint32 mTIM_1_TIMER_DONE;
268
uint32 mTIM_1_LAST_CLOCK;
269
uint32 mTIM_1_BORROW_IN;
270
uint32 mTIM_1_BORROW_OUT;
271
uint32 mTIM_1_LAST_LINK_CARRY;
272
uint32 mTIM_1_LAST_COUNT;
273
274
uint32 mTIM_2_BKUP;
275
uint32 mTIM_2_ENABLE_RELOAD;
276
uint32 mTIM_2_ENABLE_COUNT;
277
uint32 mTIM_2_LINKING;
278
uint32 mTIM_2_CURRENT;
279
uint32 mTIM_2_TIMER_DONE;
280
uint32 mTIM_2_LAST_CLOCK;
281
uint32 mTIM_2_BORROW_IN;
282
uint32 mTIM_2_BORROW_OUT;
283
uint32 mTIM_2_LAST_LINK_CARRY;
284
uint32 mTIM_2_LAST_COUNT;
285
286
uint32 mTIM_3_BKUP;
287
uint32 mTIM_3_ENABLE_RELOAD;
288
uint32 mTIM_3_ENABLE_COUNT;
289
uint32 mTIM_3_LINKING;
290
uint32 mTIM_3_CURRENT;
291
uint32 mTIM_3_TIMER_DONE;
292
uint32 mTIM_3_LAST_CLOCK;
293
uint32 mTIM_3_BORROW_IN;
294
uint32 mTIM_3_BORROW_OUT;
295
uint32 mTIM_3_LAST_LINK_CARRY;
296
uint32 mTIM_3_LAST_COUNT;
297
298
uint32 mTIM_4_BKUP;
299
uint32 mTIM_4_ENABLE_RELOAD;
300
uint32 mTIM_4_ENABLE_COUNT;
301
uint32 mTIM_4_LINKING;
302
uint32 mTIM_4_CURRENT;
303
uint32 mTIM_4_TIMER_DONE;
304
uint32 mTIM_4_LAST_CLOCK;
305
uint32 mTIM_4_BORROW_IN;
306
uint32 mTIM_4_BORROW_OUT;
307
uint32 mTIM_4_LAST_LINK_CARRY;
308
uint32 mTIM_4_LAST_COUNT;
309
310
uint32 mTIM_5_BKUP;
311
uint32 mTIM_5_ENABLE_RELOAD;
312
uint32 mTIM_5_ENABLE_COUNT;
313
uint32 mTIM_5_LINKING;
314
uint32 mTIM_5_CURRENT;
315
uint32 mTIM_5_TIMER_DONE;
316
uint32 mTIM_5_LAST_CLOCK;
317
uint32 mTIM_5_BORROW_IN;
318
uint32 mTIM_5_BORROW_OUT;
319
uint32 mTIM_5_LAST_LINK_CARRY;
320
uint32 mTIM_5_LAST_COUNT;
321
322
uint32 mTIM_6_BKUP;
323
uint32 mTIM_6_ENABLE_RELOAD;
324
uint32 mTIM_6_ENABLE_COUNT;
325
uint32 mTIM_6_LINKING;
326
uint32 mTIM_6_CURRENT;
327
uint32 mTIM_6_TIMER_DONE;
328
uint32 mTIM_6_LAST_CLOCK;
329
uint32 mTIM_6_BORROW_IN;
330
uint32 mTIM_6_BORROW_OUT;
331
uint32 mTIM_6_LAST_LINK_CARRY;
332
uint32 mTIM_6_LAST_COUNT;
333
334
uint32 mTIM_7_BKUP;
335
uint32 mTIM_7_ENABLE_RELOAD;
336
uint32 mTIM_7_ENABLE_COUNT;
337
uint32 mTIM_7_LINKING;
338
uint32 mTIM_7_CURRENT;
339
uint32 mTIM_7_TIMER_DONE;
340
uint32 mTIM_7_LAST_CLOCK;
341
uint32 mTIM_7_BORROW_IN;
342
uint32 mTIM_7_BORROW_OUT;
343
uint32 mTIM_7_LAST_LINK_CARRY;
344
uint32 mTIM_7_LAST_COUNT;
345
346
uint32 mAUDIO_BKUP[4];
347
uint32 mAUDIO_ENABLE_RELOAD[4];
348
uint32 mAUDIO_ENABLE_COUNT[4];
349
uint32 mAUDIO_LINKING[4];
350
uint32 mAUDIO_CURRENT[4];
351
uint32 mAUDIO_TIMER_DONE[4];
352
uint32 mAUDIO_LAST_CLOCK[4];
353
uint32 mAUDIO_BORROW_IN[4];
354
uint32 mAUDIO_BORROW_OUT[4];
355
uint32 mAUDIO_LAST_LINK_CARRY[4];
356
uint32 mAUDIO_LAST_COUNT[4];
357
int8 mAUDIO_VOLUME[4];
358
uint32 mAUDIO_INTEGRATE_ENABLE[4];
359
uint32 mAUDIO_WAVESHAPER[4];
360
361
int8 mAUDIO_OUTPUT[4];
362
uint8 mAUDIO_ATTEN[4];
363
uint32 mSTEREO;
364
uint32 mPAN;
365
366
//
367
// Serial related variables
368
//
369
uint32 mUART_RX_IRQ_ENABLE;
370
uint32 mUART_TX_IRQ_ENABLE;
371
372
uint32 mUART_RX_COUNTDOWN;
373
uint32 mUART_TX_COUNTDOWN;
374
375
uint32 mUART_SENDBREAK;
376
uint32 mUART_TX_DATA;
377
uint32 mUART_RX_DATA;
378
uint32 mUART_RX_READY;
379
380
uint32 mUART_PARITY_ENABLE;
381
uint32 mUART_PARITY_EVEN;
382
383
int mUART_CABLE_PRESENT;
384
void (*mpUART_TX_CALLBACK)(int data,uint32 objref);
385
uint32 mUART_TX_CALLBACK_OBJECT;
386
387
int mUART_Rx_input_queue[UART_MAX_RX_QUEUE];
388
unsigned int mUART_Rx_input_ptr;
389
unsigned int mUART_Rx_output_ptr;
390
int mUART_Rx_waiting;
391
int mUART_Rx_framing_error;
392
int mUART_Rx_overun_error;
393
394
//
395
// Screen related
396
//
397
398
uint8 *mpRamPointer;
399
uint32 mLynxLine;
400
uint32 mLynxLineDMACounter;
401
uint32 mLynxAddr;
402
403
void CopyLineSurface();
404
void BlankLineSurface();
405
};
406
407
408
#endif
409
410
411