Skip to content

Commit

Permalink
Fix a critical bug
Browse files Browse the repository at this point in the history
  • Loading branch information
d0k3 committed Mar 31, 2018
1 parent 31c66e7 commit 3e5c7c6
Show file tree
Hide file tree
Showing 13 changed files with 91 additions and 6 deletions.
5 changes: 3 additions & 2 deletions arm9/source/common/colors.h
@@ -1,5 +1,6 @@
#pragma once

#include "lottery.h"

#define RGB(r,g,b) ((b)<<16|(g)<<8|(r))

Expand Down Expand Up @@ -31,8 +32,8 @@
#define COLOR_SUPERFUCHSIA RGB(0xFF, 0x00, 0xEF)

// standard colors - used everywhere
#define COLOR_STD_BG COLOR_BLACK
#define COLOR_STD_FONT COLOR_WHITE
#define COLOR_STD_BG LOTTERY_COLOR_BG
#define COLOR_STD_FONT LOTTERY_COLOR_FONT

// colors for GodMode9 file browser
#define COLOR_SIDE_BAR COLOR_DARKGREY
Expand Down
54 changes: 54 additions & 0 deletions arm9/source/common/lottery.c
@@ -0,0 +1,54 @@
#include "lottery.h"
#include "rtc.h"
#include "colors.h"
#include "vram0.h"

#define LOTTERY_MAX 8

const LotteryTheme lo_theme[] =
{
{ // standard scheme
COLOR_WHITE,
COLOR_BLACK,
VRAM0_SPLASH_PCX,
VRAM0_FONT_PBM,
false
},
{ // bricked scheme
RGB(0xFF, 0xFF, 0x00),
RGB(0x00, 0x00, 0xFF),
"lottery/bricked/bootrom_splash.pcx",
"lottery/bricked/font_nbraille_4x6.pbm",
true
},
{ // C64 scheme
RGB(0x7B, 0x71, 0xD5),
RGB(0x41, 0x30, 0xA4),
"lottery/c64/c64_splash.pcx",
"lottery/c64/font_c64_8x8.pbm",
false
},
{ // mirror scheme
COLOR_WHITE,
COLOR_BLACK,
"lottery/mirror/mirror_splash.pcx",
"lottery/mirror/font_6x10_mr.pbm",
false
},
{ // zuish scheme
COLOR_WHITE,
COLOR_BLACK,
"lottery/zuish/zuish_splash.pcx",
"lottery/zuish/font_zuish_8x8.pbm",
false
}
};

u32 lo_n = 0;

u32 InitLottery(void) {
DsTime dstime;
get_dstime(&dstime);
lo_n = (DSTIMEGET(&dstime, bcd_s)>>1) % LOTTERY_MAX;
return lo_n;
}
26 changes: 26 additions & 0 deletions arm9/source/common/lottery.h
@@ -0,0 +1,26 @@
#pragma once

#include "common.h"


// general scheme access
#define LOTTERY_N ((lo_n > 4) ? 0 : lo_n)
#define LOTTERY_COLOR_FONT (lo_theme[LOTTERY_N].color_font)
#define LOTTERY_COLOR_BG (lo_theme[LOTTERY_N].color_bg)
#define LOTTERY_SPLASH (lo_theme[LOTTERY_N].splash)
#define LOTTERY_FONT (lo_theme[LOTTERY_N].font)
#define LOTTERY_PROMPTHACK (lo_theme[LOTTERY_N].prompthack)


typedef struct {
const u32 color_font;
const u32 color_bg;
const char* splash;
const char* font;
const bool prompthack;
} __attribute__((packed)) LotteryTheme;

extern const LotteryTheme lo_theme[];
extern u32 lo_n;

u32 InitLottery(void);
4 changes: 3 additions & 1 deletion arm9/source/common/ui.c
Expand Up @@ -14,6 +14,7 @@
#include "timer.h"
#include "power.h"
#include "hid.h"
#include "lottery.h"

#define STRBUF_SIZE 512 // maximum size of the string buffer
#define FONT_MAX_WIDTH 8
Expand Down Expand Up @@ -95,7 +96,7 @@ bool SetFontFromPbm(const void* pbm, u32 pbm_size) {

if (!pbm) {
u64 pbm_size64 = 0;
pbm = FindVTarFileInfo(VRAM0_FONT_PBM, &pbm_size64);
pbm = FindVTarFileInfo(LOTTERY_FONT, &pbm_size64);
pbm_size = (u32) pbm_size64;
}

Expand Down Expand Up @@ -276,6 +277,7 @@ void DrawStringCenter(u8* screen, int color, int bgcolor, const char *format, ..
u32 h = GetDrawStringHeight(str);
int x = (w >= SCREEN_WIDTH(screen)) ? 0 : (SCREEN_WIDTH(screen) - w) >> 1;
int y = (h >= SCREEN_HEIGHT) ? 0 : (SCREEN_HEIGHT - h) >> 1;
if (LOTTERY_PROMPTHACK) x = y = 8;

DrawStringF(screen, x, y, color, bgcolor, str);
}
Expand Down
8 changes: 5 additions & 3 deletions arm9/source/godmode.c
Expand Up @@ -19,6 +19,7 @@
#include "power.h"
#include "vram0.h"
#include "i2c.h"
#include "lottery.h"


#define N_PANES 2
Expand Down Expand Up @@ -47,7 +48,7 @@ typedef struct {

u32 SplashInit(const char* modestr) {
u64 splash_size;
u8* splash = FindVTarFileInfo(VRAM0_SPLASH_PCX, &splash_size);
u8* splash = FindVTarFileInfo(LOTTERY_SPLASH, &splash_size);
u8* bitmap = (u8*) malloc(SCREEN_SIZE_TOP);
const char* namestr = FLAVOR " " VERSION;
const char* loadstr = "booting...";
Expand All @@ -61,7 +62,7 @@ u32 SplashInit(const char* modestr) {
if (splash && bitmap && PCX_Decompress(bitmap, SCREEN_SIZE_TOP, splash, splash_size)) {
PCXHdr* hdr = (PCXHdr*) (void*) splash;
DrawBitmap(TOP_SCREEN, -1, -1, PCX_Width(hdr), PCX_Height(hdr), bitmap);
} else DrawStringF(TOP_SCREEN, 10, 10, COLOR_STD_FONT, COLOR_TRANSPARENT, "(" VRAM0_SPLASH_PCX " not found)");
} else DrawStringF(TOP_SCREEN, 10, 10, COLOR_STD_FONT, COLOR_TRANSPARENT, "(%s not found)", LOTTERY_SPLASH);
if (modestr) DrawStringF(TOP_SCREEN, SCREEN_WIDTH_TOP - 10 - GetDrawStringWidth(modestr),
SCREEN_HEIGHT - 10 - GetDrawStringHeight(modestr), COLOR_STD_FONT, COLOR_TRANSPARENT, modestr);

Expand Down Expand Up @@ -1932,7 +1933,8 @@ u32 GodMode(int entrypoint) {
show_splash = !bootloader;
#endif

// init font
// init font / lottery
InitLottery();
if (!SetFontFromPbm(NULL, 0)) return exit_mode;

// show splash screen (if enabled)
Expand Down
Binary file added data/lottery/bricked/bootrom_splash.pcx
Binary file not shown.
Binary file added data/lottery/bricked/font_nbraille_4x6.pbm
Binary file not shown.
Binary file added data/lottery/c64/c64_splash.pcx
Binary file not shown.
Binary file added data/lottery/c64/font_c64_8x8.pbm
Binary file not shown.
Binary file added data/lottery/mirror/font_6x10_mr.pbm
Binary file not shown.
Binary file added data/lottery/mirror/mirror_splash.pcx
Binary file not shown.
Binary file added data/lottery/zuish/font_zuish_8x8.pbm
Binary file not shown.
Binary file added data/lottery/zuish/zuish_splash.pcx
Binary file not shown.

3 comments on commit 3e5c7c6

@Moire9
Copy link
Contributor

@Moire9 Moire9 commented on 3e5c7c6 Apr 1, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It appears that after a few reboots that the "lottery" has some bugs, namely always running the "standard" mode. To fix this one should simply turn off the 3DS and boot GM9.

@d0k3
Copy link
Owner Author

@d0k3 d0k3 commented on 3e5c7c6 Apr 3, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not possible. The pseudo RNG in there is actually based on the current seconds in the RTC. You might get a lot of normal boots in succession, but it won't be stuck on the normal boot.

@Moire9
Copy link
Contributor

@Moire9 Moire9 commented on 3e5c7c6 Apr 3, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that was because I was rebooting in quick succession, so the RTC was essentially the same. Why can't we generate true random numbers? Is the arm11 not powerful enough?

Please sign in to comment.