home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.barnyard.co.uk
/
2015.02.ftp.barnyard.co.uk.tar
/
ftp.barnyard.co.uk
/
cpm
/
walnut-creek-CDROM
/
ZSYS
/
SIMTEL20
/
SYSLIB
/
SLIB3.LBR
/
SMTH12.Z80
< prev
next >
Wrap
Text File
|
2000-06-30
|
2KB
|
95 lines
;
; SYSLIB Module Name: SMTH12
; Author: Richard Conn
; SYSLIB Version Number: 3.6
; Module Version Number: 1.1
public divhd
;
; DIVHD -- DIVIDE HL BY DE, RESULT IN HL
;
DIVHD:
PUSH AF
PUSH BC
PUSH HL ; SAVE HL
LD HL,0
LD (ACC),HL ; ZERO ACCUMULATOR
POP HL
;
; CHECK TO MAKE SURE THAT HL > DE
;
LD A,H
CP D ; H > D?
JP C,DOVFL ; ZERO RESULT IF H < D
JP NZ,DNOVFL
LD A,L
CP E ; L > E?
JP C,DOVFL ; ZERO RESULT IF HL < DE
DNOVFL:
LD B,16 ; 16 LOOPS
DVHD:
CALL SHFTLH ; SHIFT DIVIDEND LEFT
PUSH HL ; SAVE DIVIDEND
LD HL,(ACC) ; GET ACC
CALL SHFLCH ; ROTATE ACC AND MOVE IN CARRY
LD (ACC),HL ; NEW ACC
LD A,L ; LOW COMPARISON
SUB E ; COMPARE AND SUBTRACT
LD L,A
LD A,H ; HIGH COMPARISON
SBC A,D ; COMPARE AND SUBTRACT
LD H,A
JP C,DVHD0
LD (ACC),HL ; SAVE NEW ACC
POP HL ; GET DIVIDEND
LD A,L ; PLACE IN A 1 TO QUOTIENT
OR 1
LD L,A
JP DVHD1
DVHD0:
POP HL ; GET DIVIDEND AND LEAVE LSB AT ZERO
DVHD1:
DEC B ; COUNT DOWN
JP NZ,DVHD
DVRET:
POP BC
POP AF
RET
DOVFL:
LD HL,0 ; RESULT IS ZERO
JP DVRET
;
; SHIFT ROUTINES
;
SHFTLH: ; SHIFT HL LEFT
PUSH AF
AND A ; CLEAR CARRY
SHFL:
LD A,L ; SHIFT LOW
RLA ; ROTATE 9-BIT ACC LEFT
LD L,A
LD A,H ; SHIFT HIGH
RLA
LD H,A
JP NC,OKRET
POP AF
SCF ; SET CARRY FOR OVERFLOW
RET
OKRET:
POP AF
OR A ; CLEAR CARRY FOR NO OVERFLOW
RET
SHFLCH: ; SHIFT HL LEFT, BUT SHIFT IN CARRY FLAG
PUSH AF
JP SHFL
;
; BUFFERS
;
ACC: DS 2 ; TEMP ACCUMULATOR
OVFL: DS 1 ; OVERFLOW FLAG
END