I am trying to learn how to write files to disk using kernel routines, following this Codebase64 Tutorial .
I copied my routine written in Acme Crossassembler, below. He could not open the file and gives an error message: "FILE NOT OPENED"
; Definitions
SETNAM = $FFBD
SETFLS = $FFBA
OPEN = $FFC0
CHKOUT = $FFC9
READST = $FFB7
CLOSE = $FFC3
CLRCHN = $FFCC
CHROUT = $ffd2
;Basic Start
* = $0801 ; BASIC start address (
!byte $0d,$08,$dc,$07,$9e,$20,$34,$39 ; BASIC loader to start at $c000...
!byte $31,$35,$32,$00,$00,$00 ; puts BASIC line 2012 SYS 49152
;Program Code
* = $c000 ; Can be executed by writing sys 49152
ldx
ldy
jsr printMessage
save2file:
; call SETNAM
lda
ldx
ldy
jsr SETNAM ; call SETNAM
; call SETFLS
lda
ldx $BA ; last used device number
bne +
ldx
+ ldy
jsr SETFLS ; call SETLFS
;call OPEN
jsr OPEN ; call OPEN
bcs .error1 ; if carry set, the file could not be opened
; call CHKOUT
ldx
jsr CHKOUT ; file 2 now used as output
; Copy border color to the file
jsr READST ; call READST (read status byte)
bne .error2 ; write error
lda $d020 ; get byte from memory
jsr CHROUT ; write to file
ldx
ldy
jsr printMessage
.close
lda
jsr CLOSE ; call CLOSE
jsr CLRCHN ; call CLRCHN
rts
.error1
ldx
ldy
jsr printMessage
jmp .close
.error2
ldx
ldy
jsr printMessage
jmp .close
fname: !tx "DATA,S,W"
fname_end:
message0: !by 141 : !scr"SAVING" : !by 0
message1: !by 141 : !scr"COLORS SAVED" : !by 0
errorMsg1: !by 141 : !scr"FILE NOT OPENED" : !by 0
errorMsg2: !by 17 : !scr"WRITE ERROR" : !by 0
;==========================================================================
; printMessage
; Prints null terminated string to the memory
; Input: x,y adress vector of text string
;==========================================================================
temp = $fb ;zero page pointer
printMessage:
stx temp ;save string pointer LSB
sty temp+1 ;save string pointer MSB
ldy
- lda (temp),y ;get a character
beq + ;end of string
jsr CHROUT ;print character
iny ;next
bne -
inc temp+1
bne -
+ rts
I prepared the basic procedure below using the C64 Programmer Reference. It works as expected in the same environment.
10 OPEN 3,8,3, "O:DATA FILE,S,W"
20 PRINT#3, "SENT TO DISK"
30 CLOSE 3
So why is my asm procedure not working?
I am testing on Vice 2.4
source
share