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.

gray.h 8.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. //---
  2. // gint:gray - Gray engine and rendering functions
  3. //---
  4. #ifndef GINT_GRAY
  5. #define GINT_GRAY
  6. #include <gint/defs/types.h>
  7. #include <gint/display.h>
  8. //---
  9. // Engine control
  10. //---
  11. /* gray_start(): Start the gray engine
  12. The control of the screen is transferred to the engine; you should not use
  13. dupdate() after this function, only gupdate(). */
  14. void gray_start(void);
  15. /* gray_stop(): Stop the gray engine
  16. Safe to call if the engine was not running. The gray engine returns the
  17. control of the screen and dupdate() is safe to use again.
  18. This function will leave the screen in whatever state it is, which is most
  19. probably one of the gray buffers being displayed. You should dupdate()
  20. quickly after this call to avoid visual artifacts. If the next monochrome
  21. frame is slow to render, consider rendering it before stopping the gray
  22. engine, and calling dupdate() immediately after. */
  23. void gray_stop(void);
  24. /* gray_delays(): Set the gray engine delays
  25. The gray engine works by swapping two images at a fast pace. Pixels that are
  26. white on both or black or both will appear as such, but pixels that are
  27. black on only one of the images will look gray.
  28. If both images stay on-screen for the same amount on time, there will be
  29. only one shade of gray. But if one stays longer, then pixels that are only
  30. black here will look darker than their counterparts, making two shades of
  31. gray. This is the default.
  32. Since the gray engine has its default settings, you don't need to set the
  33. delays before using gray drawing functions. But you can do it to customize
  34. the appearance of the gray to your application. Be aware that most values
  35. will just produce visual artifacts and will not look good. There are three
  36. characteristics that you'll want to control:
  37. * The stability of the shades; depending on the frequency gray areas can
  38. appear to blink.
  39. * Stripes. If the refresh timing coincides with the screen's display
  40. duration, stripes will appear. They can be of various sizes, visibility
  41. and speed; but overall they're the *one* thing you want to avoid.
  42. * And the color of the shades themselves.
  43. Here are values from an older version of gint, which may not look good now
  44. but provide bases to search for good settings:
  45. LIGHT DARK BLINKING STRIPES COLORS
  46. --------------------------------------------------
  47. 860 1298 none terrible decent
  48. 912 1343 heavy none good
  49. 993 1609 medium light decent
  50. 1325 1607 heavy light excellent
  51. --------------------------------------------------
  52. Here are values for this version of gint (for the Graph 35+E II only):
  53. LIGHT DARK BLINKING STRIPES COLORS
  54. --------------------------------------------------
  55. 680 1078
  56. 762 1311 low some too light [default]
  57. 869 1097 medium some excellent
  58. 869 1311 medium none good
  59. 937 1425 medium none good
  60. --------------------------------------------------
  61. @light New light delay
  62. @dark New dark delay */
  63. void gray_delays(uint32_t light, uint32_t dark);
  64. /* gray_config(): Get the current configuration of the engine
  65. Provides the value of the current light and dark delays, measured in timer
  66. ticks of prescaler P_phi/64. See <gint/clock.h> on how to obtain this value.
  67. Both pointers may be NULL.
  68. @light Set to the current light delay setting
  69. @dark Set to the current dark delay setting
  70. Returns non-zero if the engine is currently running, 0 otherwise. */
  71. int gray_config(uint32_t *light, uint32_t *dark);
  72. //---
  73. // Area rendering functions
  74. //---
  75. /* gclear(): Fill the screen with a single color
  76. Clears the VRAM and paints all the pixels in the same color. Optimized for
  77. opaque colors; use grect() for other colors.
  78. @color white, light, dark, black */
  79. void gclear(color_t color);
  80. /* grect(): Fill a rectangle on the screen
  81. Applies a color or an operator to the rectangle enclosed by (x1 y1) and
  82. (x2 y2), both included.
  83. @x1 @x2 @y1 @y2 Bounding rectangle
  84. @color white, light, dark, black, none, invert, lighten, darken */
  85. void grect(int x1, int y1, int x2, int y2, color_t color);
  86. //---
  87. // Point drawing functions
  88. //---
  89. /* gpixel(): Change a pixel's color
  90. Paints the specified pixel. Use lines or area rendering when possible
  91. because painting pixels individually is slow.
  92. @x @y Coordinates of the pixel to paint
  93. @color white, light, dark, black, none, invert, lighten, darken */
  94. void gpixel(int x, int y, color_t color);
  95. /* gline(): Render a straight line
  96. Draws a line without anti-aliasing, using a Bresenham-style algorithm. Much
  97. like dline(), has optimizations for vertical and horizontal lines but is not
  98. able to handle clipping.
  99. @x1 @y1 @x2 @y2 End points of the line (both included)
  100. @color white, light, dark, black, none, invert, lighten, darken */
  101. void gline(int x1, int y1, int x2, int y2, color_t color);
  102. /* ghline(): Full-width horizontal line
  103. @y Line number
  104. @color white, light, dark, black, none, invert, lighten, darken */
  105. void ghline(int y, color_t color);
  106. /* gvline(): Full-height vertical line
  107. @x Column number
  108. @color white, light, dark, black, none, invert, lighten, darken */
  109. void gvline(int x, color_t color);
  110. //---
  111. // Text rendering
  112. //---
  113. /* dfont() and dsize() still work with the gray engine. */
  114. /* gtext(): Display a string of text
  115. Exactly like dtext(), except that the rendering is done on the two gray
  116. VRAMs and all colors are supported.
  117. @x @y Coordinates of top-left corner of the rendered string
  118. @str String to display
  119. @fg Foreground: white, light, dark, black, none, invert, lighten, darken
  120. @bg Background, same colors as fg */
  121. void gtext(int x, int y, const char *str, int fg, int bg);
  122. //---
  123. // Image rendering
  124. //---
  125. /* gimage(): Render a full image
  126. This function is exactly like dimage(), but it draws gray image instead.
  127. @x @y Coordinates of the top-left corner of the image
  128. @image Pointer to gray image encoded with [fxconv] */
  129. void gimage(int x, int y, image_t const *image);
  130. /* gsubimage(): Render a section of an image
  131. Like dsubimage() for gray images. Same options apply.
  132. @x @y Coordinates on screen of the rendered subrectangle
  133. @image Pointer to image encoded with [fxconv]
  134. @left @top Top-left coordinates of the subrectangle within [image]
  135. @width @height Subrectangle dimensions
  136. @flags OR-combination of DIMAGE_* flags */
  137. void gsubimage(int x, int y, image_t const *image, int left, int top,
  138. int width, int height, int flags);
  139. //---
  140. // VRAM management
  141. //---
  142. /* gupdate(): Push the current VRAMs to the screen
  143. This function swaps pairs of VRAM buffers in the gray engine so that the
  144. gray and light VRAMs that were being drawn to are now available to be
  145. displayed on the screen at the next refresh, while the VRAMs that were
  146. previously being displayed are now available for drawing.
  147. Unlike dupdate(), gupdate() does not interact with the screen as this
  148. interaction is done very frequently by the engine itself. It performs an
  149. atomic operation to swap buffers, but nothing on the screen will change
  150. until the engine's timer actually fires. */
  151. void gupdate(void);
  152. /* gvram(): Get the current VRAM pointers
  153. This function stores the current VRAM pointers to the specified locations.
  154. This operation needs to be done atomically because the engine might kick in
  155. and sway buffers at any time; calling gvraml() then gvramd() is unsafe.
  156. @light Set to the current light VRAM pointer
  157. @dark Set to the current dark VRAM pointer */
  158. void gvram(uint32_t **light, uint32_t **dark);
  159. /* gvraml(): Shorthand to retrieve the current light VRAM pointer */
  160. uint32_t *gvraml(void);
  161. /* gvramd(): Shorthand to retrieve the current dark VRAM pointer */
  162. uint32_t *gvramd(void);
  163. #endif /* GINT_GRAY */