Author Topic: Constructive and Creative uses of RLD and RRD  (Read 8667 times)

0 Members and 1 Guest are viewing this topic.

Offline ralphdspam

  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 841
  • Rating: +38/-1
  • My name is actually Matt.
    • View Profile
Constructive and Creative uses of RLD and RRD
« on: August 25, 2011, 09:06:44 pm »
I saw the topic "Constructive and Creative uses of IX and IY," and I liked the idea of brainstorming creative uses for commands. 

Two commands that always perplex me are RLD and RRD.  I cannot think of many practical uses of them. 
ld a, 0
ld a, a

Offline calc84maniac

  • eZ80 Guru
  • Coder Of Tomorrow
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2912
  • Rating: +471/-17
    • View Profile
    • TI-Boy CE
Re: Constructive and Creative uses of RLD and RRD
« Reply #1 on: August 25, 2011, 11:11:00 pm »
I use one of those in TI-Boy to emulate the SWAP (HL) instruction, which swaps the upper and lower nibbles of (HL).
It works like ld a,(hl) \ rrd.
"Most people ask, 'What does a thing do?' Hackers ask, 'What can I make it do?'" - Pablos Holman

Offline DrDnar

  • LV7 Elite (Next: 700)
  • *******
  • Posts: 546
  • Rating: +97/-1
    • View Profile
Re: Constructive and Creative uses of RLD and RRD
« Reply #2 on: August 26, 2011, 02:20:18 am »
As far as I can tell, the instructions are intended for use with BCD. They appear to allow multiplying and dividing by ten. Or sixteen, if you're using binary.
"No tools will make a man a skilled workman, or master of defense, nor be of any use to him who has not learned how to handle them, and has never bestowed any attention upon them. . . . Yes, [] the tools which would teach men their own use would be beyond price."—Plato's The Republic, circa 380 BC

Offline thepenguin77

  • z80 Assembly Master
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1594
  • Rating: +823/-5
  • The game in my avatar is bit.ly/p0zPWu
    • View Profile
Re: Constructive and Creative uses of RLD and RRD
« Reply #3 on: August 26, 2011, 03:12:08 pm »
Indeed, the only time I've ever used it was for BCD. It's useful if you need to recover a number from TI's floating points. For instance:

Code: [Select]
turnTheEntireOp1ToADecimalStringRegardlessOfSignificateFigures:
ld hl, op1+2
ld c, 7
outerLoop:
ld b, 2
innerLoop:
ld a, $30
rld
ld (de), a
inc de
djnz innerLoop
inc hl
dec c
jr nz, outerLoop
xor a
ld (de), a
ret
zStart v1.3.013 9-20-2013 
All of my utilities
TI-Connect Help
You can build a statue out of either 1'x1' blocks or 12'x12' blocks. The 1'x1' blocks will take a lot longer, but the final product is worth it.
       -Runer112

Offline ralphdspam

  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 841
  • Rating: +38/-1
  • My name is actually Matt.
    • View Profile
Re: Constructive and Creative uses of RLD and RRD
« Reply #4 on: August 26, 2011, 06:01:52 pm »
I'm glad there are actually uses for that command.  I like the idea of manipulating nibbles, but I don't like the fact that it modifies the source data.  Can you use it on ROM code without any problems? 
ld a, 0
ld a, a

Offline calcdude84se

  • Needs Motivation
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2272
  • Rating: +78/-13
  • Wondering where their free time went...
    • View Profile
Re: Constructive and Creative uses of RLD and RRD
« Reply #5 on: August 26, 2011, 09:01:12 pm »
I'm glad there are actually uses for that command.  I like the idea of manipulating nibbles, but I don't like the fact that it modifies the source data.  Can you use it on ROM code without any problems? 
You probably shouldn't be manipulating code by nibble :P Anyway, A contains the correct result even if (HL) can't be changed, IIRC.
"People think computers will keep them from making mistakes. They're wrong. With computers you make mistakes faster."
-Adam Osborne
Spoiler For "PartesOS links":
I'll put it online when it does something.

