Jump to content
IGNORED

Format of .XEX files?


Recommended Posts

Hi!  I am working on a text adventure for the C64 and eventually port it to the C128, Plus4, Apple2E and Atari8 platforms.  In the mean time, I am working on an open-source version with enough to derive other text adventures.  Now, I have an optimization technique called the Cubby-Hole technique.  This puts code and data in locations used by the BASIC and OS but not needed by the program.  I know some things about the .XEX file's makeup.  I know that I can load multiple chunks into memory but don't know enough about the format.  What's the format?

  • Like 1
Link to comment
Share on other sites

One would hope your assembler or toolset will take care of that for you.

 

E.g. in MADS you have the ORG to determine the load address and then optionally an INI between segments if you want to run some code between block loads (for example to move data to RAM under the OS) and finally a RUN statement to launch the main code.

Link to comment
Share on other sites

Binary files in the A8 computers are composed as a sequence of blocks of data. Each block must be preceded by two words: and a loading address (A) and a terminating address (B), and then (B-A+1) bytes of data. The bytes in words are in Lo-Hi order.

 

The first block must be preceded by the word $FFFF, and any other block may omit it.

 

So, if you want to load arbitrary data in different portions of the memory, just precede each block of data with the corresponding A and B values, and the file itself with $FFFF.

 

On 9/11/2021 at 4:43 PM, Harry Potter said:

how do I define a start address for a specific module or not to run the module?

There are two special vectors in memory: $02E0 (RUNAD) and $02E2 (INITAD). As soon as you load a value in INITAD, the loader or OS will JSR to the pointed address, and at the end of the load, the OS will JMP to the RUNAD if it was loaded.

 

On 9/11/2021 at 4:38 PM, Harry Potter said:

I need to set up the config myself.

If you can do perl commands, I wrote a tool to manage XEX files, which it can also create XEX files from binary data files:  XEX-Filter

Edited by vitoco
  • Like 1
Link to comment
Share on other sites

Again, you shouldn't have to. Lets look at atari-asm-xex.cfg

FEATURES {
    STARTADDRESS: default = $2E00;
}
SYMBOLS {
    __STARTADDRESS__: type = export, value = %S;
}
MEMORY {
    ZP:      file = "", define = yes, start = $0082, size = $007E;
    MAIN:    file = %O, define = yes, start = %S,    size = $BC20 - %S;
}
FILES {
    %O: format = atari;
}
FORMATS {
    atari: runad = start;
}
SEGMENTS {
    ZEROPAGE: load = ZP,      type = zp,  optional = yes;
    EXTZP:    load = ZP,      type = zp,  optional = yes; # to enable modules to be able to link to C and assembler programs
    CODE:     load = MAIN,    type = rw,                  define = yes;
    RODATA:   load = MAIN,    type = ro   optional = yes;
    DATA:     load = MAIN,    type = rw   optional = yes;
    BSS:      load = MAIN,    type = bss, optional = yes, define = yes;
}

 

The code will be launched at the start address of the file... so the first MEMORY block of the file is MAIN and the start address is the STARTADRESSS, which (if not overridden) is $2E00.

 

Obviously there are 100 and 1 ways to skin a cat and so if this isn't sufficient you'll need to be more specific about what you want to achieve, what you've tried so far etc

Link to comment
Share on other sites

5 minutes ago, Harry Potter said:

I have to load a module in $02E2, right?

Yes if you want to initialize something in the middle of the loading and then continue with the loading of the remaining blocks/modules.

 

But if you want to run your code after all the modules were loaded, you need to add a 2 byte module at $02E0 with the run address, at the end for simplicity.

 

Link to comment
Share on other sites

Thank you, again.  I am also working on a memory expansion for the Atari XL to load data into the extra RAM (Name?) and allow use of some of the OS's memory that are unused by cc65 programs.  It currently works, but I need to add significant functionality to it, i.e. support of extra RAM in printf() and direct printing.  I've been working on the Hidden64's (the C64 version of the library) free() function but have problems.

Link to comment
Share on other sites

On 9/11/2021 at 10:19 PM, Harry Potter said:

I know that I can load multiple chunks into memory but don't know enough about the format

if as a human from C64 you are disturbed by RUN and INIT addresses ($ 2E0- $ 2e3) then they can be configured elsewhere, also blocks can be compressed with LZ4, aPL or ZX0 algorithms. For example, LiteDOS handles LZ4 compressed blocks very well. An advanced user can also create xex in such a way that it can be loaded from a non-linear block order - eg in the case of paragraph games it would apply.

 

chkxex.exe eve.cex

 

001:     $02E0 $02E1: $0002
     RUN $0C00
002:     $0C00 $2E63: $2264 (LZ4:1352)
003:     $0080 $00EC: $006D

Len: 5 101 bytes

 

 

chkxex.exe eve.obx

 

001:     $02E0 $02E1: $0002
     RUN $0C00
002:     $0C00 $2E63: $2264
003:     $0080 $00EC: $006D
Len: 8 929 bytes

 

Link to comment
Share on other sites

59 minutes ago, Harry Potter said:

Should I just exclude the trailer?

On 9/11/2021 at 10:07 PM, Wrathchild said:

you'll need to be more specific about what you want to achieve

Presumably you want to launch the program when its loaded and so this would be left as-is?

 

If needs be just make a dummy binary using the segments in your config file and try and load it into Altirra with the debugger enabled and this will output the segments loaded and entry addresses ran.

 

If that doesn't match your expectation then you can post that up and we can take a look

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