sub: exi, pad

This commit is contained in:
PikalaxALT 2021-12-20 16:47:06 -05:00
parent cc142257a0
commit 0479237582
10 changed files with 180 additions and 94 deletions

View File

@ -92,7 +92,7 @@ LCF := $(NEF:%.nef=%.lcf)
SBIN := $(NEF:%.nef=%.sbin)
XMAP := $(NEF).xMAP
MWCFLAGS = $(DEFINES) $(OPTFLAGS) -enum int -lang c99 -Cpp_exceptions off -gccext,on -proc $(PROC) -msgstyle gcc -gccinc -i ./include -i $(WORK_DIR)/files -I$(WORK_DIR)/lib/include -ipa file -interworking
MWCFLAGS = $(DEFINES) $(OPTFLAGS) -enum int -lang c99 -Cpp_exceptions off -gccext,on -proc $(PROC) -msgstyle gcc -gccinc -i ./include -i $(WORK_DIR)/files -I$(WORK_DIR)/lib/include -ipa file -interworking -inline on,noauto
MWASFLAGS = $(DEFINES) -proc $(PROC_S) -i ./include -DSDK_ASM
MWLDFLAGS := -w off -proc $(PROC) -nopic -nopid -interworking -map closure,unused -symtab sort -m _start -msgstyle gcc
ARFLAGS := rcS

View File

@ -17,5 +17,6 @@
#include <nitro/snd.h>
#include <nitro/pad.h>
#include <nitro/rtc.h>
#include <nitro/exi.h>
#endif //NITRO_H_

8
lib/include/nitro/exi.h Normal file
View File

@ -0,0 +1,8 @@
#ifndef GUARD_EXI_H
#define GUARD_EXI_H
#ifdef SDK_ARM7
#include <nitro/exi/ARM7/genPort.h>
#endif //SDK_ARM7
#endif //GUARD_EXI_H

View File

@ -0,0 +1,16 @@
#ifndef NITRO_EXI_GENPORT_H_
#define NITRO_EXI_GENPORT_H_
#include <nitro/hw/ARM7/io_reg.h>
typedef enum {
EXI_GPIOIF_SERIAL = 0x0000,
EXI_GPIOIF_UNDEF = REG_EXI_RCNT0_L_RE0_MASK,
EXI_GPIOIF_GPIO = REG_EXI_RCNT0_L_RE1_MASK,
EXI_GPIOIF_JOY = REG_EXI_RCNT0_L_RE1_MASK | REG_EXI_RCNT0_L_RE0_MASK
} EXIGpioIF;
void EXIi_SetBitRcnt0L(u16 mask, u16 data);
void EXIi_SelectRcnt(EXIGpioIF type);
#endif //NITRO_EXI_GENPORT_H_

View File