Offline calc84maniac

  • eZ80 Guru
  • Coder Of Tomorrow
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2912
  • Rating: +471/-17
    • View Profile
    • TI-Boy CE
Re: Constructive and Creative uses of RLD and RRD
« Reply #6 on: August 26, 2011, 10:30:15 pm »
* calc84maniac uses OPTIMIZATION
Code: [Select]
turnTheEntireOp1ToADecimalStringRegardlessOfSignificateFigures:
ld hl, op1+2
ld b, 7
ld a, $30
loop:
rld
ld (de), a
inc de
rld
ld (de), a
inc de
inc hl
djnz loop
xor a
ld (de), a
ret

Edit:
Ooh, even better!
Code: [Select]
turnTheEntireOp1ToADecimalStringRegardlessOfSignificateFigures:
ld hl, op1+2
ld bc, 7
loop:
ld a, $33
rrd
ldi
ld (de), a
inc de
jp pe, loop
xor a
ld (de), a
ret
« Last Edit: August 26, 2011, 10:40:08 pm by calc84maniac »
"Most people ask, 'What does a thing do?' Hackers ask, 'What can I make it do?'" - Pablos Holman

Offline Xeda112358

  • they/them
  • Moderator
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 4704
  • Rating: +719/-6
  • Calc-u-lator, do doo doo do do do.
    • View Profile
Re: Constructive and Creative uses of RLD and RRD
« Reply #7 on: December 30, 2011, 11:40:38 pm »
Ooh, rrd and rld are some of my favorite instructions! When I was describing what it does in my pocket asm tutorial was this:
Quote
rrd/rld the two nibbles from (hl) and the last nibble of 'a' make three nibbles. rrd                
           rotates them right and rld rotates them left.
As for a way to use them, I have a few codes that make excellent use of them. This one is from my program BSPRT. It uses hexadecimal sprite data, so instead of converting the hex string to a location in RAM and then copying it to the screen, I just did both at once (here is the sprite display part):
Code: (BSPRT) [Select]
;Inputs:
;     HL points to the buffer location to draw to
;     DE points to the sprite data

     ld bc,080Ch     ;010C08
Loop:
     call PutNibble  ;CD****
     call PutNibble  ;CD****
     ld a,b          ;78
     ld b,0          ;0600
     add hl,bc       ;09
     ld b,a          ;47
     djnz Loop       ;10F3
     ret             ;C9
PutNibble:
     ld a,(de)       ;1A
     add $C0         ;C6C0
     jr nc,$+4       ;3002
       sub 7         ;D607
     rld             ;ED6F
     inc de          ;13
     ret             ;C9
This is my favorite one, though. When I made a graph shifting routine, I made these to shift 4 pixels very quickly:
Code: [Select]
ShiftLeft4:
     ld hl,GraphBuf+767
     ld c,64
       xor a
       ld b,12
         rld
         dec hl
         djnz $-3
       dec c
       jr nz,$-9
       ret
Code: [Select]
ShiftRight4:
     ld hl,GraphBuf
     ld c,64
       xor a
       ld b,12
         rrd
         inc hl
         djnz $-3
       dec c
       jr nz,$-9
       ret
I feel pretty proud of these :) I think the first can be optimised more, but it is still nice, I think :)

Offline chickendude

  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 817
  • Rating: +90/-1
  • Pro-Riot Squad
    • View Profile
Re: Constructive and Creative uses of RLD and RRD
« Reply #8 on: December 31, 2011, 05:32:36 am »
Unless i'm missing something, the first just says "Array", maybe you pasted the wrong thing?

Offline Hayleia

  • Programming Absol
  • Coder Of Tomorrow
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3367
  • Rating: +393/-7
    • View Profile
Re: Constructive and Creative uses of RLD and RRD
« Reply #9 on: December 31, 2011, 06:49:29 am »
It is because she wrote [code=something].
Here is what she meant :)

Code: [Select]
;Inputs:
;     HL points to the buffer location to draw to
;     DE points to the sprite data

     ld bc,080Ch     ;010C08
