📄 dos.c
字号:
/* Check player 2 joystick */
if(joy[1].stick[0].axis[1].d1) input.pad[1] |= INPUT_UP;
else
if(joy[1].stick[0].axis[1].d2) input.pad[1] |= INPUT_DOWN;
if(joy[1].stick[0].axis[0].d1) input.pad[1] |= INPUT_LEFT;
else
if(joy[1].stick[0].axis[0].d1) input.pad[1] |= INPUT_RIGHT;
if(joy[1].button[0].b) input.pad[1] |= INPUT_BUTTON2;
if(joy[1].button[1].b) input.pad[1] |= INPUT_BUTTON1;
}
}
}
/* Check user interface keys */
void check_ui_keys(void)
{
/* Frame skip keys */
if(check_key(KEY_F1)) { frame_skip = 1; add_msg("Frame skip disabled"); };
if(check_key(KEY_F2)) { frame_skip = 2; add_msg("Frame skip set to 1"); };
if(check_key(KEY_F3)) { frame_skip = 3; add_msg("Frame skip set to 2"); };
if(check_key(KEY_F4)) { frame_skip = 4; add_msg("Frame skip set to 3"); };
/* State save/load keys */
if(check_key(KEY_F5)) { if(save_state()) add_msg("State saved to slot %d", state_slot); };
if(check_key(KEY_F6)) { state_slot = (state_slot + 1) % 10; add_msg("Slot %d", state_slot); };
if(check_key(KEY_F7)) { if(load_state()) add_msg("State loaded from slot %d", state_slot); };
/* Screen snapshot */
if(check_key(KEY_F8))
{
char name[0x100];
PALETTE snap_pal;
BITMAP *snap_bmp = create_bitmap_ex(option.video_depth, BMP_WIDTH, BMP_HEIGHT);
if(snap_bmp)
{
int i;
/* Get current palette */
get_palette(snap_pal);
/* Remove unused palette entries */
for(i = 0x20; i < 0xFE; i += 1)
snap_pal[i].r = snap_pal[i].g = snap_pal[i].b = 0x00;
/* Clip image */
blit(sms_bmp, snap_bmp, BMP_X_OFFSET, BMP_Y_OFFSET, 0, 0, BMP_WIDTH, BMP_HEIGHT);
/* Generate file name */
sprintf(name, "snap%04d.pcx", snap_count);
/* Remove unused bits */
if(option.video_depth == 8)
{
int x, y;
for(y = 0; y < BMP_HEIGHT; y += 1)
for(x = 0; x < BMP_WIDTH; x += 1)
putpixel(snap_bmp, x, y, getpixel(snap_bmp, x, y) & PIXEL_MASK);
}
/* Save snapshot in PCX format */
save_pcx(name, snap_bmp, snap_pal);
/* Deallocate temporary bitmap */
destroy_bitmap(snap_bmp);
/* Bump snapshot counter */
snap_count = (snap_count + 1) & 0xFFFF;
/* Display results */
add_msg("Saved screen to %s", name);
}
}
/* FPS meter toggle */
if(check_key(KEY_F9))
{
option.fps ^= 1;
add_msg("FPS meter %s", vdp.limit ? "on" : "off");
}
/* Speed throttling */
if(check_key(KEY_F10))
{
if(!option.sound)
{
option.throttle ^= 1;
add_msg("Speed throttling %s", option.throttle ? "on" : "off");
}
}
/* Speed throttling */
if(check_key(KEY_F11))
{
option.vsync ^= 1;
add_msg("VSync %s", option.vsync ? "on" : "off");
}
/* Sprite limit toggle */
if(check_key(KEY_F12))
{
vdp.limit ^= 1;
add_msg("Sprite limit %s", vdp.limit ? "on" : "off");
}
if(check_key(KEY_BACKSPACE))
{
if(music_log)
{
snd.log = 0;
fclose(music_log);
music_log = NULL;
add_msg("Stopped logging sound.");
}
else
{
char name[0x100];
char ext[0x100];
sprintf(ext, "%02d.ssl", music_log_count);
strcpy(name, game_name);
strcpy(strrchr(name, '.'), ext);
snd.log = 1;
music_log_count += 1;
music_log = fopen(name, "wb");
add_msg("Logging `%s'", name);
}
}
/* Exit keys */
if(key[KEY_ESC] || key[KEY_END]) exit_flag = 1;
}
/* Update audio */
void update_audio(void)
{
if(!option.sound) return;
osd_play_streamed_sample_16(0, &snd.buffer[0][0], snd.bufsize * 2, option.sndrate, 60, -100);
osd_play_streamed_sample_16(1, &snd.buffer[1][0], snd.bufsize * 2, option.sndrate, 60, 100);
}
/* Update video */
void update_video(void)
{
/* Wait for VSync */
if(option.vsync) vsync();
/* Update the palette */
if(option.video_depth == 8) update_palette();
/* Use the blur effect */
if(option.blur)
{
if(IS_GG)
blur(&sms_bmp->line[24][96], 160, 144, 192);
else
blur(&sms_bmp->line[0][0], 256, 192, 0);
}
if(option.fps) msg_print(2, 2, "%d", frame_rate);
if(msg_enable) msg_print(4, BMP_HEIGHT - 12, "%s", msg);
blitter_proc(sms_bmp, screen);
}
/* Update VGA palette hardware */
void update_palette(void)
{
RGB color;
int index;
if(bitmap.pal.update == 0) return;
for(index = 0; index < PALETTE_SIZE; index += 1)
{
if(bitmap.pal.dirty[index])
{
color.r = (bitmap.pal.color[index][0] >> 2);
color.g = (bitmap.pal.color[index][1] >> 2);
color.b = (bitmap.pal.color[index][2] >> 2);
set_color(0x00 | index, &color);
set_color(0x20 | index, &color);
set_color(0x40 | index, &color);
}
}
bitmap.pal.update = 0;
memset(bitmap.pal.dirty, 0, PALETTE_SIZE);
}
/* Load a game file */
int load_rom(char *filename)
{
int size;
if(stricmp(strrchr(filename, '.'), ".zip") == 0)
{
char name[0x100];
cart.rom = loadzip(filename, name, &size);
if(!cart.rom) return (0);
printf("Loaded `%s', (%d bytes) from archive `%s'\n", name, size, filename);
strcpy(game_name, name);
/* Take care of image header, if present */
if((size / 512) & 1)
{
size -= 512;
memmove(cart.rom, cart.rom + 512, size);
}
cart.pages = (size / 0x4000);
}
else
{
FILE *fd = NULL;
fd = fopen(filename, "rb");
if(!fd) return (0);
/* Seek to end of file, and get size */
fseek(fd, 0, SEEK_END);
size = ftell(fd);
fseek(fd, 0, SEEK_SET);
/* Don't load games smaller than 32k */
if(size < 0x8000) return (0);
/* Take care of image header, if present */
if((size / 512) & 1)
{
size -= 512;
fseek(fd, 512, SEEK_SET);
}
cart.pages = (size / 0x4000);
cart.rom = malloc(size);
if(!cart.rom) return (0);
fread(cart.rom, size, 1, fd);
fclose(fd);
}
/* Figure out game image type */
if(stricmp(strrchr(game_name, '.'), ".gg") == 0)
cart.type = TYPE_GG;
else
cart.type = TYPE_SMS;
return (1);
}
void system_load_sram(void)
{
load_sram();
}
/* Load SRAM data */
void load_sram(void)
{
char name[0x100];
FILE *fd;
strcpy(name, game_name);
strcpy(strrchr(name, '.'), ".sav");
fd = fopen(name, "rb");
if(fd)
{
sms.save = 1;
fread(sms.sram, 0x8000, 1, fd);
fclose(fd);
}
}
/* Save SRAM data */
void save_sram(void)
{
if(sms.save)
{
char name[0x100];
FILE *fd = NULL;
strcpy(name, game_name);
strcpy(strrchr(name, '.'), ".sav");
fd = fopen(name, "wb");
if(fd)
{
fwrite(sms.sram, 0x8000, 1, fd);
fclose(fd);
}
}
}
/* Load system state */
int load_state(void)
{
char name[0x100];
FILE *fd = NULL;
strcpy(name, game_name);
sprintf(strrchr(name, '.'), ".st%d", state_slot);
fd = fopen(name, "rb");
if(!fd) return (0);
system_load_state(fd);
fclose(fd);
return (1);
}
/* Save system state */
int save_state(void)
{
char name[0x100];
FILE *fd = NULL;
strcpy(name, game_name);
sprintf(strrchr(name, '.'), ".st%d", state_slot);
fd = fopen(name, "wb");
if(!fd) return (0);
system_save_state(fd);
fclose(fd);
return(1);
}
void msg_print(int x, int y, char *fmt, ...)
{
int i = BMP_X_OFFSET;
int j = BMP_Y_OFFSET;
va_list ap;
char token[0x100];
char str[0x100];
strcpy(str, "\0");
va_start(ap, fmt);
vsprintf(token, fmt, ap);
strcat(str, token);
va_end(ap);
textprintf(sms_bmp, font, i+x+1, j+y , bg, "%s", str);
textprintf(sms_bmp, font, i+x-1, j+y , bg, "%s", str);
textprintf(sms_bmp, font, i+x , j+y+1, bg, "%s", str);
textprintf(sms_bmp, font, i+x , j+y-1, bg, "%s", str);
textprintf(sms_bmp, font, i+x , j+y , fg, "%s", str);
}
void add_msg(char *fmt, ...)
{
va_list ap;
char token[0x100];
msg_enable = FRAMES_PER_SECOND;
strcpy(msg, "\0");
va_start(ap, fmt);
vsprintf(token, fmt, ap);
strcat(msg, token);
va_end(ap);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -