Skip to content

Commit

Permalink
read png, wav assets at runtime to customize logo (#13)
Browse files Browse the repository at this point in the history
from $HOME directory
  • Loading branch information
Apaczer authored May 19, 2024
1 parent 7cf7407 commit 536cb58
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 27 deletions.
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@

BUILDTIME=$(shell date +'\"%Y-%m-%d %H:%M\"')

CC = gcc
CXX = g++
STRIP = strip
SDL_CFLAGS := `sdl-config --cflags`
CC = $(CROSS_COMPILE)gcc
CXX = $(CROSS_COMPILE)g++
STRIP = $(CROSS_COMPILE)strip
SDL_CFLAGS := $(shell $(SYSROOT)/usr/bin/sdl-config --cflags)

OUTPUTNAME = boot-logo

Expand Down
27 changes: 23 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,30 @@
# logo
Main repository at https://github.com/TriForceX/MiyooCFW

**Instructions:**

After compiling the Miyoo CFW toolchain (https://github.com/TriForceX/MiyooCFW/wiki/Making-Games) on your system, edit the appropriate "Makefile" in your copy of this repository to point it to where you've installed the toolchain (and rename the file to just "Makefile"), and simply run the "make" command in the terminal (while inside the source directory) to build the new "boot-logo" binary.

You'll need to convert your logo image into a "0x" formatted hexadecimal data string and add it to "assets.h". (The same goes for the sound file.) You'll also need to count the total number of "initialisers", the comma separated values, in your hexadecimal string, and write their total number into the square brackets for the header identifier that contains your file.
You can customize your boot-logo output by modyfing following files:
- `$HOME/logo.png` - scrolling logo image
- `$HOME/logo.wav` - scrolling logo sound
- `$HOME/logobg.png` - background image

For images use PNG, for sound WAV (stereo, 22050 Hz, signed 16-bit PCM)

**Building:**
- native linux build:
```
make clean
make
```
- cross-compile for miyoo:
```
export SYSROOT=/opt/miyoo/arm-miyoo-linux-uclibcgnueabi/sysroot
export CROSS_COMPILE=/opt/miyoo/usr/bin/arm-linux-
make clean
make
```
You'll need to convert your logo image into a "0x" formatted hexadecimal data string and add it to "assets.h". (The same goes for the sound file.)
You have to also count the total number of "initialisers", the comma separated values, in your hexadecimal string, and write their total number
into the square brackets for the header identifier that contains your file.

**Tips:**

Expand Down
68 changes: 49 additions & 19 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,15 @@ void exit_event() {
}

int main(int argc, char* argv[]) {
char* homepath = getenv("HOME");
char logoimg_path[256], logosound_path[256], logobg_path[256];
if (homepath == NULL) {
printf("$HOME has not been defined in env");
} else {
sprintf(logoimg_path, "%s/logo.png", getenv("HOME"));
sprintf(logosound_path, "%s/logo.wav", getenv("HOME"));
sprintf(logobg_path, "%s/logobg.png", getenv("HOME"));
}
if (SDL_Init(SDL_INIT_VIDEO|SDL_INIT_AUDIO) != 0) {
printf("Unable to initialize SDL: %s\n", SDL_GetError());
return -1;
Expand All @@ -58,50 +67,71 @@ int main(int argc, char* argv[]) {
SDL_RWops *RWops;
SDL_Surface *logoimg;

if (FILE *f = fopen(logoimg_path, "r")) {
RWops = SDL_RWFromFile(logoimg_path, "rb");
} else {
printf("Didn't find PNG in %s - using default logoimg\n", logoimg_path);
#ifdef VERSION_POCKETGO
RWops = SDL_RWFromConstMem(png_logo_pocketgo, sizeof(png_logo_pocketgo));
RWops = SDL_RWFromConstMem(png_logo_pocketgo, sizeof(png_logo_pocketgo));
#elif VERSION_POWKIDDY
RWops = SDL_RWFromConstMem(png_logo_powkiddy, sizeof(png_logo_powkiddy));
RWops = SDL_RWFromConstMem(png_logo_powkiddy, sizeof(png_logo_powkiddy));
#elif VERSION_BITTBOY
RWops = SDL_RWFromConstMem(png_logo_bittboy, sizeof(png_logo_bittboy));
RWops = SDL_RWFromConstMem(png_logo_bittboy, sizeof(png_logo_bittboy));
#elif VERSION_GENERIC
RWops = SDL_RWFromConstMem(png_logo_generic, sizeof(png_logo_generic));
RWops = SDL_RWFromConstMem(png_logo_generic, sizeof(png_logo_generic));
#else
RWops = SDL_RWFromConstMem(png_logo_miyoo, sizeof(png_logo_miyoo));
RWops = SDL_RWFromConstMem(png_logo_miyoo, sizeof(png_logo_miyoo));
#endif

logoimg = IMG_LoadPNG_RW(RWops);
if (!logoimg) {
printf("Error loading logo: %s\n", IMG_GetError());
return -1;
}
}
logoimg = IMG_LoadPNG_RW(RWops);
if (!logoimg) {
printf("Error loading logo: %s\n", IMG_GetError());
return -1;
}

Mix_OpenAudio(22050, AUDIO_S16SYS, 2, 1024);
Mix_OpenAudio(22050, AUDIO_S16SYS, 2, 1024);
Mix_AllocateChannels(2);
SDL_RWops *RWops2;
Mix_Chunk *logosound;

RWops2 = SDL_RWFromConstMem(wav_logosound, sizeof(wav_logosound));
logosound = Mix_LoadWAV_RW(RWops2, 0);
if (!logosound) {
printf("Error loading sound: %s\n", Mix_GetError());
return -1;
}
if (FILE *f = fopen(logosound_path, "r")) {
RWops2 = SDL_RWFromFile(logosound_path, "rb");
} else {
printf("Didn't find WAV in %s - using default logosound\n", logosound_path);
RWops2 = SDL_RWFromConstMem(wav_logosound, sizeof(wav_logosound));
}
logosound = Mix_LoadWAV_RW(RWops2, 0);
if (!logosound) {
printf("Error loading sound: %s\n", Mix_GetError());
return -1;
}

int dest_y = (screen->h - logoimg->h) / 2;
uint32_t curr_time = SDL_GetTicks();
uint32_t old_time = curr_time;
uint32_t color = SDL_MapRGB(screen->format, R, G, B);
bool blitbg = false;
SDL_Rect rect;
SDL_Rect dstrect;
SDL_Event event;
SDL_Surface* logobg;
if (FILE *f = fopen(logobg_path, "r")) {
logobg = IMG_Load(logobg_path);
blitbg = true;
} else {
printf("Didn't find PNG in %s - using default background\n", logobg_path);
}
for (int i = 0 - logoimg->h - ANIMDELAY; i <= dest_y; i = i + ANIMSPEED) {
exit_event();
rect.x = 0;
rect.y = 0;
rect.w = screen->w;
rect.h = screen->h;
SDL_FillRect(screen, &rect, color);
if (blitbg) {
SDL_BlitSurface(logobg, NULL, screen, &rect);
} else {
SDL_FillRect(screen, &rect, color);
}
dstrect.x = (screen->w - logoimg->w) / 2;
dstrect.y = i;
dstrect.w = logoimg->w;
Expand Down

0 comments on commit 536cb58

Please sign in to comment.