📄 gamepad.c
字号:
#include "config.h"
#include "user_init.h"
#ifdef SUPPORT_GAME
#include "global.h"
#include "regmap.h"
#include "epp.h"
#include "func.h"
#include "cdfunc.h"
#include "osd.h"
#include "hwsetup.h"
#include "fs9660.h"
//sound
#include "auregs.h"
#include "pcm.h"
#include "game.h"
#include "avd.h"
#include "bitop.h"
#include "ircode.h"
#include "irconfig.h"
#include "memmap.h"
#include "macro.h"
extern BYTE vfd_keycode[];
extern UINT8 zhx_volume;
//PCM FIFO start word address.
#define CH_START 0
#define PCM_FIFO_SIZE (2048-32)
extern char *file_ext_name(UINT16);
static const unsigned char game_color_index[64 * 3] = {
103, 128, 128,
35, 217, 113,
35, 217, 113,
62, 202, 158,
75, 194, 180,
83, 164, 206,
68, 97, 217,
81, 90, 176,
93, 83, 135,
93, 83, 71,
98, 105, 68,
103, 128, 64,
82, 165, 79,
16, 128, 128,
16, 128, 128,
16, 128, 128,
147, 128, 128,
118, 195, 53,
40, 239, 109,
67, 224, 154,
93, 209, 199,
101, 179, 225,
81, 90, 239,
132, 60, 202,
145, 53, 161,
145, 53, 97,
118, 68, 52,
128, 113, 45,
138, 158, 38,
16, 128, 128,
16, 128, 128,
16, 128, 128,
235, 128, 128,
131, 187, 75,
144, 180, 98,
157, 172, 120,
170, 165, 143,
183, 157, 165,
173, 112, 172,
168, 90, 176,
194, 75, 157,
170, 38, 78,
144, 53, 34,
154, 98, 26,
169, 165, 16,
103, 128, 128,
59, 128, 128,
16, 128, 128,
235, 128, 128,
183, 157, 101,
196, 150, 124,
196, 150, 124,
209, 142, 146,
209, 142, 146,
204, 120, 150,
204, 120, 150,
199, 98, 154,
211, 90, 112,
198, 98, 90,
203, 120, 86,
208, 143, 83,
147, 128, 128,
59, 128, 128,
16, 128, 128
};
/*
BYTE origin_code(BYTE code,BYTE type)
translate mapped code to original code
parameter: type=0,common ir code
type=1,lcd panel code
type=2,vfd panel code
lcd_cnt:the lcd key is the second time we found
SUNPLUS huziqin 2003-3-29 9:11
*/
BYTE origin_code(BYTE KeyCode,BYTE type)
{
BYTE addr;
if(type==1) { //ZHX 061003
for(addr=0x40;addr<=0x5f;addr++) { //0x80-0x9f
if(ir_mapcode[addr] == KeyCode)
break;
}
if((ir_mapcode[0x5f]==KeyCode)||(addr < 0x5f))
addr += 0x40;
else
addr = 0xff;
}
else {
for(addr=0;addr<=0x3f;addr++) //0x00-0x5f
{
if(type == 0) {
if(ir_mapcode[addr] == KeyCode)
break;
}
else {
if(vfd_keycode[addr] == KeyCode)
break;
}
}
if (!type) {
if((ir_mapcode[0x3f]==KeyCode)||(addr > 0x1f))
addr += 0x20;
else if (addr==0x3f)
addr = 0xff;
}
else {
if (addr==0x3f)
addr = 0xfe;
}
}
return addr;
}
#define ir_code(x) origin_code(x,0)
#define lcd_code(x) origin_code(x,1)
#define vfd_code(x) (origin_code(x,2)+1)
void game_init()
{
int i, temp0, temp1;
#if CONFIG==CONFIG_COMBO_SVCD
/*
regs0->ref0_luma,regs0->ref1_luma for game use,height need 240
regs0->ref0_chroma,regs0->ref1_chroma are no use in game mode
*/
#ifdef SUPPORT_BOOMBOX_ESP
regs0->ref0_luma = (CDDA_OFFSET+MP3_OFFSET_XADD);//61
regs0->ref0_chroma = (CDDA_OFFSET+MP3_OFFSET_XADD);//61
regs0->ref1_luma = (CDDA_OFFSET+MP3_OFFSET_XADD+240);//301
regs0->ref1_chroma = (CDDA_OFFSET+MP3_OFFSET_XADD);//61
#else
regs0->ref0_luma = 0;
regs0->ref0_chroma = 0;
regs0->ref1_luma = 240;
regs0->ref1_chroma = 0;
#endif
regs0->audya = GAME_AUD_START;
//switch to game mode 256x240
regs0->dis_pic_id = 0;
regs0->dis_x_start = 0;
regs0->dis_y_start = 0;
regs0->dis_x_size = 256;
regs0->dis_y_size = 236;
regs0->linesize = 2; //RF_LINESIZE_256;
//clear screen
{
char *p;
int x, y;
p = (BYTE *) (SDRAM_BASE + regs0->ref0_luma * 1024);
for(y = 0; y < 240; y++)
{
for(x = 0; x < 256; x++)
p[x] = 0;
p = p + 1024;
}
}
#else
config_framebuffer(MEM_CONFIG_LORES);
regs0->audya = GAME_AUD_START;
regs0->ref0_luma = FRAM0_START;
regs0->ref0_chroma = FRAM0_START;
regs0->ref1_luma = FRAM1_START;
regs0->ref1_chroma = FRAM1_START;
//switch to game mode 256x240
regs0->dis_pic_id = 0;
regs0->dis_x_start = 0;
regs0->dis_y_start = 0;
regs0->dis_x_size = 256;
regs0->dis_y_size = 236;
regs0->linesize = 2; //RF_LINESIZE_256;
//clear screen
{
char *p;
int x, y;
p = (BYTE *) (SDRAM_BASE + FRAM0_START * 1024);
for(y = 0; y < 240; y++)
{
for(x = 0; x < 256; x++)
p[y * 256 + x] = 0;
}
}
#endif
regs0->gpio_master[0] &= (~(0x07 << 0)); //game GPIO 0,2
regs0->game_mode = 5;
for(i = 0; i < 64; i++)
{
regs0->mbuf_fill0 = temp0 = (i << 8) + game_color_index[3 * i];
regs0->mbuf_fill1 = temp1 =
(game_color_index[3 * i + 1] << 8) + game_color_index[3 * i + 2];
}
#if CONFIG==CONFIG_COMBO_SVCD //rbhung 2002.09.09
switch (tv_format)
{
case TV_NTSC:
regs0->dis_offset = (5 << 8) + 20; //Y/X
regs0->h_exp_mode = 0x100 | 0x1b; //0x40;
regs0->v_filter_mode = ((UINT16) (256) | (((INT16) 4) << 10));
break;
#if CONFIG_TV_SYS==PAL_M
case PAL_M:
#endif
case TV_PAL:
regs0->dis_offset = (0 << 8) + 20; //Y/X
regs0->h_exp_mode = 0x100 | 0x1b; //0x40;
regs0->v_filter_mode = ((UINT16) (218) | (((INT16) 4) << 10));
break;
}
#else
switch (tv_format)
{
case TV_NTSC:
regs0->dis_offset = (5 << 8) + 20; //Y/X
regs0->h_exp_mode = 0x100 | 0x1b; //0x40;
regs0->v_filter_mode = ((UINT16) (256) | (((INT16) 4) << 10));
break;
#if CONFIG_TV_SYS==PAL_M
case PAL_M:
#endif
case TV_PAL:
regs0->dis_offset = (20 << 8) + 20; //Y/X //2003.02.24 rbhung for EDO Game
regs0->h_exp_mode = 0x100 | 0x1b; //0x40;
regs0->v_filter_mode = ((UINT16) (256) | (((INT16) 4) << 10));
break;
}
#endif
/*
* config PCM hardware
*/
// set DRAM configuration
#if CONFIG == CONFIG_COMBO_SVCD
RF_VCD_VERSION = 1; // SDRAM
#elif CONFIG == CONFIG_COMBO_VCD
RF_VCD_VERSION = 0; // EDO RAM
#endif
RF_EQ_ON = 0; // turn off EQ hardware
RF_PCM_RAMP_FN = 0; // turn off RAMP hardware
/*
* DAC configuration in RF_PCM_CFG
* b7 : 0/1, data on positive/negative edge of BCK.
* b6-5 : 0/1/2, LRCK period is 32/48/64 BCK.
* b4 : 0/1, low indicates L/R channel.
* b3-2 : 0/1/2/3, 16/18/20/24-bit width.
* b1 : 0/1, data is left/right justified.
* b0 : 0/1, data without/with one BCK delay.
*/
RF_PCM_CFG = 0x32; // for 713
RF_PCM_RESET = 0; // reset PCM related hardware
RF_AU_RESET = 0; // reset AUDIO decoder related hardware
RF_PCM_MODE = MODE_KEYSHIFT; // set KEYSHIFT mode
PCM_set_volume((zhx_volume/8 +1) * AUDIO_VOLUME_AMP); //ZHX 090803
//PCM_set_volume(GAME_INITIAL_VOL * AUDIO_VOLUME_AMP); //rbhung 2002.10.07 Set Default Volume
//KS_set_resample_step(8192);
//KS_set_resample_step(8192/2); // set resampling step to 0.5, do upsampling by the factor of 2.
KS_set_resample_step(8192 / 4); // set resampling step to 0.25, do upsampling by the factor of 4.
KS_cx_set_start(-1, -1);
/* set PCM channel address */
while(RF_RAM2_WRT_DIS);
AU_RAM2[R2_PCML0_ADR] = CH_START >> 3;
while(RF_RAM2_WRT_DIS);
AU_RAM2[R2_PCMR0_ADR] = CH_START >> 3;
while(RF_RAM2_WRT_DIS);
AU_RAM2[R2_PCML1_ADR] = CH_START >> 3;
while(RF_RAM2_WRT_DIS);
AU_RAM2[R2_PCMR1_ADR] = CH_START >> 3;
RF_PCM_BUF_LEN = (PCM_FIFO_SIZE - 32) / 64;
/* 0~5 maps to 44.1kHz, 48kHz, 32kHz, 22.05kHz, 24kHz, 16kHz */
select_Fs(0); // 44.1kHz Fs
//select_Fs(3); // 22.05kHz Fs
}
void game_parameter_init(S_HARDWARE * pHard)
{
pHard->TVMode = 0;
if(cd_type_loaded == CDROM)
{
if(strcmp(file_ext_name(Gmem.gmp3.mp3_trk_now), "GUN") == 0) //rbhung 2002.12.27 for light-gun
pHard->bRunOption = NES_DEBUG_ON|NES_LIGHT_GUN_ON; //NES_GAMEPAD_AB_SWAP for A/B Key Swap
else
pHard->bRunOption = NES_DEBUG_ON; //NES_BREAK_A_START for Gamepad Break Key Setup
}
else
pHard->bRunOption = NES_DEBUG_ON;
//osd
pHard->pRegion0DataStart = 0;
pHard->pRegion1DataStart = 0;
pHard->unRegion0Offset = 0;
pHard->unRegion1Offset = 0;
//audio , 2002/2/8 09:21AM modify parameter for DSP driver
pHard->pPCMStart = (BYTE *) (&(RF_PCM_AMP));
pHard->pPCMEnd = 0;
pHard->PCMLen = 0;
pHard->unVolume = 0;
pHard->unVolumeCurStep = zhx_volume/8+1;//GAME_INITIAL_VOL; //ZHX 090803
pHard->unVolumeMaxStep = 8;
return;
}
/*
define VFD key break id for nes driver, mapping to vfdkey.h
*/
void SetGameBreakKey(S_HARDWARE * pHard)
{
pHard->bBreakIrKey[0] = ir_code(IRC_EJECT); //0x10; //eject
pHard->bBreakIrKey[1] = ir_code(IRC_STOP); //0x14; //stop//jhuang 2002/9/11
pHard->bBreakIrKey[2] = ir_code(IRC_RETURN); //0x53; //return
#ifdef POWER_KEY
pHard->bBreakIrKey[3] = ir_code(IRC_POWER);
#else
pHard->bBreakIrKey[3] = 0xff;
#endif
pHard->bBreakIrKey[4] = lcd_code(IRC_EJECT);/*ZHX 061003*/
pHard->bBreakIrKey[5] = lcd_code(IRC_STOP); /*ZHX 061003*/
pHard->bBreakIrKey[6] = ir_code(IRC_VOLUME_DN); //0x2; //volume--//jhuang 2002/9/11
pHard->bBreakIrKey[7] = ir_code(IRC_VOLUME_UP); //0x3; //volume++//jhuang 2002/9/11
pHard->bBreakIrKey[8] = vfd_code(IRC_EJECT);
pHard->bBreakIrKey[9] = vfd_code(IRC_STOP);
pHard->bBreakIrKey[10] = vfd_code(IRC_RETURN);
pHard->bBreakIrKey[11] = 0xff;
}
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -