2010-09-20	Mark Nord - ebook.so  hg/firmware/300/opt/sony/ebook/application/ebook.so
		Analysis of original Code

.text:00006510 ; =============== S U B R O U T I N E =======================================
.text:00006510
.text:00006510
.text:00006510                 EXPORT eBook_rotate
.text:00006510 eBook_rotate                            ; = doRotate = ebook.rotate()
.text:00006510                 STMFD   SP!, {R4,R10,LR}
.text:00006514                 LDR     R10, =__GLOBAL_OFFSET_TABLE_ ; PIC mode
.text:00006518                 NOP
.text:0000651C                 LDR     R3, =0x2EC	; gEinkOrientation
.text:00006520                 LDR     R4, [R10,R3]
.text:00006524                 LDRB    R3, [R4]
.text:00006528                 CMP     R3, #0		; toggle 0/1
.text:0000652C                 MOVNE   R3, #0		; 0 = normal
.text:00006530                 MOVEQ   R3, #1		; 1 = rotated 
.text:00006534                 STRB    R3, [R4]		; store gEinkOrientation
.text:00006538                 LDRB    R0, [R4]		; parameter passed
.text:0000653C                 BL      ebookEinkDoRotate
.text:00006540                 LDRB    R0, [R4]		; parameter passed
.text:00006544                 BL      ebookSubcpuDoRotate
.text:00006548                 LDMFD   SP!, {R4,R10,PC}
.text:00006548 ; End of function eBook_rotate
.text:00006548
.text:00006548 ; ---------------------------------------------------------------------------
.text:0000654C off_654C        DCD __GLOBAL_OFFSET_TABLE_ ; DATA XREF: eBook_rotate+4r
.text:00006550 dword_6550      DCD 0x2EC               ; gEinkOrientation


.text:0000ABD8 ; =============== S U B R O U T I N E =======================================
.text:0000ABD8
.text:0000ABD8
.text:0000ABD8                 EXPORT ebookEinkDoRotate
.text:0000ABD8 ebookEinkDoRotate                       
.text:0000ABD8    ; The states toggled between are hard-coded in Lines 
		  ; .text:0000ABF0  and .text:0000ABFC 

.text:0000ABD8                 STMFD   SP!, {R10,LR}
.text:0000ABDC                 LDR     R10, =__GLOBAL_OFFSET_TABLE_ ; PIC mode
.text:0000ABE0                 NOP
.text:0000ABE4                 TST     R0, #0xFF	; isolate byte
.text:0000ABE8                 LDRNE   R3, =0x3D0	; gEink
.text:0000ABEC                 LDRNE   R0, [R10,R3]
.text:0000ABF0                 MOVNE   R1, #0		; R1 holds toggled param R0  0= rotated left
.text:0000ABF4                 LDREQ   R3, =0x3D0	; gEink
.text:0000ABF8                 LDREQ   R0, [R10,R3]	
.text:0000ABFC                 MOVEQ   R1, #1		; R1 holds toggled param R0  1 = normal 
.text:0000AC00                 BL      EinkSetOrientation
.text:0000AC04                 LDMFD   SP!, {R10,PC}
.text:0000AC04 ; End of function ebookEinkDoRotate
.text:0000AC04
.text:0000AC04 ; ---------------------------------------------------------------------------
.text:0000AC08 off_AC08        DCD __GLOBAL_OFFSET_TABLE_ 
.text:0000AC0C dword_AC0C      DCD 0x3D0          	; gEink    
.text:0000AC0C                                        

