GameBoy (Color) port of the GTA San Andreas arcade game Duality
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

config.ba0.c 1.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /*
  2. * config.ba0.c
  3. * Duality
  4. *
  5. * Copyright (C) 2025 Thomas Buck <thomas@xythobuz.de>
  6. *
  7. * This program is free software: you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation, either version 3 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * See <http://www.gnu.org/licenses/>.
  18. */
  19. #include <stddef.h>
  20. #undef NULL
  21. #include "banks.h"
  22. #include "score.h"
  23. #include "sample.h"
  24. #include "sound.h"
  25. #include "config.h"
  26. struct config_mem mem;
  27. BANKREF(config)
  28. static uint32_t calc_crc(void) {
  29. const uint8_t *d = (const uint8_t *)mem;
  30. uint32_t c = 0xFFFFFFFF;
  31. for (size_t i = 0; i < offsetof(struct config_mem, crc); i++) {
  32. // adapted from "Hacker's Delight"
  33. c ^= d[i];
  34. for (size_t j = 0; j < 8; j++) {
  35. uint32_t mask = -(c & 1);
  36. c = (c >> 1) ^ (0xEDB88320 & mask);
  37. }
  38. }
  39. return ~c;
  40. }
  41. void conf_init(void) BANKED {
  42. ENABLE_RAM;
  43. SWITCH_RAM(0);
  44. if (calc_crc() != mem.crc) {
  45. mem.config.debug_flags = 0;
  46. mem.config.sfx_vol = 0x03;
  47. mem.config.music_vol = 0x07;
  48. score_reset();
  49. }
  50. }
  51. void conf_write_crc(void) BANKED {
  52. mem.crc = calc_crc();
  53. }