16 colors 1 hscan

For anything related to VDP (plane, color, sprite, tiles)

Moderators: BigEvilCorporation, Mask of Destiny

Post Reply
Jpg3D
Interested
Posts: 20
Joined: Mon Mar 03, 2014 9:19 pm

16 colors 1 hscan

Post by Jpg3D » Sun Oct 29, 2017 1:23 pm

Hi again spritesmind users.

After watching this video and seeing this can be achieved, https://www.youtube.com/watch?v=nt-AxAqlrOo i was trying to replicate the scrolling floor effect. So i decided to debug that level in regen emulator. After a few minutes i discovered that the game does not use interruptions so i tried to write my version of the code using polling, that looks like it's more accurate than h-interrupts. The idea is to swap 16 colors on only 1 hblank.

Code: Select all


	*interrupts are disabled.

        LEA $00C00005,A5
        LEA $00C00004,A6
        LEA $C00008,A1        

FNLP    

WLN MOVE.B (A5),D0  
    BTST #3,D0 
    BEQ.S WLN          *wait until vscan = 0
    
    	DMA2CR 16,PAL1,0	*load default pallete
        BSR DMAWAIT		
        
WLF MOVE.B (A5),D0  
    BTST #3,D0 
    BNE.S WLF          *wait until vscan = 1            *wait until frame starts drawing
    
    MOVEQ.L #50,D1   					*set d1 to 51 just for testing

HD  CMP.B #43,(A1)                                            *take a look to hv counter. I wait until line 43 to perform de pallete swap.
    BNE.S HD

NL  STVDPREG 19,((16)&$ff)				*
      STVDPREG 20,(((16)>>8)&$ff)			*
       
    MOVE.W	#$9600+(((PAL2>>1)&$FF00)>>8),(A6)
    MOVE.W	#$9500+((PAL2>>1)&$FF),(A6)
    MOVE.W	#$9700+((((PAL2>>1)&$FF0000)>>16)&$7F),(A6)
    
    MOVE.W D5,(a6)		*completely crazy here as i dont understand why write values
    MOVE.W D5,(a6)		* to vdp sometimes looks like it perform faster operations 
    MOVE.W D5,(a6)		* this is just 4 enable displays
    MOVE.W D5,(a6)
    
WL1 MOVE.B (A5),D0  
    BTST #2,D0 
    BNE.S WL1           *wait until hscan = 0
    
    MOVE.B (A5),D0
    OR.B #%100,D0

    MOVE.W #$8000+((1)<<8)|(%00110100),D4						*disable display to d4
    MOVE.L #$C0000080|(((0)&$3FFF)<<16)|(((0)&$C000)>>14),D6		*dma destination address to d6
    MOVE.W #$8000+((1)<<8)|(%01110100),D5						*enable display to d5

WL  CMP.B (A5),D0
    BNE.S WL             *wait until hscan = 1							

    MOVE.W D4,(a6)					*disable display for faster dma			
    MOVE.L D6,(a6)					*write dma destination. At this moment 16 colors should be updated while the hscan
    MOVE.W D5,(a6)					*enable display again

    STVDPREG 19,((16)&$ff)			*write again dma values so i only have to write destination at hblank on the next loop.
    STVDPREG 20,(((16)>>8)&$ff)		*
       
    MOVE.W	#$9600+(((PAL2>>1)&$FF00)>>8),(A6)			*write source to vdp
    MOVE.W	#$9500+((PAL2>>1)&$FF),(A6)
    MOVE.W	#$9700+((((PAL2>>1)&$FF0000)>>16)&$7F),(A6)

       
    DBRA.W D1,WL1		*repeat process 51 hscans

    JMP FNLP    			*wait until next frame


the result i obtained is a 16 color pal swap at hscan 43 with a little garbage at the left on my pal md1. I hope someone may give a hand with this. so we can use it to achieve new cool effects.
Thank you.

Image

You can download the rom if you want to have a look at it.
https://uploadfiles.io/lloc6

Jpg3D
Interested
Posts: 20
Joined: Mon Mar 03, 2014 9:19 pm

Re: 16 colors 1 hscan

Post by Jpg3D » Sun Oct 29, 2017 4:07 pm

after polling the hv counter i achieved to dma 16 colors on only 1 hscan removing the garbage.
it's basically the same code. Im trying to do some improvements because the synchronization does not work if the console is overclocked.

You can test the rom here. I would apreciate if someone test this rom on any 60 hz console.
https://ufile.io/cvu92

Image

Code: Select all

        LEA $00C00005,A5
        LEA $00C00004,A6
        
  LEA $C00008,A1
  LEA $C00009,A2

FNLP    

WLN MOVE.B (A5),D0  
    BTST #3,D0 
    BEQ.S WLN          *wait until vscan = 0
    
    	DMA2CR 16,PAL1,0
        BSR DMAWAIT
        
WLF MOVE.B (A5),D0  
    BTST #3,D0 
    BNE.S WLF          *wait until vscan = 1
    
    MOVEQ.L #50,D1   

