Download issue 2.4: Acrobat - tim

Transcript
the number of successful subtracts in A. The number in A is then the number of tenthousands that was in the original number. To convert this value to an ASCII number,
ADD 30H or OR 30H. You know that we can print the contents of A to the video through
@DSP.
Here is
the best
illustration of our problem. Assume A has 6. If we CALLed
@DSP with 6 in A, NOTHING would print because the ASCII value for 6 is an unprintable
(not obscene) character used to ACKnowledge in serial communications. To get the number
"6" to print on the video, we must first modify it to 36H.
In DECASC, we use DBUFFER to build the string of ASCII characters one byte at a time.
Returning from the sub DECASCi, we try each diminutive power of ten until the number is
0. At that time, DECASC returns to the main body which calls HEXASC:
02080 HEXASC PUSH
HL
;save count
02090
LD
DE,HBUFFER
;point to buffer with DE
02100
LD
A,H
;convert high half of H
02110
AND
0F0H
;mask off bits 3-0
02120
CALL
SHIFT
;shift it down to lsnibble
02130
CALL
CONASC
;make it ASCII
02140
LD
A,H
;convert low nibble of H
02150
AND
0FH
;mask off 7-4
02160
CALL
CONASC
02170
LD
A,L
;convert L as we did H
02180
AND
0F0H
02190
CALL
SHIFT
02200
CALL
CONASC
02210
LD
A,L
02220
AND
0FH
02230
CALL
CONASC
02240
POP
HL
02250
RET
02260 SHIFT
LD
B,4
;loop 4 times
02270 SHLOOP SRL
A
;shift right 1 bit
02280
DJNZ
SHLOOP
02290
RET
02300 CONASC ADD
A,30H
;make it an ASCII
02310
CP
3AH
;does it surpass arabic
02320
JR
C,OK1
;IF no THEN oki ELSE
02330
ADD
A,7
;offset for A-F range
02340 OK1
LD
(DE),A
;stuff in buffer
02350
INC
DE
;point to next position
02360
RET
This is the easiest because it just involves adding 30H to the values 0-9 and 37H to
the values A-F (10-15) for each of the four nibbles. The sub SHIFT moves information
obtained from the high nibble to the low nibble that it might undergo the services of
CONASC which adds 30H. If the sum is greater than 39H ("9") then another 7 is added.
The string
is concantenated
in HBUFFER and HEXASC returns control to the main body
which calls BINASC.
02370 BINASC PUSH
HL
;save HL
02380
EX
DE,HL
; DE <==> HL
02390
LD
HL,BBUFFER
;point to buffer
02400
LD
B,2
;establish loop of 2 bytes
02410 BLOOP
LD
A,0H
;set up bit marker in A
02420 BLOOP2 LD
(HL),30H
;set bit to zero
02430
PUSH
AF
;save bit position
02440
AND
D
;see if position is set
02450
JR
Z,ZEROD
;if not - skip it
02460
LD
(HL),31H
;ELSE put a "1" in buffer
02470 ZEROD
INC
HL
;point to next "bit"
02480
POP
AF
;restore bit position
02490
SRL
A
;shift it right
02500
PUSH
AF
;save it
02510
BIT
3,A
;test for nibble’s end
02520
JR
Z,NOSKIP
02530
INC
HL
;skip over space
Page 49