Timer interrupt: Difference between revisions

From NeoGeo Development Wiki
Jump to navigation Jump to search
(Copypasta from official doc)
 
(Neo Turf Masters example)
 
(5 intermediate revisions by the same user not shown)
Line 1: Line 1:
[[68k vector table|Vector address]] on cart systems: $68. On CD systems: $64.
The timer interrupt is a [[68k interrupts|68k interrupt]] triggered when the 32-bit down-counter internal to [[LSPC]] reaches 0. As it is synchronous with the video output, it is mainly used for [[scanline effects]].


This [[68k interrupts|interrupt]] is triggered when the 32bit timer counter reaches 0 (is this timer completly internal to the LSPC ?).
=Mode of operation=
The value of this counter is decremented by the [[Clock|pixel clock]] (every 166.7ns), and reloaded with the specified value in REG_TIMERHIGH ($3C0008) and REG_TIMERLOW ($3C000A) each time one of these 3 selectable events occur:


* When REG_TIMERLOW register is set.
The value of this counter is decremented by the [[Clock|pixel clock]], which runs at 6MHz (166.7ns period). It is automatically reloaded with the value specified in {{Reg|REG_TIMERHIGH}} and {{Reg|REG_TIMERLOW}} each time one of these 3 selectable events occur:
* At the beginning of the frame blanking period.
* When the timer counter reaches 0.


This interrupt needs to be acknowledged by the following instruction:
* Immediately when {{Reg|REG_TIMERLOW}} register is written to.
<pre>
* At the beginning of the frame blanking period (one-shot).
M0VE.W    #2,$3C000C
* When the counter reaches 0 (repeat).
</pre>


The REG_LSPCMODE ($3C0006.w) register is used to configure the timer's operation:
=Range=


*Bit 7 = 1: Load timer counter when it becomes 0.
* Minimum time ($00000000): 166.7ns, corresponds to 1 pixel, useless, see below.
*Bit 6 = 1: Load timer counter at the beginning of the HBlank of the first VBlank line.
* Maximum time ($FFFFFFFF): 715.8s, corresponds to 42366 frames, or 11.9 minutes.
*Bit 5 = 1: Load timer counter as soon as REG_TIMERLOW is written to.
*Bit 4 = 1: Enable timer interrupt.


REG_TIMERHIGH and REG_TIMERLOW registers should never be set to 0.
=[[68k vector table|Vector address]]=
* Cartridge systems: $68 (IRQ2)
* CD systems: $64 (IRQ1)
 
Like other interrupts, this one needs to be acknowledged with {{Reg|REG_IRQACK}} to trigger again.
 
=Configuration=
 
The {{Reg|REG_LSPCMODE}} register is used to configure the timer's operation:
 
* Bit 4 = 1: Enable timer interrupt.
* Bit 5 = 1: Reload counter as soon as {{Reg|REG_TIMERLOW}} is written to.
* Bit 6 = 1: Reload counter at the beginning of the hblank of the first vblank line (start of each frame).
* Bit 7 = 1: Reload counter when it reaches 0.
 
'''Caution''': When the timer interrupt is enabled, the value of {{Reg|REG_TIMERHIGH}} and {{Reg|REG_TIMERLOW}} should always be set higher than 4, or the [[68k]] will get flooded with interrupts and program execution will lock up.
 
=Example: [[Neo Turf Masters]]=
 
[[File:Timer_turfmast.png]]
 
* A: First line of the frame. The timer is reloaded with the value set at C: 41016. The next interrupt will trigger at B, in 106 lines and 313 pixels (just before the 107th line). The scroll value for the mountains is set.
* B: Start of the ground area. The timer is immediately reloaded to 767 and the mode is set to "reload when 0 is reached". This will trigger interrupts every 2 lines so that the ground can be shifted to produce the perspective effect. A variable is used to count the number of ground lines.
* C: End of the ground area. When enough ground lines are rendered, the timer is immediately reloaded to 16383 so that the next interrupt won't happen soon. The mode is set to "reload on first line of next frame" and the reload value (not the timer !) is set to 41016.


To trigger interrupts for every N pixels, set the timer registers to N-1, and set bits 4 and 7 of REG_LSPCMODE.


To trigger interrupts when the scanning reaches multiple arbitrary display locations, set bits 4, 5 and 7 of REG_LSPCMODE. Then, in the interrupt handler routine, set the interval between the next interrupt and the following in the timer registers.


[[Category:Base system]]
[[Category:Base system]]
[[Category:Video system]]

Latest revision as of 08:24, 24 March 2019

The timer interrupt is a 68k interrupt triggered when the 32-bit down-counter internal to LSPC reaches 0. As it is synchronous with the video output, it is mainly used for scanline effects.

Mode of operation

The value of this counter is decremented by the pixel clock, which runs at 6MHz (166.7ns period). It is automatically reloaded with the value specified in REG_TIMERHIGH and REG_TIMERLOW each time one of these 3 selectable events occur:

  • Immediately when REG_TIMERLOW register is written to.
  • At the beginning of the frame blanking period (one-shot).
  • When the counter reaches 0 (repeat).

Range

  • Minimum time ($00000000): 166.7ns, corresponds to 1 pixel, useless, see below.
  • Maximum time ($FFFFFFFF): 715.8s, corresponds to 42366 frames, or 11.9 minutes.

Vector address

  • Cartridge systems: $68 (IRQ2)
  • CD systems: $64 (IRQ1)

Like other interrupts, this one needs to be acknowledged with REG_IRQACK to trigger again.

Configuration

The REG_LSPCMODE register is used to configure the timer's operation:

  • Bit 4 = 1: Enable timer interrupt.
  • Bit 5 = 1: Reload counter as soon as REG_TIMERLOW is written to.
  • Bit 6 = 1: Reload counter at the beginning of the hblank of the first vblank line (start of each frame).
  • Bit 7 = 1: Reload counter when it reaches 0.

Caution: When the timer interrupt is enabled, the value of REG_TIMERHIGH and REG_TIMERLOW should always be set higher than 4, or the 68k will get flooded with interrupts and program execution will lock up.

Example: Neo Turf Masters

  • A: First line of the frame. The timer is reloaded with the value set at C: 41016. The next interrupt will trigger at B, in 106 lines and 313 pixels (just before the 107th line). The scroll value for the mountains is set.
  • B: Start of the ground area. The timer is immediately reloaded to 767 and the mode is set to "reload when 0 is reached". This will trigger interrupts every 2 lines so that the ground can be shifted to produce the perspective effect. A variable is used to count the number of ground lines.
  • C: End of the ground area. When enough ground lines are rendered, the timer is immediately reloaded to 16383 so that the next interrupt won't happen soon. The mode is set to "reload on first line of next frame" and the reload value (not the timer !) is set to 41016.