din: ld hl,0 ; ANSWER :=0; ld bc,0 ; SIGN := 0;NSIGN := 0; call get ; A := INPUT (character); cp '+' ; is A = '+'? jp z,dinsign ; if so then go save sign cp '-' ; is A = '-'? jp nz,dinnumb ; if not then go to numeric tests; dec c ; SIGN := -1; dinsign:ld b,c ; NSIGN := SIGN; call get ; A := INPUT (character); dinnumb:cp '0' ; is A LT '0'? ret c ; if so then return [not numeric]; cp ':' ; is A LT ':'? ret nc ; if not then return [not numeric); and 15 ; A :=A & b'00001111' [mask low order]; ld c,a ; VALUE := A [save input, loworder]; ld a,b ; A := NSIGN; ld b,9 ; CNT := 9; ld d,h ; MULTPLR := ANSWER [high order]; ld e,l ; MULTPLR := ANSWER [low order]; rla ; is SIGN positive? [uses copy in A] ; jp nc,dinmpyp ; if not then go to positive multipiy; xor a ; A :=0; CARRY := 0; sub c ; A := A - VALUE [negate VALUE]; ld c,a ; C := A [save negated value] ; ld a,h ; A := ANSWER [high order]; rla ; is ANSWER negative? jp c,dinmpyn ; if so then proceed [not first time]; ld b,0 ; CNT := 0 [so sign extension at DINEGATE works]; jp dinegate ; first time add VALUE to ANSWER [initialized to zero]; dinmpyn:add hl,de ; ANSWER := ANSWER + MULTPLR [both are negsttve]; ret nc ; if no overflow then return; dec b ; CNT:= CNT-1; jp nz,dinmpyn ; if CNT NE 0 then reiterate; dinegate: dec b ; CNT := CNT - 1 [now CNT := -1]; add hl,bc ; ANSWER := ANSWER + (-VALUE) [16 bit ops]; jp dinsign ; reiterate with next numeric character; dinmpyp:add hl,de ; ANSWER := ANSWER + MULTPLR; ret c ; if CARRY := 1 then return [overflow]; dec b ; CNT := CNT-1; jp nz,dinmpyp ; if CNT NE 0 then reiterate; add hl,bc ; ANSWER := ANSWER + VALUE; jp dinsign ; reiterate with next numeric character;