Instruction manual
0129 21 08 db decimal_entry: ld hl,buffer
012c cd 4c 00 call get_line ;returns with DE pointing to terminating zero
012f 21 08 db ld hl,buffer
0132 cd 3f 01 call decimal_string_to_word
0135 d0 ret nc ;no error, return with word in hl
0136 21 36 04 ld hl,decimal_error_msg ;error, try again
0139 cd 18 00 call write_string
013c c3 29 01 jp decimal_entry
013f ;
013f ;Subroutine to convert a decimal string to a word value
013f ;Call with address of string in HL, pointer to end of string in DE
013f ;Carry flag set if error (non-decimal char)
013f ;Carry flag clear, word value in HL if no error.
013f 42 decimal_string_to_word: ld b,d
0140 4b ld c,e ;use BC as string pointer
0141 22 00 db ld (current_location),hl ;save addr. of buffer start in RAM
0144 21 00 00 ld hl,000h ;starting value zero
0147 22 06 db ld (current_value),hl
014a 21 8f 01 ld hl,decimal_place_value ;pointer to values
014d 22 04 db ld (value_pointer),hl
0150 0b decimal_next_char: dec bc ;next char (moving right to left)
0151 2a 00 db ld hl,(current_location) ;check if at end of decimal string
0154 37 scf ;get ready to sub. DE from buffer addr.
0155 3f ccf ;set carry to zero (clear)
0156 ed 42 sbc hl,bc ;cont. if bc > or = hl (buffer address)
0158 da 64 01 jp c,decimal_continue ;borrow means bc > hl
015b ca 64 01 jp z,decimal_continue ;z means bc = hl
015e 2a 06 db ld hl,(current_value) ;return if de < buffer add. (no borrow)
0161 37 scf ;get value back from RAM variable
0162 3f ccf
0163 c9 ret ;return with carry clear, value in hl
0164 0a decimal_continue: ld a,(bc) ;next char in string (right to left)
0165 d6 30 sub 030h ;ASCII value of zero char
0167 fa 8a 01 jp m,decimal_error ;error if char value less than 030h
016a fe 0a cp 00ah ;error if byte value > or = 10 decimal
016c f2 8a 01 jp p,decimal_error ;a reg now has value of decimal numeral
016f 2a 04 db ld hl,(value_pointer) ;get value to add an put in de
0172 5e ld e,(hl) ;little-endian (low byte in low memory)
0173 23 inc hl
0174 56 ld d,(hl)
51










