mon_pdata equ $c009 ; print text string @ x ended by $04 mon_out4hs equ $c015 ; print 4 hex chars @ x mon_pcrlf equ $c021 ; print crlf mon_outs equ $c024 ; print space sys_return equ $d003 ; MCFS2 return sys_call equ $d006 ; MCFS2 system call consvec equ $7fe5 ; console status vector conovec equ $7fe8 ; console output vector conivec equ $7feb ; console input vector MEM_START: equ $0100 ; start of RAM ;;; ;;; Program start ;;; org $a100 ;;; Load file ;;; Save filename (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 bne *+5 jmp file_not_found ; no file name provided jsr copy_to_fname ; copy file name argument to local buffer ldx #file_name ; set file name in fcb stx fcb0+2 ;;; Load file info ldaa #$01 ; check file fommand staa fcb0 ldx #fcb0 jsr sys_call tst fcb0+1 ; read error code bne file_not_found ;;; Check file ldaa fcb0+4 ; get flags bita #$40 bne file_is_directory staa file_flags ;;; Calculate end of file ldx fcb0+7 bne file_too_big ldd fcb0+9 addd #file_data-1 std file_end ; save file end ldx file_end cpx mem_end bhi file_too_big ;;; Load file contents into memory ldaa #$10 ; load file fommand staa fcb0 ldx #file_data stx fcb0+4 ldx #fcb0 jsr sys_call tst fcb0+1 ; read error code bne file_read_error load_complete: jmp prepare ;;; File error handlers file_not_found: ldx #txt_not_found jsr mon_pdata bra quit file_read_error: ldx #txt_read_error jsr mon_pdata bra quit file_is_directory: ldx #txt_is_directory jsr mon_pdata bra quit file_too_big: ldx #txt_out_of_memory jsr mon_pdata bra quit ;;; ;;; Quit ;;; quit: jmp sys_return ;;; ;;; Copy string at X to file name buffer ;;; copy_to_fname: stx xtemp1 ldx #file_name stx xtemp2 ldab #$64 copy_to_fname_loop: ldx xtemp1 ldaa ,x beq copy_to_fname_done cmpa #$20 beq copy_to_fname_done inx stx xtemp1 ldx xtemp2 staa ,x inx stx xtemp2 decb bvc copy_to_fname_loop copy_to_fname_done: ldx xtemp2 clr ,x rts ;;; ;;; Prepare file data (checksum) ;;; prepare: ldx #file_flags ldd #0 chksm_loop: addb ,x adca #0 cpx file_end beq chksm_end inx bra chksm_loop chksm_end: std checksum jmp quit ;;; ;;; Texts ;;; txt_out_of_memory: fcc "Out of memory" fcb $0d,$0a,$04 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 ;;; ;;; Variables ;;; mem_end: fdb $7dff ; end of memory xtemp1: rmb 2 xtemp2: rmb 2 ;;; ;;; File Control Block ;;; fcb0: fcb 0 ; command fcb 0 ; error code 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 ;;; ;;; File storage ;;; org MEM_START checksum: rmb 2 file_flags: rmb 1 file_name: rmb 32 file_end: rmb 2 file_data: equ *