Skip to content

Commit

Permalink
Develop (#55)
Browse files Browse the repository at this point in the history
* Implemented several esc[m codes

* Added commands for setting default foreground and background

* Added control codes for high intensity colors

* Update gfx.c

Change the arithmetic for background intense color to correct a small color selection bug

* Updated binaries

* add 1m,2m,22m and 27m for legacy intensity support (#53)

* add 1m,2m,22m and 27m for legacy intensity support

added control codes to control color intensity, for 4 byte color selection in programs that use the legacy color selection scheme 1,2 and 22 (for programs that do not support 90m-107m).  fixed a bug in 7m that would cause older code to occasionally produce output were reverse did not work correctly when calling 7m or 27m when it was not needed (when the state was already swapped). this was done by adding a 'reverse' variable to ctx so that the terminal can keep track of color swaps for the state of the reverse text. the above fixes produce proper output with gorilla.com under CP/M.

* Update docs and bin folder

compiled the patched version

* Update gfx.c

code formatting change

* Improved formatting and fixes compile on Linux

Co-authored-by: Dave Collins <68202212+lindoran@users.noreply.github.com>
  • Loading branch information
chregu82 and lindoran committed Apr 13, 2021
1 parent 8474c1c commit e4579a8
Show file tree
Hide file tree
Showing 11 changed files with 150 additions and 21 deletions.
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ $(BUILD_DIR)/%.o : $(SRC_DIR)/%.c
@$(ARMGNU)-gcc $(CFLAGS) -c $< -o $@
@echo "CC $<"

$(BUILD_DIR)/%.o : $(SRC_DIR)/%.S
@$(ARMGNU)-gcc $(CFLAGS) -c $< -o $@
@echo "AS $<"

$(BUILD_DIR)/%.o : $(SRC_DIR)/%.s
@$(ARMGNU)-gcc $(CFLAGS) -c $< -o $@
@echo "AS $<"
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.
17 changes: 15 additions & 2 deletions doc/terminal_codes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,24 @@ Scrolling

Settings

<ESC>[m Reset color attributes (white on black)
<ESC>[m Reset color attributes (gray on black)
<ESC>[<a>;<b>;<c>m Set display attributes (1 to 3 params, so <b> and <c> are optional)
0 = Reset all attributes
1 = increase intensity (only in 4 byte mode colors 0..7)
2 = decrease intensity (only in 4 byte mode colors 8..15)
7 = Turn on reverse color
22= shifts color from dim to bright (only in 4 byte mode 0..7)
27= Turn off reverse color
30 ... 37 set foreground color to palette color 0 ... 7
40 ... 47 set background color to palette color 0 ... 7
90 ... 97 set high intensity foreground color (palette color 8 ... 15)
100 ... 107 set high intensity background color (palette color 8 ... 15)
<ESC>[38;5;<n>m Set foreground color to <n> (0-255)
<ESC>[38;6;<n>m Set foreground color to <n> (0-255) and save as default
<ESC>[48;5;<n>m Set background color to <n> (0-255)
<ESC>[48;6;<n>m Set background color to <n> (0-255) and save as default
<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>[=0m Reset color attributes (gray 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)
<ESC>[=0f Set 8x8 font
Expand Down
1 change: 1 addition & 0 deletions make.bat
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ if "%RPI%"=="4" (
echo Compiling for Pi generation %RPI%

::Get Repository Version
md build 2>NUL
del build\tmp.txt 2>NUL
git describe --all --long > build\tmp.txt
set /p GIT_DESCRIBE=<build\tmp.txt
Expand Down
1 change: 1 addition & 0 deletions makeall
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/sh
mkdir ./build
for i in 1 2 3
do
cd uspi
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 2 /* Build version. */
#define PIGFX_BUILDVERSION 3 /* Build version. */

/** Versions:

Expand Down
144 changes: 126 additions & 18 deletions src/gfx.c
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,11 @@ typedef struct {
scn_state state; /// Current scan state
} term;

GFX_COL bg; /// Background characters color
GFX_COL fg; /// Foreground characters color
GFX_COL default_bg; /// Default background characters color
GFX_COL default_fg; /// Default foreground characters color
GFX_COL bg; /// Background characters color
GFX_COL fg; /// Foreground characters color
unsigned int reverse; /// reverse status: 0 - normal; 1 -reverse
unsigned int bg32; /// Computed ctx.bg<<24 | ctx.bg<<16 | ctx.bg<<8 | ctx.bg;
unsigned int fg32; /// Computed ctx.fg<<24 | ctx.fg<<16 | ctx.fg<<8 | ctx.fg;

Expand Down Expand Up @@ -334,15 +337,33 @@ void gfx_set_env( void* p_framebuffer, unsigned int width, unsigned int height,
ctx.term.cursor_visible = 1;
ctx.term.state.next = state_fun_normaltext;


// store reverse state to 'normal'
ctx.reverse = 0;

// set default colors
gfx_set_fg(15);
gfx_set_bg(0);
gfx_set_default_fg(GRAY);
gfx_set_default_bg(BLACK);

// set colors
gfx_set_fg(ctx.default_fg);
gfx_set_bg(ctx.default_bg);

ctx.paletteloader.pCustPal = fb_get_cust_pal_p();

gfx_term_render_cursor();
}

void gfx_set_default_bg( GFX_COL col )
{
ctx.default_bg = col;
}

void gfx_set_default_fg( GFX_COL col )
{
ctx.default_fg = col;
}

/** Sets the background color. */
void gfx_set_bg( GFX_COL col )
{
Expand Down Expand Up @@ -2358,33 +2379,120 @@ int state_fun_final_letter( char ch, scn_state *state )
break;

case 'm':
if( state->cmd_params_size == 1 && state->cmd_params[0]==0 )
{
gfx_set_bg(0);
gfx_set_fg(15);
goto back_to_normal;
}
if( state->cmd_params_size == 3 &&
state->cmd_params[0]==38 &&
state->cmd_params[1]==5 )
state->cmd_params[0]==38 )
{
gfx_set_fg( state->cmd_params[2] );
if (state->cmd_params[1]==5)
{
// esc[38;5;colm
gfx_set_fg( state->cmd_params[2] );

}
else if (state->cmd_params[1]==6)
{
// esc[38;6;colm
gfx_set_fg( state->cmd_params[2] );
gfx_set_default_fg(state->cmd_params[2]);
}
goto back_to_normal;
}
if( state->cmd_params_size == 3 &&
state->cmd_params[0]==48 &&
state->cmd_params[1]==5 )
else if( state->cmd_params_size == 3 &&
state->cmd_params[0]==48 )
{
gfx_set_bg( state->cmd_params[2] );
if (state->cmd_params[1]==5)
{
// esc[48;5;colm
gfx_set_bg( state->cmd_params[2] );
}
else if (state->cmd_params[1]==6)
{
// esc[48;6;colm
gfx_set_bg( state->cmd_params[2] );
gfx_set_default_bg(state->cmd_params[2]);
}
goto back_to_normal;
}
if( state->cmd_params_size == 3 &&
else if( state->cmd_params_size == 3 &&
state->cmd_params[0]==58 &&
state->cmd_params[1]==5 )
{
// esc[58;5;colm
gfx_set_transparent_color( state->cmd_params[2] );
goto back_to_normal;
}
else if (state->cmd_params_size == 0)
{
// esc[m
gfx_set_bg(ctx.default_bg);
gfx_set_fg(ctx.default_fg);
ctx.reverse = 0; // sets reverse to 'normal' for the current defaults.
goto back_to_normal;
}
else
{
// esc[par1;par2;par3m (actually one to 3 params)
if (state->cmd_params_size > 3) state->cmd_params_size = 3; // limit to 3
for (unsigned int i=0; i<state->cmd_params_size; i++)
{
switch (state->cmd_params[i])
{
case 0:
// reset
gfx_set_bg(ctx.default_bg);
gfx_set_fg(ctx.default_fg);
ctx.reverse = 0; // sets reverse to 'normal' for the current defaults.
break;
case 1:
// increase intensity - as 22m for 4byte TODO: 256 Color pal
if (ctx.fg <= 7) gfx_set_fg(ctx.fg+8);
break;
case 2:
// decrease intensity -transpose dim fg colors from bright TODO 255 color pal
if (ctx.fg >= 8) gfx_set_fg(ctx.fg-8);
break;
case 7:
// toggle text mode to 'reverse'
if (ctx.reverse == 0)
{
gfx_swap_fg_bg();
ctx.reverse = 1;
}
break;
case 22:
// transpose bright fg colors from dim, this is interesting it is meant to be 'normal'
// but is often implemented as 'bright', this is needed for gorilla.bas compatiblity.
// function is fliped since the normal terminal color is often 'dim'; in this case it is.
// TODO: 256 color (how would this have effect?)
if (ctx.fg <= 7) gfx_set_fg(ctx.fg+8);
break;
case 27:
// toggle text mode to 'normal'
if (ctx.reverse == 1)
{
gfx_swap_fg_bg();
ctx.reverse = 0;
}
break;
case 30 ... 37:
// fg color
gfx_set_fg(state->cmd_params[i]-30);
break;
case 40 ... 47:
// bg color
gfx_set_bg(state->cmd_params[i]-40);
break;
case 90 ... 97:
// bright foreground color 8 to 15
gfx_set_fg(state->cmd_params[i]-82);
break;
case 100 ... 107:
// bright background color 8 to 15
gfx_set_bg(state->cmd_params[i]-92);
break;
}
}
goto back_to_normal;
}
goto back_to_normal;
break;

Expand Down
2 changes: 2 additions & 0 deletions src/gfx.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

// gfx functions
extern void gfx_set_env( void* p_framebuffer, unsigned int width, unsigned int height, unsigned int bpp, unsigned int pitch, unsigned int size );
extern void gfx_set_default_bg( GFX_COL col );
extern void gfx_set_default_fg( GFX_COL col );
extern void gfx_set_bg( GFX_COL col );
extern void gfx_set_fg( GFX_COL col );
extern void gfx_swap_fg_bg();
Expand Down

0 comments on commit e4579a8

Please sign in to comment.