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

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

DEFINITIONS

This source file includes following definitions.
  1. filewritetask
  2. sub_FFA54734_my
  3. sub_FFA54D74_my
  4. sub_FFA548A0_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 #define MAX_CHUNKS_FOR_JPEG 7 // filewritetask is prepared for this many chunks
  13 /*
  14  * fwt_data_struct: defined here as it's camera dependent
  15  * unneeded members are designated with unkn
  16  * file_offset, full_size, seek_flag only needs to be defined for DryOS>=r50 generation cameras
  17  * pdc is always required

  18  * name is not currently used
  19  */
  20 typedef struct
  21 {
  22     int unkn1;
  23     int file_offset;    // needed for DryOS>=r50
  24     int full_size;      // needed for DryOS>=r50
  25     int unkn2, unkn3, unkn4;
  26     cam_ptp_data_chunk pdc[MAX_CHUNKS_FOR_JPEG];
  27     int seek_flag;      // needed for DryOS>=r50
  28     char name[32];
  29 } fwt_data_struct;
  30 #define FWT_MUSTSEEK    2   // value of the masked seek_flag indicating seek is required
  31 #define FWT_SEEKMASK    0xffffffff   // masks out unneeded bits of seek_flag
  32 
  33 #include "../../../generic/filewrite.c"
  34 
  35 /*************************************************************/
  36 //** filewritetask @ 0xFFA54A38 - 0xFFA54B7C, length=82
  37 void __attribute__((naked,noinline)) filewritetask() {
  38 asm volatile (
  39 "    STMFD   SP!, {R1-R7,LR} \n"
  40 "    LDR     R7, =0x9740 \n"
  41 "    MOV     R6, #0 \n"
  42 
  43 "loc_FFA54A44:\n"
  44 "    LDR     R0, [R7, #0x14] \n"
  45 "    MOV     R2, #0 \n"
  46 "    ADD     R1, SP, #8 \n"
  47 "    MOV     R5, R7 \n"
  48 "    BL      sub_003F7218 \n"
  49 "    CMP     R0, #0 \n"
  50 "    LDRNE   R1, =0x38E \n"
  51 "    LDRNE   R0, =0xFFA54B7C \n"
  52 "    BLNE    _DebugAssert \n"
  53 "    LDR     R0, [SP, #8] \n"
  54 "    LDR     R1, [R0] \n"
  55 "    CMP     R1, #0xB \n"
  56 "    ADDCC   PC, PC, R1, LSL#2 \n"
  57 "    B       loc_FFA54A44 \n"
  58 "    B       loc_FFA54B4C \n"
  59 "    B       loc_FFA54B4C \n"
  60 "    B       loc_FFA54B4C \n"
  61 "    B       loc_FFA54B4C \n"
  62 "    B       loc_FFA54B4C \n"
  63 "    B       loc_FFA54B4C \n"
  64 "    B       loc_FFA54B4C \n"
  65 "    B       loc_FFA54B54 \n"
  66 "    B       loc_FFA54AA8 \n"
  67 "    B       loc_FFA54B18 \n"
  68 "    B       loc_FFA54B10 \n"
  69 
  70 "loc_FFA54AA8:\n"
  71 "    STR     R6, [SP] \n"
  72 
  73 "loc_FFA54AAC:\n"
  74 "    LDR     R0, [R5, #0x14] \n"
  75 "    MOV     R1, SP \n"
  76 "    BL      sub_003F745C \n"
  77 "    LDR     R0, [SP] \n"
  78 "    CMP     R0, #0 \n"
  79 "    BEQ     loc_FFA54AD8 \n"
  80 "    LDR     R0, [R5, #0x14] \n"
  81 "    MOV     R2, #0 \n"
  82 "    ADD     R1, SP, #4 \n"
  83 "    BL      sub_003F7218 \n"
  84 "    B       loc_FFA54AAC \n"
  85 
  86 "loc_FFA54AD8:\n"
  87 "    LDR     R0, [R5, #8] \n"
  88 "    CMN     R0, #1 \n"
  89 "    BEQ     loc_FFA54B04 \n"
  90 "    BL      fwt_close \n"  // --> Patched. Old value = 0xFF831550.
  91 "    MVN     R0, #0 \n"
  92 "    STR     R0, [R5, #8] \n"
  93 "    LDR     R0, =0x1315A4 \n"
  94 "    STR     R6, [R5, #4] \n"
  95 "    BL      sub_FF866624 \n"
  96 "    MOV     R1, #0 \n"
  97 "    BL      sub_FF86493C \n"
  98 
  99 "loc_FFA54B04:\n"
 100 "    LDR     R0, [R5, #0x10] \n"
 101 "    BL      _GiveSemaphore \n"
 102 "    B       loc_FFA54A44 \n"
 103 
 104 "loc_FFA54B10:\n"
 105 "    BL      sub_FFA54734_my \n"  // --> Patched. Old value = 0xFFA54734. Open stage
 106 "    B       loc_FFA54A44 \n"
 107 
 108 "loc_FFA54B18:\n"
 109 "    LDR     R1, [R0, #4] \n"
 110 "    MOV     R4, R0 \n"
 111 "    LDR     R0, [R5, #8] \n"
 112 "    MOV     R2, #0 \n"
 113 "    BL      fwt_lseek \n"  // --> Patched. Old value = 0xFF8316C0. _lseek
 114 "    CMN     R0, #1 \n"
 115 "    LDREQ   R0, =0x9200013 \n"
 116 "    MOV     R1, R4 \n"
 117 "    STREQ   R0, [R4, #0x14] \n"
 118 "    MOVNE   R0, #0 \n"
 119 "    MOVEQ   R0, #7 \n"
 120 "    BL      sub_FFA54678 \n"
 121 "    B       loc_FFA54A44 \n"
 122 
 123 "loc_FFA54B4C:\n"
 124 "    BL      sub_FFA54D74_my \n"  // --> Patched. Old value = 0xFFA54D74. Write stage
 125 "    B       loc_FFA54A44 \n"
 126 
 127 "loc_FFA54B54:\n"
 128 "    BL      sub_FFA548A0_my \n"  // --> Patched. Old value = 0xFFA548A0. Close stage
 129 "    B       loc_FFA54A44 \n"
 130 );
 131 }
 132 
 133 /*************************************************************/
 134 //** sub_FFA54734_my @ 0xFFA54734 - 0xFFA5489C, length=91
 135 void __attribute__((naked,noinline)) sub_FFA54734_my() {
 136 asm volatile (
 137 "    STMFD   SP!, {R4-R9,LR} \n"
 138 "    LDR     R6, =0x9740 \n"
 139 "    MOV     R4, R0 \n"
 140 //hook start placed here to avoid bne a few instructions below
 141 //R0 holds data block start
 142 "    STMFD   SP!, {R4-R12,LR}\n"
 143 "    BL      filewrite_main_hook\n"
 144 "    LDMFD   SP!, {R4-R12,LR}\n"
 145 //hook end
 146 "    LDR     R0, [R6, #4] \n"
 147 "    SUB     SP, SP, #0x3C \n"
 148 "    CMP     R0, #0 \n"
 149 "    BNE     loc_FFA54870 \n"
 150 "    ADD     R0, R4, #0x54 \n"
 151 "    BL      sub_FF866624 \n"
 152 "    MOV     R1, #0 \n"
 153 "    BL      sub_FF8648B0 \n"
 154 "    LDR     R0, [R4, #0x10] \n"
 155 "    BL      sub_FF8638D8 \n"
 156 "    LDR     R0, [R4, #0x50] \n"
 157 "    LDR     R9, =0x1B6 \n"
 158 "    CMP     R0, #1 \n"
 159 "    LDREQ   R0, [R4, #0xC] \n"
 160 "    ADD     R7, R4, #0x54 \n"
 161 "    ORREQ   R0, R0, #0x8000 \n"
 162 "    STREQ   R0, [R4, #0xC] \n"
 163 "    LDR     R8, [R4, #0xC] \n"
 164 "    LDR     R5, [R4, #0x10] \n"
 165 "    MOV     R2, R9 \n"
 166 "    MOV     R1, R8 \n"
 167 "    MOV     R0, R7 \n"
 168 "    BL      fwt_open \n"  // --> Patched. Old value = 0xFF83154C.
 169 "    CMN     R0, #1 \n"
 170 "    BNE     loc_FFA54800 \n"
 171 "    MOV     R0, R7 \n"
 172 "    BL      sub_FF831B30 \n"
 173 "    MOV     R2, #0xF \n"
 174 "    MOV     R1, R7 \n"
 175 "    ADD     R0, SP, #4 \n"
 176 "    BL      sub_003FC17C \n"
 177 "    MOV     R0, #0 \n"
 178 "    LDR     R1, =0x41FF \n"
 179 "    STRB    R0, [SP, #0x13] \n"
 180 "    STR     R1, [SP, #0x24] \n"
 181 "    MOV     R1, #0x10 \n"
 182 "    STR     R0, [SP, #0x2C] \n"
 183 "    STR     R1, [SP, #0x28] \n"
 184 "    ADD     R1, SP, #0x24 \n"
 185 "    ADD     R0, SP, #4 \n"
 186 "    STR     R5, [SP, #0x30] \n"
 187 "    STR     R5, [SP, #0x34] \n"
 188 "    STR     R5, [SP, #0x38] \n"
 189 "    BL      sub_FF86417C \n"
 190 "    MOV     R2, R9 \n"
 191 "    MOV     R1, R8 \n"
 192 "    MOV     R0, R7 \n"
 193 "    BL      sub_FF83154C \n"
 194 
 195 "loc_FFA54800:\n"
 196 "    CMN     R0, #1 \n"
 197 "    MOV     R5, R0 \n"
 198 "    STR     R0, [R6, #8] \n"
 199 "    BNE     loc_FFA5483C \n"
 200 "    ADD     R0, R4, #0x54 \n"
 201 "    BL      sub_FF866624 \n"
 202 "    LDR     R1, [R6, #0x1C] \n"
 203 "    BL      sub_FF86493C \n"
 204 "    LDR     R1, [R6, #0x18] \n"
 205 "    CMP     R1, #0 \n"
 206 "    BEQ     loc_FFA54898 \n"
 207 "    ADD     SP, SP, #0x3C \n"
 208 "    LDMFD   SP!, {R4-R9,LR} \n"
 209 "    LDR     R0, =0x9200001 \n"
 210 "    BX      R1 \n"
 211 
 212 "loc_FFA5483C:\n"
 213 "    MOV     R0, #1 \n"
 214 "    STR     R0, [R6, #4] \n"
 215 "    LDR     R0, =0x1315A4 \n"
 216 "    MOV     R2, #0x20 \n"
 217 "    ADD     R1, R4, #0x54 \n"
 218 "    BL      sub_003FC364 \n"
 219 //mod start
 220 "    LDR     R3, =current_write_ignored\n"
 221 "    LDR     R3, [R3]\n"
 222 "    CMP     R3, #0\n"
 223 "    BNE     loc_A\n" // jump over the next block
 224 //mod end
 225 "    LDR     R1, [R4, #8] \n"
 226 "    MOV     R0, R5 \n"
 227 "    BL      sub_FF831800 \n"
 228 "    CMP     R0, #0 \n"
 229 "    MOVEQ   R1, R4 \n"
 230 "    MOVEQ   R0, #7 \n"
 231 "    BEQ     loc_FFA54894 \n"
 232 
 233 "loc_FFA54870:\n"
 234 "loc_A:\n"
 235 "    LDR     R0, [R4, #0x50] \n"
 236 "    CMP     R0, #2 \n"
 237 "    BEQ     loc_FFA5488C \n"
 238 "    LDR     R0, [R4, #4] \n"
 239 "    CMP     R0, #0 \n"
 240 "    MOVEQ   R1, R4 \n"
 241 "    BEQ     loc_FFA54894 \n"
 242 
 243 "loc_FFA5488C:\n"
 244 "    MOV     R1, R4 \n"
 245 "    MOV     R0, #9 \n"
 246 
 247 "loc_FFA54894:\n"
 248 "    BL      sub_FFA54678 \n"
 249 
 250 "loc_FFA54898:\n"
 251 "    ADD     SP, SP, #0x3C \n"
 252 "    LDMFD   SP!, {R4-R9,PC} \n"
 253 );
 254 }
 255 
 256 /*************************************************************/
 257 //** sub_FFA54D74_my @ 0xFFA54D74 - 0xFFA54E50, length=56
 258 void __attribute__((naked,noinline)) sub_FFA54D74_my() {
 259 asm volatile (
 260 "    STMFD   SP!, {R4-R10,LR} \n"
 261 "    MOV     R5, R0 \n"
 262 "    LDR     R0, [R0] \n"
 263 "    CMP     R0, #6 \n"
 264 "    BHI     loc_FFA54DA0 \n"
 265 "    ADD     R0, R5, R0, LSL#3 \n"
 266 "    LDR     R8, [R0, #0x18]! \n"
 267 "    LDR     R7, [R0, #4] \n"
 268 "    CMP     R7, #0 \n"
 269 "    BNE     loc_FFA54DB8 \n"
 270 "    B       loc_FFA54DAC \n"
 271 
 272 "loc_FFA54DA0:\n"
 273 "    LDR     R1, =0x2DD \n"
 274 "    LDR     R0, =0xFFA54B7C \n"
 275 "    BL      _DebugAssert \n"
 276 
 277 "loc_FFA54DAC:\n"
 278 "    MOV     R1, R5 \n"
 279 "    MOV     R0, #7 \n"
 280 "    B       loc_FFA54E4C \n"
 281 
 282 "loc_FFA54DB8:\n"
 283 "    LDR     R9, =0x9740 \n"
 284 "    MOV     R4, R7 \n"
 285 
 286 "loc_FFA54DC0:\n"
 287 "    LDR     R0, [R5, #4] \n"
 288 "    CMP     R4, #0x1000000 \n"
 289 "    MOVLS   R6, R4 \n"
 290 "    MOVHI   R6, #0x1000000 \n"
 291 "    BIC     R1, R0, #0xFF000000 \n"
 292 "    CMP     R1, #0 \n"
 293 "    BICNE   R0, R0, #0xFF000000 \n"
 294 "    RSBNE   R0, R0, #0x1000000 \n"
 295 "    CMPNE   R6, R0 \n"
 296 "    MOVHI   R6, R0 \n"
 297 "    LDR     R0, [R9, #8] \n"
 298 "    MOV     R2, R6 \n"
 299 "    MOV     R1, R8 \n"
 300 "    BL      fwt_write \n"  // --> Patched. Old value = 0xFF831654.
 301 "    LDR     R1, [R5, #4] \n"
 302 "    CMP     R6, R0 \n"
 303 "    ADD     R1, R1, R0 \n"
 304 "    STR     R1, [R5, #4] \n"
 305 "    BEQ     loc_FFA54E20 \n"
 306 "    CMN     R0, #1 \n"
 307 "    LDRNE   R0, =0x9200015 \n"
 308 "    LDREQ   R0, =0x9200005 \n"
 309 "    STR     R0, [R5, #0x14] \n"
 310 "    B       loc_FFA54DAC \n"
 311 
 312 "loc_FFA54E20:\n"
 313 "    SUB     R4, R4, R0 \n"
 314 "    CMP     R4, R7 \n"
 315 "    ADD     R8, R8, R0 \n"
 316 "    MOVCS   R1, #0x308 \n"
 317 "    LDRCS   R0, =0xFFA54B7C \n"
 318 "    BLCS    _DebugAssert \n"
 319 "    CMP     R4, #0 \n"
 320 "    BNE     loc_FFA54DC0 \n"
 321 "    LDR     R0, [R5] \n"
 322 "    MOV     R1, R5 \n"
 323 "    ADD     R0, R0, #1 \n"
 324 
 325 "loc_FFA54E4C:\n"
 326 "    LDMFD   SP!, {R4-R10,LR} \n"
 327 "    B       sub_FFA54678 \n"
 328 );
 329 }
 330 
 331 /*************************************************************/
 332 //** sub_FFA548A0_my @ 0xFFA548A0 - 0xFFA54A34, length=102
 333 void __attribute__((naked,noinline)) sub_FFA548A0_my() {
 334 asm volatile (
 335 "    STMFD   SP!, {R4-R6,LR} \n"
 336 "    MOV     R4, R0 \n"
 337 "    LDR     R0, [R0, #0x50] \n"
 338 "    LDR     R5, =0x9740 \n"
 339 "    CMP     R0, #3 \n"
 340 "    SUB     SP, SP, #0x38 \n"
 341 "    BEQ     loc_FFA54A18 \n"
 342 "    LDR     R0, [R5, #8] \n"
 343 "    CMN     R0, #1 \n"
 344 "    BEQ     loc_FFA548F4 \n"
 345 "    LDR     R1, [R4, #0xC] \n"
 346 "    LDR     R6, =0x9200003 \n"
 347 "    TST     R1, #0x8000 \n"
 348 "    BEQ     loc_FFA548E0 \n"
 349 //mod start
 350 "    LDR     R3, =current_write_ignored\n"
 351 "    LDR     R3, [R3]\n"
 352 "    CMP     R3, #0\n"
 353 "    BNE     loc_B\n" // jump over the next block
 354 //mod end
 355 "    BL      sub_FF831554 \n"
 356 "    B       loc_FFA548E4 \n"
 357 
 358 "loc_FFA548E0:\n"
 359 "loc_B:\n"
 360 "    BL      fwt_close \n"  // --> Patched. Old value = 0xFF831550.
 361 
 362 "loc_FFA548E4:\n"
 363 "    CMP     R0, #0 \n"
 364 "    MVN     R0, #0 \n"
 365 "    STRNE   R6, [R4, #0x14] \n"
 366 "    STR     R0, [R5, #8] \n"
 367 
 368 "loc_FFA548F4:\n"
 369 "    LDR     R0, [R4, #0x14] \n"
 370 "    TST     R0, #1 \n"
 371 "    BNE     loc_FFA549FC \n"
 372 "    LDR     R0, [R4, #0xC] \n"
 373 "    TST     R0, #8 \n"
 374 "    BNE     loc_FFA54918 \n"
 375 "    LDR     R0, [R4, #0x50] \n"
 376 "    CMP     R0, #3 \n"
 377 "    BNE     loc_FFA54948 \n"
 378 
 379 "loc_FFA54918:\n"
 380 "    ADD     R1, SP, #0x20 \n"
 381 "    ADD     R0, R4, #0x54 \n"
 382 "    BL      sub_FF8640C4 \n"
 383 "    CMP     R0, #0 \n"
 384 "    LDREQ   R1, =0x346 \n"
 385 "    LDREQ   R0, =0xFFA54B7C \n"
 386 "    BLEQ    _DebugAssert \n"
 387 "    LDR     R0, [SP, #0x28] \n"
 388 "    LDR     R1, [R4, #4] \n"
 389 "    ADD     R0, R0, R1 \n"
 390 "    STR     R0, [SP, #0x28] \n"
 391 "    B       loc_FFA54978 \n"
 392 
 393 "loc_FFA54948:\n"
 394 "    LDR     R0, =0x81FF \n"
 395 "    STR     R0, [SP, #0x20] \n"
 396 "    MOV     R0, #0x20 \n"
 397 "    STR     R0, [SP, #0x24] \n"
 398 "    LDR     R0, [R4, #4] \n"
 399 "    STR     R0, [SP, #0x28] \n"
 400 "    LDR     R0, [R4, #0x10] \n"
 401 "    STR     R0, [SP, #0x2C] \n"
 402 "    LDR     R0, [R4, #0x10] \n"
 403 "    STR     R0, [SP, #0x30] \n"
 404 "    LDR     R0, [R4, #0x10] \n"
 405 "    STR     R0, [SP, #0x34] \n"
 406 
 407 "loc_FFA54978:\n"
 408 "    LDR     R0, [R4, #0x50] \n"
 409 "    CMP     R0, #2 \n"
 410 "    BEQ     loc_FFA549FC \n"
 411 "    ADD     R1, SP, #0x20 \n"
 412 "    ADD     R0, R4, #0x54 \n"
 413 "    BL      sub_FF86417C \n"
 414 "    LDR     R0, [R4, #0x50] \n"
 415 "    CMP     R0, #1 \n"
 416 "    BNE     loc_FFA549FC \n"
 417 "    MOV     R2, #0x20 \n"
 418 "    ADD     R1, R4, #0x54 \n"
 419 "    MOV     R0, SP \n"
 420 "    BL      sub_003FC364 \n"
 421 "    MOV     R0, SP \n"
 422 "    BL      _strlen \n"
 423 "    MOV     R2, #0x54 \n"
 424 "    ADD     R0, R0, SP \n"
 425 "    MOV     R1, #0x4D \n"
 426 "    STRB    R2, [R0, #-3] \n"
 427 "    STRB    R1, [R0, #-2] \n"
 428 "    MOV     R1, #0x50 \n"
 429 "    STRB    R1, [R0, #-1] \n"
 430 "    MOV     R1, SP \n"
 431 "    ADD     R0, R4, #0x54 \n"
 432 "    BL      sub_FF863A14 \n"
 433 "    CMP     R0, #0 \n"
 434 "    MOVEQ   R1, #0x164 \n"
 435 "    LDREQ   R0, =0xFFA54B7C \n"
 436 "    BLEQ    _DebugAssert \n"
 437 "    MOV     R0, SP \n"
 438 "    BL      sub_FF8645D8 \n"
 439 "    ADD     R0, R4, #0x54 \n"
 440 "    BL      sub_FF8645D8 \n"
 441 
 442 "loc_FFA549FC:\n"
 443 "    ADD     R0, R4, #0x54 \n"
 444 "    BL      sub_FF866624 \n"
 445 "    LDR     R1, [R5, #0x1C] \n"
 446 "    BL      sub_FF86493C \n"
 447 "    MOV     R0, #0 \n"
 448 "    STR     R0, [R5, #4] \n"
 449 "    B       loc_FFA54A20 \n"
 450 
 451 "loc_FFA54A18:\n"
 452 "    LDR     R0, [R5, #0x1C] \n"
 453 "    BLX     R0 \n"
 454 
 455 "loc_FFA54A20:\n"
 456 "    LDR     R1, [R5, #0x18] \n"
 457 "    CMP     R1, #0 \n"
 458 "    LDRNE   R0, [R4, #0x14] \n"
 459 "    BLXNE   R1 \n"
 460 "    ADD     SP, SP, #0x38 \n"
 461 "    LDMFD   SP!, {R4-R6,PC} \n"
 462 );
 463 }

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