RLD and RRD instructions

By Metalion

Paragon (1622)

Metalion's picture

24-01-2014, 14:28

Just wondering ...
Does anyone have ever found a useful utilization of the RLD and RRD instructions ?
Smile Smile Smile

Login or register to post comments

By NYYRIKKI

Enlighted (6016)

NYYRIKKI's picture

24-01-2014, 14:56

Hmm...

PRINTMEM:
; Input: HL=Address
; Output HEX(HL) -> SCREEN
	xor	a
	rld
	call	.Nibble
.Nibble:
	push	af
	daa
	add	a,F0h
	adc	a,40h
	call	A2h		; prints ASCII character in A
	pop	af
	rld
	ret

...maybe useful also while manipulating SCREEN 5/7 data.

By Metalion

Paragon (1622)

Metalion's picture

24-01-2014, 15:08

Indeed !
Thanks Nyyrikki !

Cool

By msd

Paragon (1510)

msd's picture

24-01-2014, 15:54

; HL = pointer to hex output buffer (upper case ASCII)
;  A = binary number to convert
Bin2Hex:
	ld 	b,a
	rrca
	rrca
	rrca
	rrca
	and	0Fh		; These instructions are the important ones
	cp	10		;
	sbc	a,69h		;
	daa			;
	ld 	(hl),a
	inc	hl
	ld 	a,b
	and 	0Fh
	cp	10
	sbc	a,69h
	daa
	ld	(hl),a
	ret

By anonymous

incognito ergo sum (116)

anonymous's picture

24-01-2014, 16:10

Also quite useful when processing BCD...

; #1 = pointer to BCD string
; #2 = length of BCD string
; #3 = name of processing function
%macro ProcessBCD %n, %n, %s
    ld    hl,#1
    ld    b,#2
    ld    a,30h
.#loop:
    rld
    %% #3
    rld
    %% #3
    rld
    inc   hl
    djnz .#loop
%endmacro

And then for example
%macro VRAM_OUT
    out   [98h],a
%endmacro

ProcessBCD score, 4, "VRAM_OUT"

Just some tniASM v1.0 template programming :)