2017-04-11 9 views
6

다음은이 Codebase64 Tutorial 다음의 커널 루틴을 사용하여 디스크 파일을 쓰는 방법을 배우려고합니다.Commodore 64에서 어셈블리를 사용하여 디스크 파일 쓰기

아래의 Acme Crossassembler로 작성한 루틴을 복사했습니다. 이 파일을 열지 못했습니다 및 오류 메시지를 제공합니다 : 나는 C64 프로그래머 참조를 사용하여 다음의 기본 루틴을 준비했습니다

; Definitions 
SETNAM = $FFBD 
SETFLS = $FFBA 
OPEN = $FFC0 
CHKOUT = $FFC9 
READST = $FFB7 
CLOSE = $FFC3 
CLRCHN = $FFCC 
CHROUT = $ffd2  

;Basic Start 
    * = $0801        ; BASIC start address (#2049) 
    !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 #<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 #$00 
    ldx $BA     ; last used device number 
    bne + 
     ldx #$08   ; default to device 8 
+ ldy #$00 
    jsr SETFLS    ; call SETLFS 

    ;call OPEN 
    jsr OPEN    ; call OPEN 
    bcs .error1    ; if carry set, the file could not be opened 

    ; call CHKOUT 
    ldx #$02    ; 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 #$02  ; 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    

"열지 않은 파일". 동일한 환경에서 예상대로 작동합니다.

10 OPEN 3,8,3, "O:DATA FILE,S,W" 
20 PRINT#3, "SENT TO DISK" 
30 CLOSE 3  

그렇다면 왜 내 asm 루틴이 작동하지 않습니까?

가 나는 부분을 변경하여

내가 그것을 해결했습니다 ... J으로 표시된 바와 같이 Apperently 문제가 Logical numbersecondary adress이었다

+0

BASIC 루틴은 어셈블러와 매우 다르지만 하나의 언어가 작동한다고 말하면 다른 언어는별로 유용하지 않습니다! 코드를 디버깅 했습니까? – t0mm13b

+2

BASIC 명령이 데이터 채널 3 ('3,8,3')에서 파일 3을 열고 있지만 ASM이 데이터 채널 0 ('ldy # $ 00')에서 파일 0 ('lda # $ 00')에 액세스하려고 시도하고 있습니다. 장치 8 (디스크)의 보조 주소 번호로 유효하지 않습니다. –

+1

@ J ... 숫자를 변경했고 효과가있었습니다. – wizofwor

답변

6

부사장 2.4에서 테스트하고있어이 .IE :

; call SETFLS 
    lda #$03 
    ldx $BA     ; last used device number 
    bne + 
     ldx #$08   ; default to device 8 
+ ldy #$03 
    jsr SETFLS    ; call SETLFS 

...

; call CHKOUT 
    ldx #$03    ; filenumber=3 
    jsr CHKOUT    ; file 2 now used as output 

...

.close 
    lda #$03  ; filenumber 3 
    jsr CLOSE  ; call CLOSE 
    jsr CLRCHN ; call CLRCHN 
    rts 

"COLORS SAVED"메시지가 화면 대신 파일로 전송 된 것과 같은 다른 문제가 있지만 쉽게 해결할 수 있습니다.