mirror of
https://github.com/ZDoom/gzdoom-gles.git
synced 2024-12-12 21:31:57 +00:00
040cb17370
# Conflicts: # CMakeLists.txt # libraries/glslang/OGLCompilersDLL/CMakeLists.txt # libraries/glslang/OGLCompilersDLL/InitializeDll.cpp # libraries/glslang/OGLCompilersDLL/InitializeDll.h # libraries/glslang/glslang/CMakeLists.txt # libraries/glslang/glslang/GenericCodeGen/CodeGen.cpp # libraries/glslang/glslang/GenericCodeGen/Link.cpp # libraries/glslang/glslang/Include/BaseTypes.h # libraries/glslang/glslang/Include/Common.h # libraries/glslang/glslang/Include/ConstantUnion.h # libraries/glslang/glslang/Include/InfoSink.h # libraries/glslang/glslang/Include/InitializeGlobals.h # libraries/glslang/glslang/Include/PoolAlloc.h # libraries/glslang/glslang/Include/ResourceLimits.h # libraries/glslang/glslang/Include/ShHandle.h # libraries/glslang/glslang/Include/Types.h # libraries/glslang/glslang/Include/arrays.h # libraries/glslang/glslang/Include/intermediate.h # libraries/glslang/glslang/Include/revision.h # libraries/glslang/glslang/Include/revision.template # libraries/glslang/glslang/MachineIndependent/Constant.cpp # libraries/glslang/glslang/MachineIndependent/InfoSink.cpp # libraries/glslang/glslang/MachineIndependent/Initialize.cpp # libraries/glslang/glslang/MachineIndependent/Initialize.h # libraries/glslang/glslang/MachineIndependent/IntermTraverse.cpp # libraries/glslang/glslang/MachineIndependent/Intermediate.cpp # libraries/glslang/glslang/MachineIndependent/LiveTraverser.h # libraries/glslang/glslang/MachineIndependent/ParseContextBase.cpp # libraries/glslang/glslang/MachineIndependent/ParseHelper.cpp # libraries/glslang/glslang/MachineIndependent/ParseHelper.h # libraries/glslang/glslang/MachineIndependent/PoolAlloc.cpp # libraries/glslang/glslang/MachineIndependent/RemoveTree.cpp # libraries/glslang/glslang/MachineIndependent/RemoveTree.h # libraries/glslang/glslang/MachineIndependent/Scan.cpp # libraries/glslang/glslang/MachineIndependent/Scan.h # libraries/glslang/glslang/MachineIndependent/ScanContext.h # libraries/glslang/glslang/MachineIndependent/ShaderLang.cpp # libraries/glslang/glslang/MachineIndependent/SymbolTable.cpp # libraries/glslang/glslang/MachineIndependent/SymbolTable.h # libraries/glslang/glslang/MachineIndependent/Versions.cpp # libraries/glslang/glslang/MachineIndependent/Versions.h # libraries/glslang/glslang/MachineIndependent/attribute.cpp # libraries/glslang/glslang/MachineIndependent/attribute.h # libraries/glslang/glslang/MachineIndependent/gl_types.h # libraries/glslang/glslang/MachineIndependent/glslang.y # libraries/glslang/glslang/MachineIndependent/glslang_tab.cpp # libraries/glslang/glslang/MachineIndependent/glslang_tab.cpp.h # libraries/glslang/glslang/MachineIndependent/intermOut.cpp # libraries/glslang/glslang/MachineIndependent/iomapper.cpp # libraries/glslang/glslang/MachineIndependent/iomapper.h # libraries/glslang/glslang/MachineIndependent/limits.cpp # libraries/glslang/glslang/MachineIndependent/linkValidate.cpp # libraries/glslang/glslang/MachineIndependent/localintermediate.h # libraries/glslang/glslang/MachineIndependent/parseConst.cpp # libraries/glslang/glslang/MachineIndependent/parseVersions.h # libraries/glslang/glslang/MachineIndependent/pch.cpp # libraries/glslang/glslang/MachineIndependent/pch.h # libraries/glslang/glslang/MachineIndependent/preprocessor/Pp.cpp # libraries/glslang/glslang/MachineIndependent/preprocessor/PpAtom.cpp # libraries/glslang/glslang/MachineIndependent/preprocessor/PpContext.cpp # libraries/glslang/glslang/MachineIndependent/preprocessor/PpContext.h # libraries/glslang/glslang/MachineIndependent/preprocessor/PpScanner.cpp # libraries/glslang/glslang/MachineIndependent/preprocessor/PpTokens.cpp # libraries/glslang/glslang/MachineIndependent/preprocessor/PpTokens.h # libraries/glslang/glslang/MachineIndependent/propagateNoContraction.cpp # libraries/glslang/glslang/MachineIndependent/propagateNoContraction.h # libraries/glslang/glslang/MachineIndependent/reflection.cpp # libraries/glslang/glslang/MachineIndependent/reflection.h # libraries/glslang/glslang/OSDependent/Unix/CMakeLists.txt # libraries/glslang/glslang/OSDependent/Unix/ossource.cpp # libraries/glslang/glslang/OSDependent/Windows/CMakeLists.txt # libraries/glslang/glslang/OSDependent/Windows/main.cpp # libraries/glslang/glslang/OSDependent/Windows/ossource.cpp # libraries/glslang/glslang/OSDependent/osinclude.h # libraries/glslang/glslang/Public/ShaderLang.h # libraries/glslang/glslang/updateGrammar # libraries/glslang/spirv/CMakeLists.txt # libraries/glslang/spirv/GLSL.ext.AMD.h # libraries/glslang/spirv/GLSL.ext.EXT.h # libraries/glslang/spirv/GLSL.ext.KHR.h # libraries/glslang/spirv/GLSL.ext.NV.h # libraries/glslang/spirv/GLSL.std.450.h # libraries/glslang/spirv/GlslangToSpv.cpp # libraries/glslang/spirv/GlslangToSpv.h # libraries/glslang/spirv/InReadableOrder.cpp # libraries/glslang/spirv/Logger.cpp # libraries/glslang/spirv/Logger.h # libraries/glslang/spirv/SPVRemapper.cpp # libraries/glslang/spirv/SPVRemapper.h # libraries/glslang/spirv/SpvBuilder.cpp # libraries/glslang/spirv/SpvBuilder.h # libraries/glslang/spirv/SpvPostProcess.cpp # libraries/glslang/spirv/SpvTools.cpp # libraries/glslang/spirv/SpvTools.h # libraries/glslang/spirv/bitutils.h # libraries/glslang/spirv/disassemble.cpp # libraries/glslang/spirv/disassemble.h # libraries/glslang/spirv/doc.cpp # libraries/glslang/spirv/doc.h # libraries/glslang/spirv/hex_float.h # libraries/glslang/spirv/spirv.hpp # libraries/glslang/spirv/spvIR.h # src/CMakeLists.txt
179 lines
5.4 KiB
C++
179 lines
5.4 KiB
C++
// NES 2A03 APU sound chip emulator
|
|
|
|
// Nes_Snd_Emu 0.1.8
|
|
#ifndef NES_APU_H
|
|
#define NES_APU_H
|
|
|
|
#include "blargg_common.h"
|
|
|
|
typedef blargg_long nes_time_t; // CPU clock cycle count
|
|
typedef unsigned nes_addr_t; // 16-bit memory address
|
|
|
|
#include "Nes_Oscs.h"
|
|
|
|
struct apu_state_t;
|
|
class Nes_Buffer;
|
|
|
|
class Nes_Apu {
|
|
public:
|
|
// Set buffer to generate all sound into, or disable sound if NULL
|
|
void output( Blip_Buffer* );
|
|
|
|
// Set memory reader callback used by DMC oscillator to fetch samples.
|
|
// When callback is invoked, 'user_data' is passed unchanged as the
|
|
// first parameter.
|
|
void dmc_reader( int (*callback)( void* user_data, nes_addr_t ), void* user_data = NULL );
|
|
|
|
// All time values are the number of CPU clock cycles relative to the
|
|
// beginning of the current time frame. Before resetting the CPU clock
|
|
// count, call end_frame( last_cpu_time ).
|
|
|
|
// Write to register (0x4000-0x4017, except 0x4014 and 0x4016)
|
|
enum { start_addr = 0x4000 };
|
|
enum { end_addr = 0x4017 };
|
|
void write_register( nes_time_t, nes_addr_t, int data );
|
|
|
|
// Read from status register at 0x4015
|
|
enum { status_addr = 0x4015 };
|
|
int read_status( nes_time_t );
|
|
|
|
// Run all oscillators up to specified time, end current time frame, then
|
|
// start a new time frame at time 0. Time frames have no effect on emulation
|
|
// and each can be whatever length is convenient.
|
|
void end_frame( nes_time_t );
|
|
|
|
// Additional optional features (can be ignored without any problem)
|
|
|
|
// Reset internal frame counter, registers, and all oscillators.
|
|
// Use PAL timing if pal_timing is true, otherwise use NTSC timing.
|
|
// Set the DMC oscillator's initial DAC value to initial_dmc_dac without
|
|
// any audible click.
|
|
void reset( bool pal_mode = false, int initial_dmc_dac = 0 );
|
|
|
|
// Adjust frame period
|
|
void set_tempo( double );
|
|
|
|
// Save/load exact emulation state
|
|
void save_state( apu_state_t* out ) const;
|
|
void load_state( apu_state_t const& );
|
|
|
|
// Set overall volume (default is 1.0)
|
|
void volume( double );
|
|
|
|
// Set treble equalization (see notes.txt)
|
|
void treble_eq( const blip_eq_t& );
|
|
|
|
// Set sound output of specific oscillator to buffer. If buffer is NULL,
|
|
// the specified oscillator is muted and emulation accuracy is reduced.
|
|
// The oscillators are indexed as follows: 0) Square 1, 1) Square 2,
|
|
// 2) Triangle, 3) Noise, 4) DMC.
|
|
enum { osc_count = 5 };
|
|
void osc_output( int index, Blip_Buffer* buffer );
|
|
|
|
// Set IRQ time callback that is invoked when the time of earliest IRQ
|
|
// may have changed, or NULL to disable. When callback is invoked,
|
|
// 'user_data' is passed unchanged as the first parameter.
|
|
void irq_notifier( void (*callback)( void* user_data ), void* user_data = NULL );
|
|
|
|
// Get time that APU-generated IRQ will occur if no further register reads
|
|
// or writes occur. If IRQ is already pending, returns irq_waiting. If no
|
|
// IRQ will occur, returns no_irq.
|
|
enum { no_irq = INT_MAX / 2 + 1 };
|
|
enum { irq_waiting = 0 };
|
|
nes_time_t earliest_irq( nes_time_t ) const;
|
|
|
|
// Count number of DMC reads that would occur if 'run_until( t )' were executed.
|
|
// If last_read is not NULL, set *last_read to the earliest time that
|
|
// 'count_dmc_reads( time )' would result in the same result.
|
|
int count_dmc_reads( nes_time_t t, nes_time_t* last_read = NULL ) const;
|
|
|
|
// Time when next DMC memory read will occur
|
|
nes_time_t next_dmc_read_time() const;
|
|
|
|
// Run DMC until specified time, so that any DMC memory reads can be
|
|
// accounted for (i.e. inserting CPU wait states).
|
|
void run_until( nes_time_t );
|
|
|
|
public:
|
|
Nes_Apu();
|
|
BLARGG_DISABLE_NOTHROW
|
|
private:
|
|
friend class Nes_Nonlinearizer;
|
|
void enable_nonlinear( double volume );
|
|
static double nonlinear_tnd_gain() { return 0.75; }
|
|
private:
|
|
friend struct Nes_Dmc;
|
|
|
|
// noncopyable
|
|
Nes_Apu( const Nes_Apu& );
|
|
Nes_Apu& operator = ( const Nes_Apu& );
|
|
|
|
Nes_Osc* oscs [osc_count];
|
|
Nes_Square square1;
|
|
Nes_Square square2;
|
|
Nes_Noise noise;
|
|
Nes_Triangle triangle;
|
|
Nes_Dmc dmc;
|
|
|
|
double tempo_;
|
|
nes_time_t last_time; // has been run until this time in current frame
|
|
nes_time_t last_dmc_time;
|
|
nes_time_t earliest_irq_;
|
|
nes_time_t next_irq;
|
|
int frame_period;
|
|
int frame_delay; // cycles until frame counter runs next
|
|
int frame; // current frame (0-3)
|
|
int osc_enables;
|
|
int frame_mode;
|
|
bool irq_flag;
|
|
void (*irq_notifier_)( void* user_data );
|
|
void* irq_data;
|
|
Nes_Square::Synth square_synth; // shared by squares
|
|
|
|
void irq_changed();
|
|
void state_restored();
|
|
void run_until_( nes_time_t );
|
|
|
|
// TODO: remove
|
|
friend class Nes_Core;
|
|
};
|
|
|
|
inline void Nes_Apu::osc_output( int osc, Blip_Buffer* buf )
|
|
{
|
|
assert( (unsigned) osc < osc_count );
|
|
oscs [osc]->output = buf;
|
|
}
|
|
|
|
inline nes_time_t Nes_Apu::earliest_irq( nes_time_t ) const
|
|
{
|
|
return earliest_irq_;
|
|
}
|
|
|
|
inline void Nes_Apu::dmc_reader( int (*func)( void*, nes_addr_t ), void* user_data )
|
|
{
|
|
dmc.prg_reader_data = user_data;
|
|
dmc.prg_reader = func;
|
|
}
|
|
|
|
inline void Nes_Apu::irq_notifier( void (*func)( void* user_data ), void* user_data )
|
|
{
|
|
irq_notifier_ = func;
|
|
irq_data = user_data;
|
|
}
|
|
|
|
inline int Nes_Apu::count_dmc_reads( nes_time_t time, nes_time_t* last_read ) const
|
|
{
|
|
return dmc.count_reads( time, last_read );
|
|
}
|
|
|
|
inline nes_time_t Nes_Dmc::next_read_time() const
|
|
{
|
|
if ( length_counter == 0 )
|
|
return Nes_Apu::no_irq; // not reading
|
|
|
|
return apu->last_dmc_time + delay + long (bits_remain - 1) * period;
|
|
}
|
|
|
|
inline nes_time_t Nes_Apu::next_dmc_read_time() const { return dmc.next_read_time(); }
|
|
|
|
#endif
|