⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 snesapu.pas

📁 著名的游戏开发库Allegro4.2.0 for DELPHI
💻 PAS
📖 第 1 页 / 共 2 页
字号:
{***************************************************************************************************
* Program:    Super Nintendo Entertainment System(tm) Audio Processing Unit Emulator               *
* Platform:   Intel 80386 & MMX                                                                    *
* Programmer: Anti Resonance                                                                       *
*                                                                                                  *
* "SNES" and "Super Nintendo Entertainment System" are trademarks of Nintendo Co., Limited and its *
* subsidiary companies.                                                                            *
*                                                                                                  *
* 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.                                              *
* 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.                                        *
*                                                                                                  *
* Types and structures converted from C++                   Copyright (c)2004 Alpha-II Productions *
***************************************************************************************************}

unit SNESAPU;

interface
uses
  SysUtils, Windows, MMSystem;
//**************************************************************************************************
// Type Redefinitions

type
  b8	                  = Boolean;
  u8	                  = Byte;
  u16	                  = Word;
  u32	                  = LongWord;
  s8	                  = ShortInt;
  s16	                  = SmallInt;
  s32	                  = LongInt;
  s64	                  = Int64;
  f32                   = Single;
  f64                   = Double;
  f80                   = Extended;


//**************************************************************************************************
// APU.h

//SPC700 build options bits 7-0 ----------------
const
  SA_HALFC              = $02;          // Half-carry enabled
  SA_CNTBK	            = $04;          // Counter Break
  SA_SPEED	            = $08;          // Speed hack
  SA_IPLW		            = $10;          // IPL ROM region writeable
  SA_DSPBK	            = $20;          // Break SPC700/Update DSP if 0F3h is read from

//DSP build options bits 15-8 ------------------
  SA_VMETERM	          = $100;         // Volume metering on main output (for APR)
  SA_VMETERC	          = $200;         // Volume metering on voices (for visualization)
  SA_SNESINT	          = $400;         // Use pregenerated gaussian curve from SNES
  SA_STEREO	            = $800;         // Stereo controls (seperation and EFBCT)

//APU build options bits 23-16 -----------------
  SA_DEBUG	            = $10000;       // Debugging ability
  SA_DSPINTEG	          = $20000;       // DSP emulation is integrated with the SPC700


//**************************************************************************************************
// SPC700.h

const
  APU_CLK               = 24576000;     // Number of clock cycles in one second

//SPC700 debugging options ---------------------
  SPC_NODSP	            = $8;
  SPC_TRACE	            = $10;
  SPC_RETURN	          = $1;
  SPC_HALT	            = $2;

//Saved state ----------------------------------
type
  SPCState = record
    pRAM                : Pointer;      // [0.0] -> APU's RAM (64k)
    _r1                 : u32;          // [0.4] reserved
    pc                  : u16;          // [0.8] Registers
    a, y, x             : u8;
	  psw                 : u8;
    sp                  : u16;

    t8kHz, t64kHz       : u32;          // [1.0] # of cycles left until timer increase
    t64Cnt              : u32;          // [1.8] # of 64kHz ticks since emulation began
    _r2                 : u32;          // [1.C] reserved
    upCnt               : array[0..2] of u8; // [2.0] Up counters for counter increase
    portMod             : u8;           // [2.3] Flags for in ports that have been modified
    outp                : array[0..3] of u8; // [2.4] Out ports
    _r3                 : array[0..1] of u32; // [2.8] reserved
  end;

//**************************************************************************************************
// DSP.h

const
//CPU capability -------------------------------
  CPU_MMX	              = 1;            // Multi-Media eXtensions
  CPU_3DNOW	            = 2;            // 3DNow! extensions
  CPU_SSE		            = 4;            // Streaming SIMD Extensions

//Mixing routines ------------------------------
  MIX_NONE	            = 0;            // No mixing
  MIX_INT		            = 1;            // Use integer math
  MIX_FLOAT	            = 3;            // Use floating-point math

//Interpolation routines -----------------------
  INT_NONE              = 0;            // None
  INT_LINEAR            = 1;            // Linear
  INT_CUBIC             = 2;            // Cubic
  INT_GAUSS             = 3;            // Gaussian

//DSP options ----------------------------------
  DSP_ANALOG	          = $01;          // Simulate analog anomalies
  DSP_OLDSMP            = $02;					// Old ADPCM sample decompression routine
  DSP_SURND	            = $04;					// "Surround" sound
  DSP_REVERSE	          = $08;					// Reverse stereo samples
  DSP_NOECHO	          = $10;					// Disable echo

//PackWave options -----------------------------
  BRR_LINEAR            = $01;          // Use linear compression for all blocks
  BRR_LOOP              = $02;					// Set loop flag in block header
  BRR_NOINIT            = $04;					// Don't create an initial block of silence
  BRR_8BIT              = $10;					// Input samples are 8-bit


//DSP registers --------------------------------
type
  DSPVoice = record
    volL                : s8;           // Volume Left
    volR                : s8;           // Volume Right
    pitch               : u16;          // Pitch (rate/32000) (3.11)
    srcn                : u8;           // Sound source being played back
    adsr                : array[0..1] of u8; // Envelope rates for attack, decay, and sustain
    gain                : u8;           // Envelope gain (if not using ADSR)
    envx                : u8;           // Current envelope height (.7)
    outx                : u8;           // Current sample being output (-.7)
    __r                 : array[0..5] of s8;
  end;

  DSPFIR = record
    __r                 : array[0..14] of s8;
    c                   : s8;           //Filter coefficient
  end;

  DSPReg = record
	case Integer of
  	1:(voice            : array[0..7] of DSPVoice); // Voice registers
	  2:(
      __r1              : array[0..11] of u8;
      mvolL             : s8;           // Main Volume Left (-.7)
      efb               : s8;           // Echo Feedback (-.7)
      __r2              : array[0..13] of u8;
      mvolR             : s8;           // Main Volume Right (-.7)
      __r3              : array[0..14] of u8;
      evolL             : s8;           // Echo Volume Left (-.7)
      pmon              : u8;           // Pitch Modulation on/off for each voice
      __r4              : array[0..13] of u8;
      evolR             : s8;           // Echo Volume Right (-.7)
      non               : u8;           // Noise output on/off for each voice
      __r5              : array[0..13] of u8;
      kon               : u8;           // Key On for each voice
      eon               : u8;           // Echo on/off for each voice
      __r6              : array[0..13] of u8;
      kof               : u8;           // Key Off for each voice (instantiates release mode)
      dir               : u8;           // Page containing source directory (wave table offsets)
      __r7              : array[0..13] of u8;
      flg               : u8;           // DSP flags and noise frequency
      esa               : u8;           // Starting page used to store echo waveform
      __r8              : array[0..13] of u8;
      endx              : u8;           // Waveform has ended
      edl               : u8);         	// Echo Delay in ms >> 4
  3: (fir               : array[0..7] of DSPFIR); // FIR filter
  4: (reg               : array[0..127] of u8);
  end;

//Internal mixing data -------------------------
  EnvM = (
    ENV_DEC,                            // Linear decrease
    ENV_EXP,                            // Exponential decrease
    ENV_INC,									          // Linear increase
    ENV_3,ENV_4,ENV_5,
    ENV_BENT,									          // Bent line increase
    ENV_DIR,									          // Direct setting
    ENV_REL,									          // Release mode (key off)
    ENV_SUST,									          // Sustain mode
    ENV_ATTACK,									        // Attack mode

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -