Friday 26 February 2016

An old dog remembers old tricks

Each time I return to a platform there's the ramp-up time where I re-learn what I knew before. And Knight Lore on the Coco3 is no different. It has been a few years since Lode Runner after all... but then I also find I learn something new as well.

Today's exercise was getting 20KB of data loaded into memory from disk, preferably independently of the main executable - something I did for Lode Runner. In the end it's almost trivial, but when you can't recall how to do it, and then you encounter some corruption along the way, it chews up your spare time. In the end it was all resolved and I learned something new about the Coco3.

The data - location and graphics data in this case - resides in a single .ASM file generated by a custom utility from a memory dump of Knight Lore running in MESS. The same utility I used to generate all the C data structures and arrays. This .ASM file is then .included in a very small file which is then built and LOADM'd from BASIC before loading and running the main executable.

For the curious, here's that file

.include "coco3.asm"

        ; $2000,$4000,$6000
        .org    MMUTSK1+1
        .db     DATA_PG1, DATA_PG2, DATA_PG3

        .org    0x2000
.include "kl_dat.asm"
       
        ; $2000,$4000,$6000
        .org    MMUTSK1+1
        .db     0x39, 0x3a, 0x3b


This loads directly into the GIME's MMU registers on-the-fly, allowing the data to be loaded into pages of 128KB memory not mapped by default. And lastly it restores the default page mapping. It doesn't even have to be executed, simply loading it does the trick. When the main executable runs, it simply re-maps the pages into memory and the data magically appears.

No comments:

Post a Comment