Skip to content
This repository has been archived by the owner on May 17, 2023. It is now read-only.

Commit

Permalink
Initial Release
Browse files Browse the repository at this point in the history
  • Loading branch information
Slattz committed Apr 14, 2017
0 parents commit 59e7220
Show file tree
Hide file tree
Showing 51 changed files with 30,568 additions and 0 deletions.
42 changes: 42 additions & 0 deletions 3ds.ld
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@

OUTPUT_FORMAT("elf32-littlearm", "elf32-bigarm", "elf32-littlearm")
OUTPUT_ARCH(arm)
ENTRY(_Reset)
SECTIONS
{
. = 0x00100000;

. = ALIGN(4);
.text :
{
__text_start = .;
bootloader.o (.text*)
*(.text*)
}

. = ALIGN(4);
.data :
{
*(.data)
}

. = ALIGN(4);
.rel.dyn :
{
*(.__rel_dyn_start)
*(.rel*)
*(.rel.*)
*(.__rel_dyn_end)
}

__code_end = .;

. = ALIGN(4);
.bss :
{
*(.__bss_start)
*(.bss COMMON)
*(.__bss_end)
}
__end__ = .;
}
87 changes: 87 additions & 0 deletions Includes/common.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
#ifndef COMMON_H
#define COMMON_H
#include "plugin.h"
#include "hid.h"

extern u32 IoBasePad;
extern vu32 *pad_base;

static inline int is_pressed(u32 keys)
{
if (pad_base != NULL)
{
if (((hidKeysDown() & keys) == keys))
return (1);
}
else
if (((((*(vu32*)(IoBasePad) ^ 0xFFF) & 0xFFF) & keys) == keys))
return (1);
return (0);
}

static inline int any_is_pressed(u32 keys)
{
if (pad_base != NULL)
{
if (((hidKeysDown() & keys)))
return (1);
}
else
if (((((*(vu32*)(IoBasePad) ^ 0xFFF) & 0xFFF) & keys)))
return (1);
return (0);
}

static inline void wait_keys(u32 keys)
{
while (!(any_is_pressed(keys)))
continue;
}

static inline void wait_keys_released(u32 keys)
{
while (1)
if (!(any_is_pressed(keys)))
return;
}

static inline void wait_all_released(void)
{
while (1)
if (((*(vu32*)(IoBasePad) ^ 0xFFF) & 0xFFF) == 0)
return;
}

static inline int upper_left_touched(void)
{
if (is_pressed(KEY_TOUCH))
if (hidTouchPos().px < 160 && hidTouchPos().py < 120)
return (1);
return (0);
}

static inline int upper_right_touched(void)
{
if (is_pressed(KEY_TOUCH))
if (hidTouchPos().px >= 160 && hidTouchPos().py < 120)
return (1);
return (0);
}

static inline int lower_left_touched(void)
{
if (is_pressed(KEY_TOUCH))
if (hidTouchPos().px < 160 && hidTouchPos().py >= 120)
return (1);
return (0);
}

static inline int lower_right_touched(void)
{
if (is_pressed(KEY_TOUCH))
if (hidTouchPos().px >= 160 && hidTouchPos().py >= 120)
return (1);
return (0);
}

#endif
146 changes: 146 additions & 0 deletions Includes/configs.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
#ifndef WRITEU8
# define WRITEU8(addr, data) *(vu8*)(addr) = data
#endif
#ifndef WRITEU16
# define WRITEU16(addr, data) *(vu16*)(addr) = data
#endif
#ifndef WRITEU32
# define WRITEU32(addr, data) *(vu32*)(addr) = data
#endif
#ifndef WRITES64
# define WRITES64(addr, data) *(vs64*)(addr) = data
#endif
#ifndef READU8
# define READU8(addr) *(vu8*)(addr)
#endif
#ifndef READU16
# define READU16(addr) *(vu16*)(addr)
#endif
#ifndef READU32
# define READU32(addr) *(vu32*)(addr)
#endif
#ifndef READS64
# define READS64(addr) *(vs64*)(addr)
#endif

