Go Down

Topic: TV out display.screen WHAT IS IT ?? (Read 766 times) previous topic - next topic

Katzmatt

currently i am working on porting the games made for the hackvision over to be able to use the OLED 128x64 B/W display from adafruit http://www.adafruit.com/products/326
and replacing the TVout with its library
and i keep coming across this command
Code: [Select]
display.screen[si++] &= ~(temp >> rshift); or something similar it always starts with the display.screen and i know it deals with Bitmaps and such but there is NO mention of this command in the TVout library nor any of the libraries of the hackvision http://nootropicdesign.com/projectlab/2011/02/06/asteroids-on-hackvision/
and because i dont know what this command is i cannot change the command to the new library for the OLED display so im really stuck in a rut so to speak
i have found this stupid command in almost all of the libraries
PLEASE help i have a deadline in about 2 weeks
in the asteroids code it is in the main code at approximately line 1745 ish
thanks

AWOL

Code: [Select]
display.screen[si++] &= ~(temp >> rshift);
Just work through the expression and decompose it.
There's a right shift (>>), a bitwise NOT (~) and a bitwise AND (&) operation.
That usually implies trying to reset some bits.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Katzmatt

in some spots the code is something like display.screen[index] &= b11110000 //this was from the tetris code

or something like that but it just dosent translate in any way to something that could be thought of as a bitmap command

for the Oled library this is the complete command for bitmaps
  display.clearDisplay();
  display.drawBitmap(30, 16,  logo16_glcd_bmp, 16, 16, 1);
  display.display();
it just dosnt make sense

AWOL

Quote
it just dosent translate in any way to something that could be thought of as a bitmap command
so what technique does it use?
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Katzmatt

thats exactly it
there is not command i can find that specifically does bitmaps that are included
this is the commands in the tetris one
its slightly different in that its TV.screen
Code: [Select]
void setCell(char x, char y,char bx, char by, char c, char f) {
  int index = bx/8 + x/2 + by*W/8 + y*4*W/8;
  if (c) {
    if (x & 1) {
      TV.screen[index] &= 0b11110000;
      TV.screen[index] |= 0b00001110;
      index+=W/8;
      TV.screen[index] &= 0b11110000;
      TV.screen[index] |= 0b00001010;
      if (f) TV.screen[index] &= 0b11111011;
      index+=W/8;
      TV.screen[index] &= 0b11110000;
      TV.screen[index] |= 0b00001110;
      index+=W/8;
      TV.screen[index] &= 0b11110000;
    }



and this is in the asteroids
Code: [Select]
void overlaybitmap(uint8_t x, uint8_t y, const unsigned char * bmp,
   uint16_t i, uint8_t width, uint8_t lines) {

uint8_t temp, lshift, rshift, save, xtra;
uint16_t si = 0;

rshift = x&7;
lshift = 8-rshift;
if (width == 0) {
  width = pgm_read_byte((uint32_t)(bmp) + i);
  i++;
}
if (lines == 0) {
  lines = pgm_read_byte((uint32_t)(bmp) + i);
  i++;
}

if (width&7) {
  xtra = width&7;
  width = width/8;
  width++;
}
else {
  xtra = 8;
  width = width/8;
}

for (uint8_t l = 0; l < lines; l++) {
  si = ((y + l) % display.vres())*display.hres() + x/8;
  //si = (y + l)*display.hres + x/8;
  if (width == 1)
    temp = 0xff >> rshift + xtra;
  else
    temp = 0;
  save = display.screen[si];
  temp = pgm_read_byte((uint32_t)(bmp) + i++);
  display.screen[si++] |= temp >> rshift;
  for ( uint16_t b = i + width-1; i < b; i++) {
    if (si % display.hres() == 0) {
      // wrapped around to the left side
      si -= display.hres();
    }
    save = display.screen[si];
    display.screen[si] |= temp << lshift;
    temp = pgm_read_byte((uint32_t)(bmp) + i);
    display.screen[si++] |= temp >> rshift;
  }
  if (si % display.hres == 0) {
    // wrapped around to the left side
    si -= display.hres;
  }
  if (rshift + xtra < 8)
    display.screen[si-1] |= (save & (0xff >> rshift + xtra)); //test me!!!
  display.screen[si] |= temp << lshift;
}
} // end of bitmap


im confused because in the tetris one it takes all the necissary information to make the bitmaps
(in tetris it seems to be laying out the squares for where one of three things could be a full square, a ghost square or a empty square)
and it has all the cordinate info for the bitmap here
Code: [Select]
int index = bx/8 + x/2 + by*W/8 + y*4*W/8;
BUT instead of having it all nice and seperated like whats required in the OLED library it adds it all together BUT WHY i dont geddit because then it becomes an indecipherable mess of numbers
i have tried doing the numbers on paper and switching to binary and the like but nothing seems to work
i have also looked in the tv library files and it does not mention anything about a screen command

as for if this is bitmap
it is
but how? i do not know

AWOL

Quote
BUT WHY i dont geddit because then it becomes an indecipherable mess of numbers

It's a means of making the code as efficient as possible.
It is never intended to be portable, but as fast and precise as possible.
TV has to be quick and exact, or frames will roll or lines stretch.

Get a sheet of paper and work through a couple of line.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Tom Carpenter

#6
Jul 11, 2012, 10:37 pm Last Edit: Jul 11, 2012, 10:39 pm by TCWORLD Reason: 1
Just to get an idea lets compare these two lines of code. I know they are from different examples, but that doesn't matter, lets just assume we want them to do the same thing.
Code: [Select]
TV.screen[index] &= ~(temp >> rshift);
Code: [Select]
TV.screen[index] &= 0b11110000;

What happens if say be let: temp = 240, and rshift = 4.
Then work through it. The first thing it would do, would be:

(temp >> rshift) = (240 >> 4) = (0b11110000 >> 4) = 0b00001111

Then it would do the bitwise not (the ~ symbol) which basically says if a bit is 1, then it should be 0 and vice versa. So:
~0b00001111 = 0b11110000.

Can you see then that in this case the two do exacly the same thing? (assuming the numbers were the two I gave)

Now say you wanted to do this:
Code: [Select]

TV.screen[index] &= 0b01111111;
TV.screen[index+1] &= 0b10111111;
TV.screen[index+2] &= 0b11011111;
TV.screen[index+3] &= 0b11101111;
TV.screen[index+4] &= 0b11110111;
TV.screen[index+5] &= 0b11111011;
TV.screen[index+6] &= 0b11111101;
TV.screen[index+7] &= 0b11111110;

That took a lot of writing out, and we had to get the bit patterns exactly right. Now imagine you have 100, or 1000 of these. That would be ALOT of work for us. Wouldn't it be great if the arduino did all the hard work.

Now consider this:
Code: [Select]
for(byte i = 0; i < 8; i++){
 TV.screen[index+i] &= ~(128 >> i); //128 in binary is 0b10000000
}


Follow it through. Can you see that the result is exactly the same? (HINT: do it as in the first example, the bit shift first, then the not)


It is simply a way of saving you effort and reducing the program size. It just depends on the situation. There is no right or wrong way (although in my example the latter would be much more desireable). :)
~Tom~

Go Up