Loop:
     call PutNibble  ;CD****
     call PutNibble  ;CD****
     ld a,b          ;78
     ld b,0          ;0600
     add hl,bc       ;09
     ld b,a          ;47
     djnz Loop       ;10F3
     ret             ;C9
PutNibble:
     ld a,(de)       ;1A
     add $C0         ;C6C0
     jr nc,$+4       ;3002
       sub 7         ;D607
     rld             ;ED6F
     inc de          ;13
     ret             ;C9
I own: 83+ ; 84+SE ; 76.fr ; CX CAS ; Prizm ; 84+CSE
Sorry if I answer with something that seems unrelated, English is not my primary language and I might not have understood well. Sorry if I make English mistakes too.

click here to know where you got your last +1s

Offline Xeda112358

  • they/them
  • Moderator
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 4704
  • Rating: +719/-6
  • Calc-u-lator, do doo doo do do do.
    • View Profile
Re: Constructive and Creative uses of RLD and RRD
« Reply #10 on: December 31, 2011, 10:21:06 am »
Unless i'm missing something, the first just says "Array", maybe you pasted the wrong thing?
I am not seeing that... On mine, Hayleia and I have the same thing...

Offline Hayleia

  • Programming Absol
  • Coder Of Tomorrow
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3367
  • Rating: +393/-7
    • View Profile
Re: Constructive and Creative uses of RLD and RRD
« Reply #11 on: December 31, 2011, 10:23:43 am »
Unless i'm missing something, the first just says "Array", maybe you pasted the wrong thing?
I am not seeing that... On mine, Hayleia and I have the same thing...
??? I see "Array" too on yours. Maybe it depends on the browser.
But do you see "BSPRT" next to "code" ? (I don't see it, I had to quote you to see it should be here ;))
« Last Edit: January 02, 2012, 12:27:43 pm by Hayleia »
I own: 83+ ; 84+SE ; 76.fr ; CX CAS ; Prizm ; 84+CSE
Sorry if I answer with something that seems unrelated, English is not my primary language and I might not have understood well. Sorry if I make English mistakes too.

click here to know where you got your last +1s

Offline chickendude

  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 817
  • Rating: +90/-1
  • Pro-Riot Squad
    • View Profile
Re: Constructive and Creative uses of RLD and RRD
« Reply #12 on: December 31, 2011, 11:00:35 am »
Well, it doesn't really matter now as i see what code you were talking about in Hayleia's post. Btw, what exactly do you mean by "hexidecimal sprites"? I'm trying to figure out what exactly your code does.

Offline Xeda112358

  • they/them
  • Moderator
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 4704
  • Rating: +719/-6
  • Calc-u-lator, do doo doo do do do.
    • View Profile
Re: Constructive and Creative uses of RLD and RRD
« Reply #13 on: December 31, 2011, 02:10:01 pm »
Ah, well with that code, will draw a sprite with hexadecimal data input. By that, I mean . db "3C4281818181423C" as opposed to .db 3Ch,42h,81h,81h,81h,81h,42h,3Ch

The first is what a TI-BASIC string would be like and the program that code is in is designed for TI-BASIC programmers to use.

Offline Quigibo

  • The Executioner
  • CoT Emeritus
  • LV11 Super Veteran (Next: 3000)
  • *
  • Posts: 2031
  • Rating: +1075/-24
  • I wish real life had a "Save" and "Load" button...
    • View Profile
Re: Constructive and Creative uses of RLD and RRD
« Reply #14 on: January 02, 2012, 06:07:01 am »
Axe uses RRD and RLD for nibble storing.  I've never used them anywhere else, they are definitely very uncommon.  :ninja:

Code: [Select]
;hl = Nth nibble after address $8000
;e = Nibble to store there
NibSto:
scf
rr h
rr l
jr nc,__NibStoHigh
rrd
ld a,e
rld
ret
__NibStoHigh:
rld
ld a,e
rrd
ret
__NibStoEnd:
« Last Edit: January 02, 2012, 06:07:40 am by Quigibo »
___Axe_Parser___
Today the calculator, tomorrow the world!