Copy.Asm Source code

Post your CP/M & TDOS questions here
Post Reply
User avatar
Milli
Site Admin
Posts: 224
Joined: Fri Jul 19, 2019 3:13 pm
Location: Beaver Falls PA
Contact:

Copy.Asm Source code

Post by Milli » Tue Aug 20, 2019 9:18 am

Code: Select all

;;    sample file-to-file copy program
;
;
;    at the ccp level, the command
;
;
;         copy a:x.y b:u.v
;
;
boot    equ  0000h     ; system reboot
bdos    equ  0005h     ; bdos entry point
fcb1    equ  005ch     ; first file name
sfcb    equ  fcb1      ; source fcb
fcb2    equ  006ch     ; second file name
dbuff   equ  0080h     ; default buffer
tpa     equ  0100h     ; beginning of tpa
;
printf  equ  9         ; print buffer func#
openf   equ  15        ; open file func#
closef  equ  16        ; close file func#
deletef equ  19        ; delete file func#
readf   equ  20        ; sequential read func#
writef  equ  21        ; sequential write
makef   equ  22        ; make file func#
;
        org  tpa       ; beginning of tpa
        lxi  sp,stack  ; set local stack
        mvi  c,16      ; half an fcb
        lxi  d,fcb2    ; source of move
        lxi  h,dfcb    ; destination fcb
mfcb:   ldax d         ; source fcb
        inx  d         ; ready next
        mov  m,a       ; dest fcb
        inx  h         ; ready next
        dcr  c         ; count 16...0
        jnz  mfcb      ; loop 16 times
;
;    name has been removed, zero cr
        xra  a         ; a = 00h
        sta  dfcbcr    ; current rec = 0
;
;    source and destination fcb's ready
        lxi  d,sfcb    ; source file
        call open      ; error if 255
        lxi  d,nofile  ; ready message
        inr  a         ; 255 becomes 0
        cz   finis     ; done if no file
;
;    source file open, prep destination
        lxi  d,dfcb    ; destination
        call delete    ; remove if present
;
        lxi  d,dfcb    ; destination
        call make      ; create the file
        lxi  d,nodir   ; ready message
        inr  a         ; 255 becomes 0
        cz   finis     ; done if no dir space
;
;    source file open, dest file open
;    copy until end of file on source
;
copy:   lxi  d,sfcb    ; source
        call read      ; read next record
        ora  a         ; end of file?
        jnz  eofile    ; skip write if so
;
;    not end of file, write the record
        lxi  d,dfcb    ; destination
        call write     ; write the record
        lxi  d,space   ; ready message
        ora  a         ; 00 if write ok
        cnz  finis     ; end if so
        jmp  copy      ; loop until eof
;
eofile:                ; end of file, close destination
        lxi  d,dfcb    ; destination
        call close     ; 255 if error
        lxi  h,wrprot  ; ready message
        inr  a         ; 255 becomes 00
        cz   finis     ; shouldn't happen
;
;    copy operation complete, end
        lxi  d,normal  ; ready message
;
finis:                 ; write message given in de, reboot
        mvi  c,printf
        call bdos      ; write message
        jmp  boot      ; reboot system
;
;    system interface subroutines
;    (all return directly from bdos)
;
open:   mvi  c,openf
        jmp  bdos
;
close:  mvi  c,closef
        jmp  bdos
;
delete: mvi  c,deletef
        jmp  bdos
;
read:   mvi  c,readf
        jmp  bdos
;
write:  mvi  c,writef
        jmp  bdos
;
make:   mvi  c,makef
        jmp  bdos
;
;    console messages
nofile: db 'no source file$'
nodir:  db 'no directory space$'
space:  db 'out of dat space$'
wrprot: db 'write protected?$'
normal: db 'copy complete$'
;
;    data areas
dfcb:   ds   32        ; destination fcb
dfcbcr: equ  dfcb+32   ; current record
;
        ds   32        ; 16 level stack
stack:
        end
        
Attachments
copy.zip
(1.21 KiB) Downloaded 246 times
Milli

User avatar
pearsoe
Posts: 11
Joined: Sun Jul 21, 2019 3:28 pm

Re: Copy.Asm Source code

Post by pearsoe » Tue Aug 20, 2019 2:24 pm

What assembler do you use for CP/M? Also is there a disassembler you would recommend?

User avatar
Milli
Site Admin
Posts: 224
Joined: Fri Jul 19, 2019 3:13 pm
Location: Beaver Falls PA
Contact:

Re: Copy.Asm Source code

Post by Milli » Tue Aug 20, 2019 3:36 pm

I do most of my assembly on a PC using TASM - but ZSM for CP/M is a good one. I don't have any particular disassembler but I do you an online one:

https://onlinedisassembler.com/odaweb/
Milli

User avatar
Wmaalouli
Posts: 155
Joined: Sat Jul 20, 2019 2:09 pm

Re: Copy.Asm Source code

Post by Wmaalouli » Tue Aug 20, 2019 7:15 pm

I used asm80.org for the development of Adamed. It's a very versatile online assembler that can target different CPU's. Otherwise I use the standard ASM assembler on the Adam itself.

Post Reply