sys_return: equ $d003 sys_call: equ $d006 console_output: equ $7fe8 mon_pdata: equ $c009 mon_out4hs: equ $c015 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 (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 ;;; Check if content is executable ldx secbuf+0 cpx #$4700 beq info_exe_file ;;; Check if content is ASCII ldx fsizeh ; do we have a very large file? bne check_text_large ldd #secbuf ; calculate end of file data addd fsizel ; get file size - needed for files smaller that one sector subd #1 std xtemp ldx xtemp ; check if file larger than a sector cpx #secbuf+511 bls check_text check_text_large: ldx #secbuf+511 stx xtemp check_text: ldx #secbuf ; start of file data check_text_loop: ldaa ,x cmpa #$1f bls check_text_not cmpa #$7e bhi check_text_not check_text_next: inx cpx xtemp bls check_text_loop bra file_is_text check_text_not: cmpa #$09 ; tab? beq check_text_next cmpa #$0a ; line feed? beq check_text_next cmpa #$0d ; carriage return? beq check_text_next ;;; General binary file ldx #txt_bin_file jsr mon_pdata prog_end: jmp sys_return file_not_found: ldx #txt_not_found jsr mon_pdata bra prog_end file_read_error: ldx #txt_read_error jsr mon_pdata bra prog_end file_is_directory: ldx #txt_is_directory jsr mon_pdata bra prog_end file_is_text: ldx #txt_text_file jsr mon_pdata bra prog_end info_exe_file: ldx #txt_exe_file jsr mon_pdata ldx #txt_load jsr mon_pdata ldx #secbuf+2 jsr mon_out4hs ldd secbuf+2 addd fcb0+9 subd #7 std xtemp ldaa #'- jsr console_output ldaa #$20 jsr console_output ldaa #'$ jsr console_output ldx #xtemp jsr mon_out4hs jsr mon_pcrlf ldx #txt_entry_point jsr mon_pdata ldx #secbuf+4 jsr mon_out4hs jsr mon_pcrlf bra prog_end * fcb0: fcb $01 ; command fcb 0 ; error code fname0: fdb 0 ; file name fcb 0 ; flags fdb 0 ; sectors fsizeh: fdb 0 ; size MSB fsizel: fdb 0 ; size LSB fdb 0 ; year fcb 0 ; month fcb 0 ; day fcb 0 ; hours fcb 0 ; minutes fcb 0 ; seconds * fcb1: fcb $11 ; command fcb 0 ; error code fname1: fdb 0 ; file name fdb secbuf ; destination address fdb 0 ; sector number * 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 txt_bin_file: fcc "File is binary" fcb $0d,$0a,$04 txt_text_file: fcc "File is ASCII text" fcb $0d,$0a,$04 txt_exe_file: fcc "File is executable" fcb $0d,$0a,$04 txt_load: fcc " Load: $" fcb $04 txt_entry_point: fcc " Entry: $" fcb $04 * xtemp: fdb 0 * *tstnam: * fcc "cftest" * fcb 0 * secbuf: rmb 512 fcb 0