Jump to content
IGNORED

Locating blocks of memory in cc65


Recommended Posts

I want to reserve some blocks of memory in programs developed with cc65. I want 4 pages, page 6 through page 9 for instance. I am unsure what to do...any one have an idea how to lay down a block of 256 bytes at a specific location in C and have the compiler reserve space? I know how to build a pointer to an arbitrary location, but keeping the memory preserved is the issue.

Link to comment
Share on other sites

Hi Dan,

 

Are you writing in 'C' or in assembly?

I think the standard build model for the Atari assumes

that DOS is loaded, therefore all that memory is already

available to you.

 

In 'C' you'll need to define a pointer to the start of

your required memory area, and in assembler you

can either use a define, or alternatively you can

use a customer linker configuration file to declare

the blocks for you. I can probably dig up some

examples of this if required.

 

Regards,

Mark

Edited by Wrathchild
Link to comment
Share on other sites

Hi Mark. Mostly C...I know how to define pointers and etc., but I am not sure how to reserve space from use at compile/link time. That is, setting up a particular page to have a particular block of memory loaded into it, that won't get written over later in the load or during runtime...I think I will be needing to investigate custom linker setups, as you mention. SO if you could post some linker examples that would be very helpful I think.

Link to comment
Share on other sites

Hi,

 

This was a little experiment I did to check that it was impractical

to write DLIs in C. VBIs could be OK, but really you're best of

using assembler for these ;).

 

However, it should give you an idea of how the configuration file

can be used to provide your memory blocks, segments can be

defined to reside in these memory blocks. Start with 1 per block

to keep things simple, but later you can use the .align statement to

provide addresses on boundries. It then shows how these can be

made visible to a 'C' program via a simple assembler file and

finally the C file gives examples of utilising the pointers.

 

Hope that helps, no doubt some of it could be done slightly differently.

 

Regards,

Mark

vbi_dli.zip

Edited by Wrathchild
Link to comment
Share on other sites

Excellent, thanks!

 

I find it useful, when I need to use assembly, to wrap it in C with the asm() function. That way I can stick with relatively normal control of flow constructs for most stuff but still drop into asm when needed. A DLI function wouldn't be anything more than C in name only though, I would expect.

Link to comment
Share on other sites

http://www.atariage.com/forums/index.php?showtopic=67762

 

Check out also the Gauntlet ROM implementation on this Forum too.

Coding to cart is fun - but I haven't really tried doing 'C' work here yet.

I'd like too try it to see, but there may be some considerations that need

to be looked into with the way that CC65 is handling the heap/stack etc.

 

Has anyone else attempted this yet?

 

Regards,

Mark

Link to comment
Share on other sites

  • 2 weeks later...
This was a little experiment I did to check that it was impractical to write DLIs in C. VBIs could be OK, but really you're best of using assembler for these ;).

 

There's also the small matter that CC65 won't save any of the working zero page registers, so your interrupt routine can't use any C library routines anyway without crashing your program. At least that's my understanding. :D

 

You can reserve memory with CC65 in a couple of different ways (that I know of at least):

 

1. Use the heap functions (malloc and family) which adds a lot of overhead to your program.)

 

2. Reserve space with a custom linker config script (you may need to fill your exe file to get the memory layout you want at load time, or deal with the loading some other way.)

 

3. Do what I do and play fast and loose, and just declare a pointer to some portion of memory you know isn't used by your program, the C stack, the heap or screen memory. ;)

 

Mark's way is probably the best, since the linker takes care of it all and warns you when a memory overflow occurs.

 

To the original question: the standard CC65 linker config script doesn't touch $600-900, but DOS exists in this area. There may be some issues with using CC65 programs without a DOS loaded though.

Edited by Shawn Jefferson
Link to comment
Share on other sites

Well, depending on what you do, you could probably get away with a c function in an interrupt, at least as far as the ZP stuff goes. CC65 uses 23 or so locations, so you can also save/restore them and there's a call for doing so in the CC65 internals. The actual function call mechanism itself doesn't touch any ZP, but the body of most functions does.

 

1. Actually, overhead from usage of these functions is only bad if you constantly call them. Using it to get a few blocks here and there during initialization is negligible. Then again, in this environment they really don't do much for you other than keeping you from walking on your own memory...they have no knowledge of any other "reserved" areas besides their own.

 

2. Yah this is the way to go I think.

 

3. Nah........I need to be more careful than that with the app I am doing. It'll drive me crazy later if I don't.

 

page 6 is clear even with dos loaded, isn't it?

Link to comment
Share on other sites

1. Actually, overhead from usage of these functions is only bad if you constantly call them. Using it to get a few blocks here and there during initialization is negligible. Then again, in this environment they really don't do much for you other than keeping you from walking on your own memory...they have no knowledge of any other "reserved" areas besides their own.

 

I meant more the overhead in size.

 

3. Nah........I need to be more careful than that with the app I am doing. It'll drive me crazy later if I don't.

 

Programming is all about the challenge! ;)

 

page 6 is clear even with dos loaded, isn't it?

 

Yeah, but that's only 256 bytes.

 

If you load your program without DOS somehow (via flashcart, etc...) then I think you could start your program at $400 (??)

Link to comment
Share on other sites

If you load your program without DOS somehow (via flashcart, etc...) then I think you could start your program at $400 (??)

Indeed, $400->$47F being the cassette/single density disk I/O block buffer.

 

I find myself retaining its use in the replacement I/O routines for carts, e.g.

copy correct 128 bytes from cartmem (when correct bank selected) to $400

and then swap out the cart and copy from $400 to desired destination address.

Though actually easier and quicker to shift 256 byte pages around instead,

this often retains compatability with the existing I/O routines found in games.

 

I also often find that using the end of the page 1 stack (i.e. $100 upwards)

is a great little holder for code snippets. If you know the stack isn't going to

go below say $180 then there's half a page free! I've haven't really looked

at CC65's hw-stack usage to know what's safe when writing in 'C' though.

 

Regards,

Mark

Link to comment
Share on other sites

I also often find that using the end of the page 1 stack (i.e. $100 upwards)

is a great little holder for code snippets. If you know the stack isn't going to

go below say $180 then there's half a page free! I've haven't really looked

at CC65's hw-stack usage to know what's safe when writing in 'C' though.

 

I don't think it uses the hw stack that much, at least, not that much more than any other typical program would. The C stack is used quite a bit, of course, but that is in upper memory (under the screen IIRC.)

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...