Page 1 of 1

Palette changing only every two lines

Posted: Sun Mar 23, 2014 2:12 am
by M-374 LX
While trying to use the horizontal interrupts to change a palette every line, the palette actually changes every two lines. The same happens with different codes I have tried. What may be wrong?

Here is one of those codes:

Code: Select all

		add.w   #1,cur_scanline

		tst.b		color_change_enabled
		jeq		endHBL

		moveq	#0,	%d0
		moveq	#0,	%d1

		move.w	cur_scanline,%d0
		and.w	#1,%d0
		tst.w	%d0
		jeq		otherColor

		move.w	#0x888,%d0
		move.w	#0x0C0,%d1
		jmp		afterColor
		move.w	#0xFFF,%d0
		move.w	#0x0E0,%d1
		move.l	#0xC0020000,0xC00004
		move.w	%d0,0xC00000
		move.l	#0xC00A0000,0xC00004
		move.w	%d1,0xC00000


Posted: Sun Mar 23, 2014 10:28 am
by r57shell
two possible reasons:
1) wrong HBLANK settings
2) long code

Posted: Sun Mar 23, 2014 5:17 pm
by M-374 LX
I have just found the cause of the problem: the VDP register #10 was set to 1 instead of 0.

One more question: is it faster to store the current scanline in the RAM or to read it from VDP port 0xC00008?

Posted: Sun Mar 23, 2014 6:37 pm
by Chilly Willy
Don't bother. It would be faster to just change a pointer after setting the color... like this.

Code: Select all

    movea.l next_set,-(sp)

    move.l #0xC0020000,0xC00004
    move.w #0x888,0xC00000
    move.l #0xC00A0000,0xC00004
    move.w #0x0C0,0xC00000
    move.l #set_2,next_set

    move.l #0xC0020000,0xC00004
    move.w #0xFFF,0xC00000
    move.l #0xC00A0000,0xC00004
    move.w #0x0E0,0xC00000
    move.l #set_1,next_set
Don't forget to set next_set = set_1 to start with. You can improve the speed a little with judicious register usage for the addressing rather than using absolute longs. Also, don't forget to save/restore all registers used in the exception. The above code doesn't change any registers. If you used a0 for calling the code, you'd need to add saving/restoring a0.