Page 1 of 3
question about color and HBlankInt
Posted: Fri Feb 15, 2013 11:48 am
by zhengyaxin_8bit
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:

Posted: Fri Feb 15, 2013 11:49 am
by zhengyaxin_8bit
Posted: Fri Feb 15, 2013 12:00 pm
by zhengyaxin_8bit
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
;********************************************
Posted: Fri Feb 15, 2013 1:32 pm
by Stef
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...
Posted: Fri Feb 15, 2013 3:00 pm
by zhengyaxin_8bit
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
Posted: Fri Feb 15, 2013 3:08 pm
by zhengyaxin_8bit
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?
Posted: Fri Feb 15, 2013 3:22 pm
by Stef
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.
Posted: Fri Feb 15, 2013 4:14 pm
by TmEE co.(TM)
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.
Posted: Fri Feb 15, 2013 4:44 pm
by zhengyaxin_8bit
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
Posted: Fri Feb 15, 2013 4:48 pm
by zhengyaxin_8bit
Still not ideal, there is no better way, or am I wrong?

Posted: Fri Feb 15, 2013 4:55 pm
by TmEE co.(TM)
You want to write too many colors. You can only do 3 colors in one line without garbage showing up. Just 3.
Posted: Fri Feb 15, 2013 6:17 pm
by Mask of Destiny
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.
Posted: Sat Feb 16, 2013 4:15 am
by zhengyaxin_8bit
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

Posted: Sat Feb 16, 2013 5:11 am
by zhengyaxin_8bit
I just do the experiment,TmEE co.(TM) is right.
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
Posted: Sat Feb 16, 2013 11:46 am
by Stef
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.