Movatterモバイル変換


[0]ホーム

URL:


Pan Docs

    Timer obscure behaviour

    System counter

    DIV is just the visible part of thesystem counter.

    Thesystem counter is constantly incrementing every M-cycle, unless the CPU is inSTOP mode.

    Timer Global Circuit

    7654321070KEY1DoubleSpeedModeactive?DIVResetWriteto DIVIncrementM-cycleclock10FallingedgedetectorDIV-APUeventSee detailedschematic210TACTAC.freqTAC.enableTimertickSeedetailedschematicTMATIMALoadInc.Overflow43210IFInterrupt request

    Relation between Timer and Divider register

    This is a schematic of the circuit involving TAC and DIV:

    OnDMG:

    76543210DIVResetWriteto DIVIncrementM-cycleclock0321210TACTAC.freqTAC.enableANDFallingedgedetectorTimertick

    OnCGB:

    76543210DIVResetWriteto DIVIncrementM-cycleclock0321210TACTAC.freqTAC.enableFallingedgedetectorANDTimertick

    Notice how the bits themselves are connected to the multiplexer and then to the falling-edge detector; this causes a few odd behaviors:

    • Resetting the entire system counter (by writing toDIV) can reset the bit currently selected by the multiplexer, thus sending a “Timer tick” and/or “DIV-APU event” pulse early.
    • Changing which bit of the system counter is selected (by changing the “Clock select” bits ofTAC) from a bit currently set to another that is currently unset, will send a “Timer tick” pulse.(For example: if the system counter is equal to $3FF0 andTAC to $FC, writing $05 or $06 toTAC will instantly send a “Timer tick”, but $04 or $07 won’t.)
    • On monochrome consoles, disabling the timer if the currently selected bit is set, will send a “Timer tick” once.This does not happen on Color models.
    • On Color models, a write toTAC that fulfills the previous bullet’s conditionsand turns the timer on (it was disabled before) may or may not send a “Timer tick”.The exact behaviour varies between individual consoles.

    Timer overflow behavior

    WhenTIMA overflows, the value fromTMA is copied, and the timer flag is set inIF, butone M-cycle later.This means thatTIMA is equal to $00 for the M-cycle after it overflows.

    This only happens whenTIMA overflows from incrementing, it cannot be made to happen by manually writing toTIMA.

    Here is an example;SYS represents the lower 8 bits of the system counter, andTAC is $FD (timer enabled, bit 1 ofSYS selected as source):

    TIMA overflows on cycleA, but the interrupt is only requested on cycleB:

    M-cycleAB
    SYS2B2C2D2E2F3031
    TIMAFEFFFF00232424
    TMA23232323232323
    IFE0E0E0E0E4E4E4

    Here are some unexpected behaviors:

    1. Writing toTIMA during cycleA acts as if the overflowdidn’t happen!TMA will not be copied toTIMA (the value written will therefore stay), and bit 2 ofIF will not be set.Writing toDIV,TAC, or other registers won’t prevent theIF flag from being set orTIMA from being reloaded.
    2. Writing toTIMA during cycleB will be ignored;TIMA will be equal toTMA at the end of the cycle anyway.
    3. Writing toTMA during cycleB will have the same value copied toTIMA as well, on the same cycle.

    Here is howTIMA andTMA interact:

    76543210TMAWriteto TMALoadCPU data bus01TIMATimertickIncrementFallingedgedetectorWrite toTIMANOTANDDelaySet43210IFORLoad
    Explanation of the above behaviors:
    1. Writing toTIMA blocks the falling edge from the increment from being detected (see theAND gate)1.
    2. The “Load” signal stays enabled for the entirety of cycleB, and sinceTIMA is made ofTAL cells, it’s constantly copying its input.However, the “Write to TIMA” signal gets reset in the middle of the cycle, thus the multiplexer emitsTMA’s value again; in essence, the CPU’s write toTIMAdoes go through, but it’s overwritten right after.
    3. As mentioned in the previous bullet point,TIMA constantly copies its input, so it updates together withTMA.This and the previous bullet point can be emulated as ifTMA was copied toTIMA at the very end of the cycle, though this is not quite what’s happening in hardware.

    [8]ページ先頭

    ©2009-2026 Movatter.jp