PDA

View Full Version : Christmas Present for PC! Your very own RTC for FR and LG


interdpth
December 24th, 2009, 11:08 PM
Added it to my hack earlier so I decided to just go and release.

Be sure to give me full credit.
Edit: I'm a hypocrite lolollo


I fudged my sources somehow and were unable to recover them properly.
Here's the ASM
.thumb
.org 0x00041E
LDR R3, off_8000424
MOV PC, R3
@ End of function sub_80003A4

@ ---------------------------------------------------------------------------
NOP
@ ---------------------------------------------------------------------------
off_8000424: .long 0x8B01000






.org 0xB01000 @ CODE XREF: sub_80003A4+7Cj
@ DATA XREF: sub_80003A4+7Ao ...
BL AgbMain
LDR R0, var1
LDRB R0, [R0]
LDR R3, off_8B01018
CMP R0, #0
BNE loc_8B01016
LDRH R1, [R7,#0x28]
MOV R0, #1
AND R0, R1
LDR R3, off_8B0101C

loc_8B01016: @ CODE XREF: sub_80003A4+B00C68j
MOV PC, R3
@ ---------------------------------------------------------------------------
var1: .long 0x3003530
off_8B01018: .long 0x8000445 @ DATA XREF: sub_80003A4+B00C64r
off_8B0101C: .long 0x800042D @ DATA XREF: sub_80003A4+B00C70r


rtc_cmd: @ CODE XREF: rtc_get+18p
@ RTC_TurnOn+18p
PUSH {R4-R7,LR} @ Alternative name is '.gcc2_compiled.'
LSL R4, R0, #1
MOV R3, #7
MOV R7, #2
LDR R2, off_80001F8
MOV R6, #4
MOV R5, #5

loc_80001D2: @ CODE XREF: rtc_cmd+2Aj
MOV R0, R4
ASR R0, R3
AND R0, R7
LSL R0, R0, #0x10
LSR R0, R0, #0x10
MOV R1, R0
ORR R1, R6
STRH R1, [R2]
STRH R1, [R2]
STRH R1, [R2]
ORR R0, R5
STRH R0, [R2]
SUB R3, #1
CMP R3, #0
BGE loc_80001D2
MOV R0, #0
POP {R4-R7}
POP {R1}
BX R1
@ End of function rtc_cmd

@ ---------------------------------------------------------------------------
off_80001F8: .long 0x80000C4 @ DATA XREF: rtc_cmd+8r

@ =============== S U B R O U T I N E =======================================



rtc_data:
PUSH {R4-R7,LR}
MOV R4, R0
LSL R4, R4, #1
MOV R3, #0
MOV R7, #2
LDR R2, off_8000234
MOV R6, #4
MOV R5, #5

loc_800020C: @ CODE XREF: rtc_data+2Cj
MOV R0, R4
ASR R0, R3
AND R0, R7
LSL R0, R0, #0x10
LSR R0, R0, #0x10
MOV R1, R0
ORR R1, R6
STRH R1, [R2]
STRH R1, [R2]
STRH R1, [R2]
ORR R0, R5
STRH R0, [R2]
ADD R3, #1
CMP R3, #7
BLE loc_800020C
MOV R0, #0
POP {R4-R7}
POP {R1}
BX R1
@ End of function rtc_data

@ ---------------------------------------------------------------------------
.align 4
off_8000234: .long 0x80000C4 @ DATA XREF: rtc_data+Ar

@ =============== S U B R O U T I N E =======================================



rtc_read: @ CODE XREF: rtc_get:loc_80002AAp
@ rtc_get:loc_80002C2p ...
PUSH {R4-R7,LR}
MOV R5, #0
MOV R2, #0
LDR R3, off_8000274
MOV R6, #4
MOV R7, #5
MOV R0, #2
MOV R12, R0

loc_8000248: @ CODE XREF: rtc_read+30j
ADD R4, R2, #1
MOV R0, #4

loc_800024C: @ CODE XREF: rtc_read+1Aj
STRH R6, [R3]
SUB R0, #1
CMP R0, #0
BGE loc_800024C
STRH R7, [R3]
LDRH R1, [R3]
MOV R0, R12
AND R0, R1
LSL R0, R0, #0x10
LSR R0, R0, #0x10
LSL R0, R2
ORR R5, R0
MOV R2, R4
CMP R2, #7
BLE loc_8000248
ASR R5, R5, #1
MOV R0, R5
POP {R4-R7}
POP {R1}
BX R1
@ End of function rtc_read

@ ---------------------------------------------------------------------------
off_8000274: .long 0x80000C4 @ DATA XREF: rtc_read+6r

@ =============== S U B R O U T I N E =======================================



rtc_check: @ CODE XREF: RTC_TurnOn+26p docode+2p
LDR R0, off_8000284
LDR R0, [R0]
CMP R0, #0
BEQ locret_8000282
MOV R0, #1

locret_8000282: @ CODE XREF: rtc_check+6j
BX LR
@ End of function rtc_check

@ ---------------------------------------------------------------------------
off_8000284: .long 0x3005547 @ DATA XREF: rtc_checkr

@ =============== S U B R O U T I N E =======================================



rtc_get: @ CODE XREF: RTC_TurnOn+30p
@ RTC_GetTime+36p
PUSH {R4-R6,LR}
MOV R6, R0
LDR R1, off_80002D8
MOV R2, #1
STRH R2, [R1]
LDR R5, off_80002DC
MOV R0, #7
STRH R0, [R5]
STRH R2, [R1]
MOV R4, #5
STRH R4, [R1]
MOV R0, #0x65
BL rtc_cmd
STRH R4, [R5]
MOV R4, R6
MOV R5, #3

loc_80002AA: @ CODE XREF: rtc_get+2Ej
BL rtc_read
STRB R0, [R4]
ADD R4, #1
SUB R5, #1
CMP R5, #0
BGE loc_80002AA
LDR R1, off_80002DC
MOV R0, #5
STRH R0, [R1]
ADD R4, R6, #4
MOV R5, #2

loc_80002C2: @ CODE XREF: rtc_get+46j
BL rtc_read
STRB R0, [R4]
ADD R4, #1
SUB R5, #1
CMP R5, #0
BGE loc_80002C2
MOV R0, #0
POP {R4-R6}
POP {R1}
BX R1
@ End of function rtc_get

@ ---------------------------------------------------------------------------
off_80002D8: .long 0x80000C4 @ DATA XREF: rtc_get+4r
off_80002DC: .long 0x80000C6 @ DATA XREF: rtc_get+Ar rtc_get+30r

@ =============== S U B R O U T I N E =======================================



RTC_TurnOn: @ CODE XREF: docode+Ap
PUSH {R4,R5,LR}
LDR R0, off_800031C
MOV R1, #1
STRH R1, [R0]
SUB R0, #4
STRH R1, [R0]
MOV R5, #5
STRH R5, [R0]
LDR R4, off_8000320
MOV R0, #7
STRH R0, [R4]
MOV R0, #0x63
BL rtc_cmd
STRH R5, [R4]
BL rtc_read
LDR R1, off_8000324
STR R0, [R1]
BL rtc_check
LDR R1, off_8000328
STR R0, [R1]
LDR R0, off_800032C
BL rtc_get
MOV R0, #0
POP {R4,R5}
POP {R1}
BX R1
@ End of function RTC_TurnOn

@ ---------------------------------------------------------------------------
off_800031C: .long 0x80000C8 @ DATA XREF: RTC_TurnOn+2r
off_8000320: .long 0x80000C6 @ DATA XREF: RTC_TurnOn+10r
off_8000324: .long 0x3005547 @ DATA XREF: RTC_TurnOn+22r
off_8000328: .long 0x3005504 @ DATA XREF: RTC_TurnOn+2Ar
off_800032C: .long 0x3005505 @ DATA XREF: RTC_TurnOn+2Er

@ =============== S U B R O U T I N E =======================================



UNBCD: @ CODE XREF: RTC_GetTime+3Ep
@ RTC_GetTime+4Ep ...
MOV R2, #0xF
AND R2, R0
ASR R0, R0, #4
LSL R1, R0, #2
ADD R1, R1, R0
LSL R1, R1, #1
ADD R2, R2, R1
MOV R0, R2
BX LR
@ End of function UNBCD

@ ---------------------------------------------------------------------------
.align 4

@ =============== S U B R O U T I N E =======================================


RTC_GetTime: @ CODE XREF: docode+10p

var_14 = -0x14
var_13 = -0x13
var_12 = -0x12
var_11 = -0x11
var_10 = -0x10
var_F = -0xF
var_E = -0xE

PUSH {R4,R5,LR}
SUB SP, SP, #8
MOV R5, R0
LDR R0, off_8000370
LDR R0, [R0]
CMP R0, #0
BNE loc_8000378
MOV R1, #0
LDR R0, dword_8000374
STRH R0, [R5]
MOV R0, #6
STRB R0, [R5,#2]
MOV R0, #0x1A
STRB R0, [R5,#3]
MOV R0, #1
STRB R0, [R5,#4]
MOV R0, #0xC
STRB R0, [R5,#5]
STRB R1, [R5,#6]
STRB R1, [R5,#7]
B loc_8000420
@ ---------------------------------------------------------------------------
nop
nop
nop


off_8000370: .long 0x3005504 @ DATA XREF: RTC_GetTime+6r
dword_8000374: .long 0x7D9 @ DATA XREF: RTC_GetTime+10r
@ ---------------------------------------------------------------------------

loc_8000378: @ CODE XREF: RTC_GetTime+Cj
MOV R0, SP
BL rtc_get
MOV R0, SP
LDRB R0, [R0,#0x14+var_14]
BL UNBCD
LDR R1, var2
ADD R0, R0, R1
STRH R0, [R5]
MOV R0, SP
LDRB R0, [R0,#0x14+var_13]
BL UNBCD
STRB R0, [R5,#2]
MOV R0, SP
LDRB R1, [R0,#0x14+var_12]
MOV R4, #0x3F
MOV R0, R4
AND R0, R1
BL UNBCD
STRB R0, [R5,#3]
MOV R0, SP
LDRB R1, [R0,#0x14+var_11]
MOV R0, R4
AND R0, R1
BL UNBCD
STRB R0, [R5,#4]
MOV R0, SP
LDRB R0, [R0,#0x14+var_10]
AND R4, R0
MOV R0, R4
BL UNBCD
STRB R0, [R5,#5]
MOV R0, SP
LDRB R0, [R0,#0x14+var_F]
BL UNBCD
STRB R0, [R5,#6]
MOV R0, SP
LDRB R0, [R0,#0x14+var_E]
BL UNBCD
STRB R0, [R5,#7]
LDR R2, off_800042C
LDRB R3, [R5,#6]
LDRB R0, [R2,#2]
ADD R1, R3, R0
STRB R1, [R5,#6]
LSL R0, R1, #0x18
LSR R0, R0, #0x18
CMP R0, #0x3B
BLS loc_80003F6
MOV R0, R1
SUB R0, #0x3C
STRB R0, [R5,#6]
LDRB R0, [R5,#5]
ADD R0, #1
STRB R0, [R5,#5]

loc_80003F6: @ CODE XREF: RTC_GetTime+A4j
LDRB R3, [R5,#5]
LDRB R0, [R2,#1]
ADD R1, R3, R0
STRB R1, [R5,#5]
LSL R0, R1, #0x18
LSR R0, R0, #0x18
CMP R0, #0x17
BLS loc_8000412
MOV R0, R1
SUB R0, #0x18
STRB R0, [R5,#5]
LDRB R0, [R5,#4]
ADD R0, #1
STRB R0, [R5,#4]

loc_8000412: @ CODE XREF: RTC_GetTime+C0j
LDRB R2, [R2]
LDRB R1, [R5,#4]
ADD R0, R2, R1
MOV R1, #7
BL __modsi3
STRB R0, [R5,#4]

loc_8000420: @ CODE XREF: RTC_GetTime+28j
MOV R0, #0
ADD SP, SP, #8
POP {R4,R5}
POP {R1}
BX R1
@ End of function RTC_GetTime

@ ---------------------------------------------------------------------------
.align 4
off_800042C: .long 0x3005537 @ DATA XREF: RTC_GetTime+94r
@vars
var2: .long 0x7D0




@ =============== S U B R O U T I N E =======================================


docode: @ CODE XREF: AgbMain+2p
PUSH {LR}
BL rtc_check
CMP R0, #0
BNE loc_800043E
BL RTC_TurnOn

loc_800043E: @ CODE XREF: docode+8j
LDR R0, =0x300553D
BL RTC_GetTime
MOV R0, #0
POP {R1}
BX R1
@ End of function docode

@ ---------------------------------------------------------------------------
.align 4
off_800044C: .long 0x300553D @ DATA XREF: docode:loc_800043Er

@ =============== S U B R O U T I N E =======================================



AgbMain: @ CODE XREF: .text:080000ECp
@ DATA XREF: .text:080000E4o ...
PUSH {LR}
BL docode
POP {R0}
BX R0
@ End of function AgbMain

@ ---------------------------------------------------------------------------
.align 4

@ =============== S U B R O U T I N E =======================================



__modsi3: @ CODE XREF: RTC_GetTime+D6p
MOV R3, #1
CMP R1, #0
BEQ Ldiv0
BPL Over1
NEG R1, R1

Over1: @ CODE XREF: __modsi3+6j
PUSH {R4}
PUSH {R0}
CMP R0, #0
BPL Over2
NEG R0, R0

Over2: @ CODE XREF: __modsi3+10j
CMP R0, R1
BCC Lgot_result
@MOV R4, #0x10000000
MOV R4, #1
LSL R4, #8
LSL R4, #4
LSL R4, #0x10


Loop1: @ CODE XREF: __modsi3+28j
CMP R1, R4
BCS Lbignum
CMP R1, R0
BCS Lbignum
LSL R1, R1, #4
LSL R3, R3, #4
B Loop1
@ ---------------------------------------------------------------------------

Lbignum: @ CODE XREF: __modsi3+1Ej __modsi3+22j
LSL R4, R4, #3

Loop2: @ CODE XREF: __modsi3+38j
CMP R1, R4
BCS Loop3
CMP R1, R0
BCS Loop3
LSL R1, R1, #1
LSL R3, R3, #1
B Loop2
@ ---------------------------------------------------------------------------

Loop3: @ CODE XREF: __modsi3+2Ej __modsi3+32j ...
MOV R2, #0
CMP R0, R1
BCC Over3
SUB R0, R0, R1

Over3: @ CODE XREF: __modsi3+3Ej
LSR R4, R1, #1
CMP R0, R4
BCC Over4
SUB R0, R0, R4
MOV R12, R3
MOV R4, #1
ROR R3, R4
ORR R2, R3
MOV R3, R12

Over4: @ CODE XREF: __modsi3+46j
LSR R4, R1, #2
CMP R0, R4
BCC Over5
SUB R0, R0, R4
MOV R12, R3
MOV R4, #2
ROR R3, R4
ORR R2, R3
MOV R3, R12

Over5: @ CODE XREF: __modsi3+58j
LSR R4, R1, #3
CMP R0, R4
BCC Over6
SUB R0, R0, R4
MOV R12, R3
MOV R4, #3
ROR R3, R4
ORR R2, R3
MOV R3, R12

Over6: @ CODE XREF: __modsi3+6Aj
MOV R12, R3
CMP R0, #0
BEQ Over7
LSR R3, R3, #4
BEQ Over7
LSR R1, R1, #4
B Loop3
@ ---------------------------------------------------------------------------

Over7: @ CODE XREF: __modsi3+7Cj __modsi3+80j
@MOV R4, #0xE0000000
MOV R4, #0xE
LSL R4, #8
LSL R4, #4
LSL R4, #0x10
AND R2, R4
BEQ Lgot_result
MOV R3, R12
MOV R4, #3
ROR R3, R4
TST R2, R3
BEQ Over8
LSR R4, R1, #3
ADD R0, R0, R4

Over8: @ CODE XREF: __modsi3+96j
MOV R3, R12
MOV R4, #2
ROR R3, R4
TST R2, R3
BEQ Over9
LSR R4, R1, #2
ADD R0, R0, R4

Over9: @ CODE XREF: __modsi3+A4j
MOV R3, R12
MOV R4, #1
ROR R3, R4
TST R2, R3
BEQ Lgot_result
LSR R4, R1, #1
ADD R0, R0, R4

Lgot_result: @ CODE XREF: __modsi3+16j __modsi3+8Cj ...
POP {R4}
CMP R4, #0
BPL Over10
NEG R0, R0

Over10: @ CODE XREF: __modsi3+BCj
POP {R4}
MOV PC, LR
@ ---------------------------------------------------------------------------

Ldiv0: @ CODE XREF: __modsi3+4j
PUSH {LR}
BL __div0
MOV R0, #0
POP {PC}
@ End of function __modsi3

@ ---------------------------------------------------------------------------
.align 4

@ =============== S U B R O U T I N E =======================================



__div0: @ CODE XREF: __modsi3+C6p
MOV PC, LR
@ End of function __div0

So here's the patch.
Download the IPS patch (http://depositfiles.com/files/qwbiez164)

I am not posting an example script, and to anyone else, PLEASE DO NOT POST AN EXAMPLE SCRIPT ANYWHERE except in your own hack
Why? Because then i'd see "RTC IN MY HACK" and properly my slightly modified example script. So you'll have to make your own from the data below, sorry for the earlier trouble.

I use No$GBA and vba-m for testing. :)

Patches on to the games main loop at 0x41E. Then executes my code at 0xb01000.

The time it gives you is stored at 0x300553C
In the following format.
Year u16
skip a byte
month u8
day u8
Day of week(mon-sun/1-7) u8
Hour u8
minute u8
second u8

at 0x3005537
is
u8 dayofweek;
u8 hours;
u8 minutes;

use that when you create your time setter function. code auto compensates(I didn't and don't plan on a date thing you can do that on your own)





Please give me credit.

Thanks to kawai/ZodiacDaGreat for helping me with an example script.

Merry Christmas everyone

ZodiacDaGreat
December 25th, 2009, 12:17 PM
So, it's approved uh? Well, here's my contribution. Merry Christmas guys :)

@ Fire Red RTC Hack
@ Version 1.0.2
@ By ZodiacDaGreat
@ ----------------------------------------------------------------
.code 16
.thumb

.org 0x000000
.Main:
push {r4}

@ RTC Part
bl .SetupRTC
ldr r0, .IWRAMRTC
bl .ManipulateRTC

@ Part of the original routine
ldr r4, .UnkFunc1
bl .BranchLink
lsl r0, r0, #0x18
cmp r0, #0x0
bne .Endme

ldr r4, .UnkFunc2
bl .BranchLink

.Endme:
ldr r4, .Return

.BranchLink:
bx r4

@ ----------------------------------------------------------------
@ Seting Up RTC
.SetupRTC:
push {r4, r5, lr}
ldr r3, .IOPORTCNT
mov r2, #0x1
strh r2, [r3] @ Enable RTC

mov r5, #0x5
sub r3, r3, #0x4 @ r3 = IOPORTDATA
strh r2, [r3]
strh r5, [r3]

ldr r4, .IOPORTDIRECTION
mov r3, #0x7
strh r3, [r4]

mov r0, #0x63
bl .RTCFunc1

strh r5, [r4]
bl .RTCFunc2

ldr r3, .Temp
strh r0, [r3]
pop {r4, r5, pc}

@ ----------------------------------------------------------------
.RTCFunc1:
push {r4-r7, lr}
ldr r1, .IOPORTDATA
lsl r4, r0, #0x1 @ r4 = 0xC6
mov r7, #0x2
mov r0, #0x7 @ Counter
mov r6, #0x4
mov r5, #0x5
.Loop1:
mov r2, r4
asr r2, r0
and r2, r7
mov r3, r2
orr r3, r6
orr r2, r5

lsl r3, r3, #0x10 @ Prevents overflow
lsl r2, r2, #0x10
lsr r3, r3, #0x10
lsr r2, r2, #0x10

strh r3, [r1]
strh r3, [r1]
strh r3, [r1]
strh r2, [r1]

sub r0, r0, #0x1
bcs .Loop1
pop {r4-r7, pc}

@ ----------------------------------------------------------------
.RTCFunc2:
push {r4-r6, lr}
ldr r2, .IOPORTDATA
mov r0, #0x0
mov r4, #0x0
mov r1, #0x4
mov r6, #0x5
mov r5, #0x2
.Loop2:
strh r1, [r2]
strh r1, [r2]
strh r1, [r2]
strh r1, [r2]
strh r1, [r2]
strh r6, [r2]

ldrh r3, [r2]
and r3, r3, r5
lsl r3, r0
add r0, r0, #0x1
orr r4, r3
cmp r0, #0x8
bne .Loop2
asr r0, r4, #0x1
pop {r4-r6, pc}

@ ----------------------------------------------------------------
.ManipulateRTC:
push {r4-r6, lr}
ldr r2, .IOPORTDATA
ldr r5, .IOPORTDIRECTION
mov r1, #0x1
mov r3, #0x7
mov r4, #0x5
strh r1, [r2]
mov r6, r0
strh r3, [r5]
strh r1, [r2]
strh r4, [r2]

mov r0, #0x65
bl .RTCFunc1

strh r4, [r5]
mov r5, #0x0

.Loop3:
bl .RTCFunc2
add r4, r6, r5
add r5, r5, #0x1
strb r0, [r4]
cmp r5, #0x4
bne .Loop3

ldr r3, .IOPORTDIRECTION
mov r2, #0x5
strh r2, [r3]

.Loop4:
bl .RTCFunc2
add r4, r6, r5
add r5, r5, #0x1
strb r0, [r4]
cmp r5, #0x7
bne .Loop4

mov r0, #0x0
pop {r4-r6, pc}

@ ----------------------------------------------------------------
.align 2
.UnkFunc1: .word 0x0800B179
.UnkFunc2: .word 0x08000511
.Return: .word 0x080004bF

.Temp: .word 0x03007E5C
.IWRAMRTC: .word 0x03004038
.IOPORTDATA: .word 0x080000C4
.IOPORTDIRECTION: .word 0x080000C6
.IOPORTCNT: .word 0x080000C8

@ ----------------------------------------------------------------
@ Put 00B5 0148 0047 0000 [Reverse Address+1] 0000 10BC at 0x4B0

Remember to credit me if you use my code, it's for Fire Red. The RTC is at 0x03004038. The format is:
[Year][Month][Date][Filler][Hour][Month][Date]
They are all a byte each in size.

Thanks to
HackMew - For RTC tips and hints on how it works

helloNL
December 25th, 2009, 12:52 PM
what i dont understand is what does it do?

558122_DG
December 25th, 2009, 12:53 PM
hmmm, nice present although all it did was destroy what little understanding i had of asm :P

.Seth
December 25th, 2009, 12:55 PM
Nice job, interdpth. Many of us have desired an RTC for the FireRed and Leafgreen versions.

I'll put it to use right away. ;)

diegoisawesome
December 25th, 2009, 02:52 PM
So, it's approved uh? Well, here's my contribution. Merry Christmas guys :)

@ Fire Red RTC Hack
@ Version 1.0.2
@ By ZodiacDaGreat
@ ----------------------------------------------------------------
.code 16
.thumb

.org 0x000000
.Main:
push {r4}

@ RTC Part
bl .SetupRTC
ldr r0, .IWRAMRTC
bl .ManipulateRTC

@ Part of the original routine
ldr r4, .UnkFunc1
bl .BranchLink
lsl r0, r0, #0x18
cmp r0, #0x0
bne .Endme

ldr r4, .UnkFunc2
bl .BranchLink

.Endme:
ldr r4, .Return

.BranchLink:
bx r4

@ ----------------------------------------------------------------
@ Seting Up RTC
.SetupRTC:
push {r4, r5, lr}
ldr r3, .IOPORTCNT
mov r2, #0x1
strh r2, [r3] @ Enable RTC

mov r5, #0x5
sub r3, r3, #0x4 @ r3 = IOPORTDATA
strh r2, [r3]
strh r5, [r3]

ldr r4, .IOPORTDIRECTION
mov r3, #0x7
strh r3, [r4]

mov r0, #0x63
bl .RTCFunc1

strh r5, [r4]
bl .RTCFunc2

ldr r3, .Temp
strh r0, [r3]
pop {r4, r5, pc}

@ ----------------------------------------------------------------
.RTCFunc1:
push {r4-r7, lr}
ldr r1, .IOPORTDATA
lsl r4, r0, #0x1 @ r4 = 0xC6
mov r7, #0x2
mov r0, #0x7 @ Counter
mov r6, #0x4
mov r5, #0x5
.Loop1:
mov r2, r4
asr r2, r0
and r2, r7
mov r3, r2
orr r3, r6
orr r2, r5

lsl r3, r3, #0x10 @ Prevents overflow
lsl r2, r2, #0x10
lsr r3, r3, #0x10
lsr r2, r2, #0x10

strh r3, [r1]
strh r3, [r1]
strh r3, [r1]
strh r2, [r1]

sub r0, r0, #0x1
bcs .Loop1
pop {r4-r7, pc}

@ ----------------------------------------------------------------
.RTCFunc2:
push {r4-r6, lr}
ldr r2, .IOPORTDATA
mov r0, #0x0
mov r4, #0x0
mov r1, #0x4
mov r6, #0x5
mov r5, #0x2
.Loop2:
strh r1, [r2]
strh r1, [r2]
strh r1, [r2]
strh r1, [r2]
strh r1, [r2]
strh r6, [r2]

ldrh r3, [r2]
and r3, r3, r5
lsl r3, r0
add r0, r0, #0x1
orr r4, r3
cmp r0, #0x8
bne .Loop2
asr r0, r4, #0x1
pop {r4-r6, pc}

@ ----------------------------------------------------------------
.ManipulateRTC:
push {r4-r6, lr}
ldr r2, .IOPORTDATA
ldr r5, .IOPORTDIRECTION
mov r1, #0x1
mov r3, #0x7
mov r4, #0x5
strh r1, [r2]
mov r6, r0
strh r3, [r5]
strh r1, [r2]
strh r4, [r2]

mov r0, #0x65
bl .RTCFunc1

strh r4, [r5]
mov r5, #0x0

.Loop3:
bl .RTCFunc2
add r4, r6, r5
add r5, r5, #0x1
strb r0, [r4]
cmp r5, #0x4
bne .Loop3

ldr r3, .IOPORTDIRECTION
mov r2, #0x5
strh r2, [r3]

.Loop4:
bl .RTCFunc2
add r4, r6, r5
add r5, r5, #0x1
strb r0, [r4]
cmp r5, #0x7
bne .Loop4

mov r0, #0x0
pop {r4-r6, pc}

@ ----------------------------------------------------------------
.align 2
.UnkFunc1: .word 0x0800B179
.UnkFunc2: .word 0x08000511
.Return: .word 0x080004bF

.Temp: .word 0x03007E5C
.IWRAMRTC: .word 0x03004038
.IOPORTDATA: .word 0x080000C4
.IOPORTDIRECTION: .word 0x080000C6
.IOPORTCNT: .word 0x080000C8

@ ----------------------------------------------------------------
@ Put 00B5 0148 0047 0000 [Reverse Address+1] 0000 10BC at 0x4B0

Remember to credit me if you use my code, it's for Fire Red. The RTC is at 0x03004038. The format is:
[Year][Month][Date][Filler][Hour][Minutes][Seconds]
They are all a byte each in size.

Thanks to
HackMew - For RTC tips and hints on how it works
Um, I think you meant to put that. :P
EDIT: Also, is it just me, or does this use the Windows clock?
Does this mean that it wouldn't work on an actual GBA?

Chaos Rush
December 25th, 2009, 03:20 PM
Is this RTC identical to R/S/E? Also, if you were to put a FireRed or LeafGreen rom on a GBA Flashcart, would the RTC work correctly?

interdpth
December 25th, 2009, 05:30 PM
what i dont understand is what does it do?

I asked you not to post if you don't understand.

Um, I think you meant to put that. :P
EDIT: Also, is it just me, or does this use the Windows clock?
Does this mean that it wouldn't work on an actual GBA?

Is this RTC identical to R/S/E? Also, if you were to put a FireRed or LeafGreen rom on a GBA Flashcart, would the RTC work correctly?

I forgot to add some extra data to my post on how to offset the changes, added it, so please refer to it. And yes it should work on the real GBA, the emulators just base it off of a time() call, so it uses your OS's time.

Chaos Rush
December 25th, 2009, 05:55 PM
I forgot to add some extra data to my post on how to offset the changes, added it, so please refer to it. And yes it should work on the real GBA, the emulators just base it off of a time() call, so it uses your OS's time.
So this is better than the R/S/E one? That's cool. Since the R/S/E RTC doesn't work on GBA flashcarts, you should see if you can add your FR/LG clock to R/S/E (and remove the clock that comes with R/S/E so then we don't have to see the "internal battery has run dry" message on a GBA flashcart).

ZodiacDaGreat
December 25th, 2009, 06:25 PM
So this is better than the R/S/E one? That's cool. Since the R/S/E RTC doesn't work on GBA flashcarts, you should see if you can add your FR/LG clock to R/S/E (and remove the clock that comes with R/S/E so then we don't have to see the "internal battery has run dry" message on a GBA flashcart).
I guess it depends on whether or not that the flash cart has the RTC chip built in if it doesn't then RTC doesn't work.

Haku.
December 25th, 2009, 07:42 PM
Could anyone care to show me how do i insert this?
At which offset and how do i use it please?
I'm not very good with ASM yet.
Must i use setvar 0x8003 or 0x????.

interdpth
December 25th, 2009, 08:03 PM
I have no clue what you mean.

Haku.
December 25th, 2009, 09:42 PM
What i meant is, how do i use this?
Must i use callasm [offset] + 1?

interdpth
December 25th, 2009, 09:56 PM
No. You just apply it to the game and it runs every frame.

Did you not read the description?

Chaos Rush
December 25th, 2009, 09:59 PM
I guess it depends on whether or not that the flash cart has the RTC chip built in if it doesn't then RTC doesn't work.
Well that's a bummer...

Would it ever be possible to add a RTC in R/S/FR/LG/E where it works like G/S/C's RTC?

interdpth
December 25th, 2009, 10:06 PM
GSC also has a builtin RTC chip.

Darthatron
December 26th, 2009, 04:16 AM
Problem at the moment will be fixed in a few hours

I ruined interdpth's night. :( Thanks for this by the way, I have been waiting patiently. ;)

diegoisawesome
December 26th, 2009, 07:52 AM
This is the first ASM script I've compiled correctly! The problem was that I was using devkitARM for THUMB scripts!

Hehe, I am so stupid sometimes... :P

Destinyfate
December 26th, 2009, 08:47 AM
thnaks alot merry late christmas lol XD

interdpth
December 26th, 2009, 12:18 PM
Can a mod move this thread and rename it plz

mindfreak
December 26th, 2009, 12:56 PM
To bad you had to post a patch.
It's much more fun trying to assemble this on your own and now almost anyone can use it.:(
Anyway, merry Christmas and thanks for sharing.

diegoisawesome
December 26th, 2009, 12:59 PM
At least me and a few others can be proud that we assembled it! :D
Although I assembled ZodiacDaGreat's because interdpth's is for LeafGreen...

interdpth
December 26th, 2009, 02:35 PM
Zodiac's won't work vanilla. I'm 99% sure my patch will work for FR, I don't have the game otherwise i'd have a ROM for it.

But I messed something up in code before i pasted it, so the code was bad.

Hopefully people will respect my wishes and not post an example script how to use it

Anywho, i'll be having a day and night system based off of MasterMind's code soon. ^_^

Future releases like this will be ASM only. And i'll make sure I don't fudge it up XD

mindfreak
December 26th, 2009, 03:17 PM
Yes I got ZodiacDaGreats clock Working!:classic:
Now I've just to find out how I can display it ingame.(interdpths example script)
And somehow I think thats the most difficult part since all the rest was given here.

pokefreak2
December 26th, 2009, 03:17 PM
is this for a script like callsm? or do you just paste the code in the game with hex editor and it runs the RTC? for firered/leafgreen?

diegoisawesome
December 26th, 2009, 05:02 PM
Zodiac's won't work vanilla. I'm 99% sure my patch will work for FR, I don't have the game otherwise i'd have a ROM for it.

But I messed something up in code before i pasted it, so the code was bad.

Hopefully people will respect my wishes and not post an example script how to use it

Anywho, i'll be having a day and night system based off of MasterMind's code soon. ^_^

Future releases like this will be ASM only. And i'll make sure I don't fudge it up XD
What do you mean, "won't work vanilla"? It works just fine when implemented. And if yours works fine in FR, I may just try it.

Full Metal
December 26th, 2009, 05:32 PM
ok...i'm confuzzled, does this, or does it not work with firered?
would i have to do some fancy stuff with patches to get it to work in FR (as in the changelog)?
I gues i dont mind it being lg, it's just that i own a fr...i sold my lg :\
plus...my work on my sinnoh patch is all on fr too....so yea...
And ps, can't wait for d/n system ^-^

diegoisawesome
December 26th, 2009, 05:39 PM
I have confirmed that this fully works in FR, so no worries. And I see that your patch, interdpth, has day of the week AND full 2009 vs 09 in the year, so sorry to Zodiac. :P

interdpth
December 26th, 2009, 06:04 PM
What do you mean, "won't work vanilla"? It works just fine when implemented. And if yours works fine in FR, I may just try it.

I meant with the org being 0.

Mine is fully setup XD

Oh, hey, go GF, yay it works for both. Diego, if you need to script a to see how to use it, let me know.

diegoisawesome
December 26th, 2009, 06:28 PM
I meant with the org being 0.

Mine is fully setup XD

Oh, hey, go GF, yay it works for both. Diego, if you need to script a to see how to use it, let me know.
Nah, I think I'm doing fine with my writebytetooffset setup...
Btw, am I on the right track? :P

interdpth
December 26th, 2009, 06:33 PM
I never used writebytetooffset

check your pm's

diegoisawesome
December 26th, 2009, 07:53 PM
at 0x3005537
is
u8 dayofweek;
u8 hours;
u8 minutes;

use that when you create your time setter function. code auto compensates(I didn't and don't plan on a date thing you can do that on your own)
How do I use these? When I change one, it randomly changes the actual clock.

interdpth
December 26th, 2009, 08:16 PM
0x300553C.minutes =0x300553C.minutes + 0x3005537.minutes;
if(0x300553C.minutes > 59)
{
0x300553C.minutes -= 60;
0x300553C.hours++;
}
0x300553C.hours =0x300553C.hours + 0x3005537.hours;
if(0x300553C.hours > 23)
{
0x300553C.hours -= 24;
0x300553C.dayofweek++;
}
0x300553C.dayofweek = (0x300553C.dayofweek + 0x3005537.dayofweek) % 7;

The RTC does that math every frame so use that as a basis for your setter.

diegoisawesome
December 26th, 2009, 08:35 PM
0x300553C.minutes =0x300553C.minutes + 0x3005537.minutes;
if(0x300553C.minutes > 59)
{
0x300553C.minutes -= 60;
0x300553C.hours++;
}
0x300553C.hours =0x300553C.hours + 0x3005537.hours;
if(0x300553C.hours > 23)
{
0x300553C.hours -= 24;
0x300553C.dayofweek++;
}
0x300553C.dayofweek = (0x300553C.dayofweek + 0x3005537.dayofweek) % 7;

The RTC does that math every frame so use that as a basis for your setter.
On a GBA, this would make it to what you set it, right? But on the computer, wouldn't this offset your computer's time by that amount?

interdpth
December 26th, 2009, 09:35 PM
Yeah, that's pretty much it.

diegoisawesome
December 26th, 2009, 09:41 PM
Yeah, that's pretty much it.
But since I want GBA compatibility and PC compatibility, what should I do? Add an option to select PC or GBA?

... ... ...

Actually, that sounds like a good idea. :P

interdpth
December 26th, 2009, 09:43 PM
No need just make a time set function yo.

diegoisawesome
December 26th, 2009, 10:14 PM
No need just make a time set function yo.
... ... ...
Man, I am such a n00b. How would I do this, and how could I make it so it has the right time in and out of the computer? :/

liuyanghejerry
December 26th, 2009, 10:30 PM
^^ This is VERY GOOD,and bring the chance of DAN for FR/LG!
Nice work!

interdpth
December 26th, 2009, 10:47 PM
... ... ...
Man, I am such a n00b. How would I do this, and how could I make it so it has the right time in and out of the computer? :/

If they're on an actual console.

They fix the time.

If not they don't need to touch it

BlazingShadow
December 27th, 2009, 03:02 AM
Man just another troublesome thing showed up.....

D-Trogh
December 27th, 2009, 03:20 AM
It sucks that I have to study for my exams.. Life at uni sucks in general, almost have no spare time.. Anyway, nice work. Maybe I can try it in the week after my exams. (A month from now XD )

interdpth
December 27th, 2009, 09:31 AM
Man just another troublesome thing showed up.....

What the heck are you talking about? o.O

linkandzelda
December 27th, 2009, 03:59 PM
I like this interdpth... Im not gonna try it just yet (although im VERY tempted too) as there is something else i will try first when its out...

Btw for all those people wondering if this is compatible with the GBA time and windows time etc, VBA emulates an RTC chip which uses your windows clock, on a real GBA cart that has an RTC chip it just uses the real chip for the time. That brings me to a question interdpth.. If this just grabs the time from an RTC chip then we cant set the time without using that time set function right? lol (im not the best with this...)

Link

pokefreak2
December 27th, 2009, 09:44 PM
I like this interdpth... Im not gonna try it just yet (although im VERY tempted too) as there is something else i will try first when its out...

Btw for all those people wondering if this is compatible with the GBA time and windows time etc, VBA emulates an RTC chip which uses your windows clock, on a real GBA cart that has an RTC chip it just uses the real chip for the time. That brings me to a question interdpth.. If this just grabs the time from an RTC chip then we cant set the time without using that time set function right? lol (im not the best with this...)

LinkCan't believe link posted here i bet if a day and night system came out for fire red he'd use it for LC :D

interdpth
December 27th, 2009, 10:55 PM
Looks like i'll be his hero in a few days. >_>

Hiroshi Sotomura
December 28th, 2009, 12:59 AM
I smell a new ROM hacking fad. :(
But hey, you've heard the other things I've had to say about it. Let's see if you can do a more efficient Day/Night idea that's outside of the box when you get to it.

Chaos Rush
December 28th, 2009, 11:09 AM
I have another idea:

If the game is able to check for the Windows clock, is there anyway to check for a Nintendo DS clock?

Sorry, but I really wanna find out if RTC support is possible on an EZFlash 3in1.

interdpth
December 28th, 2009, 11:51 AM
the game doesn't check windows clock.

the emulator does. -_-

Does your EZFlash say it has an RTC?

If so, you should know.

Chaos Rush
December 28th, 2009, 12:22 PM
Does your EZFlash say it has an RTC?

If so, you should know.
EZFlash does not have an RTC, that's why I'm asking if it's possible to check for the DS clock. The idea was that even though EZFlash has no RTC, Nintendo DS does, and the EZFlash operates in the GBA slot of a Nintendo DS.

interdpth
December 28th, 2009, 06:25 PM
Added the RTC asm back to the first post :)

Banjora Marxvile
December 29th, 2009, 10:50 AM
EZFlash does not have an RTC, that's why I'm asking if it's possible to check for the DS clock. The idea was that even though EZFlash has no RTC, Nintendo DS does, and the EZFlash operates in the GBA slot of a Nintendo DS.

He answered your question. The RTC apparently (if I understand it right) checks what your Emulator knows, and your Emulator only knows it by checking the Windows Clock. If your EZ Flash understands the DS clock, and uses that, then yes, but as I know EZ Flash is a GBA thing, then it won't read the DS clock, meaning that the RTC won't read the clock, as EZ Flash can't... Sounds complicated, but simple.

Matteron (96)
December 30th, 2009, 03:32 PM
I got all this to work fine, but I have a question, well two actually.
1. Will eevee be able to evolve into espeon/umbreon?
2. If I were to make a script to tell the player that the time is <insert time here>, what would I need to enter in xse?

interdpth
December 30th, 2009, 03:34 PM
I don't know about eevee

But you need copy byte commands to read the values.

Younegai
December 31st, 2009, 12:06 PM
I has a question :P

Well, I don't really know where this should go, but, I was wondering if it were possible to have tiles act accordingly to the RTC. Like windows and lights, etc. And if so, would I need to do something to the code/script (I'm horrible at that stuff by the way...) or would I have to do something in AdvanceMap?

Matteron (96)
December 31st, 2009, 12:29 PM
I has a question :P

Well, I don't really know where this should go, but, I was wondering if it were possible to have tiles act accordingly to the RTC. Like windows and lights, etc. And if so, would I need to do something to the code/script (I'm horrible at that stuff by the way...) or would I have to do something in AdvanceMap?
Right now the easiest way to make stuff like lights that turn on at night is to open up DaN and change the pallet so that the pallet that you used for the light is brighter than all the other tiles.

Dude_flibble_07
January 7th, 2010, 03:28 AM
Hey! been looking all over for a rtc for fr! 3 questions though: how do I put it in and can I use day and night with this? and if so, how? sorry, i am hopeless at scripting.

Darthatron
January 7th, 2010, 03:36 AM
Hey! been looking all over for a rtc for fr! 3 questions though: how do I put it in and can I use day and night with this? and if so, how? sorry, i am hopeless at scripting.

Look in the tool box, there is a thread for exactly what you are asking for.

Flandre Scarlet
January 18th, 2010, 07:43 AM
Oh my god man, thanks so much! It's great someone managed to make a RTC for FireRed/LeafGreen. It works perfect on Firered.

Again, thanks! ;3

Omega Zero
January 31st, 2010, 12:56 AM
Soo.. how do you get the script example to work? like example in your hack special adventures.. i have tryed callasm but that just freezes the game t_t.. is it writebytetooffset?

Jambo51
July 2nd, 2010, 06:13 AM
I'm trying to use the RTC to get the day of the week byte so that I can have day specific events, but every time I copy the byte stored at 0x305540 (I also checked offsets on either side of this), it returns 0 as the result.

I'm running Windows 7 and i'm just wondering if it's a problem with VBA's time call, or if i'm looking in the wrong offset for the day of the week byte, or if i'm scripting it wrong, or if there's a problem with the RTC itself.

I haven't yet checked if it works on Vista, but will try shortly.

That said, i'm fairly sure that the RTC works fine, so if it's related to the time call function of VBA, then that would explain a lot.

Shiny Quagsire
July 2nd, 2010, 07:36 AM
Make sure VBA's RTC clock is on. :)

Jambo51
July 2nd, 2010, 10:00 AM
Make sure VBA's RTC clock is on. :)

It is. It's just the day of the week byte I can't find.

Shiny Quagsire
July 2nd, 2010, 10:19 AM
The time it gives you is stored at 0x300553C
In the following format.
Year u16
skip a byte
month u8
day u8
Day of week(mon-sun/1-7) u8
Hour u8
minute u8
second u8

that would be:
XX XX XX XX XX YY XX XX XX
the YY is the day of the week, it's at: 300554C

knizz
July 2nd, 2010, 10:42 AM
Can someone show me the part of the ASM that reads out the time value (=without the mainloop-hook and date-conversion). I can't understand GBATEK in this point.

Jambo51
July 2nd, 2010, 04:10 PM
that would be:
XX XX XX XX XX YY XX XX XX
the YY is the day of the week, it's at: 300554C

I tried it and it didn't work. Thanks for the help though, shiny quagsire.
I'll continue this dialogue using PM's so we don't clutter up the thread.

colcolstyles
July 5th, 2010, 05:52 PM
I'm trying to use the RTC to get the day of the week byte so that I can have day specific events, but every time I copy the byte stored at 0x305540 (I also checked offsets on either side of this), it returns 0 as the result.

I'm running Windows 7 and i'm just wondering if it's a problem with VBA's time call, or if i'm looking in the wrong offset for the day of the week byte, or if i'm scripting it wrong, or if there's a problem with the RTC itself.

I haven't yet checked if it works on Vista, but will try shortly.

That said, i'm fairly sure that the RTC works fine, so if it's related to the time call function of VBA, then that would explain a lot.

The RTC doesn't provide a day-of-the-week byte. I haven't used this but from a brief scan of both ZDG and interdpth's code, I don't see any code that calculates the day of the week. You'll have to manually calculate the day from the date. Wikipedia has a nice article on the subject (http://en.wikipedia.org/wiki/Calculating_the_day_of_the_week#An_algorithm_to_calculate_the_day_of_the_week) which I used to base my code off of (note: you'll have to call SWI $06 to utilize the modulo operator in assembly (read about it here (http://nocash.emubase.de/gbatek.htm#biosarithmeticfunctions)))

Can someone show me the part of the ASM that reads out the time value (=without the mainloop-hook and date-conversion). I can't understand GBATEK in this point.

Aw, but that'll ruin the fun. It took me months to figure out how to read the time. Trust me, you'll feel a lot better if you figure it out yourself than if you take the easy way out.

Shiny Quagsire
July 5th, 2010, 06:14 PM
Aw, but that'll ruin the fun. It took me months to figure out how to read the time. Trust me, you'll feel a lot better if you figure it out yourself than if you take the easy way out.

It only took me about a week to figure it out :)
About 30 minutes to write an ASM routine to make the same effect :D

The RTC doesn't provide a day-of-the-week byte.
How come it works for me? :\

colcolstyles
July 5th, 2010, 06:56 PM
How come it works for me? :\

The code you're using probably has an additional routine that finds the day of the week. Maybe there is something in interdpth's code that does that. I didn't really look very hard.

2RandomStudios
November 30th, 2010, 08:18 AM
I understand how to insert it and all, but how would you actually use this in-game? Would you put a script on the berry tree? If so, what would the script be?
Thanks!

altariaking
November 30th, 2010, 08:27 AM
I understand how to insert it and all, but how would you actually use this in-game? Would you put a script on the berry tree? If so, what would the script be?
Thanks!

Yep, you would use a script, however, the script you would have to do yourself, as he said in the front post that he doesn't want anyone to give it away.

2RandomStudios
November 30th, 2010, 02:10 PM
Yep, you would use a script, however, the script you would have to do yourself, as he said in the front post that he doesn't want anyone to give it away.

Thanks, but I'm new to ROM hacking and don't have the first clue on what to put in the script. If you could PM me with a sample as to what I might do, that would be awesome. Thanks!

Elite Trainer Red
December 7th, 2010, 06:53 PM
Question does anyone have any idea about the pallete changing in the D&N?