It is currently Fri Oct 19, 2018 8:58 pm

 All times are UTC - 7 hours

 Page 1 of 1 [ 2 posts ]
 Print view Previous topic | Next topic
Author Message
 Post subject: Bank Switching loopPosted: Tue Feb 24, 2015 6:26 am

Joined: Thu Jan 29, 2015 10:28 am
Posts: 7
Location: Moscow, Russian Federation
A little newbie question adout changing the banks: I get how to change it pressing buttons, but I confused making a loop for it. I mean, I don't know how to loop switching like first goes Bank 1 then Bank 2, next Bank 3 and all over again from Bank 1 without any pressing buttons.

Code:

lda \$4016
and #%00000001
lda #\$01
jsr Bankswitch

Bankswitch:
tax
sta Bankvalues, x
rts

Bankvalues:

.db \$00,\$01,\$02,\$03 ; Numbers of banks

The last thing which I reached is where I press the start button, I change bank number by jumping to subroutine.

Top

 Post subject: Re: Bank Switching loopPosted: Tue Feb 24, 2015 6:57 am

Joined: Sat Feb 12, 2005 9:43 pm
Posts: 10901
Location: Rio de Janeiro - Brazil
You mean you want to go 0, 1, 2, 3, 0, 1, 2, 3, ... over and over? All you have to do is put the bank index in a variable and increment that variable every time you want to change banks forcing it back to 0 when it overflows. Something like this:

Code:
clc
lda BankIndex
cmp #\$04
bcc SaveIndex
lda #\$00
SaveIndex:
sta BankIndex

There's a shortcut you can take whenever you're working with a power of 2 range. Look at how numbers look like in binary:

00 = %00000000
01 = %00000001
02 = %00000010
03 = %00000011
04 = %00000100
05 = %00000101
06 = %00000110
07 = %00000111
08 = %00001000
09 = %00001001
10 = %00001010
11 = %00001011
12 = %00001100
13 = %00001101
14 = %00001110
15 = %00001111
(...)

Notice how the last 2 digits repeat the sequence 00, 01, 10, 11 over and over, which are the numbers you want. This means you can get the values you need by simply masking out the upper bits:

Code:
clc
lda BankIndex
and #%00000011
sta BankIndex

Top

 Display posts from previous: All posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost timeSubject AscendingDescending
 Page 1 of 1 [ 2 posts ]

 All times are UTC - 7 hours

#### Who is online

Users browsing this forum: No registered users and 7 guests

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

Search for:
 Jump to:  Select a forum ------------------ NES / Famicom    NESdev    NESemdev    NES Graphics    NES Music    Homebrew Projects       2018 NESdev Competition       2017 NESdev Competition       2016 NESdev Competition       2014 NESdev Competition       2011 NESdev Competition    Newbie Help Center    NES Hardware and Flash Equipment       Reproduction    NESdev International       FCdev       NESdev China       NESdev Middle East Other    General Stuff    Membler Industries    Other Retro Dev       SNESdev       GBDev    Test Forum Site Issues    phpBB Issues    Web Issues    nesdevWiki