1
0
mirror of https://gitlab.com/camelot/kickc.git synced 2024-06-02 00:41:42 +00:00
kickc/src/test/kc/examples/c64/music/music_irq.c
2024-01-02 19:21:16 +01:00

40 lines
1.1 KiB
C
Executable File

// A simple SID music player using RASTER IRQ
#include <c64.h>
// SID tune at an absolute address
__address(0x1000) char MUSIC[] = kickasm(resource "toiletrensdyr.sid") {{
.const music = LoadSid("toiletrensdyr.sid")
.fill music.size, music.getData(i)
}};
typedef void (*PROC_PTR)();
// Pointer to the music init routine
PROC_PTR musicInit = (PROC_PTR) MUSIC;
// Pointer to the music play routine
PROC_PTR musicPlay = (PROC_PTR) MUSIC+3;
// Setup Raster IRQ and initialize SID player
void main() {
asm { sei }
(*musicInit)();
// Disable CIA 1 Timer IRQ
CIA1->INTERRUPT = CIA_INTERRUPT_CLEAR_ALL;
// Set raster line to $fd
VICII->CONTROL1 &=$7f;
VICII->RASTER = $fd;
// Enable Raster Interrupt
VICII->IRQ_ENABLE = IRQ_RASTER;
// Set the IRQ routine
*KERNEL_IRQ = &irq_play;
asm { cli }
}
// Raster IRQ Routine playing music
__interrupt(rom_sys_c64) void irq_play() {
(VICII->BORDER_COLOR)++;
// Play SID
(*musicPlay)();
// Acknowledge the IRQ
VICII->IRQ_STATUS = IRQ_RASTER;
(VICII->BORDER_COLOR)--;
}