在 Commodore 64 上使用程序集写入磁盘文件
Writing a disk file using assembly on Commodore 64
我正在尝试学习如何使用内核例程按照此 Codebase64 Tutorial 写入磁盘文件。
我已经复制了我的例程,用 Acme Crossassembler 编写,如下所示。它无法打开文件并给出错误消息:"FILE NOT OPENED"
; Definitions
SETNAM = $FFBD
SETFLS = $FFBA
OPEN = $FFC0
CHKOUT = $FFC9
READST = $FFB7
CLOSE = $FFC3
CLRCHN = $FFCC
CHROUT = $ffd2
;Basic Start
* = 01 ; BASIC start address (#2049)
!byte [=10=]d,,$dc,,e,,, ; BASIC loader to start at $c000...
!byte ,,,[=10=],[=10=],[=10=] ; puts BASIC line 2012 SYS 49152
;Program Code
* = $c000 ; Can be executed by writing sys 49152
ldx #<message0
ldy #>message0
jsr printMessage
save2file:
; call SETNAM
lda #fname_end-fname ; file name size
ldx #<fname ; file name vector
ldy #>fname ; file name vector
jsr SETNAM ; call SETNAM
; call SETFLS
lda #[=10=]
ldx $BA ; last used device number
bne +
ldx # ; default to device 8
+ ldy #[=10=]
jsr SETFLS ; call SETLFS
;call OPEN
jsr OPEN ; call OPEN
bcs .error1 ; if carry set, the file could not be opened
; call CHKOUT
ldx # ; filenumber=2
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 #<message1
ldy #>message1
jsr printMessage
.close
lda # ; filenumber 2
jsr CLOSE ; call CLOSE
jsr CLRCHN ; call CLRCHN
rts
.error1
ldx #<errorMsg1
ldy #>errorMsg1
jsr printMessage
jmp .close
.error2
ldx #<errorMsg2
ldy #>errorMsg2
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 #0 ;starting string index
- lda (temp),y ;get a character
beq + ;end of string
jsr CHROUT ;print character
iny ;next
bne -
inc temp+1
bne -
+ rts
我已经使用 C64 程序员参考准备了下面列出的基本例程。它在完全相同的环境中按预期工作。
10 OPEN 3,8,3, "O:DATA FILE,S,W"
20 PRINT#3, "SENT TO DISK"
30 CLOSE 3
那么,为什么我的 asm 例程不起作用?
我正在 Vice 2.4 上测试
显然问题出在 Logical number
和 secondary adress
中,如 J...
所示
我已经通过更换零件修复了它。即:
; call SETFLS
lda #
ldx $BA ; last used device number
bne +
ldx # ; default to device 8
+ ldy #
jsr SETFLS ; call SETLFS
...
; call CHKOUT
ldx # ; filenumber=3
jsr CHKOUT ; file 2 now used as output
...
.close
lda # ; filenumber 3
jsr CLOSE ; call CLOSE
jsr CLRCHN ; call CLRCHN
rts
还有其他问题,例如 "COLORS SAVED" 消息被发送到文件而不是屏幕,但这些问题很容易解决。
我知道这是一个旧线程,但只需调用 jsr close 然后从每个错误例程中调用 rts 就会将错误打印到屏幕上,不是吗?这样你就可以在输出文本之前关闭 file/etc。
我正在尝试学习如何使用内核例程按照此 Codebase64 Tutorial 写入磁盘文件。
我已经复制了我的例程,用 Acme Crossassembler 编写,如下所示。它无法打开文件并给出错误消息:"FILE NOT OPENED"
; Definitions
SETNAM = $FFBD
SETFLS = $FFBA
OPEN = $FFC0
CHKOUT = $FFC9
READST = $FFB7
CLOSE = $FFC3
CLRCHN = $FFCC
CHROUT = $ffd2
;Basic Start
* = 01 ; BASIC start address (#2049)
!byte [=10=]d,,$dc,,e,,, ; BASIC loader to start at $c000...
!byte ,,,[=10=],[=10=],[=10=] ; puts BASIC line 2012 SYS 49152
;Program Code
* = $c000 ; Can be executed by writing sys 49152
ldx #<message0
ldy #>message0
jsr printMessage
save2file:
; call SETNAM
lda #fname_end-fname ; file name size
ldx #<fname ; file name vector
ldy #>fname ; file name vector
jsr SETNAM ; call SETNAM
; call SETFLS
lda #[=10=]
ldx $BA ; last used device number
bne +
ldx # ; default to device 8
+ ldy #[=10=]
jsr SETFLS ; call SETLFS
;call OPEN
jsr OPEN ; call OPEN
bcs .error1 ; if carry set, the file could not be opened
; call CHKOUT
ldx # ; filenumber=2
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 #<message1
ldy #>message1
jsr printMessage
.close
lda # ; filenumber 2
jsr CLOSE ; call CLOSE
jsr CLRCHN ; call CLRCHN
rts
.error1
ldx #<errorMsg1
ldy #>errorMsg1
jsr printMessage
jmp .close
.error2
ldx #<errorMsg2
ldy #>errorMsg2
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 #0 ;starting string index
- lda (temp),y ;get a character
beq + ;end of string
jsr CHROUT ;print character
iny ;next
bne -
inc temp+1
bne -
+ rts
我已经使用 C64 程序员参考准备了下面列出的基本例程。它在完全相同的环境中按预期工作。
10 OPEN 3,8,3, "O:DATA FILE,S,W"
20 PRINT#3, "SENT TO DISK"
30 CLOSE 3
那么,为什么我的 asm 例程不起作用?
我正在 Vice 2.4 上测试
显然问题出在 Logical number
和 secondary adress
中,如 J...
我已经通过更换零件修复了它。即:
; call SETFLS
lda #
ldx $BA ; last used device number
bne +
ldx # ; default to device 8
+ ldy #
jsr SETFLS ; call SETLFS
...
; call CHKOUT
ldx # ; filenumber=3
jsr CHKOUT ; file 2 now used as output
...
.close
lda # ; filenumber 3
jsr CLOSE ; call CLOSE
jsr CLRCHN ; call CLRCHN
rts
还有其他问题,例如 "COLORS SAVED" 消息被发送到文件而不是屏幕,但这些问题很容易解决。
我知道这是一个旧线程,但只需调用 jsr close 然后从每个错误例程中调用 rts 就会将错误打印到屏幕上,不是吗?这样你就可以在输出文本之前关闭 file/etc。