;---------------------------------------------------------------------------------------- ; Test - Read Target switching ;-Description: ; This test does some basic bashing of the VDP control port relating to read operations. ; It is not exhaustive. This should probably be re-visited to make it do something more ; useful. ;##NOTE## This test has been seen to occasionally lock up on the hardware, as well as ;produce different results on each run. ;##NOTE## I have a theory, that there is a hardware bug in the VDP that occurs when ;switching from one read target to another read target. I suspect that if a valid read ;target has already been selected, and a data read pre-cached, and a write is then made ;to the VDP to switch to a new target, the flag that says that a data byte is available ;for read remains set, so that if a data port read is attempted before the new data from ;the new read target is actually pre-cached, a lockup can occur. The lock-up most likely ;occurs because the VDP thinks no data is available to return to the caller when another ;data port write occurs, and internally the VDP also thinks it doesn't need to pre-cache ;any more data. ;##NOTE## Our changes have been successful in making this test stable and reliable. A ;single NOP instruction before attempting a data port read seems to be sufficient to make ;read target switching stable. We still need to confirm if the wait is required before or ;after setting the read target however. ;---------------------------------------------------------------------------------------- TestReadTargetSwitchingText: dc.b 'Read target switching ' TestReadTargetSwitchingTextEnd: TestReadTargetSwitchingExpectedResult: dc.w $3000, $3000, $3000, $3000, $3000, $3000, $3000, $3000, $3000, $3000, $2222, $3333, $3000, $3000, $3000, $3000 TestReadTargetSwitching: ;Initialize the text result block move.w #(TestReadTargetSwitchingTextEnd-TestReadTargetSwitchingText),D7 move.w #2,(A0)+ ;Set the number of display lines move.w D7,(A0)+ ;Set the text length move.w #$0020,D6 ;Set the data length move.w D6,(A0)+ lea TestReadTargetSwitchingText,A1 sub.w #1,D7 TestReadTargetSwitchingWriteText: move.b (A1)+,(A0)+ dbf D7,TestReadTargetSwitchingWriteText move.w #1,(A0)+ ;Set the expected result data present flag lea TestReadTargetSwitchingExpectedResult,A1 ;Write the expected result data to the buffer sub.w #1,D6 TestReadTargetSwitchingWriteExpectedResultData: move.b (A1)+,(A0)+ dbf D6,TestReadTargetSwitchingWriteExpectedResultData ;Fill the FIFO buffer with some writes to VRAM at 0x8000 move.l #$40000002,$C00004 move.w #$1111,$C00000 move.w #$2222,$C00000 move.w #$3333,$C00000 move.w #$4444,$C00000 move.w #$5555,$C00000 move.w #$6666,$C00000 ;Try invalid writes mixed with reads move.l #$00000010,$C00004 ;Read from VSRAM move.w $C00000,(A0)+ move.w $C00000,(A0)+ nop ;Wait for a few cycles after a read before modifying any VDP settings. On the nop ;real hardware, if a control port write occurs immediately after a data port nop ;read, the VDP can lock up. Most likely, this occurs due to the read target nop ;being modified to an invalid target before a read pre-cache is complete. nop nop nop nop nop nop move.l #$00000000,$C00004 ;Read from VRAM move.l #$00000000,$C00004 ;Read from VRAM move.l #$00000000,$C00004 ;Read from VRAM move.l #$00000000,$C00004 ;Read from VRAM move.l #$00000010,$C00004 ;Read from VSRAM ;##NOTE## Has been seen to read back 0x3300! Note that this occurs even if a delay is ;introduced between the VRAM and VSRAM read target switching above. The correct value ;is only guaranteed to be returned if we insert a delay between setting the read ;target and reading from the data port. ;##TODO## Do more testing on this behaviour to figure out what could be causing it. ;At least 12 NOP cycles are required to get consistent results. nop nop nop nop nop nop nop nop nop nop nop nop move.w $C00000,(A0)+ move.w $C00000,(A0)+ nop ;Wait for a few cycles after a read before modifying any VDP settings. On the nop ;real hardware, if a control port write occurs immediately after a data port nop ;read, the VDP can lock up. Most likely, this occurs due to the read target nop ;being modified to an invalid target before a read pre-cache is complete. nop nop nop nop nop nop move.l #$00000020,$C00004 ;Read from CRAM move.l #$00000000,$C00004 ;Read from VRAM move.l #$00000010,$C00004 ;Read from VSRAM move.l #$00000020,$C00004 ;Read from CRAM move.l #$00000000,$C00004 ;Read from VRAM move.l #$00000010,$C00004 ;Read from VSRAM nop nop nop nop nop nop nop nop nop nop nop nop move.w $C00000,(A0)+ ;##NOTE## Has been seen to read back 0x3300! move.w $C00000,(A0)+ nop ;Wait for a few cycles after a read before modifying any VDP settings. On the nop ;real hardware, if a control port write occurs immediately after a data port nop ;read, the VDP can lock up. Most likely, this occurs due to the read target nop ;being modified to an invalid target before a read pre-cache is complete. nop nop nop nop nop nop move.l #$40000002,$C00004 ;Write to VRAM at 0x8000 move.w #$0000,$C00004 ;Partial write to change to read from VRAM at 0x8000 ;Note that we used to have a delay block here move.w #$0010,$C00004 ;Completed write to change to read from VSRAM move.w $C00000,(A0)+ move.w $C00000,(A0)+ move.w $C00000,(A0)+ move.w $C00000,(A0)+ nop ;Wait for a few cycles after a read before modifying any VDP settings. On the nop ;real hardware, if a control port write occurs immediately after a data port nop ;read, the VDP can lock up. Most likely, this occurs due to the read target nop ;being modified to an invalid target before a read pre-cache is complete. nop nop nop nop nop nop move.l #$00020002,$C00004 ;Read from VRAM at 0x8002 move.w $C00000,(A0)+ move.w $C00000,(A0)+ nop ;Wait for a few cycles after a read before modifying any VDP settings. On the nop ;real hardware, if a control port write occurs immediately after a data port nop ;read, the VDP can lock up. Most likely, this occurs due to the read target nop ;being modified to an invalid target before a read pre-cache is complete. nop nop nop nop nop nop move.l #$00000010,$C00004 ;Read from VSRAM move.w $C00000,(A0)+ move.w $C00000,(A0)+ nop ;Wait for a few cycles after a read before modifying any VDP settings. On the nop ;real hardware, if a control port write occurs immediately after a data port nop ;read, the VDP can lock up. Most likely, this occurs due to the read target nop ;being modified to an invalid target before a read pre-cache is complete. nop nop nop nop nop nop move.l #$00000010,$C00004 ;Read from VSRAM move.w $C00000,(A0)+ move.w $C00000,(A0)+ nop ;Wait for a few cycles after a read before modifying any VDP settings. On the nop ;real hardware, if a control port write occurs immediately after a data port nop ;read, the VDP can lock up. Most likely, this occurs due to the read target nop ;being modified to an invalid target before a read pre-cache is complete. nop nop nop nop nop nop rts