I was recently interested in how to 'bload' some data on my commodore 64. For the sake of discussion the data isn't really relevant (it could be any blob of bytes).
Generally you can load a file into the memory address specified in the file itself by using the well known
LOAD "filename",8,1
where the value 8 represents the disk drive device id, and the 1 signals the file should be loaded into it's specified target address.
But I was curious if you could load data into a specific address (different from the one specified in the saved file) and stumbled on this snippet of code:
10 SYS 57812"NAME",8 : REM SET FILENAME AND DEVICE
20 POKE781,LO:POKE782,HI : REM SET TARGET ADDRESS
30 POKE780,0 : REM FORCE "LOAD"
40 SYS65439 : REM LOAD THE FILE
It seems reasonable to assume the pokes are setting up the input values for the SYS on line 40, which calls the kernel SCNKEY routine at $EA87 (via the jump table address $FF9F). (According to Mapping the Commodore 64, 780-783 are loaded into .A .X .Y and status registers when SYS is invoked.)
But I can't make sense out of syntax of the first SYS on line 10, nor do I understand why the code would want to call SCNKEY to load a file into memory. Obviously this is exploiting some trick on the 64, but I'm not savvy enough to grok the magic here.
My actual goal is to find a small ML snippet that will load any filename into a given memory address. So this example (being close) is really just a starting point, I might be barking up the wrong tree entirely. But I would still like to understand how this code works.
Full disclosure: I am not in a position to actually try this for another week - so this entire process is a thought experiment right now. I am assuming the code above actually works.
EDIT
My question above was motivated by my desire to learn how to load a file into any target address from assembly or ML. I thought if I understood how the BASIC routine worked, I could translate it to assembly - but that thought process turned out to be a red herring. For those interested, I eventually worked out the following snippet in CBM prg Studio v3.14:
*=$C000
SETLFS = $FFBA ; set logical file parameters
SETNAM = $FFBD ; set filename parameters
LOAD = $FFD5 ; load from a device
loader lda #$01 ; logical file number
ldx #$08 ; device number
ldy #$00 ; secondary address
jsr SETLFS
lda #$08 ; length of filename in characters
ldx #<FNAME ; address of filename (lo)
ldy #>FNAME ; address of filename (hi)
jsr SETNAM
lda #$00 ; 0 = load, non-zero = verify
ldx #$00 ; target load address (lo)
ldy #$C0 ; target load address (hi)
jsr LOAD
rts
FNAME text “filename”