.equ l_ReadFile 0x2048E210
.equ l_WriteFile 0x2048D3F2
.equ GSMsprintfW 0x2053808C
.equ GSMstrlenW 0x205379CC
.equ GSMstrcmpW 0x205379A0
.equ ker_ASCIItoLEUCS2 0x204876C4
.equ mmi_MessageBoxLabel 0x2050E2B6
.equ mmi_MessageBoxString 0x2050FB72
.equ FindFile 0x2048EBB8
.equ nffs_DeleteFile 0x207C038C
.equ p_GSMmemset 0x40000A0
.equ p_GSMmemcpy 0x40000AC
.equ p_GSMmemcmp 0x40000A8

.equ header 0x31364190
.equ my_addr 0x31364290
.equ pict_buf 0x31389990

  ;???? ?????? ? ????????? ???????? ???? - ?????
  0x204C661C:
   ldr r1,[r0,4]
   ;ldr r1,[r0,#14]
   
  ;---??????? ???????????? ??????? ? ????????? ???????? ????---
  0x204C64CA:
   b 0x204C65C0
   ;bne 0x204C65C0
   
  0x2043DA9C:
   b 0x2043DAEA
   ;bne 0x2043DAEA
  ;------------------------------------------------------------
     
  0x2054DF58:
   ldr r4,=themes+1
   bx r4
   ;.hex 401A0068AC680823
   .data
   
   0x2040915E:
   ldr r0,=setup+1
   bx r0
   ;.hex 02200FF135F800222749042005F1A4F8
   .data
  
  0x20EE0AF8:
  themes:
    sub r0,r0,r1
    ldr r0,[r0]
    push {r0}
    ldr r4,[r5,8]
    
    ;????????? ?????? ??? ?? ?????????
    ldr r1,=header
    ldrb r0,[r1]
    cmp r0,1			;???? ?? ????? 1 -> ?? ???? ?????????
    beq file_loaded
    
    cmp r0,2			;???? 2 -> ???? ?? ???????????
    beq no_theme
    
    ;????? -> ?? ???? ?????????????:
    
    ;?????? ?? C:/UIFM/ath.cnf ??? ????? ????
    mov r3,0xF0
    mov r2,0
    ldr r1,=header
    add r1,0x10
    adr r0,=ath_cnf
    bl l_ReadFile
    cmp r0,0
    beq contin_theme
    
    ldr r1,=header
    mov r0,2
    strb r0,[r1]
    b no_theme
    
   contin_theme:
    sub SP,SP,4
    mov r3,4
    mov r2,0
    mov r1,SP
    ldr r0,=header
    add r0,0x10
    bl l_ReadFile
    ldr r3,[SP]
    add SP,SP,4
    
    mov r2,0x10
    ldr r1,=my_addr
    ldr r0,=header
    add r0,0x10
    bl l_ReadFile
    cmp r0,0
    beq contin2_theme
    
    ldr r1,=header
    mov r0,2
    strb r0,[r1]
    
    mov r2,0
    mov r1,0
    adr r0,=ath_cnf
    bl nffs_DeleteFile
    b no_theme
    
   contin2_theme:
    ldr r1,=header
    mov r0,1
    strb r0,[r1]
    
   file_loaded:
    ldr r2,[r4,4]
    
    ldr r3,=0x20DD9BB0
    mov r1,0
   pict_find_loop: 
    ldr r0,[r3,4]
    cmp r0,r2
    beq pict_found
    add r1,1
    add r3,8
    ldr r0,=0x1316
    cmp r1,r0
    ble pict_find_loop
    
    b no_theme
   pict_found:
    
    lsl r1,r1,3
    
    ldr r0,=my_addr
    add r0,r1
    ldr r1,[r0]
    ldr r2,[r0,4]
    
    cmp r1,0
    beq no_theme
    
    mov r3,r2
    mov r2,r1
    ldr r1,=pict_buf
    ldr r0,=header
    add r0,0x10
    bl l_ReadFile
    cmp r0,0
    beq contin3_theme
    
    ldr r1,=header
    mov r0,0
    strb r0,[r1]
    b no_theme
    
   contin3_theme:
    ldr r2,=header
    add r2,8
    ldr r0,[r4]
    str r0,[r2]
    ldr r1,=pict_buf
    str r1,[r2,4]
    mov r4,r2        
    
   no_theme: 
    mov r3,8
    pop {r0} 
    ldr r2,=0x2054DF60+1
    bx r2
   
   setup:
    ldr r1,=0xC38
    add r1,SP
    ldr r1,[r1]
    
    ldrb r0,[r1,0xA]
    cmp r0,0xC
    beq setup_exit1
    
    add r0,r1,0x20
   srch_2E:
    ldrb r1,[r0]
    cmp r1,0
    beq setup_exit1
    cmp r1,0x2E
    beq found_2E
    add r0,2
    b srch_2E
    
   found_2E:
    add r0,2
    ldrb r1,[r0]
    cmp r1,0x41
    beq is_A
    cmp r1,0x61
    beq is_A
    b setup_exit
   is_A:
    add r0,2
    ldrb r1,[r0]
    cmp r1,0x54
    beq is_T
    cmp r1,0x74
    beq is_T
    b setup_exit
   is_T:
    add r0,2
    ldrb r1,[r0]
    cmp r1,0x68
    beq is_H
    cmp r1,0x48
    bne setup_exit
   is_H:
   
    ldr r1,=header
    ldrb r0,[r1]
    cmp r0,1
    bne not_uninstall
    
    ldr r0,=0xC38
    add r0,SP
    ldr r0,[r0]
    add r0,0x20
    bl GSMstrlenW
    mov r3,r0
    lsl r3,r3,1
    
    ldr r0,=header
    add r0,0x10
    bl GSMstrlenW
    ldr r1,=header
    add r1,0x10
    lsl r0,r0,1
    add r0,r1,r0
    sub r1,r0,r3
    
    ldr r0,=0xC38
    add r0,SP
    ldr r0,[r0]
    add r0,0x20
    bl GSMstrcmpW
    cmp r0,0
    bne not_uninstall
    
    ldr r1,=header
    mov r0,0
    strb r0,[r1]
    
    mov r2,0
    mov r1,0
    adr r0,=ath_cnf
    bl nffs_DeleteFile
    b uninst_exit
    
   setup_exit1:
    b setup_exit 
    
   not_uninstall:
    mov r2,0xF0
    mov r1,0
    ldr r0,=header
    add r0,0x10
    ldr r3,=p_GSMmemset
    ldr r3,[r3]
    bl call_by_R3
    
    ldr r0,=0xC38
    add r0,SP
    ldr r3,[r0]
    add r3,0x20
    mov r1,0xB
    lsl r0,r1,2
    ldr r1,=0x30004FD0
    ldr r2,[r1,r0]
    adr r1,="%s/%s"
    ldr r0,=header
    add r0,0x10
    bl GSMsprintfW
    
    
    mov r3,0xF0
    mov r2,0
    ldr r1,=header
    add r1,0x10
    adr r0,=ath_cnf
    bl l_WriteFile
    
    sub SP,SP,4
    mov r3,4
    mov r2,0
    mov r1,SP
    ldr r0,=header
    add r0,0x10
    bl l_ReadFile
    ldr r3,[SP]
    add SP,SP,4
    
    mov r2,0x10
    ldr r1,=my_addr
    ldr r0,=header
    add r0,0x10
    bl l_ReadFile
   
    ldr r1,=header
    mov r0,1
    strb r0,[r1]
    
    sub SP,SP,4
    adr r0,="Тема установлена!" 
    bl GSMstrlen
  
    adr r1,="Тема установлена!" 
    mov r2,r0  
    mov r0,SP
    bl ker_ASCIItoLEUCS2
  
    adr r2,="I=",0
    mov r1,SP
    mov r0,2
    bl mmi_MessageBoxString
    add SP,SP,4
    
    b inst_uninst_exit
    ;bl initialization
    
   uninst_exit:
   
    sub SP,SP,4
    adr r0,="Тема отменена!" 
    bl GSMstrlen
  
    adr r1,="Тема отменена!" 
    mov r2,r0  
    mov r0,SP
    bl ker_ASCIItoLEUCS2
  
    adr r2,="I=",0
    mov r1,SP
    mov r0,2
    bl mmi_MessageBoxString
    add SP,SP,4 
   
   inst_uninst_exit:
    ldr r0,=0x2040916E+1
    bx r0
    
   setup_exit: 
    mov r2,0
    ldr r1,=0x5DC
    mov r0,4
    bl mmi_MessageBoxLabel
    
    ldr r0,=0x2040916E+1
    bx r0

   call_by_R1:
    bx R1
    
   call_by_R3:
    bx R3
     
   .data
     ath_cnf:
      .hex 43003A002F005500490046004D002F004100540048002E0043004E0046000000