3

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

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

1 回答 1

6

我找到了一个解决方案:

  1. 创建一个生成以下代码的 .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
    
  2. 从 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;
    }
    
  3. 使用标准编译这两个文件cc65 Makefile,这会为您提供一个.c64包含代码的文件,但没有 SID 数据

  4. 使用重定位 SID 文件sidreloc(该选项-p定义新的起始页,在这种情况下20意味着 $2000)

    ./sidreloc -r 10-1f -p 20 sidfile.sid sidfile2000.sid
    
  5. .prg使用以下命令将 SID 文件转换为 C64 psid64

    psid –n sidfile2000.sid
    
  6. sidfile2000.prg将文件与编译后的C程序链接在一起使用exomizer(数字2061是程序的起始地址,2061是默认的cc65):

    exomizer sfx 2061 music.c64 sidfile2000.prg -o final.prg
    
于 2016-12-11T00:12:56.547 回答