Skip to content

Commit

Permalink
Working X-A2 task demo
Browse files Browse the repository at this point in the history
- Doesn't load Fujihack into RAM every time menu option is pressed
- Slightly more seamless transition from Fujihack back to liveview
- Use fuji_press_key_alias
- More assembly patches all over the place :(
  • Loading branch information
petabyt committed Jun 25, 2023
1 parent 09e4c61 commit 0dafb72
Show file tree
Hide file tree
Showing 12 changed files with 60 additions and 99 deletions.
1 change: 1 addition & 0 deletions src/Linker.ld
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ OUTPUT_ARCH(arm)
ENTRY(_start)

SECTIONS {
/* TODO: Make CPP symbol */
. = 0x0142a640;

.text : { *(.text) }
Expand Down
5 changes: 1 addition & 4 deletions src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,9 @@ FRONTIER_JS=$(FRONTIER)/mjs/

HACK_BIN_DEPS=boot.o stub.o file.o main.o sys.o mem.o io.o screen.o remap.o video.o
HACK_BIN_DEPS+=$(addprefix $(FRONTIER_CORE),asm.o bmp.o ui.o)
#HACK_BIN_DEPS+=$(addprefix $(FRONTIER_JS),mjs.o)

ARMCFLAGS+=-I$(FRONTIER_JS)

#WRAPS=--wrap=_malloc_r

ARMCFLAGS+=-include ../model/$(model).h -c -marm -O0 -I$(TOPL)/src -mcpu=cortex-a5 -fpic -mapcs-frame
ARMLDFLAGS+=-T Linker.ld $(WRAPS) -lc -lgcc -lm

Expand All @@ -34,7 +31,7 @@ clean-all:
hack.bin: $(HACK_BIN_DEPS) build-frontier
$(ARMCC)-ld $(HACK_BIN_DEPS) $(ARMLDFLAGS) -lc -lgcc -o hack.elf
$(ARMCC)-objcopy -O binary hack.elf hack.bin
$(TOPL)/frontier/emulator/frontier.o -i hack.elf -o hack.bin -s
$(TOPL)/frontier/tool/frontier.o -i hack.elf -o hack.bin -s
$(ARMCC)-size --format=berkeley --target=binary hack.bin

# Compiling rules are defined in ../Makefile
2 changes: 1 addition & 1 deletion src/dump.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ void fh_dump_ram() {
fuji_file_reset();

fuji_file_wait();
fuji_fwrite(handler, fd, 0x10000000, 0x0);
fuji_fwrite(handler, fd, 0x40000000, 0x0);
fuji_file_wait();
fuji_file_reset();

Expand Down
48 changes: 1 addition & 47 deletions src/ff_io.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ struct FujiInputMap {
};

void fuji_press_key(int code, int down);
void fuji_press_key_alias(char *alias, char *down);

// Returns current drive (DOS style)
// Crashes without SD card (???)
Expand Down Expand Up @@ -94,53 +95,6 @@ void fuji_file_reset();
int fuji_dir_open(char *first, char *second, char *buffer);
int fuji_dir_next(char *buffer);

struct FujiEventReq {
uint16_t event_code;
uint8_t current_tsk_id;
uint8_t target_tsk_id;
uint32_t target_tsk_id2;
uint32_t *unknown;
};

int fuji_task_event(int id, struct FujiEventReq *req);

// Task creation data struct
struct FujiTask {
uint32_t a;
char *b;
uint32_t c;
uint32_t d;
void *e;
uint32_t f;
};

int fuji_get_task_id();

// (Found in script WAIT and WAIT_SET code)
int fuji_task_sleep(int ms);

// Called to init tasks on startup
int fuji_create_task(int x, int y, struct FujiTask *task);

struct FujiTaskBuffer {
int a;
int b;
int c;
int d;
int e;
};

// Creates a task that is started "ms" miliseconds after this function is called.
// Returns a task ID, which is used in fuji_wait_task_stop
// ms: task is called after x ms or called every x ms
// option1: 0 for timeout delayed call, 1 is for repeating called
// These were found in firmware by looking at "SoftTimerStart"/"SoftTimerStop"
int fuji_wait_task_start(int ms, int option1, void (*callback)(), struct FujiTaskBuffer *buf);
int fuji_wait_task_stop(int bufResult);

// Used by OS to decompress firmware from flash (syslog DECE)
int fuji_load_flash(int sector, int length, void *buffer, void (*callback)(int size), int flag);

#pragma pack(pop)

#endif
13 changes: 7 additions & 6 deletions src/ff_ptp.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@
#pragma pack(push, 1)

struct FujiPTPParams {
uint32_t code; // ptp command code
uint32_t transid; // ?
uint32_t sessionid; // ?
uint32_t length; // ?
uint32_t param1;
uint32_t param2;
uint32_t code;
uint32_t transid;
uint32_t sessionid;
uint32_t length;
uint32_t params[5];
void *payload_ptr;
uint32_t payload_length;
};

struct FujiPTPResponse {
Expand Down
14 changes: 11 additions & 3 deletions src/fujihack.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,20 @@

#include <stdint.h>

#include "ff_sqlite.h"

struct FujihackState {
uint32_t activated;
void *settings_ptr;
};

int fh_start_remap_shutter();
int fh_infinite_record_limit();

void memory_dump(char file[], uintptr_t location);
int cardspeed();
void enable_script_flag();
void fh_dump_ram();

//int cardspeed();
//void enable_script_flag();

#define SCREENWRT(x, y, ...) \
{char scdbg_buffer[64]; \
Expand Down
1 change: 1 addition & 0 deletions src/hijack.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Handy on-the-fly asm hijacks
#include <stdint.h>

void generate_branch(void *base, void *to, void *buffer) {
Expand Down
27 changes: 3 additions & 24 deletions src/io.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <bmp.h>

#include "ff_io.h"
#include "ff_task.h"
#include "ff_screen.h"
#include "ff_sqlite.h"

Expand Down Expand Up @@ -36,31 +37,9 @@ void fuji_screen_write_(char *text, int x, int y, int fg, int bg) {
}
#endif

int stop_logs = 0;
int col_y = 1;
void screen_log(char *string) {
if (string == 0) return;
if (string[0] == '@') return;

char max[32];
memcpy(max, string, 32);
max[31] = '\0';

bmp_string(10, 10 + (18 * col_y), max, 0xffffff);

if (col_y == 24) {
col_y = 0;
bmp_clear(0);
} else {
col_y++;
}

fuji_task_sleep(0);
bmp_apply();
}

void uart_str(char *string) {
screen_log(string);
void uart_str(const char *string) {
// TODO: Log?
}

int printf(const char *format, ...) {
Expand Down
34 changes: 25 additions & 9 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,24 @@

#include <sys.h>
#include <ui.h>
#include <bmp.h>

#include <ff_io.h>
#include <ff_screen.h>
#include <ff_task.h>

#include "fujihack.h"

struct FujiTaskBuffer test_task = {0};
int test_rgb = 0x0;
void test_task_loop() {
char buffer[128];
sprintf(buffer, "Task: %d %d", test_task.a, test_task.b);
bmp_fill_rect(100, 100, 100, 100, test_rgb);
bmp_string(300, 250, buffer, -1);
test_rgb += 0x111111;
}

// TODO: Allow non UI hijack_menu states (modules, button presses)
// Prevent binary from being loaded every time
int loaded = 0;
Expand All @@ -21,12 +33,8 @@ int main_menu() {
ui_text("Fujihack pre-release - Written by Daniel Cook", 0xffffff);
ui_text("Running on the " MODEL_NAME, 0xffffff);

if (ui_button("Quit all")) {
return 1;
}

if (ui_button("Test button 1")) {

if (ui_button("Test multitasking")) {
fuji_wait_task_start(100, FUJI_TASK_REPEAT, test_task_loop, &test_task);
}

if (ui_button("Test button 2")) {
Expand Down Expand Up @@ -58,7 +66,7 @@ int hijack_menu() {
// First keypress after pressing menu should be from "Press any key to continue"
// The menu will not be rendered until
ui_reset();
main_menu();
bmp_clear(0);
return 1;
}

Expand All @@ -83,9 +91,15 @@ int hijack_menu() {
}

if (m->key_status == 0x0) {
if (ui_frame(main_menu) == 1) {
// Quit button does nothing for now
ui_reset();

int key = ui_process_key();
if (key == SYS_BUTTON_QUIT) {
return 1;
}

bmp_clear(0);
int rc = ui_update(main_menu);
}

return 1;
Expand All @@ -97,6 +111,8 @@ void intro_screen() {
//bmp_string(50, 10, "Press any button to continue.", 0xffffffff);
}

void entry();

int menu_dont_load() {
fuji_rst_config1(0xf);
fuji_rst_config2(0xf);
Expand Down
5 changes: 3 additions & 2 deletions src/remap.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <stdint.h>

#include <ff_io.h>
#include <ff_task.h>

static struct FujiTaskBuffer buf;

Expand All @@ -13,8 +14,8 @@ static void remap_func() {
struct FujiInputMap *f = (struct FujiInputMap *)MEM_INPUT_MAP;
// Listen for OK
if (last_input == 0x816 && f->key_code == 1 && f->key_status == 0 && last_key_status == 0) {
fuji_press_key_keyword("S2", "ON");
fuji_press_key_keyword("S2", "OFF");
fuji_press_key_alias("S2", "ON");
fuji_press_key_alias("S2", "OFF");
last_input = 0;
last_key_status = -1;
}
Expand Down
3 changes: 2 additions & 1 deletion src/screen.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ int bmp_apply() {
}

void bmp_pixel(int x, int y, uint32_t rgb) {
// Fuji is indecisive about which buffer to use, just painting to both is easier
// Fuji uses 3 buffers for double buffering. Need to paint to all 3 since I don't
// know how to do double buffering.
for (int i = 0; i < 3; i++) {
uintptr_t *ptr = (uintptr_t *)(MEM_OPENGL_BUFFERS);
screen_buffer = ptr[i];
Expand Down
6 changes: 4 additions & 2 deletions src/sys.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
#include <sys/stat.h>

#include <sys.h>
#include "ff_io.h"

#include <ff_io.h>
#include <ff_task.h>

int sys_check_key(int key) {
if (key == SYS_BUTTON_QUIT) {
Expand Down Expand Up @@ -38,7 +40,7 @@ void msleep(int ms) {

// TODO: move to assembly
void exit(int status) {

while (1) {}
}

void abort() {
Expand Down

0 comments on commit 0dafb72

Please sign in to comment.