Advertisement
rilo

KickC Goat Tracker sound FX example

Jul 8th, 2019
449
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.65 KB | None | 0 0
  1. // A simple SID music player using RASTER IRQ
  2. import "c64.kc"
  3.  
  4. const byte* MUSIC = $8000;
  5. const byte sfxchannel = 14; // 3
  6.  
  7. byte[] gunshot = { $00,$F9,$08,$C4,$81,$A8,$41,$C0,$81,$BE,$BC,$80,$BA,$B8,$B6,$B4,$B2,$B0,$AE,$AC,$AA,$A8,$A6,$A4,$A2,$A0,$9E,$9C,$9A,$98,$96,$94,$92,$90,$00 };
  8.  
  9. // Load the SID
  10. kickasm(resource "music.sid") {{
  11. .const music = LoadSid("music.sid")
  12. }}
  13.  
  14. // Place the SID into memory
  15. kickasm(pc MUSIC) {{
  16. .fill music.size, music.getData(i)
  17. }}
  18.  
  19. // Setup Raster IRQ and initialize SID player
  20. void main() {
  21. asm {
  22. sei
  23. lda #$00
  24. jsr music.init
  25. }
  26. // Disable CIA 1 Timer IRQ
  27. *CIA1_INTERRUPT = CIA_INTERRUPT_CLEAR;
  28. // Set raster line to $fd
  29. *VIC_CONTROL &=$7f;
  30. *RASTER = $fd;
  31. // Enable Raster Interrupt
  32. *IRQ_ENABLE = IRQ_RASTER;
  33. // Set the IRQ routine
  34. *KERNEL_IRQ = &irq_play;
  35. asm { cli }
  36. do {
  37. for (dword i = 0; i < 100000; i++) { }
  38. // shots are fired
  39. play_sfx(gunshot,sfxchannel);
  40. } while (true);
  41. }
  42.  
  43. void play_sfx(byte* sfx, byte channel) {
  44. const byte* memA = $fd;
  45. *memA = <sfx;
  46. *(memA+1) = >sfx;
  47. *(memA+2) = channel;
  48. asm {
  49. pha
  50. txa
  51. pha
  52. tya
  53. pha
  54. lda memA
  55. ldy memA+1
  56. ldx memA+2
  57. jsr music.init+6
  58. pla
  59. tay
  60. pla
  61. tax
  62. pla
  63. }
  64. }
  65.  
  66. // Raster IRQ Routine playing music
  67. interrupt(kernel_keyboard) void irq_play() {
  68. (*BORDERCOL)++;
  69. // Play SID
  70. asm { jsr music.play }
  71.  
  72. // Acknowledge the IRQ
  73. *IRQ_STATUS = IRQ_RASTER;
  74. (*BORDERCOL)--;
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement