Jump to content
Davideesk

Using CMDR-DOS in 65c02 assembly

Recommended Posts

I couldn't find any resources on how to create and change directories on the SD card using assembly, so I wrote some helper functions based off the code in "x16-rom/basic/x16additions.s". These functions show how to use the KERNAL API to send commands and get file/directory names from CMDR-DOS.

I wrote the functions to be simple, so error & SD card checking will be left up to the reader. The code itself was written using the ACME assembler, but it should be easy to convert it to other assemblers.

Code: https://gist.github.com/DavidSM64/a036a622f4b7a2d8364c355e72766eb7

The 3 functions are:

  1. execute_dos_command
    • Takes in a string pointer that contains a channel 15 command and executes it.
    • A table of commands can be found here: https://github.com/commanderx16/x16-rom/tree/master/dos (It is the large table that starts with "BLOCK-ALLOCATE")
    • Examples:
      • "MD:FOO" = Creates a new directory called FOO
      • "CD:FOO" = Enters the FOO directory
      • "CD:.." = Enters the parent directory
      • "RD:FOO" = Deletes the FOO directory
  2. get_dos_directory
    • Takes in a string pointer that contains valid directory syntax (see examples), the length of that input string, and an output pointer where the result will be written to.
    • This function isn't particularly useful, since it also outputs the formatting used in BASIC.
    • Examples:
      • "$" = List out everything in the current directory
      • "$:*=P" = Only list out files
      • "$:*=D" = Only list out directories
      • "$:FOO*=D" = Only list out directories that start with FOO (FOO, FOO2, FOOBAR, etc.)
    • The output will look like this:
      • spacer.png
      • The first 4 bytes can be ignored
      • For each line:
        • 2 bytes at the start for the block count
        • Then follows a certain number of bytes (might be a variable amount, the line ends with $00)
  3. get_dos_dir_entries
    • Same inputs as get_dos_directory
    • This function only outputs the file / directory names, separated by a $00.
    • Returns the number of entries in the current directory into the accumulator.
    • The output will look like this:
      • spacer.png
      • This will not show the file type, but files typically have an extension while directories do not.

 

  • Like 2

Share this post


Link to post
Share on other sites

Very useful! I have been wondering if and how you for example can load all files with a certain extension. With help of your third function this seems absolutely doable.

  • Thanks 1

Share this post


Link to post
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.

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.


×
×
  • Create New...

Important Information

Please review our Terms of Use