#ifndef IO_BASE_PAD
# define IO_BASE_PAD 1
#endif
#ifndef IO_BASE_LCD
# define IO_BASE_LCD 2
#endif
#ifndef IO_BASE_PDC
# define IO_BASE_PDC 3
#endif
#ifndef IO_BASE_GSPHEAP
# define IO_BASE_GSPHEAP 4
#endif
#ifndef BUTTON_A
# define BUTTON_A 0x00000001
#endif
#ifndef BUTTON_B
# define BUTTON_B 0x00000002
#endif
#ifndef BUTTON_SE
# define BUTTON_SE 0x00000004
#endif
#ifndef BUTTON_ST
# define BUTTON_ST 0x00000008
#endif
#ifndef BUTTON_DR
# define BUTTON_DR 0x00000010
#endif
#ifndef BUTTON_DL
# define BUTTON_DL 0x00000020
#endif
#ifndef BUTTON_DU
# define BUTTON_DU 0x00000040
#endif
#ifndef BUTTON_DD
# define BUTTON_DD 0x00000080
#endif
#ifndef BUTTON_R
# define BUTTON_R 0x00000100
#endif
#ifndef BUTTON_L
# define BUTTON_L 0x00000200
#endif
#ifndef BUTTON_ZR
# define BUTTON_ZR 0x00008000
#endif
#ifndef BUTTON_ZL
# define BUTTON_ZL 0x00004000
#endif
#ifndef BUTTON_X
# define BUTTON_X 0x00000400
#endif
#ifndef BUTTON_Y
# define BUTTON_Y 0x00000800
#endif
#ifndef BUTTON_CD
# define BUTTON_CD 0x80000000
#endif
#ifndef BUTTON_CL
# define BUTTON_CL 0x20000000
#endif
#ifndef BUTTON_CR
# define BUTTON_CR 0x10000000
#endif
#ifndef BUTTON_CU
# define BUTTON_CU 0x40000000
#endif

#ifndef A
# define A BUTTON_A
#endif
#ifndef B
# define B BUTTON_B
#endif
#ifndef X
# define X BUTTON_X
#endif
#ifndef Y
# define Y BUTTON_Y
#endif
#ifndef L
# define L BUTTON_L
#endif
#ifndef R
# define R BUTTON_R
#endif
#ifndef ZL
# define ZL BUTTON_ZL
#endif
#ifndef ZR
# define ZR BUTTON_ZR
#endif
#ifndef ST
# define ST BUTTON_ST
#endif
#ifndef SE
# define SE BUTTON_SE
#endif
#ifndef DU
# define DU BUTTON_DU
#endif
#ifndef DD
# define DD BUTTON_DD
#endif
#ifndef DL
# define DL BUTTON_DL
#endif
#ifndef DR
# define DR BUTTON_DR
#endif
#ifndef CU
# define CU BUTTON_CU
#endif
#ifndef CL
# define CL BUTTON_CL
#endif
#ifndef CR
# define CR BUTTON_CR
#endif
#ifndef CD
# define CD BUTTON_CD
#endif
52 changes: 52 additions & 0 deletions Includes/hid.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#ifndef MYHID_H
#define MYHID_H

#include "types.h"
#define BIT(x) (1U << x)

enum
{
KEY_A = BIT(0), ///< A
KEY_B = BIT(1), ///< B
KEY_SELECT = BIT(2), ///< Select
KEY_START = BIT(3), ///< Start
KEY_DRIGHT = BIT(4), ///< D-Pad Right
KEY_DLEFT = BIT(5), ///< D-Pad Left
KEY_DUP = BIT(6), ///< D-Pad Up
KEY_DDOWN = BIT(7), ///< D-Pad Down
KEY_R = BIT(8), ///< R
KEY_L = BIT(9), ///< L
KEY_X = BIT(10), ///< X
KEY_Y = BIT(11), ///< Y
KEY_ZL = BIT(14), ///< ZL (New 3DS only)
KEY_ZR = BIT(15), ///< ZR (New 3DS only)
KEY_TOUCH = BIT(20), ///< Touch (Not actually provided by HID)
KEY_CSTICK_RIGHT = BIT(24), ///< C-Stick Right (New 3DS only)
KEY_CSTICK_LEFT = BIT(25), ///< C-Stick Left (New 3DS only)
KEY_CSTICK_UP = BIT(26), ///< C-Stick Up (New 3DS only)
KEY_CSTICK_DOWN = BIT(27), ///< C-Stick Down (New 3DS only)
KEY_CPAD_RIGHT = BIT(28), ///< Circle Pad Right
KEY_CPAD_LEFT = BIT(29), ///< Circle Pad Left
KEY_CPAD_UP = BIT(30), ///< Circle Pad Up
KEY_CPAD_DOWN = BIT(31), ///< Circle Pad Down

// Generic catch-all directions
KEY_UP = KEY_DUP | KEY_CPAD_UP, ///< D-Pad Up or Circle Pad Up
KEY_DOWN = KEY_DDOWN | KEY_CPAD_DOWN, ///< D-Pad Down or Circle Pad Down
KEY_LEFT = KEY_DLEFT | KEY_CPAD_LEFT, ///< D-Pad Left or Circle Pad Left
KEY_RIGHT = KEY_DRIGHT | KEY_CPAD_RIGHT, ///< D-Pad Right or Circle Pad Right
KEY_CPAD = KEY_CPAD_DOWN | KEY_CPAD_UP | KEY_CPAD_LEFT | KEY_CPAD_RIGHT
};

typedef struct s_touch
{
u16 px; ///< Touch X
u16 py; ///< Touch Y
} t_touch;

u32 hidKeysDown(void);
t_touch hidTouchPos(void);
void set_hid_address(u32 address);
void setHID(u32 keys);

#endif
Loading

0 comments on commit 59e7220

Please sign in to comment.