Jump to content

  •  

Photo

Palette line fading help


  • This topic is locked This topic is locked
23 replies to this topic

#19 MarkeyJester

MarkeyJester

    3 Super Emeralds

  • Pro User
  • 1746 posts
  • Gender:Male

Posted 28 March 2012 - 11:43 PM

Indeed that's what it's for, it also does d7 too, d7/a0, you can back up all registers if you really wanted by using d0-a6, you just need to remember to restore them later (or at least increase the stack).

Right, my headache has gone, so I have given this a few tries today. No matter what I tried, I couldn't get to copy. I also tried your little tip:

	lea	($FFFFFB50).w,a3
movea.w (a3),($FFFFF5C0).w


What you don't know here is how it works, so allow me to elaborate:

lea	($FFFFFB40).w,a3		; a3 = $FFFFFB40

	lea	($FFFFFBC0).w,a4		; a4 = $FFFFFBC0

Now, if you were to:

move.l	a3,a4

This will move what's in a3 into a4, if a3 = $FFFFFB40, then after that instruction, a4 will also = $FFFFFB40, that will move the "address" accross, not what's AT the address, now... if you were to:

move.l	(a3),(a4)

This will move the data AT address a3 to the addres AT a4, so it's basically the same as:

move.l	($FFFFFB40).w,($FFFFFBC0).w

Now, by adding the "increment" symbol "+", you can increase the address of the registers:

move.l	(a3)+,(a4)+

So:
  • The data from address $FFFFFB40 - $FFFFFB43 will be copied to $FFFFFBC0 - $FFFFFBC3.
  • a3 will increment by 4, and a4 will increment by 4, a3 is now $FFFFFB44 and a4 is now $FFFFFBC4.
By using address registers and the incrementation, you can change the address of the "lea", and the rest of the (a?)+ will follow suit.
  • 0

#20 redhotsonic

redhotsonic

    Also known as RHS

  • Pro User
  • 1910 posts
  • Gender:Male
  • Location:United Kingdom

Posted 29 March 2012 - 12:08 AM

Right, let me see if I get this right.

move.l (a3)+,(a4)+

This command will copy the longword from a3 to a4. Then afterwards, both a3 and a4 will increment by a longword. So if I did this:

 lea ($FFFFFB50).w,a3
lea ($FFFFF5C0).w,a4
move.l (a3)+,(a4)+
move.l (a3)+,(a4)+
move.l (a3)+,(a4)+
move.l (a3)+,(a4)+


Would this copy the palette line?

I'm on my phone as gf has laptop so couldn't test it and I'm off to bed =P


As for d7, I got told years ago to never use it. Can't remember why, but whenever I have tried using it, the game normally ends up freezing, so I always use d0-d6

Edited by redhotsonic, 29 March 2012 - 12:14 AM.

  • 0

#21 Crash

Crash

    8 Chaos Emeralds

  • Member
  • 205 posts
  • Gender:Male
  • Location:Australia

Posted 29 March 2012 - 09:21 AM

As for d7, I got told years ago to never use it. Can't remember why, but whenever I have tried using it, the game normally ends up freezing, so I always use d0-d6


No, d7 is fine to use. a7 is the stack pointer though, and shouldn't be used as a normal address register ;)
  • 0

#22 vladikcomper

vladikcomper

    5 Chaos Emeralds

  • Pro User
  • 315 posts
  • Gender:Male
  • Location:Russia

Posted 29 March 2012 - 07:05 PM

Yes, D7 is fine, until you're programming objects.

It's used as a counter in 'ObjectsLoad' routine, which run all objects codes. So if you touch D7 in object's code, wrong number of objects will be loaded. Due to counter corruption, loading objects may continue when objects RAM ends, so 'ObjectsLoad' will load wrong data, jumping to wrong locations for it. This will eventually crash the game.
  • 0

#23 redhotsonic

redhotsonic

    Also known as RHS

  • Pro User
  • 1910 posts
  • Gender:Male
  • Location:United Kingdom

Posted 29 March 2012 - 08:50 PM

That explains why d7 doesn't work half the time!



Okay:

  lea ($FFFFF5C0).w,a4
lea ($FFFFF5C0).w,a4
move.l (a3)+,(a4)+
move.l (a3)+,(a4)+
move.l (a3)+,(a4)+
move.l (a3)+,(a4)+


This works! The palette line is copied! So, $FFFFF5C0 is ready.




Posted Image

Here is the background. When you die, it does this code:

		movem.l d7/a0,-(sp)
move.w #$5601,($FFFFF626).w
jsr Pal_FadeFrom2
move.w #$003F,($FFFFF626).w
movem.l (sp)+,d7/a0


This fades it to black and it works.

Posted Image

Now, as you are aware, the shield coding here didn't work. So, I tried this:

shield_monitor:
moveq #$4D,d0
jsr (LoadPLC).l
bclr #3,status_secondary(a1)
addq.w #1,(a2)
bset #0,status_secondary(a1)
move.w #$AF,d0
jsr (PlayMusic).l
move.b #$38,(Object_RAM+$2180).w ; load Obj38 (shield) at $FFFFD180
move.w a1,(Object_RAM+$2180+parent).w
movem.l d7/a0-a2,-(sp)
moveq #0,d0
lea ($FFFFF5C0).w,a0
move.w #$0601,($FFFFF626).w
jsr Pal_FadeTo3
move.w #$003F,($FFFFF626).w
movem.l (sp)+,d7/a0-a2
rts