@ -95,4 +95,117 @@
#endif
#define REG_RCNT0_L_OFFSET 0x134
#define REG_RCNT0_L_ADDR (HW_REG_BASE + REG_RCNT0_L_OFFSET)
#define reg_EXI_RCNT0_L (*(REGType16v *)REG_RCNT0_L_ADDR)
#define REG_RCNT0_H_OFFSET 0x136
#define REG_RCNT0_H_ADDR (HW_REG_BASE + REG_RCNT0_H_OFFSET)
#define reg_EXI_RCNT0_H (*(REGType16v *)REG_RCNT0_H_ADDR)
#define REG_EXI_RCNT0_L_RE1_SHIFT 15
#define REG_EXI_RCNT0_L_RE1_SIZE 1
#define REG_EXI_RCNT0_L_RE1_MASK 0x8000
#define REG_EXI_RCNT0_L_RE0_SHIFT 14
#define REG_EXI_RCNT0_L_RE0_SIZE 1
#define REG_EXI_RCNT0_L_RE0_MASK 0x4000
#define REG_EXI_RCNT0_L_I_SHIFT 8
#define REG_EXI_RCNT0_L_I_SIZE 1
#define REG_EXI_RCNT0_L_I_MASK 0x0100
#define REG_EXI_RCNT0_L_DIR_SO_SHIFT 7
#define REG_EXI_RCNT0_L_DIR_SO_SIZE 1
#define REG_EXI_RCNT0_L_DIR_SO_MASK 0x0080
#define REG_EXI_RCNT0_L_DIR_SI_SHIFT 6
#define REG_EXI_RCNT0_L_DIR_SI_SIZE 1
#define REG_EXI_RCNT0_L_DIR_SI_MASK 0x0040
#define REG_EXI_RCNT0_L_DIR_SD_SHIFT 5
#define REG_EXI_RCNT0_L_DIR_SD_SIZE 1
#define REG_EXI_RCNT0_L_DIR_SD_MASK 0x0020
#define REG_EXI_RCNT0_L_DIR_SC_SHIFT 4
#define REG_EXI_RCNT0_L_DIR_SC_SIZE 1
#define REG_EXI_RCNT0_L_DIR_SC_MASK 0x0010
#define REG_EXI_RCNT0_L_DATA_SO_SHIFT 3
#define REG_EXI_RCNT0_L_DATA_SO_SIZE 1
#define REG_EXI_RCNT0_L_DATA_SO_MASK 0x0008
#define REG_EXI_RCNT0_L_DATA_SI_SHIFT 2
#define REG_EXI_RCNT0_L_DATA_SI_SIZE 1
#define REG_EXI_RCNT0_L_DATA_SI_MASK 0x0004
#define REG_EXI_RCNT0_L_DATA_SD_SHIFT 1
#define REG_EXI_RCNT0_L_DATA_SD_SIZE 1
#define REG_EXI_RCNT0_L_DATA_SD_MASK 0x0002
#define REG_EXI_RCNT0_L_DATA_SC_SHIFT 0
#define REG_EXI_RCNT0_L_DATA_SC_SIZE 1
#define REG_EXI_RCNT0_L_DATA_SC_MASK 0x0001
#ifndef SDK_ASM
#define REG_EXI_RCNT0_L_FIELD( re1, re0, i, dir_so, dir_si, dir_sd, dir_sc, data_so, data_si, data_sd, data_sc ) \
(u16)( \
((u32)(re1) << REG_EXI_RCNT0_L_RE1_SHIFT) | \
((u32)(re0) << REG_EXI_RCNT0_L_RE0_SHIFT) | \
((u32)(i) << REG_EXI_RCNT0_L_I_SHIFT) | \
((u32)(dir_so) << REG_EXI_RCNT0_L_DIR_SO_SHIFT) | \
((u32)(dir_si) << REG_EXI_RCNT0_L_DIR_SI_SHIFT) | \
((u32)(dir_sd) << REG_EXI_RCNT0_L_DIR_SD_SHIFT) | \
((u32)(dir_sc) << REG_EXI_RCNT0_L_DIR_SC_SHIFT) | \
((u32)(data_so) << REG_EXI_RCNT0_L_DATA_SO_SHIFT) | \
((u32)(data_si) << REG_EXI_RCNT0_L_DATA_SI_SHIFT) | \
((u32)(data_sd) << REG_EXI_RCNT0_L_DATA_SD_SHIFT) | \
((u32)(data_sc) << REG_EXI_RCNT0_L_DATA_SC_SHIFT))
#endif
#define REG_EXI_RCNT0_H_DATA_R7_SHIFT 7
#define REG_EXI_RCNT0_H_DATA_R7_SIZE 1
#define REG_EXI_RCNT0_H_DATA_R7_MASK 0x0080
#define REG_EXI_RCNT0_H_DATA_R6_SHIFT 6
#define REG_EXI_RCNT0_H_DATA_R6_SIZE 1
#define REG_EXI_RCNT0_H_DATA_R6_MASK 0x0040
#define REG_EXI_RCNT0_H_DATA_R5_SHIFT 5
#define REG_EXI_RCNT0_H_DATA_R5_SIZE 1
#define REG_EXI_RCNT0_H_DATA_R5_MASK 0x0020
#define REG_EXI_RCNT0_H_DATA_R4_SHIFT 4
#define REG_EXI_RCNT0_H_DATA_R4_SIZE 1
#define REG_EXI_RCNT0_H_DATA_R4_MASK 0x0010
#define REG_EXI_RCNT0_H_DATA_R3_SHIFT 3
#define REG_EXI_RCNT0_H_DATA_R3_SIZE 1
#define REG_EXI_RCNT0_H_DATA_R3_MASK 0x0008
#define REG_EXI_RCNT0_H_DATA_R2_SHIFT 2
#define REG_EXI_RCNT0_H_DATA_R2_SIZE 1
#define REG_EXI_RCNT0_H_DATA_R2_MASK 0x0004
#define REG_EXI_RCNT0_H_DATA_R1_SHIFT 1
#define REG_EXI_RCNT0_H_DATA_R1_SIZE 1
#define REG_EXI_RCNT0_H_DATA_R1_MASK 0x0002
#define REG_EXI_RCNT0_H_DATA_R0_SHIFT 0
#define REG_EXI_RCNT0_H_DATA_R0_SIZE 1
#define REG_EXI_RCNT0_H_DATA_R0_MASK 0x0001
#ifndef SDK_ASM
#define REG_EXI_RCNT0_H_FIELD( data_r7, data_r6, data_r5, data_r4, data_r3, data_r2, data_r1, data_r0 ) \
(u16)( \
((u32)(data_r7) << REG_EXI_RCNT0_H_DATA_R7_SHIFT) | \
((u32)(data_r6) << REG_EXI_RCNT0_H_DATA_R6_SHIFT) | \
((u32)(data_r5) << REG_EXI_RCNT0_H_DATA_R5_SHIFT) | \
((u32)(data_r4) << REG_EXI_RCNT0_H_DATA_R4_SHIFT) | \
((u32)(data_r3) << REG_EXI_RCNT0_H_DATA_R3_SHIFT) | \
((u32)(data_r2) << REG_EXI_RCNT0_H_DATA_R2_SHIFT) | \
((u32)(data_r1) << REG_EXI_RCNT0_H_DATA_R1_SHIFT) | \
((u32)(data_r0) << REG_EXI_RCNT0_H_DATA_R0_SHIFT))
#endif
#endif //NITRO_HW_ARM7_IO_REG_H_

