📄 msdos.cpp
字号:
old_joy2_down = joy2_down; old_joy2_b1 = joy2_b1; old_joy2_b2 = joy2_b2; }}#endifvoid S9xSetPalette (){ uint16 Brightness = IPPU.MaxBrightness * 138; PALLETE p; for (int i = 0; i < 256; i++) { p[i].r = (((PPU.CGDATA [i] >> 0) & 0x1F) * Brightness) >> 10; p[i].g = (((PPU.CGDATA [i] >> 5) & 0x1F) * Brightness) >> 10; p[i].b = (((PPU.CGDATA [i] >> 10) & 0x1F) * Brightness) >> 10; } set_palette_range (p, 0, 255, FALSE);}void S9xProcessEvents (bool8 block){ static char prev_keystate[128]; extern volatile char key[128];#ifdef GRIP_SUPPORT ReadGrip ();#endif#ifdef SIDEWINDER_SUPPORT if (num_sidewinders) ReadSidewinders ();#endif char key1[128]; char *keystate = (char *) key1; int fn = 0; memcpy (key1, (char *) key, sizeof (key1));#undef KEY_DOWN#define KEY_DOWN(a) (keystate[a])#undef KEY_PRESS#define KEY_PRESS(a) (keystate[a] && !prev_keystate[a])#undef KEY_WASPRESSED#define KEY_WASPRESSED(a) (prev_keystate[a] && !keystate[a])#undef PROCESS_KEY#define PROCESS_KEY(k, b, v)\if (KEY_PRESS(k)) b |= v;\if (KEY_WASPRESSED(k)) b &= ~v; if (KEY_PRESS (SCANCODE_ESCAPE)) S9xExit (); // Joypad 1: PROCESS_KEY(SCANCODE_K, joypads [0], SNES_RIGHT_MASK) PROCESS_KEY(SCANCODE_CURSORRIGHT, joypads [0], SNES_RIGHT_MASK) PROCESS_KEY(SCANCODE_H, joypads [0], SNES_LEFT_MASK) PROCESS_KEY(SCANCODE_CURSORLEFT, joypads [0], SNES_LEFT_MASK) PROCESS_KEY(SCANCODE_N, joypads [0], SNES_DOWN_MASK) PROCESS_KEY(SCANCODE_J, joypads [0], SNES_DOWN_MASK) PROCESS_KEY(SCANCODE_CURSORDOWN, joypads [0], SNES_DOWN_MASK) PROCESS_KEY(SCANCODE_U, joypads [0], SNES_UP_MASK) PROCESS_KEY(SCANCODE_CURSORUP, joypads [0], SNES_UP_MASK) PROCESS_KEY(SCANCODE_ENTER, joypads [0], SNES_START_MASK) PROCESS_KEY(SCANCODE_SPACE, joypads [0], SNES_SELECT_MASK) PROCESS_KEY(SCANCODE_A, joypads [0], SNES_TL_MASK) PROCESS_KEY(SCANCODE_V, joypads [0], SNES_TL_MASK) PROCESS_KEY(SCANCODE_Q, joypads [0], SNES_TL_MASK) PROCESS_KEY(SCANCODE_Z, joypads [0], SNES_TR_MASK) PROCESS_KEY(SCANCODE_B, joypads [0], SNES_TR_MASK) PROCESS_KEY(SCANCODE_W, joypads [0], SNES_TR_MASK) PROCESS_KEY(SCANCODE_S, joypads [0], SNES_X_MASK) PROCESS_KEY(SCANCODE_M, joypads [0], SNES_X_MASK) PROCESS_KEY(SCANCODE_E, joypads [0], SNES_X_MASK) PROCESS_KEY(SCANCODE_X, joypads [0], SNES_Y_MASK) PROCESS_KEY(SCANCODE_COMMA, joypads [0], SNES_Y_MASK) PROCESS_KEY(SCANCODE_R, joypads [0], SNES_Y_MASK) PROCESS_KEY(SCANCODE_D, joypads [0], SNES_A_MASK) PROCESS_KEY(SCANCODE_PERIOD, joypads [0], SNES_A_MASK) PROCESS_KEY(SCANCODE_T, joypads [0], SNES_A_MASK) PROCESS_KEY(SCANCODE_C, joypads [0], SNES_B_MASK) PROCESS_KEY(SCANCODE_SLASH, joypads [0], SNES_B_MASK) PROCESS_KEY(SCANCODE_Y, joypads [0], SNES_B_MASK) // Joypad 2:// PROCESS_KEY(SCANCODE_CURSORRIGHT, joypads [1], SNES_RIGHT_MASK)// PROCESS_KEY(SCANCODE_CURSORLEFT, joypads [1], SNES_LEFT_MASK)// PROCESS_KEY(SCANCODE_CURSORDOWN, joypads [1], SNES_DOWN_MASK)// PROCESS_KEY(SCANCODE_CURSORUP, joypads [1], SNES_UP_MASK) PROCESS_KEY(SCANCODE_KEYPADENTER, joypads [0], SNES_START_MASK) PROCESS_KEY(SCANCODE_KEYPADPLUS, joypads [0], SNES_SELECT_MASK) PROCESS_KEY(SCANCODE_INSERT, joypads [0], SNES_X_MASK) PROCESS_KEY(SCANCODE_REMOVE, joypads [0], SNES_Y_MASK) PROCESS_KEY(SCANCODE_HOME, joypads [0], SNES_A_MASK) PROCESS_KEY(SCANCODE_END, joypads [0], SNES_B_MASK) PROCESS_KEY(SCANCODE_PAGEUP, joypads [0], SNES_TL_MASK) PROCESS_KEY(SCANCODE_PAGEDOWN, joypads [0], SNES_TR_MASK) if (KEY_PRESS (SCANCODE_0)) Settings.DisableHDMA = !Settings.DisableHDMA; if (KEY_PRESS (SCANCODE_1)) PPU.BG_Forced ^= 1; if (KEY_PRESS (SCANCODE_2)) PPU.BG_Forced ^= 2; if (KEY_PRESS (SCANCODE_3)) PPU.BG_Forced ^= 4; if (KEY_PRESS (SCANCODE_4)) PPU.BG_Forced ^= 8; if (KEY_PRESS (SCANCODE_5)) PPU.BG_Forced ^= 16; if (KEY_PRESS (SCANCODE_6)) Settings.SwapJoypads = !Settings.SwapJoypads; if (KEY_PRESS (SCANCODE_7)) { if (IPPU.Controller == SNES_SUPERSCOPE) show_mouse (NULL); S9xNextController (); if (IPPU.Controller == SNES_SUPERSCOPE) show_mouse (screen); } if (KEY_PRESS (SCANCODE_8)) Settings.BGLayering = !Settings.BGLayering; if (KEY_PRESS (SCANCODE_9)) if (Settings.SixteenBit) Settings.Transparency = !Settings.Transparency; if (KEY_PRESS(SCANCODE_TAB)) superscope_turbo = !superscope_turbo; PROCESS_KEY(SCANCODE_GRAVE, superscope_pause, 1); if (KEY_PRESS(SCANCODE_F1)) fn = 1; if (KEY_PRESS(SCANCODE_F2)) fn = 2; if (KEY_PRESS(SCANCODE_F3)) fn = 3; if (KEY_PRESS(SCANCODE_F4)) fn = 4; if (KEY_PRESS(SCANCODE_F5)) fn = 5; if (KEY_PRESS(SCANCODE_F6)) fn = 6; if (KEY_PRESS(SCANCODE_F7)) fn = 7; if (KEY_PRESS(SCANCODE_F8)) fn = 8; if (KEY_PRESS(SCANCODE_F9)) fn = 9; if (KEY_PRESS(SCANCODE_F10)) fn = 10; if (KEY_PRESS(SCANCODE_F11)) fn = 11; if (KEY_PRESS(SCANCODE_F12)) fn = 12; if (fn > 0) { if (!KEY_DOWN(SCANCODE_LEFTALT) && !KEY_DOWN(SCANCODE_LEFTSHIFT)) { if (fn == 11) { S9xLoadSnapshot (S9xChooseFilename (TRUE)); } else if (fn == 12) { Snapshot (S9xChooseFilename (FALSE)); } else { char def [PATH_MAX]; char filename [PATH_MAX]; char drive [_MAX_DRIVE]; char dir [_MAX_DIR]; char ext [_MAX_EXT]; _splitpath (Memory.ROMFilename, drive, dir, def, ext); sprintf (filename, "%s%s%s.%03d", S9xGetSnapshotDirectory (), SLASH_STR, def, fn - 1); S9xLoadSnapshot (filename); } } else if (KEY_DOWN(SCANCODE_LEFTALT)) { if (fn >= 4) S9xToggleSoundChannel (fn - 4);#ifdef DEBUGGER else if (fn == 1) CPU.Flags |= DEBUG_MODE_FLAG;#endif else if (fn == 2) S9xLoadSnapshot (S9xChooseFilename (TRUE)); else if (fn == 3) Snapshot (S9xChooseFilename (FALSE)); } else { char def [PATH_MAX]; char filename [PATH_MAX]; char drive [_MAX_DRIVE]; char dir [_MAX_DIR]; char ext [_MAX_EXT]; _splitpath (Memory.ROMFilename, drive, dir, def, ext); sprintf (filename, "%s%s%s.%03d", S9xGetSnapshotDirectory (), SLASH_STR, def, fn - 1); Snapshot (filename); } } if (KEY_PRESS (SCANCODE_BREAK) || KEY_PRESS (SCANCODE_BREAK_ALTERNATIVE) || KEY_PRESS (SCANCODE_SCROLLLOCK)) Settings.Paused ^= 1; if (KEY_PRESS (SCANCODE_PRINTSCREEN)) SaveScreenshot (); if (KEY_PRESS (SCANCODE_MINUS)) { if (Settings.SkipFrames <= 1) Settings.SkipFrames = AUTO_FRAMERATE; else if (Settings.SkipFrames != AUTO_FRAMERATE) Settings.SkipFrames--; } if (KEY_PRESS (SCANCODE_EQUAL)) { if (Settings.SkipFrames == AUTO_FRAMERATE) Settings.SkipFrames = 1; else if (Settings.SkipFrames < 10) Settings.SkipFrames++; } memcpy (prev_keystate, keystate, sizeof (prev_keystate)); if (block) __dpmi_yield ();}void S9xSetTitle (const char *title){}void S9xPutImage (int width, int height){ //extern volatile char key[128]; if (IPPU.Controller == SNES_SUPERSCOPE) scare_mouse (); if (wait_for_vsync) { vsync (); //while ((inportb (0x3da) & 8) && !key [SCANCODE_ESCAPE]); //while (!(inportb (0x3da) & 8) && !key [SCANCODE_ESCAPE]); } if (interpolate && Settings.SixteenBit && screen_width >= 512 && height < 240) { void TVMode (uint8 *srcPtr, uint32 srcPitch, uint8 *deltaPtr, BITMAP *dstBitmap, int width, int height); if (width != last_rendered_width || height != last_rendered_height) memset (Delta, 0xff, (IMAGE_WIDTH + 2) * IMAGE_HEIGHT * 2); TVMode (GFX.Screen, GFX.Pitch, Delta, screen, width, height); } else if (stretch) { stretch_blit (off_screen, screen, 0, 0, width, height, 0, 0, screen_width, screen_height); mouse_offset_x = 0; mouse_offset_y = 0; mouse_scale_h = screen_width / (double) width; mouse_scale_v = screen_height / (double) height; } else if (Settings.SupportHiRes) { if (screen_width < width || screen_height < height) { stretch_blit (off_screen, screen, 0, 0, width, height, 0, 0, screen_width, screen_height); mouse_offset_x = 0; mouse_offset_y = 0; mouse_scale_h = screen_width / (double) width; mouse_scale_v = screen_height / (double) height; } else { int h = height; int w = width; if (h < 240) h <<= 1; if (w == 256) w = 512; if (w > screen_width) w = screen_width; if (h > screen_height) h = screen_height; mouse_offset_x = (screen_width - w) >> 1; mouse_offset_y = (screen_height - h) >> 1; stretch_blit (off_screen, screen, 0, 0, width, height, mouse_offset_x, mouse_offset_y, w, h); mouse_scale_h = w / (double) width; mouse_scale_v = h / (double) height; } } else { if (modes [mode].mode == GFX_VGA && screen_width == 256) { int y_buff; int y_start; int y_end; int x_start = (screen_width - width) >> 1; mouse_offset_x = 0; mouse_scale_h = 1.0; mouse_scale_v = 1.0; if (screen_height >= height) { mouse_offset_y = y_start = (screen_height - height) >> 1; y_end = y_start + height; y_buff = 0; } else { y_start = 0; y_end = screen_height; y_buff = (height - screen_height) >> 1; } uint8 *s = GFX.Screen + screen_pitch * y_buff; uint8 *p = screen->line[0] + screen->w * y_start + x_start; for (int y = y_start; y < y_end; y++, s += screen_pitch, p += screen->w) movedata (_my_ds(), (unsigned int) s, (unsigned int) screen->seg, (unsigned int) p, width); } else { mouse_offset_x = (screen_width - width) >> 1; mouse_offset_y = (screen_height - height) >> 1; mouse_scale_h = 1.0; mouse_scale_v = 1.0; blit (off_screen, screen, 0, 0, mouse_offset_x, mouse_offset_y, width, height); } } if (IPPU.Controller == SNES_SUPERSCOPE) unscare_mouse (); last_rendered_width = width; last_rendered_height = height;}const char *S9xSelectFilename (const char *def, const char *dir1, const char *ext1, const char *title){ static char path [PATH_MAX]; char buffer [PATH_MAX]; S9xTextMode (); printf ("\n%s (default: %s): ", title, def); fflush (stdout); if (fgets (buffer, sizeof (buffer) - 1, stdin)) { char *p = buffer; while (isspace (*p) || *p == '\n') p++; if (!*p) { strcpy (buffer, def); p = buffer; } char *q = strrchr (p, '\n'); if (q) *q = 0; char fname [PATH_MAX]; char drive [_MAX_DRIVE]; char dir [_MAX_DIR]; char ext [_MAX_EXT]; _splitpath (p, drive, dir, fname, ext); _makepath (path, drive, *dir ? dir : dir1, fname, *ext ? ext : ext1); S9xGraphicsMode (); return (path); } S9xGraphicsMode (); return (NULL);}void outReg(Register r){ switch (r.port) { /* First handle special cases: */ case ATTRCON_ADDR: /* reset read/write flip-flop */ inportb (STATUS_ADDR); /* ensure VGA output is enabled */ outportb (ATTRCON_ADDR, r.index | 0x20); outportb (ATTRCON_ADDR, r.value); break; case MISC_ADDR: case VGAENABLE_ADDR: /* directly to the port */ outportb (r.port, r.value); break; case SEQ_ADDR: case GRACON_ADDR: case CRTC_ADDR: default: /* index to port */ outportb (r.port, r.index); /* value to port+1 */ outportb (r.port + 1, r.value); break; }}/* readyVgaRegs() does the initialization to make the VGA ready to accept any combination of configuration register settings. This involves enabling writes to index 0 to 7 of the CRT controller (port 0x3d4), by clearing the most significant bit (bit 7) of index 0x11.*/void readyVgaRegs (void){ int v; outportb (0x3d4, 0x11); v = inportb (0x3d5) & 0x7f; outportb (0x3d4, 0x11); outportb (0x3d5, v);}/* outRegArray sets n registers according to the array pointed to by r. First, indexes 0-7 of the CRT controller are enabled for writing.*/void outRegArray (Register *r, int n){ readyVgaRegs (); while (n--) outReg (*r++);}void S9xExtraUsage (){ printf ("\-m num Screen mode:\n\ 0 - 320x240 (modex, slower), 1 - 320x200 (faster but clipped)\n\ 2 - 256x256 (fastest but non-standard), 3-6 - 640x480, 7 - 640x400\n\ 8 - 800x600, 9 - 320x240 16 bit, 10 - 640x480 16 bit\n"); printf ("\-scale Scale SNES screen to fit S-VGA screen\n");}void S9xParseDisplayArg (char **argv, int &ind, int){ if ((strcmp (argv [ind], "-m") == 0 || strcasecmp (argv [ind], "-mode") == 0 ) && argv [ind + 1]) { mode = atoi (argv [++ind]); if (mode >= sizeof (modes) / sizeof (modes [0])) mode = 0; } else if (strcasecmp (argv [ind], "-scale") == 0 || strcasecmp (argv [ind], "-sc") == 0) stretch = TRUE; else if (strcasecmp (argv [ind], "-w") == 0) wait_for_vsync = TRUE; else if (strcasecmp (argv [ind], "-y") == 0) { Settings.SixteenBit = TRUE; Settings.SupportHiRes = TRUE; Settings.Transparency = TRUE; interpolate = TRUE; } else S9xUsage ();}volatile uint32 FrameTimer = 0;static void TimerInterrupt (...){ FrameTimer++;}static END_OF_FUNCTION (TimerInterrupt);void InitTimer (){ install_timer (); LOCK_VARIABLE (FrameTimer); LOCK_FUNCTION (TimerInterrupt); if (install_int (TimerInterrupt, Settings.FrameTime / 1000) < 0) { printf ("Snes9X: Dynamic speed limiting not available\n"); Settings.SkipFrames = 3; }}int S9xMinCommandLineArgs (){ return (2);}#include "display.h"static int Rates[8] ={ 0, 8192, 11025, 16500, 22050, 29300, 36600, 44000};bool8 S9xOpenSoundDevice (int mode, bool8 stereo, int buffer_size){ int playback_rate = Rates [mode & 7]; int sixteen_bit = TRUE; int in_stereo = stereo; so.mute_sound = TRUE; if (sx_sb_init (&in_stereo, &sixteen_bit, &playback_rate, &buffer_size) < 0) { return (FALSE); } so.stereo = in_stereo; so.sixteen_bit = sixteen_bit; so.playback_rate = playback_rate; so.buffer_size = buffer_size; so.encoded = FALSE; atexit (sx_sb_exit); /* Lock variables into memory */ void S9xMixSamples_end(); void S9xMixSamplesO_end(); void MixStereo (int); void MixStereo_end(); void MixMono (int); void MixMono_end(); void S9xAPUSetEndOfSample (int, Channel *); void S9xAPUSetEndOfSample_end(); void S9xAPUSetEndX (int); void S9xAPUSetEndX_end(); void S9xSetEnvelopeRate_end(); void S9xSetEnvRate (Channel *, unsigned long, int, int); void S9xSetEnvRate_end (); extern long FilterValues[4][2]; extern int Echo [15360 + 14]; extern int DummyEchoBuffer [MAX_BUFFER_SIZE]; extern int MixBuffer [MAX_BUFFER_SIZE]; extern int EchoBuffer [MAX_BUFFER_SIZE]; extern int FilterTaps [8]; extern unsigned long Z; extern int Loop [16]; LOCK_FUNCTION (S9xMixSamples); LOCK_FUNCTION (S9xMixSamplesO); LOCK_FUNCTION (MixStereo); LOCK_FUNCTION (MixMono);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -