Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
alexbevi
GitHub Repository: alexbevi/BizHawk
Path: blob/master/genplus-gx/cinterface/zap.c
2 views
1
#include "shared.h"
2
#include "eeprom_93c.h"
3
#include "eq.h"
4
5
6
7
extern struct
8
{
9
uint8 enabled;
10
uint8 status;
11
uint8 *rom;
12
uint8 *ram;
13
uint16 regs[13];
14
uint16 old[4];
15
uint16 data[4];
16
uint32 addr[4];
17
} action_replay;
18
19
typedef struct
20
{
21
uint8 address_bits; // number of bits needed to address memory: 7, 8 or 16 //
22
uint16 size_mask; // depends on the max size of the memory (in bytes) //
23
uint16 pagewrite_mask; // depends on the maximal number of bytes that can be written in a single write cycle //
24
uint32 sda_in_adr; // 68000 memory address mapped to SDA_IN //
25
uint32 sda_out_adr; // 68000 memory address mapped to SDA_OUT //
26
uint32 scl_adr; // 68000 memory address mapped to SCL //
27
uint8 sda_in_bit; // bit offset for SDA_IN //
28
uint8 sda_out_bit; // bit offset for SDA_OUT //
29
uint8 scl_bit; // bit offset for SCL //
30
} T_CONFIG_I2C;
31
32
typedef enum
33
{
34
STAND_BY = 0,
35
WAIT_STOP,
36
GET_SLAVE_ADR,
37
GET_WORD_ADR_7BITS,
38
GET_WORD_ADR_HIGH,
39
GET_WORD_ADR_LOW,
40
WRITE_DATA,
41
READ_DATA
42
} T_STATE_I2C;
43
44
typedef struct
45
{
46
uint8 sda; // current /SDA line state //
47
uint8 scl; // current /SCL line state //
48
uint8 old_sda; // previous /SDA line state //
49
uint8 old_scl; // previous /SCL line state //
50
uint8 cycles; // current operation cycle number (0-9) //
51
uint8 rw; // operation type (1:READ, 0:WRITE) //
52
uint16 slave_mask; // device address (shifted by the memory address width)//
53
uint16 word_address; // memory address //
54
T_STATE_I2C state; // current operation state //
55
T_CONFIG_I2C config; // EEPROM characteristics for this game //
56
} T_EEPROM_I2C;
57
58
extern T_EEPROM_I2C eeprom_i2c;
59
60
typedef enum
61
{
62
STANDBY,
63
GET_OPCODE_,//
64
GET_ADDRESS,
65
WRITE_BYTE,
66
READ_BYTE
67
} T_STATE_SPI;
68
69
typedef struct
70
{
71
uint8 cs; // !CS line state //
72
uint8 clk; // SCLK line state //
73
uint8 out; // SO line state //
74
uint8 status; // status register //
75
uint8 opcode; // 8-bit opcode //
76
uint8 buffer; // 8-bit data buffer //
77
uint16 addr; // 16-bit address //
78
uint32 cycles; // current operation cycle //
79
T_STATE_SPI state; // current operation state //
80
} T_EEPROM_SPI;
81
82
extern T_EEPROM_SPI spi_eeprom;
83
84
extern struct
85
{
86
uint8 enabled;
87
uint8 *rom;
88
uint16 regs[0x20];
89
uint16 old[6];
90
uint16 data[6];
91
uint32 addr[6];
92
} ggenie;
93
94
extern struct
95
{
96
uint8 State;
97
uint8 Counter;
98
} activator[2];
99
100
extern uint8 pad_index;
101
102
extern struct
103
{
104
uint8 State;
105
uint8 Port;
106
} lightgun;
107
108
extern struct
109
{
110
uint8 State;
111
uint8 Counter;
112
uint8 Wait;
113
uint8 Port;
114
} mouse;
115
116
extern struct
117
{
118
uint8 State;
119
} paddle[2];
120
121
extern struct
122
{
123
uint8 State;
124
uint8 Counter;
125
} sportspad[2];
126
127
extern struct
128
{
129
uint8 State;
130
uint8 Counter;
131
uint8 Table[12];
132
} teamplayer[2];
133
134
extern struct
135
{
136
uint8 axis;
137
uint8 busy;
138
} tablet;
139
140
extern struct
141
{
142
uint8 State;
143
uint8 Counter;
144
uint8 Latency;
145
} xe_a1p[2];
146
147
typedef struct
148
{
149
// Configuration //
150
int PreAmp[4][2]; // stereo channels pre-amplification ratio (%) //
151
int NoiseFeedback;
152
int SRWidth;
153
154
// PSG registers: //
155
int Registers[8]; // Tone, vol x4 //
156
int LatchedRegister;
157
int NoiseShiftRegister;
158
int NoiseFreq; // Noise channel signal generator frequency //
159
160
// Output calculation variables //
161
int ToneFreqVals[4]; // Frequency register values (counters) //
162
int ToneFreqPos[4]; // Frequency channel flip-flops //
163
int Channel[4][2]; // current amplitude of each (stereo) channel //
164
int ChanOut[4][2]; // current output value of each (stereo) channel //
165
166
// Internal M-clock counter //
167
unsigned long clocks;
168
169
} SN76489_Context;
170
171
extern SN76489_Context SN76489;
172
173
extern int fm_buffer[1080 * 2];
174
extern int fm_last[2];
175
extern int *fm_ptr;
176
177
// Cycle-accurate FM samples //
178
extern uint32 fm_cycles_ratio;
179
extern uint32 fm_cycles_start;
180
extern uint32 fm_cycles_count;
181
182
// YM chip function pointers //
183
extern void (*YM_Reset)(void);
184
extern void (*YM_Update)(int *buffer, int length);
185
extern void (*YM_Write)(unsigned int a, unsigned int v);
186
187
typedef struct
188
{
189
UINT32 ar; // attack rate: AR<<2 //
190
UINT32 dr; // decay rate: DR<<2 //
191
UINT32 rr; // release rate:RR<<2 //
192
UINT8 KSR; // key scale rate //
193
UINT8 ksl; // keyscale level //
194
UINT8 ksr; // key scale rate: kcode>>KSR //
195
UINT8 mul; // multiple: mul_tab[ML] //
196
197
// Phase Generator //
198
UINT32 phase; // frequency counter //
199
UINT32 freq; // frequency counter step //
200
UINT8 fb_shift; // feedback shift value //
201
INT32 op1_out[2]; // slot1 output for feedback //
202
203
// Envelope Generator //
204
UINT8 eg_type; // percussive/nonpercussive mode //
205
UINT8 state; // phase type //
206
UINT32 TL; // total level: TL << 2 //
207
INT32 TLL; // adjusted now TL //
208
INT32 volume; // envelope counter //
209
UINT32 sl; // sustain level: sl_tab[SL] //
210
211
UINT8 eg_sh_dp; // (dump state) //
212
UINT8 eg_sel_dp; // (dump state) //
213
UINT8 eg_sh_ar; // (attack state) //
214
UINT8 eg_sel_ar; // (attack state) //
215
UINT8 eg_sh_dr; // (decay state) //
216
UINT8 eg_sel_dr; // (decay state) //
217
UINT8 eg_sh_rr; // (release state for non-perc.) //
218
UINT8 eg_sel_rr; // (release state for non-perc.) //
219
UINT8 eg_sh_rs; // (release state for perc.mode) //
220
UINT8 eg_sel_rs; // (release state for perc.mode) //
221
222
UINT32 key; // 0 = KEY OFF, >0 = KEY ON //
223
224
// LFO //
225
UINT32 AMmask; // LFO Amplitude Modulation enable mask //
226
UINT8 vib; // LFO Phase Modulation enable flag (active high)//
227
228
// waveform select //
229
unsigned int wavetable;
230
} YM2413_OPLL_SLOT;
231
232
typedef struct
233
{
234
YM2413_OPLL_SLOT SLOT[2];
235
236
// phase generator state //
237
UINT32 block_fnum; // block+fnum //
238
UINT32 fc; // Freq. freqement base //
239
UINT32 ksl_base; // KeyScaleLevel Base step //
240
UINT8 kcode; // key code (for key scaling) //
241
UINT8 sus; // sus on/off (release speed in percussive mode) //
242
} YM2413_OPLL_CH;
243
244
// chip state //
245
typedef struct {
246
YM2413_OPLL_CH P_CH[9]; // OPLL chips have 9 channels //
247
UINT8 instvol_r[9]; // instrument/volume (or volume/volume in percussive mode) //
248
249
UINT32 eg_cnt; // global envelope generator counter //
250
UINT32 eg_timer; // global envelope generator counter works at frequency = chipclock/72 //
251
UINT32 eg_timer_add; // step of eg_timer //
252
UINT32 eg_timer_overflow; // envelope generator timer overlfows every 1 sample (on real chip) //
253
254
UINT8 rhythm; // Rhythm mode //
255
256
// LFO //
257
UINT32 lfo_am_cnt;
258
UINT32 lfo_am_inc;
259
UINT32 lfo_pm_cnt;
260
UINT32 lfo_pm_inc;
261
262
UINT32 noise_rng; // 23 bit noise shift register //
263
UINT32 noise_p; // current noise 'phase' //
264
UINT32 noise_f; // current noise period //
265
266
267
// instrument settings //
268
//
269
//0-user instrument
270
//1-15 - fixed instruments
271
//16 -bass drum settings
272
//17,18 - other percussion instruments
273
//
274
UINT8 inst_tab[19][8];
275
276
UINT32 fn_tab[1024]; // fnumber->increment counter //
277
278
UINT8 address; // address register //
279
UINT8 status; // status flag //
280
281
double clock; // master clock (Hz) //
282
int rate; // sampling rate (Hz) //
283
} YM2413;
284
285
extern YM2413 ym2413;
286
287
// struct describing a single operator (SLOT) //
288
typedef struct
289
{
290
INT32 *DT; // detune :dt_tab[DT] //
291
UINT8 KSR; // key scale rate :3-KSR //
292
UINT32 ar; // attack rate //
293
UINT32 d1r; // decay rate //
294
UINT32 d2r; // sustain rate //
295
UINT32 rr; // release rate //
296
UINT8 ksr; // key scale rate :kcode>>(3-KSR) //
297
UINT32 mul; // multiple :ML_TABLE[ML] //
298
299
// Phase Generator //
300
UINT32 phase; // phase counter //
301
INT32 Incr; // phase step //
302
303
// Envelope Generator //
304
UINT8 state; // phase type //
305
UINT32 tl; // total level: TL << 3 //
306
INT32 volume; // envelope counter //
307
UINT32 sl; // sustain level:sl_table[SL] //
308
UINT32 vol_out; // current output from EG circuit (without AM from LFO) //
309
310
UINT8 eg_sh_ar; // (attack state) //
311
UINT8 eg_sel_ar; // (attack state) //
312
UINT8 eg_sh_d1r; // (decay state) //
313
UINT8 eg_sel_d1r; // (decay state) //
314
UINT8 eg_sh_d2r; // (sustain state) //
315
UINT8 eg_sel_d2r; // (sustain state) //
316
UINT8 eg_sh_rr; // (release state) //
317
UINT8 eg_sel_rr; // (release state) //
318
319
UINT8 ssg; // SSG-EG waveform //
320
UINT8 ssgn; // SSG-EG negated output //
321
322
UINT8 key; // 0=last key was KEY OFF, 1=KEY ON //
323
324
// LFO //
325
UINT32 AMmask; // AM enable flag //
326
327
} FM_SLOT;
328
329
typedef struct
330
{
331
FM_SLOT SLOT[4]; // four SLOTs (operators) //
332
333
UINT8 ALGO; // algorithm //
334
UINT8 FB; // feedback shift //
335
INT32 op1_out[2]; // op1 output for feedback //
336
337
INT32 *connect1; // SLOT1 output pointer //
338
INT32 *connect3; // SLOT3 output pointer //
339
INT32 *connect2; // SLOT2 output pointer //
340
INT32 *connect4; // SLOT4 output pointer //
341
342
INT32 *mem_connect; // where to put the delayed sample (MEM) //
343
INT32 mem_value; // delayed sample (MEM) value //
344
345
INT32 pms; // channel PMS //
346
UINT8 ams; // channel AMS //
347
348
UINT32 fc; // fnum,blk //
349
UINT8 kcode; // key code //
350
UINT32 block_fnum; // blk/fnum value (for LFO PM calculations) //
351
} FM_CH;
352
353
354
typedef struct
355
{
356
UINT16 address; // address register //
357
UINT8 status; // status flag //
358
UINT32 mode; // mode CSM / 3SLOT //
359
UINT8 fn_h; // freq latch //
360
INT32 TA; // timer a value //
361
INT32 TAL; // timer a base //
362
INT32 TAC; // timer a counter //
363
INT32 TB; // timer b value //
364
INT32 TBL; // timer b base //
365
INT32 TBC; // timer b counter //
366
INT32 dt_tab[8][32]; // DeTune table //
367
368
} FM_ST;
369
370
371
// OPN unit //
372
373
374
// OPN 3slot struct //
375
typedef struct
376
{
377
UINT32 fc[3]; // fnum3,blk3: calculated //
378
UINT8 fn_h; // freq3 latch //
379
UINT8 kcode[3]; // key code //
380
UINT32 block_fnum[3]; // current fnum value for this slot (can be different betweeen slots of one channel in 3slot mode) //
381
UINT8 key_csm; // CSM mode Key-ON flag //
382
383
} FM_3SLOT;
384
385
// OPN/A/B common state //
386
typedef struct
387
{
388
FM_ST ST; // general state //
389
FM_3SLOT SL3; // 3 slot mode state //
390
unsigned int pan[6*2]; // fm channels output masks (0xffffffff = enable) //
391
392
// EG //
393
UINT32 eg_cnt; // global envelope generator counter //
394
UINT32 eg_timer; // global envelope generator counter works at frequency = chipclock/144/3 //
395
396
// LFO //
397
UINT8 lfo_cnt; // current LFO phase (out of 128) //
398
UINT32 lfo_timer; // current LFO phase runs at LFO frequency //
399
UINT32 lfo_timer_overflow; // LFO timer overflows every N samples (depends on LFO frequency) //
400
UINT32 LFO_AM; // current LFO AM step //
401
UINT32 LFO_PM; // current LFO PM step //
402
403
} FM_OPN;
404
405
// YM2612 chip //
406
typedef struct
407
{
408
FM_CH CH[6]; // channel state //
409
UINT8 dacen; // DAC mode //
410
INT32 dacout; // DAC output //
411
FM_OPN OPN; // OPN state //
412
413
} YM2612;
414
415
extern YM2612 ym2612;
416
417
// current chip state //
418
extern INT32 m2,c1,c2; // Phase Modulation input for operators 2,3,4 //
419
extern INT32 mem; // one sample delay memory //
420
extern INT32 out_fm[8]; // outputs of working channels //
421
extern UINT32 bitmask; // working channels output bitmasking (DAC quantization) //
422
423
extern uint8 tmss[4]; // TMSS security register //
424
425
extern uint8 rom_region;
426
427
extern uint8 pause_b;
428
extern EQSTATE eq;
429
extern int16 llp,rrp;
430
431
432
433
#define Z(a) memset((a), 0, sizeof(*(a)))
434
#define Y(a) memset((a), 0, sizeof((a)))
435
436
void zap(void)
437
{
438
Z(&config);
439
Z(&eeprom_93c);
440
441
Z(&ext);
442
Y(boot_rom);
443
Y(work_ram);
444
Y(zram);
445
Z(&zbank);
446
Z(&zstate);
447
Z(&pico_current);
448
Z(&input);
449
memset(old_system, -1, sizeof(old_system));
450
Y(io_reg);
451
Z(&region_code);
452
Z(&rominfo);
453
Z(&romtype);
454
Z(&m68k);
455
Z(&s68k);
456
457
Y(zbank_memory_map);
458
459
Z(&sram); // NB: sram.sram is not allocated
460
461
Z(&svp);
462
463
Z(&bitmap);
464
Z(&snd);
465
466
Z(&mcycles_vdp);
467
468
Z(&system_hw);
469
Z(&system_bios);
470
Z(&system_clock);
471
472
Y(reg);
473
Y(sat);
474
Y(vram);
475
Y(cram);
476
Y(vsram);
477
Z(&hint_pending);
478
Z(&vint_pending);
479
Z(&status);
480
Z(&dma_length);
481
482
Z(&ntab);
483
Z(&ntbb);
484
Z(&ntwb);
485
Z(&satb);
486
Z(&hscb);
487
Y(bg_name_dirty);
488
Y(bg_name_list);
489
Z(&bg_list_index);
490
Z(&hscroll_mask);
491
Z(&playfield_shift);
492
Z(&playfield_col_mask);
493
Z(&playfield_row_mask);
494
Z(&odd_frame);
495
Z(&im2_flag);
496
Z(&interlaced);
497
Z(&vdp_pal);
498
Z(&v_counter);
499
Z(&vc_max);
500
Z(&vscroll);
501
Z(&lines_per_frame);
502
Z(&max_sprite_pixels);
503
Z(&fifo_write_cnt);
504
Z(&fifo_slots);
505
Z(&hvc_latch);
506
Z(&hctab);
507
508
Z(&vdp_68k_data_w);
509
Z(&vdp_z80_data_w);
510
Z(&vdp_68k_data_r);
511
Z(&vdp_z80_data_r);
512
513
Z(&spr_col);
514
515
Z(&Z80);
516
517
Y(z80_readmap);
518
Y(z80_writemap);
519
520
Z(&z80_writemem);
521
Z(&z80_readmem);
522
Z(&z80_writeport);
523
Z(&z80_readport);
524
525
//=======
526
527
Z(&action_replay);
528
529
Z(&eeprom_i2c);
530
Z(&spi_eeprom);
531
532
Z(&ggenie);
533
534
Y(activator);
535
536
Y(gamepad);
537
538
Z(&pad_index);
539
540
541
Z(&lightgun);
542
543
Z(&mouse);
544
545
Y(paddle);
546
547
Y(sportspad);
548
549
Y(teamplayer);
550
551
Z(&tablet);
552
553
Y(xe_a1p);
554
555
Z(&SN76489);
556
557
Y(fm_buffer);
558
Y(fm_last);
559
Z(&fm_ptr);
560
561
Z(&fm_cycles_ratio);
562
Z(&fm_cycles_start);
563
Z(&fm_cycles_count);
564
565
Z(&YM_Reset);
566
Z(&YM_Update);
567
Z(&YM_Write);
568
569
Z(&ym2413);
570
571
Z(&ym2612);
572
573
Z(&m2);
574
Z(&c1);
575
Z(&c2);
576
Z(&mem);
577
Y(out_fm);
578
Z(&bitmask);
579
580
Y(tmss);
581
582
Z(&rom_region);
583
584
Z(&pause_b);
585
Z(&eq);
586
Z(&llp);
587
Z(&rrp);
588
}
589
590
591