NintendoAge http://nintendoage.com/forum/ -Sqooner NES Programming http://nintendoage.com/forum/messageview.cfm?catid=22&threadid=7155 2017-11-09T03:41:34 -05.00 Roth 161 Originally posted by: siudym
 
Hi,
I have a problem with background animation. Mapper is UNROM, so the animation is changing the tiles in VRAM (NameTable)
Unfortunately, the method is poor and takes a lot of NMI time. How do you animate background elements (change BGR tiles numbers in VRAM) to minimize the VBLANK time (NMI)?
 
The code that is used for the animation:
[code]
;------------------------------------
BGR_Anim:      ;in the NMI loop

   INC Anim_Timer   ;timer
   INC Anim_Timer
   INC Anim_Timer
   INC Anim_Timer

   LDA Anim_Timer
   CMP #$00
   BCC skip1

   LDA BGR_NT_TILE1_AddrHI
   STA $2006
   LDA BGR_NT_TILE1_AddrLO
   STA $2006
   lda #$10          ;pattern table bgr tile1 nr.
   sta $2007
   LDA BGR_NT_TILE1_AddrHI
   STA $2006
   LDA BGR_NT_TILE2_AddrLO
   STA $2006
   lda #$11         ;pattern table bgr tile2 nr.
   sta $2007
   LDA BGR_NT_TILE1_AddrHI
   STA $2006
   LDA BGR_NT_TILE3_AddrLO
   STA $2006
   lda #$20         ;pattern table bgr tile3 nr.
   sta $2007
   LDA BGR_NT_TILE1_AddrHI
   STA $2006
   LDA BGR_NT_TILE4_AddrLO
   STA $2006
   lda #$21         ;pattern table bgr tile4 nr.
   sta $2007
   LDA #$00   ;reset screen
   STA $2006
   LDA #$00
   STA $2006

skip1:

   LDA Anim_Timer
   CMP #$40
   BCC skip2

   LDA BGR_NT_TILE1_AddrHI
   STA $2006
   LDA BGR_NT_TILE1_AddrLO
   STA $2006
   lda #$12
   sta $2007
   LDA BGR_NT_TILE1_AddrHI
   STA $2006
   LDA BGR_NT_TILE2_AddrLO
   STA $2006
   lda #$13
   sta $2007
   LDA BGR_NT_TILE1_AddrHI
   STA $2006
   LDA BGR_NT_TILE3_AddrLO
   STA $2006
   lda #$22
   sta $2007
   LDA BGR_NT_TILE1_AddrHI
   STA $2006
   LDA BGR_NT_TILE4_AddrLO
   STA $2006
   lda #$23
   sta $2007
   LDA #$00
   STA $2006
   LDA #$00
   STA $2006

skip2:

   LDA Anim_Timer
   CMP #$80
   BCC skip3

   LDA BGR_NT_TILE1_AddrHI
   STA $2006
   LDA BGR_NT_TILE1_AddrLO
   STA $2006
   lda #$14
   sta $2007
   LDA BGR_NT_TILE1_AddrHI
   STA $2006
   LDA BGR_NT_TILE2_AddrLO
   STA $2006
   lda #$15
   sta $2007
   LDA BGR_NT_TILE1_AddrHI
   STA $2006
   LDA BGR_NT_TILE3_AddrLO
   STA $2006
   lda #$24
   sta $2007
   LDA BGR_NT_TILE1_AddrHI
   STA $2006
   LDA BGR_NT_TILE4_AddrLO
   STA $2006
   lda #$25
   sta $2007
   LDA #$00
   STA $2006
   LDA #$00
   STA $2006

skip3:

   LDA Anim_Timer
   CMP #$C0
   BCC skip4

   LDA BGR_NT_TILE1_AddrHI
   STA $2006
   LDA BGR_NT_TILE1_AddrLO
   STA $2006
   lda #$12
   sta $2007
   LDA BGR_NT_TILE1_AddrHI
   STA $2006
   LDA BGR_NT_TILE2_AddrLO
   STA $2006
   lda #$13
   sta $2007
   LDA BGR_NT_TILE1_AddrHI
   STA $2006
   LDA BGR_NT_TILE3_AddrLO
   STA $2006
   lda #$22
   sta $2007
   LDA BGR_NT_TILE1_AddrHI
   STA $2006
   LDA BGR_NT_TILE4_AddrLO
   STA $2006
   lda #$23
   sta $2007
   LDA #$00
   STA $2006
   LDA #$00
   STA $2006

