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

📄 nes_apu.h

📁 三星ic 9980的源代码. 718版.
💻 H
字号:
/**************************************************************************************************************** 
 *				                        	                                                 
 *	Project		:	GameCD Player									 
 *	Module		:	Game Emulator								 
 *														 
 *	Copyright	:	(c) 2004, Samsung India Software Operations,					 
 *				All Rights Reserved.								 
 *				This software is the confidential and proprietary information			 
 *				of Samsung Electronics, Inc. (Confidential Information).  You			 
 *				shall not disclose such Confidential Information and shall use			 
 *				it only in accordance with the terms of the license agreement			 
 *				you entered into with Samsung Electronics.					 
 *														 
 *	File		:	Svcd/GEmu/nes_apu.h								 
 *	Date		:	11th of May, 2004								 
 *				                                                                                 
 *	Author(s)	:	             		 	                   			 
 *	      		 	Chandandeep Pabla	-	chandan@samsung.com			 
 *				                                                                                 
 *	Department	:	System LSI Division, SISO.                                               
 *				                                                                                 
 *	Platform	:	S5H5002 DVD Player, ARM9TDMI						 
 *	Compiler	:	armcc version 2.5.1								 
 *				                                                                                 
 *	File Desc.	:	This file implements the functions prototypes for the functions in nes_apu.c     
 *				                                                                                 
 *	History		:	                                                                                 
 *				                                                                                 
 ****************************************************************************************************************/

/*
** Nofrendo (c) 1998-2000 Matthew Conte (matt@conte.com)
**
**
** This program is free software; you can redistribute it and/or
** modify it under the terms of version 2 of the GNU Library General 
** Public License as published by the Free Software Foundation.
**
** 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 
** Library General Public License for more details.  To obtain a 
** copy of the GNU Library General Public License, write to the Free 
** Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
**
** Any permitted reproduction of these routines, in whole or in part,
** must bear this legend.
**
**
** nes_apu.h
**
** NES APU emulation header file
** $Id: nes_apu.h,v 1.21 2000/08/11 02:27:21 matt Exp $
*/

#ifndef _NES_APU_H_
#define _NES_APU_H_
typedef  char     int8;
typedef  short    int16;
typedef  signed long      int32;

typedef  unsigned char  uint8;
typedef  unsigned short  uint16;

typedef  unsigned long   uint32;

typedef  uint8    boolean;

#ifndef  TRUE
#define  TRUE     1
#endif
#ifndef  FALSE
#define  FALSE    0
#endif

//#define  INLINE      static


/************************* Capabilities ********************

	Change the value here for different audio options
	
********************************************************/	
/* For choosing mono sound or stereo sound */
#define MONO	0

/* 	Macro for generating data at different sampling frequancies.
 	Chage the sampling frequancy value here as per ur requirements 
*/ 
#define GAME_AUDIO_SAMPLING_RATE			11025
#define INCREASED_GAME_AUDIO_SAMPLING_RATE 22050
#define GAME_AUDIO_SAMPLE_BITS			16
#define GCD_AUDIO_REFRESH_RATE    60
#define SAMPLE_SIZE		(GAME_AUDIO_SAMPLING_RATE/GCD_AUDIO_REFRESH_RATE)
#define INCREASED_SAMPLE_SIZE (INCREASED_GAME_AUDIO_SAMPLING_RATE/GCD_AUDIO_REFRESH_RATE)
#define  APU_BASEFREQ   1789772.7272727272727272
#define APU_CYCLERATE 	0xA25671
#define INCREASED_APU_CYCLERATE  0x512B38
//0xDFB8BA
//0x6FDC5D
//0x512B38  -22050
//0xA25671  -- 11025


/* define this for realtime generated noise */
#define  REALTIME_NOISE 

#define  APU_WRA0       0x4000
#define  APU_WRA1       0x4001
#define  APU_WRA2       0x4002
#define  APU_WRA3       0x4003
#define  APU_WRB0       0x4004
#define  APU_WRB1       0x4005
#define  APU_WRB2       0x4006
#define  APU_WRB3       0x4007
#define  APU_WRC0       0x4008
#define  APU_WRC2       0x400A
#define  APU_WRC3       0x400B
#define  APU_WRD0       0x400C
#define  APU_WRD2       0x400E
#define  APU_WRD3       0x400F
#define  APU_WRE0       0x4010
#define  APU_WRE1       0x4011
#define  APU_WRE2       0x4012
#define  APU_WRE3       0x4013

#define  APU_SMASK      0x4015

/* length of generated noise */
#define  APU_NOISE_32K	  0x7F//0x7FFF
#define  APU_NOISE_93   	93


/* to/from 16.16 fixed point */
#define  APU_TO_FIXED(x)   (unsigned long) ((x) << 16)
#define  APU_FROM_FIXED(x)	(unsigned long) ((x) >> 16)

/* channel structures */
/* As much data as possible is precalculated,
** to keep the sample processing as lean as possible
*/
 
