;------------------------------------------------------------------------------------ ;Test 12 - DMA Copy to CRAM V2 ;-In: ; D3.b = Increment data ; D4.b = Text display number ; D5.b = DMA mode ;------------------------------------------------------------------------------------ TestDMACopyToCRAMV2Text: dc.b 'DMA Copy to CRAM inc=1 ' dc.b 'DMA Copy to CRAM inc=2 ' dc.b 'DMA Copy to CRAM inc=4 ' TestDMACopyToCRAMV2ExpectedResult: dc.w $02EE, $04EC, $06EA, $08E8, $0AE6, $0CE4, $0EE2, $02E0, $04CE, $06CC, $08CA, $0AC8, $0CC6, $0EC4, $02C2, $04C0 dc.w $06AE, $08AC, $0AAA, $0CA8, $0EA6, $02A4, $04A2, $06A0, $088E, $0A8C, $0C8A, $0E88, $0286, $0484, $0682, $0880 dc.w $0A6E, $0C6C, $0E6A, $0268, $0466, $0664, $0862, $0A60, $0C4E, $0E4C, $024A, $0448, $0646, $0844, $0A42, $0C40 dc.w $0E2E, $022C, $042A, $0628, $0826, $0A24, $0C22, $0E20, $020E, $040C, $060A, $0808, $0A06, $0C04, $0E02, $0200 dc.w $02EE, $04EC, $06EA, $08E8, $0AE6, $0CE4, $0EE2, $02E0, $04CE, $06CC, $08CA, $0AC8, $0CC6, $0EC4, $02C2, $04C0 dc.w $06AE, $08AC, $0AAA, $0CA8, $0EA6, $02A4, $04A2, $06A0, $088E, $0A8C, $0C8A, $0E88, $0286, $0484, $0682, $0880 dc.w $0A6E, $0C6C, $0E6A, $0268, $0466, $0664, $0862, $0A60, $0C4E, $0E4C, $024A, $0448, $0646, $0844, $0A42, $0C40 dc.w $0E2E, $022C, $042A, $0628, $0826, $0A24, $0C22, $0E20, $020E, $040C, $060A, $0808, $0A06, $0C04, $0E02, $0200 dc.w $02EE, $04EC, $06EA, $08E8, $0AE6, $0CE4, $0EE2, $02E0, $04CE, $06CC, $08CA, $0AC8, $0CC6, $0EC4, $02C2, $04C0 dc.w $06AE, $08AC, $0AAA, $0CA8, $0EA6, $02A4, $04A2, $06A0, $088E, $0A8C, $0C8A, $0E88, $0286, $0484, $0682, $0880 dc.w $0A6E, $0C6C, $0E6A, $0268, $0466, $0664, $0862, $0A60, $0C4E, $0E4C, $024A, $0448, $0646, $0844, $0A42, $0C40 dc.w $0E2E, $022C, $042A, $0628, $0826, $0A24, $0C22, $0E20, $020E, $040C, $060A, $0808, $0A06, $0C04, $0E02, $0200 dc.w $02EE, $04EC, $06EA, $08E8, $0AE6, $0CE4, $0EE2, $02E0, $04CE, $06CC, $08CA, $0AC8, $0CC6, $0EC4, $02C2, $04C0 dc.w $06AE, $08AC, $0AAA, $0CA8, $0EA6, $02A4, $04A2, $06A0, $088E, $0A8C, $0C8A, $0E88, $0286, $0484, $0682, $0880 dc.w $0A6E, $0C6C, $0E6A, $0268, $0466, $0664, $0862, $0A60, $0C4E, $0E4C, $024A, $0448, $0646, $0844, $0A42, $0C40 dc.w $0E2E, $022C, $042A, $0628, $0826, $0A24, $0C22, $0E20, $020E, $040C, $060A, $0808, $0A06, $0C04, $0E02, $0200 dc.w $02EE, $04EC, $06EA, $08E8, $0AE6, $0CE4, $0EE2, $02E0, $04CE, $06CC, $08CA, $0AC8, $0CC6, $0EC4, $02C2, $04C0 dc.w $06AE, $08AC, $0AAA, $0CA8, $0EA6, $02A4, $04A2, $06A0, $088E, $0A8C, $0C8A, $0E88, $0286, $0484, $0682, $0880 dc.w $0A6E, $0C6C, $0E6A, $0268, $0466, $0664, $0862, $0A60, $0C4E, $0E4C, $024A, $0448, $0646, $0844, $0A42, $0C40 dc.w $0E2E, $022C, $042A, $0628, $0826, $0A24, $0C22, $0E20, $020E, $040C, $060A, $0808, $0A06, $0C04, $0E02, $0200 dc.w $02EE, $04EC, $06EA, $08E8, $0AE6, $0CE4, $0EE2, $02E0, $04CE, $06CC, $08CA, $0AC8, $0CC6, $0EC4, $02C2, $04C0 dc.w $06AE, $08AC, $0AAA, $0CA8, $0EA6, $02A4, $04A2, $06A0, $088E, $0A8C, $0C8A, $0E88, $0286, $0484, $0682, $0880 dc.w $0A6E, $0C6C, $0E6A, $0268, $0466, $0664, $0862, $0A60, $0C4E, $0E4C, $024A, $0448, $0646, $0844, $0A42, $0C40 dc.w $0E2E, $022C, $042A, $0628, $0826, $0A24, $0C22, $0E20, $020E, $040C, $060A, $0808, $0A06, $0C04, $0E02, $0200 TestDMACopyToCRAMV2: ;Initialize the text result block move.w #36,D7 move.w #9,(A0)+ ;Set the number of display lines move.w D7,(A0)+ ;Set the text length move.w #$0100,D6 ;Set the data length move.w D6,(A0)+ lea TestDMACopyToCRAMV2Text,A1 move.w D4,D1 mulu.w D7,D1 add.l D1,A1 sub.w #1,D7 TestDMACopyToCRAMV2WriteText: move.b (A1)+,(A0)+ dbf D7,TestDMACopyToCRAMV2WriteText move.w #1,(A0)+ ;Set the expected result data present flag lea TestDMACopyToCRAMV2ExpectedResult,A1 ;Write the expected result data to the buffer move.w D4,D1 mulu.w D6,D1 add.l D1,A1 sub.w #1,D6 TestDMACopyToCRAMV2WriteExpectedResultData: move.b (A1)+,(A0)+ dbf D6,TestDMACopyToCRAMV2WriteExpectedResultData ;Initialize CRAM move.l #$C0000000,$C00004 move.w #$3F,D0 lea TestDMACopyToCRAMV2TestData,A1 TestDMACopyToCRAMV2CRAMLoop: ; move.w #$2222,$C00000 move.w (A1)+,$C00000 dbf D0,TestDMACopyToCRAMV2CRAMLoop ;Do a DMA fill operation to CRAM address 0x20 move.w #$0009,D1 move.w #$8F00, D2 move.b D3,D2 move.w D2,$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,$C00004 ;Set the DMA source register to 0x0000 move.w #$9600,$C00004 move.w #$9700, D2 move.b D5,D2 move.w D2,$C00004 move.l #$002000E0,(A0) ;DMA copy to CRAM address 0x20 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 #$0080,D7 ;Add a small delay loop before writing to the data port, just in case we actually kicked off a DMA copy operation. TestDMACopyToCRAMV2DelayLoop1: dbf D7,TestDMACopyToCRAMV2DelayLoop1 TestDMACopyToCRAMV2DMAWaitLoop1: move.w $C00004,D7 btst #1,D7 bne TestDMACopyToCRAMV2DMAWaitLoop1 move.w #$8144,$C00004 move.w #$8F02,$C00004 ;Dump CRAM move.l #$00000020,$C00004 move.w #$3F,D0 TestDMACopyToCRAMV2CRAMLoop2: move.w $C00000,(A0)+ dbf D0,TestDMACopyToCRAMV2CRAMLoop2 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 CRAM move.l #$C0000000,$C00004 move.w #$3F,D0 lea TestDMACopyToCRAMV2TestData,A1 TestDMACopyToCRAMV2CRAMLoop3: ; move.w #$2222,$C00000 move.w (A1)+,$C00000 dbf D0,TestDMACopyToCRAMV2CRAMLoop3 ;Do a DMA fill operation to CRAM address 0x21 move.w #$0009,D1 move.w #$8F00, D2 move.b D3,D2 move.w D2,$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,$C00004 ;Set the DMA source register to 0x0000 move.w #$9600,$C00004 move.w #$9700, D2 move.b D5,D2 move.w D2,$C00004 move.l #$002100E0,(A0) ;DMA copy to CRAM address 0x21 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 #$0080,D7 ;Add a small delay loop before writing to the data port, just in case we actually kicked off a DMA copy operation. TestDMACopyToCRAMV2DelayLoop2: dbf D7,TestDMACopyToCRAMV2DelayLoop2 move.w #$68AC,$C00000 ;Start DMA fill with 0x68AC TestDMACopyToCRAMV2DMAWaitLoop2: move.w $C00004,D7 btst #1,D7 bne TestDMACopyToCRAMV2DMAWaitLoop2 move.w #$8144,$C00004 move.w #$8F02,$C00004 ;Dump CRAM move.l #$00000020,$C00004 move.w #$3F,D0 TestDMACopyToCRAMV2CRAMLoop4: move.w $C00000,(A0)+ dbf D0,TestDMACopyToCRAMV2CRAMLoop4 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 CRAM move.l #$C0000000,$C00004 move.w #$3F,D0 TestDMACopyToCRAMV2CRAMLoop5: move.w #$0000,$C00000 dbf D0,TestDMACopyToCRAMV2CRAMLoop5 rts TestDMACopyToCRAMV2TestData: dc.w $02EE, $04EC, $06EA, $08E8, $0AE6, $0CE4, $0EE2, $02E0, $04CE, $06CC, $08CA, $0AC8, $0CC6, $0EC4, $02C2, $04C0 dc.w $06AE, $08AC, $0AAA, $0CA8, $0EA6, $02A4, $04A2, $06A0, $088E, $0A8C, $0C8A, $0E88, $0286, $0484, $0682, $0880 dc.w $0A6E, $0C6C, $0E6A, $0268, $0466, $0664, $0862, $0A60, $0C4E, $0E4C, $024A, $0448, $0646, $0844, $0A42, $0C40 dc.w $0E2E, $022C, $042A, $0628, $0826, $0A24, $0C22, $0E20, $020E, $040C, $060A, $0808, $0A06, $0C04, $0E02, $0200