Skip to content

Commit

Permalink
added Clock.pak to extras
Browse files Browse the repository at this point in the history
  • Loading branch information
Shaun Inman committed Jun 17, 2022
1 parent cbcfe28 commit 59e0966
Show file tree
Hide file tree
Showing 7 changed files with 256 additions and 4 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ say
!say/
blank
!blank/
clock
!clock/

screenshot
!screenshot/
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,20 @@ _MiniUI is a custom launcher and integrated in-game menu for the [Miyoo Mini](ht

MiniUI is simple, some might say to a fault. That's okay. I think it's one of those things where, if you like it, even just a little bit, you'll love it. (For the uninitiated, MiniUI is a direct descendent of [MinUI](https://github.com/shauninman/MinUI) which itself is a distillation of the stock launcher and menu of the [Trimui Model S](http://www.trimui.com).)

MiniUI is defined by no. No boxart. No video previews. No background menu music. No custom themes. No also rans. MiniUI is too full of self-loathing for all that. It doesn't like launchers. It doesn't like being one. It wants to disappear and speed you on your way. MiniUI is unapologetically opinionated software. Sorry not sorry.
MiniUI is defined by no. No boxart. No video previews. No background menu music. No custom themes. No also rans. MiniUI wants to disappear and speed you on your way. MiniUI is unapologetically opinionated software. Sorry not sorry.

Check the [Releases](https://github.com/shauninman/MiniUI/releases) for the latest and if you want more info before downloading, the readme included in every release is also available [here](https://github.com/shauninman/MiniUI/tree/main/skeleton).

MiniUI maybe be simple but it's also extensible. See the [Extras readme](https://github.com/shauninman/MiniUI/tree/main/extras) for info on adding additional paks or creating your own.

## Key features

- No settings or configuration
- Simple launcher, simple SD card
- No launcher settings or configuration
- Consistent in-emulator menu with quick access to save states, disc changing, and emulator options
- Automatically sleeps after 30 seconds or press POWER to sleep (and wake)
- Automatically sleeps after 30 seconds or press POWER to sleep (and later, wake)
- Automatically powers off while asleep after two minutes or hold POWER for one second
- Automatically resumes right where you left off if powered off while in-game, manually or while asleep
- Automatically resumes right where you left off if powered off while in-game
- Resume from manually created, last used save state by pressing X in the launcher instead of A
- Streamlined emulator frontend (picoarch + libretro cores)

Expand Down
3 changes: 3 additions & 0 deletions extras/Tools/Clock.pak/launch.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh
cd "$(dirname "$0")"
./clock
2 changes: 2 additions & 0 deletions makefile
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ tools:
cd ./third-party/screenshot && make
cd ./third-party/logotweak/logomake && make
cd ./third-party/logotweak/logowrite && make
cd ./src/clock && make

payload:
rm -rf ./build
Expand Down Expand Up @@ -100,6 +101,7 @@ payload:
cp ./third-party/picoarch/output/picodrive_libretro.so ./build/PAYLOAD/.system/cores/
cp ./third-party/picoarch/output/snes9x2005_plus_libretro.so ./build/PAYLOAD/.system/cores/
cp ./third-party/DinguxCommander/output/DinguxCommander ./build/EXTRAS/Tools/Files.pak/
cp ./src/clock/clock ./build/EXTRAS/Tools/Clock.pak/
cp -r ./third-party/DinguxCommander/res ./build/EXTRAS/Tools/Files.pak/
cp ./third-party/screenshot/screenshot ./build/EXTRAS/Tools/Screenshots.pak/
cp ./third-party/picoarch/output/beetle-pce-fast_libretro.so ./build/EXTRAS/Emus/PCE.pak/mednafen_pce_fast_libretro.so
Expand Down
Binary file added skeleton/.system/res/digits.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
231 changes: 231 additions & 0 deletions src/clock/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,231 @@
// loosely based on https://github.com/gameblabla/clock_sdl_app

#include <stdio.h>
#include <time.h>
#include <unistd.h>
#include <SDL/SDL.h>
#include <SDL/SDL_image.h>

int main(int argc , char* argv[]) {
SDL_Init(SDL_INIT_VIDEO);
SDL_ShowCursor(0);

SDL_Surface* screen = SDL_SetVideoMode(640, 480, 16, SDL_HWSURFACE | SDL_DOUBLEBUF);

#define RES_PATH "/mnt/SDCARD/.system/res/"
SDL_Surface* confirm = IMG_Load(RES_PATH "confirm.png");
SDL_Surface* digits = IMG_Load(RES_PATH "digits.png"); // 20x32

SDL_Event event;
int quit = 0;
int save_changes = 0;
int select_cursor = 0;

time_t t = time(NULL);
struct tm tm = *localtime(&t);

uint32_t day_selected = tm.tm_mday;
uint32_t month_selected = tm.tm_mon + 1;
uint32_t year_selected = tm.tm_year + 1900;
uint32_t hour_selected = tm.tm_hour;
uint32_t minute_selected = tm.tm_min;
uint32_t seconds_selected = tm.tm_sec;

uint32_t white = SDL_MapRGB(screen->format, 255,255,255);

#define kSlash 10
#define kColon 11
#define kBar 12
int blit(int i, int x, int y) {
SDL_BlitSurface(digits, &(SDL_Rect){i*20,0,20,32}, screen, &(SDL_Rect){x,y});
return x + 20;
}
void blitBar(int x, int y, int len) {
int w = len * 20;
SDL_FillRect(screen, &(SDL_Rect){x,y,w,5}, white);
SDL_BlitSurface(digits, &(SDL_Rect){kBar*20,0,3,5}, screen, &(SDL_Rect){x,y});
SDL_BlitSurface(digits, &(SDL_Rect){(kBar*20)+2,0,3,5}, screen, &(SDL_Rect){x+w-3,y});
}
int blitNumber(int num, int x, int y) {
int n;
if (num > 999) {
n = num / 1000;
num -= n * 1000;
x = blit(n, x,y);

n = num / 100;
num -= n * 100;
x = blit(n, x,y);
}
n = num / 10;
num -= n * 10;
x = blit(n, x,y);

n = num;
x = blit(n, x,y);

return x;
}
void validate(void) {
// leap year
uint32_t february_days = 28;
if ( ((year_selected % 4 == 0) && (year_selected % 100 != 0)) || (year_selected % 400 == 0)) february_days = 29;

// day
if (day_selected < 1) day_selected = 1;
if (month_selected > 12) month_selected = 12;
else if (month_selected < 1) month_selected = 1;

if (year_selected > 2100) year_selected = 2100;
else if (year_selected < 1970) year_selected = 1970;

switch(month_selected)
{
case 2:
if (day_selected > february_days) day_selected = february_days;
break;
case 4:
case 6:
case 9:
case 11:
if (day_selected > 30) day_selected = 30;
break;
default:
if (day_selected > 31) day_selected = 31;
break;
}

// time
if (hour_selected > 23) hour_selected = 0;
if (minute_selected > 59) minute_selected = 0;
if (seconds_selected > 59) seconds_selected = 0;
}

SDL_EnableKeyRepeat(300,100);

while(!quit) {
unsigned long frame_start = SDL_GetTicks();

while (SDL_PollEvent(&event)) {
switch(event.type) {
case SDL_KEYDOWN:
switch(event.key.keysym.sym) {
case SDLK_UP:
switch(select_cursor) {
case 0:
year_selected++;
break;
case 1:
month_selected++;
break;
case 2:
day_selected++;
break;
case 3:
hour_selected++;
break;
case 4:
minute_selected++;
break;
case 5:
seconds_selected++;
break;
}
break;
case SDLK_DOWN:
switch(select_cursor) {
case 0:
year_selected--;
break;
case 1:
month_selected--;
break;
case 2:
day_selected--;
break;
case 3:
hour_selected--;
break;
case 4:
minute_selected--;
break;
case 5:
seconds_selected--;
break;
}
break;
case SDLK_LEFT:
select_cursor--;
if (select_cursor < 0) select_cursor += 6;
break;
case SDLK_RIGHT:
select_cursor++;
if (select_cursor > 5) select_cursor -= 6;
break;
case SDLK_SPACE: // A
save_changes = 1;
quit = 1;
break;
case SDLK_LCTRL: // B
quit = 1;
break;
default:
break;
}
break;
case SDL_QUIT:
quit = 1;
break;
}
}

validate();

// render
SDL_BlitSurface(confirm, NULL, screen, NULL);

// datetime
int x = 130;
int y = 185;

x = blitNumber(year_selected, x,y);
x = blit(kSlash, x,y);
x = blitNumber(month_selected, x,y);
x = blit(kSlash, x,y);
x = blitNumber(day_selected, x,y);
x += 20; // space
x = blitNumber(hour_selected, x,y);
x = blit(kColon, x,y);
x = blitNumber(minute_selected, x,y);
x = blit(kColon, x,y);
x = blitNumber(seconds_selected, x,y);

// cursor
x = 130;
y = 222;
if (select_cursor>0) {
x += 100; // YYYY/
x += (select_cursor - 1) * 60;
}
blitBar(x,y, (select_cursor>0 ? 2 : 4));

SDL_Flip(screen);

// slow down to 60fps
unsigned long frame_duration = SDL_GetTicks() - frame_start;
#define kTargetFrameDuration 17
if (frame_duration<kTargetFrameDuration) SDL_Delay(kTargetFrameDuration-frame_duration);
}

SDL_FreeSurface(confirm);
SDL_FreeSurface(digits);
SDL_Quit();

if (save_changes) {
char cmd[512];
snprintf(cmd, sizeof(cmd), "date -s '%d-%d-%d %d:%d:%d';hwclock --utc -w", year_selected, month_selected, day_selected, hour_selected, minute_selected, seconds_selected);
system(cmd);
}

return EXIT_SUCCESS;
}
14 changes: 14 additions & 0 deletions src/clock/makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
ifeq (,$(CROSS_COMPILE))
$(error missing CROSS_COMPILE for this toolchain)
endif

TARGET = clock

CC = $(CROSS_COMPILE)gcc
CFLAGS = -marm -mtune=cortex-a7 -mfpu=neon-vfpv4 -mfloat-abi=hard -march=armv7ve
LDFLAGS = -lSDL -lSDL_image

all:
$(CC) main.c -o $(TARGET) $(CFLAGS) $(LDFLAGS)
clean:
rm -f $(TARGET)

0 comments on commit 59e0966

Please sign in to comment.