skip4:
   RTS
[/code]


after branching on Anim_Timer, and executing the corresponding code, you don't skip the rest of the code.
You should do something like this :
 
lda Anim_Timer
; cmp#$00 ; not needed
beq anim1
cmp #$40
beq anim2
cmp #$80
beq anim3
cmp #$C0
beq anim4
jmp skipAnimation

anim1:
 ; anim 1 code here
jmp skipAnimation

anim2:
 ; anim 2 code here
jmp skipAnimation

anim3:
 ; anim 3 code here
jmp skipAnimation

anim4:
 ; anim 4 code here

skipAnimation:

Note that I'm using BEQ and not BCC to check Anim_Timer state and update only once the NT.

Also you can replace this :
   LDA #$00
   STA $2006
   LDA #$00
   STA $2006

by this :
   LDA #$00
   STA $2006
   STA $2006

and this :
 
INC Anim_Timer   ;timer
INC Anim_Timer
INC Anim_Timer
INC Anim_Timer

by this :
 
lda Anim_Timer
clc
adc #$04
sta Anim_Timer

to gain cycles and ROM bytes.

Hope it helps ! ]]>
NES Programming http://nintendoage.com/forum/messageview.cfm?catid=22&threadid=7155 2017-11-08T19:48:31 -05.00 Roth 161 Originally posted by: siudym
 
Hi,
I have a problem with background animation. Mapper is UNROM, so the animation is changing the tiles in VRAM (NameTable)
Unfortunately, the method is poor and takes a lot of NMI time. How do you animate background elements (change BGR tiles numbers in VRAM) to minimize the VBLANK time (NMI)?
 
The code that is used for the animation:
[code]
;------------------------------------
BGR_Anim:      ;in the NMI loop

   INC Anim_Timer   ;timer
   INC Anim_Timer
   INC Anim_Timer
   INC Anim_Timer

   LDA Anim_Timer
   CMP #$00
   BCC skip1

   LDA BGR_NT_TILE1_AddrHI
   STA $2006
   LDA BGR_NT_TILE1_AddrLO
   STA $2006
   lda #$10          ;pattern table bgr tile1 nr.
   sta $2007
   LDA BGR_NT_TILE1_AddrHI
   STA $2006
   LDA BGR_NT_TILE2_AddrLO
   STA $2006
   lda #$11         ;pattern table bgr tile2 nr.
   sta $2007
   LDA BGR_NT_TILE1_AddrHI
   STA $2006
   LDA BGR_NT_TILE3_AddrLO
   STA $2006
   lda #$20         ;pattern table bgr tile3 nr.
   sta $2007
   LDA BGR_NT_TILE1_AddrHI
   STA $2006
   LDA BGR_NT_TILE4_AddrLO
   STA $2006
   lda #$21         ;pattern table bgr tile4 nr.
   sta $2007
   LDA #$00   ;reset screen
   STA $2006
   LDA #$00
   STA $2006

skip1:

   LDA Anim_Timer
   CMP #$40
   BCC skip2

   LDA BGR_NT_TILE1_AddrHI
   STA $2006
   LDA BGR_NT_TILE1_AddrLO
   STA $2006
   lda #$12
   sta $2007
   LDA BGR_NT_TILE1_AddrHI
   STA $2006
   LDA BGR_NT_TILE2_AddrLO
   STA $2006
   lda #$13
   sta $2007
   LDA BGR_NT_TILE1_AddrHI
   STA $2006
   LDA BGR_NT_TILE3_AddrLO
   STA $2006
   lda #$22
   sta $2007
   LDA BGR_NT_TILE1_AddrHI
   STA $2006
   LDA BGR_NT_TILE4_AddrLO
   STA $2006
   lda #$23
   sta $2007
   LDA #$00
   STA $2006
   LDA #$00
   STA $2006

