11 /* glyph is the 32 bit address of the glyph */
13 /* width and height of the glyph in pixels */
16 } __attribute__((packed
));
18 extern struct FontTable fontTable
[];
20 extern uint8
*frameBuffer
;
21 extern uint64 frameBufferSize
;
23 extern uint32 physBasePtr
;
24 extern uint8 bitsPerPixel
;
25 extern uint16 xResolution
;
26 extern uint16 yResolution
;
27 extern uint8 redMaskSize
;
28 extern uint8 redFieldPosition
;
29 extern uint8 greenMaskSize
;
30 extern uint8 greenFieldPosition
;
31 extern uint8 blueMaskSize
;
32 extern uint8 blueFieldPosition
;
33 extern uint8 rsvdMaskSize
;
34 extern uint8 rsvdFieldPosition
;
45 * Set the pixel at x,y to the specified ARGB color.
49 SetPixel(Color color
, Point p
)
51 uint32 pixelValue
= 0;
52 int bytesPerPixel
= 1;
56 /* Convert color into local colorspace. */
58 switch (bitsPerPixel
) {
62 pixelValue
= (uint32
)color
;
68 pixelValue
= (uint32
)(((color
>> redFieldPosition
) & rMask
) |
69 ((color
>> greenFieldPosition
) & gMask
) |
70 ((color
>> blueFieldPosition
) & bMask
) |
71 ((color
>> rsvdFieldPosition
) & aMask
));
76 UNIMPLEMENTED("8 or 4 bits per pixel");
81 /* Find pixel address */
82 pixel
= frameBuffer
+ bytesPerPixel
* (p
.x
+ p
.y
* xResolution
);
84 switch (bytesPerPixel
) {
86 *((uint32
*)pixel
) = pixelValue
;
89 *((uint16
*)pixel
) = (uint16
)pixelValue
;
92 *((uint8
*)pixel
) = (uint8
)pixelValue
;
101 Color c
= COLOR_BLACK
;
105 switch (bitsPerPixel
) {
108 pixel
= frameBuffer
+ 4 * (p
.x
+ p
.y
* xResolution
);
109 c
= *((uint32
*)pixel
);
113 pixel
= frameBuffer
+ 2 * (p
.x
+ p
.y
* xResolution
);
114 pix16
= *((uint16
*)pixel
);
115 c
= (((pix16
& rMask
) << redFieldPosition
) |
116 ((pix16
& gMask
) << greenFieldPosition
) |
117 ((pix16
& bMask
) << blueFieldPosition
) |
118 ((pix16
& aMask
) << rsvdFieldPosition
));
122 UNIMPLEMENTED("8 or 4 bits per pixel");
133 * Set a rectangular area to be the specified color.
137 ColorRectangle(Color color
, Point c0
, Point c1
)
139 uint64 xLow
, xHigh
, yLow
, yHigh
, x
, y
;
141 if (c0
.x
== c1
.x
|| c0
.y
== c1
.y
) {
160 for (x
= xLow
; x
<= xHigh
; x
++) {
161 for (y
= yLow
; y
<= yHigh
; y
++) {
173 ColorCircle(Color color
, Point c
, Length r
)
175 uint64 xl
, xr
, yt
, yb
;
182 /* correct borders */
188 if (c
.x
+ r
> xResolution
- 1) {
189 xr
= xResolution
- 1;
198 if (c
.y
+ r
> yResolution
- 1) {
199 yb
= yResolution
- 1;
204 for (p
.x
= xl
; p
.x
<=xr
; p
.x
++) {
205 for (p
.y
= yt
; p
.y
<= yb
; p
.y
++) {
208 /* limit x and y to quadrant 4 */
220 if (xx
* xx
+ yy
* yy
< r
* r
) {
229 * SetBootBackground --
231 * Set the screen background to the default boot color.
235 SetBootBackground(void)
239 for (p
.x
= 0; p
.x
< xResolution
; p
.x
++) {
240 for (p
.y
= 0; p
.y
< yResolution
; p
.y
++) {
241 SetPixel(BOOT_BACKGROUND_COLOR
, p
);
250 * Calculate frame buffer size and map it into the virtual
257 uint64 bytesPerPixel
= 0;
260 * Identity map the frame buffer.
263 frameBuffer
= (uint8
*)(VA
)physBasePtr
;
265 switch (bitsPerPixel
) {
278 frameBufferSize
= xResolution
* yResolution
* bytesPerPixel
;
280 MapIORegion((PA
)frameBuffer
,
281 (PA
)(frameBuffer
+ frameBufferSize
),
289 rMask
= ((1ULL << redMaskSize
) - 1) << redFieldPosition
;
290 gMask
= ((1ULL << greenMaskSize
) - 1) << greenFieldPosition
;
291 bMask
= ((1ULL << blueMaskSize
) - 1) << blueFieldPosition
;
292 aMask
= (rsvdMaskSize
? (1ULL << rsvdMaskSize
) - 1 : 0) << rsvdFieldPosition
;
296 * Set a pleasing background color.
303 #define PIXEL_VALUE(glyph,p) ((((glyph)[(p) >> 3]) & \
304 (1 << (7 - ((p) % 8)) )) >> \
310 * Display msg at pixel coordinates x,y.
314 PrintMessage(Color color
, Point where
, char *msg
)
317 uint64 xOff
= 0; /* offset from start of message */
319 for (c
= 0; msg
[c
]; c
++) {
326 glyph
= (uint8
*)((VA
)fontTable
[ch
].glyph
);
329 /* loop over pixels */
330 for (p
= 0; p
< fontTable
[ch
].w
* fontTable
[ch
].h
; p
++) {
332 if (PIXEL_VALUE(glyph
, p
) == 1) {
335 p
.x
= where
.x
+ xOff
+ xp
;
342 if ((xp
% fontTable
[ch
].w
) == 0) {
348 xOff
+= fontTable
[ch
].w
;
355 * Register a callback with irq12 (will be a deferred function call).
356 * When the cursor moves, the old cursor spot is replaced with its
357 * saved spot, then the new cursor spot is saved and the cursor is
362 #include "cursor.xbm"
364 static Color savedCursor
[cursor_width
][cursor_height
];
369 unsigned int button1
:1;
370 unsigned int button2
:1;
371 unsigned int button3
:1;
372 unsigned int button4
:1;
373 unsigned int button5
:1;
377 static CbID cursorCbId
;
380 RestoreCursorArea(void)
385 for (x
= 0; x
< cursor_width
; x
++) {
386 for (y
= 0; y
< cursor_height
; y
++) {
387 sx
= cursorInfo
.x
- cursor_x_hot
+ x
;
388 sy
= cursorInfo
.y
- cursor_y_hot
+ y
;
390 if (sx
< 0 || sy
< 0 || sx
> xResolution
|| sy
> yResolution
) {
396 SetPixel(savedCursor
[x
][y
], p
);
408 for (x
= 0; x
< cursor_width
; x
++) {
409 for (y
= 0; y
< cursor_height
; y
++) {
410 sx
= cursorInfo
.x
- cursor_x_hot
+ x
;
411 sy
= cursorInfo
.y
- cursor_y_hot
+ y
;
413 if (sx
< 0 || sy
< 0 || sx
> xResolution
|| sy
> yResolution
) {
419 savedCursor
[x
][y
] = GetPixel(p
);
426 #define CURSOR_ISSET(x,y) ((cursor_bits[(x)] >> y) & 1)
434 for (x
= 0; x
< cursor_width
; x
++) {
435 for (y
= 0; y
< cursor_height
; y
++) {
436 sx
= cursorInfo
.x
- cursor_x_hot
+ x
;
437 sy
= cursorInfo
.y
- cursor_y_hot
+ y
;
439 if (sx
< 0 || sy
< 0 || sx
> xResolution
|| sy
> yResolution
) {
446 if (!CURSOR_ISSET(x
,y
)) {
450 SetPixel(COLOR_BLACK
, p
);
457 DoButtons(int b1
, int b2
, int b3
)
467 ColorCircle(COLOR_BLUE
, p
, r
);
469 ColorCircle(COLOR_PLEASING_GREEN
, p
, r
);
473 ColorCircle(COLOR_ROBINs_PURPLE
, p
, r
);
475 ColorCircle(COLOR_PLEASING_GREEN
, p
, r
);
479 ColorCircle(COLOR_RED
, p
, r
);
481 ColorCircle(COLOR_PLEASING_GREEN
, p
, r
);
487 DoCursor(uint8
*packet
, uint64 N
)
489 int32 xd
= 0, yd
= 0;
493 /* update coordinates */
497 * Byte 1: Yof Xof Ys Xs 1 b1 b2 b0
503 * Byte 1: Yof Xof Ys Xs 1 b1 b2 b0
510 if (packet
[0] & 0x10) {
514 if (packet
[0] & 0x20) {
523 if (cursorInfo
.x
< 0) {
525 } else if (cursorInfo
.x
> xResolution
) {
526 cursorInfo
.x
= xResolution
;
528 if (cursorInfo
.y
< 0) {
530 } else if (cursorInfo
.y
> yResolution
) {
531 cursorInfo
.y
= yResolution
;
534 cursorInfo
.button1
= packet
[0] & 1;
535 cursorInfo
.button2
= (packet
[0] >> 2) & 1;
536 cursorInfo
.button3
= (packet
[0] >> 1) & 1;
538 /* draw some small circles */
539 DoButtons(cursorInfo
.button1
, cursorInfo
.button2
, cursorInfo
.button3
);
549 cursorInfo
.x
= xResolution
/ 2;
550 cursorInfo
.y
= yResolution
/ 2;
552 cursorInfo
.button1
= 0;
553 cursorInfo
.button2
= 0;
554 cursorInfo
.button3
= 0;
555 cursorInfo
.button4
= 0;
556 cursorInfo
.button5
= 0;
561 cursorCbId
= InstallMouseCB(DoCursor
);