[Coco] How do SAVEM and CSAVEM files work?
David Broman
davbrdavbr at hotmail.com
Thu Oct 30 18:59:00 EDT 2025
Those segment headers are sometimes referred to as preamble (the 00 ones) and postamble (the ff one). If you search the cocopedia (run by some cool guy) for those words, you'll find an article with this info as well. LOADM happily obeys multiple preambles, but, as Sean mentioned, SAVEM won't write them.
I view the .bin files generated by lwasm the hard way, in a hex / binary editor. But it's enough to see what's going on if you don't mind doing a little arithmetic to help you skip around in the file to find the next preamble.
-----Original Message-----
From: Coco <coco-bounces at maltedmedia.com> On Behalf Of Sean Conner via Coco
Sent: Thursday, October 30, 2025 3:20 PM
To: Allen Huffman via Coco <coco at maltedmedia.com>
Cc: Sean Conner <sean at conman.org>
Subject: Re: [Coco] How do SAVEM and CSAVEM files work?
It was thus said that the Great Allen Huffman via Coco once stated:
> I just noticed that the lwasm assembler will generate multiple
> segments if you have an RMB in your code. For example:
>
>
> ORG $3F00
> START RTS
> END
>
> If you use the -fbasic option, you get a BASIC loader that loads data
> at 3F00, as expected
>
> But if there is an RMB:
>
> ORG $3F00
> START RTS
> RMB 10
> RTS
> END
>
> …It makes two segments with a start-end for the first part (RTS) then
> a start-end for the next part, 10 bytes down.
>
> I assume if I put this in memory and did a CSAVEM/SAVEM, it has no
> idea about gaps like that so the file itself will just be one
> continual block of data”
Pretty much. The syntax for the CSAVEM/SAVEM commands don't really allow for multiple segments.
> 57 for RTS, then the zeros:
>
> 3F00: 57,0,0,0,0,0,0,0,0,0,0,57
>
> But M files support segments, such as multiple ORG statements, don’t they?
>
> ORG $3F00
> START RTS
>
> ORG $3F08
> START2 RTS
>
> END
Yup. In my assembler [1], when outputing a Coco binary file, will only generate multiple segments if it ends up being smaller. So, for instance, the following (contrived) example:
org $3000
rts
rmb 5
rts
will generate one segment, while:
org $3000
rts
rmb 6
rts
will generate two. A segment headers is five bytes long, and thus, any gap less than that isn't worth making a new segment. While a 1-byte gap might seem silly, there has to be a cutoff at some point and that's what I picked.
> Is there any utility in toolshed, etc. that can dump an M file and
> show how it looks inside?
I don't use toolshed, so I don't know, but I did write my own as it's not that hard. A Coco binary file has the following structure:
00 One byte marker for data block
LLLL two byte length of block
AAAA two byte address to load
FF One byte marker for end of binary file
0000 no length
AAAA execute at this address (unless 0000)
There can be multiple blocks starting with 00, and there should only be one starting with FF. What the data blocks are is anybody's guess, but I assume any block that overlaps the execution address does contain executable code.
-spc
[1] https://github.com/spc476/a09
--
Coco mailing list
Coco at maltedmedia.com
https://pairlist5.pair.net/mailman/listinfo/coco
More information about the Coco
mailing list