Brak opisu

lcd.h 4.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. /****************************************************************************
  2. * Copyright (C) 2015-2016 by the SotS Team *
  3. * *
  4. * This file is part of Sovereign of the Skies. *
  5. * *
  6. * Sovereign of the Skies is free software: you can redistribute it *
  7. * and/or modify it *
  8. * under the terms of the GNU Lesser General Public License as published *
  9. * by the Free Software Foundation, either version 3 of the License, or *
  10. * (at your option) any later version provided you include a copy of the *
  11. * licence and this header. *
  12. * *
  13. * Sovereign of the Skies is distributed in the hope that it will be *
  14. * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of *
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
  16. * GNU Lesser General Public License for more details. *
  17. * *
  18. * You should have received a copy of the GNU Lesser General Public *
  19. * License along with Sovereign of the Skies. *
  20. * If not, see <http://www.gnu.org/licenses/>. *
  21. ****************************************************************************/
  22. /**
  23. * @file lcd.h
  24. * @author Sturmvogel
  25. * @date 15 dec 2016
  26. * @brief Operations on the GBA Screen
  27. *
  28. * This header contains methods to manipulate and update the lcd screen,
  29. * for interacting with the object entity engine
  30. * @see objects.h
  31. */
  32. #ifndef LCD_H_
  33. #define LCD_H_
  34. /* === STRUCTURES === */
  35. struct bg_config {
  36. u32 id : 2;
  37. u32 char_base : 2;
  38. u32 map_base : 5;
  39. u32 size : 2;
  40. u32 colormode : 1;
  41. u32 priority : 2;
  42. };
  43. struct map_entry {
  44. u16 tile : 10;
  45. u16 hflip : 1;
  46. u16 vflip : 1;
  47. u16 pal : 4;
  48. };
  49. union t_map_entry {
  50. u16 short_map;
  51. struct map_entry entry;
  52. };
  53. struct color {
  54. u16 r : 5;
  55. u16 g : 5;
  56. u16 b : 5;
  57. };
  58. /* === EXTERN METHODS === */
  59. /**
  60. * @brief copy tileset or tilemap to bg
  61. * @param bg_id bg id to copy tileset to
  62. * @param source tileset source
  63. * @param byte_size tileset size
  64. * @param start_tile start tile to copy to
  65. * @param mode 1 = copy tileset 2 = copy tilemap
  66. * @return
  67. */
  68. extern u8 gpu_copy_to_vram_by_bgid(u8 bg_id, void* source, u16 byte_size, u16 start_tile, u8 mode);
  69. /**
  70. * @brief reset bg configs and init bgs
  71. */
  72. extern void gpu_init_bgs();
  73. /**
  74. * @brief drop all tilesets from bg ( ? )
  75. * @param bg background to drop tilesets from
  76. */
  77. extern void gpu_tile_bg_drop_all_sets(u8 bg);
  78. /**
  79. * @setup bg vram
  80. * @param mirror not so sure about that
  81. * @param configs pointer to config array (4 entries)
  82. * @param count number of entries
  83. */
  84. extern void gpu_bg_vram_setup(u8 mirror, struct bg_config* configs, u8 count);
  85. /**
  86. * @brief set tilemap of bg in the bg structure
  87. * @param bg_id bg to set tilemap for
  88. * @param tilemap pointer to tilemap
  89. */
  90. extern void virtual_bg_set_tilemap(u8 bg_id, void* tilemap);
  91. /**
  92. * @brief set tilemap of bg to NULL in bg structure
  93. * @param bg_id bg to set tilemap for
  94. */
  95. extern void virtual_bg_nullify_tilemap(u8 bg_id);
  96. /**
  97. * @brief get tilemap of bg in bg structure
  98. * @param bg_id bg to get tilemap for
  99. * @return pointer to tilemap, might be null
  100. */
  101. extern void* virtual_bg_get_tilemap(u8 bg_id);
  102. /**
  103. * @brief sends virtual tilemap to vram
  104. * @param bg_id bg id to send tilemap for
  105. */
  106. extern void virtual_bg_send_tilemap(u8 bg_id);
  107. /**
  108. * @brief TODO DOCUMENT
  109. */
  110. extern void gpu_pal_apply();
  111. /**
  112. * @brief decompress palette and copy to f/u buffers
  113. * @param src palette source (lz compressed)
  114. * @param start palette start (in bytes)
  115. * @param end palette count (in entries, I think)
  116. */
  117. void pal_decompress_slice_to_faded_and_unfaded(void* src, u16 start, u16 end);
  118. /**
  119. * @brief show bg
  120. * @param id bg id
  121. */
  122. void gpu_bg_show(u8 id);
  123. /**
  124. * @brief hide bg
  125. * @param id bg id
  126. */
  127. void gpu_bg_hide(u8 id);
  128. /**
  129. * @brief sync bg visibility and mode, execute during vblank to avoid artifacts
  130. */
  131. void gpu_sync_bg_visibility_and_mode();
  132. /**
  133. * @brief set I/O
  134. * @param id device ID
  135. * @param value value to set I/O device to
  136. */
  137. void lcd_io_set_func(u8 id, u16 value);
  138. /**
  139. * @brief upload palettes from buffer to palette memory
  140. */
  141. void gpu_pal_upload();
  142. /**
  143. * @brief free pal tag
  144. * @param tag tag to free
  145. */
  146. void gpu_pal_free_by_tag(u16 tag);
  147. /**
  148. * @brief get from I/O
  149. * @param id device ID
  150. * @return I/O value
  151. */
  152. u16 lcd_io_get(u8 id);
  153. /* === MACROS AND DEFINES === */
  154. /* TODO: Implement without macros */
  155. #define palette_faded_buffer ((struct color*) 0x020375F8)
  156. #define palette_unfaded_buffer ((struct color*) 0x020371F8)
  157. #endif