Alternative library and kernel for add-in development on fx-9860G and fx-CG50 under Linux.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

display.h 9.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. //---
  2. // gint:display - Drawing functions
  3. //
  4. // This module covers the drawing functions that are common to fx9860g and
  5. // fxcg50. Platform-specific definitions are found in <gint/display-fx.h>
  6. // and <gint/display-cg.h>.
  7. //---
  8. #ifndef GINT_DISPLAY
  9. #define GINT_DISPLAY
  10. #include <gint/defs/types.h>
  11. /* Platform-specific functions include VRAM management and the definition of
  12. the color_t type. */
  13. #ifdef FX9860G
  14. #include <gint/display-fx.h>
  15. #endif
  16. #ifdef FXCG50
  17. #include <gint/display-cg.h>
  18. #endif
  19. /* TODO: dinfo() or similar */
  20. //---
  21. // Video RAM management
  22. //---
  23. /* dupdate(): Push the video RAM to the display driver
  24. This function makes the contents of the VRAM visible on the screen. It is
  25. the direct equivalent of Bdisp_PutDisp_DD().
  26. On fxcg50, if triple buffering is enabled (which is the default and disabled
  27. only by calling dvram()), it also swaps buffers. Due to the DMA being used,
  28. always waits for the previous call to dupdate() call() to finish. */
  29. void dupdate(void);
  30. //---
  31. // Area rendering functions
  32. //---
  33. /* dclear(): Fill the screen with a single color
  34. This function clears the screen by painting all the pixels in a single
  35. color. It is optimized for opaque colors.
  36. On fx9860g, use drect() if you need complex operators such as invert.
  37. @color fx9860g: white, black
  38. fxcg50: Any R5G6B5 color */
  39. void dclear(color_t color);
  40. /* drect(): Fill a rectangle of the screen
  41. This functions applies a color or an operator to a rectangle defined by two
  42. points (x1 y1) and (x2 y2). Both are included in the rectangle.
  43. @x1 @y1 @x2 @y2 Bounding rectangle (drawn area).
  44. @color fx9860g: white, black, none, invert
  45. fxcg50: Any R5G6B5 color */
  46. void drect(int x1, int y1, int x2, int y2, color_t color);
  47. //---
  48. // Point drawing functions
  49. //---
  50. /* dpixel(): Change a pixel's color
  51. Paints the selected pixel with an opaque color. Setting pixels individually
  52. is a slow method for rendering. Other functions that draw lines, rectangles,
  53. images or text will take advantage of possible optimizations to make the
  54. rendering faster: check them out first.
  55. On fx9860g, if an operator such as invert is used, the result will depend
  56. on the current color of the pixel.
  57. @x @y Coordinates of the pixel to repaint
  58. @color fx9860g: white, black, none, invert
  59. fxcg50: Any R5G6B5 color */
  60. void dpixel(int x, int y, color_t color);
  61. /* dline(): Render a straight line
  62. This function draws a line using a Bresenham-style algorithm. Please note
  63. that dline() may not render lines exactly like Bdisp_DrawLineVRAM().
  64. dline() has optimization facilities for horizontal and vertical lines. The
  65. speedup for horizontal lines is about x2 on fxcg50 and probably about x30
  66. on fx9860g. Vertical lines have a smaller speedup.
  67. dline() is currently not able to clip arbitrary lines without calculating
  68. all the pixels, so drawing a line from (-1e6,0) to (1e6,395) will work but
  69. will be veeery slow.
  70. @x1 @y1 @x2 @y2 End points of the line (both included).
  71. @color fx9860g: white, black, none, invert
  72. fxcg50: Any R5G6B5 color */
  73. void dline(int x1, int y1, int x2, int y2, color_t color);
  74. /* dhline(): Full-width horizontal line
  75. This function draws a horizontal line from the left end of the screen to the
  76. right end, much like the Basic command "Horizontal".
  77. @y Line number
  78. @color fx9860g: white, black, none, invert
  79. fxcg50: Any R5G6B5 color */
  80. void dhline(int y, color_t color);
  81. /* dvline(): Full-height vertical line
  82. This function draws a vertical line from the top end of the screen to the
  83. bottom end, much like the Basic command "Vertical".
  84. @x Column number
  85. @color fx9860g: white, black, none, invert
  86. fxcg50: Any R5G6B5 color */
  87. void dvline(int x, color_t color);
  88. //---
  89. // Text rendering (topti)
  90. //---
  91. /* font_t - font data encoded for topti */
  92. typedef struct
  93. {
  94. /* Length of font name (not necessarily NUL-terminated!) */
  95. uint title :5;
  96. /* Font shape flags */
  97. uint bold :1;
  98. uint italic :1;
  99. uint serif :1;
  100. uint mono :1;
  101. /* Whether data is variable-length (proportional font) */
  102. uint prop :1;
  103. /* Reserved for future use */
  104. uint :2;
  105. /* Implemented charcter set */
  106. uint charset :4;
  107. /* Line height */
  108. uint8_t line_height;
  109. /* Storage height */
  110. uint8_t data_height;
  111. /* The rest of the data depends on whether the font is proportional */
  112. union {
  113. /* For monospaced fonts */
  114. struct {
  115. /* Width of glyphs */
  116. uint16_t width;
  117. /* Storage size, in longwords, of each glyph */
  118. uint16_t storage_size;
  119. /* Raw glyph data */
  120. uint32_t data[];
  121. };
  122. /* For proportional fonts */
  123. struct {
  124. /* Storage index to find glyphs quickly */
  125. uint16_t index[16];
  126. /* Size array (padded to 4 bytes), 1 byte per entry,
  127. followed by glyph data */
  128. uint8_t sized_data[];
  129. };
  130. };
  131. /* The font name is stored after the data. The size is the length set
  132. in the [title] field, padded to 4 bytes with NULs. There might not
  133. be a NUL at the end. */
  134. } GPACKED(4) font_t;
  135. /* dfont(): Set the default font for text rendering
  136. This font will be used by dtext() and sister functions. If [font = NULL],
  137. gint's default font is used.
  138. On fx9860g, the default font is a 5x7 font very close to the system's.
  139. On fxcg50, the default font is an original 8x9 font.
  140. @font Font to use for subsequent text rendering calls
  141. Returns the previously configured font. */
  142. font_t const *dfont(font_t const * font);
  143. /* dsize(): Get the width and height of rendered text
  144. This function computes the size that the given string would take up if
  145. rendered with a certain font. If you specify a NULL font, the currently
  146. configured font will be used; this is different from dfont(), which uses
  147. gint's default font when NULL is passed.
  148. Note that the height of each glyph is not stored in the font, only the
  149. maximum. Usually this is what you want because vertically-centered strings
  150. must have the same baseline regardless of their contents. So the height
  151. returned by dsize() is the same for all strings, only depends on the font.
  152. The height is computed in constant time, and the width in linear time. If
  153. [w = NULL], this function returns in constant time.
  154. @str String whose size must be evaluated
  155. @font Font to use; if NULL, defaults to the current font
  156. @w @h Set to the width and height of the rendered text, may be NULL */
  157. void dsize(char const *str, font_t const * font, int *w, int *h);
  158. /* dtext(): Display a string of text
  159. Draws some text in the video RAM using the font set with dfont() (or gint's
  160. default if no such font was set).
  161. On fx9860g, due to the particular design of topti, this function performs
  162. drastic rendering optimizations using the line structure of the VRAM and is
  163. able to render several characters at once.
  164. This is not a printf()-family function so [str] cannot contain formats like
  165. "%d" and you cannot pass additional arguments.
  166. @x @y Coordinates of top-left corner of the rendered string
  167. @str String to display
  168. @fg Text color
  169. fx9860g: white, black, none, invert
  170. fxcg50: Any R5G6B6 color, or C_NONE
  171. @bg Background color
  172. fx9860g: white, black, none, invert
  173. fxcg50: Any R5G6B5 color, or C_NONE */
  174. void dtext(int x, int y, char const *str, int fg, int bg);
  175. /* dprint(): Display a formatted string
  176. Much like dtext(), but accepts printf-like formats with arguments. See
  177. <gint/std/stdio.h> for a detailed view of what this format supports. */
  178. void dprint(int x, int y, int fg, int bg, char const *format, ...);
  179. //---
  180. // Image rendering (bopti)
  181. //---
  182. /* The image_t structure is platform-dependent. */
  183. /* dimage(): Render a full image
  184. This function blits an image on the VRAM using gint's special format. It is
  185. a special case of dsubimage() where the full image is drawn with clipping.
  186. @x @y Coordinates of the top-left corner of the image
  187. @image Pointer to image encoded with [fxconv] */
  188. void dimage(int x, int y, image_t const *image);
  189. /* Option values for dsubimage() */
  190. enum {
  191. /* No option */
  192. DIMAGE_NONE = 0x00,
  193. /* Disable clipping, ie. adjustments to the specified subrectangle and
  194. screen location such that any part that overflows from the image or
  195. the screen is ignored. Slightly faster. */
  196. DIMAGE_NOCLIP = 0x01,
  197. };
  198. /* dsubimage(): Render a section of an image
  199. This function blits a subrectangle [left, top, width, height] of an image on
  200. the VRAM. It is more general than dimage() and also provides a few options.
  201. @x @y Coordinates on screen of the rendered subrectangle
  202. @image Pointer to image encoded with [fxconv]
  203. @left @top Top-left coordinates of the subrectangle within [image]
  204. @width @height Subrectangle dimensions
  205. @flags OR-combination of DIMAGE_* flags */
  206. void dsubimage(int x, int y, image_t const *image, int left, int top,
  207. int width, int height, int flags);
  208. //---
  209. // Advanced functions
  210. //---
  211. /* dupdate_noint(): Push VRAM to the display without interrupts
  212. This function does exactly as dupdate(), but does not use interrupts and
  213. always returns when the transfer is finished. It actively waits for the end
  214. of the transfer and is thus bad for any general-purpose use. In fact, it is
  215. only needed to display panic messages in exception handlers. Don't use it
  216. unless you know precisely why you're doing it. */
  217. void dupdate_noint(void);
  218. #endif /* GINT_DISPLAY */