File: example3.s

package info (click to toggle)
goattracker 2.70-1
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 2,628 kB
  • ctags: 3,087
  • sloc: ansic: 15,942; cpp: 7,833; asm: 3,644; makefile: 72
file content (148 lines) | stat: -rw-r--r-- 4,470 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
; Example of using playroutine 1 in multispeed
;
; playeraddress+0 = init music (A = tunenumber starting from 0)
; playeraddress+3 = play music
;
; Remember that this player uses 2 zeropage locations, so save those
; locations before calling the player, if you need all of the ZP.
; The player doesn't depend on their contents between calls at all!
;
; For multispeed operation, simply call playeraddress+3 many times
; per frame.

                processor 6502
                org 2048

getin           = $ffe4

start:          jsr initraster
                lda #22
                sta $d018
                lda #$00
                jsr $1000                       ;Initialize song 0
                ldx #$00
                lda #$20
clearscreen:    sta $0400,x
                sta $0500,x
                sta $0600,x
                sta $0700,x
                inx
                bne clearscreen
textloop:       lda text,x
                jsr convertascii
                sta $0400,x
                lda #$01
                sta $d800,x
                inx
                cpx #5*40
                bcc textloop
                ldx #$00
authorloop:     lda $1020,x
                jsr convertascii
                sta $0458,x
                inx
                cpx #32
                bne authorloop
idle:           lda currraster
                ldx #52
                jsr printhex
                lda maxraster
                ldx #55
                jsr printhex
                jmp idle

printhex:       pha
                lsr
                lsr
                lsr
                lsr
                tay
                lda hexnybble,y
                jsr convertascii
                sta $0400,x
                pla
                and #$0f
                tay
                lda hexnybble,y
                jsr convertascii
                sta $0401,x
                rts

convertascii:   cmp #$60
                bcc ca_ok
                sbc #$60
ca_ok:          rts

initraster:     sei
                lda #<raster
                sta $0314
                lda #>raster
                sta $0315
                lda #50                         ;Set low bits of raster
                sta $d012                       ;position
                lda $d011
                and #$7f                        ;Set high bit of raster
                sta $d011                       ;position (0)
                lda #$7f                        ;Set timer interrupt off
                sta $dc0d
                lda #$01                        ;Set raster interrupt on
                sta $d01a
                lda $dc0d                       ;Acknowledge timer interrupt
                cli
irwait:         lda maxraster
                beq irwait
                lda #$00
                sta maxraster
                rts

raster:         nop
                nop
                nop
                nop
                nop
                lda $d012
                sta raster_cmp+1
                inc $d020
                jsr $1003                       ;Play music and measure
                lda $d012                       ;rastertime it took to
                dec $d020                       ;execute
                sec
raster_cmp:     sbc #$00
                clc
                adc accraster
                sta accraster
                cmp maxraster
                bcc raster_skip
                sta maxraster
raster_skip:    dec $d019
                ldy nextraster
                bne raster_skip2
                sty accraster
                sta currraster
raster_skip2:   tya
                eor #$01
                tax
                sta nextraster
                lda rasterlinetbl,x
                sta $d012
                jmp $ea31

text:           dc.b "Example 3: Multispeed-musicroutine      "
                dc.b "Rastertime:   /                         "
                dc.b "Author:                                 "
                dc.b "                                        "
                dc.b "                                        "


hexnybble:      dc.b "0123456789ABCDEF"

maxraster:      dc.b 0
accraster:      dc.b 0
currraster:     dc.b 0
nextraster:     dc.b 0

rasterlinetbl:  dc.b 50,210

                org $1000

                incbin example3.bin