.text:0000A728 ; =============== S U B R O U T I N E =======================================
.text:0000A728
.text:0000A728
.text:0000A728                 EXPORT EinkSetOrientation
.text:0000A728 EinkSetOrientation                      ; handles all 4 orientations !!
.text:0000A728
.text:0000A728 var_14          = -0x14
.text:0000A728
.text:0000A728                 STMFD   SP!, {R4-R6,LR}
.text:0000A72C                 SUB     SP, SP, #4
.text:0000A730                 MOV     R5, R0
.text:0000A734                 MOV     R6, #0
.text:0000A738                 LDR     R3, [R0,#0x1C]
.text:0000A73C                 CMP     R3, R1
.text:0000A740                 BEQ     loc_A7F0
.text:0000A744                 STR     R1, [R0,#0x1C]
.text:0000A748                 CMP     R1, #3
.text:0000A74C                 ADDLS   PC, PC, R1,LSL#2
.text:0000A750                 B       loc_A784
.text:0000A754 ; ---------------------------------------------------------------------------
.text:0000A754
.text:0000A754 loc_A754                                
.text:0000A754                 B       loc_A764
.text:0000A758 ; ---------------------------------------------------------------------------
.text:0000A758
.text:0000A758 loc_A758                               
.text:0000A758                 B       loc_A774
.text:0000A75C ; ---------------------------------------------------------------------------
.text:0000A75C
.text:0000A75C loc_A75C                                
.text:0000A75C                 B       loc_A764
.text:0000A760 ; ---------------------------------------------------------------------------
.text:0000A760
.text:0000A760 loc_A760                                
.text:0000A760                 B       loc_A774
.text:0000A764 ; ---------------------------------------------------------------------------
.text:0000A764
.text:0000A764 loc_A764                                
.text:0000A764 ; jumptable 0000A74C entries 0,2	       ; normal and flipped
.text:0000A764                 MOV     R3, #0x320
.text:0000A768                 STR     R3, [R0,#4]
.text:0000A76C                 SUB     R3, R3, #0xC8
.text:0000A770                 B       loc_A780
.text:0000A774 ; ---------------------------------------------------------------------------
.text:0000A774
.text:0000A774 loc_A774                                
.text:0000A774 ; jumptable 0000A74C entries 1,3	       ; rotated left / right
.text:0000A774                 MOV     R3, #0x258
.text:0000A778                 STR     R3, [R0,#4]
.text:0000A77C                 ADD     R3, R3, #0xC8
.text:0000A780
.text:0000A780 loc_A780                                
.text:0000A780                 STR     R3, [R5,#8]
.text:0000A784
.text:0000A784 loc_A784                                
.text:0000A784 ; jumptable 0000A74C default entry
.text:0000A784                 ADD     R2, R1, #2
.text:0000A788                 AND     R2, R2, #3
.text:0000A78C                 LDR     R0, [R5]        ; fd
.text:0000A790                 LDR     R1, =0x46F2     ; cmd
.text:0000A794                 BL      _ioctl
.text:0000A798
.text:0000A798 loc_A798                                
.text:0000A798                 MOV     R0, R6
.text:0000A79C                 ADD     R6, R6, #1
.text:0000A7A0                 MOV     R1, #0
.text:0000A7A4                 BL      _FskWindowGetInd
.text:0000A7A8                 MOV     R4, R0
.text:0000A7AC                 CMP     R0, #0
.text:0000A7B0                 BEQ     loc_A7E8
.text:0000A7B4                 LDMIB   R5, {R1,R2}
.text:0000A7B8                 BL      _FskWindowSetSize
.text:0000A7BC                 MOV     R0, SP
.text:0000A7C0                 LDR     R1, =0xC03
.text:0000A7C4                 MOV     R2, #0
.text:0000A7C8                 MOVL    R3, 0xFFFFFFFF
.text:0000A7CC                 BL      _FskEventNew
.text:0000A7D0                 CMP     R0, #0
.text:0000A7D4                 BNE     loc_A798
.text:0000A7D8                 MOV     R0, R4
.text:0000A7DC                 LDR     R1, [SP,#0x14+var_14]
.text:0000A7E0                 BL      _FskWindowEventQueue
.text:0000A7E4                 B       loc_A798
.text:0000A7E8 ; ---------------------------------------------------------------------------
.text:0000A7E8
.text:0000A7E8 loc_A7E8                                
.text:0000A7E8                 MOV     R3, #1
.text:0000A7EC                 STRB    R3, [R5,#0x41]
.text:0000A7F0
.text:0000A7F0 loc_A7F0                                
.text:0000A7F0                 MOV     R0, #0
.text:0000A7F4                 ADD     SP, SP, #4
.text:0000A7F8                 LDMFD   SP!, {R4-R6,PC}
.text:0000A7F8 ; End of function EinkSetOrientation
.text:0000A7F8
.text:0000A7F8 ; ---------------------------------------------------------------------------
.text:0000A7FC ; int dword_A7FC
.text:0000A7FC dword_A7FC      DCD 0x46F2              ; DATA XREF: EinkSetOrientation+68r
.text:0000A800 dword_A800      DCD 0xC03               ; DATA XREF: EinkSetOrientation+98r
.text:0000A804


.text:0000D640 ; =============== S U B R O U T I N E =======================================
.text:0000D640
.text:0000D640
.text:0000D640                 EXPORT ebookSubcpuDoRotate
.text:0000D640 ebookSubcpuDoRotate                     ; CODE XREF: eBook_resetOrientation+24p
.text:0000D640                                         ; eBook_rotate+34p
.text:0000D640                 STMFD   SP!, {R4,R5,R10,LR}
.text:0000D644                 LDR     R10, =__GLOBAL_OFFSET_TABLE_ ; PIC mode
.text:0000D648                 NOP
.text:0000D64C                 AND     R4, R0, #0xFF   ; isolate byte 0/1 used as boolean for kOrientation
.text:0000D650                 LDR     R3, =0x444      ; gSubcpu
.text:0000D654                 LDR     R5, [R10,R3]
.text:0000D658                 MOV     R0, R5
.text:0000D65C                 LDR     R3, =0x490      ; kOrientation
.text:0000D660                 LDR     R1, [R10,R3]
.text:0000D664                 MOV     R2, R4
.text:0000D668                 BL      SubcpuThreadPostBooleanEvent
.text:0000D66C                 STRB    R4, [R5,#0xB0]
.text:0000D670                 LDMFD   SP!, {R4,R5,R10,PC}
.text:0000D670 ; End of function ebookSubcpuDoRotate
.text:0000D670
.text:0000D670 ; ---------------------------------------------------------------------------
.text:0000D674 off_D674        DCD __GLOBAL_OFFSET_TABLE_
.text:0000D674                                         
.text:0000D678 dword_D678      DCD 0x444               ; gSubcpu
.text:0000D67C dword_D67C      DCD 0x490               ; kOrientation
.text:0000D680


abstract of patch applied, thus doRotate rotates the screen thru all four (4) possible states,
Joypad Up/Down Left/Right will be toggled via kOrientation, but with fipped and right rotated screen UP/DOWN action isn't reversed.

.text:00006510                 EXPORT eBook_rotate
.text:00006510 eBook_rotate                            ; = doRotate = ebook.rotate()
	 	rotate 	gEinkOrientation from 0 to 3,
		where 0 = normal, 1 = rotated left, 2 = flipped vertical, 3 = rotated rigth


.text:0000ABD8                 EXPORT ebookEinkDoRotate
.text:0000ABD8 ebookEinkDoRotate                       ; CODE XREF: eBook_resetOrientation+1Cp			
		remap parameter passed from eBook_rotate
		0 = 1; 1 = 0; 2 = 3; 3 = 2; this will be passed to EinkSetOrientation

.text:0000D640                 EXPORT ebookSubcpuDoRotate
.text:0000D640 ebookSubcpuDoRotate                     ; CODE XREF: eBook_resetOrientation+24p
.text:0000D64C                 AND     R4, R0, #0x01   ; isolate bit 1 (in ebook.rotate 1 and 3 = rotated) to use as boolean for kOrientation		
