sys_return: equ $d003 sys_call: equ $d006 console_output: equ $7fe8 mon_pdata: equ $c009 mon_out4hs: equ $c015 mon_pcrlf: equ $c021 ;;; Address of cassette interface casport: equ $8060 org $a100 ;;; Go to first argument str_skp_next: ldaa ,x beq str_skp_next_e cmpa #$20 beq str_skp_next_1 inx bra str_skp_next str_skp_next_1: ldaa ,x beq str_skp_next_e cmpa #$20 bne str_skp_next_e inx bra str_skp_next_1 str_skp_next_e: * ;;; Save filename (first argument) * ldx #tstnam stx fname0 stx fname1 * ldx #fcb0 jsr sys_call tst fcb0+1 ; read error code bne file_not_found ldx #fcb1 jsr sys_call tst fcb1+1 ; read error code bne file_read_error ;;; Check file ldaa fcb0+4 ; get flags bita #$40 bne file_is_directory ;;; Calculate end of file in memory ldx fcb0+9 ldab #$ff abx stx eaddr jmp save ; begin saving file_not_found: ldx #txt_not_found jsr mon_pdata jmp sys_return file_read_error: ldx #txt_read_error jsr mon_pdata jmp sys_return file_is_directory: ldx #txt_is_directory jsr mon_pdata jmp sys_return ;;; ;;; Save file to tape ;;; save: jsr sync ldx #$0100 save_loop: ldaa ,x jsr byte inx cpx eaddr bls save_loop jsr sync clr casport prog_end: jmp sys_return rts ;;; ;;; Send sync ;;; 2048 bits "1" ;;; 1 bit "0" ;;; sync: ldx #2048 syncl: ldab #0 stab casport jsr dly0 ldab #1 stab casport jsr dly1 dex bne syncl ;; Send end of sync bit ldab #0 stab casport jsr dly0 ldab #1 stab casport jsr dly0 rts ;;; ;;; Send one byte in A ;;; byte: ldab #8 stab count ;; Start bit - "0" ldab #0 stab casport jsr dly0 ldab #1 stab casport jsr dly0 ;; Data bit bloop: lsra bcs byte1 ;; Send zero ldab #0 stab casport jsr dly0 ldab #1 stab casport jsr dly0 bra byte2 ;; Send one byte1: ldab #0 stab casport jsr dly0 ldab #1 stab casport jsr dly1 ;; End of byte? byte2: dec count bne bloop rts ;;; ;;; Bit delays ;;; dly0: ldab #50 dly0l: decb bne dly0l rts dly1: ldab #100 dly1l: decb bne dly1l rts ;;; ;;; Variables and strings ;;; fcb0: fcb $01 ; command fcb 0 ; error code fname0: fdb 0 ; file name fcb 0 ; flags fdb 0 ; sectors fdb 0 ; size MSB fdb 0 ; size LSB fdb 0 ; year fcb 0 ; month fcb 0 ; day fcb 0 ; hours fcb 0 ; minutes fcb 0 ; seconds * fcb1: fcb $10 ; command fcb 0 ; error code fname1: fdb 0 ; file name fdb $0100 ; destination address * txt_not_found: fcc "File not found" fcb $0d,$0a,$04 txt_read_error: fcc "File read error" fcb $0d,$0a,$04 txt_is_directory: fcc "Entry is a directory" fcb $0d,$0a,$04 * count: fcb 0 eaddr: fdb 0 * *tstnam: * fcc "testfile" * fcb 0 *