Page 1 of 1
Global Constants in 4k+4k
Posted: Mon Feb 14, 2022 4:19 pm
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
Re: Global Constants in 4k+4k
Posted: Mon Feb 14, 2022 6:32 pm
by BigEd
The answer probably depends on which assembler you are using - which is it?
Re: Global Constants in 4k+4k
Posted: Tue Feb 15, 2022 10:48 am
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.
Re: Global Constants in 4k+4k
Posted: Tue Feb 15, 2022 11:43 am
by BigEd
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.)
Re: Global Constants in 4k+4k
Posted: Tue Feb 15, 2022 1:52 pm
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.
Re: Global Constants in 4k+4k
Posted: Tue Feb 15, 2022 1:54 pm
by drogon
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
Re: Global Constants in 4k+4k
Posted: Tue Feb 15, 2022 3:03 pm
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.)
Re: Global Constants in 4k+4k
Posted: Sun Mar 06, 2022 4:51 pm
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.
Re: Global Constants in 4k+4k
Posted: Tue Mar 22, 2022 12:07 pm
by Sheep64
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.