typedef struct rectangle_s
{
   uint8 regs[4];

   boolean enabled;
   
   int32 phaseacc;
   int32 freq;
   int32 output_vol;
   boolean fixed_envelope;
   boolean holdnote;
   uint8 volume;

   int32 sweep_phase;
   int32 sweep_delay;
   boolean sweep_on;
   uint8 sweep_shifts;
   uint8 sweep_length;
   boolean sweep_inc;

   /* this may not be necessary in the future */
   int32 freq_limit;

   /* rectangle 0 uses a complement addition for sweep
   ** increases, while rectangle 1 uses subtraction
   */
   boolean sweep_complement;

   int32 env_phase;
   int32 env_delay;
   uint8 env_vol;

   int vbl_length;
   uint8 adder;
   int duty_flip;
} rectangle_t;

typedef struct triangle_s
{
   uint8 regs[3];

   boolean enabled;

   int32 freq;
   int32 phaseacc;
   int32 output_vol;

   uint8 adder;

   boolean holdnote;
   boolean counter_started;
   /* quasi-hack */
   int write_latency;

   int vbl_length;
   int linear_length;
} triangle_t;


typedef struct noise_s
{
   uint8 regs[3];

   boolean enabled;

   int32 freq;
   int32 phaseacc;
   int32 output_vol;

   int32 env_phase;
   int32 env_delay;
   uint8 env_vol;
   boolean fixed_envelope;
   boolean holdnote;

   uint8 volume;

   int vbl_length;

#ifdef REALTIME_NOISE
   uint8 xor_tap;
#else
   boolean short_sample;
   int cur_pos;
#endif /* REALTIME_NOISE */
} noise_t;

typedef struct dmc_s
{
   uint8 regs[4];

   /* bodge for timestamp queue */
   boolean enabled;
   
   int32 freq;
   int32 phaseacc;
   int32 output_vol;

   uint32 address;
   uint32 cached_addr;
   int dma_length;
   int cached_dmalength;
   uint8 cur_byte;

   boolean looping;
   boolean irq_gen;
   boolean irq_occurred;

} dmc_t;

enum
{
   APU_FILTER_NONE,
   APU_FILTER_LOWPASS,
   APU_FILTER_WEIGHTED
};
#if _ENABLE_APU_EXT  
typedef struct
{
   uint32 min_range, max_range;
   uint8 (*read_func)(uint32 address);
} apu_memread;

typedef struct
{
   uint32 min_range, max_range;
   void (*write_func)(uint32 address, uint8 value);
} apu_memwrite;

/* external sound chip stuff */
typedef struct apuext_s
{
   void  (*init)(void);
   void  (*shutdown)(void);
   void  (*reset)(void);
   //DCR
   void  (*paramschanged)(void);
   int32 (*process)(void);
   apu_memread *mem_read;
   apu_memwrite *mem_write;
} apuext_t;
#endif /*_ENABLE_APU_EXT  */

/* apu ring buffer member */
typedef struct apudata_s
{
   uint32 timestamp, address;
   uint8 value;
} apudata_t;


typedef struct apu_s
{
   rectangle_t rectangle[2];
   triangle_t triangle;
   noise_t noise;
   dmc_t dmc;
#if _ENABLE_APU_EXT  
   /* external sound chip */
   apuext_t *ext;
#endif
} apu_t;

//extern apu_t *apu;

#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */

/* Function prototypes */
extern apu_t *apu_getcontext(void);
extern void apu_setcontext(apu_t *src_apu);

extern void apu_create(void);

extern void apu_setparams();

extern void apu_process(void);
extern void apu_reset(void);
#if _ENABLE_APU_EXT  
extern void apu_setext(apu_t *apu, apuext_t *ext);
#endif
extern void apu_setchan(int chan, boolean enabled);

extern uint8 apu_read(uint32 address);
extern void apu_write(uint32 address, uint8 value);

#ifdef __cplusplus
}
#endif /* __cplusplus */

#endif /* _NES_APU_H_ */

/*
** $Log: nes_apu.h,v $
** Revision 1.21  2000/08/11 02:27:21  matt
** general cleanups, plus apu_setparams routine
**
** Revision 1.20  2000/07/30 04:32:59  matt
** no more apu_getcyclerate hack
**
** Revision 1.19  2000/07/27 02:49:50  matt
** eccentricity in sweeping hardware now emulated correctly
**
** Revision 1.18  2000/07/25 02:25:15  matt
** safer apu_destroy
**
** Revision 1.17  2000/07/23 15:10:54  matt
** hacks for win32
**
** Revision 1.16  2000/07/23 00:48:15  neil
** Win32 SDL
**
** Revision 1.15  2000/07/17 01:52:31  matt
** made sure last line of all source files is a newline
**
** Revision 1.14  2000/07/11 02:39:26  matt
** added setcontext() routine
**
** Revision 1.13  2000/07/10 05:29:34  matt
** moved joypad/oam dma from apu to ppu
**
** Revision 1.12  2000/07/04 04:54:48  matt
** minor changes that helped with MAME
**
** Revision 1.11  2000/07/03 02:18:53  matt
** much better external module exporting
**
** Revision 1.10  2000/06/26 05:00:37  matt
** cleanups
**
** Revision 1.9  2000/06/23 03:29:28  matt
** cleaned up external sound inteface
**
** Revision 1.8  2000/06/20 04:06:16  matt
** migrated external sound definition to apu module
**
** Revision 1.7  2000/06/20 00:07:35  matt
** added convenience members to apu_t struct
**
** Revision 1.6  2000/06/09 16:49:02  matt
** removed all floating point from sound generation
**
** Revision 1.5  2000/06/09 15:12:28  matt
** initial revision
**
*/

⌨️ 快捷键说明

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