Hi,
First i'd like to greet everybody. I was first introduced to the Commodore 64 back in -85. Thats when i got my own C64. Although, there were already lots of software available, i interrested more and more about developing software myself. And i did some assembly coding, small demos and stuff. After two years i moved to Amiga but C64 is still the machine i like. Years passed and every now and then i studied the design of C64 and 6502. I become interrested about processors and compilers. Few years ago i started to develope my own multiplatform compiler toolchain. Progress is slow but maybe one day the whole thing is ready. Propably ever, but that doesn't matter. However, thing which lead to my problem is that, because i've finished my assembler, i thought it would be cool to code a little demo and test the assembler a bit. So, i coded a little iff-viewer for C64 and 1541.
Now into my problem. I tested the demo with Vice and everything seems to work. My assembler outputs a .prg file and it could be run in vice without problems. The demo loads an .iff-files from the device 8 and Vice kindly mapped the whole Windows directory as a big disk. So i though, well, the demo is ready. I want to run it in the REAL C64. Hell, it uses interlaced display and all. So i generated an .d64 image which contained my demo.prg and bunch of .iff files. That image didn't run in vice at first time but i sorted it out, maybe. I manage to generate a .d64 image which worked with Vice but when i used my MMC64 to transfer it to a real 1541 floppy the demo didn't work any more.
I have the C64 reference manual and the documentation there is very poor. Thats why i suspect that i coded the file handling such an incompatible way that it works in the Vice with certain circumstances but not in the real C64.
I include my file handling module here so somebody with good knowledge can check it out. Or point me to a place where i could find a proper documentation/examples.
Regards
Code:
SETNAM = $ffbd
SETLFS = $ffba
OPEN = $ffc0
CHKIN = $ffc6
CLOSE = $ffc3
GETIN = $ffe4
FILE = 5
DEVICE = 8
SEC = 0
.code
;**************************************************************
; openfile: - Open a file for reading
; INPUTS:
; - X, LO-byte of filename
; - Y, HI-byte of filename
; RETURNS:
; C=0 if succesfull
; REMARKS:
; Filenamebuffer pointed by X/Y registers is
; in ASCII and zero terminated.
;
.public openfile
openfile:
stx fn+1 ; calculate length of filename
sty fn+2
ldy #$ff
ofloop:
iny
fn: lda $ffff,y
sta filename_buf,y
bne ofloop
tya
ldx #lo(filename_buf)
ldy #hi(filename_buf)
jsr SETNAM
lda #FILE
ldx #DEVICE
ldy #SEC
jsr SETLFS
jsr OPEN
bcs exit
ldx #FILE
jsr CHKIN
clc
exit:
rts
.bss
filename_buf: ; temporary storage for a file's name
ds.b 16+1
.code
;**************************************************************
; closefile: - Closes a file
;
.public closefile
closefile:
lda #FILE
jmp CLOSE
.code
;**************************************************************
; readfile: - Reads a file
; INPUTS:
; - A, Amount of bytes to read
; REMARKS:
; Read bytes are stored to a global 'buffer'
;
.public readfile
readfile:
sta rfcomp+1
stx rfoldx+1
sty rfoldy+1
lda #0
sta rfptr+1
rfloop:
lda #FILE
jsr GETIN
rfptr: ldx #$ff
sta buffer,x
inx
stx rfptr+1
rfcomp: cpx #$ff
bne rfloop
rfoldx: ldx #$ff
rfoldy: ldy #$ff
rts
.bss
.public buffer
buffer: ; file read buffer
ds.b 256