# 3 Digit Display NON BCD

I've been working on a 3 digit display for a countdown timer and have been running into so many little issues.

BCD seems to work but have it's own problems

Timer = 999
Display
Decrement
Loop until 0

This is the direction I am headed...

I found this bit of code that looks like what I need, any thought?

print_number:
ld bc, #-100
call print_digit
ld 2(ix), a

ld bc, #-10
call print_digit
ld 3(ix), a

ld bc, #-1
call print_digit
ld 4(ix), a

push ix
pop hl
ld bc, #5
call WRITE_VRAM

ret

print_digit:
ld a, #'0' - 1
1\$:
inc a
jr c, 1\$

sbc hl, bc
ret

Why not ASCII?

```counter		db	'999'

print_counter:	ld	hl,counter
ld	bc,3
jp	WRITE_VRAM

dec_counter:	ld	hl,counter+2
decloop:	ld	a,(hl)
dec	a
cp	'0'
jr	nc,done
ld	(hl),'9'
ld	a,l
cp	LOW counter
ret	z
dec	hl
jr	decloop
done:		ld	(hl),a
ret

reset_counter:	ld	hl,counter
ld	a,'9'
ld	(hl),a
inc	hl
ld	(hl),a
inc	hl
ld	(hl),a
ret
```

`dec_counter` returns Z if the counter wrapped around, NZ otherwise. NOTE: Untested.

Ah, seems that pgimeno posted already almost same solution... but I post this anyway.

The problem seems to be that you think this trough number conversion while you have perfectly good plan in place.

```BDOS:	EQU #F37D

;Timer = 999

LD HL,"99"
LD (NUMBER+1),HL
LD L,1
LD (NUMBER-1),HL
.DISPLOOP
;Display

LD DE,NUMBER
LD C,9
CALL BDOS

;Decrement

CALL DECNUM

;Loop until 0

JP NZ,.DISPLOOP
RET

DECNUM:

LD A,"0"-1
LD HL,LASTDIGIT
.DECLOOP
DEC (HL)
RET Z
CP (HL)
RET NZ
LD (HL),"9"
DEC HL
JP .DECLOOP

DB 1
NUMBER:	DB "999"
LASTDIGIT: EQU \$-1
DB 10,13,"\$"
```

Edit: Fixed (I hope)

Sweet, I'll try it out and get back with ya....

BTW...Will this compile with TNIASM?
If not, which one did you use?

TNX

Mine is Pasmo syntax. I don't know TNIASM syntax, sorry. I guess you have to add # here and there and don't know what else.

Chilly Willy wrote:

BTW...Will this compile with TNIASM?
If not, which one did you use?

Both snippets of code are pretty standard syntax.