; Binary to ASCII Decimal String Conversion Print Routine ; [DE] contains binary number to be displayed as a decimal number. ; Note String is built right->left in buffer ; Then printed out via CPM.         (ZILOG) ; PRINT_DEC: LD HL,BUFFER ;Location to hold string LD (BUFPTR),HL ;Save buffer pointer EX DE,HL LD A,0 LD (CURLEN),A ;Current length of buffer is 0 LD A,H LD (NGFLAG),A ;Save Sign Value OR A ;Set FLAGS Value JP P,CNVERT ;JMP IF VALYE IS + EX DE,HL LD HL,0 OR A ;CLEAR Carry SBC HL,DE ;Convert Value to a String CNVERT:       LD E,0 ;HL := HL DIV 10, DE := HL MOD 10 LD B,16 OR A DVLOOP:       RL L     ;Do a 24-bit shift left RL H RL E LD A,E SUB 10 ;If remainder is 10 or more next 1 CCF JR NC,DECCNT LD E,A DECCNT:       DJNZ DVLOOP ;continue until all bits are done RL L RL H CHINS:LD A,E ;Insert next character into buffer ADD A,'0' CALL INSERT LD A,H OR L JR NZ,CNVERT EXIT: LD A,(NGFLAG) ;All done OR A ;Check it + or - overall JP P,POS LD A,'-' CALL INSERT POS: LD HL,BUFFER LD A,(HL) ;number of characters in buffer INC A LD C,A LD B,0 ADD HL,BC ;Point to end of buffer LD (HL),'$' ;Put in terminating character for CPM LD DE,BUFFER+1 ;Now print the complete string LD C,PRINT ;(+1, because buffer count is in first posttion) CALL BDOS RET   INSERT: PUSH HL ;Save for now PUSH AF LD HL,(BUFPTR) ;Current end of buffer LD D,H LD E,L INC DE ;DE = End+1 LD (BUFPTR),DE LD A,(CURLEN) OR A JR Z,EXITMR LD C,A LD B,0 LDDR ;Move entire buffer up one byte EXITMR:       LD A,(CURLEN) INC A LD (CURLEN),A LD (HL),A EX DE,HL POP AF LD (HL),A POP HL RET   BUFPTR: DS 2 ;pointer to last character in buffer CURLEN: DS 1 ;Current length NGFLAG: DS 1 BUFFER: DB ' $' ;<<<<< Decimal string will be built here