我想在 cc65 程序中包含和播放 .sid 文件(C64 芯片音乐的音乐)。通常 sid 文件包含一个起价为 1000 美元的播放程序,我如何将其链接到我的 cc65 程序?
目前我使用以下命令用 cc65 编译我的代码:

cl65 -O -o C64test.prg -t c64 C64test.c

最佳答案

我找到了一个解决方案:

  • 创建一个 .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
    
  • 从 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;
    }
    
  • 使用标准 cc65 Makefile 编译这两个文件,这会为您提供带有代码的 .c64 文件,但没有 SID 数据
  • 使用 sidreloc 重新定位 SID 文件(选项 -p 定义新的起始页,在这种情况下 20 表示 $2000)
    ./sidreloc -r 10-1f -p 20 sidfile.sid sidfile2000.sid
    
  • 使用 .prg 将 SID 文件转换为 C64 psid64 :
    psid –n sidfile2000.sid
    
  • 使用 sidfile2000.prg 将文件 exomizer 与编译的 C 程序链接在一起(2061 的数字是程序的起始地址,2061 是 cc65 的默认值):
    exomizer sfx 2061 music.c64 sidfile2000.prg -o final.prg
    
  • 关于c - 如何将 SID 文件包含到 C64 上的 cc65 程序中?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/40950140/

    10-11 15:25
    查看更多