question about color and HBlankInt

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

Moderators: BigEvilCorporation, Mask of Destiny

zhengyaxin_8bit
Very interested
Posts: 101
Joined: Thu Sep 04, 2008 2:57 am
Location: China

question about color and HBlankInt

Post by zhengyaxin_8bit » Fri Feb 15, 2013 11:48 am

The screen is divided into two parts.The upper part of using a color palette,and the bottom half of another color palette.Simulator displays the correct,but Game console displays an error.There is a line in the middle of the screen

This is my demo source code:
https://www.box.com/files#/files/0/f/0/1/f_6228473143
and this is shot:
Image

zhengyaxin_8bit
Very interested
Posts: 101
Joined: Thu Sep 04, 2008 2:57 am
Location: China

Post by zhengyaxin_8bit » Fri Feb 15, 2013 11:49 am


zhengyaxin_8bit
Very interested
Posts: 101
Joined: Thu Sep 04, 2008 2:57 am
Location: China

Post by zhengyaxin_8bit » Fri Feb 15, 2013 12:00 pm

Code: Select all

;********************************************
NMI:                                    ;IE0 Vertical Interrupt (Level 6)
        movem.l d0-a7,-(sp)
        move.w  #$8A70,$C00004
        move.w  #$8014,$C00004          ;open IRQ
        MOVE.L  #$C0000000,$C00004      ;CRAM WRITE
        MOVE.W  #$3F,D0                 ;PALETTE 0;64 COLOR
        LEA.L   title_a_PALETTE_OFFSET,A3
?Send_PAL
        MOVE.W  (A3)+,$C00000
        DBF     D0,?Send_PAL
        JSR     TFMMUSICNMI
        jsr     nmi_sound
        MOVE.l  #0,m_NMIFlag
        movem.l (sp)+,d0-a7
        RTE
;********************************************
IRQ:
        movem.l d0-a7,-(sp)
        MOVE.L  #$C0000000,$C00004      ;CRAM WRITE
        MOVE.W  #$3F,D0                 ;PALETTE 0;64 COLOR
        LEA.L   title_b_PALETTE_OFFSET,A3
?Send_PAL
        MOVE.W  (A3)+,$C00000
        DBF     D0,?Send_PAL
        movem.l (sp)+,d0-a7
        RTE
;********************************************

Stef
Very interested
Posts: 3131
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

Post by Stef » Fri Feb 15, 2013 1:32 pm

If you write the palette during active display the real hardware show pixel garbage in active screen. You should tunr off the VDP while you're updating the palette or take care about modifying it only during the HBlank.
Of course you can't update the whole palette during a single hblank, at best you can update 4/5 entries i guess...
Last edited by Stef on Fri Feb 15, 2013 3:20 pm, edited 1 time in total.

zhengyaxin_8bit
Very interested
Posts: 101
Joined: Thu Sep 04, 2008 2:57 am
Location: China

Post by zhengyaxin_8bit » Fri Feb 15, 2013 3:00 pm

Stef wrote:If you write the palette during active display the real hardware show pixel garbage in active screen. You should tunr off the VDP while you're updating the palette or take care about modifying it only during the HBlank.
Of course you can't update the whole palette during a single hblank, at beast you can update 4/5 entries i guess...
I modified the code as follows:

Code: Select all

;**************************************************************
IRQ:									;
		movem.l d0-a7,-(sp)
		move.w	#$816C,$C00004

		MOVE.L	#$C0600000,$C00004		;CRAM WRITE
		MOVE.W	#$3F-$30,D0				;PALETTE 0;64 COLOR
		LEA.L	title_b_PALETTE_OFFSET+$60,A3
?Send_PAL
		MOVE.W	(A3)+,$C00000
		DBF	D0,?Send_PAL

		move.w	#$817C,$C00004
		movem.l (sp)+,d0-a7
		RTE
;**************************************************************
Effect is better than before,But still there is pixel garbage

