1 // Nintendo Game Boy sound hardware emulator with save state support
9 // Clock rate sound hardware runs at
10 enum { clock_rate
= 4194304 * GB_APU_OVERCLOCK
};
12 // Registers are at io_addr to io_addr+io_size-1
13 enum { io_addr
= 0xFF10 };
14 enum { io_size
= 0x30 };
15 enum { regs_size
= io_size
+ 0x10 };
18 mode_dmg
, // Game Boy monochrome
19 mode_cgb
, // Game Boy Color
20 mode_agb
// Game Boy Advance
23 // 0: Square 1, 1: Square 2, 2: Wave, 3: Noise
24 enum { osc_count
= 4 }; // 0 <= chan < osc_count
27 struct Gb_Osc
* oscs
[osc_count
];
28 blip_time_t last_time
; // time sound emulator has been run to
29 blip_time_t frame_period
; // clocks between each frame sequencer step
33 struct Gb_Square square1
;
34 struct Gb_Square square2
;
36 struct Gb_Noise noise
;
37 blip_time_t frame_time
; // time of next frame sequencer action
38 int frame_phase
; // phase of next frame sequencer step
40 uint8_t regs
[regs_size
];// last values written to registers
42 // large objects after everything else
43 struct Blip_Synth synth
;
49 void Apu_init( struct Gb_Apu
* this );
51 // Emulates to time t, then writes data to addr
52 void Apu_write_register( struct Gb_Apu
* this, blip_time_t t
, int addr
, int data
) ICODE_ATTR
;
54 // Emulates to time t, then subtracts t from the current time.
55 // OK if previous write call had time slightly after t.
56 void Apu_end_frame( struct Gb_Apu
* this,blip_time_t t
) ICODE_ATTR
;
60 // Emulates to time t, then reads from addr
61 int Apu_read_register( struct Gb_Apu
* this, blip_time_t t
, int addr
) ICODE_ATTR
;
63 // Resets hardware to state after power, BEFORE boot ROM runs. Mode selects
64 // sound hardware. If agb_wave is true, enables AGB's extra wave features.
65 void Apu_reset( struct Gb_Apu
* this, enum gb_mode_t mode
, bool agb_wave
);
67 // Same as set_output(), but for a particular channel
68 void Apu_set_output( struct Gb_Apu
* this, int chan
, struct Blip_Buffer
* center
,
69 struct Blip_Buffer
* left
, struct Blip_Buffer
* right
);
71 // Sets overall volume, where 1.0 is normal
72 void Apu_volume( struct Gb_Apu
* this, double v
);
74 // If true, reduces clicking by disabling DAC biasing. Note that this reduces
75 // emulation accuracy, since the clicks are authentic.
76 void Apu_reduce_clicks( struct Gb_Apu
* this, bool reduce
);
78 // Sets frame sequencer rate, where 1.0 is normal. Meant for adjusting the
79 // tempo in a music player.
80 void Apu_set_tempo( struct Gb_Apu
* this, int t
);
83 void write_osc( struct Gb_Apu
* this, int reg
, int old_data
, int data
) ICODE_ATTR
;