init commit take 2
This commit is contained in:
24
thread/3ds.ld
Normal file
24
thread/3ds.ld
Normal file
@@ -0,0 +1,24 @@
|
||||
OUTPUT_FORMAT("elf32-littlearm", "elf32-littlearm", "elf32-littlearm")
|
||||
OUTPUT_ARCH(arm)
|
||||
|
||||
/*0x080C3EE0*/
|
||||
ENTRY(_start)
|
||||
|
||||
SECTIONS
|
||||
{
|
||||
. = 0x0801A6E0;
|
||||
start_addr = .;
|
||||
.text.start : { *(.text.start) }
|
||||
.text : { *(.text) *(.text*) }
|
||||
.rodata : { *(.rodata) *(.rodata*) }
|
||||
.data : { *(.data) *(.data*) }
|
||||
.bss : { *(.bss) *(.bss*) }
|
||||
/*. = ALIGN(32);*/
|
||||
/*.stack : {
|
||||
stack_start = .;
|
||||
. += 0x40;
|
||||
. = ALIGN(32);
|
||||
stack_end = .;
|
||||
}*/
|
||||
total_size = . - start_addr;
|
||||
}
|
||||
16
thread/Makefile
Normal file
16
thread/Makefile
Normal file
@@ -0,0 +1,16 @@
|
||||
ifeq ($(strip $(DEVKITARM)),)
|
||||
$(error "Please set DEVKITARM in your environment. export DEVKITARM=<path to>devkitARM")
|
||||
endif
|
||||
|
||||
include $(DEVKITARM)/ds_rules
|
||||
|
||||
SFLAGS=-c -mcpu=arm946e-s -march=armv5te -mlittle-endian -fshort-wchar
|
||||
CFLAGS=$(SFLAGS) -std=c99
|
||||
|
||||
all:
|
||||
$(CC) -g source/thread.c source/lib.c $(CFLAGS)
|
||||
$(CC) -g source/_start.s source/FS.S -I source $(SFLAGS)
|
||||
$(CC) -nostdlib -T 3ds.ld _start.o thread.o lib.o FS.o
|
||||
$(OBJCOPY) -O binary a.out arm9.bin
|
||||
rm -f *.o *.out
|
||||
|
||||
9
thread/source/FS.h
Normal file
9
thread/source/FS.h
Normal file
@@ -0,0 +1,9 @@
|
||||
#ifndef FS_H
|
||||
#define FS_H
|
||||
#include <stdio.h>
|
||||
extern unsigned int fopen9(void *handle, wchar_t* name, unsigned int flag);
|
||||
extern void fwrite9(void* handle, unsigned int* bytesWritten, void* dst, unsigned int size);
|
||||
extern void fread9(void* handle, unsigned int* bytesRead, void *src, unsigned int size);
|
||||
extern void fclose9(void *handle);
|
||||
|
||||
#endif
|
||||
41
thread/source/FS.s
Normal file
41
thread/source/FS.s
Normal file
@@ -0,0 +1,41 @@
|
||||
.text
|
||||
|
||||
.thumb
|
||||
.global fopen9
|
||||
.type fopen9, %function
|
||||
fopen9:
|
||||
push {r0-r6, lr}
|
||||
ldr r4, =0x0805B015
|
||||
blx r4
|
||||
pop {r0-r6, pc}
|
||||
.pool
|
||||
|
||||
.thumb
|
||||
.global fwrite9
|
||||
.type fwrite9, %function
|
||||
fwrite9:
|
||||
push {r4, lr}
|
||||
ldr r4, =0x0805C379
|
||||
blx r4
|
||||
pop {r4, pc}
|
||||
.pool
|
||||
|
||||
.thumb
|
||||
.global fread9
|
||||
.type fread9, %function
|
||||
fread9:
|
||||
push {r4, lr}
|
||||
ldr r4, =0x0804D855
|
||||
blx r4
|
||||
pop {r4, pc}
|
||||
.pool
|
||||
|
||||
.thumb
|
||||
.global fclose9
|
||||
.type fclose9, %function
|
||||
fclose9:
|
||||
push {r4, lr}
|
||||
ldr r4, =0x08053C6D
|
||||
blx r4
|
||||
pop {r4, pc}
|
||||
.pool
|
||||
21
thread/source/_start.s
Normal file
21
thread/source/_start.s
Normal file
@@ -0,0 +1,21 @@
|
||||
.arm
|
||||
.global thread
|
||||
.global _start
|
||||
_start:
|
||||
push {r0-r12 , lr}
|
||||
ldr r0, =0x08000c00
|
||||
mov r1, #0xA00
|
||||
mov r2, #0x0
|
||||
thread_stack_loop:
|
||||
str r2, [r0], #0x4
|
||||
subs r1, r1, #4
|
||||
bgt thread_stack_loop
|
||||
mov r0, #0x3F @ thread priority
|
||||
ldr r1, =thread @ thread_addr
|
||||
mov r2, #0x0 @ arg
|
||||
ldr r3, =0x08000c00 @ StackTop
|
||||
ldr r4, =0x1
|
||||
svc 0x8
|
||||
pop {r0-r12 , lr}
|
||||
ldr r0, =0x80CB0A8
|
||||
ldr pc, =0x080860B4
|
||||
36
thread/source/lib.c
Normal file
36
thread/source/lib.c
Normal file
@@ -0,0 +1,36 @@
|
||||
#include "lib.h"
|
||||
|
||||
void *memset(void * ptr, int value, unsigned int num){
|
||||
unsigned char *p = ptr;
|
||||
while (num) {
|
||||
*p++ = value;
|
||||
num--;
|
||||
}
|
||||
return ptr;
|
||||
}
|
||||
|
||||
int strcomp(char* s1, char* s2, unsigned int size){
|
||||
for(int i = 0; i < size; i++){
|
||||
if(s1[i] != s2[i]) return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
void strcopy(char* dest, char* source, unsigned int size){
|
||||
for(int i = 0; i < size*2; i++) dest[i] = source[i];
|
||||
}
|
||||
|
||||
int memcmp(void* buf1, void* buf2, int size){
|
||||
int equal = 0;
|
||||
for(int i = 0; i < size; i++){
|
||||
if(*((unsigned char*)buf1 + i) != *((unsigned char*)buf2 + i)){
|
||||
equal = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return equal;
|
||||
}
|
||||
|
||||
unsigned isPressed(unsigned bitfield){
|
||||
return ((~*(unsigned *)0x10146000) & 0xFFF) == (bitfield & 0xFFF) ? 1 : 0;
|
||||
}
|
||||
25
thread/source/lib.h
Normal file
25
thread/source/lib.h
Normal file
@@ -0,0 +1,25 @@
|
||||
#ifndef LIB_H
|
||||
#define LIB_H
|
||||
|
||||
#define BUTTON_A (1 << 0)
|
||||
#define BUTTON_B (1 << 1)
|
||||
#define BUTTON_SELECT (1 << 2)
|
||||
#define BUTTON_START (1 << 3)
|
||||
#define BUTTON_RIGHT (1 << 4)
|
||||
#define BUTTON_LEFT (1 << 5)
|
||||
#define BUTTON_UP (1 << 6)
|
||||
#define BUTTON_DOWN (1 << 7)
|
||||
#define BUTTON_R1 (1 << 8)
|
||||
#define BUTTON_L1 (1 << 9)
|
||||
#define BUTTON_X (1 << 10)
|
||||
#define BUTTON_Y (1 << 11)
|
||||
#define BUTTON_ZL (1 << 14)
|
||||
#define BUTTON_ZR (1 << 15)
|
||||
|
||||
void* memset(void * ptr, int value, unsigned int num);
|
||||
int strcomp(char* s1, char*s2, unsigned int size);
|
||||
void strcopy(char* dest, char* source, unsigned int size);
|
||||
int memcmp(void* buf1, void* buf2, int size);
|
||||
unsigned isPressed(unsigned bitfield);
|
||||
|
||||
#endif
|
||||
87
thread/source/thread.c
Normal file
87
thread/source/thread.c
Normal file
@@ -0,0 +1,87 @@
|
||||
/*
|
||||
* thread.c
|
||||
* by Reisyukaku
|
||||
*/
|
||||
|
||||
#include <wchar.h>
|
||||
#include <stdio.h>
|
||||
#include "thread.h"
|
||||
#include "lib.h"
|
||||
#include "FS.h"
|
||||
|
||||
#define VRAM (unsigned char*)0x18000000
|
||||
#define FCRAM (unsigned char*)0x20000000
|
||||
#define FCRAM_EXT (unsigned char*)0x28000000
|
||||
#define ARM9_MEM (unsigned char*)0x8000000
|
||||
#define AXIWRAM (unsigned char*)0x1FF80000
|
||||
#define TOP_FRAME 0
|
||||
#define BOT_FRAME 1
|
||||
|
||||
unsigned char handle[32];
|
||||
unsigned char bmpHead[] = {
|
||||
0x42, 0x4D, 0x36, 0x65, 0x04, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x36, 0x00, 0x00, 0x00, 0x28, 0x00,
|
||||
0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0xF0, 0x00,
|
||||
0x00, 0x00, 0x01, 0x00, 0x18, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x65, 0x04, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00
|
||||
};
|
||||
|
||||
void memdump(void* filename, void* buf, unsigned int size){
|
||||
unsigned int br = 0;
|
||||
memset(&handle, 0, 32);
|
||||
fopen9(&handle, filename, 6);
|
||||
fwrite9(&handle, &br, buf, size);
|
||||
fclose9(&handle);
|
||||
memset(VRAM+0x1E6000, 0xFF, 0x46500);
|
||||
}
|
||||
|
||||
void transpose (void * dst, const void * src, unsigned dim1, unsigned dim2, unsigned item_length) {
|
||||
char * ptr_write;
|
||||
const char * ptr_read;
|
||||
unsigned x, y, z;
|
||||
for (x = 0; x < dim1; x ++) for (y = 0; y < dim2; y ++) {
|
||||
ptr_write = ((char *) dst) + item_length * (y * dim1 + x);
|
||||
ptr_read = ((const char *) src) + item_length * (x * dim2 + y);
|
||||
for (z = 0; z < item_length; z ++) *(ptr_write ++) = *(ptr_read ++);
|
||||
}
|
||||
}
|
||||
|
||||
void screenShot(int frame){
|
||||
unsigned int br;
|
||||
short width = frame == 0 ? 400 : 320;
|
||||
short height = 240;
|
||||
int frameOff = frame == 0 ? 0x1E6000 : 0x48F000; //<- Defaults
|
||||
int length = frame == 0 ? 0x46500 : 0x38400;
|
||||
memset(&handle, 0, 32);
|
||||
fopen9(&handle, frame == 0 ? L"sdmc:/screen_top.bmp" : L"sdmc:/screen_bot.bmp", 6);
|
||||
transpose(FCRAM+0xF80000, VRAM+frameOff, width, height, 3);
|
||||
bmpHead[18] = frame == 0 ? 0x90 : 0x40;
|
||||
fwrite9(&handle, &br, bmpHead, 0x36);
|
||||
fwrite9(&handle, &br, FCRAM+0xF80000, length);
|
||||
fclose9(&handle);
|
||||
memset(VRAM+frameOff, 0xFF, 0x46500);
|
||||
}
|
||||
|
||||
void patches(void){
|
||||
//Change version string
|
||||
for(int i = 0; i < 0x600000; i+=4){
|
||||
if(strcomp((void*)0x27B00000 - i, (void*)L"Ver.", 4)) strcopy((void*)0x27B00000 - i, (void*)L"\uE024Rei", 4);
|
||||
}
|
||||
}
|
||||
|
||||
void thread(void){
|
||||
while(1){
|
||||
if(isPressed(BUTTON_SELECT | BUTTON_X)){
|
||||
screenShot(TOP_FRAME);
|
||||
screenShot(BOT_FRAME);
|
||||
}
|
||||
if(isPressed(BUTTON_START)){
|
||||
memdump(L"sdmc:/AXIWRAM.bin", AXIWRAM, 0x00080000);
|
||||
memdump(L"sdmc:/FCRAM.bin", FCRAM, 0x010000000);
|
||||
}
|
||||
patches();
|
||||
}
|
||||
__asm("SVC 0x09");
|
||||
}
|
||||
6
thread/source/thread.h
Normal file
6
thread/source/thread.h
Normal file
@@ -0,0 +1,6 @@
|
||||
/*
|
||||
* thread.h
|
||||
* by Reisyukaku
|
||||
*/
|
||||
|
||||
void thread(void);
|
||||
Reference in New Issue
Block a user