Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/fbergama/pigfx
Browse files Browse the repository at this point in the history
  • Loading branch information
chregu82 committed Aug 5, 2020
2 parents 4c7b5f2 + 15e5132 commit 4788431
Show file tree
Hide file tree
Showing 18 changed files with 599 additions and 22 deletions.
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,31 @@ See [terminal_codes](doc/terminal_codes.txt) for a complete list of supported co
See [Here](https://en.wikipedia.org/wiki/File:Xterm_256color_chart.svg) for a
reference of the provided xterm color palette.

## Bitmap handling
A maximum of 128 bitmaps can be loaded to the PiGFX, either as list of pixels, or RLE compressed. Loaded bitmaps can then be put onto the background. A transparent color can be specified, these pixels won't be drawn. RLE compression expects a list of 2 byte values: first byte is the pixel color, second byte is the number of pixels to draw with this color.

See [terminal_codes](doc/terminal_codes.txt) for the specific commands.

There are 3 examples for loading bitmaps: [load bitmap](shapes/load_bitmap_sample.bin), [load RLE bitmap](shapes/load_rle_bitmap_sample.bin), [load 10 RLE dinosaur bitmaps](shapes/load_dinos.bin).

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 a 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 condition stays 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.

Sprites can be drawn solid or with a transparent color. A drawn sprite keeps its settings (solid/transparent) until it gets removed.

Once a sprite is active, you should not manipulate or reload its bitmap source, otherwise the sprite changes to this new bitmap source if it gets moved.

Animations could be realized by redefining the sprite with a different bitmap source.

There's a [example](shapes/anim_dinos.bin) for a moving dinosaur (after first loading them).

There is no collision detection yet.


## Compiling on Mac / Linux

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.
13 changes: 10 additions & 3 deletions doc/terminal_codes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,19 @@ Graphics
<ESC>[#<x0>;<y0>;<r>c Fill a circle with center at <x0>,<y0> and radius <r>
<ESC>[#<x0>;<y0>;<r>C Draw a circle with center at <x0>,<y0> and radius <r>
<ESC>[#<x0>;<y0>;<x1>;<y1>;<x2>;<y2>T Draw a triangle from <x0>,<y0> to <x1>,<y1> to <x2>,<y2>
<ESC>[#<idx>;<x>;<y>b Load raw bitmap to index 0-127 with width x and height y pixels. Expects x*y pixel bytes sent after this command.
<ESC>[#<idx>;<x>;<y>B Load RLE compressed bitmap to index 0-127 with width x and height y pixels. Expects RLE compressed 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>;<y>m Move sprite with index 0-255 to x,y, restore background.

Settings

<ESC>[m Reset color attributes (white on black)
<ESC>[38;5;<n>m Set foreground color to <n> (0-255)
<ESC>[48;5;<n>m Set background color to <n> (0-255)
<ESC>[m Reset color attributes (white on black)
<ESC>[38;5;<n>m Set foreground color to <n> (0-255)
<ESC>[48;5;<n>m Set background color to <n> (0-255)
<ESC>[58;5;<n>m Set transparent color to <n> (0-255)
<ESC>[=0m Reset color attributes (white on black) and sets normal drawing (sprites and characters)
<ESC>[=1m Set XOR drawing (sprites and characters)
<ESC>[=2m Set transparent drawing (sprites and characters)
Expand Down
2 changes: 1 addition & 1 deletion memmap
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ MEMORY
ram : ORIGIN = 0x8000, LENGTH = 10M
}

heap_size = 262144;
heap_size = 5242880;

SECTIONS
{
Expand Down
4 changes: 2 additions & 2 deletions pigfx_config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
#define HEARTBEAT_FREQUENCY 1 /* Status led blink frequency in Hz */

#define PIGFX_MAJVERSION 1 /* Major version number */
#define PIGFX_MINVERSION 6 /* Minor version number */
#define PIGFX_BUILDVERSION 2 /* Build version. */
#define PIGFX_MINVERSION 7 /* Minor version number */
#define PIGFX_BUILDVERSION 0 /* Build version. */

/** Versions:

Expand Down
4 changes: 4 additions & 0 deletions sprite/Makefile
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
img2sprite: img2sprite.cpp
g++ img2sprite.cpp -I../fonts/ -o img2sprite
png2xterm256: png2xterm256.cpp
g++ png2xterm256.cpp -I../fonts/ -o png2xterm256
rlecomp: rlecomp.cpp
g++ rlecomp.cpp -o rlecomp
1 change: 1 addition & 0 deletions sprite/anim_dinos.bin
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[=2m[#99;1;0;100s[#99;2;20;100s[#99;3;30;100s[#99;4;40;100s[#99;5;50;100s[#99;6;60;100s[#99;7;70;100s[#99;8;80;100s[#99;9;90;100s[#99;10;100;100s[#99;1;110;100s[#99;2;120;100s[#99;3;130;100s[#99;4;140;100s[#99;5;150;100s[#99;6;160;100s[#99;7;170;100s[#99;8;180;100s[#99;9;190;100s[#99;10;200;100s[#99;1;210;100s[#99;2;220;100s[#99;3;230;100s[#99;4;240;100s[#99;5;250;100s[#99;6;260;100s[#99;7;270;100s[#99;8;280;100s[#99;9;290;100s[#99;10;300;100s[#99;1;310;100s[#99;2;320;100s[#99;3;330;100s[#99;4;340;100s[#99;5;350;100s[#99;6;360;100s[#99;7;370;100s[#99;8;380;100s[#99;9;390;100s[#99;10;400;100s[#99;1;410;100s[#99;2;420;100s[#99;3;430;100s[#99;4;440;100s[#99;5;450;100s[#99;6;460;100s[#99;7;470;100s[#99;8;480;100s[#99;9;490;100s[#99;10;500;100s[#99;1;510;100s[#99;2;520;100s[#99;3;530;100s[#99;4;540;100s[#99;5;550;100s
1 change: 1 addition & 0 deletions sprite/load_bitmap_sample.bin
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[#2;100;100b                                                                                
Loading

0 comments on commit 4788431

Please sign in to comment.