PDA

View Full Version : Bitwise Question


GM006
12th May 2004, 03:12
I have a Playlist with 26 tracks on it. I want to play the tracks back in the order the user selected them in. There are only 16 GPRMs and I've read that the bitwise stuff can make it so 2 GPRMs can store upto 32 entries... can someone tell me step by step how this is accomplished?

auenf
12th May 2004, 14:24
search for programmable playback.

Enf...

GM006
12th May 2004, 19:56
I figured out how splitting it up works... but how do I "turn off" the bit when I'm done using it?

McPoodle
22nd May 2004, 00:41
Perform a logical AND with a mask. For every bit you want to reset, set the mask's bit to 0, and for every bit you want to leave alone, set the mask's bit to 1. For example, if you're treating GPRM 1 as two registers and you want to reset just the top register, GPRM 1 AND 0F. To reset just the bottom register, GPRM 1 AND F0.

GM006
13th June 2004, 01:53
I'm not quite sure I follow you... I've split the GPRM into 2 parts... Each part is 8bits and that's where I've registered what button was pushed... my question now is how do I "turn off" ONLY the first 8bits or "turn off" ONLY the last 8 bits?

Dimmer
13th June 2004, 05:53
my question now is how do I "turn off" ONLY the first 8bits or "turn off" ONLY the last 8 bits?Exactly the way McPoodle very accurately explained earlier. Perhaps, you have something else in mind when you say "turn off". Either way, it would be a good idea for you to search the web or a bookstore for the words "Boolean algebra" in order to understand the basics of bitwise operations (AND, OR, NOT). Most people find it very simple.

GM006
13th June 2004, 07:48
Hm... well I'll have to do that but for now, what does he mean by "mask"? I have a chart that shows the bits and their values. So basically if my code looked like this:
(button 24 selected)

Mov GPRM7,SPRM8
Div GPRM7, 64
Or GPRM1,GPRM7

(next selection page)
ok, to my understanding, only bits 7 & 8 are "on" (00000011)
the user now selects another track (selection 9)

Mov GPRM7,SPRM8
Or GPRM1,GPRM7

(next page)

Now my GPRM looks like this: 0000001101001000

The user selects the "play list" which will play their selections in the order they were selected.

Or GPRM7,GPRM1
Mov GPRM1, 0
if GPRM7 & 16 then jump to song1
if GPRM7 & 32 then jump to song2
etc.

In the post command I need a command that set the first 8 bits to 0 again (at least the ones that became "1"). So GPRM7 will look like 000000001001000. Then selection 2 plays. In the Post command the remaining 1 bits get reset to 0 as well.

After all that, the post command for the first selection regardless if track 27 or track 9 was first:

AND GPRM7, 0
AND GPRM7, 1
AND GPRM7, 2
AND GPRM7, 3
AND GPRM7, 4
AND GPRM7, 5
AND GPRM7, 6
AND GPRM7, 7
AND GPRM7, 8

Did I get it right? I'm not at work right now so I can't really test it ;)

Dimmer
13th June 2004, 11:01
Naturally, you should write binary numbers putting the most significant digit first, same as "normal" decimal numbers. For example, 6 = 110, not 011.So basically if my code looked like this:
(button 24 selected)

Mov GPRM7,SPRM8
Div GPRM7, 64
Or GPRM1,GPRM7

(next selection page)
ok, to my understanding, only bits 7 & 8 are "on" (00000011) Correct provided GPRM1 originally was 0, in which case you didn't have to use OR in the last command; MOV would've given the same result. You missed a zero though. That should be:
0000 0001 1000 0000 (hexadecimal 0x0180)
the user now selects another track (selection 9)

Mov GPRM7,SPRM8
Or GPRM1,GPRM7

(next page)

Now my GPRM looks like this: 0000001101001000 You slightly messed up the result; GPRM1 now should be:
0010 0101 1000 0000 (0x2580)
The user selects the "play list" which will play their selections in the order they were selected.

Or GPRM7,GPRM1
Mov GPRM1, 0
if GPRM7 & 16 then jump to song1
if GPRM7 & 32 then jump to song2
etc. This doesn't make sense to me. It looked like you use GPRM7 as a temporary register and GPRM1 to store the two selected values, but now you reset GPRM1 to 0. Maybe you wanted to use MOV instead of OR in the first command. Also, I can't figure out what you meant by "GPRM7 & 16", etc. since it doesn't look like a proper syntax for an IF statement. In the post command I need a command that set the first 8 bits to 0 again (at least the ones that became "1"). So GPRM7 will look like 000000001001000. Then selection 2 plays. In the Post command the remaining 1 bits get reset to 0 as well.

After all that, the post command for the first selection regardless if track 27 or track 9 was first:

