home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
CP/M
/
CPM_CDROM.iso
/
mbug
/
mbug113.arc
/
INOUT.Z80
< prev
next >
Wrap
Text File
|
1979-12-31
|
6KB
|
253 lines
ENTRY ODEC, IDEC, IKL, OTL, CRLF, MCHINW, VDU
;
; DECIMAL PRINT ROUTINE
; NUMBER TO PRINT IN HL REGISTER
;
ODEC: PUSH AF ; SAVE
PUSH BC ;
PUSH DE ;
LD A,H ; TEST SIGN
LD B,' ' ; IF + PRINT SPACE
OR A ; SET FLAGS
JP P,PLUS ; OK
PUSH HL ; MOVE TO
POP DE ; DE
LD HL,0 ; 0 - X = -X
AND A ; RESET CARRY
SBC HL,DE ; SUBTRACT TO CHANGE SIGN
LD B,'-' ; IF - print -
PLUS: CALL VDU ; PRINT SIGN
LD IX,TENS ; POINTER TO POWERS OF TEN
LD B,5 ; FIVE DIGITS
LD C,'0' ; use C as leading zero flag
;
LOOP: LD A,2FH ; ASCII ZERO - 1
LD E,(IX+0) ; GET LOW BYTE
LD D,(IX+1) ; GET HIGH BYTE
LOOP1: AND A ; CHEAR CARRY
SBC HL,DE ; SUBTRACT DECADE
INC A ; INCREASE DIGIT
JR NC,LOOP1 ; NOT NEGATIVE YET
ADD HL,DE ; OK, RESTORE NO
CP '0' ; IS IT A ZERO ?
JR Z,ZERO ; YES DO LEADING ZERO TEST
LD C,A ; NO REMOVE SUPRESSION
ODEC1: PUSH BC ; SAVE COUNT
LD B,A ; print needs it in B
CALL VDU ; PRINT
POP BC ; RESTORE COUNT
INC IX ; POINT TO NEXT
INC IX ; DECADE VALUE
DJNZ LOOP ; DO IT 5 TIMES
POP DE ; RESTORE REGISTERS
POP BC ;
POP AF ;
RET ; FINISHED
;
ZERO: CP C ; If A = '0' AND C = '0'
JR NZ,ODEC1 ; IF NOT PRINT ZERO
LD A,B ; TEST COUNTER
CP 1 ; TO SEE IF LAST DIGIT
LD A,'0' ; RESTORE A
JR Z,ODEC1 ; LAST DIGIT,PRINT '0'
LD A,' ' ; IF TRUE PRINT SPACE
JR ODEC1
;
; Table for conversion to decimal
;
TENS: DEFW 10000
DEFW 1000
DEFW 100
DEFW 10
DEFW 1
;
; Decimal input routine
;
; Number is returned in HL registers
; when a non digit character is typed.
; The non digit char is returned in A.
; + or - sign is permitted, NO '.' INTEGERS ONLY.
;
; IF ERROR IS FOUND '?' TYPED, START AGAIN.
;
IDEC: PUSH AF ; save registers
PUSH BC ; to be used in this routine
PUSH DE ;
IDEC0: LD A,'+' ; set sign to +
LD (SIGN),A ;
LD DE,LINE ; max of 7 characters
;
; Fetch characters and examine for special types
;
IDEC1: PUSH HL
PUSH BC
LD C,10 ; BDOS code.
CALL 5 ; Call BDOS
POP BC
POP HL
;
JP IDEC2 ; Go to next Bit
;
; Errors here
;
ERROR1: LD B,'?' ; type ?
CALL VDU ; on screen
JR IDEC0 ; Start over
;
; Adjust sign
;
SIGNS: LD (SIGN),A ; set indicator
JR IDEC1 ; continue
;
; Assemble number
;
IDEC2: LD IY,CNT ; Number of characters Typed.
LD IX,LINES ; pointer to start
LD HL,0 ; number = zero
LD BC,0 ;
;
IDEC3: LD A,(IX+0) ; get digit
;
CP '-' ; Negative Number ?
JR NZ,IDEC4 ; No
LD (SIGN),A ; Yes change Sign.
JR IDEC5 ;
;
IDEC4: CP '0' ; < '0' ?
JR C,DONE ; yes
CP '9'+1 ; > '9' ?
JR NC,DONE ; yes
;
SUB '0' ; Convert to Binary.
LD C,A ; In BC.
;
SLA L ; Multiply Number by 10.
RL H ; * 2
JR C,ERROR1 ; too big
PUSH HL ; SAVE
POP DE ;in de
SLA L ;
RL H ; X * 2 * 2 = 4*X
JR C,ERROR1 ; too big
SLA L ;
RL H ; 4 * X * 2 = 8*X
JR C,ERROR1 ; too big
ADC HL,DE ; 8*X + 2*X = 10*X
JP M,ERROR1 ; CHECK FOR > 32767
ADC HL,BC ; add digit in C
JP M,ERROR1 ; AGAIN JUST IN CASE
;
IDEC5: INC IX ; move pointer
DEC (IY+0) ; Decrement Counter
JR NZ,IDEC3 ; next digit
;
; correct sign
;
DONE: LD A,(SIGN) ; fetch sign
CP '-' ; is it minus
JR NZ,DONEIT ; no leave it plus
PUSH HL ; put number into
POP DE ; DE
LD HL,0 ; Set HL to zero
AND A ; CLEAR CARRY
SBC HL,DE ; 0 - X = -X
DONEIT: POP DE ; RESTORE
POP BC ;
POP AF ;
LD A,(FINAL) ; Return first non digit in A
RET ; ALL DONE
;
LINE: DEFB LINEE-LINES; input buffer maximum count.
CNT: DEFB 0 ; Actual character Count.
LINES: DEFS 8 ; Characters
LINEE: ; End of line.
;
SIGN: DEFB 0 ; sign for number
FINAL: DEFB 0 ; First non digit char
;
VDU: PUSH HL
PUSH DE
PUSH BC
PUSH AF
LD E,B ; Character to Print.
LD C,2 ; BDOS code.
CALL 5 ; Call BDOS
POP AF
POP BC
POP DE
POP HL
RET
;
MCHINW: PUSH HL
PUSH DE
PUSH BC
LD C,1 ; BDOS code.
CALL 5 ; Call BDOS
POP BC
POP DE
POP HL
RET
;
;
; Text Input Routine IKL
; reads a string of chars from keyboard
; prints on screen, stopps when char read
; is equal to char in A register, HL register
; is used as a POINTER to store data, terminal
; char is LAST char stored.
;
IKL: PUSH AF ; save flags
PUSH BC ;
IKL1: PUSH AF ; save term char in A
CALL MCHINW ; read keyboard
CP 7FH ; DELETE ?
JP Z,IKL3 ; YES
LD (HL),A ; NO STORE
INC HL ;
IKL2: POP AF ; restore A
CP B ; IS IT THE ONE ?
JR NZ,IKL1 ; NO
POP BC ;
POP AF ; RESTORE
RET ; YES
;
IKL3: DEC HL ; BACK POINTER
JR IKL2 ;
;
;
; Text output routine OTL
; HL is pointer and A contains final Char.
; Final char is NOT printed.
;
OTL: PUSH AF ; save flags
PUSH BC ;
OTL1: PUSH AF ; save term
LD A,(HL) ; GET char
LD B,A ;
POP AF ; restore
CP B ; is this the END ?
JR Z,OTL2 ; yes
CALL VDU ; no print it
INC HL ;
JR OTL1 ; get next
;
OTL2: POP BC ;
POP AF ; restore
RET ;
;
; Carriage Return Line Feed Routine
; called CRLF.
; no registers are changed.
;
CRLF: PUSH BC ; Save BC.
LD B,0DH ; CR
CALL VDU ; do it
LD B,0AH ; LF
CALL VDU ; do it
POP BC ; Restore BC
RET ; Thats All !!
;
END