Skip to content

Commit cc7c640

Browse files
committed
- change/fix key override handling
- fix/improve input code - better memory management - improved drawing
1 parent 4a8d708 commit cc7c640

15 files changed

Lines changed: 169 additions & 249 deletions

File tree

source/arm9/source/hid.c

Lines changed: 6 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,18 @@
11
#include "hid.h"
22

33
void hidScanInput() {}
4-
4+
u32 key_old = 0x00000000;
55

66
u32 hidKeysDown() {
77

8-
u32 key = 0;
9-
vu32 t = 0;
10-
11-
while (HID_STATE != 0x00000FFF);
12-
while (true) {
13-
14-
key = HID_STATE;
15-
if(key != 0x00000FFF)
16-
break;
17-
}
18-
19-
for (t = 0; t < 0x150000; t++) {}
20-
21-
return ~key;
22-
}
23-
24-
u32 hidKeysDownTimeout(int seconds) {
25-
26-
u32 key = 0;
27-
vu32 t = 0;
28-
u64 timeout = 0; // fake timer
29-
30-
while (HID_STATE != 0x00000FFF);
31-
while (true) {
32-
33-
key = HID_STATE;
34-
if(key != 0x00000FFF)
35-
break;
8+
u32 key = HID_STATE;
369

37-
if(seconds > 0) {
38-
timeout++;
39-
if ((int)(timeout/200000) > seconds)
40-
break;
41-
}
10+
if(key_old != key) {
11+
key_old = key;
12+
return ~key;
4213
}
43-
for (t = 0; t < 0x150000; t++) {}
4414

45-
return ~key;
15+
return 0x00000000;
4616
}
4717

4818
u32 hidKeysHeld() {

source/arm9/source/hid.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
#define HID_STATE (*(volatile u32*)0x10146000)
66

7+
#define BIT(n) (1U<<(n))
8+
79
#define KEY_A (1 << 0)
810
#define KEY_B (1 << 1)
911
#define KEY_SELECT (1 << 2)
@@ -22,11 +24,7 @@
2224
#define KEY_L KEY_L1
2325
#define KEY_X (1 << 10)
2426
#define KEY_Y (1 << 11)
25-
#define KEY_ANY 0x00000FFF
26-
27-
#define BIT(n) (1U<<(n))
2827

2928
u32 hidKeysDown();
3029
u32 hidKeysHeld();
31-
u32 hidKeysDownTimeout(int seconds);
3230
void hidScanInput();

source/arm9/stage2/data/stage2.bin

-100 Bytes
Binary file not shown.

source/arm9/stage2/payload/payload_stage2.ld

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ ENTRY(_start)
44

55
MEMORY
66
{
7-
ram : ORIGIN = 0x23000000, LENGTH = 16K
7+
ram : ORIGIN = 0x08006000, LENGTH = 0x10000K
88
}
99

1010
SECTIONS

source/arm9/stage2/payload/source/common.h

Lines changed: 0 additions & 41 deletions
This file was deleted.

source/arm9/stage2/payload/source/main.c

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,13 @@
1-
#include "common.h"
1+
#include <string.h>
22

33
#define PTR_PAYLOAD_MAIN 0x23F00000
4-
#define PTR_PAYLOAD_MAIN_DATA 0x20000000
5-
#define PTR_PAYLOAD_SIZE_MAX 0x00100000
6-
#define PTR_PAYLOAD_STAGE2 0x23000000
4+
#define PTR_PAYLOAD_MAIN_DATA 0x26000000
5+
#define PTR_PAYLOAD_SIZE_MAX 0x000FFD00
6+
#define PTR_PAYLOAD_STAGE2 0x08006000
77

88
int main()
99
{
1010
memcpy((void*)PTR_PAYLOAD_MAIN, (void*)PTR_PAYLOAD_MAIN_DATA, PTR_PAYLOAD_SIZE_MAX);
11-
12-
//gateway
13-
*(volatile uint32_t*)0x80FFFC0 = 0x18300000; // framebuffer 1 top left
14-
*(volatile uint32_t*)0x80FFFC4 = 0x18300000; // framebuffer 2 top left
15-
*(volatile uint32_t*)0x80FFFC8 = 0x18300000; // framebuffer 1 top right
16-
*(volatile uint32_t*)0x80FFFCC = 0x18300000; // framebuffer 2 top right
17-
*(volatile uint32_t*)0x80FFFD0 = 0x18346500; // framebuffer 1 bottom
18-
*(volatile uint32_t*)0x80FFFD4 = 0x18346500; // framebuffer 2 bottom
19-
*(volatile uint32_t*)0x80FFFD8 = 1; // framebuffer select top
20-
*(volatile uint32_t*)0x80FFFDC = 1; // framebuffer select bottom
21-
22-
//cakehax
23-
*(u32*)0x23FFFE00 = 0x18300000;
24-
*(u32*)0x23FFFE04 = 0x18300000;
25-
*(u32*)0x23FFFE08 = 0x18346500;
26-
2711
((void (*)())PTR_PAYLOAD_MAIN)();
2812

2913
return 0;

source/config_new.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
#include "config.h"
1616
#include "gfx.h"
1717

18-
boot_config_s sconf;
18+
//boot_config_s sconf;
1919
#else
2020
#include <3ds.h>
2121
#endif
@@ -138,7 +138,7 @@ int configInit() {
138138

139139
// init config
140140
#ifdef ARM9
141-
config = &sconf;
141+
config = (boot_config_s *)PTR_CFG;
142142
#else
143143
config = malloc(sizeof(boot_config_s));
144144
#endif
@@ -222,7 +222,7 @@ void loadBg(gfxScreen_t screen) {
222222
}
223223

224224
#ifdef ARM9
225-
u8 *bg = screen == GFX_TOP ? PTR_TOP_BG_BUF : PTR_BOT_BG_BUF;
225+
u8 *bg = screen == GFX_TOP ? PTR_TOP_BG : PTR_BOT_BG;
226226
#else
227227
u8 *bg = malloc(size);
228228
#endif

source/gfx.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,15 @@ void gfxClearBot(u8 bot[8]) {
179179
gfxFillColor(GFX_BOTTOM, GFX_LEFT, bot);
180180
}
181181

182+
void gfxClear() {
183+
memset(PTR_TOP_SCREEN, 0, TOP_SCREEN_SIZE);
184+
memset(PTR_BOT_SCREEN, 0, BOT_SCREEN_SIZE);
185+
memset(PTR_TOP_SCREEN_BUF, 0, TOP_SCREEN_SIZE);
186+
memset(PTR_BOT_SCREEN_BUF, 0, BOT_SCREEN_SIZE);
187+
memset(PTR_TOP_BG, 0, TOP_SCREEN_SIZE);
188+
memset(PTR_BOT_BG, 0, BOT_SCREEN_SIZE);
189+
}
190+
182191
void gfxSwap() {
183192
#ifdef ARM9
184193
memcpy(PTR_TOP_SCREEN, PTR_TOP_SCREEN_BUF, TOP_SCREEN_SIZE);

source/gfx.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,6 @@ void gfxClearTop(u8 top1[3], u8 top2[3]);
3535

3636
void gfxClearBot(u8 bot[8]);
3737

38+
void gfxClear();
39+
3840
void gfxSwap();

source/loader.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#else
66

77
#include "gfx.h"
8-
#include "arm9/source/common.h"
8+
#include "arm9/source/fatfs/ff.h"
99
#include "stage2_bin.h"
1010

1111
#endif
@@ -22,10 +22,12 @@ int load_bin(char *path, long offset) {
2222
return -1;
2323
}
2424

25-
if (fileReadOffset(path, (void *) PTR_PAYLOAD_MAIN_DATA, size, offset) != 0) {
25+
if (fileReadOffset(path, (void *) PTR_PAYLOAD_MAIN_DATA, PTR_PAYLOAD_SIZE_MAX, offset) != 0) {
2626
return -1;
2727
}
2828

29+
gfxClear();
30+
2931
memcpy((void *) PTR_PAYLOAD_STAGE2, stage2_bin, stage2_bin_size);
3032
((void (*)()) PTR_PAYLOAD_STAGE2)();
3133

0 commit comments

Comments
 (0)