Faster DUMP.COM for CP/M

267 views
Skip to first unread message

ladislau szilagyi

unread,
May 29, 2023, 9:51:54 AM5/29/23
to RC2014-Z80
Hi,

I was curious about the performance of some of the original CP/M transient commands...e.g. DUMP.COM

I found the source of DUMP.COM in the DR's CP/M manual and studied-it carefully.

Then, I wrote my own FASTDUMP.COM

Here it is, I included the source file, it's quite small...
(to be assembled with HiTech's ZAS or my Z80AS, and linked with LINK using -ptext=100H -c100H )

----------------------
; Fast DUMP
;
; this version of DUMP is almost twice as faster
; as the original CP/M DUMP
;
; May 2023
;
; Ladislau Szilagyi

BDOS equ     5               ;entry point for the CP/M BDOS.
FCB equ     5CH             ;default file control block.
FCBR equ FCB+32

BUFF   equ     80H             ;i/o buffer and command line storage.

CR equ 0DH
LF equ 0AH

macro OutA
call Bin2Hex ;A=B,C = chars to type
ld b,c
ld c,a ;high
call BiosConout
ld c,b ;low
call BiosConout
endm

psect text

start:
ld sp,(6) ;set SP below BDOS
ld   hl,(1) ;fetch BIOS console routines
inc hl
inc hl
inc hl
ld   de,BiosConst
ld   bc,9
ldir
ld a,(BUFF) ;any parameter?
or a
jp z,TypeHelp ;no, type help
xor a ;setup FCB
ld (FCBR),a
ld de,FCB
ld c,15
call BDOS ;open file
inc a
jp z,TypeNotFound
ld hl,0 ;HL=offset in file
ld de,BUFF ;DE=pointer in rec
loop: ld a,e
cp BUFF ;if buff empty...
jr nz,1f
push de ;save pointer
push hl ;save offset
ld de,FCB ;read next buff
ld c,20
call BDOS
pop hl ;restore offset
pop de ;restore pointer
or a
jp nz,0 ;quit if EOF
1: ld a,l ;check offset
and 0FH
jr nz,nooff
ld c,CR
call BiosConout ;CR
ld c,LF
call BiosConout ;LF
call BiosConst ;check console status
or a
jp nz,0 ;quit if key hit
ld a,h ;print offset in hexa
OutA
ld a,l
OutA
nooff: ld c,' ' ;blank
call BiosConout
ld a,(de) ;A=char
inc e ;increment pointer
jr nz,2f ;if end-of-record,
ld e,80H ;reset pointer
2: OutA ;print char in hexa
inc hl ;increment addr
jr loop
;
TypeNotFound:
ld hl,FileNotFoundMsg
jr type
;
TypeHelp:
ld hl,HelpMsg
type: ld a,(hl)
or a
jp z,0
inc hl
ld c,a ;char to type
call BiosConout
jr type
;
; BIOS shortcuts
;
BiosConst:  jp 0
BiosConin:  jp 0
BiosConout: jp 0
;
;------------------------------------------------------------
; Bin2Hex
;
; A = byte
;
; returns BC = hexa representation of A
; A = high nibble in hexa (ready to be stored/printed)
;------------------------------------------------------------
Bin2Hex:
ld c,a ;C = byte
and 0FH ;A = low nibble
call nibble2hex ;B = hexa
ld a,c ;A = byte
ld c,b ;C = low nibble in hexa
and 0F0H ;A = (high nibble, 0000)
rrca
rrca
rrca
rrca ;A = high nibble
;falls through, will return A = B = high nibble in hexa
;
; A = bin
; returns A = B = hexa
;
nibble2hex: ;A = bin
add     a,090h
        daa
        adc     a,040h
        daa ;A = hexa
ld b,a
ret
;
HelpMsg:
defm "Use: dump filename.ext"
defb 0
FileNotFoundMsg:
defm "Could not open file!"
defb 0

end start

--------------------

Some comments :

- My FASTDUMP behaves like the "original" DUMP, expecting the same filename.ext parameter and typing the same output
- You may stop-it hitting any key... exactly as the "original" DUMP
- I added a little help text, if no parameters are used in the command line...
- I used direct BIOS calls for console out/in/status, instead of BDOS calls
- I used a faster bin-to-hex routine, compared to the one used by the "original" DUMP

Some testing proved that it is almost twice as faster as the original DUMP.COM
I tested my FASTDUMP on a 7.3728 MHz RC2014, provided with my custom BIOS ( https://github.com/Laci1953/RC2014-CPM/tree/main/BDOS_BIOS )

Statistics:
                       DUMP     FASTDUMP
--------------------------------------------------------
144 KB file:     95s          50s
204 KB file:     110s        65s

Wow... perhaps it's worth polishing the "old" CP/M tools...

Ladislau

ladislau szilagyi

unread,
May 29, 2023, 10:04:04 AM5/29/23
to RC2014-Z80
Hi,


You may found there also the new CP/M commands grep, eraq, copyq.

Ladislau

ladislau szilagyi

unread,
May 30, 2023, 3:27:33 AM5/30/23
to RC2014-Z80
Hi,


FDUMPX is the equivalent of DUMPX, who types also the ASCII chars (but much more faster, because DUMPX is written in C...)

Statistics:
                        DUMPX     FDUMPX
-----------------------------------------------
36 KB file:      120s          15s

ladislau szilagyi

unread,
Jun 3, 2023, 8:22:43 AM6/3/23
to RC2014-Z80
Here ( https://github.com/Laci1953/RC2014-CPM/tree/main/fasttype ) you may find also a faster TYPE

Statistics:
                                   TYPE         FASTTYPE
-----------------------------------------------------------------
204 KB file:               55s            25s

Ladislau

Richard Kiernan

unread,
Jun 3, 2023, 3:57:26 PM6/3/23
to RC2014-Z80
Very impressive improvements. Where would you say you're finding the most room for optimisation compared to the original CP/M tools?

Phillip Stevens

unread,
Jun 4, 2023, 1:22:50 AM6/4/23
to RC2014-Z80
On Sunday, 4 June 2023 Richard Kiernan wrote:
Very impressive improvements. Where would you say you're finding the most room for optimisation compared to the original CP/M tools?

There's going to be a substantial speed up from calling the BIOS functions rather than using the BDOS functions.
The BDOS OUTCON function does quite a bit more housekeeping before it calls BIOS OUTCHAR.

OUTCON:
    Output can be paused with ^S and restarted with ^Q.
    While the output is paused, the program can be terminated with ^C.
    Check for a TAB character and move to the right column by spacing on the CONSOLE.
    Check whether a printer is attached and echo the output to the LIST device.
    Check whether it was a rubout character, and decrement the cursor position and output a backspace.
    Check for line feed, and the update the cursor position.
    Increment the cursor position to do correct tabbing, and line wrap.
    Then output the character using the BIOS OUTCHAR:

So there's quite a bit of performance robbing formatting and system management being avoided by using the direct BIOS call, which may go some way to explain the speed up.

Cheers, Phillip

ladislau szilagyi

unread,
Jun 4, 2023, 2:22:06 AM6/4/23
to RC2014-Z80
Hi,

yes, Phillip pointed out very accurately the difference between calling BDOS & BIOS console related functions.

But, again, all I wanted was to obtain maximum possible speed when executing some usual CP/M commands, noticing that the original CP/M implementation lagged far behind the I/O transfer rate (baud rate) provided by the serial.

Of course, some of the initial functionality was lost (e.g. CTRL^S / CTRL^Q ) but I obtained what I wanted : raw speed !

Now, I feel like opening Pandora's box, while mentioning also other possible improvements to the 'original' CP/M 2.2 set of (internal and transient) commands:

- a command to search for an ASCII string in a set of files (see my GREP here:  https://github.com/Laci1953/RC2014-CPM/tree/main/grep )
- a command to erase files with query ( see my ERAQ here:  https://github.com/Laci1953/RC2014-CPM/tree/main/eraq )
- a command to copy files with query ( see my COPYQ here:  https://github.com/Laci1953/RC2014-CPM/tree/main/copyq )
- a command to find files ( Jay Cotton's FIND here:  https://github.com/jayacotton/macro-library/tree/master/test/find )

I am aware that many efforts have been made in this direction (ZCCP, ZSDOS, ...) and that there are other versions of CP/M ( v3 ) which tried to solve the issue, adding many new useful commands, but... for all those who are using the "old" CP/M 2.2, this approach is not valid.

What I feel that's missing is a "catalogue" of such "new" CP/M 2.2 utility programs (commands)... or, perhaps I'm not aware about the existence of such a "catalogue"...

regards,
Ladislau

Phillip Stevens

unread,
Jun 4, 2023, 8:24:20 AM6/4/23
to RC2014-Z80
On Sunday, 4 June 2023, ladislau szilagyi wrote:
What I feel that's missing is a "catalogue" of such "new" CP/M 2.2 utility programs (commands)... or, perhaps I'm not aware about the existence of such a "catalogue"...

I'm not aware of a comprehensive one either. But there's a few repositories that I go to regularly.
I'm sure there are plenty of others, and even a list of repositories would be worth curating.
Cheers, Phillip

Fred Weigel

unread,
Jun 4, 2023, 1:00:02 PM6/4/23
to RC2014-Z80

http://www.z80.eu/microshell.html

I use microshell -- about as close as you can get to a good shell with cp/m 2.2

Takes too much RAM to use with HiTech C, but easily removed to run the compiler. Or, use microshell
as the batch subsystem. I couple that with a utility to "name" drive/user areas. I haven't tried your faster
dump yet, but I hope it works with microshell to allow redirection. "r dump r.com >r.dmp" Then, edit the r.dmp,
or "r dd r.com >xyzzy", then type (blind) d100 1ff<return> g0<return> to get:
DDT VERS 2.2
NEXT  PC
0500 0100
-d100 1ff
0100 3A 80 00 B7 C2 55 01 CD 4F 01 52 20 31 2E 30 30 :....U..O.R 1.00
0110 0D 0A 0A 20 20 52 20 50 52 4F 47 52 41 4D 20 50 ...  R PROGRAM P
0120 41 52 41 4D 53 0D 0A 0A 4C 4F 41 44 20 50 52 4F ARAMS...LOAD PRO
0130 47 52 41 4D 20 46 52 4F 4D 20 43 4F 4D 4D 4F 4E GRAM FROM COMMON
0140 20 41 52 45 41 20 4F 52 20 4C 42 52 0D 0A 24 D1  AREA OR LBR..$.
0150 0E 09 C3 05 00 3A 80 00 FE 7E DA 62 01 3E 7E 32 .....:...~.b.>~2
0160 80 00 C6 81 6F 26 00 74 CD 32 04 21 81 00 11 5C ....o&.t.2.!...\
0170 00 CD C7 03 2E 81 54 5D CD BE 03 7E B7 CA 89 01 ......T]...~....
0180 FE 20 CA 8D 01 23 C3 7B 01 12 C3 98 01 7E 12 13 . ...#.{.....~..
0190 23 B7 C2 8D 01 7B D6 82 32 80 00 0E 20 1E FF CD #....{..2... ...
01A0 05 00 32 83 03 3E 01 32 5C 00 21 65 00 36 43 23 ..2..>.2\.!e.6C#
01B0 36 4F 23 36 4D 2E 68 06 18 CD B6 03 0E 20 1E 00 6O#6M.h...... ..
01C0 CD 05 00 11 5C 00 21 84 03 06 24 CD A8 03 11 84 ....\.!...$.....
01D0 03 0E 0F CD 05 00 3C C2 87 02 21 53 04 06 18 CD ......<...!S....
01E0 B6 03 11 47 04 21 84 03 06 24 CD A8 03 11 84 03 ...G.!...$......
01F0 0E 0F CD 05 00 3C CA 73 02 11 6B 04 0E 1A CD 05 .....<.s..k.....
-g0

(needs monospace). Anyway, you get the idea. The only problem with microshell? TPA is reduced to 
48902 bytes on my 63K cp/m 2.2 system (as compared to 57094). Worse is when combined with
the cp/net 1.2 client:(57094 base, 52742 with cp/net, then down to 44550 with microshell).
Reply all
Reply to author
Forward
0 new messages