zhengyaxin_8bit
Very interested
Posts: 101
Joined: Thu Sep 04, 2008 2:57 am
Location: China

Post by zhengyaxin_8bit » Fri Feb 15, 2013 3:08 pm

I read the article "HBlank the Timings" from viewtopic.php?t=388&highlight=hblank

Code: Select all

                               LINE N                 LINE N + 1 
  |----------------------------------------------|--------------------    
<HBS>---------<HBE>----------------------------<HBS> 
                                            | 
                                         <H-INT> 
                                                 | 
                                               <LRE> 

HBS -> HBLANK start 
HBE -> HBLANK end 
H-INT -> H-INT Trigger 
LRE -> Line rendering   
The H-INT isn't HBLANK start
How do I know the HBLANK began?

Stef
Very interested
Posts: 3131
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

Post by Stef » Fri Feb 15, 2013 3:22 pm

zhengyaxin_8bit wrote:I read the article "HBlank the Timings" from viewtopic.php?t=388&highlight=hblank

Code: Select all

                               LINE N                 LINE N + 1 
  |----------------------------------------------|--------------------    
<HBS>---------<HBE>----------------------------<HBS> 
                                            | 
                                         <H-INT> 
                                                 | 
                                               <LRE> 

HBS -> HBLANK start 
HBE -> HBLANK end 
H-INT -> H-INT Trigger 
LRE -> Line rendering   
The H-INT isn't HBLANK start
How do I know the HBLANK began?
You can check the VDP status flag to know if you are in the hblank, you can also use the VDP HV counter for that purpose.

TmEE co.(TM)
Very interested
Posts: 2440
Joined: Tue Dec 05, 2006 1:37 pm
Location: Estonia, Rapla City
Contact:

Post by TmEE co.(TM) » Fri Feb 15, 2013 4:14 pm

Only 3 color updates fit into offscreen area per line.
Disable VDP rendering as Hint happens, DMA in one or 2 palettes and enable VDP again. You will lose some/most/all sprites for that line, but that pushes many palette writes into offscreen area.
Mida sa loed ? Nagunii aru ei saa ;)
http://www.tmeeco.eu
Files of all broken links and images of mine are found here : http://www.tmeeco.eu/FileDen

zhengyaxin_8bit
Very interested
Posts: 101
Joined: Thu Sep 04, 2008 2:57 am
Location: China

Post by zhengyaxin_8bit » Fri Feb 15, 2013 4:44 pm

I improved the code,

Code: Select all

IRQ:
		movem.l d0-a7,-(sp)
?WAIT_HBLANK:
		MOVE.W	$C00004,D0
		AND.W	#$02,D0
		CMP.W	#$02,D0
		BEQ		?WAIT_HBLANK

		MOVE.L	#$C0600000,$C00004		;CRAM WRITE
		MOVE.L	m_AddrSave,A3
		MOVE.l	(A3)+,$C00000			;8*4/2=16
		MOVE.l	(A3)+,$C00000
		MOVE.l	(A3)+,$C00000
		MOVE.l	(A3)+,$C00000
		MOVE.l	(A3)+,$C00000
		MOVE.l	(A3)+,$C00000
		MOVE.l	(A3)+,$C00000
		MOVE.l	(A3)+,$C00000
		movem.l (sp)+,d0-a7
		RTE
The new effect here
http://s1048.beta.photobucket.com/user/ ... 2.png.html

zhengyaxin_8bit
Very interested
Posts: 101
Joined: Thu Sep 04, 2008 2:57 am
Location: China

Post by zhengyaxin_8bit » Fri Feb 15, 2013 4:48 pm

Still not ideal, there is no better way, or am I wrong? :oops:

TmEE co.(TM)
Very interested
Posts: 2440
Joined: Tue Dec 05, 2006 1:37 pm
Location: Estonia, Rapla City
Contact:

Post by TmEE co.(TM) » Fri Feb 15, 2013 4:55 pm

