Looking for some good disk I/O examples
Posted: Sat Jan 29, 2022 7:34 pm
Hey guys,
So in BASIC, I can use commands like OPEN, PRINT#, INPUT# and CLOSE to read/write files on disk; but how would this work in Assembly? I've done some research and it looks like there are some memory addresses in the Kernal I can work with for this, but the only examples I've been able to find are for the C64. Of course I also looked at cc65, just cuz (and to be honest, I'd prefer C over Assembly most of the time) but cc65 can do inline Assembly, so learning it in Assembly would help with cc65 as well. So it looks like the process is roughly:
1. Set a couple registers and JSR SETNAM (to set the name of the file to save, like in BASIC the OPEN command has that parameter)
2. Set a few more registers and JSR SETLFS (to set a few numbers I don't fully understand even in BASIC, but they work
). Seriously though I know the first number is kind of like a pointer (like the "1" in i.e. INPUT#1). And I know second one is the device number, 1 for tape or 8[-15] disk. The third ("secondary") number is a total mystery to me, and I'm guessing it's because the examples (and Kernal reference) I found were for the C64.
3. JSR OPEN
4. I forget the shorthand word for this, but it was to "check in" or "check out" (set the default input/output device). It's funny, their shorthand is so goofy that at first I was like, "what the... JSR CHICKEN?"
5. I'm guessing I would need to use GETCHAR and PUTCHAR after that (depending on whether I'm reading or writing)
6. Then there was a "restore default input/output device" subroutine (again, I forget the shorthand)
7. then JSR CLOSE and you're done
But when I tried to do that (using code I accidentally deleted), it seemed to save blank/empty SEQ files. So I kind of feel like I'm missing a step or three (maybe something in those mysterious numbers for SETLFS, or something else?). Or maybe the addresses are different for the VIC than they were for the C64? Regardless, it would sure be great if there were some tutorials out there.
So in BASIC, I can use commands like OPEN, PRINT#, INPUT# and CLOSE to read/write files on disk; but how would this work in Assembly? I've done some research and it looks like there are some memory addresses in the Kernal I can work with for this, but the only examples I've been able to find are for the C64. Of course I also looked at cc65, just cuz (and to be honest, I'd prefer C over Assembly most of the time) but cc65 can do inline Assembly, so learning it in Assembly would help with cc65 as well. So it looks like the process is roughly:
1. Set a couple registers and JSR SETNAM (to set the name of the file to save, like in BASIC the OPEN command has that parameter)
2. Set a few more registers and JSR SETLFS (to set a few numbers I don't fully understand even in BASIC, but they work

3. JSR OPEN
4. I forget the shorthand word for this, but it was to "check in" or "check out" (set the default input/output device). It's funny, their shorthand is so goofy that at first I was like, "what the... JSR CHICKEN?"

5. I'm guessing I would need to use GETCHAR and PUTCHAR after that (depending on whether I'm reading or writing)
6. Then there was a "restore default input/output device" subroutine (again, I forget the shorthand)
7. then JSR CLOSE and you're done
But when I tried to do that (using code I accidentally deleted), it seemed to save blank/empty SEQ files. So I kind of feel like I'm missing a step or three (maybe something in those mysterious numbers for SETLFS, or something else?). Or maybe the addresses are different for the VIC than they were for the C64? Regardless, it would sure be great if there were some tutorials out there.