3 Digit Display NON BCD

Door Chilly Willy

Expert (66)

afbeelding van Chilly Willy

08-09-2021, 12:51

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

Does anyone have a quick routine that I can start with;

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
add hl, bc
jr c, 1$

sbc hl, bc
ret

Aangemeld of registreer om reacties te plaatsen

Van pgimeno

Champion (300)

afbeelding van pgimeno

08-09-2021, 14:07

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.

Van NYYRIKKI

Enlighted (5874)

afbeelding van NYYRIKKI

08-09-2021, 16:01

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)

Van Chilly Willy

Expert (66)

afbeelding van Chilly Willy

08-09-2021, 19:09

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

Van pgimeno

Champion (300)

afbeelding van pgimeno

10-09-2021, 18:42

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.

Van Metalion

Paragon (1444)

afbeelding van Metalion

10-09-2021, 19:39

Chilly Willy wrote:

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

Both snippets of code are pretty standard syntax.
You should not have big problems adapting to your assembler.