+
+void rtg_enable_mouse_cursor() {
+ mouse_cursor_enabled = 1;
+}
+
+void rtg_set_mouse_cursor_pos(int16_t x, int16_t y) {
+ mouse_cursor_x = x;
+ mouse_cursor_y = y;
+ //printf("Set mouse cursor pos to %d, %d.\n", x, y);
+}
+
+static uint8_t clut_cursor_data[256*256];
+
+void update_mouse_cursor(uint8_t *src) {
+ if (src != NULL) {
+ memset(clut_cursor_data, 0x00, 256*256);
+ uint8_t cur_bit = 0x80;
+ uint8_t line_pitch = (mouse_cursor_w / 8) * 2;
+
+ for (uint8_t y = 0; y < mouse_cursor_h; y++) {
+ for (uint8_t x = 0; x < mouse_cursor_w; x++) {
+ if (src[(x / 8) + (line_pitch * y)] & cur_bit)
+ clut_cursor_data[x + (y * 256)] |= 0x01;
+ if (src[(x / 8) + (line_pitch * y) + (mouse_cursor_w / 8)] & cur_bit)
+ clut_cursor_data[x + (y * 256)] |= 0x02;
+ cur_bit >>= 1;
+ if (cur_bit == 0x00)
+ cur_bit = 0x80;
+ }
+ cur_bit = 0x80;
+ }
+ }
+
+ for (int y = 0; y < mouse_cursor_h; y++) {
+ for (int x = 0; x < mouse_cursor_w; x++) {
+ cursor_data[x + (y * 256)] = cursor_palette[clut_cursor_data[x + (y * 256)]];
+ }
+ }
+
+ printf ("Updated mouse cursor data.\n");
+
+ while (rtg_on && !updating_screen)
+ usleep(0);
+ cursor_image_updated = 1;
+}
+
+void rtg_set_cursor_clut_entry(uint8_t r, uint8_t g, uint8_t b, uint8_t idx) {
+ uint32_t color = 0;
+ unsigned char *dst = (unsigned char *)&color;
+
+ dst[0] = r;
+ dst[1] = g;
+ dst[2] = b;
+ dst[3] = 0xFF;
+ if (cursor_palette[idx + 1] != color) {
+ cursor_palette[0] = 0;
+ cursor_palette[idx + 1] = color;
+ update_mouse_cursor(NULL);
+ }
+}
+
+static uint8_t old_mouse_w, old_mouse_h;
+static uint8_t old_mouse_data[256];
+
+void rtg_set_mouse_cursor_image(uint8_t *src, uint8_t w, uint8_t h) {
+ uint8_t new_cursor_data = 0;
+
+ mouse_cursor_w = w;
+ mouse_cursor_h = h;
+
+ if (memcmp(src, old_mouse_data, (w / 8 * h)) != 0) {
+ printf("New cursor data.\n");
+ new_cursor_data = 1;
+ } else {
+ printf("No new cursor data.\n");
+ }
+
+ if (old_mouse_w != w || old_mouse_h != h || new_cursor_data) {
+ printf("Set new %dx%d mouse cursor image.\n", mouse_cursor_w, mouse_cursor_h);
+ old_mouse_w = w;
+ old_mouse_h = h;
+ update_mouse_cursor(src);
+ }
+}