root/platform/g12/sub/100c/filewrite.c

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

DEFINITIONS

This source file includes following definitions.
  1. filewritetask
  2. sub_FFAE0DBC_my
  3. sub_FFAE0EFC_my
  4. sub_FFAE0970_my

   1 /*
   2  * filewrite.c - auto-generated by CHDK code_gen.
   3  */
   4 #include "lolevel.h"
   5 #include "platform.h"
   6 
   7 typedef struct {
   8     unsigned int address;
   9     unsigned int length;
  10 } cam_ptp_data_chunk; //camera specific structure
  11 
  12 // Found in sub_FFAE0EFC (1.00c) --> "CMP     R0, #6"
  13 #define MAX_CHUNKS_FOR_JPEG 7   // filewritetask is prepared for this many chunks
  14 /*
  15  * fwt_data_struct: defined here as it's camera dependent
  16  * unneeded members are designated with unkn
  17  * pdc is required, everything after that is optional (DryOS < R50)
  18  * file_offset, full_size, seek_flag only needs to be defined for DryOS>=r50 generation cameras
  19  */
  20 typedef struct
  21 {
  22     int unkn1[5];                                   // sub_FFAE0EFC --> "LDR     R7, [R0, #0x14]!"
  23     cam_ptp_data_chunk pdc[MAX_CHUNKS_FOR_JPEG];
  24     int unkn2;
  25     char name[32];                                  // sub_FFAE0DBC --> "ADD     R0, R0, #0x50"
  26                                                     // offset of 'name' from start = 0x50 = 80 bytes = 20 words
  27 } fwt_data_struct;
  28 
  29 #include "../../../generic/filewrite.c"
  30 
  31 /*************************************************************/
  32 //** filewritetask @ 0xFFAE0AE4 - 0xFFAE0BC0, length=56
  33 void __attribute__((naked,noinline)) filewritetask() {
  34 asm volatile (
  35 "    STMFD   SP!, {R1-R5,LR} \n"
  36 "    LDR     R4, =0xC0C4 \n"
  37 
  38 "loc_FFAE0AEC:\n"
  39 "    LDR     R0, [R4, #0x10] \n"
  40 "    MOV     R2, #0 \n"
  41 "    ADD     R1, SP, #8 \n"
  42 "    BL      sub_FF83A460 /*_ReceiveMessageQueue*/ \n"
  43 "    CMP     R0, #0 \n"
  44 "    LDRNE   R1, =0x33F \n"
  45 "    LDRNE   R0, =0xFFAE0BD4 /*'dwFWrite.c'*/ \n"
  46 "    BLNE    _DebugAssert \n"
  47 "    LDR     R0, [SP, #8] \n"
  48 "    LDR     R1, [R0] \n"
  49 "    CMP     R1, #9 \n"
  50 "    ADDLS   PC, PC, R1, LSL#2 \n"
  51 "    B       loc_FFAE0AEC \n"
  52 "    B       loc_FFAE0BB4 \n"
  53 "    B       loc_FFAE0BB4 \n"
  54 "    B       loc_FFAE0BB4 \n"
  55 "    B       loc_FFAE0BB4 \n"
  56 "    B       loc_FFAE0BB4 \n"
  57 "    B       loc_FFAE0BB4 \n"
  58 "    B       loc_FFAE0BB4 \n"
  59 "    B       loc_FFAE0BBC \n"
  60 "    B       loc_FFAE0B48 \n"
  61 "    B       loc_FFAE0BAC \n"
  62 
  63 "loc_FFAE0B48:\n"
  64 "    MOV     R0, #0 \n"
  65 "    STR     R0, [SP] \n"
  66 
  67 "loc_FFAE0B50:\n"
  68 "    LDR     R0, [R4, #0x10] \n"
  69 "    MOV     R1, SP \n"
  70 "    BL      sub_FF83A6A4 /*_GetNumberOfPostedMessages*/ \n"
  71 "    LDR     R0, [SP] \n"
  72 "    CMP     R0, #0 \n"
  73 "    BEQ     loc_FFAE0B7C \n"
  74 "    LDR     R0, [R4, #0x10] \n"
  75 "    MOV     R2, #0 \n"
  76 "    ADD     R1, SP, #4 \n"
  77 "    BL      sub_FF83A460 /*_ReceiveMessageQueue*/ \n"
  78 "    B       loc_FFAE0B50 \n"
  79 
  80 "loc_FFAE0B7C:\n"
  81 "    LDR     R0, [R4, #4] \n"
  82 "    CMN     R0, #1 \n"
  83 "    BEQ     loc_FFAE0BA0 \n"
  84 "    BL      fwt_close \n"  // --> Patched. Old value = _Close.
  85 "    MVN     R0, #0 \n"
  86 "    STR     R0, [R4, #4] \n"
  87 "    LDR     R0, =0xFE668 \n"
  88 "    BL      sub_FF876B34 \n"
  89 "    BL      sub_FF874D90 \n"
  90 
  91 "loc_FFAE0BA0:\n"
  92 "    LDR     R0, [R4, #0xC] \n"
  93 "    BL      _GiveSemaphore \n"
  94 "    B       loc_FFAE0AEC \n"
  95 
  96 "loc_FFAE0BAC:\n"
  97 "    BL      sub_FFAE0DBC_my \n"  // --> Patched. Old value = 0xFFAE0DBC.
  98 "    B       loc_FFAE0AEC \n"
  99 
 100 "loc_FFAE0BB4:\n"
 101 "    BL      sub_FFAE0EFC_my \n"  // --> Patched. Old value = 0xFFAE0EFC.
 102 "    B       loc_FFAE0AEC \n"
 103 
 104 "loc_FFAE0BBC:\n"
 105 "    BL      sub_FFAE0970_my \n"  // --> Patched. Old value = 0xFFAE0970.
 106 "    B       loc_FFAE0AEC \n"
 107 );
 108 }
 109 
 110 /*************************************************************/
 111 //** sub_FFAE0DBC_my @ 0xFFAE0DBC - 0xFFAE0E70, length=46
 112 void __attribute__((naked,noinline)) sub_FFAE0DBC_my() {
 113 asm volatile (
 114 "    STMFD   SP!, {R4-R8,LR} \n"
 115 "    MOV     R4, R0 \n"
 116 "    ADD     R0, R0, #0x50 \n"
 117 "    SUB     SP, SP, #0x38 \n"
 118 "    BL      sub_FF876B34 \n"
 119 "    MOV     R1, #0 \n"
 120 "    BL      sub_FF874D28 \n"
 121 "    LDR     R0, [R4, #0xC] \n"
 122 "    BL      sub_FF810338 \n"
 123 "    LDR     R0, [R4, #0x4C] \n"
 124 "    LDR     R8, =0x1B6 \n"
 125 "    CMP     R0, #1 \n"
 126 "    LDREQ   R0, [R4, #8] \n"
 127 "    ADD     R6, R4, #0x50 \n"
 128 "    ORREQ   R0, R0, #0x8000 \n"
 129 "    STREQ   R0, [R4, #8] \n"
 130 "    LDR     R7, [R4, #8] \n"
 131 "    LDR     R5, [R4, #0xC] \n"
 132 //hook start
 133 "    STMFD   SP!, {R4-R12,LR} \n"
 134 "    MOV     R0, R4 \n"
 135 "    BL      filewrite_main_hook \n"
 136 "    LDMFD   SP!, {R4-R12,LR} \n"
 137 //hook end
 138 "    MOV     R0, R6 \n"
 139 "    MOV     R2, R8 \n"
 140 "    MOV     R1, R7 \n"
 141 "    BL      fwt_open \n"  // --> Patched. Old value = _Open.
 142 "    CMN     R0, #1 \n"
 143 "    BNE     sub_FFAE0E74 \n"
 144 "    MOV     R0, R6 \n"
 145 "    BL      sub_FF837474 \n"
 146 "    MOV     R2, #0xF \n"
 147 "    MOV     R1, R6 \n"
 148 "    MOV     R0, SP \n"
 149 "    BL      sub_FFBB30C8 \n"
 150 "    LDR     R0, =0x41FF \n"
 151 "    MOV     R1, #0 \n"
 152 "    STRB    R1, [SP, #0xF] \n"
 153 "    STR     R0, [SP, #0x20] \n"
 154 "    MOV     R0, #0x10 \n"
 155 "    ADD     R2, SP, #0x24 \n"
 156 "    STMIA   R2, {R0,R1,R5} \n"
 157 "    ADD     R1, SP, #0x20 \n"
 158 "    MOV     R0, SP \n"
 159 "    STR     R5, [SP, #0x30] \n"
 160 "    STR     R5, [SP, #0x34] \n"
 161 "    BL      sub_FF874698 \n"
 162 "    MOV     R2, R8 \n"
 163 "    MOV     R1, R7 \n"
 164 "    MOV     R0, R6 \n"
 165 "    BL      fwt_open \n"  // --> Patched. Old value = _Open.
 166 "    LDR     PC, =0xFFAE0E74 \n"  // Continue in firmware
 167 );
 168 }
 169 
 170 /*************************************************************/
 171 //** sub_FFAE0EFC_my @ 0xFFAE0EFC - 0xFFAE0FC4, length=51
 172 void __attribute__((naked,noinline)) sub_FFAE0EFC_my() {
 173 asm volatile (
 174 "    STMFD   SP!, {R4-R10,LR} \n"
 175 "    MOV     R5, R0 \n"
 176 "    LDR     R0, [R0] \n"
 177 "    CMP     R0, #6 \n"
 178 "    BHI     loc_FFAE0F30 \n"
 179 "    ADD     R0, R5, R0, LSL#3 \n"
 180 "    LDR     R7, [R0, #0x14]! \n"
 181 "    LDR     R6, [R0, #4] \n"
 182 "    CMP     R6, #0 \n"
 183 "    BNE     loc_FFAE0F40 \n"
 184 
 185 "loc_FFAE0F24:\n"
 186 "    MOV     R1, R5 \n"
 187 "    MOV     R0, #7 \n"
 188 "    B       sub_FFAE0FD4 \n"
 189 
 190 "loc_FFAE0F30:\n"
 191 "    LDR     R1, =0x299 \n"
 192 "    LDR     R0, =0xFFAE0BD4 /*'dwFWrite.c'*/ \n"
 193 "    BL      _DebugAssert \n"
 194 "    B       loc_FFAE0F24 \n"
 195 
 196 "loc_FFAE0F40:\n"
 197 "    LDR     R9, =0xC0C4 \n"
 198 "    MOV     R4, R6 \n"
 199 
 200 "loc_FFAE0F48:\n"
 201 "    LDR     R0, [R5, #4] \n"
 202 "    CMP     R4, #0x1000000 \n"
 203 "    MOVLS   R8, R4 \n"
 204 "    MOVHI   R8, #0x1000000 \n"
 205 "    BIC     R1, R0, #0xFF000000 \n"
 206 "    CMP     R1, #0 \n"
 207 "    BICNE   R0, R0, #0xFF000000 \n"
 208 "    RSBNE   R0, R0, #0x1000000 \n"
 209 "    CMPNE   R8, R0 \n"
 210 "    MOVHI   R8, R0 \n"
 211 "    LDR     R0, [R9, #4] \n"
 212 "    MOV     R2, R8 \n"
 213 "    MOV     R1, R7 \n"
 214 "    BL      fwt_write \n"  // --> Patched. Old value = _Write.
 215 "    LDR     R1, [R5, #4] \n"
 216 "    CMP     R8, R0 \n"
 217 "    ADD     R1, R1, R0 \n"
 218 "    STR     R1, [R5, #4] \n"
 219 "    BEQ     loc_FFAE0FA8 \n"
 220 "    CMN     R0, #1 \n"
 221 "    LDRNE   R0, =0x9200015 \n"
 222 "    LDREQ   R0, =0x9200005 \n"
 223 "    STR     R0, [R5, #0x10] \n"
 224 "    B       loc_FFAE0F24 \n"
 225 
 226 "loc_FFAE0FA8:\n"
 227 "    SUB     R4, R4, R0 \n"
 228 "    CMP     R4, R6 \n"
 229 "    ADD     R7, R7, R0 \n"
 230 "    LDRCS   R0, =0xFFAE0BD4 /*'dwFWrite.c'*/ \n"
 231 "    MOVCS   R1, #0x2C4 \n"
 232 "    BLCS    _DebugAssert \n"
 233 "    CMP     R4, #0 \n"
 234 "    BNE     loc_FFAE0F48 \n"
 235 "    LDR     PC, =0xFFAE0FC8 \n"  // Continue in firmware
 236 );
 237 }
 238 
 239 /*************************************************************/
 240 //** sub_FFAE0970_my @ 0xFFAE0970 - 0xFFAE09A4, length=14
 241 void __attribute__((naked,noinline)) sub_FFAE0970_my() {
 242 asm volatile (
 243 "    STMFD   SP!, {R4-R6,LR} \n"
 244 "    LDR     R5, =0xC0C4 \n"
 245 "    MOV     R4, R0 \n"
 246 "    LDR     R0, [R5, #4] \n"
 247 "    SUB     SP, SP, #0x38 \n"
 248 "    CMN     R0, #1 \n"
 249 "    BEQ     sub_FFAE09B8 \n"
 250 "    LDR     R1, [R4, #8] \n"
 251 "    LDR     R6, =0x9200003 \n"
 252 "    TST     R1, #0x8000 \n"
 253 "    BEQ     loc_FFAE09A4 \n"
 254 //mod start
 255 "    LDR R3, =current_write_ignored\n"
 256 "    LDR R3, [R3]\n"
 257 "    CMP R3, #0\n"
 258 "    BNE loc_D\n" // jump over the next block
 259 //mod end
 260 "    BL      sub_FF873DD4 \n"
 261 "    B       sub_FFAE09A8 \n"
 262 
 263 "loc_FFAE09A4:\n"
 264 "loc_D:\n"
 265 "    BL      fwt_close \n"  // --> Patched. Old value = _Close.
 266 "    LDR     PC, =0xFFAE09A8 \n"  // Continue in firmware
 267 );
 268 }

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