public static void Flip() { if (emulator.EmulatorPointer == IntPtr.Zero) { return; } var ram = PemsaEmulator.GetRam(emulator.EmulatorPointer); var screenColor = new int[16]; for (var i = 0; i < 16; i++) { screenColor[i] = PemsaEmulator.GetScreenColor(emulator.EmulatorPointer, i); } for (var i = 0; i < 0x2000; i++) { var val = Marshal.ReadByte(ram + i + 0x6000); var rv = screenColor[val & 0x0f]; var lv = screenColor[val >> 4]; screenColorData[i * 2] = Palette.standard[rv]; screenColorData[i * 2 + 1] = Palette.standard[lv]; } }
public override void Update() { PemsaEmulator.Render(emulator.EmulatorPointer); screenTexture.SetPixels(screenColorData); screenTexture.Apply(); fps = (int)(1f / Time.deltaTime); }
public void OnAudioFilterRead(float[] data, int channels) { PemsaEmulator.SampleAudioMultiple(emulator.EmulatorPointer, audioSamples, SampleSize); for (int i = 0; i < SampleSize; i += 1) { for (int j = 0; j < channels; j += 1) { data[i * channels + j] = (float)audioSamples[i]; } } }
public static void Render() { PemsaDrawMode drawMode = PemsaEmulator.GetDrawMode(emulator.EmulatorPointer); if (drawMode != PemsaDrawMode.SCREEN_NORMAL) { var material = emulator.GetComponent <MeshRenderer>().materials[0]; switch (drawMode) { case PemsaDrawMode.SCREEN_HORIZONTAL_STRETCH: { material.SetFloat("_StretchMultX", 0.5f); break; } case PemsaDrawMode.SCREEN_VERTICAL_STRETCH: { material.SetFloat("_StretchMultY", 0.5f); break; } case PemsaDrawMode.SCREEN_STRETCH: { material.SetFloat("_StretchMultX", 0.5f); material.SetFloat("_StretchMultY", 0.5f); break; } case PemsaDrawMode.SCREEN_HORIZONTAL_MIRROR: { material.SetFloat("_MirrorX", 1f); break; } case PemsaDrawMode.SCREEN_VERTICAL_MIRROR: { material.SetFloat("_MirrorY", 1f); break; } case PemsaDrawMode.SCREEN_MIRROR: { material.SetFloat("_MirrorX", 1f); material.SetFloat("_MirrorY", 1f); break; } case PemsaDrawMode.SCREEN_HORIZONTAL_FLIP: { material.SetFloat("_FlipX", 1f); break; } case PemsaDrawMode.SCREEN_VERTICAL_FLIP: { material.SetFloat("_FlipY", 1f); break; } case PemsaDrawMode.SCREEN_90_ROTATION: { material.SetFloat("_Rot", (float)Math.PI / 2); break; } case PemsaDrawMode.SCREEN_180_ROTATION: { material.SetFloat("_Rot", (float)Math.PI); break; } case PemsaDrawMode.SCREEN_270_ROTATION: { material.SetFloat("_Rot", (float)(3 * Math.PI / 2)); break; } } } }