暂无描述

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