📄 system.c
字号:
/*
Copyright (C) 1998, 1999, 2000 Charles Mac Donald
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
*/
#include "shared.h"
t_bitmap bitmap;
t_cart cart;
t_snd snd;
t_input input;
FM_OPL *ym3812;
void system_init(int rate, int frequency)
{
/* Initialize the VDP emulation */
vdp_init();
/* Initialize the SMS emulation */
sms_init();
/* Initialize the look-up tables and related data */
render_init();
/* Enable sound emulation if the sample rate was specified */
audio_init(rate, frequency);
/* Don't save SRAM by default */
sms.save = 0;
/* Clear emulated button state */
memset(&input, 0, sizeof(t_input));
}
void audio_init(int rate, int frequency)
{
/* Clear sound context */
memset(&snd, 0, sizeof(t_snd));
/* Reset logging data */
snd.log = 0;
snd.callback = NULL;
/* Oops.. sound is disabled */
if(!rate) return;
/* Calculate buffer size in samples */
snd.bufsize = (rate / frequency);
/* Sound output */
snd.buffer = (signed short int *)malloc(snd.bufsize * 4);
if(!snd.buffer) return;
/* YM3812/YM2413 sound stream */
snd.fm_buffer = (signed short int *)malloc(snd.bufsize * 2);
if(!snd.fm_buffer) return;
/* SN76489 sound stream */
snd.psg_buffer[0] = (signed short int *)malloc(snd.bufsize * 2);
snd.psg_buffer[1] = (signed short int *)malloc(snd.bufsize * 2);
if(!snd.psg_buffer[0] || !snd.psg_buffer[1]) return;
/* Set up SN76489 emulation */
SN76496_init(0, MASTER_CLOCK, 255, rate);
/* Set up YM3812 emulation */
ym3812 = OPLCreate(OPL_TYPE_YM3812, MASTER_CLOCK, rate);
if(!ym3812) return;
/* Set up YM2413 emulation */
ym2413_init(1);
/* Inform other functions that we can use sound */
snd.enabled = 1;
}
void system_shutdown(void)
{
if(snd.enabled) OPLDestroy(ym3812);
}
void system_reset(void)
{
cpu_reset();
vdp_reset();
sms_reset();
render_reset();
LoadSRAM();
if(snd.enabled)
{
OPLResetChip(ym3812);
ym2413_reset(0);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -