FC/NES PPU卷轴滚屏示例 歌词显示

陪她去流浪 桃子 2012年09月01日 阅读次数:2478
编写女孩不哭 2012-08-31
环境6502汇编, 6502通用汇编器 1.2.6 修改版
歌词Kelly Clarkson - Because of you

效果图

源代码

//文件头 header.bin
4E 45 53 1A 01 01 01 00
00 00 00 00 00 00 00 00
; lyric.inc

lyric_data:
    .str "Kelly Clarkson"
    .str "Because Of You"
    .str "I will not make"
    .str "the same mistakes that you did"
    .str "I will not let myself"
    .str "Cause my heart so much misery"
    .str "I will not break the way you did"
    .str "You fell so hard"
    .str "I've learned the hard way"
    .str "To never let it get that far"
    .str "Because of you"
    .str "I never stray too far"
    .str "from the sidewalk"
    .str "Because of you"
    .str "I learned to play on the"
    .str "safe side so I don t get hurt"
    .str "Because of you"
    .str "I find it hard to trust not only"
    .str "me, but everyone around me"
    .str "Because of you"
    .str "I am afraid"
    .str "I lose my way"
    .str "And it s not too long before"
    .str "you point it out"
    .str "I cannot cry"
    .str "Because you know that's"
    .str "weakness in your eyes"
    .str "I'm forced to fake"
    .str "A smile, a laugh"
    .str "everyday of my life"
    .str "My heart can't possibly break"
    .str "When it wasn't even whole"
    .str "to start with"
    .str "Because of you"
    .str "I never stray too far from"
    .str "the sidewalk"
    .str "Because of you"
    .str "I learned to play on "
    .str "the safe side"
    .str "so I don t get hurt"
    .str "Because of you"
    .str "I find it hard to trust not only"
    .str "me, but everyone around me"
    .str "Because of you"
    .str "I am afraid"
    .str "I watched you die"
    .str "I heard you cry every night"
    .str "in your sleep"
    .str "I was so young"
    .str "You should have known better"
    .str "than to lean on me"
    .str "You never thought of anyone else"
    .str "You just saw your pain"
    .str "And now I cry in the"
    .str "middle of the night"
    .str "For the same damn thing"
    .str "Because of you"
    .str "I never stray too far"
    .str "from the sidewalk"
    .str "Because of you"
    .str "I learned to play on the"
    .str "safe side so I don't get hurt"
    .str "Because of you"
    .str "I try my hardest just to"
    .str "forget everything"
    .str "Because of you"
    .str "I don't know how to let"
    .str "anyone else in"
    .str "Because of you"
    .str "I'm ashamed of my life"
    .str "because it s empty"
    .str "Because of you"
    .str "I am afraid"
    .str "Because of you"
    .str "Because of you"
    .byte $00
;lrcshow.65s
        .start  reset
        .org    $C000
        .include "lyric.inc"
        
reset:
        sei
        cld
        ldx     #$ff
        txs
_reset_vb1:
        lda     $2002
        bpl     _reset_vb1
_reset_vb2:
        lda     $2002
        bpl     _reset_vb2
        inx
        stx     $00
        stx     $01
        stx     $06
        stx     $2000
        stx     $2001
        lda     #<lyric_data
        sta     $02
        lda     #>lyric_data
        sta     $03
        lda     #$20
        sta     $04
        sta     $05

        jsr     clear_nt
        jsr     set_palette
        lda     #$00
        sta     $2005
        sta     $2005
        lda     #$80
        sta     $2000
        lda     #$1e
        sta     $2001
main:
        jmp     main
; ////////////////////////////////////////////////////////////////
clear_nt:
        lda     #$20
        sta     $2006
        jsr     _cn_sub1
        lda     #$28
        sta     $2006
        jsr     _cn_sub1
        rts
_cn_sub1:
        lda     #$00
        sta     $2006
        ldy     #$04
_loop_y1:
        ldx     #$00
_loop_x1:
        sta     $2007
        inx
        bne     _loop_x1
        dey
        bne     _loop_y1
        rts
; ////////////////////////////////////////////////////////////////
set_palette:
        lda     #$3f
        sta     $2006
        lda     #$00
        sta     $2006
        ldx     #$00
_sp_loop1:
        lda     _pal_data,x
        sta     $2007
        inx
        cpx     #$04
        bne     _sp_loop1
        
        lda     #$3f
        sta     $2006
        lda     #$10
        sta     $2006
        ldx     #$00
_sp_loop2:
        lda     _pal_data+4,x
        sta     $2007
        inx
        cpx     #$04
        bne     _sp_loop2
        rts
_pal_data:
        .db     $0F,$03,$11,$1A
        .db     $0F,$1A,$11,$03
; ////////////////////////////////////////////////////////////////
irq:
        rti
; ////////////////////////////////////////////////////////////////
nmi:
        lda     $06
        cmp     #$01
        beq     _nmi_next3
        eor     #$01
        sta     $06
        rti
_nmi_next3:
        eor     #$01
        sta     $06
        lda     #$00
        sta     $2001
        lda     $01
        cmp     #$08
        bne     _nmi_next2
        lda     #$00
        sta     $01
        jsr     draw_lyric
_nmi_next2:
        inc     $01
        inc     $00
        lda     $00
        cmp     #$f0
        bne     _nmi_next1
        lda     #$00
        sta     $00
_nmi_next1:
        lda     #$00
        sta     $2005
        lda     $00
        sta     $2005
        lda     #$1e
        sta     $2001
        rti
; ////////////////////////////////////////////////////////////////
draw_lyric:
        lda     $05             ; 判断是否是$23C0(屏幕结束)
        cmp     #$23
        bne     _dl_next4       ; 不是, 跳出
        lda     $04
        cmp     #$c0
        bne     _dl_next4       ; 不是, 跳出
        lda     #$00            ; 复位到 屏幕开始
        sta     $04
        lda     #$20
        sta     $05     
_dl_next4:      
        lda     $05             ; 屏幕地址
        sta     $2006
        lda     $04
        sta     $2006
        ldy     #$00
        lda     ($02),y         ; 取得字符串长度
        bne     _dl_next5
        lda     #<lyric_data    ; 结束了, 回到开始
        sta     $02
        lda     #>lyric_data
        sta     $03     
        rts
_dl_next5:
        tax
        cpx     #$20            ; 最长为32
        bcs     _dl_loop1       ; >=
        txa                     ; 取得要打印的空白的个数
        sec                     ; 取相反数<---+
        sbc     #$20
        eor     #$ff
        clc
        adc     #$01            ; <-----------+
        pha                     ; 先保存, 记得保存堆栈平衡
        jmp     _dl_next3
_dl_loop1:
        ldx     #$20            ; >= , 只取32个字符
        lda     #$00            ; 0个空格
        pha
_dl_next3:
        iny                     ; 第一个字符
        lda     ($02),y
        sta     $2007
        inc     $04
        bne     _dl_cc1
        inc     $05
_dl_cc1:
        dex
        bne     _dl_next3
        
        iny     ; 定位到一下句的第一个字符
        tya
        clc
        adc     $02
        sta     $02
        bcc     _dl_cc2
        inc     $03
_dl_cc2:
        pla
        tax
        beq     _rts
        cpx     #$20
        beq     _rts
        lda     #$00
_dl_loop2:
        sta     $2007
        inc     $04
        bne     _dl_cc3
        inc     $05
_dl_cc3:
        dex
        bne     _dl_loop2
_rts:
        rts
        
; ////////////////////////////////////////////////////////////////
        .org    $fffa
        .dw     nmi,reset,irq
//lrcshow.chr
注:字模数据为ASCII数据, 这里不再上传.

这篇文章的内容已被作者标记为“过时”/“需要更新”/“不具参考意义”。

标签:代码片段 · 汇编 · 6502 · nes