Switch display.fs over to use it.
Signed-off-by: Mark Cave-Ayland mark.cave-ayland@ilande.co.uk --- openbios-devel/forth/device/display.fs | 31 ++++++--------- openbios-devel/include/libopenbios/video.h | 1 + openbios-devel/libopenbios/video_common.c | 58 ++++++++++++++++++++++++++++ 3 files changed, 70 insertions(+), 20 deletions(-)
diff --git a/openbios-devel/forth/device/display.fs b/openbios-devel/forth/device/display.fs index f641e46..f59ef1f 100644 --- a/openbios-devel/forth/device/display.fs +++ b/openbios-devel/forth/device/display.fs @@ -164,6 +164,7 @@ defer fb-emit ( x -- )
\ bind to low-level C function later defer fb8-blitmask +defer fb8-invertrect
: fb8-line2addr ( line -- addr ) window-top + @@ -225,15 +226,11 @@ defer fb8-blitmask ;
: fb8-toggle-cursor ( -- ) - line# char-height * window-top + screen-width * - column# char-width * window-left + + frame-buffer-adr + - char-height 0 ?do - char-width 0 ?do - dup i + dup c@ invert ff and swap c! - loop - screen-width + - loop - drop + column# char-width * window-left + + line# char-height * window-top + + char-width char-height + foreground-color background-color + fb8-invertrect ;
: fb8-erase-screen ( -- ) @@ -248,20 +245,14 @@ defer fb8-blitmask ;
: fb8-invert-screen ( -- ) - frame-buffer-adr - screen-height screen-width * - bounds ?do - i c@ case - foreground-color of background-color endof - background-color of foreground-color endof - dup - endcase - i c! - loop + 0 0 screen-width screen-height + background-color foreground-color + fb8-invertrect ;
: fb8-blink-screen ( -- ) - fb8-invert-screen fb8-invert-screen + fb8-invert-screen 2000 ms + fb8-invert-screen ;
: fb8-insert-characters ( n -- ) diff --git a/openbios-devel/include/libopenbios/video.h b/openbios-devel/include/libopenbios/video.h index 6f79b49..4f10eb8 100644 --- a/openbios-devel/include/libopenbios/video.h +++ b/openbios-devel/include/libopenbios/video.h @@ -8,6 +8,7 @@ void draw_pixel(int x, int y, int colind); void video_scroll(int height); void fill_rect(int col_ind, int x, int y, int w, int h); void video_mask_blit(void); +void video_invert_rect(void);
typedef struct osi_fb_info { unsigned long mphys; diff --git a/openbios-devel/libopenbios/video_common.c b/openbios-devel/libopenbios/video_common.c index 9fb7962..d1a81b5 100644 --- a/openbios-devel/libopenbios/video_common.c +++ b/openbios-devel/libopenbios/video_common.c @@ -183,6 +183,61 @@ video_mask_blit(void) } }
+/* ( x y w h fgcolor bgcolor -- ) */ + +void +video_invert_rect( void ) +{ + ucell bgcolor = POP(); + ucell fgcolor = POP(); + int h = POP(); + int w = POP(); + int y = POP(); + int x = POP(); + char *pp; + + bgcolor = get_color(bgcolor); + fgcolor = get_color(fgcolor); + + if (!video.has_video || x < 0 || y < 0 || w <= 0 || h <= 0 || + x + w > video.fb.w || y + h > video.fb.h) + return; + + pp = (char*)video.fb.mvirt + video.fb.rb * y; + for( ; h--; pp += video.fb.rb ) { + int ww = w; + if( video.fb.depth == 24 || video.fb.depth == 32 ) { + unsigned long *p = (unsigned long*)pp + x; + while( ww-- ) { + if (*p == fgcolor) { + *p++ = bgcolor; + } else if (*p == bgcolor) { + *p++ = fgcolor; + } + } + } else if( video.fb.depth == 16 || video.fb.depth == 15 ) { + unsigned short *p = (unsigned short*)pp + x; + while( ww-- ) { + if (*p == (unsigned short)fgcolor) { + *p++ = bgcolor; + } else if (*p == (unsigned short)bgcolor) { + *p++ = fgcolor; + } + } + } else { + char *p = (char *)(pp + x); + + while( ww-- ) { + if (*p == (char)fgcolor) { + *p++ = bgcolor; + } else if (*p == (char)bgcolor) { + *p++ = fgcolor; + } + } + } + } +} + void draw_pixel( int x, int y, int colind ) { @@ -335,6 +390,9 @@ init_video( unsigned long fb, int width, int height, int depth, int rb ) PUSH( pointer2cell(video_mask_blit) ); fword("is-noname-cfunc"); feval("to fb8-blitmask"); + PUSH( pointer2cell(video_invert_rect) ); + fword("is-noname-cfunc"); + feval("to fb8-invertrect"); PUSH((video.fb.depth + 1) >> 3); feval("to depth-bytes");