View File

@ -12,98 +12,6 @@
.public PXI_IsCallbackReady
.public PXIi_SetToFifo
arm_func_start EXIi_SetBitRcnt0L
EXIi_SetBitRcnt0L: ; 0x037FB51C
ldr r2, _037FB538 ; =0x04000134
mvn r3, r0
ldrh r0, [r2]
and r0, r3, r0
orr r0, r1, r0
strh r0, [r2]
bx lr
.align 2, 0
_037FB538: .word 0x04000134
arm_func_end EXIi_SetBitRcnt0L
arm_func_start EXIi_SelectRcnt
EXIi_SelectRcnt: ; 0x037FB53C
ldr ip, _037FB550 ; =EXIi_SetBitRcnt0L
mov r0, r0, lsl #0x10
mov r1, r0, lsr #0x10
mov r0, #0xc000
bx ip
.align 2, 0
_037FB550: .word EXIi_SetBitRcnt0L
arm_func_end EXIi_SelectRcnt
arm_func_start PAD_InitXYButton
PAD_InitXYButton: ; 0x037FB554
stmdb sp!, {lr}
sub sp, sp, #0xc
bl OS_IsTickAvailable
cmp r0, #0
beq _037FB574
bl OS_IsAlarmAvailable
cmp r0, #0
bne _037FB57C
_037FB574:
mov r0, #0
b _037FB5D4
_037FB57C:
ldr r0, _037FB5E0 ; =PADi_XYButtonAvailable
ldr r0, [r0]
cmp r0, #0
movne r0, #0
bne _037FB5D4
ldr r0, _037FB5E4 ; =PADi_XYButtonAlarm
bl OS_CreateAlarm
bl OS_GetTick
ldr r2, _037FB5E8 ; =PADi_XYButton_Callback
ldr r3, _037FB5EC ; =0x0000082E
str r2, [sp, #4]
adds ip, r0, r3
mov lr, #0
str lr, [sp, #8]
adc r2, r1, #0
ldr r0, _037FB5E4 ; =PADi_XYButtonAlarm
mov r1, ip
str lr, [sp]
bl OS_SetPeriodicAlarm
ldr r1, _037FB5E0 ; =PADi_XYButtonAvailable
mov r0, #1
str r0, [r1]
_037FB5D4:
add sp, sp, #0xc
ldmia sp!, {lr}
bx lr
.align 2, 0
_037FB5E0: .word PADi_XYButtonAvailable
_037FB5E4: .word PADi_XYButtonAlarm
_037FB5E8: .word PADi_XYButton_Callback
_037FB5EC: .word 0x0000082E
arm_func_end PAD_InitXYButton
arm_func_start PADi_XYButton_Callback
PADi_XYButton_Callback: ; 0x037FB5F0
stmdb sp!, {r4, lr}
mov r0, #0x8000
mov r4, #0
bl EXIi_SelectRcnt
ldr r0, _037FB628 ; =0x04000136
ldrh r1, [r0]
ldr r0, _037FB62C ; =0x027FFFA8
tst r1, #0x80
movne r4, #0x8000
and r1, r1, #0xb
orr r1, r4, r1, lsl #10
strh r1, [r0]
ldmia sp!, {r4, lr}
bx lr
.align 2, 0
_037FB628: .word 0x04000136
_037FB62C: .word 0x027FFFA8
arm_func_end PADi_XYButton_Callback
arm_func_start SND_Enable
SND_Enable: ; 0x037FB630
ldr r1, _037FB644 ; =0x04000501
@ -6610,6 +6518,7 @@ isFirstCheck$3676: ; 0x03806B04
.bss
.type PADi_XYButtonAlarm,@object
.public PADi_XYButtonAlarm
PADi_XYButtonAlarm: ; 0x03806E80
.space 0x2C
.size PADi_XYButtonAlarm,.-PADi_XYButtonAlarm

View File

@ -37,6 +37,7 @@ Autoload WRAM
Object MI_memory.o
Object MI_swap.o
Object PXI_fifo.o
Object EXI_genPort.o
Object PAD_xyButton.o
Object sub.wram_1.o
Object libsyscall.o

10
sub/lib/src/EXI_genPort.c Normal file
View File

@ -0,0 +1,10 @@
#include <nitro.h>
__declspec(noinline)
void EXIi_SetBitRcnt0L(u16 mask, u16 data) {
reg_EXI_RCNT0_L = (~mask & reg_EXI_RCNT0_L) | data;
}
void EXIi_SelectRcnt(EXIGpioIF type) {
EXIi_SetBitRcnt0L(REG_EXI_RCNT0_L_RE1_MASK | REG_EXI_RCNT0_L_RE0_MASK, type);
}

View File

@ -2,3 +2,30 @@
BOOL PADi_XYButtonAvailable = FALSE;
// OSAlarm PADi_XYButtonAlarm = {};
extern OSAlarm PADi_XYButtonAlarm;
void PADi_XYButton_Callback(void);
BOOL PAD_InitXYButton(void) {
if (!OS_IsTickAvailable() || !OS_IsAlarmAvailable()) {
return FALSE;
}
if (PADi_XYButtonAvailable) {
return FALSE;
}
OS_CreateAlarm(&PADi_XYButtonAlarm);
OS_SetPeriodicAlarm(&PADi_XYButtonAlarm, OS_GetTick() + 2094ll, 2094ll, (OSAlarmHandler)PADi_XYButton_Callback, NULL);
PADi_XYButtonAvailable = TRUE;
return TRUE;
}
void PADi_XYButton_Callback(void) {
u16 rcnt0_h;
u16 data_r7 = 0;
EXIi_SelectRcnt(EXI_GPIOIF_GPIO);
rcnt0_h = reg_EXI_RCNT0_H;
if (rcnt0_h & REG_EXI_RCNT0_H_DATA_R7_MASK) {
data_r7 = 0x8000;
}
*(u16 *)HW_BUTTON_XY_BUF = data_r7 | ((rcnt0_h & (REG_EXI_RCNT0_H_DATA_R3_MASK | REG_EXI_RCNT0_H_DATA_R1_MASK | REG_EXI_RCNT0_H_DATA_R0_MASK)) << 10);
}

View File

@ -27,7 +27,7 @@ getword() {
od -j "$2" -N 4 -A n -t u "$1" | awk '{$1=$1};1'
}
# dump_autoload SBIN PROC VMA AUTOLOAD
# dump_autoload SBIN PROC VMA SIZE AUTOLOAD
dump_autoload() {
outfile="${1}_a${5}"
# ARM9 has the start module params in the footer
@ -229,6 +229,7 @@ case "$mode" in
if [ "$mode" == "autoload" ]; then
resp=$( dump_autoload "$basefile" "$proc" "$vma" "$size" "$autoload" )
basefile=$(echo $resp | cut -d' ' -f1)
size=$( wc -c <${buildfile} )
resp=$( dump_autoload "$buildfile" "$proc" "$vma" "$size" "$autoload" )
buildfile=$(echo $resp | cut -d' ' -f1)
vma=$(echo $resp | cut -d' ' -f2)