PSP2, 3DS: Options for incrementing the screen mode
Jeffrey Pfau jeffrey@endrift.com
Thu, 03 Sep 2015 23:39:46 -0700
6 files changed,
75 insertions(+),
12 deletions(-)
M
src/gba/gui/gui-runner.c
→
src/gba/gui/gui-runner.c
@@ -220,6 +220,9 @@ if (runner->luminanceSource.luxLevel > 0) {
--runner->luminanceSource.luxLevel; } } + if (guiKeys & (1 << GBA_GUI_INPUT_SCREEN_MODE) && runner->incrementScreenMode) { + runner->incrementScreenMode(runner); + } uint16_t keys = runner->pollGameInput(runner); if (runner->prepareForFrame) { runner->prepareForFrame(runner);
M
src/gba/gui/gui-runner.h
→
src/gba/gui/gui-runner.h
@@ -11,7 +11,8 @@ #include "util/gui.h"
enum GBAGUIInput { GBA_GUI_INPUT_INCREASE_BRIGHTNESS = GUI_INPUT_USER_START, - GBA_GUI_INPUT_DECREASE_BRIGHTNESS + GBA_GUI_INPUT_DECREASE_BRIGHTNESS, + GBA_GUI_INPUT_SCREEN_MODE, }; struct GBAGUIBackground {@@ -43,6 +44,7 @@ void (*drawFrame)(struct GBAGUIRunner*, bool faded);
void (*drawScreenshot)(struct GBAGUIRunner*, const uint32_t* pixels, bool faded); void (*paused)(struct GBAGUIRunner*); void (*unpaused)(struct GBAGUIRunner*); + void (*incrementScreenMode)(struct GBAGUIRunner*); uint16_t (*pollGameInput)(struct GBAGUIRunner*); };
M
src/platform/3ds/main.c
→
src/platform/3ds/main.c
@@ -18,8 +18,18 @@
#include <3ds.h> #include <sf2d.h> +static enum ScreenMode { + SM_PA_BOTTOM, + SM_AF_BOTTOM, + SM_SF_BOTTOM, + SM_PA_TOP, + SM_AF_TOP, + SM_SF_TOP, + SM_MAX +} screenMode = SM_PA_BOTTOM; + #define AUDIO_SAMPLES 0x80 -#define AUDIO_SAMPLE_BUFFER (AUDIO_SAMPLES * 32) +#define AUDIO_SAMPLE_BUFFER (AUDIO_SAMPLES * 24) FS_archive sdmcArchive;@@ -45,7 +55,11 @@
static void _postAudioBuffer(struct GBAAVStream* stream, struct GBAAudio* audio); static void _drawStart(void) { - sf2d_start_frame(GFX_BOTTOM, GFX_LEFT); + if (screenMode < SM_PA_TOP) { + sf2d_start_frame(GFX_BOTTOM, GFX_LEFT); + } else { + sf2d_start_frame(GFX_TOP, GFX_LEFT); + } } static void _drawEnd(void) {@@ -111,11 +125,34 @@ HIDUSER_DisableGyroscope();
} } +static void _drawTex(bool faded) { + switch (screenMode) { + case SM_PA_TOP: + sf2d_draw_texture_scale_blend(tex, 80, 296, 1, -1, 0xFFFFFF3F | (faded ? 0 : 0xC0)); + break; + case SM_PA_BOTTOM: + sf2d_draw_texture_scale_blend(tex, 40, 296, 1, -1, 0xFFFFFF3F | (faded ? 0 : 0xC0)); + break; + case SM_AF_TOP: + sf2d_draw_texture_scale_blend(tex, 20, 384, 1.5, -1.5, 0xFFFFFF3F | (faded ? 0 : 0xC0)); + break; + case SM_AF_BOTTOM: + sf2d_draw_texture_scale_blend(tex, 0, 368 - 40 / 3, 4 / 3.0, -4 / 3.0, 0xFFFFFF3F | (faded ? 0 : 0xC0)); + break; + case SM_SF_TOP: + sf2d_draw_texture_scale_blend(tex, 0, 384, 5 / 3.0, -1.5, 0xFFFFFF3F | (faded ? 0 : 0xC0)); + break; + case SM_SF_BOTTOM: + sf2d_draw_texture_scale_blend(tex, 0, 384, 4 / 3.0, -1.5, 0xFFFFFF3F | (faded ? 0 : 0xC0)); + break; + } +} + static void _drawFrame(struct GBAGUIRunner* runner, bool faded) { UNUSED(runner); GSPGPU_FlushDataCache(0, renderer.outputBuffer, 256 * VIDEO_VERTICAL_PIXELS * 2); GX_SetDisplayTransfer(0, renderer.outputBuffer, GX_BUFFER_DIM(256, VIDEO_VERTICAL_PIXELS), tex->data, GX_BUFFER_DIM(256, VIDEO_VERTICAL_PIXELS), 0x000002202); - sf2d_draw_texture_scale_blend(tex, 40, 296, 1, -1, 0xFFFFFF3F | (faded ? 0 : 0xC0)); + _drawTex(faded); #if RESAMPLE_LIBRARY == RESAMPLE_BLIP_BUF if (!hasSound) { blip_clear(runner->context.gba->audio.left);@@ -140,10 +177,8 @@ memset(&newPixels[y * 256 + VIDEO_HORIZONTAL_PIXELS], 0, 32);
} GSPGPU_FlushDataCache(0, (void*) newPixels, VIDEO_HORIZONTAL_PIXELS * VIDEO_VERTICAL_PIXELS * 2); GX_SetDisplayTransfer(0, (void*) newPixels, GX_BUFFER_DIM(VIDEO_HORIZONTAL_PIXELS, VIDEO_VERTICAL_PIXELS), tex->data, GX_BUFFER_DIM(256, VIDEO_VERTICAL_PIXELS), 0x000002202); - gspWaitForPPF(); linearFree(newPixels); - GSPGPU_FlushDataCache(0, (void*) tex->data, 256 * VIDEO_VERTICAL_PIXELS * 2); - sf2d_draw_texture_scale_blend(tex, 40, 296, 1, -1, 0xFFFFFF3F | (faded ? 0 : 0xC0)); + _drawTex(faded); } static uint16_t _pollGameInput(struct GBAGUIRunner* runner) {@@ -153,12 +188,25 @@ activeKeys |= activeKeys >> 24;
return activeKeys; } +static void _incrementScreenMode(struct GBAGUIRunner* runner) { + UNUSED(runner); + // Clear the buffer + _drawStart(); + _drawEnd(); + _drawStart(); + _drawEnd(); + screenMode = (screenMode + 1) % SM_MAX; +} + static uint32_t _pollInput(void) { hidScanInput(); uint32_t keys = 0; int activeKeys = hidKeysHeld(); if (activeKeys & KEY_X) { keys |= 1 << GUI_INPUT_CANCEL; + } + if (activeKeys & KEY_Y) { + keys |= 1 << GBA_GUI_INPUT_SCREEN_MODE; } if (activeKeys & KEY_B) { keys |= 1 << GUI_INPUT_BACK;@@ -220,7 +268,7 @@ #endif
GSPGPU_FlushDataCache(0, (void*) &audioLeft[audioPos], AUDIO_SAMPLES * sizeof(int16_t)); GSPGPU_FlushDataCache(0, (void*) &audioRight[audioPos], AUDIO_SAMPLES * sizeof(int16_t)); audioPos = (audioPos + AUDIO_SAMPLES) % AUDIO_SAMPLE_BUFFER; - if (audioPos == AUDIO_SAMPLE_BUFFER / 8) { + if (audioPos == AUDIO_SAMPLES * 3) { u8 playing = 0; csndIsPlaying(0x8, &playing); if (!playing) {@@ -288,6 +336,7 @@ .drawFrame = _drawFrame,
.drawScreenshot = _drawScreenshot, .paused = _gameUnloaded, .unpaused = _gameLoaded, + .incrementScreenMode = _incrementScreenMode, .pollGameInput = _pollGameInput }; GBAGUIInit(&runner, 0);
M
src/platform/psp2/main.c
→
src/platform/psp2/main.c
@@ -37,6 +37,9 @@ int input = 0;
if (pad.buttons & PSP2_CTRL_TRIANGLE) { input |= 1 << GUI_INPUT_CANCEL; } + if (pad.buttons & PSP2_CTRL_SQUARE) { + input |= 1 << GBA_GUI_INPUT_SCREEN_MODE; + } if (pad.buttons & PSP2_CTRL_CIRCLE) { input |= 1 << GUI_INPUT_BACK; }@@ -78,6 +81,9 @@ .gameLoaded = GBAPSP2LoadROM,
.gameUnloaded = GBAPSP2UnloadROM, .prepareForFrame = GBAPSP2PrepareForFrame, .drawFrame = GBAPSP2Draw, + .paused = 0, + .unpaused = 0, + .incrementScreenMode = GBAPSP2IncrementScreenMode, .pollGameInput = GBAPSP2PollInput };
M
src/platform/psp2/psp2-context.c
→
src/platform/psp2/psp2-context.c
@@ -29,12 +29,12 @@ #include <psp2/power.h>
#include <vita2d.h> -enum ScreenMode { +static enum ScreenMode { SM_BACKDROP, SM_PLAIN, SM_FULL, SM_MAX -}; +} screenMode; static struct GBAVideoSoftwareRenderer renderer; static vita2d_texture* tex;@@ -43,8 +43,6 @@ static struct GBASceRotationSource {
struct GBARotationSource d; struct SceMotionSensorState state; } rotation; - -static int screenMode = 0; extern const uint8_t _binary_backdrop_png_start[]; static vita2d_texture* backdrop = 0;@@ -239,6 +237,10 @@ case SM_FULL:
vita2d_draw_texture_tint_scale(tex, 0, 0, 960.0f / 240.0f, 544.0f / 160.0f, (faded ? 0 : 0xC0000000) | 0x3FFFFFFF); break; } +} + +void GBAPSP2IncrementScreenMode(struct GBAGUIRunner* runner) { + screenMode = (screenMode + 1) % SM_MAX; } __attribute__((noreturn, weak)) void __assert_func(const char* file, int line, const char* func, const char* expr) {
M
src/platform/psp2/psp2-context.h
→
src/platform/psp2/psp2-context.h
@@ -17,6 +17,7 @@ void GBAPSP2LoadROM(struct GBAGUIRunner* runner);
void GBAPSP2UnloadROM(struct GBAGUIRunner* runner); void GBAPSP2PrepareForFrame(struct GBAGUIRunner* runner); void GBAPSP2Draw(struct GBAGUIRunner* runner, bool faded); +void GBAPSP2IncrementScreenMode(struct GBAGUIRunner* runner); uint16_t GBAPSP2PollInput(struct GBAGUIRunner* runner); #endif