skip2:

   LDA Anim_Timer
   CMP #$80
   BCC skip3

   LDA BGR_NT_TILE1_AddrHI
   STA $2006
   LDA BGR_NT_TILE1_AddrLO
   STA $2006
   lda #$14
   sta $2007
   LDA BGR_NT_TILE1_AddrHI
   STA $2006
   LDA BGR_NT_TILE2_AddrLO
   STA $2006
   lda #$15
   sta $2007
   LDA BGR_NT_TILE1_AddrHI
   STA $2006
   LDA BGR_NT_TILE3_AddrLO
   STA $2006
   lda #$24
   sta $2007
   LDA BGR_NT_TILE1_AddrHI
   STA $2006
   LDA BGR_NT_TILE4_AddrLO
   STA $2006
   lda #$25
   sta $2007
   LDA #$00
   STA $2006
   LDA #$00
   STA $2006

skip3:

   LDA Anim_Timer
   CMP #$C0
   BCC skip4

   LDA BGR_NT_TILE1_AddrHI
   STA $2006
   LDA BGR_NT_TILE1_AddrLO
   STA $2006
   lda #$12
   sta $2007
   LDA BGR_NT_TILE1_AddrHI
   STA $2006
   LDA BGR_NT_TILE2_AddrLO
   STA $2006
   lda #$13
   sta $2007
   LDA BGR_NT_TILE1_AddrHI
   STA $2006
   LDA BGR_NT_TILE3_AddrLO
   STA $2006
   lda #$22
   sta $2007
   LDA BGR_NT_TILE1_AddrHI
   STA $2006
   LDA BGR_NT_TILE4_AddrLO
   STA $2006
   lda #$23
   sta $2007
   LDA #$00
   STA $2006
   LDA #$00
   STA $2006

skip4:
   RTS
[/code]


Ask this in this thread: http://nintendoage.com/forum/messageview.cfm?StartRow=1&catid=22&threadid=103138

Hopefully someone there can help. I can't really see an issue from what you have posted. I have changed upwards to 36 tiles at once in my game with no issues. I know that's cutting it pretty close to the time limit with that many tiles. ]]>
NES Programming http://nintendoage.com/forum/messageview.cfm?catid=22&threadid=7155 2017-11-08T05:49:11 -05.00 Roth 161 Hi,
I have a problem with background animation. Mapper is UNROM, so the animation is changing the tiles in VRAM (NameTable)
Unfortunately, the method is poor and takes a lot of NMI time. How do you animate background elements (change BGR tiles numbers in VRAM) to minimize the VBLANK time (NMI)?
 
The code that is used for the animation:
[code]
;------------------------------------
BGR_Anim:      ;in the NMI loop

   INC Anim_Timer   ;timer
   INC Anim_Timer
   INC Anim_Timer
   INC Anim_Timer

   LDA Anim_Timer
   CMP #$00
   BCC skip1

   LDA BGR_NT_TILE1_AddrHI
   STA $2006
   LDA BGR_NT_TILE1_AddrLO
   STA $2006
   lda #$10          ;pattern table bgr tile1 nr.
   sta $2007
   LDA BGR_NT_TILE1_AddrHI
   STA $2006
   LDA BGR_NT_TILE2_AddrLO
   STA $2006
   lda #$11         ;pattern table bgr tile2 nr.
   sta $2007
   LDA BGR_NT_TILE1_AddrHI
   STA $2006
   LDA BGR_NT_TILE3_AddrLO
   STA $2006
   lda #$20         ;pattern table bgr tile3 nr.
   sta $2007
   LDA BGR_NT_TILE1_AddrHI
   STA $2006
   LDA BGR_NT_TILE4_AddrLO
   STA $2006
   lda #$21         ;pattern table bgr tile4 nr.
   sta $2007
   LDA #$00   ;reset screen
   STA $2006
   LDA #$00
   STA $2006