AND GPRM7, 0
AND GPRM7, 1
AND GPRM7, 2
AND GPRM7, 3
AND GPRM7, 4
AND GPRM7, 5
AND GPRM7, 6
AND GPRM7, 7
AND GPRM7, 8

Did I get it right? I'm not at work right now so I can't really test it No, that's not right, it's much simpler. To blank out top 8 bits of GPRM7, you have to use:
And GPRM7, 255

255 = 0x00FF = 0000 0000 1111 1111 is referred to as "mask". It sets top 8 bits of the GPRM to 0 without changing the bottom 8 bits. In general, whatever bit of the mask is set to 1, it keeps the corresponding bit of the GPRM untouched. If a mask's bit is 0, it sets the GPRM's bit to 0. If you wanted to blank out the bottom 8 bits of the GPRM, you'd use this mask:
65280 = 0xFF00 = 1111 1111 0000 0000

Actually, I don't think you're doing the whole thing the most efficient way. Here's what I would suggest to store two selections in GPRM7, 8 bit per each selection. First selection:
Mov GPRM7, SPRM8
Div GPRM7, 256

If button 24 (0x18) was pressed, SPRM8=0x6000. After these commands, GPRM7 would be 0x0060.

Second selection:
Or GPRM7, SPRM8
Div GPRM7, 4

If button 9 was pressed, SPRM8=0x2400, GPRM7=0x0918.

Let's say GPRM0 is designated for temporary values. Then to play the first selection, you'd do:
Mov GPRM0, GPRM7
And GPRM0, 255
If (GPRM0 == 1) <jump to song 1>
...
If (GPRM0 == 26) <jump to song 26>

In the Post commands after the song's been played:
Div GPRM7, 256 *EDIT: corrected typo*

Then jump to the beginning in order to play the second selection.

Of course if you have 26 songs, you'll have to repeat the procedure 13 times using GPRM 1 - 13 to store all the selections.

GM006
13th June 2004, 12:32
Thank you for the reply. I get it now. The sonic support guy told me that If GPRM7 & 1 means its comparing... ie - If GPRM7 = 1 then jump to song1. He told me they're the same... only difference is one is checking single bits, the other is checking 16bit numbers. Oh well. Couple of more questions...
For the first selection you have Mov GPRM7, SPRM8
For the second selection you have Or GPRM7, SPRM8
Does it have to be both (Or/Mov) or can it be one or the other?
Then to check to see what song is going to play you have...
Mov GPRM0, GPRM7
And GPRM0, 255
Wouldn't that just erase the first selection from the temp holder?
And GPRM7, 255 would make more sense to me... but then again you actually know what you're doing ;)
And that post command should that be And instead of Div?
And finally how does GPRM0 = 1? I didn't see how that is possible.
Thanks again for all your help.

Dimmer
13th June 2004, 22:32
The sonic support guy told me that If GPRM7 & 1 means its comparing... ie - If GPRM7 = 1 then jump to song1. He told me they're the same... only difference is one is checking single bits, the other is checking 16bit numbers. The support guy's suggestion is for a different case. He said to check only one bit at a time. For example, GPRM7 & 16 would only check bit 4 since
16 = 0x0010 = 0000 0000 0001 0000. It means the condition will be true for 16, 17, 18, etc. This would require 2 GPRMs to store 1 selection. You however want to check 8 bits at a time.
For the first selection you have Mov GPRM7, SPRM8
For the second selection you have Or GPRM7, SPRM8
Does it have to be both (Or/Mov) or can it be one or the other?
Yes, it does. First Mov replaces the old contents of GPRM7 with the button number; then Div GPRM7, 256 shifts that number 8 bit to the right. Second Or adds another button number to GPRM7 without touching the first selection.
Then to check to see what song is going to play you have...
Mov GPRM0, GPRM7
And GPRM0, 255
Wouldn't that just erase the first selection from the temp holder? Yes, it would. That's why I use temporary holder to keep the original untouched.
And that post command should that be And instead of Div? Div shifts the GPRM value 8 the bits to the right. As a result, the top 8 bits are clean, the bottom 8 bits are the 2nd selection, and the 1st selection is gone. Sorry I made a typo there - it should be Div GPRM7, 256
And finally how does GPRM0 = 1? I didn't see how that is possible. That's the actual button number after being shifted 10 bits to the right, first with Div 256 and then with Div 4. In SPRM8, the original button number value is always shifted 10 bits to the left.

GM006
16th June 2004, 03:54
Thank You very much for your help. For the most part it worked flawlessly... I had to change a few things around to get it to work exactly the way I needed it to but it now works perfectly. Thanks again for the help and pointing me in the right direction.