Thoughts on Higher Level Language Design for 6502 Systems

Discuss technical or other issues relating to programming the Nintendo Entertainment System, Famicom, or compatible systems.

Moderator: Moderators

slobu
Posts: 275
Joined: Tue Jul 12, 2011 10:58 am

Post by slobu » Fri Jan 06, 2012 6:19 pm

I've heard global vars are bad.. but, in the context of constrained devices, isn't speed a better tradeoff than tidiness? In my limited experience the only drawback is my own potential for errors (stepping on an already used var).

I think BatariBASIC has a great way to deal with multi-bank sub-routines. You can call "GOSUB FOO" for local routines and "GOSUB FOO BANK3" to tell the compiler it's located on another page.

User avatar
tokumaru
Posts: 12003
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Post by tokumaru » Fri Jan 06, 2012 6:55 pm

slobu wrote:I've heard global vars are bad.. but, in the context of constrained devices, isn't speed a better tradeoff than tidiness?
It depends... if you have a lot of global variables you'll run out of RAM faster in systems that don't have much of it, like the NES, and that's a huge problem.
You can call "GOSUB FOO" for local routines and "GOSUB FOO BANK3" to tell the compiler it's located on another page.
IMO it's not a matter of how to call them... I mean, the compiler is the one generating the ASM/binaries, so it KNOWS what routines are in different banks, it doesn't need the programmer to explicitly say it.

hcs
Posts: 31
Joined: Mon Nov 27, 2006 11:34 pm
Location: NYC
Contact:

Post by hcs » Fri Jan 06, 2012 7:56 pm

tokumaru wrote:I mean, the compiler is the one generating the ASM/binaries, so it KNOWS what routines are in different banks, it doesn't need the programmer to explicitly say it.
With cc65 it's the linker that actually knows the final addresses of everything, and by then it's probably too late to insert bankswitching, at least as it is implemented. (afaik)

Post Reply