jorgeche: I haven't touched gccVB in ages, and since then its gone an overhaul, so the following may not work right.
This is the timing code from my Zelda demo. I just tested the ROM in the latest (at least I think it is) copy of Reality Boy, and it seems to be running at the correct speed.
I actually used the ROM timer interrupt to increment a counter that I could then use to calculate the time. I'm not sure of the duration of the timer, but I think I have it set to 10x100uS (1mS).
// Timer Interrupt Handler
// Create a timed delay
void INTTIM()
{
asm("
di /* Disable interrupts */
add -4, r3 /* Increment sp by register size */
st.w r2, 0 [r3] /* Store the contents of r2 in sp */
movhi 0x0500, r0, r1 /* Put address of timer val in r1 */
movea 0x0008, r1, r1 /* */
ld.w 0 [r1], r2 /* Load timer value into r2 */
add 1, r2 /* Increment timer value by 1 */
st.w r2, 0 [r1] /* Store timer value back in ram */
ld.w 0 [r3], r2 /* Retrieve previous r2 from sp */
add 4, r3 /* Set sp back to previous value */
ld.w 0 [r3], r1 /* Retrieve previous r1 from sp */
add 4, r3 /* Set sp back to previous value */
ei /* Re-enable interrrupts */
reti /* Return from interrupt */
");
return;
}
// Timer Initialisation
// Create a timed delay
void InitTimer()
{
HW_REGS[THR] = 0x00; // THR, timer duration value high byte
HW_REGS[TLR] = 0x09; // TLR, timer duration value low byte
HW_REGS[TCR] = HW_REGS[TCR] & ~TIMER_20US; // T-Clk-Sel = 0, 100uS delay
HW_REGS[TCR] = HW_REGS[TCR] | TIMER_INT; // Tim-Z-Int = 1, enable interrupt
HW_REGS[TCR] = HW_REGS[TCR] | TIMER_ENB; // T-Enb = 1, turn on timer
return;
}
Hope this is some help. I haven't touched this since the early days (it was made just after the timer was figured out IIRC), so it probably doesn't work anymore.