我想在 cc65 程序中包含和播放 .sid 文件(C64 芯片音乐的音乐)。通常 sid 文件包含一个起价为 1000 美元的播放程序,我如何将其链接到我的 cc65 程序?目前我使用以下命令用 cc65 编译我的代码:
cl65 -O -o C64test.prg -t c64 C64test.c
Run Code Online (Sandbox Code Playgroud)
我找到了一个解决方案:
创建一个 .asm 文件,生成以下代码:
.export _setupAndStartPlayer
sid_init = $2000
sid_play = $2003
siddata = $2000
.segment "CODE"
.proc _setupAndStartPlayer: near
lda #$00 ; select first tune
jsr sid_init ; init music
; now set the new interrupt pointer
sei
lda #<_interrupt ; point IRQ Vector to our custom irq routine
ldx #>_interrupt
sta $314 ; store in $314/$315
stx $315
cli ; clear interrupt disable flag
rts
.endproc
.proc _interrupt
jsr sid_play
;dec 53280 ; flash border to see we are live
jmp $EA31 ; do the normal interrupt service routine
.endproc
Run Code Online (Sandbox Code Playgroud)
从 C 调用 asm 函数:
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <c64.h>
extern int setupAndStartPlayer();
int main(void) {
printf("Setting up player\n");
setupAndStartPlayer();
return 0;
}
Run Code Online (Sandbox Code Playgroud)
使用标准编译这两个文件cc65 Makefile,这将为您提供一个.c64包含代码的文件,但没有 SID 数据
使用重新定位 SID 文件sidreloc(该选项-p定义新的起始页,在这种情况下20意味着 $2000)
./sidreloc -r 10-1f -p 20 sidfile.sid sidfile2000.sid
Run Code Online (Sandbox Code Playgroud)
该SID文件转换为C64.prg采用psid64:
psid –n sidfile2000.sid
Run Code Online (Sandbox Code Playgroud)
使用以下命令将文件sidfile2000.prg与编译的 C 程序链接在一起exomizer(数字2061是程序的起始地址,2061 是 的默认值cc65):
exomizer sfx 2061 music.c64 sidfile2000.prg -o final.prg
Run Code Online (Sandbox Code Playgroud)