game.c
来自「ESS3890+SL原代码(1*16内存)」· C语言 代码 · 共 1,099 行 · 第 1/3 页
C
1,099 行
}#ifdef VGB_CD } else { if(tt){ ret |= (tt&0x0303); /*RIGHT, LEFT*/ ret |= (tt&0x0404)<<1; /*UP*/ ret |= (tt&0x0808)>>1; /*DOWN*/ ret |= (tt&0x1010)<<3; /*START*/ ret |= (tt&0x2020)<<1; /*SELECT*/ ret |= (tt&0xC0C0)>>2; /*AB*/ } ret = ~ret; }#endif /*VGB_CD*/ tt = get_keycode(1); if(tt==STOP_KEY || tt==EJECT_KEY){#ifdef VGB_CD if(gmby_name_id == 0x20) ret = 0x3F; else#endif ret = 0x0C; } return ( ret );}#ifdef SOUND#define PERIOD 25#define GMBY_PERIOD 13#define NOTE_EMPTY(SNDChip) (SNDChip->wp==SNDChip->rp)#define NOTE_NUMBER(SNDChip) ((SNDChip->wp>=SNDChip->rp)? \ (SNDChip->wp-SNDChip->rp): \ (SNDChip->wp+RECORD_NOTES-SNDChip->rp))#define GMBY_SNDVAL_size 20#define GMBY_SNDHIS_size 8#define GMBY_SNDCOE_size 8#define GMBY_SNDVAL_start GMBY_SNDDP_start#define GMBY_SNDCOE_start (GMBY_SNDVAL_start+GMBY_SNDVAL_size)#define GMBY_SNDHIS_start (GMBY_SNDCOE_start+GMBY_SNDCOE_size)#ifdef INES_CDstatic void get_noisetbl(int freq);inline void get_noisetbl(int freq){ int i,value,factor=255; int phase =0; buscon_xfer(r2b, BDMA_USEDX, GMBY_SGB_start, 96, 1); for ( i=0; i<96; i++) { phase += (freq<<1); if ( phase>=44100 ) { phase -= 44100; factor = ((get_random_number(255))&1)?255:-255; } value = (factor<<16)|(factor&0xffff);#if 0 } else { value = factor<<16; phase += freq; if ( phase>=44100 ) { phase -= 44100; factor = ((get_random_number(255))&1)?255:-255; } value |= (factor&0xffff); }#endif put_riscfifo(value); } mvd[gate_control] = flush_r2b; buscon_wait(r2b);}/** NSyncSND() ************************************************//** Flush all accumulated changes by issuing Sound() calls **//** and set the synchronization on/off. The second argument **//** should be GBSND_SYNC/GBSND_ASYNC to set/reset sync, or **//** GBSND_FLUSH to leave sync mode as it is. To emulate **//** noise channel with MIDI drums, OR second argument with **//** GBSND_DRUMS. **//*************************************************************/void NSyncSND(){ register int nn;/*70224/4194304*F_LATCH*/ register int pcm_space,pcm_ptr; P_SND *SNDChip; int *dp; SNDChip = NSNDChip;#ifdef ECHO MIC_service(); #endif /* Update changed channels */ /* check PCM buffer has space */ PCM_update_space(pcm_space); if ( pcm_space >= 1536 ) { if ( NOTE_EMPTY(SNDChip) ) { return; } SNDChip->rp = (SNDChip->rp+1)&(RECORD_NOTES-1); /* generate the pcm value */ dp = (int *)dram(GMBY_SNDVAL_start); dp[5] = (SNDChip->freq[SNDChip->rp][0]); dp[7] = (SNDChip->volume[SNDChip->rp][0]); dp[11] = (SNDChip->freq[SNDChip->rp][1]); dp[13] = (SNDChip->volume[SNDChip->rp][1]); dp[17] = (SNDChip->freq[SNDChip->rp][2]); dp[19] = (SNDChip->volume[SNDChip->rp][2]); dp[1] = (SNDChip->volume[SNDChip->rp][3]); /* if (dp[1]==510) dp[1]=0; */ VP_xfer(7*NCMDQ_VP_xfer, VPCMD_W_DP, 0, VPDMA_INC1+VPDMA_USEDX, GMBY_SNDVAL_start, GMBY_SNDVAL_size+GMBY_SNDCOE_size, 1);#if 0 if ( dp[5]==172 && dp[7]==208 && !py_start ) { py_start = 1; py_cnt = 0; py_ptr = (int*)dram(GMBY_SGB_start+400); } if ( py_start ) { py_ptr[py_cnt] = dp[5]; py_ptr[py_cnt+1] = dp[7]; py_cnt+=2; if ( py_cnt>=256 ) BREAKPOINT(100); }#endif pcm_ptr = PCM_raw_wrptr; for (nn = 0; nn < 6; nn++) { if ( dp[1]!=0 ) {#if 0 lowb = get_random_number(255); hib = /*get_random_number(28)*/lowb&0x0F; tbl_ptr = (hib<<8) + lowb; VP_xfer(0, VPCMD_W_DPCM, 0, VPDMA_INC1+VPDMA_USEDX, GMBY_SGB_start+tbl_ptr, 96, 1);#else get_noisetbl(SNDChip->freq[SNDChip->rp][3]); VP_xfer(0, VPCMD_W_DPCM, 0, VPDMA_INC1+VPDMA_USEDX, GMBY_SGB_start, 96, 1);#endif } VP_xfer(0, VPCMD_W_DPCM, 368, 0, GMBY_SNDHIS_start, GMBY_SNDHIS_size, 1); if ( nn==0 ) { VP_ucode(0, syncsnd); } else { VP_ucode(0, rsyncsnd); } wait4l_only; wait4l_only; VP_xfer(0, VPCMD_R_DPCM, 560, 0, GMBY_SNDHIS_start, GMBY_SNDHIS_size, 1); VP_xfer(0, VPCMD_R_DP, 0, 0, pcm_ptr, 192, 1); BUF_advance_ptr(pcm_ptr,192,PCM); VP_xfer_wait(); } VP_xfer(0, VPCMD_R_DP, 384, VPDMA_INC1+VPDMA_USEDX, GMBY_SNDVAL_start, GMBY_SNDVAL_size, 1); PCM_raw_wrptr = pcm_ptr; BUF_advance_ptr(PCM_raw_rdptr,1152,PCM);#ifdef SPATIAL BUF_advance_ptr(SPA_wrptr,1152,PCM);#endif BUF_advance_ptr(PCM_wrptr,1152,PCM); VP_xfer_wait(); }}/* #define OLD_SND *//** SoundLoop() **********************************************//** Update sound parameters. This function has to be called **//** with SND_UPDATE frequency. **//*************************************************************/int SoundLoop(int mS){ int I, J; int notes,times=0; P_SND *SNDChip; SNDChip = NSNDChip; do { /* now record the note */ notes = NOTE_NUMBER(SNDChip); if ( (notes==0) || ((times<2)&&(notes<(RECORD_NOTES-1))) ) { for ( J=0; J<GBSND_CHANNELS; J++ ) { if ( J!=3 && SNDChip->Freq[J]>=11000 ) { /* SNDChip->freq[SNDChip->wp][J] = 0; */ SNDChip->volume[SNDChip->wp][J] = 0; } else { SNDChip->freq[SNDChip->wp][J] = (SNDChip->Freq[J]); SNDChip->volume[SNDChip->wp][J] = (SNDChip->SND[21]&(0x01<<J))? \ (SNDChip->Volume[J]):0;#define RMNOISE#ifdef RMNOISE if ( J==1 && (SNDChip->volume[SNDChip->wp][J]>245) && SNDChip->freq[SNDChip->wp][J]<=65 ) { /* SNDChip->freq[SNDChip->wp][J] = 60; */ if (SNDChip->motor_cnt==0) SNDChip->volume[SNDChip->wp][J]=512 ; else SNDChip->volume[SNDChip->wp][J] = 0; SNDChip->motor_cnt++; if ( SNDChip->motor_cnt>=4 ) SNDChip->motor_cnt=0; }#endif } } SNDChip->wp = (SNDChip->wp+1)&(RECORD_NOTES-1); mS -= PERIOD; } times++; if ( notes>=(RECORD_NOTES-1) ) mS -= PERIOD; NSyncSND(); } while((mS>=PERIOD)&&(times<8)) ; for(J=0;J<4;J++) if(SNDChip->Freq[J]&&SNDChip->Volume[J]) { if(SNDChip->FSweep[J]) { I=SNDChip->FCount[J]+SNDChip->FSweep[J]; if ( I>2047 ) I=2047; if ( I>8 ){ SNDChip->Freq[J]=SND_CONSTANT/(I+1);#ifndef OLD_SND SNDChip->FSweep[J]=I*SNDChip->FSweep[J]/SNDChip->FCount[J];#endif SNDChip->FCount[J]=I; } } if(SNDChip->VSweep[J]) if(SNDChip->VCount[J]<SNDChip->VSweep[J]) SNDChip->VCount[J]++; else { SNDChip->Volume[J]=0; } if(SNDChip->VDecay[J]) { I=SNDChip->Volume[J]-SNDChip->VDecay[J]; SNDChip->Volume[J]=I<0? 0:I; } } return mS;}int GM_get_timer(){ int elapsed; if(NSNDChip->lasttimer) elapsed = mvd[riface_timer2]-NSNDChip->lasttimer; NSNDChip->lasttimer = mvd[riface_timer2]; if ( elapsed<0 ) elapsed += -timer2_period; elapsed = elapsed /81000 ; NSNDChip->deltatime = SoundLoop(elapsed+NSNDChip->deltatime); return 0;}#endif /*INES_CD*/int CD_InitSound(int Rate){ int I,r1,r2; unsigned int * pdest = (unsigned int *) dram(GMBY_SNDCOE_start); for (I = gmby_filter_id*8; I < (gmby_filter_id*8+8); I++) *pdest++ = bp_gbsnd[I];#ifdef VGB_CD if( gmby_name_id == 0x20) { /*VGB*/ VSNDChip = (VGB_SND *)dram_cached(GMBY_SNDSTK_start); /* Trash sound if it was initialized */ CD_TrashSound(); VSNDChip->SOUND_amplify = 8; } #endif#ifdef INES_CD if(gmby_name_id == 0x60) { dram_clear(INES_SNDLength_start, 32); P_Lengths = (int *) dram_cached(INES_SNDLength_start); Noise_freq = (int *)dram_cached(INES_SNDLength_start+32); RISC_to_dram(INES_SNDLength_start, (int *)NES_Lengths, 32); RISC_to_dram(INES_SNDLength_start+32, (int *)NES_Noise_freq, 16); NSNDChip = (P_SND *)dram_cached(GMBY_SNDSTK_start); /* Trash sound if it was initialized */ PCM_clear_buffer(); /* NSNDChip->SOUND_amplify = 8; */ NSNDChip->motor_cnt = 0; }#endif return Rate;}/** TrashSound() *********************************************//** Shut down sound. **//*************************************************************/void CD_TrashSound(void){ PCM_clear_buffer();}#endif /*SOUND*/extern void VCX_service();int gm_data_start;void copy_gm_data(int *gm_rom){ int i, *cmdaddr, cmd, *to, *from; unsigned char *temp; int data_from, data_to, data_size, bss_from, bss_size; int text_from, text_size; int gm_text_start; temp = (unsigned char *)gm_rom; cmdaddr = (int *)(temp + *(gm_rom+1)); data_from = *(cmdaddr+1); data_to = *(cmdaddr+2); data_size = *(cmdaddr+3); cmd = *(cmdaddr+4); bss_from = *(cmdaddr+5); bss_size = *(cmdaddr+6); cmd = *(cmdaddr+8); text_from = *(cmdaddr+9); text_size = *(cmdaddr+11); gm_data_start = GMBY_globals_start; from = (int *)(temp + data_from); to = (int *)gm_data_start; for(i=0; i<data_size; i++) *(to+i) = *(from+i); to = (int *)(bss_from+gm_data_start); for (i=0;i<bss_size;i++) *(to+i) = 0; /* set r25 */ asm("ld _gm_data_start[r0],r25"); gm_text_start = dram_cached(GMBY_CODE_start); from = (int *)(temp + text_from); to = (int *)gm_text_start; for(i=0; i<text_size; i++)*(to+i) = *(from+i); /*move up GAME ROM data */ if(!is_ess_game || gmby_name_id == 0x30 || gmby_name_id == 0x20) { int size; to = (int *)dram_cached(GMBY_ROM_start); if(gmby_name_id == 0x20) from = to + 0x4000; else from = to + 0x3000; temp = (unsigned char *)from; if(gmby_name_id == 0x20 || gmby_name_id == 0x30){ size = temp[0x148]>>4; size = size?(2<<size):0; size += 2<<(temp[0x148]&0x0F); size = size *4096; gmby_name_id = 0x20; } else size = (temp[4]*4096+temp[5]*2048) + 4; for(i=0; i<size; i++) *(to+i) = *(from +i); } UTIL_flushcache(0x30, 8192);}void GM_copy_rom(int *gm_rom);volatile int gm_r22_seg;void GM_copy_rom(int *gm_rom){ int gm_text_start;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?