1; Example of using playroutine 1 in multispeed
2;
3; playeraddress+0 = init music (A = tunenumber starting from 0)
4; playeraddress+3 = play music
5;
6; Remember that this player uses 2 zeropage locations, so save those
7; locations before calling the player, if you need all of the ZP.
8; The player doesn't depend on their contents between calls at all!
9;
10; For multispeed operation, simply call playeraddress+3 many times
11; per frame.
12
13                processor 6502
14                org 2048
15
16getin           = $ffe4
17
18start:          jsr initraster
19                lda #22
20                sta $d018
21                lda #$00
22                jsr $1000                       ;Initialize song 0
23                ldx #$00
24                lda #$20
25clearscreen:    sta $0400,x
26                sta $0500,x
27                sta $0600,x
28                sta $0700,x
29                inx
30                bne clearscreen
31textloop:       lda text,x
32                jsr convertascii
33                sta $0400,x
34                lda #$01
35                sta $d800,x
36                inx
37                cpx #5*40
38                bcc textloop
39                ldx #$00
40authorloop:     lda $1020,x
41                jsr convertascii
42                sta $0458,x
43                inx
44                cpx #32
45                bne authorloop
46idle:           lda currraster
47                ldx #52
48                jsr printhex
49                lda maxraster
50                ldx #55
51                jsr printhex
52                jmp idle
53
54printhex:       pha
55                lsr
56                lsr
57                lsr
58                lsr
59                tay
60                lda hexnybble,y
61                jsr convertascii
62                sta $0400,x
63                pla
64                and #$0f
65                tay
66                lda hexnybble,y
67                jsr convertascii
68                sta $0401,x
69                rts
70
71convertascii:   cmp #$60
72                bcc ca_ok
73                sbc #$60
74ca_ok:          rts
75
76initraster:     sei
77                lda #<raster
78                sta $0314
79                lda #>raster
80                sta $0315
81                lda #50                         ;Set low bits of raster
82                sta $d012                       ;position
83                lda $d011
84                and #$7f                        ;Set high bit of raster
85                sta $d011                       ;position (0)
86                lda #$7f                        ;Set timer interrupt off
87                sta $dc0d
88                lda #$01                        ;Set raster interrupt on
89                sta $d01a
90                lda $dc0d                       ;Acknowledge timer interrupt
91                cli
92irwait:         lda maxraster
93                beq irwait
94                lda #$00
95                sta maxraster
96                rts
97
98raster:         nop
99                nop
100                nop
101                nop
102                nop
103                lda $d012
104                sta raster_cmp+1
105                inc $d020
106                jsr $1003                       ;Play music and measure
107                lda $d012                       ;rastertime it took to
108                dec $d020                       ;execute
109                sec
110raster_cmp:     sbc #$00
111                clc
112                adc accraster
113                sta accraster
114                cmp maxraster
115                bcc raster_skip
116                sta maxraster
117raster_skip:    dec $d019
118                ldy nextraster
119                bne raster_skip2
120                sty accraster
121                sta currraster
122raster_skip2:   tya
123                eor #$01
124                tax
125                sta nextraster
126                lda rasterlinetbl,x
127                sta $d012
128                jmp $ea31
129
130text:           dc.b "Example 3: Multispeed-musicroutine      "
131                dc.b "Rastertime:   /                         "
132                dc.b "Author:                                 "
133                dc.b "                                        "
134                dc.b "                                        "
135
136
137hexnybble:      dc.b "0123456789ABCDEF"
138
139maxraster:      dc.b 0
140accraster:      dc.b 0
141currraster:     dc.b 0
142nextraster:     dc.b 0
143
144rasterlinetbl:  dc.b 50,210
145
146                org $1000
147
148                incbin example3.bin
149