skip1:

   LDA Anim_Timer
   CMP #$40
   BCC skip2

   LDA BGR_NT_TILE1_AddrHI
   STA $2006
   LDA BGR_NT_TILE1_AddrLO
   STA $2006
   lda #$12
   sta $2007
   LDA BGR_NT_TILE1_AddrHI
   STA $2006
   LDA BGR_NT_TILE2_AddrLO
   STA $2006
   lda #$13
   sta $2007
   LDA BGR_NT_TILE1_AddrHI
   STA $2006
   LDA BGR_NT_TILE3_AddrLO
   STA $2006
   lda #$22
   sta $2007
   LDA BGR_NT_TILE1_AddrHI
   STA $2006
   LDA BGR_NT_TILE4_AddrLO
   STA $2006
   lda #$23
   sta $2007
   LDA #$00
   STA $2006
   LDA #$00
   STA $2006

skip2:

   LDA Anim_Timer
   CMP #$80
   BCC skip3

   LDA BGR_NT_TILE1_AddrHI
   STA $2006
   LDA BGR_NT_TILE1_AddrLO
   STA $2006
   lda #$14
   sta $2007
   LDA BGR_NT_TILE1_AddrHI
   STA $2006
   LDA BGR_NT_TILE2_AddrLO
   STA $2006
   lda #$15
   sta $2007
   LDA BGR_NT_TILE1_AddrHI
   STA $2006
   LDA BGR_NT_TILE3_AddrLO
   STA $2006
   lda #$24
   sta $2007
   LDA BGR_NT_TILE1_AddrHI
   STA $2006
   LDA BGR_NT_TILE4_AddrLO
   STA $2006
   lda #$25
   sta $2007
   LDA #$00
   STA $2006
   LDA #$00
   STA $2006

skip3:

   LDA Anim_Timer
   CMP #$C0
   BCC skip4

   LDA BGR_NT_TILE1_AddrHI
   STA $2006
   LDA BGR_NT_TILE1_AddrLO
   STA $2006
   lda #$12
   sta $2007
   LDA BGR_NT_TILE1_AddrHI
   STA $2006
   LDA BGR_NT_TILE2_AddrLO
   STA $2006
   lda #$13
   sta $2007
   LDA BGR_NT_TILE1_AddrHI
   STA $2006
   LDA BGR_NT_TILE3_AddrLO
   STA $2006
   lda #$22
   sta $2007
   LDA BGR_NT_TILE1_AddrHI
   STA $2006
   LDA BGR_NT_TILE4_AddrLO
   STA $2006
   lda #$23
   sta $2007
   LDA #$00
   STA $2006
   LDA #$00
   STA $2006

skip4:
   RTS
[/code]
]]>
NES Programming http://nintendoage.com/forum/messageview.cfm?catid=22&threadid=7155 2016-07-09T11:09:38 -05.00 Roth 161 NES Programming http://nintendoage.com/forum/messageview.cfm?catid=22&threadid=7155 2016-07-09T10:32:20 -05.00 Roth 161 NES Programming http://nintendoage.com/forum/messageview.cfm?catid=22&threadid=7155 2016-07-09T09:37:15 -05.00 Roth 161 NES Programming http://nintendoage.com/forum/messageview.cfm?catid=22&threadid=7155 2016-07-09T09:36:16 -05.00 Roth 161 Originally posted by: SoleGooseProductions
 
Originally posted by: Daniel_Doyce

I'm about to go through these tutorials in detail. Are the source code files still hosted somewhere? I see references to code in each of the sections, but no attachments. Thanks!

In the last paragraph of each lesson there is a link (it says "click here", but it is part way into the text). They seem to still be good for me. Good luck with learning, ask as many questions as you want  .
  Ah, now I feel stupid. Got it, thanks!

  ]]>
NES Programming http://nintendoage.com/forum/messageview.cfm?catid=22&threadid=7155 2016-07-09T09:29:26 -05.00 Roth 161 Originally posted by: Daniel_Doyce

I'm about to go through these tutorials in detail. Are the source code files still hosted somewhere? I see references to code in each of the sections, but no attachments. Thanks!
In the last paragraph of each lesson there is a link (it says "click here", but it is part way into the text). They seem to still be good for me. Good luck with learning, ask as many questions as you want  .

]]>
NES Programming http://nintendoage.com/forum/messageview.cfm?catid=22&threadid=7155 2016-07-09T09:07:58 -05.00 Roth 161 NES Programming http://nintendoage.com/forum/messageview.cfm?catid=22&threadid=7155 2016-06-16T11:13:15 -05.00 Roth 161
low cost pcb ]]>