Shift or Rotate from Dragon BASIC

Hardware Hacking, Programming and Game Solutions/Cheats
Rink
Posts: 236
Joined: Mon Sep 05, 2011 7:01 pm

Shift or Rotate from Dragon BASIC

Post by Rink »

I might be being really dumb here, but is there no way to perform a right shift (or a rotate) from Dragon BASIC? Tried to do something by dividing by 2 but it doesn't always work - something to do with precision maybe.

I find it hard to believe the entire function was missed out but I can't find anything. :( Any help would be greatly appreciated.
Rink
Posts: 236
Joined: Mon Sep 05, 2011 7:01 pm

Re: Shift or Rotate from Dragon BASIC

Post by Rink »

Well, got something working using a simple divide by two and breaking the byte up into an array. It seems the power function (which I used originally so I could pull one bit out of the middle) does something weird to the number's representation.

It'll do until I can be bothered to write proper machine code instead.
User avatar
tormod
Posts: 416
Joined: Sat Apr 27, 2013 12:06 pm
Location: Switzerland
Contact:

Re: Shift or Rotate from Dragon BASIC

Post by tormod »

I found a number of interesting (Coco) programs at http://www.cs.unc.edu/~yakowenk/coco.html and one of them, SAMDISP.BAS, does right shift in Basic by dividing by 2 and INT'ing the result. Maybe the INT makes all the difference.
User avatar
snarkhunter
Posts: 241
Joined: Fri Apr 03, 2009 7:16 pm
Location: France

Re: Shift or Rotate from Dragon BASIC

Post by snarkhunter »

Hello,

I believe X1=INT(X/B) should right-rotate your initial X value as X1, then X2=X-(X1*B) will save the "carry" bit as X2.
Where B is the intended base (2, 10, or anything else you fancy...).
From there, you should be able to do whatever you want with those values.

Kind regards,
Lionel
Rink
Posts: 236
Joined: Mon Sep 05, 2011 7:01 pm

Re: Shift or Rotate from Dragon BASIC

Post by Rink »

Cheers guys, I'll have a play with those.

Out of curiosity, does anyone know if any of the other Microsoft licensed BASIC interpreters have a shift function? I guess they thought no one would need it.
User avatar
snarkhunter
Posts: 241
Joined: Fri Apr 03, 2009 7:16 pm
Location: France

Re: Shift or Rotate from Dragon BASIC

Post by snarkhunter »

Rink wrote:Out of curiosity, does anyone know if any of the other Microsoft licensed BASIC interpreters have a shift function? I guess they thought no one would need it.
Actually, I don't know. But I seriously doubt it. Such a function does not have much do do with high level languages. It's more things from the low-level programming era.
A couple of machine-code instructions will get you this (combining ASL/ASR + ROL/ROR using registers A & B, for instance ; not sure now about the actual order needed for those, though!). If I remember well, one will post the "lost" bit to the "Carry" flag, and the other one will pick up the "Carry" bit.
As demonstrated, this can be managed from basic, but it will obviously be much slower: logical operations are quick in machine-code, and quite slow when using such a language as BASIC (unless compiled with a smart compiler).

Hope I'm not telling you too many "lies" here: I'm now a bit rusty about all this!

Kind regards,
Lionel
User avatar
Rolo
Posts: 228
Joined: Sun Feb 10, 2013 7:36 pm

Re: Shift or Rotate from Dragon BASIC

Post by Rolo »

I never saw a single 8-bit Microsoft Basic interpreter with shift or rotate operators. We did not need this ;) . We would use integer numbers if possible and divide by two or multiply with two. Of course this does only make sense with integers, not floating point numbers.
Rink
Posts: 236
Joined: Mon Sep 05, 2011 7:01 pm

Re: Shift or Rotate from Dragon BASIC

Post by Rink »

Rolo wrote:I never saw a single 8-bit Microsoft Basic interpreter with shift or rotate operators. We did not need this ;) . We would use integer numbers if possible and divide by two or multiply with two. Of course this does only make sense with integers, not floating point numbers.
Granted - assuming you can keep your BASIC interpreter from shifting your number to a floating point representation. Presumably, one of the ideas/links etc. posted above contains the secret to doing it well. :)

I don't often program in BASIC - have always preferred assembly language to be honest. But it was fun to try doing things a little differently - didn't expect it to take me quite so long mind. :D
User avatar
Rolo
Posts: 228
Joined: Sun Feb 10, 2013 7:36 pm

Re: Shift or Rotate from Dragon BASIC

Post by Rolo »

Ahhh, now I see the point. As a Commodore user I only would use the "%"-suffix to define an integer variable (like A%=5). I just looked it up in the booklet ("An Introductiuon to Basic..."). Dragon Basic obviously does not have that special data type. I haven't had realized that until now. Strange, why did they leave that out?
Rink
Posts: 236
Joined: Mon Sep 05, 2011 7:01 pm

Re: Shift or Rotate from Dragon BASIC

Post by Rink »

Rolo wrote:Ahhh, now I see the point. As a Commodore user I only would use the "%"-suffix to define an integer variable (like A%=5). I just looked it up in the booklet ("An Introductiuon to Basic..."). Dragon Basic obviously does not have that special data type. I haven't had realized that until now. Strange, why did they leave that out?
Presumably it was an oversight at Microsoft. My theory is this: that person was sacked from Microsoft for this failure and got a job at Hudson.

And the reason I say that, is because HuBASIC on the Sharp X1 seems to have similar issues. DEFINT (used to declare a variable as an integer) and the % suffix don't bloody work!!! Although they are syntactically valid.
Post Reply