;------------------------------------------------------------------------------------ ;Test 11 - DMA Fill to VRAM ;------------------------------------------------------------------------------------ TestDMAFillToVRAMText: dc.b 'DMA Fill to VRAM ' TestDMAFillToVRAMTextEnd: TestDMAFillToVRAMExpectedResult: dc.w $1234, $1212, $0012, $0000, $1234, $1212, $0012, $0000, $3412, $1212, $1212, $0000, $3412, $1212, $1212, $0000 dc.w $1234, $1212, $0012, $0000, $1200, $1234, $0012, $0012, $3412, $1212, $1212, $0000, $3400, $1212, $1212, $0012 dc.w $1234, $1212, $0012, $0000, $1200, $1234, $0012, $0012, $3412, $1212, $1212, $0000, $3412, $1212, $1212, $0012 dc.w $1234, $1212, $0012, $0000, $1200, $1234, $0012, $0012, $3412, $1212, $1212, $0000, $3400, $1212, $1212, $0012 dc.w $1234, $1212, $0012, $0000, $1200, $1234, $0012, $0012, $0000, $1234, $1212, $0000, $0000, $1200, $1234, $0012 dc.w $1234, $1212, $0012, $0000, $1234, $1234, $0012, $0012, $3412, $1212, $1212, $0000, $3400, $1212, $1212, $0012 dc.w $1234, $1212, $0012, $0000, $1234, $1234, $0012, $0012, $0000, $1234, $1212, $0000, $0000, $1200, $1234, $0012 dc.w $3412, $1212, $0012, $0000, $3412, $1212, $0012, $0012, $0000, $1234, $1212, $0000, $0000, $1200, $1234, $0012 dc.w $3412, $1212, $0012, $0000, $3412, $1212, $0012, $0012, $3412, $1212, $0012, $0000, $3400, $1212, $0012, $0012 dc.w $3412, $1212, $0012, $0000, $3400, $1212, $0012, $0012, $3412, $1212, $1212, $0000, $3400, $1212, $1212, $0012 dc.w $3412, $1212, $0012, $0000, $3400, $1212, $0012, $0012, $3412, $1212, $1212, $0000, $3412, $1212, $1212, $0012 TestDMAFillToVRAM: ;Initialize the text result block move.w #(TestDMAFillToVRAMTextEnd-TestDMAFillToVRAMText),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 TestDMAFillToVRAMText,A1 sub.w #1,D7 TestDMAFillToVRAMWriteText: move.b (A1)+,(A0)+ dbf D7,TestDMAFillToVRAMWriteText move.w #1,(A0)+ ;Set the expected result data present flag lea TestDMAFillToVRAMExpectedResult,A1 ;Write the expected result data to the buffer sub.w #1,D6 TestDMAFillToVRAMWriteExpectedResultData: move.b (A1)+,(A0)+ dbf D6,TestDMAFillToVRAMWriteExpectedResultData ;Clear data in VRAM at 0x8000 move.l #$40000002,$C00004 move.w #$0000,$C00000 move.w #$0000,$C00000 move.w #$0000,$C00000 move.w #$0000,$C00000 move.w #$0000,$C00000 move.w #$0000,$C00000 move.w #$0000,$C00000 move.w #$0000,$C00000 ;Do a DMA fill operation to VRAM address 0x8000 move.w #$0004,D1 move.w #$8F01,$C00004 move.w #$8154,$C00004 move.w #$9300, D2 move.b D1,D2 move.w D2,$C00004 move.w #$9400, D2 lsr.l #8,D1 move.b D1,D2 move.w D2,$C00004 move.w #$9780,$C00004 move.l #$40000082,(A0) ;DMA fill at VRAM address 0x8000 nop ;If we uncomment this block, we get corrupted write data at the start of the nop ;fill. If we don't have any wait cycles between the control port write and the nop ;data port write, the written data is usually correct, with the exception that nop ;the byte order of the first write is reversed. If we do insert wait states nop ;between the control port write and the data port write, without any wait states nop ;before the control port write, the fill starts with a fill data of 0x00, and at nop ;some point during the fill operation, usually 4 or 5 bytes in, the data port nop ;write then occurs, and the fill operation from then on picks up the correct fill nop ;data from that data port write. In other words, if we don't insert a wait state nop ;between when we set all our registers for a fill above, and when we actually nop ;perform the control port write to setup for the fill operation, the fill can nop ;inadvertantly trigger immediately when the control port write is made, without nop ;waiting for the data port write to occur. We have found from testing that at nop ;least 20 NOP cycles are required in order to get reliable results, when the nop ;control port write occurs as a long word write from RAM. nop nop nop nop nop move.l (A0),$C00004 move.w #$1234,$C00000 ;Start DMA fill with 0x1234 TestDMAFillToVRAMDMAWaitLoop1: move.w $C00004,D5 btst #1,D5 bne TestDMAFillToVRAMDMAWaitLoop1 move.w #$8144,$C00004 move.w #$8F02,$C00004 move.l #$00000002,$C00004 ;Read from VRAM at 0x8000 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 #$00010002,$C00004 ;Read from VRAM at 0x8001 nop ;Wait for a few cycles before reading from the data port, to avoid intermittent nop ;read errors when reading from odd VRAM addresses. Without this delay, the real nop ;hardware may return incomplete data, where the upper byte is correct, but the nop ;lower byte is set the same as the previously read data. Where back to back reads nop ;occur without a delay between any of them, this can result in a chain effect, nop ;where the lower byte of each subsequent read actually contains the contents of nop ;what the lower byte should have been from the previous read. This effect appears nop ;to only occur during active scan, when the full 16-bit value cannot be cached nop ;before the data port is read. Adding 24 NOP cycles before each read was not nop ;enough to make this stable. We only got consistently valid readings when 28 NOP nop ;cycles were added. nop nop nop nop nop nop nop nop nop nop nop nop nop nop nop nop nop move.w $C00000,(A0)+ nop ;Wait for a few cycles before reading from the data port, to avoid intermittent nop ;read errors when reading from odd VRAM addresses. Without this delay, the real nop ;hardware may return incomplete data, where the upper byte is correct, but the nop ;lower byte is set the same as the previously read data. Where back to back reads nop ;occur without a delay between any of them, this can result in a chain effect, nop ;where the lower byte of each subsequent read actually contains the contents of nop ;what the lower byte should have been from the previous read. This effect appears nop ;to only occur during active scan, when the full 16-bit value cannot be cached nop ;before the data port is read. Adding 24 NOP cycles before each read was not nop ;enough to make this stable. We only got consistently valid readings when 28 NOP nop ;cycles were added. nop nop nop nop nop nop nop nop nop nop nop nop nop nop nop nop nop move.w $C00000,(A0)+ nop ;Wait for a few cycles before reading from the data port, to avoid intermittent nop ;read errors when reading from odd VRAM addresses. Without this delay, the real nop ;hardware may return incomplete data, where the upper byte is correct, but the nop ;lower byte is set the same as the previously read data. Where back to back reads nop ;occur without a delay between any of them, this can result in a chain effect, nop ;where the lower byte of each subsequent read actually contains the contents of nop ;what the lower byte should have been from the previous read. This effect appears nop ;to only occur during active scan, when the full 16-bit value cannot be cached nop ;before the data port is read. Adding 24 NOP cycles before each read was not nop ;enough to make this stable. We only got consistently valid readings when 28 NOP nop ;cycles were added. nop nop nop nop nop nop nop nop nop nop nop nop nop nop nop nop nop move.w $C00000,(A0)+ nop ;Wait for a few cycles before reading from the data port, to avoid intermittent nop ;read errors when reading from odd VRAM addresses. Without this delay, the real nop ;hardware may return incomplete data, where the upper byte is correct, but the nop ;lower byte is set the same as the previously read data. Where back to back reads nop ;occur without a delay between any of them, this can result in a chain effect, nop ;where the lower byte of each subsequent read actually contains the contents of nop ;what the lower byte should have been from the previous read. This effect appears nop ;to only occur during active scan, when the full 16-bit value cannot be cached nop ;before the data port is read. Adding 24 NOP cycles before each read was not nop ;enough to make this stable. We only got consistently valid readings when 28 NOP nop ;cycles were added. nop nop nop nop nop nop nop nop nop nop nop nop nop nop nop nop nop 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 ;Clear data in VRAM at 0x8000 move.l #$40000002,$C00004 move.w #$0000,$C00000 move.w #$0000,$C00000 move.w #$0000,$C00000 move.w #$0000,$C00000 move.w #$0000,$C00000 move.w #$0000,$C00000 move.w #$0000,$C00000 move.w #$0000,$C00000 ;Do a DMA fill operation to VRAM address 0x8001 move.w #$0004,D1 move.w #$8F01,$C00004 move.w #$8154,$C00004 move.w #$9300, D2 move.b D1,D2 move.w D2,$C00004 move.w #$9400, D2 lsr.l #8,D1 move.b D1,D2 move.w D2,$C00004 move.w #$9780,$C00004 move.l #$40010082,(A0) ;DMA fill at VRAM address 0x8001 nop ;If we uncomment this block, we get corrupted write data at the start of the nop ;fill. If we don't have any wait cycles between the control port write and the nop ;data port write, the written data is usually correct, with the exception that nop ;the byte order of the first write is reversed. If we do insert wait states nop ;between the control port write and the data port write, without any wait states nop ;before the control port write, the fill starts with a fill data of 0x00, and at nop ;some point during the fill operation, usually 4 or 5 bytes in, the data port nop ;write then occurs, and the fill operation from then on picks up the correct fill nop ;data from that data port write. In other words, if we don't insert a wait state nop ;between when we set all our registers for a fill above, and when we actually nop ;perform the control port write to setup for the fill operation, the fill can nop ;inadvertantly trigger immediately when the control port write is made, without nop ;waiting for the data port write to occur. We have found from testing that at nop ;least 20 NOP cycles are required in order to get reliable results, when the nop ;control port write occurs as a long word write from RAM. nop nop nop nop nop move.l (A0),$C00004 move.w #$1234,$C00000 ;Start DMA fill with 0x1234 TestDMAFillToVRAMDMAWaitLoop2: move.w $C00004,D5 btst #1,D5 bne TestDMAFillToVRAMDMAWaitLoop2 move.w #$8144,$C00004 move.w #$8F02,$C00004 move.l #$00000002,$C00004 ;Read from VRAM at 0x8000 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 #$00010002,$C00004 ;Read from VRAM at 0x8001 nop ;Wait for a few cycles before reading from the data port, to avoid intermittent nop ;read errors when reading from odd VRAM addresses. Without this delay, the real nop ;hardware may return incomplete data, where the upper byte is correct, but the nop ;lower byte is set the same as the previously read data. Where back to back reads nop ;occur without a delay between any of them, this can result in a chain effect, nop ;where the lower byte of each subsequent read actually contains the contents of nop ;what the lower byte should have been from the previous read. This effect appears nop ;to only occur during active scan, when the full 16-bit value cannot be cached nop ;before the data port is read. Adding 24 NOP cycles before each read was not nop ;enough to make this stable. We only got consistently valid readings when 28 NOP nop ;cycles were added. nop nop nop nop nop nop nop nop nop nop nop nop nop nop nop nop nop move.w $C00000,(A0)+ nop ;Wait for a few cycles before reading from the data port, to avoid intermittent nop ;read errors when reading from odd VRAM addresses. Without this delay, the real nop ;hardware may return incomplete data, where the upper byte is correct, but the nop ;lower byte is set the same as the previously read data. Where back to back reads nop ;occur without a delay between any of them, this can result in a chain effect, nop ;where the lower byte of each subsequent read actually contains the contents of nop ;what the lower byte should have been from the previous read. This effect appears nop ;to only occur during active scan, when the full 16-bit value cannot be cached nop ;before the data port is read. Adding 24 NOP cycles before each read was not nop ;enough to make this stable. We only got consistently valid readings when 28 NOP nop ;cycles were added. nop nop nop nop nop nop nop nop nop nop nop nop nop nop nop nop nop move.w $C00000,(A0)+ nop ;Wait for a few cycles before reading from the data port, to avoid intermittent nop ;read errors when reading from odd VRAM addresses. Without this delay, the real nop ;hardware may return incomplete data, where the upper byte is correct, but the nop ;lower byte is set the same as the previously read data. Where back to back reads nop ;occur without a delay between any of them, this can result in a chain effect, nop ;where the lower byte of each subsequent read actually contains the contents of nop ;what the lower byte should have been from the previous read. This effect appears nop ;to only occur during active scan, when the full 16-bit value cannot be cached nop ;before the data port is read. Adding 24 NOP cycles before each read was not nop ;enough to make this stable. We only got consistently valid readings when 28 NOP nop ;cycles were added. nop nop nop nop nop nop nop nop nop nop nop nop nop nop nop nop nop move.w $C00000,(A0)+ nop ;Wait for a few cycles before reading from the data port, to avoid intermittent nop ;read errors when reading from odd VRAM addresses. Without this delay, the real nop ;hardware may return incomplete data, where the upper byte is correct, but the nop ;lower byte is set the same as the previously read data. Where back to back reads nop ;occur without a delay between any of them, this can result in a chain effect, nop ;where the lower byte of each subsequent read actually contains the contents of nop ;what the lower byte should have been from the previous read. This effect appears nop ;to only occur during active scan, when the full 16-bit value cannot be cached nop ;before the data port is read. Adding 24 NOP cycles before each read was not nop ;enough to make this stable. We only got consistently valid readings when 28 NOP nop ;cycles were added. nop nop nop nop nop nop nop nop nop nop nop nop nop nop nop nop nop 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 ;Clear data in VRAM at 0x8000 move.l #$40000002,$C00004 move.w #$0000,$C00000 move.w #$0000,$C00000 move.w #$0000,$C00000 move.w #$0000,$C00000 move.w #$0000,$C00000 move.w #$0000,$C00000 move.w #$0000,$C00000 move.w #$0000,$C00000 rts