nocrew / ostis

Atari ST Emulator
GNU Lesser General Public License v2.1
20 stars 4 forks source link

Level 16 Full Screen Demo #120

Closed larsbrinkhoff closed 8 years ago

larsbrinkhoff commented 8 years ago

There is a problem in the Level 16 Full Screen Demo, in the first few seconds when it plays a sample.

Debugging the code shows that it writes to the PSG using three MOVE.L instructions:

MOVE.L (A1)+,(A4)
MOVE.L (A1)+,(A4)
MOVE.L (A1)+,(A4)

A4 is set to FFFF8800.

Currently, there is a 2-cycle delay added for each access to the PSG. Each instruction does two accesses, to there are four cycles added. A normal MOVE.L would take 20 cycles; these take 24.

Running the demo displays a shift. Supposedly 72 cycles for the three moves are too much. Random trial and error shows that 68 cycles is the right amount for the demo to run correctly.

larsbrinkhoff commented 8 years ago

More context around the moves:

MOVE.W (A2)+,D1      ;  8 / A2 = RAM
LEA (A3,D1.W),A1     ; 12 / A3 = RAM
MOVE.L (A1)+,(A4)    ; 20 / A1 = RAM
MOVE.L (A1)+,(A4)    ; 20 / A4 = FFFF8800
MOVE.L (A1)+,(A4)    ; 20
CMP.L A2,D0          ;  6
BNE.S ...            ; 10 / taken

The numbers are cycle times without any added delays or wait states.

One theory is that there is a four-cycle delay on all MOVE.L instructions. Comments in the hatari source code supports this. But that the CMP pairs with the BNE, so that four cycles goes away.

larsbrinkhoff commented 8 years ago

The Yacht table confirms that CMP should pair with BNE. CMP does its prefetch first, and BNE does two prefetch cycles last.

larsbrinkhoff commented 8 years ago

Fixed by #123.