Karoshi MSX Community
05 de Julio de 2021, 01:13:50 pm *
Bienvenido(a), Visitante. Por favor, ingresa o regístrate.

Ingresar con nombre de usuario, contraseña y duración de la sesión
Noticias:
 
   Inicio   Ayuda Buscar Ingresar Registrarse  
Páginas: [1]
  Imprimir  
Autor Tema: NIBBLE MIRRORING ROUTINE  (Leído 3908 veces)
0 Usuarios y 1 Visitante están viendo este tema.
SapphiRe_MSX
Visitante
« : 14 de Mayo de 2008, 11:42:35 am »

Hi all:

  Imagine you have a stream of nibbles and you want to mirror them. For instance you have the values:

F3 01 DE EF E4 24

and you want to obtain

42 4E FE ED 10 3F

  Next routine is useful to do that if the bytes you want to mirror are located in ram:

Código:
; INPUT
; hl -> pointer to the first byte to be mirrored
; de -> pointer to the last byte to be mirrored
; b -> number of byte-pairs to be mirrored
MIRRORNIBBLES:
RLD
EX DE,HL
RRD
EX DE,HL
RLD
EX DE,HL
RRD
EX DE,HL
RLD
INC HL
DEC DE
DJNZ MIRRORNIBLES
RET

So, in the previous example, if the bytes are located at $C000, the code to call this routine is:

Código:
LD HL,$C000 ; HL points to $F3
LD DE,$C005 ; DE points to $24
LD B,3 ; 6 bytes to be mirrored (three pairs)
CALL MIRRORNIBBLES

Warning! This routine does not work if DE = HL, but works fine otherwise.

It only changes HL, DE and B, the value of A remains the same.

Hope you find useful the routine
--
Sph.
« Última modificación: 14 de Mayo de 2008, 04:35:07 pm por SapphiRe » En línea
GuyveR800
Karoshi Newbie
*
Mensajes: 49


WWW
« Respuesta #1 : 14 de Mayo de 2008, 04:39:56 pm »

Nice routine!

RLD and RRD are really nice instructions in situations where they are useful Tongue

Here's a routine I wrote for BCD string to ASCII conversion:
Código:
; In:
; HL = Pointer to BCD string
; DE = Pointer to ASCII string
; B = Size of BCD string in bytes
BCD2ASCII:
ld a,30h
.loop:
rld
ld [de],a
inc de
rld
ld [de],a
inc de
rld
inc hl
djnz .loop
ret
En línea

Founder of The New Image in 1991.
Founder of MSX Banzai! in 1997.
Páginas: [1]
  Imprimir  
 
Ir a:  

Impulsado por MySQL Impulsado por PHP Powered by SMF 1.1.21 | SMF © 2013, Simple Machines XHTML 1.0 válido! CSS válido!