-
Notifications
You must be signed in to change notification settings - Fork 1
/
cap32.h
452 lines (405 loc) · 12.3 KB
/
cap32.h
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
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
/* Caprice32 - Amstrad CPC Emulator
(c) Copyright 1997-2005 Ulrich Doewich
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef CAP32_H
#define CAP32_H
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
//#define DEBUG
//#define DEBUG_CRTC
//#define DEBUG_FDC
//#define DEBUG_GA
//#define DEBUG_NO_VIDEO
//#define DEBUG_TAPE
//#define DEBUG_Z80
#ifndef _MAX_PATH
#ifdef _POSIX_PATH_MAX
#define _MAX_PATH _POSIX_PATH_MAX
#else
#define _MAX_PATH 256
#endif
#endif
#define CYCLE_COUNT_INIT 80000 // 4MHz divided by 50Hz = number of CPU cycles per frame
#define CPC_SCR_WIDTH 1024 // max width
#define CPC_SCR_HEIGHT 312 // max height
#define CPC_VISIBLE_SCR_WIDTH 384 // visible width: 4+40+4 * 8
#define CPC_VISIBLE_SCR_HEIGHT 270
#define ICN_DISK_WIDTH 14
#define ICN_DISK_HEIGHT 16
#define ICN_TAPE_WIDTH 18
#define ICN_TAPE_HEIGHT 13
#define VOC_THRESHOLD 128
// CRTC flags
#define VS_flag 1
#define HS_flag 2
#define HDT_flag 4
#define VDT_flag 8
#define HT_flag 16
#define VT_flag 32
#define MR_flag 64
#define VTadj_flag 128
#define VSf_flag 256
// FDC constants
#define DSK_BPTMAX 8192
#define DSK_TRACKMAX 102 // max amount that fits in a DSK header
#define DSK_SIDEMAX 2
#define DSK_SECTORMAX 29 // max amount that fits in a track header
#define FDC_TO_CPU 0
#define CPU_TO_FDC 1
#define CMD_PHASE 0
#define EXEC_PHASE 1
#define RESULT_PHASE 2
#define SKIP_flag 1 // skip sectors with DDAM/DAM
#define SEEKDRVA_flag 2 // seek operation has finished for drive A
#define SEEKDRVB_flag 4 // seek operation has finished for drive B
#define RNDDE_flag 8 // simulate random DE sectors
#define OVERRUN_flag 16 // data transfer timed out
#define SCAN_flag 32 // one of the three scan commands is active
#define SCANFAILED_flag 64 // memory and sector data does not match
#define STATUSDRVA_flag 128 // status change of drive A
#define STATUSDRVB_flag 256 // status change of drive B
// Multiface 2 flags
#define MF2_ACTIVE 1
#define MF2_RUNNING 2
#define MF2_INVISIBLE 4
typedef struct {
char id[8];
char unused1[8];
unsigned char version;
unsigned char AF[2];
unsigned char BC[2];
unsigned char DE[2];
unsigned char HL[2];
unsigned char R;
unsigned char I;
unsigned char IFF0;
unsigned char IFF1;
unsigned char IX[2];
unsigned char IY[2];
unsigned char SP[2];
unsigned char PC[2];
unsigned char IM;
unsigned char AFx[2];
unsigned char BCx[2];
unsigned char DEx[2];
unsigned char HLx[2];
unsigned char ga_pen;
unsigned char ga_ink_values[17];
unsigned char ga_ROM_config;
unsigned char ga_RAM_config;
unsigned char crtc_reg_select;
unsigned char crtc_registers[18];
unsigned char upper_ROM;
unsigned char ppi_A;
unsigned char ppi_B;
unsigned char ppi_C;
unsigned char ppi_control;
unsigned char psg_reg_select;
unsigned char psg_registers[16];
unsigned char ram_size[2];
// version 2 info follows
unsigned char cpc_model;
unsigned char last_interrupt;
unsigned char scr_modes[6];
// version 3 info follows
unsigned char drvA_DOSfilename[13];
unsigned char drvB_DOSfilename[13];
unsigned char cart_DOSfilename[13];
unsigned char fdc_motor;
unsigned char drvA_current_track;
unsigned char drvB_current_track;
unsigned char drvC_current_track;
unsigned char drvD_current_track;
unsigned char printer_data;
unsigned char psg_env_step;
unsigned char psg_env_direction;
unsigned char crtc_type;
unsigned char crtc_addr[2];
unsigned char crtc_scanline[2];
unsigned char crtc_char_count[2];
unsigned char crtc_line_count;
unsigned char crtc_raster_count;
unsigned char crtc_vt_adjust_count;
unsigned char crtc_hsw_count;
unsigned char crtc_vsw_count;
unsigned char crtc_flags[2];
unsigned char ga_int_delay;
unsigned char ga_sl_count;
unsigned char z80_int_pending;
unsigned char unused2[75];
} t_SNA_header;
typedef struct {
char id[34];
char unused1[14];
unsigned char tracks;
unsigned char sides;
unsigned char unused2[2];
unsigned char track_size[DSK_TRACKMAX*DSK_SIDEMAX];
} t_DSK_header;
typedef struct {
char id[12];
char unused1[4];
unsigned char track;
unsigned char side;
unsigned char unused2[2];
unsigned char bps;
unsigned char sectors;
unsigned char gap3;
unsigned char filler;
unsigned char sector[DSK_SECTORMAX][8];
} t_track_header;
typedef struct {
unsigned int model;
unsigned int jumpers;
unsigned int ram_size;
unsigned int speed;
unsigned int limit_speed;
unsigned int paused;
unsigned int auto_pause;
unsigned int keyboard_line;
unsigned int tape_motor;
unsigned int tape_play_button;
unsigned int printer;
unsigned int printer_port;
unsigned int mf2;
unsigned int keyboard;
unsigned int joysticks;
int cycle_count;
unsigned int scr_fs_width;
unsigned int scr_fs_height;
unsigned int scr_fs_bpp;
unsigned int scr_style;
unsigned int scr_oglfilter;
unsigned int scr_vsync;
unsigned int scr_led;
unsigned int scr_fps;
unsigned int scr_tube;
unsigned int scr_intensity;
unsigned int scr_remanency;
unsigned int scr_window;
unsigned int scr_bpp;
unsigned int scr_bps;
unsigned int scr_line_offs;
unsigned int *scr_base;
unsigned int *scr_pos;
void (*scr_render)(void);
void (*scr_prerendernorm)(void);
void (*scr_prerenderbord)(void);
void (*scr_prerendersync)(void);
bool scr_is_ogl;
unsigned int snd_enabled;
unsigned int snd_playback_rate;
unsigned int snd_bits;
unsigned int snd_stereo;
unsigned int snd_volume;
unsigned int snd_pp_device;
unsigned int snd_buffersize;
unsigned char *snd_bufferptr;
union {
struct {
unsigned int low;
unsigned int high;
};
int64_t both;
} snd_cycle_count_init;
unsigned int kbd_layout;
unsigned int max_tracksize;
char snap_path[_MAX_PATH + 1];
char snap_file[_MAX_PATH + 1];
bool snap_zip;
char drvA_path[_MAX_PATH + 1];
char drvA_file[_MAX_PATH + 1];
bool drvA_zip;
unsigned int drvA_format;
char drvB_path[_MAX_PATH + 1];
char drvB_file[_MAX_PATH + 1];
bool drvB_zip;
unsigned int drvB_format;
char tape_path[_MAX_PATH + 1];
char tape_file[_MAX_PATH + 1];
bool tape_zip;
char printer_file[_MAX_PATH + 1];
char sdump_file[_MAX_PATH + 1];
char rom_path[_MAX_PATH + 1];
char rom_file[16][_MAX_PATH + 1];
char rom_mf2[_MAX_PATH + 1];
} t_CPC;
typedef struct {
unsigned int requested_addr;
unsigned int next_addr;
unsigned int addr;
unsigned int next_address;
unsigned int scr_base;
unsigned int char_count;
unsigned int line_count;
unsigned int raster_count;
unsigned int hsw;
unsigned int hsw_count;
unsigned int vsw;
unsigned int vsw_count;
unsigned int flag_hadhsync;
unsigned int flag_inmonhsync;
unsigned int flag_invsync;
unsigned int flag_invta;
unsigned int flag_newscan;
unsigned int flag_reschar;
unsigned int flag_resframe;
unsigned int flag_resnext;
unsigned int flag_resscan;
unsigned int flag_resvsync;
unsigned int flag_startvta;
unsigned int last_hend;
unsigned int reg5;
unsigned int r7match;
unsigned int r9match;
unsigned int hstart;
unsigned int hend;
void (*CharInstMR)(void);
void (*CharInstSL)(void);
unsigned char reg_select;
unsigned char registers[18];
} t_CRTC;
typedef struct {
int timeout;
int motor;
int led;
int flags;
int phase;
int byte_count;
int buffer_count;
int cmd_length;
int res_length;
int cmd_direction;
void (*cmd_handler)(void);
unsigned char *buffer_ptr;
unsigned char *buffer_endptr;
unsigned char command[12];
unsigned char result[8];
} t_FDC;
typedef struct {
unsigned int hs_count;
unsigned char ROM_config;
unsigned char RAM_bank;
unsigned char RAM_config;
unsigned char upper_ROM;
unsigned int requested_scr_mode;
unsigned int scr_mode;
unsigned char pen;
unsigned char ink_values[17];
unsigned int palette[19];
unsigned char sl_count;
unsigned char int_delay;
} t_GateArray;
typedef struct {
unsigned char control;
unsigned char portA;
unsigned char portB;
unsigned char portC;
} t_PPI;
typedef struct {
union {
struct {
unsigned int low;
unsigned int high;
};
int64_t both;
} cycle_count;
unsigned int buffer_full;
unsigned char control;
unsigned char reg_select;
union {
unsigned char Index[16];
struct {
unsigned char TonALo, TonAHi;
unsigned char TonBLo, TonBHi;
unsigned char TonCLo, TonCHi;
unsigned char Noise;
unsigned char Mixer;
unsigned char AmplitudeA, AmplitudeB, AmplitudeC;
unsigned char EnvelopeLo, EnvelopeHi;
unsigned char EnvType;
unsigned char PortA;
unsigned char PortB;
};
} RegisterAY;
int AmplitudeEnv;
bool FirstPeriod;
void (*Synthesizer)(void);
} t_PSG;
typedef struct {
int scrln;
int scanline;
unsigned int flag_drawing;
unsigned int frame_completed;
} t_VDU;
typedef struct {
unsigned char CHRN[4]; // the CHRN for this sector
unsigned char flags[4]; // ST1 and ST2 - reflects any possible error conditions
unsigned int size; // sector size in bytes
unsigned char *data; // pointer to sector data
} t_sector;
typedef struct {
unsigned int sectors; // sector count for this track
unsigned int size; // track size in bytes
unsigned char *data; // pointer to track data
t_sector sector[DSK_SECTORMAX]; // array of sector information structures
} t_track;
typedef struct {
unsigned int tracks; // total number of tracks
unsigned int current_track; // location of drive head
unsigned int sides; // total number of sides
unsigned int current_side; // side being accessed
unsigned int current_sector; // sector being accessed
unsigned int altered; // has the image been modified?
unsigned int write_protected; // is the image write protected?
unsigned int random_DEs; // sectors with Data Errors return random data?
unsigned int flipped; // reverse the side to access?
t_track track[DSK_TRACKMAX][DSK_SIDEMAX]; // array of track information structures
} t_drive;
typedef struct {
char *pchZipFile;
char *pchExtension;
char *pchFileNames;
char *pchSelection;
int iFiles;
unsigned int dwOffset;
} t_zip_info;
typedef struct {
unsigned char label[40]; // label to display in options dialog
unsigned int tracks; // number of tracks
unsigned int sides; // number of sides
unsigned int sectors; // sectors per track
unsigned int sector_size; // sector size as N value
unsigned int gap3_length; // GAP#3 size
unsigned char filler_byte; // default byte to use
unsigned char sector_ids[2][16]; // sector IDs
} t_disk_format;
// cap32.cpp
void emulator_reset(bool bolMF2Reset);
// fdc.c
void fdc_write_data(unsigned char val);
unsigned char fdc_read_status(void);
unsigned char fdc_read_data(void);
// psg.c
void SetAYRegister(int Num, unsigned char Value);
void Calculate_Level_Tables(void);
void ResetAYChipEmulation(void);
void InitAYCounterVars(void);
void InitAY(void);
#endif