No Description

dns.c 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. #include <pokeagb/pokeagb.h>
  2. #include <agb_debug.h>
  3. #include <dns.h>
  4. #include <rtc.h>
  5. #define DNS_BUF_SIZE 256
  6. #define DNS_SEC_PAL_START 224
  7. #define DNS_SEC_PAL_START_C (DNS_SEC_PAL_START / 2)
  8. const union Color dns_color_times[5] = {
  9. rgb82rgb5(70, 70, 196),
  10. rgb82rgb5(70, 70, 196),
  11. rgb82rgb5(70, 70, 196),
  12. rgb82rgb5(70, 70, 196),
  13. rgb82rgb5(70, 70, 196)
  14. };
  15. union Color dns_color_multiply(union Color a, union Color b);
  16. void dns_blockset_load_palette(struct MapBlockset* blockset, u16 offset, u16 size){
  17. //struct RtcTimestamp stamp;
  18. //rtc_get_time(&stamp);
  19. //dprintf("rtc data was read: %x.%x.%x\n", stamp.day, stamp.month, stamp.year);
  20. if(blockset != NULL){
  21. union Color *dns_buffer = malloc(DNS_BUF_SIZE*2);
  22. if(blockset->secondary > 0)
  23. {
  24. if(blockset->secondary == 1)
  25. {
  26. //load secondary palette uncompressed
  27. memcpy(dns_buffer, blockset->palettes+DNS_SEC_PAL_START, size);
  28. dns_modify_palette(dns_buffer, size/2);
  29. gpu_pal_apply(dns_buffer, offset,size);
  30. load_palette3(offset, size/2);
  31. }
  32. else
  33. {
  34. //load secondary palette compressed
  35. LZ77UnCompWram(blockset->palettes, dns_buffer);
  36. dns_modify_palette(&dns_buffer[DNS_SEC_PAL_START_C], size/2);
  37. gpu_pal_apply(&dns_buffer[DNS_SEC_PAL_START_C], offset, size);
  38. load_palette3(offset,size/2);
  39. }
  40. }
  41. else
  42. {
  43. union Color black;
  44. black.packed = 0x0000;
  45. gpu_pal_apply(&black, 0, 2);
  46. memcpy(dns_buffer, blockset->palettes, size);
  47. dns_modify_palette(dns_buffer, size/2);
  48. gpu_pal_apply(&dns_buffer[1], offset+1, size-2);
  49. load_palette3(offset+1, (size-2)/2);
  50. //load primary palette
  51. }
  52. free(dns_buffer);
  53. }
  54. }
  55. void dns_oec01_load_pal_impl(u32 *oe_script) {
  56. struct SpritePalette *pal = (struct SpritePalette *)oe_read_word(oe_script);
  57. struct SpritePalette palToApply = {
  58. .data = NULL,
  59. .tag = pal->tag
  60. };
  61. u8 idx = gpu_pal_tags_index_of(palToApply.tag);
  62. union Color *buffer = malloc(32);
  63. memcpy(buffer, pal->data, 32);
  64. dns_modify_palette(buffer, 16);
  65. palToApply.data = buffer;
  66. gpu_pal_obj_alloc_tag_and_apply(&palToApply);
  67. if(idx == 0xFF) {
  68. u8 idx = gpu_pal_tags_index_of(palToApply.tag);
  69. tint_palette_switch(idx);
  70. }
  71. idx = gpu_pal_tags_index_of(palToApply.tag);
  72. free(buffer);
  73. palette_obj_807AA8C(idx);
  74. *oe_script += 4;
  75. }
  76. void dns_oec02_load_pal_impl(u32 *oe_script) {
  77. struct SpritePalette *pal = (struct SpritePalette *)oe_read_word(oe_script);
  78. struct SpritePalette palToApply = {
  79. .data = NULL,
  80. .tag = pal->tag
  81. };
  82. u8 idx = gpu_pal_tags_index_of(palToApply.tag);
  83. union Color *buffer = malloc(32);
  84. memcpy(buffer, pal->data, 32);
  85. dns_modify_palette(buffer, 16);
  86. palToApply.data = buffer;
  87. gpu_pal_obj_alloc_tag_and_apply(&palToApply);
  88. if(idx == 0xFF) {
  89. u8 idx = gpu_pal_tags_index_of(palToApply.tag);
  90. tint_palette_switch(idx);
  91. }
  92. free(buffer);
  93. *oe_script += 4;
  94. }
  95. void dns_pal_patch_for_npc(u16 tag, u8 idx)
  96. {
  97. extern struct SpritePalette ow_pal_table[1100];
  98. u16 npcPalIdx = hacked_npc_pal_idx_for_given_tag(tag);
  99. union Color *buffer = malloc(32);
  100. memcpy(buffer, ow_pal_table[npcPalIdx].data,32);
  101. dns_modify_palette(buffer,16);
  102. gpu_pal_apply(buffer, 256 + 16*idx, 32);
  103. free(buffer);
  104. tint_palette_switch(idx);
  105. }
  106. void dns_modify_palette(union Color* buffer, u16 size){
  107. (void)buffer;
  108. (void)size;
  109. //to activate remove the above
  110. /* if(current_map_header.light == 8)
  111. return;
  112. for(u16 i = 0; i < size; ++i) {
  113. buffer[i] = dns_color_multiply(dns_color_times[0], buffer[i]);
  114. }*/
  115. }
  116. union Color dns_color_multiply(union Color a, union Color b) {
  117. u32 red = (a.components.r * b.components.r) / 31;
  118. u32 green = (a.components.g * b.components.g) / 31;
  119. u32 blue = (a.components.b * b.components.b) / 31;
  120. return crgb5(red,green,blue);
  121. }