;; Tell the assembler that this is z80 code
.Z80
;; Define system calls to be used
cwrite EQU 2h ;argument goes in E
cwrites EQU 9h ;argument address goes in DE
bdosver EQU 0Ch;returns type in B, version in A
fopen EQU 0Fh;FCB address goes in DE
fclose EQU 10h;FCB address goes in DE
freadr EQU 14h;FCB address goes in DE
fwriter EQU 15h;128 byte record at DMA address
fmake EQU 16h;FCB address goes in DE
setdma EQU 1Ah;address goes in DE
;; Zero page constants
reset EQU 0h
bdos EQU 5h ;call number goes in C
fcb EQU 5Ch;first FCB
srecord EQU 7Ch;record index for sequential access
tlength EQU 80h;length of command tail
ctail EQU 81h;command tail
;; Get and display system version number
LD C,bdosver ;load bdosver
CALL bdos;call bdosver
CALL conv;convert to ASCII
LD C,cwrites ;load cwrites
LD DE,osname ;parameter is number address
CALL bdos;call cwrites
JP reset;exit program
;; Convert byte in A into two ASCII characters
conv: SUB 16;subtract 10 from A
JP P,tloop;if positive jump to tloop
ADD A,16;return the last 10
JP ones;if negative jump to ones
tloop: LD HL,number ;load number into HL
INC (HL);increment number
JP conv;loop
ones: SUB 1;subtract 1 from A
JP P,oloop;if positive jump to oloop
JP done;if negative jump to done
oloop: LD HL,number+2 ;load number+2 into HL
INC (HL);increment number+2
JP ones;loop
done: LD A,(number) ;load contents of number into A
SUB 10;subtract 10 from A
JP P,hex1;if A is positive we need A-F
JP dec1;if A is negative we need 0-9
hex1: ADD A,7;add 7 to A to get ASCII A-F
dec1: ADD A,58;add 10+48 to A to get ASCII 0-9
LD HL,number ;load number into HL
LD (HL),A;write A to number
LD A,(number+2) ;load contents of number+2 into A
SUB 10;subtract 10 from A
JP P,hex2;if A is positive we need A-F
JP dec2;if A is negative we need 0-9
hex2: ADD A,7;add 7 to A to get ASCII A-F
dec2: ADD A,58;add 10+48 to A to get ASCII 0-9
LD HL,number+2
LD (HL),A
RET;return to calling routine
;; Our operating system name and a space
osname: DB "CP/M "
;; Place to store two ASCII characters in positions 0 and 2
number: DB 0,".",0,"$"
;; End source file
END