[OpenBIOS] [PATCH 10/16] video_common.c: create low-level video_mask_blit() function.

Mark Cave-Ayland mark.cave-ayland at ilande.co.uk
Sun Mar 10 17:50:40 CET 2013


Switch display.fs over to use it.

Signed-off-by: Mark Cave-Ayland <mark.cave-ayland at ilande.co.uk>
---
 openbios-devel/forth/device/display.fs     |   46 ++++--------------------
 openbios-devel/include/libopenbios/video.h |    1 +
 openbios-devel/libopenbios/video_common.c  |   54 ++++++++++++++++++++++++++++
 3 files changed, 62 insertions(+), 39 deletions(-)

diff --git a/openbios-devel/forth/device/display.fs b/openbios-devel/forth/device/display.fs
index fd4ae78..f641e46 100644
--- a/openbios-devel/forth/device/display.fs
+++ b/openbios-devel/forth/device/display.fs
@@ -162,45 +162,8 @@ defer fb-emit ( x -- )
   
 \ 5.3.6.3.3 Generic eight-bit frame-buffer support
 
-\ The following two functions are unrolled for speed.
-
-
-\ blit 8 continuous pixels described by the 8bit
-\ value in bitmask8. The most significant bit is
-\ painted first. 
-
-\ this function should honour fg and bg colors
-
-: fb8-write-mask8 ( bitmask8 faddr -- )
-  over 1  and 0<> over 7 + c!
-  over 2  and 0<> over 6 + c!
-  over 4  and 0<> over 5 + c!
-  over 8  and 0<> over 4 + c!
-  over 10 and 0<> over 3 + c!
-  over 20 and 0<> over 2 + c!
-  over 40 and 0<> over 1 + c!
-  over 80 and 0<> over 0 + c!
-  2drop
-  ; 
-
-: fb8-blitmask ( fbaddr mask-addr width height --  )
-  over >r          \ save width ( -- R: width )
-  * 3 >>           \ fbaddr mask-addr width*height/8
-  bounds           \ fbaddr mask-end mask
-  r> 0 2swap       \ fbaddr width 0 mask-end mask
-  ?do              \ ( fbaddr width l-cnt )
-    2 pick over +  \ fbaddr-current
-    i c@           \ bitmask8 
-    swap fb8-write-mask8
-    ( fbaddr width l-cnt )
-    8 + 2dup = if
-      drop swap screen-width + 
-      swap 0
-    then
-    ( fbaddr width l-cnt )
-  loop
-  2drop drop
-  ;
+\ bind to low-level C function later
+defer fb8-blitmask
 
 : fb8-line2addr ( line -- addr )
   window-top +
@@ -228,6 +191,11 @@ defer fb-emit ( x -- )
   line# char-height * window-top + screen-width *
   column# char-width * window-left + + frame-buffer-adr +
   swap char-width char-height
+  \ normal or inverse?
+  foreground-color background-color
+  inverse? if
+    swap
+  then
   fb8-blitmask
   \ now advance the position
   column# 1+
diff --git a/openbios-devel/include/libopenbios/video.h b/openbios-devel/include/libopenbios/video.h
index 75e96c2..6f79b49 100644
--- a/openbios-devel/include/libopenbios/video.h
+++ b/openbios-devel/include/libopenbios/video.h
@@ -7,6 +7,7 @@ int video_get_res(int *w, int *h);
 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);
 
 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 71cca24..9fb7962 100644
--- a/openbios-devel/libopenbios/video_common.c
+++ b/openbios-devel/libopenbios/video_common.c
@@ -133,6 +133,56 @@ video_get_res( int *w, int *h )
 	return 0;
 }
 
+/* ( fbaddr maskaddr width height fgcolor bgcolor -- ) */
+
+void
+video_mask_blit(void)
+{
+	ucell bgcolor = POP();
+	ucell fgcolor = POP();
+	ucell height = POP();
+	ucell width = POP();
+	unsigned char *mask = (unsigned char *)POP();
+	unsigned char *fbaddr = (unsigned char *)POP();
+
+	ucell color;
+	unsigned char *dst, *rowdst;
+	int x, y, m, b, d, depthbytes;
+
+	fgcolor = get_color(fgcolor);
+	bgcolor = get_color(bgcolor);
+	d = video.fb.depth;
+	depthbytes = (video.fb.depth + 1) >> 3;
+
+	dst = fbaddr;
+	for( y = 0; y < height; y++) {
+		rowdst = dst;
+		for( x = 0; x < (width + 1) >> 3; x++ ) {
+			for (b = 0; b < 8; b++) {
+				m = (1 << (7 - b));
+
+				if (*mask & m) {
+					color = fgcolor;
+				} else {
+					color = bgcolor;
+				}
+
+				if( d >= 24 )
+					*((unsigned long*)dst) = color;
+				else if( d >= 15 )
+					*((short*)dst) = color;
+				else
+					*dst = color;
+
+				dst += depthbytes;
+			}
+			mask++;
+		}
+		dst = rowdst;
+		dst += video.fb.rb;
+	}
+}
+
 void
 draw_pixel( int x, int y, int colind )
 {
@@ -282,6 +332,10 @@ init_video( unsigned long fb, int width, int height, int depth, int rb )
 	feval("to frame-buffer-adr");
 	
 	/* Set global variables ready for fb8-install */
+	PUSH( pointer2cell(video_mask_blit) );
+	fword("is-noname-cfunc");
+	feval("to fb8-blitmask");
+	
 	PUSH((video.fb.depth + 1) >> 3);
 	feval("to depth-bytes");
 	PUSH((ucell)fontdata);
-- 
1.7.10.4




More information about the OpenBIOS mailing list