Global Constants in 4k+4k

Programming the 6502 microprocessor and its relatives in assembly and other languages.
Post Reply
boriskarloff
Posts: 7
Joined: 14 Nov 2021

Global Constants in 4k+4k

Post by boriskarloff »

Atari 2600
Switch banking 4k+4k

I declare some constants in the Bank 0.
I need to use them, even, in the Bank 1.
Is it possibile to declare them only once in the Bank 0?
Because if I declare again in the Bank 1, it is necessary to change their name.

Thanks
User avatar
BigEd
Posts: 11464
Joined: 11 Dec 2008
Location: England
Contact:

Re: Global Constants in 4k+4k

Post by BigEd »

The answer probably depends on which assembler you are using - which is it?
John West
Posts: 383
Joined: 03 Sep 2002

Re: Global Constants in 4k+4k

Post by John West »

I think some more context would be helpful. How exactly is the banking done?

The 2600 uses a 6507, which has only 13 address pins. The resulting 8K of externally addressable memory gets mirrored eight times in the 64K space that code can see. That 8K is further divided into 4K of I/O and RAM and 4K of ROM. Games that need more than 4K of ROM have to arrange some kind of banking.

But there are many ways of doing that, and I don't know which are used. There are too many options for speculation to be very helpful. I will speculate anyway.

Since the 4K ROM is mirrored throughout the 64K address space, you could assemble each bank to a different target address. So one thinks it's at $1000, another thinks it's at $3000, and so on. Even though only one is available at a time, you can still assemble them together and not worry about overlapping code confusing the assembler.

If the banking is only partial, and you're swapping 2K blocks while keeping 2K fixed, you could have common things in the fixed block. It sounds like that's not the case here though. If the whole 4K gets swapped, they have to be completely independent. If you've got anything that you need to place in more than one bank, they have to be independent copies. In that case, there's no need for the copies to be at the same locations. I think I would find it much less confusing if the banks were treated as completely independent things, with different names to make it clear what bank data is in.

But don't listen to me. I have never done 2600 development, and I don't know how the people who have do things. There must be a 2600 development community out there somewhere. They'd be the best people to ask if you want to know good ways to manage it. This is really a 2600 question, not a 6502 one: the same problems would arise whatever processor was used.
User avatar
BigEd
Posts: 11464
Joined: 11 Dec 2008
Location: England
Contact:

Re: Global Constants in 4k+4k

Post by BigEd »

John West wrote:
Since the 4K ROM is mirrored throughout the 64K address space, you could assemble each bank to a different target address. So one thinks it's at $1000, another thinks it's at $3000, and so on. Even though only one is available at a time, you can still assemble them together and not worry about overlapping code confusing the assembler.
I like this! (I suspect banking, in all its various forms, tends to stress our mental models of how things work. Which is to say, it's difficult to think about, correctly.)
gfoot
Posts: 871
Joined: 09 Jul 2021

Re: Global Constants in 4k+4k

Post by gfoot »

It seems odd to me that it would be economical to use a cut-down CPU and supplement it with custom banking logic, rather than using the full 6502 in the first place. But I guess the banking logic ICs were in the cartridges, not the main system itself, and these banked cartridges could have been made much later when the price of components or PLDs had maybe dropped a lot, making it economical after all.
User avatar
drogon
Posts: 1671
Joined: 14 Feb 2018
Location: Scotland
Contact:

Re: Global Constants in 4k+4k

Post by drogon »

gfoot wrote:
It seems odd to me that it would be economical to use a cut-down CPU and supplement it with custom banking logic, rather than using the full 6502 in the first place. But I guess the banking logic ICs were in the cartridges, not the main system itself, and these banked cartridges could have been made much later when the price of components or PLDs had maybe dropped a lot, making it economical after all.
Early Atari 2600 games didn't need banking - nor much RAM either. The console was too successful for its own good... some would suggest it lasted longer than it ought to...

It was pretty amazing at the time though!

-Gordon
--
Gordon Henderson.
See my Ruby 6502 and 65816 SBC projects here: https://projects.drogon.net/ruby/
User avatar
BigEd
Posts: 11464
Joined: 11 Dec 2008
Location: England
Contact:

Re: Global Constants in 4k+4k

Post by BigEd »

The idea of making a cheap-as-possible console and then having (some) of the cartridges add extra hardware, that seems like quite a good idea to me. It's true that the later and larger games needed quite complex schemes, but then the game itself can perhaps cost more. And surely the 2600 being cheap to make and cheap to buy must have been a major factor in its success.

(An ultimate example of this might be Star Fox with a 16 bit RISC in the cart. Although that's for a different platform.)
User avatar
Sheep64
In Memoriam
Posts: 311
Joined: 11 Aug 2020
Location: A magnetic field

Re: Global Constants in 4k+4k

Post by Sheep64 »

If you, for example, define a table which can be banked out then may have to define the table in two places or do some hooky includes. To minimize wasted ROM, define all of the global constants first and then define the constants which are local to each bank.
User avatar
Sheep64
In Memoriam
Posts: 311
Joined: 11 Aug 2020
Location: A magnetic field

Re: Global Constants in 4k+4k

Post by Sheep64 »

gfoot on Tue 15 Feb 2022 wrote:
It seems odd to me that it would be economical to use a cut-down CPU and supplement it with custom banking logic
This inefficiency is deliberate. Many game consoles have been sold at a loss. The profit comes from selling games but people don't buy games unless they have a console. If the console is slightly cheaper than more people buy consoles and more games are sold. This is a false economy for a customer. However, the majority of game purchases occur after the console is a sunk cost.

Actually, I presume that all of the Atari 2600 game consoles were soldered manually. Soldering 28 pin 6507 rather than 40 pin 6502 would save considerable effort. It would also reduce production line theft because 6507 is less useful with 13 address lines and no NMI.
Post Reply