diff options
Diffstat (limited to 'docs/casiowin/monochromelib/vram.en.md')
-rw-r--r-- | docs/casiowin/monochromelib/vram.en.md | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/docs/casiowin/monochromelib/vram.en.md b/docs/casiowin/monochromelib/vram.en.md new file mode 100644 index 0000000..554cb72 --- /dev/null +++ b/docs/casiowin/monochromelib/vram.en.md @@ -0,0 +1,72 @@ +--- +title: VRAM interactions +--- +As described in [the introduction](index), MonochromeLib uses video memory +as the primary way of drawing on the screen. Instead of defining its own, +MonochromeLib uses the system one, which can change according to the version +of the OS the add-in is running on. + +The screen of the fx-9860G is 128 pixels long and 64 pixels tall. It's a +1-bit monochrome screen, where a '1' represents a black pixel and a '0' +represents a white pixel. The VRAM is organized as a set of 64 groups of +128 pixels (16 bytes), going from top to bottom, then, in a line, from left to +right (the highest bit in a byte, 128, is at the left of the 8 pixel group, +whereas the lowest bit, 1, is at the right of it). + +Don't forget to [update the screen](screen#update) once the VRAM is ready +to be displayed! + +### Getting the VRAM address +As the VRAM address can vary, it is **imperative** that you use this function +if you ought to interact with the VRAM directly, instead of hardcoding the +address, which lead many add-ins to compatibility problems. + +{% highlight c %} +char *ML_vram_address(); +{% endhighlight %} + +The `char*` return type is used for compatibility. As you might want to use +bitwise operations, it is recommended to cast the return value as +`unsigned char` or make the compiler assume unsigned char by default, +for example, using `-funsigned-char` on GCC. + +### Colors +MonochromeLib defines the following set of colors and meta-colors: + +{% highlight c %} +typedef enum { + ML_TRANSPARENT = -1, + ML_WHITE, + ML_BLACK, + ML_XOR, + ML_CHECKER +} ML_Color +{% endhighlight %} + +`ML_BLACK` and `ML_WHITE` correspond to the 'raw' colors, `ML_XOR` changes the +color of every affected pixel, and `ML_CHECKER` makes a "checkerboard" color, +that sets one pixel out of two black, and the other one white. + +For an example of `ML_CHECKER`, see [the ML_rectangle example](draw#rectangle). + +### Interacting with pixels +If you don't want to interact with the VRAM directly, you can use these +simple functions to set and get the status of a pixel in the VRAM using +these functions: + +{% highlight c %} +void ML_pixel(int x, int y, ML_Color color); +ML_Color ML_pixel_test(int x, int y); +{% endhighlight %} + +All of the [drawing functions](draw) can be done using these functions, +although the library functions interact directly with the VRAM, so they +are quicker and should be used if possible. + +### Clear the VRAM +If you want to have an empty VRAM to redraw it, you can use the following +function: + +{% highlight c %} +void ML_clear_vram(void); +{% endhighlight %} |