diff options
Diffstat (limited to 'uisimulator')
-rw-r--r-- | uisimulator/Makefile | 2 | ||||
-rw-r--r-- | uisimulator/lcd-recorder.c | 37 | ||||
-rw-r--r-- | uisimulator/lcd-x11.c | 45 | ||||
-rw-r--r-- | uisimulator/lcd.c | 91 | ||||
-rw-r--r-- | uisimulator/lcd.h | 26 | ||||
-rw-r--r-- | uisimulator/uibasic.c | 45 |
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 | |||
29 | DEPEND = .depends | 29 | DEPEND = .depends |
30 | 30 | ||
31 | OBJS= alpha.o hsv.o screenhack.o yarandom.o uibasic.o resources.o visual.o\ | 31 | OBJS= alpha.o hsv.o screenhack.o yarandom.o uibasic.o resources.o visual.o\ |
32 | usleep.o | 32 | usleep.o lcd.c lcd-x11.c |
33 | 33 | ||
34 | SRCS = $(OBJS:%.o=%.c) | 34 | SRCS = $(OBJS:%.o=%.c) |
35 | HDRS = $(OBJS:%.o=%.h) | 35 | 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) | |||
79 | } | 79 | } |
80 | } | 80 | } |
81 | 81 | ||
82 | #if 0 | ||
82 | /* | 83 | /* |
83 | * Display a string at current position | 84 | * Display a string at current position |
84 | */ | 85 | */ |
@@ -107,42 +108,8 @@ void lcd_string (const char *text, BOOL invert) | |||
107 | } | 108 | } |
108 | } | 109 | } |
109 | } | 110 | } |
111 | #endif | ||
110 | 112 | ||
111 | /* | ||
112 | * Display a character. | ||
113 | * This writes a 5x8 character within a 6x8 cell. | ||
114 | * The cell does not have to be aligned to a display byte. | ||
115 | * The top left of the cell is displayed at the current position. | ||
116 | * invert is TRUE to display in reverse video. | ||
117 | */ | ||
118 | void lcd_char (int ch, BOOL invert) | ||
119 | { | ||
120 | uchar (*dp)[DISP_X] = (void *) &display[lcd_y/8][lcd_x]; | ||
121 | uint32 shift, mask, col; | ||
122 | |||
123 | /* Limit to char generation table */ | ||
124 | if (ch < ASCII_MIN || ch > ASCII_MAX) | ||
125 | ch = ASCII_MAX; | ||
126 | |||
127 | /* Calculate shift and masks for cell bit position */ | ||
128 | shift = (lcd_y & 0x7); | ||
129 | mask = ~(COL_MASK << shift); | ||
130 | if (invert) | ||
131 | invert = ~mask; | ||
132 | |||
133 | /* Write each char column */ | ||
134 | for (col = 0; col < CHAR_X-1; col++) { | ||
135 | uint32 data = (char_gen[ch-ASCII_MIN][col] << shift) ^ invert; | ||
136 | dp[0][col] = (dp[0][col] & mask) | data; | ||
137 | if (lcd_y < DISP_Y-8) | ||
138 | dp[1][col] = (dp[1][col] & (mask >> 8)) | (data >> 8); | ||
139 | } | ||
140 | |||
141 | /* Column after char */ | ||
142 | dp[0][CHAR_X-1] = (dp[0][CHAR_X-1] & mask) | invert; | ||
143 | if (lcd_y < DISP_Y-8) | ||
144 | dp[1][CHAR_X-1] = (dp[1][CHAR_X-1] & (mask >> 8)) | (invert >> 8); | ||
145 | } | ||
146 | 113 | ||
147 | /* | 114 | /* |
148 | * Write a byte to LCD controller. | 115 | * 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 @@ | |||
17 | * | 17 | * |
18 | ****************************************************************************/ | 18 | ****************************************************************************/ |
19 | 19 | ||
20 | #include <stdio.h> | ||
21 | #include <string.h> | ||
22 | #include <stdarg.h> | ||
23 | #include <stdlib.h> | ||
24 | #include <ctype.h> | ||
25 | #include <sys/types.h> | ||
26 | #include <sys/stat.h> | ||
27 | #include <fcntl.h> | ||
28 | |||
29 | #include <errno.h> | ||
30 | #include <ctype.h> | ||
31 | #include <time.h> | ||
32 | |||
33 | #include "screenhack.h" | ||
34 | |||
20 | /* | 35 | /* |
21 | * Specific implementations for X11, using the generic LCD functions and data. | 36 | * Specific implementations for X11, using the generic LCD API and data. |
22 | */ | 37 | */ |
23 | 38 | ||
39 | #include "lcd.h" | ||
40 | |||
41 | extern unsigned char display[LCD_WIDTH/8][LCD_HEIGHT]; | ||
42 | |||
43 | void lcd_update (void) | ||
44 | { | ||
45 | int x, y; | ||
46 | int p=0; | ||
47 | int bit; | ||
48 | XPoint points[LCD_WIDTH * LCD_HEIGHT]; | ||
49 | |||
50 | for(y=0; y<LCD_HEIGHT; y+=8) { | ||
51 | for(x=0; x<LCD_WIDTH; x++) { | ||
52 | if(display[y/8][x]) { | ||
53 | /* one or more bits/pixels are set */ | ||
54 | for(bit=0; bit<8; bit++) { | ||
55 | if(display[y/8][x]&(1<<bit)) { | ||
56 | points[p].x = x; | ||
57 | points[p].y = y+bit; | ||
58 | p++; /* increase the point counter */ | ||
59 | } | ||
60 | } | ||
61 | |||
62 | } | ||
63 | } | ||
64 | } | ||
65 | drawdots(&points[0], p); | ||
66 | } | ||
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 @@ | |||
21 | * This file is meant for generic LCD defines and global variables etc. | 21 | * This file is meant for generic LCD defines and global variables etc. |
22 | */ | 22 | */ |
23 | 23 | ||
24 | #define DISP_X 112 /* Display width in pixels */ | 24 | #include "lcd.h" |
25 | #define DISP_Y 64 /* Display height in pixels */ | 25 | |
26 | #define DISP_X LCD_WIDTH /* Display width in pixels */ | ||
27 | #define DISP_Y LCD_HEIGHT /* Display height in pixels */ | ||
26 | 28 | ||
27 | #define CHAR_X 6 /* Character width in pixels */ | 29 | #define CHAR_X 6 /* Character width in pixels */ |
28 | #define CHAR_Y 8 /* Character height in pixels */ | 30 | #define CHAR_Y 8 /* Character height in pixels */ |
@@ -38,7 +40,7 @@ | |||
38 | #define ASCII_MIN 0x20 /* First char in table */ | 40 | #define ASCII_MIN 0x20 /* First char in table */ |
39 | #define ASCII_MAX 0x7f /* Last char in table */ | 41 | #define ASCII_MAX 0x7f /* Last char in table */ |
40 | 42 | ||
41 | static const uchar char_gen[ASCII_MAX-ASCII_MIN+1][CHAR_X-1] = | 43 | static const unsigned char char_gen[ASCII_MAX-ASCII_MIN+1][CHAR_X-1] = |
42 | { | 44 | { |
43 | 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x20-0x2f */ | 45 | 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x20-0x2f */ |
44 | 0x00, 0x00, 0x4f, 0x00, 0x00, | 46 | 0x00, 0x00, 0x4f, 0x00, 0x00, |
@@ -150,30 +152,93 @@ static const uchar char_gen[ASCII_MAX-ASCII_MIN+1][CHAR_X-1] = | |||
150 | * Bits within a byte are arranged veritcally, LSB at top. | 152 | * Bits within a byte are arranged veritcally, LSB at top. |
151 | * Byte 0 is top left, byte 1 is 2nd left, byte DISP_X starts 2nd row. | 153 | * Byte 0 is top left, byte 1 is 2nd left, byte DISP_X starts 2nd row. |
152 | */ | 154 | */ |
153 | static uchar display[DISP_Y/8][DISP_X]; | 155 | unsigned char display[LCD_HEIGHT/8][LCD_WIDTH]; |
154 | 156 | ||
155 | static uint16 lcd_y; /* Current pixel row */ | 157 | static unsigned char lcd_y; /* Current pixel row */ |
156 | static uint16 lcd_x; /* Current pixel column */ | 158 | static unsigned char lcd_x; /* Current pixel column */ |
157 | 159 | ||
158 | /* | 160 | /* |
159 | * Set current x,y position | 161 | * Set current x,y position |
160 | */ | 162 | */ |
161 | void lcd_position (int x, int y) | 163 | void lcd_position(int x, int y) |
162 | { | 164 | { |
163 | if (x >= 0 && x < DISP_X && y >= 0 && y < DISP_Y) | 165 | if (x >= 0 && x < DISP_X && y >= 0 && y < DISP_Y) { |
164 | { | 166 | lcd_x = x; |
165 | lcd_x = x; | 167 | lcd_y = y; |
166 | lcd_y = y; | 168 | } |
167 | } | ||
168 | } | 169 | } |
169 | 170 | ||
170 | /* | 171 | /* |
171 | * Clear the display | 172 | * Clear the display |
172 | */ | 173 | */ |
173 | void lcd_clear (void) | 174 | void lcd_clear(void) |
174 | { | 175 | { |
175 | lcd_x = 0; | 176 | lcd_x = 0; |
176 | lcd_y = 0; | 177 | lcd_y = 0; |
177 | memset (display, 0, sizeof display); | 178 | memset (display, 0, sizeof display); |
178 | } | 179 | } |
179 | 180 | ||
181 | /* | ||
182 | * Display a character at current position. | ||
183 | * This writes a 5x8 character within a 6x8 cell. | ||
184 | * The cell does not have to be aligned to a display byte. | ||
185 | * The top left of the cell is displayed at the current position. | ||
186 | * invert is TRUE to display in reverse video. | ||
187 | */ | ||
188 | void lcd_char (int ch, char invert) | ||
189 | { | ||
190 | unsigned char (*dp)[DISP_X] = (void *) &display[lcd_y/8][lcd_x]; | ||
191 | unsigned long shift, mask, col; | ||
192 | |||
193 | /* Limit to char generation table */ | ||
194 | if (ch < ASCII_MIN || ch > ASCII_MAX) | ||
195 | ch = ASCII_MAX; | ||
196 | |||
197 | /* Calculate shift and masks for cell bit position */ | ||
198 | shift = (lcd_y & 0x7); | ||
199 | mask = ~(COL_MASK << shift); | ||
200 | if (invert) | ||
201 | invert = ~mask; | ||
202 | |||
203 | /* Write each char column */ | ||
204 | for (col = 0; col < CHAR_X-1; col++) { | ||
205 | unsigned long data = (char_gen[ch-ASCII_MIN][col] << shift) ^ invert; | ||
206 | dp[0][col] = (dp[0][col] & mask) | data; | ||
207 | if (lcd_y < DISP_Y-8) | ||
208 | dp[1][col] = (dp[1][col] & (mask >> 8)) | (data >> 8); | ||
209 | } | ||
210 | |||
211 | /* Column after char */ | ||
212 | dp[0][CHAR_X-1] = (dp[0][CHAR_X-1] & mask) | invert; | ||
213 | if (lcd_y < DISP_Y-8) | ||
214 | dp[1][CHAR_X-1] = (dp[1][CHAR_X-1] & (mask >> 8)) | (invert >> 8); | ||
215 | } | ||
216 | |||
217 | /* | ||
218 | * Output a string at current position | ||
219 | */ | ||
220 | void lcd_string(const char *text, char invert) | ||
221 | { | ||
222 | int ch; | ||
223 | |||
224 | while ((ch = *text++) != '\0') { | ||
225 | if (lcd_y > DISP_Y-CHAR_Y) { | ||
226 | /* Scroll (8 pixels) */ | ||
227 | memcpy (display[0], display[1], DISP_X*(DISP_Y/8-1)); | ||
228 | lcd_y -= 8; | ||
229 | } | ||
230 | |||
231 | if (ch == '\n') | ||
232 | lcd_x = DISP_X; | ||
233 | else { | ||
234 | lcd_char (ch, invert); | ||
235 | lcd_x += CHAR_X; | ||
236 | } | ||
237 | |||
238 | if (lcd_x > DISP_X-CHAR_X) { | ||
239 | /* Wrap to next line */ | ||
240 | lcd_x = 0; | ||
241 | lcd_y += CHAR_Y; | ||
242 | } | ||
243 | } | ||
244 | } | ||
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 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2002 by Daniel Stenberg <daniel@haxx.se> | ||
11 | * | ||
12 | * All files in this archive are subject to the GNU General Public License. | ||
13 | * See the file COPYING in the source tree root for full license agreement. | ||
14 | * | ||
15 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
16 | * KIND, either express or implied. | ||
17 | * | ||
18 | ****************************************************************************/ | ||
19 | |||
20 | /* | ||
21 | * This file is meant for generic LCD defines | ||
22 | */ | ||
23 | |||
24 | #define LCD_WIDTH 112 /* Display width in pixels */ | ||
25 | #define LCD_HEIGHT 64 /* Display height in pixels */ | ||
26 | |||
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 @@ | |||
41 | 41 | ||
42 | /* -- -- */ | 42 | /* -- -- */ |
43 | 43 | ||
44 | static GC draw_gc, erase_gc; | 44 | GC draw_gc, erase_gc; |
45 | static Colormap cmap; | 45 | static Colormap cmap; |
46 | static XColor color_track, color_car; | 46 | static XColor color_track, color_car; |
47 | 47 | ||
@@ -163,6 +163,27 @@ void drawline(int color, int x1, int y1, int x2, int y2) | |||
163 | (int)(y2*track_zoom)); | 163 | (int)(y2*track_zoom)); |
164 | } | 164 | } |
165 | 165 | ||
166 | void drawdot(int color, int x, int y) | ||
167 | { | ||
168 | if (color==0) { | ||
169 | XSetForeground(dpy, draw_gc, | ||
170 | get_pixel_resource("background", "Background", dpy, cmap)); | ||
171 | } | ||
172 | else | ||
173 | XSetForeground(dpy, draw_gc, | ||
174 | get_pixel_resource("foreground", "Foreground", dpy, cmap)); | ||
175 | |||
176 | XDrawPoint(dpy, window, draw_gc, x, y); | ||
177 | } | ||
178 | |||
179 | void drawdots(XPoint *points, int count) | ||
180 | { | ||
181 | XSetForeground(dpy, draw_gc, | ||
182 | get_pixel_resource("foreground", "Foreground", dpy, cmap)); | ||
183 | |||
184 | XDrawPoints(dpy, window, draw_gc, points, count, CoordModeOrigin); | ||
185 | } | ||
186 | |||
166 | void drawtext(int color, int x, int y, char *text) | 187 | void drawtext(int color, int x, int y, char *text) |
167 | { | 188 | { |
168 | if (color==0) { | 189 | if (color==0) { |
@@ -199,11 +220,10 @@ screenhack (Display *the_dpy, Window the_window) | |||
199 | 220 | ||
200 | init_window(); | 221 | init_window(); |
201 | 222 | ||
202 | drawtext(1, 20, 20, PROGNAME); | ||
203 | drawline(1, 0, 0, 40, 50); | ||
204 | |||
205 | Logf("Rockbox will kill ya!"); | 223 | Logf("Rockbox will kill ya!"); |
206 | 224 | ||
225 | lcd_string( PROGNAME, 0); | ||
226 | |||
207 | while (1) { | 227 | while (1) { |
208 | /* deal with input here */ | 228 | /* deal with input here */ |
209 | 229 | ||
@@ -214,7 +234,18 @@ screenhack (Display *the_dpy, Window the_window) | |||
214 | 234 | ||
215 | void screen_redraw() | 235 | void screen_redraw() |
216 | { | 236 | { |
217 | /* does nothing yet */ | 237 | int y, x; |
218 | drawtext(1, 20, 20, PROGNAME); | 238 | |
219 | drawline(1, 0, 0, 40, 50); | 239 | lcd_update(); |
240 | |||
241 | #if 0 | ||
242 | /* does nothing "real" yet */ | ||
243 | /* drawtext(1, 20, 20, PROGNAME);*/ | ||
244 | |||
245 | for(y=0; y< 112; y++) | ||
246 | for(x=0; x<64; x++) | ||
247 | drawdot(1, x+16, y+16); | ||
248 | /* drawline(1, 0, 0, 40, 50); */ | ||
249 | #endif | ||
220 | } | 250 | } |
251 | |||