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 MEM_START: equ $0100 ; start of RAM org $a100 ldd #file_name std fname ;;; 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: ;;; Test if file name is provided tst ,x beq *+5 stx fname ; new file name provided ;;; 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 ;;; Verify file in RAM ldx #file_flags ldd #0 chksm_loop: addb ,x adca #0 cpx file_end beq chksm_end inx bra chksm_loop chksm_end: xgdx cpx checksum bne memory_invalid ;;; Save data to file save_file: ldaa #$20 ; command $20 - save file staa fcs ldx #file_data stx fcs+4 ldx file_end stx fcs+6 ldaa file_flags 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 * memory_invalid: ldx #txt_invalid jsr mon_pdata bra prog_end ;;; Texts txt_exists: fcc "File exists" fcb $0d,$0a,$04 txt_invalid: fcc "No valid file in memory" fcb $0d,$0a,$04 txt_save_error: fcc "Save failed - " fcb $04 ;;; File Control Structure fcs: rmb 1 ; command rmb 1 ; error code fname: rmb 2 ; file name pointer fbeg: rmb 2 ; file begin fend: rmb 2 ; file end fflag: rmb 1 ; file flags rmb 9 ; payload ;;; ;;; File storage ;;; org MEM_START checksum: rmb 2 file_flags: rmb 1 file_name: rmb 32 file_end: rmb 2 file_data: equ *