;------------------------------------------------------------------------------------ TestDMAFillControlPortWritesDataBlock: dc.w $1234, $5678, $9ABC, $DEF0 TestDMAFillControlPortWritesText: dc.b 'DMA Fill Control Port Writes ' TestDMAFillControlPortWritesTextEnd: TestDMAFillControlPortWritesExpectedResult: dc.w $1122, $68AC, $6868, $6868, $9968, $BBCC, $DDEE, $FF00, $1122, $68AC, $6868, $6868, $9968, $BBCC, $DDEE, $FF00 dc.w $1122, $3344, $5566, $7788, $99AA, $BBCC, $DDEE, $FF00, $6868, $6868, $6868, $6868, $6868, $6868, $6868, $6868 dc.w $1122, $68AC, $5568, $7768, $9968, $BB68, $DDEE, $FF00, $1122, $68AC, $5566, $68AC, $99AA, $BBCC, $DDEE, $FF00 dc.w $1122, $68AC, $5568, $7768, $9968, $BB68, $DDEE, $FF00, $1122, $68AC, $5566, $68AC, $99AA, $BBCC, $DDEE, $FF00 dc.w $1122, $3344, $5566, $7788, $68AC, $BB68, $DD68, $FF68, $1168, $3344, $5566, $7788, $99AA, $BBCC, $DDEE, $FF00 TestDMAFillControlPortWrites: ;Initialize the text result block move.w #(TestDMAFillControlPortWritesTextEnd-TestDMAFillControlPortWritesText),D7 move.w #6,(A0)+ ;Set the number of display lines move.w D7,(A0)+ ;Set the text length move.w #$00A0,D6 ;Set the data length move.w D6,(A0)+ lea TestDMAFillControlPortWritesText,A1 sub.w #1,D7 TestDMAFillControlPortWritesWriteText: move.b (A1)+,(A0)+ dbf D7,TestDMAFillControlPortWritesWriteText move.w #1,(A0)+ ;Set the expected result data present flag lea TestDMAFillControlPortWritesExpectedResult,A1 ;Write the expected result data to the buffer sub.w #1,D6 TestDMAFillControlPortWritesWriteExpectedResultData: move.b (A1)+,(A0)+ dbf D6,TestDMAFillControlPortWritesWriteExpectedResultData ;Initialize VRAM move.l #$40000002,$C00004 move.w #$1122,$C00000 move.w #$3344,$C00000 move.w #$5566,$C00000 move.w #$7788,$C00000 move.w #$99AA,$C00000 move.w #$BBCC,$C00000 move.w #$DDEE,$C00000 move.w #$FF00,$C00000 ;Do a DMA fill operation to VRAM address 0x8002 move.w #$0006,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 ;Wait for the write FIFO to be empty before initiating the DMA fill, otherwise the ;fill operation will trigger immediately using whatever write data is already setup ;in the FIFO. TestDMAFillControlPortWritesWaitFIFOEmpty1: move.w $C00004,D7 btst #9,D7 beq TestDMAFillControlPortWritesWaitFIFOEmpty1 ;Write the DMA fill command words to the control port, then do a partial control port ;write to re-write the first command word over again. This should execute the DMA ;fill operation. move.l #$40020082,$C00004 ;DMA fill at VRAM address 0x8002 move.w #$4002,$C00004 ;DMA fill at VRAM address 0x8002 move.w #$68AC,$C00000 ;Start DMA fill with 0x68AC TestDMAFillControlPortWritesDMAWaitLoop1: move.w $C00004,D7 btst #1,D7 bne TestDMAFillControlPortWritesDMAWaitLoop1 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)+ 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 ;Initialize VRAM move.l #$40000002,$C00004 move.w #$1122,$C00000 move.w #$3344,$C00000 move.w #$5566,$C00000 move.w #$7788,$C00000 move.w #$99AA,$C00000 move.w #$BBCC,$C00000 move.w #$DDEE,$C00000 move.w #$FF00,$C00000 ;Do a DMA fill operation to VRAM address 0x8002 move.w #$0006,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 ;Wait for the write FIFO to be empty before initiating the DMA fill, otherwise the ;fill operation will trigger immediately using whatever write data is already setup ;in the FIFO. TestDMAFillControlPortWritesWaitFIFOEmpty2: move.w $C00004,D7 btst #9,D7 beq TestDMAFillControlPortWritesWaitFIFOEmpty2 ;Write the DMA fill command words to the control port, then do a partial control port ;write to write a new first command word. This should execute a DMA fill operation ;using the data from the new first command word. move.l #$40000082,$C00004 ;DMA fill at VRAM address 0x8000 move.w #$4002,$C00004 ;DMA fill at VRAM address 0x8002 move.w #$68AC,$C00000 ;Start DMA fill with 0x68AC TestDMAFillControlPortWritesDMAWaitLoop2: move.w $C00004,D7 btst #1,D7 bne TestDMAFillControlPortWritesDMAWaitLoop2 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)+ 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 ;Initialize VRAM move.l #$40000002,$C00004 move.w #$1122,$C00000 move.w #$3344,$C00000 move.w #$5566,$C00000 move.w #$7788,$C00000 move.w #$99AA,$C00000 move.w #$BBCC,$C00000 move.w #$DDEE,$C00000 move.w #$FF00,$C00000 move.w #$1122,$C00000 move.w #$3344,$C00000 move.w #$5566,$C00000 move.w #$7788,$C00000 move.w #$99AA,$C00000 move.w #$BBCC,$C00000 move.w #$DDEE,$C00000 move.w #$FF00,$C00000 ;Do a DMA fill operation to VRAM address 0x8002 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 ;Wait for the write FIFO to be empty before initiating the DMA fill, otherwise the ;fill operation will trigger immediately using whatever write data is already setup ;in the FIFO. TestDMAFillControlPortWritesWaitFIFOEmpty3: move.w $C00004,D7 btst #9,D7 beq TestDMAFillControlPortWritesWaitFIFOEmpty3 ;Test a register write after setting up a DMA fill operation. This will set the DMA ;fill write target to an invalid write target, causing the actual writes to be ;discarded, but the actual DMA fill operation will still execute, which we test by ;performing another DMA fill operation below without updating the DMA transfer count. move.l #$40020082,$C00004 ;DMA fill at VRAM address 0x8002 move.w #$8F02,$C00004 ;Register write setting increment data to 2 move.w #$68AC,$C00000 ;Start DMA fill with 0x68AC TestDMAFillControlPortWritesDMAWaitLoop3: move.w $C00004,D7 btst #1,D7 bne TestDMAFillControlPortWritesDMAWaitLoop3 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)+ 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.w #$8F01,$C00004 move.w #$8154,$C00004 move.l #$40040082,$C00004 ;DMA fill at VRAM address 0x8004 move.w #$68AC,$C00000 ;Start DMA fill with 0x68AC TestDMAFillControlPortWritesDMAWaitLoop31: move.w $C00004,D7 btst #1,D7 bne TestDMAFillControlPortWritesDMAWaitLoop31 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)+ 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 ;Initialize VRAM move.l #$40000002,$C00004 move.w #$1122,$C00000 move.w #$3344,$C00000 move.w #$5566,$C00000 move.w #$7788,$C00000 move.w #$99AA,$C00000 move.w #$BBCC,$C00000 move.w #$DDEE,$C00000 move.w #$FF00,$C00000 move.w #$1122,$C00000 move.w #$3344,$C00000 move.w #$5566,$C00000 move.w #$7788,$C00000 move.w #$99AA,$C00000 move.w #$BBCC,$C00000 move.w #$DDEE,$C00000 move.w #$FF00,$C00000 ;Do a DMA fill operation to VRAM address 0x8002 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 ;Wait for the write FIFO to be empty before initiating the DMA fill, otherwise the ;fill operation will trigger immediately using whatever write data is already setup ;in the FIFO. TestDMAFillControlPortWritesWaitFIFOEmpty4: move.w $C00004,D7 btst #9,D7 beq TestDMAFillControlPortWritesWaitFIFOEmpty4 ;Setup a DMA fill operation and write the command words to initiate it, but before we ;write the fill data to the data port, perform a register write to disable DMA, then ;re-write the first DMA fill command word, and perform the triggering data port ;write. This will perform the DMA fill operation as normal. It appears that the ;status of the DMA enable bit is checked at the time the second command word is ;written, not when the fill data is written, so if CD5 has already successfully been ;set, the DMA operation is triggered regardless of the DMA enable state. move.l #$40020082,$C00004 ;DMA fill at VRAM address 0x8002 move.w #$8144,$C00004 move.w #$8F02,$C00004 move.w #$4002,$C00004 ;DMA fill at VRAM address 0x8002 move.w #$68AC,$C00000 ;Start DMA fill with 0x68AC move.w #$7FFF,D1 TestDMAFillControlPortWritesDMAWaitLoop4: dbf D1,TestDMAFillControlPortWritesDMAWaitLoop4 ;This should fail, since the DMA fill operation has now completed, so CD5 has been ;cleared. move.w #$4012,$C00004 ;DMA fill at VRAM address 0x8012 move.w #$68AC,$C00000 ;Start DMA fill with 0x68AC TestDMAFillControlPortWritesDMAWaitLoop41: move.w $C00004,D7 btst #1,D7 bne TestDMAFillControlPortWritesDMAWaitLoop41 ;This should fail too as we cannot set CD5 through a control port right now, since ;DMA is disabled. move.l #$40160082,$C00004 ;DMA fill at VRAM address 0x8016 move.w #$68AC,$C00000 ;Start DMA fill with 0x68AC TestDMAFillControlPortWritesDMAWaitLoop42: move.w $C00004,D7 btst #1,D7 bne TestDMAFillControlPortWritesDMAWaitLoop42 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)+ move.w $C00000,(A0)+ move.w $C00000,(A0)+ move.w $C00000,(A0)+ move.w $C00000,(A0)+ move.w $C00000,(A0)+ move.w $C00000,(A0)+ move.w $C00000,(A0)+ move.w $C00000,(A0)+ 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 ;Initialize VRAM move.l #$40000002,$C00004 move.w #$1122,$C00000 move.w #$3344,$C00000 move.w #$5566,$C00000 move.w #$7788,$C00000 move.w #$99AA,$C00000 move.w #$BBCC,$C00000 move.w #$DDEE,$C00000 move.w #$FF00,$C00000 move.w #$1122,$C00000 move.w #$3344,$C00000 move.w #$5566,$C00000 move.w #$7788,$C00000 move.w #$99AA,$C00000 move.w #$BBCC,$C00000 move.w #$DDEE,$C00000 move.w #$FF00,$C00000 ;Do a DMA fill operation to VRAM address 0x8002 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 ;Wait for the write FIFO to be empty before initiating the DMA fill, otherwise the ;fill operation will trigger immediately using whatever write data is already setup ;in the FIFO. TestDMAFillControlPortWritesWaitFIFOEmpty5: move.w $C00004,D7 btst #9,D7 beq TestDMAFillControlPortWritesWaitFIFOEmpty5 ;This is the same as the above test, except now we verify that if we try and write ;both DMA fill command words after disabling DMA, the fill is now not performed, ;since the CD5 bit will be masked when the second command word is latched. ;##FIX## Now here's an interesting result. The real hardware shows us that this DMA ;fill operation is performed after all. If we remove the command words setting up the ;DMA fill operation before disabling DMA operations however, it no longer works. This ;tells us that something is clearly being cached or set at the time the DMA fill ;command words are written, which is not invalidated after DMA operations are ;disabled. In fact, with further testing, the state of CD5 itself is unimportant once ;the command words for a DMA fill operation have been written. We can re-write a full ;command word pair with CD5 set to 0, while DMA operations themselves are disabled, ;and the DMA fill operation still triggers when the next data port occurs. Even more ;interesting is the fact that this behaviour only occurs when DMA is disabled, IE, if ;we normally have a DMA fill operation setup, and we re-write a command word pair ;before performing the data port write, and we clear CD5 in the new command word ;pair, if DMA operations are enabled, the pending DMA fill operation will be ;cancelled, but this is not the case when a pending DMA fill operation exists, and ;DMA operations are disabled before new command word pair is written. ;For reference, this initiates a DMA fill: ;move.l #$40020082,$C00004 ;DMA fill at VRAM address 0x8002 ;move.w #$8144,$C00004 ;move.l #$40020002,$C00004 ;Write to VRAM at 0x8002 ;move.w #$68AC,$C00000 ;Start DMA fill with 0x68AC ;While this does not: ;move.l #$40020082,$C00004 ;DMA fill at VRAM address 0x8002 ;move.l #$40020002,$C00004 ;Write to VRAM at 0x8002 ;move.w #$68AC,$C00000 ;Start DMA fill with 0x68AC ;It's also worth noting however, that even when we have disabled DMA operations ;before a DMA fill data port write, the command code and command address data is ;still used live from the last latched command port data, it's just the state of the ;CD5 bit that seems to be ignored in this case. move.l #$40020082,$C00004 ;DMA fill at VRAM address 0x8002 move.w #$8144,$C00004 move.w #$8F02,$C00004 move.l #$40020002,$C00004 ;DMA fill at VRAM address 0x8002 (CD5 not set) move.w #$68AC,$C00000 ;Start DMA fill with 0x68AC move.w #$7FFF,D1 TestDMAFillControlPortWritesDMAWaitLoop5: dbf D1,TestDMAFillControlPortWritesDMAWaitLoop5 ;This should fail, since the DMA fill operation has now completed, so CD5 has been ;cleared. move.w #$4012,$C00004 ;DMA fill at VRAM address 0x8012 move.w #$68AC,$C00000 ;Start DMA fill with 0x68AC TestDMAFillControlPortWritesDMAWaitLoop51: move.w $C00004,D7 btst #1,D7 bne TestDMAFillControlPortWritesDMAWaitLoop51 ;This should fail too as we cannot set CD5 through a control port right now, since ;DMA is disabled. move.l #$40160082,$C00004 ;DMA fill at VRAM address 0x8016 move.w #$68AC,$C00000 ;Start DMA fill with 0x68AC TestDMAFillControlPortWritesDMAWaitLoop52: move.w $C00004,D7 btst #1,D7 bne TestDMAFillControlPortWritesDMAWaitLoop52 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)+ move.w $C00000,(A0)+ move.w $C00000,(A0)+ move.w $C00000,(A0)+ move.w $C00000,(A0)+ move.w $C00000,(A0)+ move.w $C00000,(A0)+ move.w $C00000,(A0)+ move.w $C00000,(A0)+ 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 ;Initialize VRAM move.l #$40000002,$C00004 move.w #$1122,$C00000 move.w #$3344,$C00000 move.w #$5566,$C00000 move.w #$7788,$C00000 move.w #$99AA,$C00000 move.w #$BBCC,$C00000 move.w #$DDEE,$C00000 move.w #$FF00,$C00000 move.w #$1122,$C00000 move.w #$3344,$C00000 move.w #$5566,$C00000 move.w #$7788,$C00000 move.w #$99AA,$C00000 move.w #$BBCC,$C00000 move.w #$DDEE,$C00000 move.w #$FF00,$C00000 ;Do a DMA fill operation to VRAM address 0x8002 move.l #TestDMATransferToVRAMDataBlock,D0 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 #$9500, D2 lsr.l #1,D0 move.b D0,D2 move.w D2,$C00004 move.w #$9600, D2 lsr.l #8,D0 move.b D0,D2 move.w D2,$C00004 ;Setup the DMA source address for the DMA transfer, but leave the upper bits of the ;DMA source address and the DMA mode setup for a DMA fill. We leave the calculated ;contents for register 0x17 for the DMA transfer setup in D2. move.w #$9780,$C00004 move.w #$9700, D2 lsr.l #8,D0 move.b D0,D2 ;Wait for the write FIFO to be empty before initiating the DMA fill, otherwise the ;fill operation will trigger immediately using whatever write data is already setup ;in the FIFO. TestDMAFillControlPortWritesWaitFIFOEmpty6: move.w $C00004,D7 btst #9,D7 beq TestDMAFillControlPortWritesWaitFIFOEmpty6 ;In this test, we try to initiate a change from a pending DMA fill operation to a DMA ;transfer operation by changing the DMA mode before writing the fill data to the data ;port. move.l #$40020082,$C00004 ;DMA fill at VRAM address 0x8002 move.w #$8144,$C00004 move.w #$8F02,$C00004 move.w D2,(A0) ;Set DMA mode to DMA transfer ;##TODO## Carry out this test properly on the hardware, and get it working correctly. ; move.w (A0),$C00004 move.w #$4008,$C00004 ;DMA fill at VRAM address 0x8008 (CD5 not set) move.w #$68AC,$C00000 ;Start DMA fill with 0x68AC move.w #$7FFF,D1 TestDMAFillControlPortWritesDMAWaitLoop6: dbf D1,TestDMAFillControlPortWritesDMAWaitLoop6 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)+ move.w $C00000,(A0)+ move.w $C00000,(A0)+ move.w $C00000,(A0)+ move.w $C00000,(A0)+ move.w $C00000,(A0)+ move.w $C00000,(A0)+ move.w $C00000,(A0)+ move.w $C00000,(A0)+ 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 ;Initialize VRAM 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 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