-
Notifications
You must be signed in to change notification settings - Fork 0
/
vgm.s
127 lines (102 loc) · 2.24 KB
/
vgm.s
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
.include "include/hardware.i"
| these are the header structure offsets
.equ MAGIC_O, 0
.equ EOF_O, 0x04
.equ VERSION_O, 0x08
.equ DATA_OFFSET_O, 0x34
.equ YM3812_CLOCK_O, 0x50
.global vgmplayer
.global vgmstop
.global opl2noteplay
.section .text
.align 2
| play the vgm block pointed to by a6
vgmplayer: move.l MAGIC_O(%a6),%d0
movea.l #magicmsg,%a1
bsr labelprintlong
move.l EOF_O(%a6),%d0
bsr longswap
movea.l #eofmsg,%a1
bsr labelprintlong
move.l VERSION_O(%a6),%d0
bsr longswap
movea.l #versionmsg,%a1
bsr labelprintlong
move.l YM3812_CLOCK_O(%a6),%d0
bsr longswap
movea.l #ym3812clockmsg,%a1
bsr labelprintlong
move.l DATA_OFFSET_O(%a6),%d0
bsr longswap
add.l #DATA_OFFSET_O,%d0
move.l %a6,%d1
add.l %d1,%d0
move.l %d0,pointer
movea.l #vgmdatamsg,%a1
bsr labelprintlong
move.w #1,running
clr.w countdown
bsr timerinit
rts
vgmstop: clr running
bsr timeruninit
rts
.section .rodata
.align 2
magicmsg: .asciz "Magic: "
eofmsg: .asciz "EOF: "
versionmsg: .asciz "Version: "
ym3812clockmsg: .asciz "YM3812 Clock Hz: "
vgmdatamsg: .asciz "VGM data starts at: "
.section .text
.align 2
| INTERRUPT
opl2noteplay: tst.w running
bne 1f
rts
1: movem.l %d0/%a0,-(%sp)
move.w countdown,%d0
beq 2f | not counting down?
subq.w #1,%d0 | yes, count down
move.w %d0,countdown | store for next time
bra out2 | finished
2: move.l pointer,%a0
again: move.b (%a0)+,%d0
cmpi.b #0x5a,%d0
beq ym3812
cmpi.b #0x61,%d0
beq countn
cmpi.b #0x62,%d0
beq count735
cmpi.b #0x63,%d0
beq count882
cmpi.b #0,%d0
beq done
out1: move.l %a0,pointer
out2: movem.l (%sp)+,%d0/%a0
rts
ym3812: move.b (%a0)+,OPL2REGADDR
move.w #0x20,%d0
1: dbra %d0,1b
move.b (%a0)+,OPL2DATA
move.w #0x20,%d0
2: dbra %d0,2b
bra again
countn: move.b (%a0)+,%d0 | bottom half
lsl.w #8,%d0 | move up
move.b (%a0)+,%d0 | top half
ror.w #8,%d0 | byteswap
lsr.w #4,%d0 | scale by 16
move.w %d0,countdown | save countdown value
bra out1
count735: move.w #735,countdown
bra out1
count882: move.w #882,countdown
bra out1
done: clr.w running | stop playback
bra out1
.section .bss
.align 2
running: .space 2
pointer: .space 4
countdown: .space 2