Streaming large files on the CoCoSDC

Back in 2017, Ed Snider released a cool video and audio player for the CoCoSDC on a CoCo 1. I thought it was wicked and at that time I remember fighting with the CoCoSDC to try and get some of my own files streaming on the CoCo. Ed was very helpful and I did manage to get it working. Next I used his player and had some fun making colour videos that could play on the coco 1 but I haven’t really looked at it since.

Last week I was watching a CoCoTalk video and Tim Lindner was discussing a new version of the manual for the CoCoSDC that he made. He was discussing a few programs he included that would make it easier to work with the CoCoSDC from an assembly language program.

I tried to interface the CoCoSDC using the updated info from his latest manual and using the programs included but I ran into problems. I fought with it for awhile and figured out exactly what I needed to do. Part of the frustration is there is a minimum file size of at least 79,360 bytes. The other limitation is the file must be padded to 512 byte boundaries.

To make it easier for myself and others in the future I created a library that is easy to use specifically for opening files for streaming and closing files on the SD card. The library has an explanation how to use it with your own assembly language programs.

I put the library and an example program to use the library on my GitHub page. I’ll give an explanation how to use it below.

In your own 6809 assembly program for the CoCo 1, 2 or 3 you must include the library from the my GitHub page called SDC_Stream_File_Library.asm. To use it you load X with the address of your filename a dot and the extension is 3 characters and end the filename with a zero/null byte then do a JSR OpenSDC_File_X_At_Start like this:

        LDX     #MountFile          * Memory location of Filename, terminated with a zero
        JSR     OpenSDC_File_X_At_Start   * Open a file on the SDC for streaming, 512 bytes at a time

If it opened the file ok then the carry flag will be clear, if there was a problem then it will return with the carry flag set. So you should deal with a file opening error in your program.

Also note that if the file isn’t at least 79,360 bytes and padded to 512 byte boundaries the CoCoSDC will lock up while checking to make sure it’s ok. The Library won’t return and will get stuck in an endless loop. So if your program is locked up it could be a problem with the size or the 512 byte padding of the file you’re openning.

Once you’ve successfully gotten your file open, next you read the two bytes from address $FF4A, such as LDU $FF4A, to read the next two bytes from the file on the SD card you do a LDU $FF4A. The CoCoSDC automatically gets the next two bytes and makes them available at the same address $FF4A. Continue reading words at $FF4A until you’ve read 512 bytes. Then you have to make sure the CoCoSDC has filled its buffer and is ready to continue feeding you more of the file at address $FF4A. The Following code will work to check the CoCoSDC is ready to continue giving you the rest of the file:

* After reading a 512 byte sector we check if we are done and also make sure the SDC's buffer has been fully loaded again
PollSDC:
        LDB     ,Y                  * Poll status, get status Bits 000000xx:
                                    * Bit 1 set = SDC Buffer has been loaded, Bit 1 clear = SDC Buffer is still being loaded
                                    * Bit 0 set = Not at End of File yet,     Bit 0 clear = Reached the End of the File
        ASRB                        * BUSY --> carry
        BCC     StreamDone          * exit if BUSY cleared (we reached the End of the File)
        BEQ     PollSDC             * continue polling if the Buffer is not completely loaded

        DECA                        * Decrement the sector counter
        BNE     LoopAgain           * keep reading if we haven't counted down to zero

StreamDone:

Then keep reading another 512 bytes and so on…

Once you are done reading from the file, you must close it. To do this with the library you do the following command:

StreamDone:
        JSR     Close_SD_File       * Close file and put Controller back into Emulation Mode

That’s all you need to open a file from the beginning and close it once you’re done. The other thing you can do with the library is open the file at a specific 512 byte block. Instead of having to read through the file to get to the part you want you can use the following code (example of starting from the 6th logical sector):

* Open a file for streaming starting at Logical Sector Number, each sector is 512 bytes.  The LSN is in A & U where
* the Logical Sector Block, 24 bit block where A=MSB (bits 23 to 16), U=Least significant Word (bits 15 to 0)
*
    LDA  #$00
    LDU  #$0006          * Start at 6 * 512 bytes from the beginning of the file
    JSR  OpenSDC_File_X_At_AU  * Open File pointed by X starting at (A and U)

One last thing to note I’ve tried the code on a CoCo 1 and a CoCo 3 (even at double speed) and it works well. My CoCoSDC is currently running MCU version 121 and SDC DOS version 1.6

See you in the next post,

Glen

This entry was posted in Uncategorized. Bookmark the permalink.

10 Responses to Streaming large files on the CoCoSDC

  1. Daniel says:

    I haven’t looked at the documentation at all yet but it appears that streaming is simply serial data in 512 byte blocks from beginning to end with no ability to control which block comes next.

    My first thought about making use of this feature is making a game like the old “dragons lair” where the game responded to user action during a video playback and it would then play a death scene if it was the wrong action or a survival scene if it was right. To do this, one would need to be able to jump around to different scenes in the sequence and to be able to jump back when a life is lost.

    • Daniel says:

      Oh I missed that you commented on jumping to blocks…. OK nevermind

      • nowhereman999 says:

        Making a Dragon’s Layer type of game would be cool and streaming from the CoCoSDC would mean you could have a giant video file to go through. Great idea!

      • Daniel says:

        Yes and a nice aspect of this is if it is designed for the CoCo(1,2 or 3) the graphics stream could be optimized for either platform’s graphics.

        All that would be needed would be a handful of artists to create all of the animation sequences and then another process to filter the cells to optimize for the graphics.

  2. tlindner says:

    Looks like I have a few more tidbits of information to add to the manual.

    • nowhereman999 says:

      Hey Tim,

      Feel free to add my CoCoSDC Streaming library to the PDF or a link to the Github and anything else you think will be useful.

      Cheers,
      Glen

  3. Darren Atkinson says:

    I don’t understand why you need to pad the file names to 8+3 characters. The firmware accepts a name like “TEST.TXT” as is. Also, it’s a good idea to check the FAILED bit (bit7) in the status register while you are polling for READY to avoid an endless loop if something goes wrong.

    • nowhereman999 says:

      Hi Darren,

      Thanks for the reply, your CoCoSDC is an amazing product. I’ll have to do more testing on the filename and I did plan to update the library to handle failures a little more gracefully.

      Cheers,
      Glen

    • nowhereman999 says:

      Hi Darren, I updated my post to correct the filename format as you specified. I was going by some information I got from an old email from Ed Snider and the format was working for me. But of course it’s your product so you know exactly how it works. Thanks for letting me know.

      I found a typo in your amazing “Motorola 6809 and Hitachi 6309 Programmer s Reference” PDF. It’s not a big deal but I thought you’d like to make it as perfect as can be. On page 132 the SUB(16 bit) instruction shows “C The Carry flag is set if a borrow out of bit 7 was needed; cleared otherwise.” I’m pretty sure it should be bit 15 not bit 7. Maybe you already fixed it in a newer version than the copy I have which says (c) 2009, I didn’t see a version # of the document.

      Thanks again for producing this excellent reference manual. I use this PDF all the time!

      Cheers,
      Glen

      • Darren Atkinson says:

        Yes, that should actually say “if a borrow into bit 15 was needed”.

        Unfortunately that document was created with old software (FrameMaker) that will no longer run on any of my current machines. It’s unlikely that there will be any further revisions.

Leave a comment