I did "#$0601,($FFFFF626).w" because then, it still uses the same line but moves over by 6. like as $FFFFF5C6. And added an extra label "Pal_FadeTo3", here:

Pal_FadeTo:
move.w #$3F,($FFFFF626).w
Pal_FadeTo2:
moveq #0,d0
lea (Normal_palette).w,a0
Pal_FadeTo3:
move.b ($FFFFF626).w,d0
adda.w d0,a0
moveq #0,d1
move.b ($FFFFF627).w,d0
; loc_23DE:
Pal_ToBlack:
move.w d1,(a0)+
dbf d0,Pal_ToBlack ; fill palette with $000 (black)
moveq #$0E,d4 ; MJ: prepare maximum colour check
moveq #$00,d6 ; MJ: clear d6

- bsr.w RunPLC_RAM
move.b #$12,(Delay_Time).w
bsr.w DelayProgram
bchg #$00,d6 ; MJ: change delay counter
beq - ; MJ: if null, delay a frame
bsr.s Pal_FadeIn
subq.b #$02,d4 ; MJ: decrease colour check
bne - ; MJ: if it has not reached null, branch
move.b #$12,(Delay_Time).w ; MJ: wait for V-blank again (so colours transfer)
bra DelayProgram ; MJ: ''

; End of function Pal_FadeTo


I did this because then "lea (Normal_palette).w,a0" doesn't interrupt with "lea ($FFFFF5C0).w,a0", but alas, still not working.

Posted Image


I then tried making it jump to "Pal_FadeTo2" anyway, and same thing happens. Also tried "move.w #$5601,($FFFFF626).w" again but still fails.

Edited by redhotsonic, 29 March 2012 - 08:56 PM.

  • 0

#24 redhotsonic

redhotsonic

    Also known as RHS

  • Pro User
  • 1910 posts
  • Gender:Male
  • Location:United Kingdom

Posted 01 May 2012 - 11:43 AM

Hello, I'm still having troubles with making the palette fade in. It's really bugging me now, and I just can't see why it's failing.

Now, I can get the palette line to fade out perfectly fine (thanks for the help, MJ):

Posted Image

I then make it fade out:

super_shoes:
addq.w #1,(a2)
bset #2,status_secondary(a1)
move.b #$96,speedshoes_time(a1)
movem.l d7/a0,-(sp)
move.w #$600F,($FFFFF626).w
jsr Pal_FadeFrom2
movem.l (sp)+,d7/a0
cmpa.w #MainCharacter,a1
bne.s loc_12A10
cmpi.w #2,(Player_mode).w ; Maybe set if the char is Tails?
beq.s loc_12A10
move.b #$2, (sonicsbursting).w ; when speed boots are active, make sonic in burst mode
move.w #$C00,(Sonic_top_speed).w
move.w #$18,(Sonic_acceleration).w
move.w #$80,(Sonic_deceleration).w
bra.s loc_12A22


Posted Image

(The blue is from a different palette line so ignore that for now)

But no matter what I do, I cannot fade it back in.

Pal_FadeTo:
move.w #$3F,($FFFFF626).w
Pal_FadeTo2:
moveq #0,d0
lea (Normal_palette).w,a0
Pal_FadeTo3:
move.b ($FFFFF626).w,d0
adda.w d0,a0
moveq #0,d1
move.b ($FFFFF627).w,d0
; loc_23DE:
Pal_ToBlack:
move.w d1,(a0)+
dbf d0,Pal_ToBlack ; fill palette with $000 (black)
moveq #$0E,d4 ; MJ: prepare maximum colour check
moveq #$00,d6 ; MJ: clear d6

- bsr.w RunPLC_RAM
move.b #$12,(Delay_Time).w
bsr.w DelayProgram
bchg #$00,d6 ; MJ: change delay counter
beq.s - ; MJ: if null, delay a frame
bsr.s Pal_FadeIn
subq.b #$02,d4 ; MJ: decrease colour check
bne.s - ; MJ: if it has not reached null, branch
move.b #$12,(Delay_Time).w ; MJ: wait for V-blank again (so colours transfer)
bra.w DelayProgram ; MJ: ''

; End of function Pal_FadeTo



I've put Pal_fadeto3, so in my objects code, I can move my own data to a0 and the RAM address.

shield_monitor:
movem.l d7/a0,-(sp)
move.w #$600F,($FFFFF626).w
moveq #0,d0
lea (Normal_palette_line4).w,a0
jsr Pal_FadeTo3
movem.l (sp)+,d7/a0
moveq #$4D,d0
jsr (LoadPLC2).l
bclr #3,status_secondary(a1)
addq.w #1,(a2)
bset #0,status_secondary(a1)
move.w #$AF,d0
jsr (PlayMusic).l
move.b #$38,(Object_RAM+$2180).w ; load Obj38 (shield) at $FFFFD180
move.w a1,(Object_RAM+$2180+parent).w
rts



Now, it doesn't matter what I "Lea" to a0, Normal_palette_line, 2, 3 or 4, or even put my own data in a new RAM address and move it to a0 (lea (Myownpalette).w,a0). Whatever I do, I ALWAYS get this:

Posted Image

I'm obviously doing something wrong. Anyone with any ideas? Thanks for the help!

redhotsonic


EDIT: I tried making it jump to different places rather than Pal_FadeTo3 and I either get the samething, or it styas black, or it freezes.

Edited by redhotsonic, 01 May 2012 - 11:45 AM.

  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users