Skip to content

Commit

Permalink
Add a pocketchip mode where the game is centered on the screen.
Browse files Browse the repository at this point in the history
  • Loading branch information
dulsi committed Aug 16, 2018
1 parent 6aedb3c commit 72c1370
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 9 deletions.
68 changes: 60 additions & 8 deletions src/Main.cpp
Expand Up @@ -13,6 +13,7 @@
#endif #endif
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <getopt.h>
#include <TinyScreen.h> #include <TinyScreen.h>
#include <SPI.h> #include <SPI.h>
#include <Wire.h> #include <Wire.h>
Expand Down Expand Up @@ -102,6 +103,7 @@ typedef struct {
SDL_Renderer *mainRenderer; SDL_Renderer *mainRenderer;
SDL_Texture *mainTexture; SDL_Texture *mainTexture;
SDL_Surface *mainScreen; SDL_Surface *mainScreen;
SDL_Rect *rect;
int mult; int mult;
#else #else
GLuint screenTexture; GLuint screenTexture;
Expand All @@ -121,7 +123,7 @@ static void writeFrameBufferToTSV() {


static void updateScreen() { static void updateScreen() {
#ifdef SDL2LIB #ifdef SDL2LIB
SDL_UpdateTexture(emulator.mainTexture, NULL, emulator.mainScreen->pixels, emulator.mainScreen->pitch); SDL_UpdateTexture(emulator.mainTexture, emulator.rect, emulator.mainScreen->pixels, emulator.mainScreen->pitch);
SDL_RenderClear(emulator.mainRenderer); SDL_RenderClear(emulator.mainRenderer);
SDL_RenderCopy(emulator.mainRenderer, emulator.mainTexture, NULL, NULL); SDL_RenderCopy(emulator.mainRenderer, emulator.mainTexture, NULL, NULL);
SDL_RenderPresent(emulator.mainRenderer); SDL_RenderPresent(emulator.mainRenderer);
Expand Down Expand Up @@ -581,10 +583,60 @@ static void key_callback(GLFWwindow* window, int key, int /*scancode*/, int acti
} }
#endif #endif


int main(void) int main(int argc, char *argv[])
{ {
bool full = false;
bool softRender = false;
int opt;
static struct option long_options[] =
{
{"multiplier", 1, 0, 'u'},
{0, 0, 0, 0}
};
#ifdef SDL2LIB #ifdef SDL2LIB
int screenX, screenY;
emulator.mult = 4; emulator.mult = 4;
emulator.rect = NULL;
screenX = SCREEN_X * emulator.mult;
screenY = SCREEN_Y * emulator.mult;
#endif
while ((opt = getopt_long(argc,argv,"pu:fw", long_options, NULL)) != -1)
{
switch (opt)
{
#ifdef SDL2LIB
case 'p':
emulator.rect = new SDL_Rect;
emulator.rect->x = 48;
emulator.rect->y = 8;
emulator.rect->w = 384;
emulator.rect->h = 256;
emulator.mult = 4;
softRender = true;
screenX = 480;
screenY = 272;
full = true;
break;
case 'u':
if (optarg)
{
emulator.mult = atol(optarg);
screenX = SCREEN_X * emulator.mult;
screenY = SCREEN_Y * emulator.mult;
}
break;
#endif
case 'f':
full = true;
break;
case 'w':
softRender = true;
break;
default:
break;
}
}
#ifdef SDL2LIB
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_AUDIO) < 0) if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_AUDIO) < 0)
{ {
printf("Failed - SDL_Init\n"); printf("Failed - SDL_Init\n");
Expand All @@ -594,17 +646,17 @@ int main(void)
window = SDL_CreateWindow("TinyScreen Simulator", window = SDL_CreateWindow("TinyScreen Simulator",
SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
SCREEN_X * emulator.mult, screenX,
SCREEN_Y * emulator.mult, screenY,
/*(fullScreen ? SDL_WINDOW_FULLSCREEN_DESKTOP : */0/*)*/); (full ? SDL_WINDOW_FULLSCREEN_DESKTOP : 0));
emulator.window = window; emulator.window = window;
if (window == NULL) if (window == NULL)
{ {
printf("Failed - SDL_CreateWindow\n"); printf("Failed - SDL_CreateWindow\n");
exit(0); exit(0);
} }


emulator.mainRenderer = SDL_CreateRenderer(emulator.window, -1, /*(softRenderer ? SDL_RENDERER_SOFTWARE : */0/*)*/); emulator.mainRenderer = SDL_CreateRenderer(emulator.window, -1, (softRender ? SDL_RENDERER_SOFTWARE : 0));
if (emulator.mainRenderer == NULL) if (emulator.mainRenderer == NULL)
{ {
printf("Failed - SDL_CreateRenderer\n"); printf("Failed - SDL_CreateRenderer\n");
Expand All @@ -613,8 +665,8 @@ int main(void)
emulator.mainTexture = SDL_CreateTexture(emulator.mainRenderer, emulator.mainTexture = SDL_CreateTexture(emulator.mainRenderer,
SDL_PIXELFORMAT_ARGB8888, SDL_PIXELFORMAT_ARGB8888,
SDL_TEXTUREACCESS_STREAMING, SDL_TEXTUREACCESS_STREAMING,
SCREEN_X * emulator.mult, screenX,
SCREEN_Y * emulator.mult); screenY);
if (emulator.mainTexture == NULL) if (emulator.mainTexture == NULL)
{ {
printf("Failed - SDL_CreateTexture\n"); printf("Failed - SDL_CreateTexture\n");
Expand Down
2 changes: 1 addition & 1 deletion src/SdFat.cpp
Expand Up @@ -28,7 +28,7 @@ bool SdFat::begin(uint8_t csPin, uint8_t divisor)
{ {
if (!boost::filesystem::create_directory(savePath)) if (!boost::filesystem::create_directory(savePath))
{ {
fprintf(stderr, "Error creating directory %s\n", savePath); fprintf(stderr, "Error creating directory %s\n", savePath.c_str());
exit(2); exit(2);
} }
} }
Expand Down

0 comments on commit 72c1370

Please sign in to comment.