root/platform/s90/sub/101a/filewrite.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. filewritetask
  2. sub_FFA792E0_my
  3. sub_FFA79414_my
  4. sub_FFA78E8C_my

   1 #include "lolevel.h"
   2 #include "platform.h"
   3 
   4 typedef struct {
   5     unsigned int address;
   6     unsigned int length;
   7 } cam_ptp_data_chunk; //camera specific structure
   8 
   9 #define MAX_CHUNKS_FOR_FWT 4 //model specific
  10 /*
  11  * fwt_data_struct: defined here as it's camera dependent
  12  * unneeded members are designated with unkn
  13  * file_offset, full_size, seek_flag only needs to be defined for DryOS>=r50 generation cameras
  14  * pdc is always required
  15  * name is not currently used
  16  */
  17 typedef struct
  18 {
  19     int unkn1, unkn2, unkn3, unkn4, unkn5;
  20     cam_ptp_data_chunk pdc[MAX_CHUNKS_FOR_FWT];
  21     int unkn6;
  22     char name[32];
  23 } fwt_data_struct;
  24 
  25 #include "../../../generic/filewrite.c"
  26 
  27 // ************ filewritetask *************
  28 
  29 void __attribute__((naked,noinline)) filewritetask () { //sub_FFA78FF4
  30 asm volatile (
  31       "    STMFD   SP!, {R1-R5,LR} \n" 
  32       "    LDR     R4, =0xB414 \n" 
  33 "loc_FFA78FFC:\n"
  34       "    LDR     R0, [R4, #0x10] \n" 
  35       "    MOV     R2, #0 \n" 
  36       "    ADD     R1, SP, #8 \n" 
  37       "    BL      sub_FF8382FC \n"         //ReceiveMessageQueue
  38       "    CMP     R0, #0 \n" 
  39       "    BNE     loc_FFA7902C \n" 
  40       "    LDR     R0, [SP, #8] \n" 
  41       "    LDR     R1, [R0] \n" 
  42       "    CMP     R1, #1 \n"               // state 1 (exit)
  43       "    BNE     loc_FFA79034 \n" 
  44       "    LDR     R0, [R4, #8] \n" 
  45       "    BL      sub_FF8387E8 \n"         //GiveSemaphore
  46 "loc_FFA7902C:\n"
  47       "    BL      sub_FF81E844 \n"         //ExitTask
  48       "    LDMFD   SP!, {R1-R5,PC} \n" 
  49 "loc_FFA79034:\n"
  50       "    SUB     R1, R1, #2 \n" 
  51       "    CMP     R1, #6 \n" 
  52       "    ADDLS   PC, PC, R1, LSL #2 \n" 
  53       "    B       loc_FFA78FFC \n" 
  54       "    B       loc_FFA79060 \n" 
  55       "    B       loc_FFA790C4 \n" 
  56       "    B       loc_FFA790CC \n" 
  57       "    B       loc_FFA790CC \n" 
  58       "    B       loc_FFA790CC \n" 
  59       "    B       loc_FFA790CC \n" 
  60       "    B       loc_FFA790D4 \n" 
  61 "loc_FFA79060:\n"                           // state 2 (erase remaining messages then close file)
  62       "    MOV     R0, #0 \n" 
  63       "    STR     R0, [SP] \n" 
  64 "loc_FFA79068:\n"
  65       "    LDR     R0, [R4, #0x10] \n" 
  66       "    MOV     R1, SP \n" 
  67       "    BL      sub_FF838540 \n"         //GetNumberOfPostedMessages
  68       "    LDR     R0, [SP] \n" 
  69       "    CMP     R0, #0 \n" 
  70       "    BEQ     loc_FFA79094 \n" 
  71       "    LDR     R0, [R4, #0x10] \n" 
  72       "    MOV     R2, #0 \n" 
  73       "    ADD     R1, SP, #4 \n" 
  74       "    BL      sub_FF8382FC \n"         //ReceiveMessageQueue
  75       "    B       loc_FFA79068 \n" 
  76 "loc_FFA79094:\n"
  77       "    LDR     R0, [R4] \n" 
  78       "    CMN     R0, #1 \n" 
  79       "    BEQ     loc_FFA790B8 \n" 
  80       "    BL      fwt_close\n"             // mod! sub_FF835414 Close
  81       "    MVN     R0, #0 \n" 
  82       "    STR     R0, [R4] \n" 
  83       "    LDR     R0, =0xD1D1C \n" 
  84       "    BL      sub_FF86E540 \n"         // pathcheck
  85       "    BL      sub_FF86C924 \n"         // file semaphore stuff
  86 "loc_FFA790B8:\n"
  87       "    LDR     R0, [R4, #0xC] \n" 
  88       "    BL      sub_FF8387E8 \n"         //GiveSemaphore
  89       "    B       loc_FFA78FFC \n" 
  90 "loc_FFA790C4:\n"                           // state 3
  91       "    BL      sub_FFA792E0_my \n"      // -> open
  92       "    B       loc_FFA78FFC \n" 
  93 "loc_FFA790CC:\n"                           // state 4,5,6,7
  94       "    BL      sub_FFA79414_my \n"      // -> write
  95       "    B       loc_FFA78FFC \n" 
  96 "loc_FFA790D4:\n"                           // state 8
  97       "    BL      sub_FFA78E8C_my \n"      // -> close
  98       "    B       loc_FFA78FFC \n"
  99       );
 100 }
 101 
 102 
 103 void __attribute__((naked,noinline)) sub_FFA792E0_my(  ) { //open
 104 asm volatile (
 105       "    STMFD   SP!, {R4-R8,LR} \n" 
 106       "    MOV     R4, R0 \n" 
 107       "    ADD     R0, R0, #0x38 \n" 
 108       "    SUB     SP, SP, #0x38 \n" 
 109       "    BL      sub_FF86E540 \n"         // pathcheck
 110       "    MOV     R1, #0 \n" 
 111       "    BL      sub_FF86C8D4 \n"         // filesemaphore + get drive free clusters
 112       "    LDR     R0, [R4, #0xC] \n" 
 113       "    BL      sub_FF86B490 \n"         // stores r0 to [0x1900]
 114       "    LDR     R7, [R4, #8] \n" 
 115       "    LDR     R8, =0x1B6 \n"           // 666 octal
 116       "    ADD     R6, R4, #0x38 \n"        // file name
 117       "    LDR     R5, [R4, #0xC] \n" 
 118 //place hook here
 119       "STMFD SP!, {R4-R12,LR}\n"
 120       "MOV R0, R4\n"
 121       "BL filewrite_main_hook\n"
 122       "LDMFD SP!, {R4-R12,LR}\n"
 123 //hook end
 124       "    MOV     R0, R6 \n" 
 125       "    MOV     R1, R7 \n" 
 126       "    MOV     R2, R8 \n" 
 127       "    BL      fwt_open\n"              // mod! sub_FF8353BC Open
 128       "LDR PC, =0xffa79324\n"               // + continue in ROM to save space
 129 /*      "    CMN     R0, #1 \n" 
 130       "    BNE     loc_FFA79384 \n"         // Open succeeded
 131       "    MOV     R0, R6 \n" 
 132       "    BL      sub_FF835780 \n" 
 133       "    MOV     R2, #0xF \n" 
 134       "    MOV     R1, R6 \n" 
 135       "    MOV     R0, SP \n" 
 136       "    BL      sub_FFB34C1C \n" 
 137       "    LDR     R0, =0x41FF \n" 
 138       "    MOV     R1, #0 \n" 
 139       "    STRB    R1, [SP, #0xF] \n" 
 140       "    STR     R0, [SP, #0x20] \n" 
 141       "    MOV     R0, #0x10 \n" 
 142       "    ADD     R2, SP, #0x24 \n" 
 143       "    STMIA   R2, {R0,R1,R5} \n" 
 144       "    ADD     R1, SP, #0x20 \n" 
 145       "    MOV     R0, SP \n" 
 146       "    STR     R5, [SP, #0x30] \n" 
 147       "    STR     R5, [SP, #0x34] \n" 
 148       "    BL      sub_FF86C244 \n" 
 149       "    MOV     R2, R8 \n" 
 150       "    MOV     R1, R7 \n" 
 151       "    MOV     R0, R6 \n" 
 152       "    BL      sub_FF8353BC \n"         // Open, no need to substitute it
 153 "loc_FFA79384:\n"
 154       "    LDR     R5, =0xB414 \n" 
 155       "    CMN     R0, #1 \n" 
 156       "    STR     R0, [R5] \n" 
 157       "    BNE     loc_FFA793CC \n" 
 158       "    LDR     R0, [R5, #0x18] \n" 
 159       "    CMP     R0, #0 \n" 
 160       "    BLXNE   R0 \n" 
 161       "    ADD     R0, R4, #0x38 \n" 
 162       "    BL      sub_FF86E540 \n"         // pathcheck
 163       "    BL      sub_FF86C924 \n"         // file semaphore stuff
 164       "    LDR     R1, [R5, #0x14] \n" 
 165       "    CMP     R1, #0 \n" 
 166       "    ADDNE   SP, SP, #0x38 \n" 
 167       "    LDMNEFD SP!, {R4-R8,LR} \n" 
 168       "    LDRNE   R0, =0x9200001 \n" 
 169       "    BXNE    R1 \n" 
 170 "loc_FFA793C4:\n"
 171       "    ADD     SP, SP, #0x38 \n" 
 172       "    LDMFD   SP!, {R4-R8,PC} \n" 
 173 "loc_FFA793CC:\n"
 174       "    LDR     R0, =0xD1D1C \n" 
 175       "    MOV     R2, #0x20 \n" 
 176       "    ADD     R1, R4, #0x38 \n" 
 177       "    BL      sub_FFB34D84 \n" 
 178       "    MOV     R1, R4 \n" 
 179       "    MOV     R0, #4 \n" 
 180       "    BL      sub_FFA78DCC \n"         //send_msg_to_filewritetask
 181       "    B       loc_FFA793C4 \n" */
 182       );
 183 }
 184 
 185 
 186 void __attribute__((naked,noinline)) sub_FFA79414_my(  ) { // write
 187 asm volatile (
 188       "    STMFD   SP!, {R4-R10,LR} \n" 
 189       "    MOV     R4, R0 \n" 
 190       "    LDR     R0, [R0] \n" 
 191       "    CMP     R0, #4 \n"               // 1st chunk
 192       "    LDREQ   R6, [R4, #0x18] \n" 
 193       "    LDREQ   R7, [R4, #0x14] \n" 
 194       "    BEQ     loc_FFA79460 \n" 
 195       "    CMP     R0, #5 \n"               // 2nd chunk
 196       "    LDREQ   R6, [R4, #0x20] \n" 
 197       "    LDREQ   R7, [R4, #0x1C] \n" 
 198       "    BEQ     loc_FFA79460 \n" 
 199       "    CMP     R0, #6 \n"               // 3rd chunk
 200       "    LDREQ   R6, [R4, #0x28] \n" 
 201       "    LDREQ   R7, [R4, #0x24] \n" 
 202       "    BEQ     loc_FFA79460 \n" 
 203       "    CMP     R0, #7 \n"               // 4th chunk
 204       "    BNE     loc_FFA79474 \n" 
 205       "    LDR     R6, [R4, #0x30] \n" 
 206       "    LDR     R7, [R4, #0x2C] \n" 
 207 "loc_FFA79460:\n"
 208       "    CMP     R6, #0 \n"               // (chunk size == 0)?
 209       "    BNE     loc_FFA79484 \n" 
 210 "loc_FFA79468:\n"
 211       "    MOV     R1, R4 \n" 
 212       "    MOV     R0, #8 \n"               // next state = close
 213       "    B       loc_FFA79518 \n" 
 214 "loc_FFA79474:\n"
 215       "    LDR     R1, =0x297 \n" 
 216       "    LDR     R0, =0xFFA790E8 \n" 
 217       "    BL      sub_FF81E88C \n"         //DebugAssert
 218       "    B       loc_FFA79468 \n" 
 219 "loc_FFA79484:\n"
 220       "    LDR     R9, =0xB414 \n" 
 221       "    MOV     R5, R6 \n" 
 222 "loc_FFA7948C:\n"
 223       "    LDR     R0, [R4, #4] \n" 
 224       "    CMP     R5, #0x1000000 \n" 
 225       "    MOVLS   R8, R5 \n" 
 226       "    MOVHI   R8, #0x1000000 \n" 
 227       "    BIC     R1, R0, #0xFF000000 \n" 
 228       "    CMP     R1, #0 \n" 
 229       "    BICNE   R0, R0, #0xFF000000 \n" 
 230       "    RSBNE   R0, R0, #0x1000000 \n" 
 231       "    CMPNE   R8, R0 \n" 
 232       "    MOVHI   R8, R0 \n" 
 233       "    LDR     R0, [R9] \n"             // file descriptor
 234       "    MOV     R2, R8 \n"               // length
 235       "    MOV     R1, R7 \n"               // address
 236       "    BL      fwt_write\n"             // mod! sub_FF8354A4 write
 237       "    LDR     R1, [R4, #4] \n" 
 238       "    CMP     R8, R0 \n" 
 239       "    ADD     R1, R1, R0 \n" 
 240       "    STR     R1, [R4, #4] \n" 
 241       "    BEQ     loc_FFA794EC \n" 
 242       "    CMN     R0, #1 \n" 
 243       "    LDRNE   R0, =0x9200015 \n" 
 244       "    LDREQ   R0, =0x9200005 \n" 
 245       "    STR     R0, [R4, #0x10] \n" 
 246       "    B       loc_FFA79468 \n" 
 247 "loc_FFA794EC:\n"
 248       "    SUB     R5, R5, R0 \n" 
 249       "    CMP     R5, R6 \n" 
 250       "    ADD     R7, R7, R0 \n" 
 251       "    LDRCS   R0, =0xFFA790E8 \n" 
 252       "    LDRCS   R1, =0x2C2 \n" 
 253       "    BLCS    sub_FF81E88C \n"         //DebugAssert
 254       "    CMP     R5, #0 \n" 
 255       "    BNE     loc_FFA7948C \n" 
 256       "    LDR     R0, [R4] \n" 
 257       "    MOV     R1, R4 \n" 
 258       "    ADD     R0, R0, #1 \n" 
 259 "loc_FFA79518:\n"
 260       "    LDMFD   SP!, {R4-R10,LR} \n" 
 261       "    B       sub_FFA78DCC \n"         //send_msg_to_filewritetask
 262       );
 263 }
 264 
 265 
 266 void __attribute__((naked,noinline)) sub_FFA78E8C_my(  ) { // close
 267 asm volatile (
 268       "    STMFD   SP!, {R4-R6,LR} \n" 
 269       "    LDR     R5, =0xB414 \n" 
 270       "    MOV     R4, R0 \n" 
 271       "    LDR     R0, [R5] \n" 
 272       "    SUB     SP, SP, #0x38 \n" 
 273       "    CMN     R0, #1 \n" 
 274 //      "    BEQ     loc_FFA78ED4 \n"       // -
 275       "LDREQ PC, =0xFFA78ED4\n"             // + replaced previous instruction
 276       "    LDR     R1, [R4, #8] \n" 
 277       "    LDR     R6, =0x9200003 \n" 
 278       "    TST     R1, #0x8000 \n" 
 279       "    BEQ     loc_FFA78EC0 \n" 
 280       "    BL      sub_FF86B984 \n" 
 281       "    B       loc_FFA78EC4 \n" 
 282 "loc_FFA78EC0:\n"
 283       "    BL      fwt_close\n"             // mod! sub_FF835414 Close
 284 "loc_FFA78EC4:\n"
 285       "LDR PC, =0xFFA78EC4\n"               // + continue in ROM to save space
 286 /*      "    CMP     R0, #0 \n" 
 287       "    MVN     R0, #0 \n" 
 288       "    STRNE   R6, [R4, #0x10] \n" 
 289       "    STR     R0, [R5] \n" 
 290 "loc_FFA78ED4:\n"
 291       "    LDR     R0, [R4, #0x10] \n" 
 292       "    TST     R0, #1 \n" 
 293       "    BNE     loc_FFA78FC4 \n" 
 294       "    LDR     R0, [R4, #8] \n" 
 295       "    TST     R0, #8 \n" 
 296       "    BEQ     loc_FFA78F1C \n" 
 297       "    ADD     R1, SP, #0x20 \n" 
 298       "    ADD     R0, R4, #0x38 \n" 
 299       "    BL      sub_FF86C090 \n" 
 300       "    CMP     R0, #0 \n" 
 301       "    MOVEQ   R1, #0x300 \n" 
 302       "    LDREQ   R0, =0xFFA790E8 \n" 
 303       "    BLEQ    sub_FF81E88C \n"         //DebugAssert
 304       "    LDR     R0, [SP, #0x28] \n" 
 305       "    LDR     R1, [R4, #4] \n" 
 306       "    ADD     R0, R0, R1 \n" 
 307       "    STR     R0, [SP, #0x28] \n" 
 308       "    B       loc_FFA78F4C \n" 
 309 "loc_FFA78F1C:\n"
 310       "    LDR     R0, =0x81FF \n" 
 311       "    STR     R0, [SP, #0x20] \n" 
 312       "    MOV     R0, #0x20 \n" 
 313       "    STR     R0, [SP, #0x24] \n" 
 314       "    LDR     R0, [R4, #4] \n" 
 315       "    STR     R0, [SP, #0x28] \n" 
 316       "    LDR     R0, [R4, #0xC] \n" 
 317       "    STR     R0, [SP, #0x2C] \n" 
 318       "    LDR     R0, [R4, #0xC] \n" 
 319       "    STR     R0, [SP, #0x30] \n" 
 320       "    LDR     R0, [R4, #0xC] \n" 
 321       "    STR     R0, [SP, #0x34] \n" 
 322 "loc_FFA78F4C:\n"
 323       "    ADD     R1, SP, #0x20 \n" 
 324       "    ADD     R0, R4, #0x38 \n" 
 325       "    BL      sub_FF86C244 \n" 
 326       "    LDR     R0, [R4, #0x34] \n" 
 327       "    CMP     R0, #0 \n" 
 328       "    BEQ     loc_FFA78FC4 \n" 
 329       "    MOV     R2, #0x20 \n" 
 330       "    ADD     R1, R4, #0x38 \n" 
 331       "    MOV     R0, SP \n" 
 332       "    BL      sub_FFB34D84 \n" 
 333       "    MOV     R0, SP \n" 
 334       "    BL      sub_FF81400C \n" 
 335       "    MOV     R2, #0x54 \n" 
 336       "    ADD     R0, SP, R0 \n" 
 337       "    MOV     R1, #0x4D \n" 
 338       "    STRB    R2, [R0, #-3] \n" 
 339       "    STRB    R1, [R0, #-2] \n" 
 340       "    MOV     R1, #0x50 \n" 
 341       "    STRB    R1, [R0, #-1] \n" 
 342       "    MOV     R1, SP \n" 
 343       "    ADD     R0, R4, #0x38 \n" 
 344       "    BL      sub_FF86B9A4 \n" 
 345       "    CMP     R0, #0 \n" 
 346       "    LDREQ   R1, =0x153 \n" 
 347       "    LDREQ   R0, =0xFFA790E8 \n" 
 348       "    BLEQ    sub_FF81E88C \n"         //DebugAssert
 349       "    MOV     R0, SP \n" 
 350       "    BL      sub_FF86C6A0 \n" 
 351       "    ADD     R0, R4, #0x38 \n" 
 352       "    BL      sub_FF86C6A0 \n" 
 353 "loc_FFA78FC4:\n"
 354       "    LDR     R0, [R5, #0x18] \n" 
 355       "    CMP     R0, #0 \n" 
 356       "    BLXNE   R0 \n" 
 357       "    ADD     R0, R4, #0x38 \n" 
 358       "    BL      sub_FF86E540 \n"         // pathcheck
 359       "    BL      sub_FF86C924 \n"         // file semaphore stuff
 360       "    LDR     R1, [R5, #0x14] \n" 
 361       "    CMP     R1, #0 \n" 
 362       "    LDRNE   R0, [R4, #0x10] \n" 
 363       "    BLXNE   R1 \n" 
 364       "    ADD     SP, SP, #0x38 \n" 
 365       "    LDMFD   SP!, {R4-R6,PC} \n" */
 366       );
 367 }
 368 

/* [<][>][^][v][top][bottom][index][help] */