;---------------------------------------------------------------------------------------- ; Test - Write to invalid target ;-Description: ; The purpose of this test is to demonstrate that performing a write to an invalid VDP ; write target still results in the written data being stored in the FIFO, and causes the ; FIFO to be advanced one step. ;-Expected result: ; 3000 3000 4000 4000 5000 5000 6000 6000 ; 3000 3000 4000 4000 E800 5000 6000 6000 C800 F800 E800 E800 A800 D800 C800 C800 ; 3000 3000 4000 4000 5000 5000 6000 6000 F800 F800 E800 E800 D800 D800 C800 C800 ;##FIX## We end up getting the values of 0x1000 out first, because at the point where ;we're switching to a read from VSRAM, we end up setting up a valid VRAM read target ;from 0x8000 before the second command word gets written. It may actually be that the ;real VDP does this too, since our above test indicates that reads may in fact not ;modify the FIFO. Do more hardware tests to confirm the real behaviour of the system. ;##NOTE## We no longer get the value of 0x1000 out first, because some fixes in our ;implementation now means that if a write is made to the control port while a read ;cache operation is pending but not yet performed, the write will occur without ;waiting for the read. This has the effect of fully writing the new command word ;before the read is able to occur. We need to do tests on the hardware to confirm ;exactly how and when read caching occurs, relative to other operations, and whether ;a control port write is delayed until it is complete. ;##NOTE## Doing the invalid write followed by a read back to back sometimes results ;in the read data being combined with the invalid write data instead of the previous ;entry in the FIFO. Since it always seems to be the first read in the pair that is ;affected, with the second read being correct, I would suspect then that this is a ;case of the read data being combined with the last read data value. Internally, ;there must be a 4-word write FIFO, which is completely separate from the buffered ;read data, and there must be a 1-word read buffer. There must also be a 1-word ;register, into which data reads and writes move through. Written data is stored in ;this register before being added to the FIFO. When doing a data read, the read data ;is loaded into this register, with unset bits in the source of the read remaining ;unchanged, with this register then being saved into the read buffer. Additionally, ;the VDP must be, for some reason, reading the next available entry in the FIFO ;regularly. This is almost certainly done as part of the normal update process, to ;check if a write is sitting in the FIFO. There must be a boolean flag or the like ;stored a part of the FIFO, which records whether the data has been written yet, and ;the FIFO data is being read each update step to see if there is unwritten data in ;the FIFO. If a data read immediately follows a data write, the read data will be ;combined with the previously written data, since that data is still in the internal ;data register. If a read does not immediately follow a write, the read data will be ;combined with the contents of the next available entry in the FIFO, since that will ;still be in the internal data register. ;##NOTE## Testing has confirmed that when a read gets combined with a write, it ;doesn't matter how long after the write the read actually occurs. When the data is ;combined, it stays combined. ;##NOTE## Testing has shown that sometimes a read following an invalid write causes ;the system to lock up. Not sure why yet. One point of speculation is that the ;overlapping read and write operations possibly cause some kind of a muck-up with ;the FIFO, where the FIFO is advanced without the data being written out. In this ;case, if there is a flag in each FIFO entry recording whether the write has been ;processed, this could result in a case where the FIFO reads as both full and empty ;at the same time, since the next entry in the FIFO reads as processed, but the last ;entry in the FIFO reads as unprocessed. This is pure speculation though. It is also ;possible the problem is on the reverse, and that it's caused by an invalid write ;immediately following a read. I can't see why this would be the case though. ;##NOTE## We've had a complete rethink of the combining behaviour of an overlapped ;read and write. It seems now that the most likely explination of what is occurring ;is that while a read is actually occurring, the contents of the next entry in the ;FIFO are modified by the write operation. Since a write should never actually be ;performed when a read target is setup, this overlap should never be a problem in ;real code, but in our tests, when performing a write to a read target, we can get ;this case occurring. The FIFO is written to directly by the caller, and this is ;completely unsynchronized with the current internal operation cycle of the VDP, so ;empty FIFO buffer contents can potentially change at any moment. Obviously, there is ;some potential problem that can occur when a read operation is being performed when ;a write occurs. We need to try and figure out what the cause of this problem is. ;##NOTE## We now have this test working in a stable state, but we needed to reset the ;read target after performing an invalid write. For some reason, performing a data port ;write with a read target set seems to invalidate the read target, so that it can no ;longer be read from. ;---------------------------------------------------------------------------------------- TestFIFOWriteToInvalidTargetText: dc.b 'FIFO Write to invalid target ' TestFIFOWriteToInvalidTargetTextEnd: TestFIFOWriteToInvalidTargetExpectedResult: dc.w $1000, $1000, $2000, $2000, $3000, $3000, $4000, $4000, $F800, $F800, $E800, $E800, $D800, $D800, $C800, $C800 TestFIFOWriteToInvalidTarget: ;Initialize the text result block move.w #(TestFIFOWriteToInvalidTargetTextEnd-TestFIFOWriteToInvalidTargetText),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 TestFIFOWriteToInvalidTargetText,A1 sub.w #1,D7 TestFIFOWriteToInvalidTargetWriteText: move.b (A1)+,(A0)+ dbf D7,TestFIFOWriteToInvalidTargetWriteText move.w #1,(A0)+ ;Set the expected result data present flag lea TestFIFOWriteToInvalidTargetExpectedResult,A1 ;Write the expected result data to the buffer sub.w #1,D6 TestFIFOWriteToInvalidTargetWriteExpectedResultData: move.b (A1)+,(A0)+ dbf D6,TestFIFOWriteToInvalidTargetWriteExpectedResultData ;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 ; ;##FIX## The following code segment often locks up on hardware. Test putting a delay ; between the first read operations, and the write operation. I suspect the problem ; only occurs when the read data is not fully buffered when the write occurs, which ; should only happen during active scan. Since the lock-up actually occurs at read time ; the problem might be caused by the write clearing some internal data that reports ; that a data byte is available for read from the control port, while some different ; internal data tells the VDP a data byte has been buffered, so the VDP doesn't fetch ; another data value, but a control port read results in the caller waiting forever for ; a new value to be read. ; move.l #$00000010,$C00004 ;Read from VSRAM ; move.w $C00000,(A0)+ ; move.w $C00000,(A0)+ ; move.w #$9999,$C00000 ;Write to invalid target ; ;##NOTE## This doesn't seem to make any difference ; nop ;Ensure that the written data isn't still in the internal register for the read ; nop ; nop ; nop ; nop ; move.w $C00000,(A0)+ ; move.w $C00000,(A0)+ ;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.w #$FFFF,$C00000 ;Write to an invalid target 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.w #$EEEE,$C00000 ;Write to an invalid target 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.w #$DDDD,$C00000 ;Write to an invalid target 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.w #$CCCC,$C00000 ;Write to an invalid target 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.w #$BBBB,$C00000 ;Write to an invalid target 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.w #$AAAA,$C00000 ;Write to an invalid target 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.w #$9999,$C00000 ;Write to an invalid target 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