Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // A simple SID music player using RASTER IRQ
- import "c64.kc"
- const byte* MUSIC = $8000;
- const byte sfxchannel = 14; // 3
- 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 };
- // Load the SID
- kickasm(resource "music.sid") {{
- .const music = LoadSid("music.sid")
- }}
- // Place the SID into memory
- kickasm(pc MUSIC) {{
- .fill music.size, music.getData(i)
- }}
- // Setup Raster IRQ and initialize SID player
- void main() {
- asm {
- sei
- lda #$00
- jsr music.init
- }
- // Disable CIA 1 Timer IRQ
- *CIA1_INTERRUPT = CIA_INTERRUPT_CLEAR;
- // Set raster line to $fd
- *VIC_CONTROL &=$7f;
- *RASTER = $fd;
- // Enable Raster Interrupt
- *IRQ_ENABLE = IRQ_RASTER;
- // Set the IRQ routine
- *KERNEL_IRQ = &irq_play;
- asm { cli }
- do {
- for (dword i = 0; i < 100000; i++) { }
- // shots are fired
- play_sfx(gunshot,sfxchannel);
- } while (true);
- }
- void play_sfx(byte* sfx, byte channel) {
- const byte* memA = $fd;
- *memA = <sfx;
- *(memA+1) = >sfx;
- *(memA+2) = channel;
- asm {
- pha
- txa
- pha
- tya
- pha
- lda memA
- ldy memA+1
- ldx memA+2
- jsr music.init+6
- pla
- tay
- pla
- tax
- pla
- }
- }
- // Raster IRQ Routine playing music
- interrupt(kernel_keyboard) void irq_play() {
- (*BORDERCOL)++;
- // Play SID
- asm { jsr music.play }
- // Acknowledge the IRQ
- *IRQ_STATUS = IRQ_RASTER;
- (*BORDERCOL)--;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement