[400plus] r1838 committed - some more work on PTP stuff (WIP)

6 views
Skip to first unread message

400...@googlecode.com

unread,
May 5, 2013, 11:23:02 AM5/5/13
to 400...@googlegroups.com
Revision: 1838
Author: fire...@gmail.com
Date: Sun May 5 08:22:46 2013
Log: some more work on PTP stuff (WIP)
http://code.google.com/p/400plus/source/detail?r=1838

Modified:
/trunk/cache_hacks.h
/trunk/firmware.h
/trunk/init.c
/trunk/ptp.c
/trunk/ptp.h
/trunk/state_object.h

=======================================
--- /trunk/cache_hacks.h Thu May 2 17:43:59 2013
+++ /trunk/cache_hacks.h Sun May 5 08:22:46 2013
@@ -47,6 +47,7 @@
#define LOOP_INSTR 0xEAFFFFFE // 1: b 1b
#define NOP_INSTR 0xE1A00000 // mov r0, r0
#define MOV_R0_1_INSTR 0xE3A00001 // mov r0, 1
+#define MOV_R0_0_INSTR 0xE3A00000 // mov r0, 0
#define BL_INSTR(pc,dest) ( 0xEB000000 | ((( ((uint32_t)dest) -
((uint32_t)pc) - 8 ) >> 2) & 0x00FFFFFF) )

#define TYPE_DCACHE 0
=======================================
--- /trunk/firmware.h Thu May 2 17:43:59 2013
+++ /trunk/firmware.h Sun May 5 08:22:46 2013
@@ -617,4 +617,7 @@
extern int TransferMirrorScreen (int r0, int r1, int r2, int r3, int
a, int b, int c, int d);
extern int TransferRotatedScreen (int r0, int r1, int r2, int r3, int
a, int b, int c, int d);

+// PTP
+extern void * PTP_Actions (void * arg0, void * arg1, void * arg2, void *
arg3, void * arg4);
+
#endif /* FIRMWARE_H_ */
=======================================
--- /trunk/init.c Sat May 4 11:12:15 2013
+++ /trunk/init.c Sun May 5 08:22:46 2013
@@ -48,6 +48,12 @@
// take over the vram copy locations, so we can invert the screen
cache_fake(0xFF92C5D8, BL_INSTR(0xFF92C5D8, &hack_invert_olc_screen),
TYPE_ICACHE);
cache_fake(0xFF92C5FC, BL_INSTR(0xFF92C5FC, &hack_invert_olc_screen),
TYPE_ICACHE);
+
+ cache_fake(0xFF9DE0DC, MOV_R0_0_INSTR, TYPE_ICACHE); // prevent screen
turn off on ptp (to see the debug on lcd)
+ // these freezes the usb communication
+ //cache_fake(0xFF81B9D0, MOV_R0_0_INSTR, TYPE_ICACHE); // prevent ui lock
+ //cache_fake(0xFF81B400, MOV_R0_0_INSTR, TYPE_ICACHE); // prevent ui lock
+ //cache_fake(0xFF9DDB24, MOV_R0_0_INSTR, TYPE_ICACHE); // prevent ui lock
}


=======================================
--- /trunk/ptp.c Sun May 5 04:09:21 2013
+++ /trunk/ptp.c Sun May 5 08:22:46 2013
@@ -11,26 +11,84 @@

#include "bmp.h"

-extern _PtpMgr_t *hPtpMgr; // defined in camera.S
+extern manager_t *hPtpMgr; // defined in camera.S
+
+state_object_t * hack_ptp_actions(state_object_t * self, void * arg1, void
* arg2, void * arg3, void * arg4);
+
+static int (*StateTransition)(void*,void*,int,int,int) = 0;
+
+int hack_state_transition(
+ state_object_t * self,
+ manager_t *manager,
+ int input,
+ int event_flag_func, // some function to set event flag
+ int some_struct // some struct for transition maybe ???
+) {
+ static int l=0;
+ int old_state = self->current_state;
+ int res = StateTransition(self, manager, input, event_flag_func,
some_struct);
+ int new_state = self->current_state;
+
+ //UILock(0, 2);
+ //PTP_SetUILock(0, 2);
+ //PTP_ResetUILock(0);
+
+ lcd_printf(0,(l++ % 20), "[%03d] O:%08X R:%08X N:%08X", l, old_state,
res, new_state);
+ printf_log(8,8, "[400Plus-PTP] [%03d] O:%08X R:%08X N:%08X", l,
old_state, res, new_state);
+ //bmp_hexdump(VramAddress, FONT_SMALL, 0, l*16, a4, 64);
+ return res;
+}

void ptp_dump_info() {

- state_object_t *ptp_state_object = hPtpMgr->state_object;
+ state_object_t *so = hPtpMgr->state_object;
+
+ if (!StateTransition) {
+ StateTransition = (void *)so->state_object_handler;
+ } else if ((void*)StateTransition != (void*)so->state_object_handler) {
// check if all states use the same function (they do, in theory)
+ beep(); beep(); beep(); beep(); beep();
+ }
+
+ so->state_object_handler = (void *)&hack_state_transition;
+
+
+
+ /*
+ if ((uint32_t)(ptp_state_object->state_matrix) & 0xFF000000) // that's in
ROM, make a copy to allow patching
+ state_object_matrix_copy_for_patching(ptp_state_object);

lcd_printf(0,0, "matrix @ 0x%08X, %d inputs, %d states ",
ptp_state_object->state_matrix, ptp_state_object->max_inputs,
ptp_state_object->max_states);
- int i;
- int s;
- int x, y;
+ int i, s, x, y, cnt = 0;
for (i=0; i<ptp_state_object->max_inputs; i++) {
for (s=0; s<ptp_state_object->max_states; s++) {
- int idx = s+i*ptp_state_object->max_states;
- y = ((idx) % 19)+1;
- x = ((float)((idx) / 19)<1) ? 0 : 22;
- lcd_printf(x,y, "%02d:%02d/%d:0x%08X[%d]", idx, i, s,
STATE_FUNC(ptp_state_object, i, s), STATE_NEXT(ptp_state_object, i, s));
- if (idx>=37) goto out;
+ if (STATE_FUNC(ptp_state_object, i, s) == &PTP_Actions) {
+ state_object_install_hook(ptp_state_object, i, s, &hack_ptp_actions);
+
+ y = ((cnt) % 19)+1;
+ x = ((float)((cnt) / 19)<1) ? 0 : 22;
+ cnt++;
+ lcd_printf(x,y, "%02d:%02d/%d:0x%08X[%d]", cnt, i, s,
STATE_FUNC(ptp_state_object, i, s), STATE_NEXT(ptp_state_object, i, s));
+ }
}
}
-out:
- return;
+ */
}

+/*
+state_object_t * hack_ptp_actions(
+ state_object_t * self,
+ void * arg1, // some functoin @ 0xff9e6638
+ void * arg2, // point to 0x4af2dc
+ void * arg3, // this function address
+ void * arg4 // point to 0x241a0
+) {
+
+ int old_state = self->current_state;
+
+ //lcd_printf(0,0, "ptpmgr: 0x%08X", hPtpMgr);
+ lcd_printf(0, 1, "[0x%08X]=%08X [0x%08X]=%08X", arg1, *((uint32_t*)arg1),
arg2, *((uint32_t*)arg2));
+ lcd_printf(0, 2, "[0x%08X]=%08X [0x%08X]=%08X", arg3, *((uint32_t*)arg3),
arg4, *((uint32_t*)arg4));
+ bmp_hexdump(VramAddress, FONT_SMALL, 0, 3*16, arg4, 64);
+ return PTP_Actions(self, arg1, arg2, arg3, arg4);
+}
+*/
=======================================
--- /trunk/ptp.h Sun May 5 04:09:21 2013
+++ /trunk/ptp.h Sun May 5 08:22:46 2013
@@ -9,24 +9,6 @@

#include "state_object.h"

-typedef struct {
- char *name;
- void *stage_class;
- state_object_t *state_object;
- void *debug_class;
- void *unk_0x10;
- void *pmgr_sync_event;
- void *unk_0x18;
- void *unk_0x1C;
- void *unk_0x20;
- void *ptp_sync_data_event_flag_struct;
- void *unk_0x28;
- void *unk_0x2C;
- void *block_64kb;
- void *unk_0x34;
- void *unk_0x38;
-} _PtpMgr_t;
-
void ptp_dump_info();

#endif // _PTP_H_
=======================================
--- /trunk/state_object.h Sun May 5 04:09:21 2013
+++ /trunk/state_object.h Sun May 5 08:22:46 2013
@@ -7,10 +7,13 @@
#ifndef _STATE_OBJECT_H_
#define _STATE_OBJECT_H_

+#include "firmware.h"
+
// with some help from ML here we have state objects
// they look the same in 400d

-typedef struct state_object_struct * (*state_transition_function_t)(
+// state object related
+typedef struct state_object * (*state_transition_function_t)(
void * x,
void * y,
void * z,
@@ -58,5 +61,44 @@
#define STATE_FUNC(stateobj,input,state) stateobj->state_matrix[(state) +
(input) * stateobj->max_states].state_transition_function
#define STATE_NEXT(stateobj,input,state) stateobj->state_matrix[(state) +
(input) * stateobj->max_states].next_state

+static inline void state_object_matrix_copy_for_patching(state_object_t *
so) {
+ int size = so->max_inputs * so->max_states * sizeof(state_transition_t);
+ state_transition_t * new_matrix = (state_transition_t
*)AllocateMemory(size);
+ memcpy(new_matrix, so->state_matrix, size);
+ so->state_matrix = new_matrix;
+}
+
+static inline void state_object_install_hook(state_object_t * so, int
input, int state, void* newfunc) {
+ if ((uint32_t)(so->state_matrix) & 0xFF000000) // that's in ROM, make a
copy to allow patching
+ state_object_matrix_copy_for_patching(so);
+ STATE_FUNC(so,input,state) = newfunc;
+}
+
+// some extra structs
+typedef struct {
+ const char * identifier; //~ off_0x00 "TaskClass"
+ const char * name; //~ off_0x04 task class name.
ie: PropMgr
+ int off_0x08; //~ unknown initialized to 1 in
CreateTaskClass
+ const struct task * task_struct_ptr; //~ off_0x0c
ret_CreateTask (ptr to task struct) called from CreateTaskClass
+ const struct msg_queue * msg_queue_ptr_maybe; //~ off_0x10 some
kind of message queue pointer (very low level functions at work)
+ void * eventdispatch_func_ptr; //~ off_0x14 event dispatch pointer.
ie: propmgrEventDispatch
+} task_class_t;
+
+typedef struct {
+ char * name;
+ task_class_t * task_class;
+ state_object_t * state_object;
+ int debug_class;
+ void * unk_0x10;
+ void * pmgr_sync_event;
+ void * unk_0x18;
+ void * unk_0x1C;
+ void * unk_0x20;
+ void * ptp_sync_data_event_flag_struct;
+ void * unk_0x28;
+ void * unk_0x2C;
+} manager_t;
+
+
#endif // _PTP_H_

Reply all
Reply to author
Forward
0 new messages