Login [Register]
Don't have an account? Register now to chat, post, use our tools, and much more.
Hi.

I am playing around with drawing different coloured pixels on the screen. Can someone confirm that the pixel layout for 16bpp is BRG, and if so how many bits are dedicated to each channel?

Through trial and error I am able to get the colours that I want, for example if I want to draw a single yellow pixel on the screen I am doing the following.


Code:

    ld hl,vRam
    ld (hl),%00000111
    inc hl
    ld (hl),%11111111
    ret
http://wikiti.brandonw.net/index.php?title=84PCE:Ports:4000

See the comments under LCDControl. It's generally 565 RGB mode when you use the OS defaults.
By default, the LCD controller and the LCD itself are both swapping red and blue color components intending to use BGR mode, however these two operations cancel each other out and you end up with RGB mode. The LCD controller also has settings that affect both the endianness of bytes and bits as well as the bits per pixel, but the default layout used by the OS is:
Code:
   ld hl,vRam
   ld (hl),%bbbbbggg ; component bit indices: 43210 543
   inc hl
   ld (hl),%gggrrrrr ; component bit indices: 210 43210
   ret
Hmmm, maybe I am missing something then.

The following code seems to colour the first pixel in appropriately, however it seems that the first 5 bits utilize the blue channel, and the last 5 bits use the green channel.


Code:

colorBlue:
   ld hl,vRam
   ld (hl),%11111000
   inc hl
   ld (hl),%00000000
   ret

colorRed:
   ld hl,vRam
   ld (hl),%00000111
   inc hl
   ld (hl),%11100000
   ret

colorGreen:
   ld hl,vRam
   ld (hl),%00000000
   inc hl
   ld (hl),%00011111
   ret
Sorry, I got the byte endianness backwards... It should have been:
Code:
   ld hl,vRam
   ld (hl),%gggbbbbb ; component bit indices: 210 43210
   inc hl
   ld (hl),%rrrrrggg ; component bit indices: 43210 543
   ret
Which means the colors are:
Code:
colorBlue:
   ld hl,vRam
   ld (hl),%00011111
   inc hl
   ld (hl),%00000000
   ret

colorGreen:
   ld hl,vRam
   ld (hl),%11100000
   inc hl
   ld (hl),%00000111
   ret

colorRed:
   ld hl,vRam
   ld (hl),%00000000
   inc hl
   ld (hl),%11111000
   ret
Makes sense now, thanks guys.
As a followup, I was wondering if using `ldir` it is possible to color the entire screen a particular color using 16bpp?
Technically it is, but it does limit the total amount of colours that you can choose from.
tr1p1ea wrote:
Technically it is, but it does limit the total amount of colours that you can choose from.


I'm assuming it's because you can only set what is in (hl) and then it's fire and forget with `ldir`. I guess this would mean that to use 16bpp you would have to assign [address] and [address+1] explicitly and loop over each subsequent set of two address spaces until you reach the label address `vRamEnd`.

I guess this means that if you want to color the entire screen you would normally be better off using an 8bpp palette since it would map better using `ldir`?
You can absolutely use ldir to fill the screen with a 16-bit color. I think the code would look something like this (untested):

Code:
; Fill VRAM with the 16-bit color in de
FillScreen:
   ld   hl,vRam
   ld   (hl),de
   ld   de,vRam+2
   ld   bc,lcdWidth*lcdHeight*2-2
   ldir
   ret
Ahh yes Runer is correct here.
Confirmed, thanks Runer.
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are GMT - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement