Jump to content
  • 0

How to load part of a file into memory?


Inkbox
 Share

Question

I have a file that exceeds the size of the memory of the system, so I can't load it all in at once. What is the way I could specify which part of it I load into memory? I've been looking at routines like MACPTR, but I can't seem to tell if there is any way to load the file in, not from the beginning of the file, but from a specific point in the middle of it. My only other thought is to use MACPTR and read until I get to my desired section and then finally copy that, but that solution seems clunky. Thanks for any ideas. 

Link to comment
Share on other sites

11 answers to this question

Recommended Posts

  • 0

I have a vague memory of there being a discussion somewhere about the FAT32 filesystem being more friendly to file seeks. I don't know whether the ability to do it has been implemented in the DOS part of the kernal, or if not, whether it's planned to be. In any case, with r41 it's only going to work with the SD card image, because that's the only well-supported storage device on the emulator. The host file system is basically a highly simplified load/save only interface.

Link to comment
Share on other sites

  • 0
  • Super Administrators
On 11/22/2022 at 1:29 PM, kaos said:

Whoaaa... I just read through the C64 DOS commands, and the KERNAL API, and it seems it does not have a concept of a file seek position..? Weird!

One always has to load/save an entire file??

Nope. There is a special file type on CBM DOS known as the "REL" file. This allows you to specify a record size and seek to specific records within a file. It's super awkward, and it would have made more sense just to implement a byte position command at the beginning, but trust computer engineers to make things more complicated than needed, for no real reason but that they can. 

 

  • Thanks 1
Link to comment
Share on other sites

  • 0
  • Super Administrators
On 11/25/2022 at 12:52 PM, neutrino said:

Perhaps an idea to implement "seek()" in the Kernal? Basic?

No. That's not how Commodore disk access works, and it never has been. There's a perfectly accessible method of doing so already, by sending a command on the command channel. 

The whole design of Commodore's disk system is for the disk drive to handle the complex side of the operation, and for the computer itself to just provide a dumb communication channel, so aside from the basic I/O commands (LOAD, SAVE, OPEN, PRINT#, INPUT#, GET), there is no need or expectation of things like record handling for REL files, seeking in sequential files, or things on the printers, like changing fonts or printing bitmapped graphics. That's why the command channel exists - to allow the I/O device to handle those things on its own, without needing a command for everything on the host system.

If you need a "Seek" command in BASIC, you can implement it as a subroutine. If you need a SEEK command in machine language, you an implement it as a subroutine. If you need a seek command in C or Pascal... you can implement it as subroutines. There's no need to add device-specific commands to the KERNAL or BASIC, since once you start down that path, it never ends.

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.

Guest
Answer this question...

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

 Share

×
×
  • Create New...

Important Information

Please review our Terms of Use