It is currently Fri Mar 22, 2019 5:43 pm

All times are UTC - 7 hours





Post new topic Reply to topic  [ 6 posts ] 
Author Message
PostPosted: Wed Mar 13, 2019 4:40 am 
Offline

Joined: Sat May 26, 2018 6:14 am
Posts: 79
Location: Italy
Hello,
I'm looking to fade in and fade out the entire screen when a scene change occur, I want to gradually put the screen from color to black and vicerversa. I read something about subtract $10 every interval of time to the background tile and change the HUE. But I can't find any example or code to understand how to do that in a simple way.

Any code example? Thanks a lot!


Top
 Profile  
 
PostPosted: Wed Mar 13, 2019 6:28 am 
Offline
User avatar

Joined: Thu Mar 31, 2016 11:15 am
Posts: 505
Well yeah if you have a color X and you subtract $10 from X, that color is going to get darker while maintaining its hue.

Image

See how colors with the same hue have the same highest digit?

Here's some example code:

Code:
copy_palette: ; Put this in your NMI handler
  lda #$3F
  sta PPUADDR
  ldy #$00
  sty PPUADDR
loop:
  lda (palete_ptr), y
  sec
  sbc fade_amount
  bcs :+
  lda #$0F
:
  sta PPUDATA
  iny
  cpy #32
  bcc loop
  rts

fade_out: ; Call when you want to fade
.repeat 5, i
  lda #$10*i
  sta fade_amount
  jsr wait_for_nmi
.endrepeat
  rts

fade_in: ; Call when you want to fade
.repeat 5, i
  lda #$40 - $10*i
  sta fade_amount
  jsr wait_for_nmi
.endrepeat
  rts



Top
 Profile  
 
PostPosted: Wed Mar 13, 2019 9:47 am 
Offline

Joined: Sat May 26, 2018 6:14 am
Posts: 79
Location: Italy
Ok thanks, I will try as soon as I can! :)


Top
 Profile  
 
PostPosted: Wed Mar 13, 2019 7:20 pm 
Offline

Joined: Mon May 25, 2009 2:20 pm
Posts: 70
here's from megaman 3 (copy-pasted from my romhack megaman odyssey)
just JSR to palfade_restore ...and/or palfade_dark, that's all :)

Code:
   .byte "PALETTE FADE"
;Fade in/out palette
;600-61F current BG/Spr Pal
;620-63F backup/previous BG/Spr Pal
;colortrig non-zero, will tell NMI to update pal on next frame

PalFade_Speed = $04

palfade_restore:
   lda #$30
   ldx #$F0
   bne PalFade_Proc

palfade_darken:
   lda #$10
   tax
;-------------------------------------------
PalFade_Proc
   stx $0D
.Store_PalIndex
   sta $0F
   ldy #$1F
.loop_AddPal_Value
   lda $620,y
   sec
   sbc $0F
   bpl .Store_PalValue
   lda #$0F   ;black
.Store_PalValue
   sta $600,y
   dey
   bpl .loop_AddPal_Value
   sty ColorTrig
   ldx #PalFade_Speed
   jsr waitvblank_x

;next session, 4 total
   lda $0F
   clc
   adc $0D
   bmi .PalFade_RTS
   cmp #$50
   bne .Store_PalIndex
.PalFade_RTS
   rts


Top
 Profile  
 
PostPosted: Wed Mar 13, 2019 11:41 pm 
Offline
User avatar

Joined: Sun Sep 19, 2004 9:28 pm
Posts: 3958
Location: A world gone mad
I don't see any immediate handling of this in the routines, but it's important to remember that colour $0D should not be used (see 2nd to last paragraph).


Top
 Profile  
 
PostPosted: Thu Mar 14, 2019 12:01 am 
Offline
User avatar

Joined: Sun Jan 22, 2012 12:03 pm
Posts: 7328
Location: Canada
Here's my answer from a very similar thread a few weeks back. There might be other useful things in that thread if you read the rest of it though, it's answering the same question.
https://forums.nesdev.com/viewtopic.php?p=224707#p224707


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC - 7 hours


Who is online

Users browsing this forum: Dwedit and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group