You want to write too many colors. You can only do 3 colors in one line without garbage showing up. Just 3.
Mida sa loed ? Nagunii aru ei saa ;)
http://www.tmeeco.eu
Files of all broken links and images of mine are found here : http://www.tmeeco.eu/FileDen

Mask of Destiny
Very interested
Posts: 615
Joined: Thu Nov 30, 2006 6:30 am

Post by Mask of Destiny » Fri Feb 15, 2013 6:17 pm

You can do as many as 8 colors per line if you combine vcounter polling, disabling the display during transfer and DMA. You'll want to do most of the DMA setup sometime before HBLANK and you'll want the command words to disable the display, start the DMA operation and turn the display back on again in registers. As TmEE noted, you lose all your sprites for the line this way, but you won't get any garbage. You still won't be able to transfer 16 colors in a single line like you're trying to though.

zhengyaxin_8bit
Very interested
Posts: 101
Joined: Thu Sep 04, 2008 2:57 am
Location: China

Post by zhengyaxin_8bit » Sat Feb 16, 2013 4:15 am

TmEE co.(TM) wrote:You want to write too many colors. You can only do 3 colors in one line without garbage showing up. Just 3.
As you said,I do these changes

Code: Select all

IRQ:
		movem.l d0-a7,-(sp)
;?WAIT_HBLANK:
;		MOVE.W	$C00004,D0
;		AND.W	#$02,D0
;		CMP.W	#$02,D0
;		BEQ		?WAIT_HBLANK

		MOVE.L	#$C0600000,$C00004		;CRAM WRITE
		MOVE.L	m_AddrSave,A3
		MOVE.W	(A3)+,$C00000
		MOVE.W	(A3)+,$C00000
		MOVE.W	(A3)+,$C00000

		movem.l (sp)+,d0-a7
		RTE
http://s1048.beta.photobucket.com/user/ ... sort=3&o=0
:cry:

zhengyaxin_8bit
Very interested
Posts: 101
Joined: Thu Sep 04, 2008 2:57 am
Location: China

Post by zhengyaxin_8bit » Sat Feb 16, 2013 5:11 am

I just do the experiment,TmEE co.(TM) is right. :D
I modify the program:

Code: Select all

IRQ:
		movem.l d0-a7,-(sp)
?WAIT_HBLANK:
		MOVE.W	$C00004,D0
		AND.W	#$02,D0
		CMP.W	#$02,D0
		BEQ		?WAIT_HBLANK
		NOP		;1
		NOP
		NOP
		NOP
		NOP
		NOP
		NOP
		NOP
		NOP
		NOP		;10
		NOP
		NOP
		NOP
		NOP
		NOP
		NOP
		NOP
		NOP
		NOP
		NOP		;20
		NOP
		NOP
		NOP
		NOP
		NOP
		NOP
		NOP
		NOP
		NOP
		NOP		;30
		NOP
		NOP
		NOP
		NOP
		NOP
		NOP
		NOP
		NOP
		NOP		;39 have pix garbage
		NOP		;40 min
		NOP
		NOP
		NOP
		NOP
		NOP
		NOP
		NOP
		NOP
		NOP
		NOP
		NOP		;51 max
		NOP		;52 Have pix garbage
		MOVE.L	#$C0600000,$C00004		;CRAM WRITE
		MOVE.L	m_AddrSave,A3
		MOVE.W	(A3)+,$C00000
		MOVE.W	(A3)+,$C00000
		MOVE.W	(A3)+,$C00000
		movem.l (sp)+,d0-a7
		RTE
The line 40-51 no garbage

Stef
Very interested
Posts: 3131
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

Post by Stef » Sat Feb 16, 2013 11:46 am

You can do better asm code so you can transfer more colors :
Prepare your command write (CRAM write) in $C00004 ahead then cache $C00000 in A0 register and prepare values to copy in Dx registers.
Then at the good moment (just when HBlank start) you just do a single MOVEM.L instruction to copy as much color data as much as possible during the HBlank period.

Post Reply