Jump to content
IGNORED

Atari 2600 libraries for C compilers?


jdrose

Recommended Posts

Thanks. I like CC65. It is a handy 6502 C cross compiler that includes an assembler as well. My gut feeling is dB would produce tighter code because it is optimized for the Atari 2600. However, I much prefer C to BASIC. May have to develop some libraries for CC65 and see the difference in program size. 4K is precious little to work with. Gotta conserve every byte.

Link to comment
Share on other sites

With 128 bytes of RAM on the 2600 you'd have a hard time to use it as a stack, compiler temporary storage, software parameter stack and your own program variables all at the same time. I suspect that for any non trivial program you'd spend most of your time looking at the assembly language produced by your "C" code to see what it was doing to the extent that you might as well have written it in assembler in the first place ;).

  • Like 5
Link to comment
Share on other sites

  • 4 months later...

With 128 bytes of RAM on the 2600 you'd have a hard time to use it as a stack, compiler temporary storage, software parameter stack and your own program variables all at the same time. I suspect that for any non trivial program you'd spend most of your time looking at the assembly language produced by your "C" code to see what it was doing to the extent that you might as well have written it in assembler in the first place ;).

 

Does not the Harmony allow for 8KBytes Accessible RAM? That may help in this case. I may not be well-read on the harmony setup but it's very tempting.

Edited by Csonicgo
Link to comment
Share on other sites

Does not the Harmony allow for 8KBytes Accessible RAM? That may help in this case. I may not be well-read on the harmony setup but it's very tempting.

 

There is no write signal available on the cart slot on a 2600. When RAM is read/written from/to on cart you use different addresses to access the same variable. By doing that the banks witching firmware knows the difference between a CPU read and write cycle and handles the data bus correctly.

 

On the CC65 compiler system you can create segments of memory. So you'd have a segment for read only RAM data (not the same as RODATA) and another segment for write only RAM data (not the same as BSS or DATA). In "C" you'd end up with code that looks like :-

 

wFoo=8;

....

t=rFoo;

 

Where wFoo is used to write a value and rFoo is used to read the same value back. Handling code like this creates more complex language statements. Simple "C" code like :-

 

++fred;

 

Would normally produce the following code sequence (only if fred has scope beyond the function) in assembler once compiled :-

 

inc fred

 

When you need to access two different memory regions to get the same effect the code becomes :-

 

wFred=rFred+1;

 

Which would compile to something like :-

 

clc
lda rFred
adc #1
sta wFred

 

Which adds a ton more cycles and ROM overhead as well.

 

You'd also have to modify all the standard library functions (which use the software parameter stack) to use the two separate memory space approach. Its certainly doable should anybody have the time or the inclination.

 

In my opinion batari Basic is much more suited to games development on the 2600 compared to "C" because its specifically adapted for it.

  • Like 1
Link to comment
Share on other sites

If there was a good C compiler/headers/ide for the 7800, I would start programming for it. I doubt cc65 produces tight enough code.

 

I've used CC65 "C" on the 7800 for several years now. Like most "embedded" style compilers you can adapt your coding style to get pretty good results. If a routine isn't performing well then rethink the algorithm or convert it to assembler (or both ;)) just like you would on any other platform. I also have my own games development library that is written in assembler for handling display lists, sprites, joystick, collisions, sound/music etc. which can be called from the logic/AI of the game written in "C".

Link to comment
Share on other sites

I've used CC65 "C" on the 7800 for several years now. Like most "embedded" style compilers you can adapt your coding style to get pretty good results. If a routine isn't performing well then rethink the algorithm or convert it to assembler (or both ;)) just like you would on any other platform. I also have my own games development library that is written in assembler for handling display lists, sprites, joystick, collisions, sound/music etc. which can be called from the logic/AI of the game written in "C".

 

 

I did something similar to this years ago for DOS. I wrote some assembly(8086) routines to handle the graphics and input, while programming the game logic in c.

 

If it were possible to produce games like this

 

 

/*Don't try to compile, you will break the matrix*/
#include <7800.h>
Byte *player={,,,,,,,,,,,,,,};
BYTE X=0;
BYTE Y=0;
void main void()
{
init7800();
Display->LoadSprite(0,player);
/*gameloop*/
while(1){
if(Joystick1->Right==1)X+=1;
if(Joystick1->Left==1)X-=1;
Display->ShowSprite(0,X,Y);
}
}

 

Then I would give it a go, otherwise, just not prepared to spend the time.

 

If a good commented library was publicly available, there would be far more homebrew games for the 7800. Especially if it added a layer of abstraction(i.e Don't need to know how the hardware works to create a game).

Edited by Matthew
Link to comment
Share on other sites

Then I would give it a go, otherwise, just not prepared to spend the time.

 

It kinda works like that.

 

If a good commented library was publicly available, there would be far more homebrew games for the 7800. Especially if it added a layer of abstraction(i.e Don't need to know how the hardware works to create a game).

 

You can't get away from not knowing something about the hardware unfortunately. The 7800 is a constrained system so techniques you might use on a multi-GHz PC with loads of RAM don't always scale down to 8 bitter capabilities. You need to know about MARIA's DLL, DLs, DLI's and how zones are broken down and composed otherwise you won't make interesting games. I do have plans to create a tool to help with that at some point. I have tools for graphics bitmap conversion for all MARIAs graphics modes (e.g. 160A, 160B, 320A, 320B, 320C and 320D) already done.

Link to comment
Share on other sites

Maybe that's the go. A light wait reusable multi-sprite kernel written in assembly, then the actual game is written in c for the on-board ARM.

 

Just have to wait for Harmony 2 for the 7800. (And a smart cookie to write the re-usable kernel + c libs).

Edited by Matthew
Link to comment
Share on other sites

I've got 4 projects in the pipeline for the 2600 that are mostly coded in C. The C is compiled as ARM code for the Harmony/Melody board. Homebrew topics exist for Space Rocks and Frantic, and source is available in their respective blog categories.

 

amaaazziiinggg. This is awesome. I can do C for ARM, as that's what my hobby is. can't wait to get started.

Link to comment
Share on other sites

With 128 bytes of RAM on the 2600 you'd have a hard time to use it as a stack, compiler temporary storage, software parameter stack and your own program variables all at the same time. I suspect that for any non trivial program you'd spend most of your time looking at the assembly language produced by your "C" code to see what it was doing to the extent that you might as well have written it in assembler in the first place ;).

I think I disagree.

bB does all those things and would probably benefit from a data stack.

I think the problem is the overhead involved in implementing one on a

processor not built for it. And I think that's more a problem of speed

than of space.

Edited by bogax
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...