summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Stenberg <daniel@haxx.se>2002-03-26 10:59:39 +0000
committerDaniel Stenberg <daniel@haxx.se>2002-03-26 10:59:39 +0000
commit319d1f3406f200e08cac3d76c90d6b62dfda25e9 (patch)
treebe4f8a0cb013615b1a510a5dadfc3d071447f813
parentd20e6eee0e483582a40968bff25108c3ed855195 (diff)
lcd_update() works for X11 now...
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@15 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--uisimulator/Makefile2
-rw-r--r--uisimulator/lcd-recorder.c37
-rw-r--r--uisimulator/lcd-x11.c45
-rw-r--r--uisimulator/lcd.c91
-rw-r--r--uisimulator/lcd.h26
-rw-r--r--uisimulator/uibasic.c45
6 files changed, 189 insertions, 57 deletions
diff --git a/uisimulator/Makefile b/uisimulator/Makefile
index 121c2b0a9f..858c1dafe0 100644
--- a/uisimulator/Makefile
+++ b/uisimulator/Makefile
@@ -29,7 +29,7 @@ LDFLAGS = -lX11 -lm -lXt -lXmu -lsocket -lnsl
DEPEND = .depends
OBJS= alpha.o hsv.o screenhack.o yarandom.o uibasic.o resources.o visual.o\
- usleep.o
+ usleep.o lcd.c lcd-x11.c
SRCS = $(OBJS:%.o=%.c)
HDRS = $(OBJS:%.o=%.h)
diff --git a/uisimulator/lcd-recorder.c b/uisimulator/lcd-recorder.c
index 37f4d3b142..f7623937c5 100644
--- a/uisimulator/lcd-recorder.c
+++ b/uisimulator/lcd-recorder.c
@@ -79,6 +79,7 @@ void lcd_update (void)
}
}
+#if 0
/*
* Display a string at current position
*/
@@ -107,42 +108,8 @@ void lcd_string (const char *text, BOOL invert)
}
}
}
+#endif
-/*
- * Display a character.
- * This writes a 5x8 character within a 6x8 cell.
- * The cell does not have to be aligned to a display byte.
- * The top left of the cell is displayed at the current position.
- * invert is TRUE to display in reverse video.
- */
-void lcd_char (int ch, BOOL invert)
-{
- uchar (*dp)[DISP_X] = (void *) &display[lcd_y/8][lcd_x];
- uint32 shift, mask, col;
-
- /* Limit to char generation table */
- if (ch < ASCII_MIN || ch > ASCII_MAX)
- ch = ASCII_MAX;
-
- /* Calculate shift and masks for cell bit position */
- shift = (lcd_y & 0x7);
- mask = ~(COL_MASK << shift);
- if (invert)
- invert = ~mask;
-
- /* Write each char column */
- for (col = 0; col < CHAR_X-1; col++) {
- uint32 data = (char_gen[ch-ASCII_MIN][col] << shift) ^ invert;
- dp[0][col] = (dp[0][col] & mask) | data;
- if (lcd_y < DISP_Y-8)
- dp[1][col] = (dp[1][col] & (mask >> 8)) | (data >> 8);
- }
-
- /* Column after char */
- dp[0][CHAR_X-1] = (dp[0][CHAR_X-1] & mask) | invert;
- if (lcd_y < DISP_Y-8)
- dp[1][CHAR_X-1] = (dp[1][CHAR_X-1] & (mask >> 8)) | (invert >> 8);
-}
/*
* Write a byte to LCD controller.
diff --git a/uisimulator/lcd-x11.c b/uisimulator/lcd-x11.c
index efd6c9e8bd..7655765137 100644
--- a/uisimulator/lcd-x11.c
+++ b/uisimulator/lcd-x11.c
@@ -17,7 +17,50 @@
*
****************************************************************************/
+#include <stdio.h>
+#include <string.h>
+#include <stdarg.h>
+#include <stdlib.h>
+#include <ctype.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+
+#include <errno.h>
+#include <ctype.h>
+#include <time.h>
+
+#include "screenhack.h"
+
/*
- * Specific implementations for X11, using the generic LCD functions and data.
+ * Specific implementations for X11, using the generic LCD API and data.
*/
+#include "lcd.h"
+
+extern unsigned char display[LCD_WIDTH/8][LCD_HEIGHT];
+
+void lcd_update (void)
+{
+ int x, y;
+ int p=0;
+ int bit;
+ XPoint points[LCD_WIDTH * LCD_HEIGHT];
+
+ for(y=0; y<LCD_HEIGHT; y+=8) {
+ for(x=0; x<LCD_WIDTH; x++) {
+ if(display[y/8][x]) {
+ /* one or more bits/pixels are set */
+ for(bit=0; bit<8; bit++) {
+ if(display[y/8][x]&(1<<bit)) {
+ points[p].x = x;
+ points[p].y = y+bit;
+ p++; /* increase the point counter */
+ }
+ }
+
+ }
+ }
+ }
+ drawdots(&points[0], p);
+}
diff --git a/uisimulator/lcd.c b/uisimulator/lcd.c
index 0db77e09bb..8607477d82 100644
--- a/uisimulator/lcd.c
+++ b/uisimulator/lcd.c
@@ -21,8 +21,10 @@
* This file is meant for generic LCD defines and global variables etc.
*/
-#define DISP_X 112 /* Display width in pixels */
-#define DISP_Y 64 /* Display height in pixels */
+#include "lcd.h"
+
+#define DISP_X LCD_WIDTH /* Display width in pixels */
+#define DISP_Y LCD_HEIGHT /* Display height in pixels */
#define CHAR_X 6 /* Character width in pixels */
#define CHAR_Y 8 /* Character height in pixels */
@@ -38,7 +40,7 @@
#define ASCII_MIN 0x20 /* First char in table */
#define ASCII_MAX 0x7f /* Last char in table */
-static const uchar char_gen[ASCII_MAX-ASCII_MIN+1][CHAR_X-1] =
+static const unsigned char char_gen[ASCII_MAX-ASCII_MIN+1][CHAR_X-1] =
{
0x00, 0x00, 0x00, 0x00, 0x00, /* 0x20-0x2f */
0x00, 0x00, 0x4f, 0x00, 0x00,
@@ -150,30 +152,93 @@ static const uchar char_gen[ASCII_MAX-ASCII_MIN+1][CHAR_X-1] =
* Bits within a byte are arranged veritcally, LSB at top.
* Byte 0 is top left, byte 1 is 2nd left, byte DISP_X starts 2nd row.
*/
-static uchar display[DISP_Y/8][DISP_X];
+unsigned char display[LCD_HEIGHT/8][LCD_WIDTH];
-static uint16 lcd_y; /* Current pixel row */
-static uint16 lcd_x; /* Current pixel column */
+static unsigned char lcd_y; /* Current pixel row */
+static unsigned char lcd_x; /* Current pixel column */
/*
* Set current x,y position
*/
-void lcd_position (int x, int y)
+void lcd_position(int x, int y)
{
- if (x >= 0 && x < DISP_X && y >= 0 && y < DISP_Y)
- {
- lcd_x = x;
- lcd_y = y;
- }
+ if (x >= 0 && x < DISP_X && y >= 0 && y < DISP_Y) {
+ lcd_x = x;
+ lcd_y = y;
+ }
}
/*
* Clear the display
*/
-void lcd_clear (void)
+void lcd_clear(void)
{
lcd_x = 0;
lcd_y = 0;
memset (display, 0, sizeof display);
}
+/*
+ * Display a character at current position.
+ * This writes a 5x8 character within a 6x8 cell.
+ * The cell does not have to be aligned to a display byte.
+ * The top left of the cell is displayed at the current position.
+ * invert is TRUE to display in reverse video.
+ */
+void lcd_char (int ch, char invert)
+{
+ unsigned char (*dp)[DISP_X] = (void *) &display[lcd_y/8][lcd_x];
+ unsigned long shift, mask, col;
+
+ /* Limit to char generation table */
+ if (ch < ASCII_MIN || ch > ASCII_MAX)
+ ch = ASCII_MAX;
+
+ /* Calculate shift and masks for cell bit position */
+ shift = (lcd_y & 0x7);
+ mask = ~(COL_MASK << shift);
+ if (invert)
+ invert = ~mask;
+
+ /* Write each char column */
+ for (col = 0; col < CHAR_X-1; col++) {
+ unsigned long data = (char_gen[ch-ASCII_MIN][col] << shift) ^ invert;
+ dp[0][col] = (dp[0][col] & mask) | data;
+ if (lcd_y < DISP_Y-8)
+ dp[1][col] = (dp[1][col] & (mask >> 8)) | (data >> 8);
+ }
+
+ /* Column after char */
+ dp[0][CHAR_X-1] = (dp[0][CHAR_X-1] & mask) | invert;
+ if (lcd_y < DISP_Y-8)
+ dp[1][CHAR_X-1] = (dp[1][CHAR_X-1] & (mask >> 8)) | (invert >> 8);
+}
+
+/*
+ * Output a string at current position
+ */
+void lcd_string(const char *text, char invert)
+{
+ int ch;
+
+ while ((ch = *text++) != '\0') {
+ if (lcd_y > DISP_Y-CHAR_Y) {
+ /* Scroll (8 pixels) */
+ memcpy (display[0], display[1], DISP_X*(DISP_Y/8-1));
+ lcd_y -= 8;
+ }
+
+ if (ch == '\n')
+ lcd_x = DISP_X;
+ else {
+ lcd_char (ch, invert);
+ lcd_x += CHAR_X;
+ }
+
+ if (lcd_x > DISP_X-CHAR_X) {
+ /* Wrap to next line */
+ lcd_x = 0;
+ lcd_y += CHAR_Y;
+ }
+ }
+}
diff --git a/uisimulator/lcd.h b/uisimulator/lcd.h
new file mode 100644
index 0000000000..0a099cb8c7
--- /dev/null
+++ b/uisimulator/lcd.h
@@ -0,0 +1,26 @@
+/***************************************************************************
+ * __________ __ ___.
+ * Open \______ \ ____ ____ | | _\_ |__ _______ ___
+ * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
+ * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
+ * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
+ * \/ \/ \/ \/ \/
+ * $Id$
+ *
+ * Copyright (C) 2002 by Daniel Stenberg <daniel@haxx.se>
+ *
+ * All files in this archive are subject to the GNU General Public License.
+ * See the file COPYING in the source tree root for full license agreement.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ ****************************************************************************/
+
+/*
+ * This file is meant for generic LCD defines
+ */
+
+#define LCD_WIDTH 112 /* Display width in pixels */
+#define LCD_HEIGHT 64 /* Display height in pixels */
+
diff --git a/uisimulator/uibasic.c b/uisimulator/uibasic.c
index 4ea453c82e..74b09f7e9a 100644
--- a/uisimulator/uibasic.c
+++ b/uisimulator/uibasic.c
@@ -41,7 +41,7 @@
/* -- -- */
-static GC draw_gc, erase_gc;
+GC draw_gc, erase_gc;
static Colormap cmap;
static XColor color_track, color_car;
@@ -163,6 +163,27 @@ void drawline(int color, int x1, int y1, int x2, int y2)
(int)(y2*track_zoom));
}
+void drawdot(int color, int x, int y)
+{
+ if (color==0) {
+ XSetForeground(dpy, draw_gc,
+ get_pixel_resource("background", "Background", dpy, cmap));
+ }
+ else
+ XSetForeground(dpy, draw_gc,
+ get_pixel_resource("foreground", "Foreground", dpy, cmap));
+
+ XDrawPoint(dpy, window, draw_gc, x, y);
+}
+
+void drawdots(XPoint *points, int count)
+{
+ XSetForeground(dpy, draw_gc,
+ get_pixel_resource("foreground", "Foreground", dpy, cmap));
+
+ XDrawPoints(dpy, window, draw_gc, points, count, CoordModeOrigin);
+}
+
void drawtext(int color, int x, int y, char *text)
{
if (color==0) {
@@ -199,11 +220,10 @@ screenhack (Display *the_dpy, Window the_window)
init_window();
- drawtext(1, 20, 20, PROGNAME);
- drawline(1, 0, 0, 40, 50);
-
Logf("Rockbox will kill ya!");
+ lcd_string( PROGNAME, 0);
+
while (1) {
/* deal with input here */
@@ -214,7 +234,18 @@ screenhack (Display *the_dpy, Window the_window)
void screen_redraw()
{
- /* does nothing yet */
- drawtext(1, 20, 20, PROGNAME);
- drawline(1, 0, 0, 40, 50);
+ int y, x;
+
+ lcd_update();
+
+#if 0
+ /* does nothing "real" yet */
+ /* drawtext(1, 20, 20, PROGNAME);*/
+
+ for(y=0; y< 112; y++)
+ for(x=0; x<64; x++)
+ drawdot(1, x+16, y+16);
+ /* drawline(1, 0, 0, 40, 50); */
+#endif
}
+