switch to software renderer if hardware not detected
This commit is contained in:
parent
5c6d87525f
commit
b43bfe06fb
|
@ -31,6 +31,8 @@ extern "C" {
|
||||||
|
|
||||||
#define TIC80_WIDTH 240
|
#define TIC80_WIDTH 240
|
||||||
#define TIC80_HEIGHT 136
|
#define TIC80_HEIGHT 136
|
||||||
|
#define TIC80_FULLWIDTH 256
|
||||||
|
#define TIC80_FULLHEIGHT (TIC80_FULLWIDTH*9/16)
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
|
@ -47,15 +49,8 @@ typedef struct
|
||||||
s32 count;
|
s32 count;
|
||||||
} sound;
|
} sound;
|
||||||
|
|
||||||
u32 screen[TIC80_WIDTH * TIC80_HEIGHT];
|
u32 screen[TIC80_FULLWIDTH * TIC80_FULLHEIGHT];
|
||||||
u32 border[TIC80_HEIGHT];
|
|
||||||
|
|
||||||
struct
|
|
||||||
{
|
|
||||||
s8 x;
|
|
||||||
s8 y;
|
|
||||||
s8 rows[TIC80_HEIGHT];
|
|
||||||
} offset;
|
|
||||||
} tic80;
|
} tic80;
|
||||||
|
|
||||||
typedef union
|
typedef union
|
||||||
|
|
53
src/studio.c
53
src/studio.c
|
@ -47,7 +47,6 @@
|
||||||
#include "ext/md5.h"
|
#include "ext/md5.h"
|
||||||
|
|
||||||
#define STUDIO_UI_SCALE 3
|
#define STUDIO_UI_SCALE 3
|
||||||
#define STUDIO_UI_BORDER 16
|
|
||||||
|
|
||||||
#define MAX_CONTROLLERS 4
|
#define MAX_CONTROLLERS 4
|
||||||
#define STUDIO_PIXEL_FORMAT SDL_PIXELFORMAT_ARGB8888
|
#define STUDIO_PIXEL_FORMAT SDL_PIXELFORMAT_ARGB8888
|
||||||
|
@ -78,6 +77,7 @@ static struct
|
||||||
|
|
||||||
SDL_Window* window;
|
SDL_Window* window;
|
||||||
SDL_Renderer* renderer;
|
SDL_Renderer* renderer;
|
||||||
|
SDL_Renderer* softwareRenderer;
|
||||||
SDL_Texture* texture;
|
SDL_Texture* texture;
|
||||||
|
|
||||||
SDL_AudioSpec audioSpec;
|
SDL_AudioSpec audioSpec;
|
||||||
|
@ -192,6 +192,7 @@ static struct
|
||||||
|
|
||||||
.window = NULL,
|
.window = NULL,
|
||||||
.renderer = NULL,
|
.renderer = NULL,
|
||||||
|
.softwareRenderer = NULL,
|
||||||
.texture = NULL,
|
.texture = NULL,
|
||||||
.audioDevice = 0,
|
.audioDevice = 0,
|
||||||
|
|
||||||
|
@ -2173,10 +2174,10 @@ static void tick()
|
||||||
SDL_SystemCursor cursor = studio.mouse.system;
|
SDL_SystemCursor cursor = studio.mouse.system;
|
||||||
studio.mouse.system = SDL_SYSTEM_CURSOR_ARROW;
|
studio.mouse.system = SDL_SYSTEM_CURSOR_ARROW;
|
||||||
|
|
||||||
{
|
// {
|
||||||
const u8* pal = (u8*)(paletteBlit() + tic_tool_peek4(studio.tic->ram.vram.mapping, studio.tic->ram.vram.vars.border & 0xf));
|
// const u8* pal = (u8*)(paletteBlit() + tic_tool_peek4(studio.tic->ram.vram.mapping, studio.tic->ram.vram.vars.border & 0xf));
|
||||||
SDL_SetRenderDrawColor(studio.renderer, pal[2], pal[1], pal[0], SDL_ALPHA_OPAQUE);
|
// SDL_SetRenderDrawColor(studio.renderer, pal[2], pal[1], pal[0], SDL_ALPHA_OPAQUE);
|
||||||
}
|
// }
|
||||||
|
|
||||||
SDL_RenderClear(studio.renderer);
|
SDL_RenderClear(studio.renderer);
|
||||||
|
|
||||||
|
@ -2228,7 +2229,7 @@ static void initTouchGamepad()
|
||||||
if(!studio.gamepad.texture)
|
if(!studio.gamepad.texture)
|
||||||
{
|
{
|
||||||
studio.gamepad.texture = SDL_CreateTexture(studio.renderer, STUDIO_PIXEL_FORMAT, SDL_TEXTUREACCESS_STREAMING,
|
studio.gamepad.texture = SDL_CreateTexture(studio.renderer, STUDIO_PIXEL_FORMAT, SDL_TEXTUREACCESS_STREAMING,
|
||||||
textureLog2(TIC80_WIDTH), textureLog2(TIC80_HEIGHT));
|
textureLog2(TIC80_FULLWIDTH), textureLog2(TIC80_FULLHEIGHT));
|
||||||
SDL_SetTextureBlendMode(studio.gamepad.texture, SDL_BLENDMODE_BLEND);
|
SDL_SetTextureBlendMode(studio.gamepad.texture, SDL_BLENDMODE_BLEND);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2327,8 +2328,8 @@ static void onFSInitialized(FileSystem* fs)
|
||||||
SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_JOYSTICK);
|
SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_JOYSTICK);
|
||||||
|
|
||||||
studio.window = SDL_CreateWindow( TIC_TITLE, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
|
studio.window = SDL_CreateWindow( TIC_TITLE, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
|
||||||
(TIC80_WIDTH+STUDIO_UI_BORDER) * STUDIO_UI_SCALE,
|
(TIC80_FULLWIDTH) * STUDIO_UI_SCALE,
|
||||||
(TIC80_HEIGHT+STUDIO_UI_BORDER) * STUDIO_UI_SCALE,
|
(TIC80_FULLHEIGHT) * STUDIO_UI_SCALE,
|
||||||
SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE
|
SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE
|
||||||
#if defined(__ARM_LINUX__)
|
#if defined(__ARM_LINUX__)
|
||||||
| SDL_WINDOW_FULLSCREEN_DESKTOP
|
| SDL_WINDOW_FULLSCREEN_DESKTOP
|
||||||
|
@ -2361,13 +2362,11 @@ static void onFSInitialized(FileSystem* fs)
|
||||||
// set the window icon before renderer is created (issues on Linux)
|
// set the window icon before renderer is created (issues on Linux)
|
||||||
setWindowIcon();
|
setWindowIcon();
|
||||||
|
|
||||||
#if defined(__ARM_LINUX__)
|
studio.renderer = SDL_CreateRenderer(studio.window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
|
||||||
s32 renderFlags = SDL_RENDERER_SOFTWARE;
|
|
||||||
#else
|
if(!studio.renderer)
|
||||||
s32 renderFlags = SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC;
|
studio.softwareRenderer = studio.renderer = SDL_CreateRenderer(studio.window, -1, SDL_RENDERER_SOFTWARE);
|
||||||
#endif
|
|
||||||
|
|
||||||
studio.renderer = SDL_CreateRenderer(studio.window, -1, renderFlags);
|
|
||||||
studio.texture = SDL_CreateTexture(studio.renderer, STUDIO_PIXEL_FORMAT, SDL_TEXTUREACCESS_STREAMING,
|
studio.texture = SDL_CreateTexture(studio.renderer, STUDIO_PIXEL_FORMAT, SDL_TEXTUREACCESS_STREAMING,
|
||||||
textureLog2(TIC80_WIDTH), textureLog2(TIC80_HEIGHT));
|
textureLog2(TIC80_WIDTH), textureLog2(TIC80_HEIGHT));
|
||||||
|
|
||||||
|
@ -2415,21 +2414,25 @@ s32 main(s32 argc, char **argv)
|
||||||
|
|
||||||
createFileSystem(onFSInitialized);
|
createFileSystem(onFSInitialized);
|
||||||
|
|
||||||
u64 nextTick = SDL_GetPerformanceCounter();
|
if(studio.softwareRenderer)
|
||||||
const u64 Delta = SDL_GetPerformanceFrequency() / TIC_FRAMERATE;
|
|
||||||
|
|
||||||
while (!studio.quitFlag)
|
|
||||||
{
|
{
|
||||||
nextTick += Delta;
|
u64 nextTick = SDL_GetPerformanceCounter();
|
||||||
tick();
|
const u64 Delta = SDL_GetPerformanceFrequency() / TIC_FRAMERATE;
|
||||||
|
|
||||||
|
while (!studio.quitFlag)
|
||||||
|
{
|
||||||
|
nextTick += Delta;
|
||||||
|
tick();
|
||||||
|
|
||||||
s64 delay = nextTick - SDL_GetPerformanceCounter();
|
s64 delay = nextTick - SDL_GetPerformanceCounter();
|
||||||
|
|
||||||
if(delay > 0)
|
if(delay > 0)
|
||||||
SDL_Delay((u32)(delay * 1000 / SDL_GetPerformanceFrequency()));
|
SDL_Delay((u32)(delay * 1000 / SDL_GetPerformanceFrequency()));
|
||||||
else nextTick -= delay;
|
else nextTick -= delay;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
// TODO: check if window minimised
|
||||||
|
else while(!studio.quitFlag) tick();
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -139,19 +139,12 @@ static void blit(tic80* tic)
|
||||||
tic80_local* tic80 = (tic80_local*)tic;
|
tic80_local* tic80 = (tic80_local*)tic;
|
||||||
|
|
||||||
u32* screen = tic->screen;
|
u32* screen = tic->screen;
|
||||||
u32* border = tic->border;
|
|
||||||
|
|
||||||
tic->offset.x = tic80->memory->ram.vram.vars.offset.x;
|
|
||||||
tic->offset.y = tic80->memory->ram.vram.vars.offset.y;
|
|
||||||
|
|
||||||
for (s32 r = 0, pos = 0; r < TIC80_HEIGHT; r++, screen += TIC80_WIDTH)
|
for (s32 r = 0, pos = 0; r < TIC80_HEIGHT; r++, screen += TIC80_WIDTH)
|
||||||
{
|
{
|
||||||
tic80->memory->api.scanline(tic80->memory, r);
|
tic80->memory->api.scanline(tic80->memory, r);
|
||||||
const u32* pal = paletteBlit(tic80->memory);
|
const u32* pal = paletteBlit(tic80->memory);
|
||||||
|
|
||||||
tic->offset.rows[r] = tic80->memory->ram.vram.vars.offset.x;
|
|
||||||
|
|
||||||
*border++ = pal[tic_tool_peek4(tic80->memory->ram.vram.mapping, tic80->memory->ram.vram.vars.border & 0xf)];
|
|
||||||
for (u32* ptr = screen, c = 0; c < TIC80_WIDTH; c++, ptr++)
|
for (u32* ptr = screen, c = 0; c < TIC80_WIDTH; c++, ptr++)
|
||||||
*ptr = pal[tic_tool_peek4(tic80->memory->ram.vram.screen.data, pos++)];
|
*ptr = pal[tic_tool_peek4(tic80->memory->ram.vram.screen.data, pos++)];
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue