Jump to content

Tutorial Apps

Sign in to follow this  

Programs to help you learn various aspects of the X16

1 file

  1. File Loader Tutorial

    Introduction
    Here is a little demo of how to dynamically load files in RAM bank in assembly.
    It's very simple to do but I think that it can be helpful for someone who don't know how to do this right away. In fact I personally would love to see more of this kind of programs in the download section 🙂
    How this loader works ?
    First thing to do is to tell the Kernal that we want to use a logical file. For this we need to use the SETLFS subroutine.
    From the "C64 Programmer Reference Guide" :
    Since we want to load from the disk (or filesystem) we'll need to use the device number 8. The logical file is not important so we use the file 0.
    Also, as we want to relocate the program into a bank at $A000, we'll set the Y register to #0 to activate secondary address mode.
    Next step is telling the Kernal which file we want to load. For this we'll use the SETNAME subroutine.
    From the "C64 Programmer Reference Guide" :
    For this we'll need to store our file names somewhere in our program so we write at the bottom of our file the names as a string of petscii characters. We then prepare our registers with the size of the filename to load, and then the address.
    Our final step to load a file is obviously the LOAD subroutine.
    From the "C64 Programmer Reference Guide" :
    As the Reference guide said, we want to load a file so we set our A register to 0 and since we want to load to banked RAM ($A000) we enter the address in our X and Y registers.
    One last thing that we need to do just after each of our LOAD calls, is to verify that our file has been successfully loaded. For this, we'll need to use the READST subroutine.
    From the "C64 Programmer Reference Guide" :
    As usual, following the Reference guide, all we need to do is call this subroutine just after our LOAD call, and check the content of the Accumulator. If zero, the load was successful.
    And that's all ! You can chain file loading as much as you need, and even you just need to call SETLFS once at the start of the chain.
    Note that you'll need to switch the bank between file loads to prevent overwriting previously added program. And since Bank 0 is also reserved you'll need to first switch to bank 1 and start from here.
    At the end you can also load a file in place of the loader, just avoid overwriting memory where the code is currently being executed. You can for example leave this kind of code in your first bank and at last run it to load a program from $0800 to $9EFF.
    Kernal Subroutines full documentation : https://www.pagetable.com/c64ref/kernal/
    Post Scriptum
    If you have any suggestions for the code or even want to change things in this description, don't hesitate to tell me !

    26 downloads

       (0 reviews)

    0 comments

    Updated

Sign in to follow this  
×
×
  • Create New...

Important Information

Please review our Terms of Use