PDA

View Full Version : CP/M Z80 assembly code examples



JonB
November 17th, 2016, 11:29 PM
Hi

I am looking for some code samples in Z80 for CP/M file management, in particular patching binary files. It seems to be very hard to find! Can anyone sling me a link or two?

Thanks
JonB

jharre
November 19th, 2016, 07:36 PM
Just a guess, but a search for "walnut creek cpm archive" probably would be helpful.

<*> Jim

MikeModifed
November 19th, 2016, 07:49 PM
Perhaps here: http://www.classiccmp.org/cpmarchives/index.php?

Mike

per
November 19th, 2016, 08:07 PM
I would guess you have to load a portion of the file, change the data you want, set up the File Control Block to indicate which 128-byte block is being written, call the BDOS write file call and finally the BDOS close-file call.

JonB
November 19th, 2016, 11:06 PM
I thought that, but is it not a little unsafe?

archeocomp
November 20th, 2016, 01:14 AM
Book "Soul of cp/m" from Waite/Lafore show many examples. Probably other books as well.

per
November 20th, 2016, 03:44 AM
I thought that, but is it not a little unsafe?
A lot of things in CP/M wouldn't be considered "safe" these days. At least you don't have to write the data manually to a sector on the floppy.

Calculating the values is nothing more than one or a few simple subtractions, since after loading data, the FCB should point to the 128 byte block after the recently loaded data (unless I am mistaken. It's worth to double-check this.).

dwesti
December 17th, 2016, 07:37 PM
my attempt:

display key codes:


.Z80

WRITESTR EQU 9h
PRTCHR EQU 02H
BDOS EQU 5h
ESC EQU 1BH

ORG 100h
MAIN:
;cls
LD DE,CL
LD C,9;WRITESTR
CALL BDOS

WAIT_K:

LD C,11 ; C_STAT
LD DE,0
CALL BDOS
OR A
JR Z,WAIT_K

LD C,6
LD DE,-1
CALL BDOS

OR A
JP Z,WAIT_K

PUSH AF
SRL A
SRL A
SRL A
SRL A
CALL CONHEX
LD (HEX),A
POP AF
CALL CONHEX
LD (HEX+1),A

LD C,9;WRITESTR
LD DE,HEX
CALL BDOS
JP WAIT_K

CONHEX:
AND 0FH
ADD A,30H
CP 3Ah
JP M,OUT_
ADD A,7
OUT_:
RET

HEX:
DB "00",13,10,"$"

CL:
DB 1Bh,"[H",1Bh,"[2J$"

END MAIN


compile:


m80 =KEYS/M
L80 KEYS,KEYS/N/E
ERA KEYS.REL

JohnElliott
December 18th, 2016, 03:08 PM
I would guess you have to load a portion of the file, change the data you want, set up the File Control Block to indicate which 128-byte block is being written, call the BDOS write file call and finally the BDOS close-file call.

If you're targeting CP/M 2 or later, you could use the random-access I/O functions rather than manually recalculating the file pointer in the FCB.

Chuck(G)
December 18th, 2016, 06:05 PM
For your "CONHEX", consider this old chestnut:



and a,15 ; get low nibble
add a,090h
daa
adc a,040h
daa
ret


This actually predates the 8080--it can be found in the Intel 8008 monitor code.

JonB
December 19th, 2016, 01:54 AM
I would guess you have to load a portion of the file, change the data you want, set up the File Control Block to indicate which 128-byte block is being written, call the BDOS write file call and finally the BDOS close-file call.

This is what I ended up doing, and it works well. To make it easier, I put the area to be patched at the start of the file.

dreNorteR
December 19th, 2016, 03:40 AM
For your "CONHEX", consider this old chestnut:



and a,15 ; get low nibble
add a,090h
daa
adc a,040h
daa
ret


One instruction shorter 8)


or 0f0h ; masks out high nibble & clears AF
daa ; F0-FF => 50-59, 60-65
cmp 60h ; set CF if decimal digit
sbc a, 1fh ; convert to ASCII
ret


This depends on how the logic instructions affect AF, the Z80 sets it on AND and clears it on OR. I couldn't find any documentation on this for the 8008/8080.


This actually predates the 8080--it can be found in the Intel 8008 monitor code.

The Intel 8008 manual I found doesn't even mention the DAA instruction exists...

dwesti
December 20th, 2016, 06:57 AM
There a some ways to convert number to hex ascii.

for example:


cp 0ah
sbc a,69h
daa


or code I found at Rodney Zaks' book.

anyway, thank you for clues =)