HD  CMP.B #43,(A1)    *wait until line 100
    BNE.S HD

NL  
    
WL1 MOVE.B (A5),D0  
    BTST #2,D0 
    BNE.S WL1           *wait until hscan = 0
    
    MOVE.B (A5),D0
    OR.B #%100,D0

WL  CMP.B #224,(A2)       
    BGE.S WL    											wait until drawing pixel 224 then continue.

    STVDPREG 19,((16)&$ff)								<- this instructions
    STVDPREG 20,(((16)>>8)&$ff)							<- executes
       
    MOVE.W	#$9600+(((PAL2>>1)&$FF00)>>8),(A6)				<-while hblank
    MOVE.W	#$9500+((PAL2>>1)&$FF),(A6)					<-is coming 
    MOVE.W	#$9700+((((PAL2>>1)&$FF0000)>>16)&$7F),(A6)         <-hblank not yet
    
    MOVE.W #$8000+((1)<<8)|(%00110100),(A6)					<-this instruction starts exactly on hblank. I disable display for faster dma.
    MOVE.L #$C0000080|(((0)&$3FFF)<<16)|(((0)&$C000)>>14),(A6)	<-dma right on hblank
    MOVE.W #$8000+((1)<<8)|(%01110100),(A6)					<-dma finishes. Still hblank screen does not get corrupt. Enable display again.

    DBRA.W D1,WL1

    JMP FNLP    


Miquel
Very interested
Posts: 514
Joined: Sat Jul 30, 2016 12:33 am

Re: 16 colors 1 hscan

Post by Miquel » Sun Oct 29, 2017 6:10 pm

If you are developing a game, what are you going to do: use the 100% of the cpu just to wait for the correct scanline?
A smart solution, proposed by other members, is to use the h exception of the previous line and then check for the wanted line on the counter.
HELP. Spanish TVs are brain washing people to be hostile to me.

Jpg3D
Interested
Posts: 20
Joined: Mon Mar 03, 2014 9:19 pm

Re: 16 colors 1 hscan

Post by Jpg3D » Sun Oct 29, 2017 6:45 pm

Miquel wrote:
Sun Oct 29, 2017 6:10 pm
If you are developing a game, what are you going to do: use the 100% of the cpu just to wait for the correct scanline?
A smart solution, proposed by other members, is to use the h exception of the previous line and then check for the wanted line on the counter.
Dont worry, this is just a timing test. I'll do that on the final version.

Miquel
Very interested
Posts: 514
Joined: Sat Jul 30, 2016 12:33 am

Re: 16 colors 1 hscan

Post by Miquel » Wed Nov 01, 2017 3:47 am

I don't follow, what causes the garbage at the left of the image? Is just a matter of precision or is there something else?
HELP. Spanish TVs are brain washing people to be hostile to me.

Sik
Very interested
Posts: 939
Joined: Thu Apr 10, 2008 3:03 pm
Contact:

Re: 16 colors 1 hscan

Post by Sik » Wed Nov 01, 2017 5:46 am

You know, it'd help if the boundaries of the screen were explicitly displayed. I can't tell whether the garbage is in border area or not (and I know a few consoles have issues with doing a DMA to CRAM from hblank... actually resulted in palette occasionally reloading as pure white in Overdrive 1 until kabuto rewrote the code and made the DMA trigger in a slower way).
Sik is pronounced as "seek", not as "sick".

Miquel
Very interested
Posts: 514
Joined: Sat Jul 30, 2016 12:33 am

Re: 16 colors 1 hscan

Post by Miquel » Wed Nov 01, 2017 7:09 pm

Sik wrote:
Wed Nov 01, 2017 5:46 am
[...] until kabuto rewrote the code and made the DMA trigger in a slower way).
How do you "trigger DMA in a slower way"? Do you mind later in time? wait a few more cycles?
HELP. Spanish TVs are brain washing people to be hostile to me.

Sik
Very interested
Posts: 939
Joined: Thu Apr 10, 2008 3:03 pm
Contact:

Re: 16 colors 1 hscan

Post by Sik » Wed Nov 01, 2017 7:13 pm

By not doing this:

Code: Select all

    move.l  d0, (a0)
Turns out the instruction runs so fast that it causes issues if you happen to do it right at the wrong spot in the scanline. This is probably why the Sega docs say to do it in two word writes and/or moving the command from RAM to the VDP control port. We also ran into this issue on exactly one console we had (・_・) so no idea how many revisions are affected.

Note that I have no idea if disabling display in hblank had some effect on this or not.
Sik is pronounced as "seek", not as "sick".

Miquel
Very interested
Posts: 514
Joined: Sat Jul 30, 2016 12:33 am

Re: 16 colors 1 hscan

Post by Miquel » Thu Nov 02, 2017 1:42 am

Thanks Sik! you are of great help.
HELP. Spanish TVs are brain washing people to be hostile to me.

Post Reply