The ITOS.I include file resides on the Kyan Pascal 2.x Utilities Disk 1.
- PROCEDURE INTTOSTR(NUMBER:INTEGER; JUSTIFY:CHAR; VAR RESULT:STRING5);
Source Code
PROCEDURE INTTOSTR(NUMBER:INTEGER; JUSTIFY:CHAR; VAR RESULT:STRING5);
BEGIN
#A
STX _T
LDY #5
LDA (_SP),Y ;ADDRESS OF RESULT STRING
STA _T+1
INY
LDA (_SP),Y
STA _T+2
INY
INY
LDA (_SP),Y ;INTEGER TO CONVERT
STA _T+4
INY
LDA (_SP),Y
STA _T+5
LDY #7
LDA (_SP),Y ;JUSTIFY CHAR
;
LDX #'0
CMP #'Z
BEQ ITS2
LDX #$20 ;SPACE
CMP #'R
BEQ ITS2
TXA ;FILL STRING WITH SPACES
LDY #4
ITS1 STA (_T+1),Y
DEY
BPL ITS1
LDX #0
ITS2 STX _T+3
;
LDA #0 ;ZERO BCD RESULT
STA _T+6
STA _T+7
STA _T+8
STA ITSCOPY ;COPY FLAG
;
LDY #16 ;BIT COUNTER
CLC
SED
ITS3 ROL _T+4
ROL _T+5
LDA _T+6
ADC _T+6
STA _T+6
LDA _T+7
ADC _T+7
STA _T+7
LDA _T+8
ADC _T+8
STA _T+8
DEY
BNE ITS3
;
CLD ;CHANGE BCD TO ASCII IN STRING
LDX #$80
LDY #0 ;INDEX TO STRING
LDA _T+8
AND #15
JSR ITS7 ;ENTER @ NIBBLE TEST POINT
;
ITS5 LDA _T+7
JSR ITS8 ;CONVERT MIDDLE BYTE
LDA _T+6
JSR ITS8 ;CONVERT LOWEST BYTE
BIT ITSCOPY
BMI ITS12
LDA _T+3
BEQ *+3 ;IF LEFT JUSTIFY, Y IS CORRECT
DEY
LDA #'0 ;SINCE NOTHING PASSED YET, PRINT ENDING ZERO
STA (_T+1),Y
ITS12 LDX _T
#
END;
#A
ITS8 PHA
AND #$F0
LSR
LSR
LSR
LSR
JSR ITS7 ;PROCESS THIS NIBBLE
PLA
AND #15
ITS7 CMP #0
BNE ITS6 ;AUTO INSERT IF NON-ZERO
BIT ITSCOPY ;OK ANYWAY?
BMI ITS6 ;YES
LDA _T+3 ;NO: PUT JUSTIFY CHAR
BNE ITS10 ;INTO STRING IN PLACE OF DIGIT
RTS ;RETURN IF LEFT JUSTIFY
ITS6 CLC
ADC #$30 ;MAKE INTO ASCII DIGIT
STX ITSCOPY
ITS10 STA (_T+1),Y
INY
RTS
ITSCOPY DS 1
#
No comments:
Post a Comment