System information
5.3 A Sample File-to-File Copy Program
The following program provides a relatively simple example of file operations. The program
source file is created as COPY.ASM using the CP/M ED program and then assembled using
ASM or MAC, resulting in a HEX file. The LOAD program is used to produce a COPY.COM
file that executes directly under the CCP. The program begins bv setting the stack pointer to a
local area and proceeds to move the second name from the default area at 006CH to a 33-byte
File Control Block called DFCB. The DFCB is then prepared for file operations by clearing the
current record field. At this point, the source and destination FCBs are ready for processing,
because the SFCB at 005CH is properly set up by the CCP upon entry to the COPY program.
That is, the first name is placed into the default FCB, with the proper fields zeroed, including the
current record field at 007CH. The program continues by opening the source file, deleting any
existing destination file, and creating the destination file. If all this is successful, the program
loops at the label COPY until each record is read from the source file and placed into the
destination file. Upon completion of the data transfer, the destination file is closed and the
program returns to the CCP command level by jumping to BOOT.
; sample file-to-file copy program
;
;
; at the ccp level, the command
;
;
; copy a:x.y b:u.v
;
;
0000 = boot equ 0000h ; system reboot
0005 = bdos equ 0005h ; bdos entry point
005C = fcb1 equ 005ch ; first file name
005C = sfcb equ fcb1 ; source fcb
006C = fcb2 equ 006ch ; second file name
0080 = dbuff equ 0080h ; default buffer
0100 = tpa equ 0100h ; beginning of tpa
;
0009 = printf equ 9 ; print buffer func#
000F = openf equ 15 ; open file func#
0010 = closef equ 16 ; close file func#
0013 = deletef equ 19 ; delete file func#
0014 = readf equ 20 ; sequential read func#
0015 = writef equ 21 ; sequential write
5.2 Call Conventions CP/M Operating System Manual
5-36