sys_return: equ $d003 sys_call: equ $d006 console_status: equ $7fe5 ; console status vector console_output: equ $7fe8 ; console output vector console_input: equ $7feB ; console input vector mon_pdata: equ $c009 mon_out2hs: equ $c012 mon_out4hs: equ $c015 mon_baddr: equ $c01e mon_pcrlf: equ $c021 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 to FCS * ldx #tstnam stx fname ldaa ,x ; Check argument bne file_check ldx #txt_argument jsr mon_pdata jmp prog_end ;;; Check if file already exists file_check: ldaa #$01 ; command $01 - check file staa fcs ldx #fcs jsr sys_call tst fcs+1 ; read error code bne *+5 jmp file_exists ; file already exists ldx #txt_send_data jsr mon_pdata ;;; Begin data load ldx #$0100 stx loaddr jsr console_input ; Get first byte load_loop: cpx #$7eff bhi load_wait ; Out of memory - stop buffering staa ,x ; Store byte in memory buffer inx ldab #$ff ; Wait for next byte load_wait: jsr console_status decb beq load_end ; Timeout waiting for next byte tsta beq load_wait jsr console_input bra load_loop ;;; Load complete load_end: dex stx hiaddr ;;; Save loaded data to file save_file: ldx #txt_saving jsr mon_pdata ldaa #$20 ; command $20 - save file staa fcs ldx loaddr stx fcs+4 ldx hiaddr stx fcs+6 ldaa #$03 ; Set attributes "rw-" staa fcs+8 ldx #fcs jsr sys_call tst fcs+1 ; read error code beq prog_end ; save OK ldx #txt_save_error jsr mon_pdata ldx #fcs+1 jsr mon_out2hs jsr mon_pcrlf prog_end: jmp sys_return * file_exists: ldx #txt_exists jsr mon_pdata bra prog_end ;;; Texts txt_argument: fcc "Destination file name missing" fcb $0d,$0a,$04 txt_send_data: fcc "Send data" fcb $0d,$0a,$04 txt_exists: fcc "File exists" fcb $0d,$0a,$04 txt_saving: fcc "Saving file" fcb $0d,$0a,$04 txt_save_error: fcc "Save failed - " fcb $04 ;;; Variables loaddr: rmb 2 ; Lowest address loaded hiaddr: rmb 2 ; Highest address loaded *tstnam: fcc "testfile" * fcb #$00 ;;; File Control Structure fcs: rmb 1 ; command rmb 1 ; error code fname: rmb 2 ; file name pointer rmb 14 ; payload