Skip to content

Commit

Permalink
Merge pull request #45 from fbergama/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
chregu82 authored Oct 3, 2020
2 parents 159502f + d398b1b commit 8474c1c
Show file tree
Hide file tree
Showing 14 changed files with 420 additions and 145 deletions.
17 changes: 12 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,20 @@ Code | Command

See [terminal_codes](doc/terminal_codes.txt) for a complete list of supported commands.

## Color palette

See [Here](https://en.wikipedia.org/wiki/File:Xterm_256color_chart.svg) for a
reference of the provided xterm color palette.
reference of the provided xterm color palette. This is the default palette used by PiGFX.

A RGB pixel can be converted to this palette by the following formula:

Pixel = 16 + (round(R / 255 * 5) * 36) + (round(G / 255 * 5) * 6) + round(B / 255 * 5)

Using a different color palette is possible. It can be switched with a control code, see [terminal_codes](doc/terminal_codes.txt).

Possible palettes are Xterm, VGA and C64. PiGFX always uses 256 colors, so the unused colors in a palette remain black.

It's also possible to load a custom color palette with a specific control code.

## Bitmap handling
A maximum of 128 bitmaps can be loaded to the PiGFX, either as list of binary pixels, list of ASCII decimal encoded pixels or list of ASCII hex encoded pixels. All of these can be RLE compressed. Loaded bitmaps can then be put onto the background. A transparent color can be specified before drawing a bitmap, these pixels won't be drawn in transparent mode. RLE compression expects a list of 2 values: first one is the pixel color, second one is the number of pixels to draw with this color.
Expand All @@ -175,10 +186,6 @@ See [terminal_codes](doc/terminal_codes.txt) for the specific commands.

There are a few examples in [this directory](sprite/sample).

The Xterm palette is used. A RGB pixel can be converted to this palette by the following formula:

Pixel = 16 + (round(R / 255 * 5) * 36) + (round(G / 255 * 5) * 6) + round(B / 255 * 5)

## Sprite handling

Once a bitmap is loaded, it can be used to draw a maximum of 256 sprites. A sprite is an object which is movable over the background. If a sprite is moved or removed, the previous background gets restored. If the sprite is manipulated by a bitmap or a different sprite, this state remains until it gets moved or removed. The sprite is then redrawn and the previous background restored. Moving a sprites, which is overlaped by another leads to artefacts.
Expand Down
Binary file modified bin/kernel.img
Binary file not shown.
Binary file modified bin/kernel7.img
Binary file not shown.
Binary file modified bin/kernel8-32.img
Binary file not shown.
Binary file modified bin/recovery7l.img
Binary file not shown.
14 changes: 13 additions & 1 deletion doc/terminal_codes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,15 @@ Graphics
<ESC>[#<idx>;<x>;<y>B Load RLE compressed bitmap to index 0-127 with width x and height y pixels. Expects RLE compressed binary pixel data after this command, e.g. 0x10 0x20 draws color 16 for the next 32 pixels.
<ESC>[#<idx>;<x>;<y>d Draw bitmap with index 0-127 at position x, y.
<ESC>[#<idx>;<ref>;<x>;<y>s Draw a sprite with index 0-255 from bitmap <ref> at position <x>, <y>.
<ESC>[#<idx>;x Remove sprite with index 0-255, restore background.
<ESC>[#<idx>x Remove sprite with index 0-255, restore background.
<ESC>[#<idx>;<x>;<y>m Move sprite with index 0-255 to x,y, restore background.

Scrolling

<ESC>[#<n>" Scroll up by <n> pixels, fill with background color.
<ESC>[#<n>_ Scroll down by <n> pixels, fill with background color.
<ESC>[#<n>< Scroll left by <n> pixels, fill with background color.
<ESC>[#<n>> Scroll right by <n> pixels, fill with background color.

Settings

Expand All @@ -70,6 +77,11 @@ Settings
<ESC>[=<n>t Set tabulation width (8 by default)
<ESC>[=<n>h Change to display mode <n> (legacy PC ANSI.SYS)
This is actually only approximate resolutions (check README_ADD)
<ESC>[=<n>p Load color palette <n>, where 0=XTerm (default), 1=VGA, 2=custom, 3=C64
<ESC>[=<b>;<n>p Set custom palette, with <n> as the number of colors to follow (1-256) and <b> as the base (10 for decimal or 16 for hex).
<n> colors need to follow this command. Color information is always 8bit RGB, e.g. 000000 for black or FFFFFF for white.
A semicolon after the last color needs to be sent.
Here's an example for color 0:red, 1:green, 2:blue -> <ESC>[=16;3pFF0000;FF00;FF;

Commands from PiGFX to the controller

Expand Down
2 changes: 1 addition & 1 deletion pigfx_config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

#define PIGFX_MAJVERSION 1 /* Major version number */
#define PIGFX_MINVERSION 8 /* Minor version number */
#define PIGFX_BUILDVERSION 1 /* Build version. */
#define PIGFX_BUILDVERSION 2 /* Build version. */

/** Versions:

Expand Down
131 changes: 10 additions & 121 deletions src/framebuffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,71 +14,7 @@
#include "synchronize.h"
#include "memory.h"
#include "mbox.h"

#define NB_PALETTE_ELE 256


static const unsigned int xterm_colors[NB_PALETTE_ELE] = {
// 16 half/full bright RGB colors
0x000000, 0x800000, 0x008000, 0x808000, 0x000080,
0x800080, 0x008080, 0xc0c0c0, 0x808080, 0xff0000,
0x00ff00, 0xffff00, 0x0000ff, 0xff00ff, 0x00ffff,
0xffffff,
// gradients
0x000000, 0x00005f, 0x000087, 0x0000af,
0x0000df, 0x0000ff, 0x005f00, 0x005f5f, 0x005f87,
0x005faf, 0x005fdf, 0x005fff, 0x008700, 0x00875f,
0x008787, 0x0087af, 0x0087df, 0x0087ff, 0x00af00,
0x00af5f, 0x00af87, 0x00afaf, 0x00afdf, 0x00afff,
0x00df00, 0x00df5f, 0x00df87, 0x00dfaf, 0x00dfdf,
0x00dfff, 0x00ff00, 0x00ff5f, 0x00ff87, 0x00ffaf,
0x00ffdf, 0x00ffff, 0x5f0000, 0x5f005f, 0x5f0087,
0x5f00af, 0x5f00df, 0x5f00ff, 0x5f5f00, 0x5f5f5f,
0x5f5f87, 0x5f5faf, 0x5f5fdf, 0x5f5fff, 0x5f8700,
0x5f875f, 0x5f8787, 0x5f87af, 0x5f87df, 0x5f87ff,
0x5faf00, 0x5faf5f, 0x5faf87, 0x5fafaf, 0x5fafdf,
0x5fafff, 0x5fdf00, 0x5fdf5f, 0x5fdf87, 0x5fdfaf,
0x5fdfdf, 0x5fdfff, 0x5fff00, 0x5fff5f, 0x5fff87,
0x5fffaf, 0x5fffdf, 0x5fffff, 0x870000, 0x87005f,
0x870087, 0x8700af, 0x8700df, 0x8700ff, 0x875f00,
0x875f5f, 0x875f87, 0x875faf, 0x875fdf, 0x875fff,
0x878700, 0x87875f, 0x878787, 0x8787af, 0x8787df,
0x8787ff, 0x87af00, 0x87af5f, 0x87af87, 0x87afaf,
0x87afdf, 0x87afff, 0x87df00, 0x87df5f, 0x87df87,
0x87dfaf, 0x87dfdf, 0x87dfff, 0x87ff00, 0x87ff5f,
0x87ff87, 0x87ffaf, 0x87ffdf, 0x87ffff, 0xaf0000,
0xaf005f, 0xaf0087, 0xaf00af, 0xaf00df, 0xaf00ff,
0xaf5f00, 0xaf5f5f, 0xaf5f87, 0xaf5faf, 0xaf5fdf,
0xaf5fff, 0xaf8700, 0xaf875f, 0xaf8787, 0xaf87af,
0xaf87df, 0xaf87ff, 0xafaf00, 0xafaf5f, 0xafaf87,
0xafafaf, 0xafafdf, 0xafafff, 0xafdf00, 0xafdf5f,
0xafdf87, 0xafdfaf, 0xafdfdf, 0xafdfff, 0xafff00,
0xafff5f, 0xafff87, 0xafffaf, 0xafffdf, 0xafffff,
0xdf0000, 0xdf005f, 0xdf0087, 0xdf00af, 0xdf00df,
0xdf00ff, 0xdf5f00, 0xdf5f5f, 0xdf5f87, 0xdf5faf,
0xdf5fdf, 0xdf5fff, 0xdf8700, 0xdf875f, 0xdf8787,
0xdf87af, 0xdf87df, 0xdf87ff, 0xdfaf00, 0xdfaf5f,
0xdfaf87, 0xdfafaf, 0xdfafdf, 0xdfafff, 0xdfdf00,
0xdfdf5f, 0xdfdf87, 0xdfdfaf, 0xdfdfdf, 0xdfdfff,
0xdfff00, 0xdfff5f, 0xdfff87, 0xdfffaf, 0xdfffdf,
0xdfffff, 0xff0000, 0xff005f, 0xff0087, 0xff00af,
0xff00df, 0xff00ff, 0xff5f00, 0xff5f5f, 0xff5f87,
0xff5faf, 0xff5fdf, 0xff5fff, 0xff8700, 0xff875f,
0xff8787, 0xff87af, 0xff87df, 0xff87ff, 0xffaf00,
0xffaf5f, 0xffaf87, 0xffafaf, 0xffafdf, 0xffafff,
0xffdf00, 0xffdf5f, 0xffdf87, 0xffdfaf, 0xffdfdf,
0xffdfff, 0xffff00, 0xffff5f, 0xffff87, 0xffffaf,
0xffffdf, 0xffffff,
// 24 gray scales
0x080808, 0x121212, 0x1c1c1c,
0x262626, 0x303030, 0x3a3a3a, 0x444444, 0x4e4e4e,
0x585858, 0x606060, 0x666666, 0x767676, 0x808080,
0x8a8a8a, 0x949494, 0x9e9e9e, 0xa8a8a8, 0xb2b2b2,
0xbcbcbc, 0xc6c6c6, 0xd0d0d0, 0xdadada, 0xe4e4e4,
0xeeeeee
};


#include "palette.h"

/*
* Framebuffer initialization is a modified version
Expand Down Expand Up @@ -289,63 +225,11 @@ FB_RETURN_TYPE fb_get_phys_res(unsigned int* pRes_w, unsigned int* pRes_h)
return FB_SUCCESS;
}

FB_RETURN_TYPE fb_set_grayscale_palette()
FB_RETURN_TYPE fb_set_palette(unsigned char idx)
{
// Set grayscale palette
unsigned int i;
typedef struct
{
mbox_msgheader_t header;
mbox_tagheader_t tag;

union
{
struct
{
uint32_t offset;
uint32_t nbrOfEntries;
uint32_t entries[NB_PALETTE_ELE];
}
request;
struct
{
uint32_t invalid;
}
response;
}
value;

mbox_msgfooter_t footer;
}
message_t;

message_t* msg = (message_t*)MEM_COHERENT_REGION;

msg->header.size = sizeof(*msg);
msg->header.code = 0;
msg->tag.id = MAILBOX_TAG_SET_PALETTE;
msg->tag.size = sizeof(msg->value);
msg->tag.code = 0;

msg->value.request.offset = 0;
msg->value.request.nbrOfEntries = NB_PALETTE_ELE;
for(i=0;i<NB_PALETTE_ELE;i++)
{
msg->value.request.entries[i] = (i & 0xFF)<<16 | (i & 0xFF)<<8 | (i & 0xFF);
msg->value.request.entries[i] = msg->value.request.entries[i] | 0xFF000000; //alpha
}

msg->footer.end = 0;

if (mbox_send(msg) != 0) {
return FB_ERROR;
}
// check idx
idx = idx % NB_PALETTES;

return FB_SUCCESS;
}

FB_RETURN_TYPE fb_set_xterm_palette()
{
// Set xterm palette
unsigned int i;
typedef struct
Expand Down Expand Up @@ -386,7 +270,7 @@ FB_RETURN_TYPE fb_set_xterm_palette()
msg->value.request.nbrOfEntries = NB_PALETTE_ELE;
for(i=0;i<NB_PALETTE_ELE;i++)
{
const unsigned int vc = xterm_colors[i];
const unsigned int vc = palette[idx][i];
msg->value.request.entries[i] = (vc<<16 & 0xFF0000) | ( vc & 0x00FF00) | ( vc>>16 & 0x0000FF) | 0xFF000000;
}

Expand Down Expand Up @@ -477,3 +361,8 @@ FB_RETURN_TYPE fb_switch_framebuffer(unsigned int yOffset)

return FB_SUCCESS;
}

unsigned int* fb_get_cust_pal_p()
{
return &palette[pal_custom][0];
}
4 changes: 2 additions & 2 deletions src/framebuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ extern FB_RETURN_TYPE fb_init( unsigned int ph_w, unsigned int ph_h, unsigned in
unsigned int bpp, void** pp_fb, unsigned int* pfbsize, unsigned int* pPitch );
extern FB_RETURN_TYPE fb_release();
FB_RETURN_TYPE fb_get_phys_res(unsigned int* pRes_w, unsigned int* pRes_h);
extern FB_RETURN_TYPE fb_set_grayscale_palette();
extern FB_RETURN_TYPE fb_set_xterm_palette();
extern FB_RETURN_TYPE fb_set_palette(unsigned char idx);
FB_RETURN_TYPE fb_get_pitch( unsigned int* pPitch );
FB_RETURN_TYPE fb_switch_framebuffer(unsigned int yOffset);
extern unsigned int* fb_get_cust_pal_p();


#endif
Loading

0 comments on commit 8474c1c

Please sign in to comment.