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.

sound_game.c 2.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /*
  2. * sound_game.c
  3. * Duality
  4. *
  5. * Copyright (C) 2025 Thomas Buck <thomas@xythobuz.de>
  6. *
  7. * Based on examples from gbdk-2020:
  8. * https://github.com/gbdk-2020/gbdk-2020/blob/develop/gbdk-lib/examples/gb/sound/sound.c
  9. *
  10. * And the docs for the DMG APU:
  11. * https://gbdev.io/pandocs/Audio_Registers.html
  12. *
  13. * This program is free software: you can redistribute it and/or modify
  14. * it under the terms of the GNU General Public License as published by
  15. * the Free Software Foundation, either version 3 of the License, or
  16. * (at your option) any later version.
  17. *
  18. * This program is distributed in the hope that it will be useful,
  19. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. * GNU General Public License for more details.
  22. *
  23. * See <http://www.gnu.org/licenses/>.
  24. */
  25. #include <assert.h>
  26. #include "banks.h"
  27. #include "sound_game.h"
  28. BANKREF(sound_game)
  29. #define NOTE_LOOP \
  30. F1, F1, F1, G1, Gd2, Gd1, Cd1, D1, \
  31. D2, D2, D2, Fd1, Fd1, D2, D2, D2
  32. // TODO
  33. #define DIFF_LOOP \
  34. F1, F1, F1, G1, Gd2, Gd1, Cd1, D1, \
  35. D2, D2, D2, Fd1, Fd1, D2, D2, D2
  36. static const enum notes game_music[] = {
  37. NOTE_LOOP, NOTE_LOOP, NOTE_LOOP, NOTE_LOOP,
  38. NOTE_LOOP, NOTE_LOOP, NOTE_LOOP, NOTE_LOOP,
  39. NOTE_LOOP, NOTE_LOOP, NOTE_LOOP, NOTE_LOOP,
  40. DIFF_LOOP, DIFF_LOOP, DIFF_LOOP, DIFF_LOOP,
  41. NOTE_LOOP, NOTE_LOOP, NOTE_LOOP, NOTE_LOOP,
  42. END
  43. };
  44. #define DRUM_LOOP \
  45. dSn, dSI, dSn, dSI, dKi, dSI, dSI, dSI, \
  46. dSn, dSI, dSn, dSI, dKi, dSI, dSI, dSI \
  47. #define SILE_LOOP \
  48. dSI, dSI, dSI, dSI, dSI, dSI, dSI, dSI, \
  49. dSI, dSI, dSI, dSI, dSI, dSI, dSI, dSI \
  50. static const enum drums game_drums[] = {
  51. DRUM_LOOP, DRUM_LOOP, DRUM_LOOP, DRUM_LOOP,
  52. DRUM_LOOP, DRUM_LOOP, DRUM_LOOP, DRUM_LOOP,
  53. SILE_LOOP, SILE_LOOP, SILE_LOOP, SILE_LOOP,
  54. DRUM_LOOP, DRUM_LOOP, DRUM_LOOP, DRUM_LOOP,
  55. DRUM_LOOP, DRUM_LOOP, DRUM_LOOP, DRUM_LOOP,
  56. dEND
  57. };
  58. static_assert(sizeof(game_music) == sizeof(game_drums), "music loops need to be same length");
  59. const struct music music_game = {
  60. .notes = game_music,
  61. .notes2 = NULL,
  62. .drums = game_drums,
  63. .duration = 160,
  64. .repeat = 0,
  65. };