-
Notifications
You must be signed in to change notification settings - Fork 0
/
Internationale.asm
228 lines (212 loc) · 4.81 KB
/
Internationale.asm
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
STACK SEGMENT
DW 200 DUP(?)
STACK ENDS
DATA SEGMENT
OPENSTR DB 'NOW PLAYING: '
TITLESTR DB 'Internationale$'
;音名 (B大调)
d0 EQU 131
e0 EQU 147
f0 EQU 165
g0 EQU 175
a0 EQU 196
b0 EQU 220
c1 EQU 233
d1 EQU 262
e1 EQU 294
f1 EQU 311
g1 EQU 349
a1 EQU 392
b1 EQU 440
c2 EQU 466
d2 EQU 523
e2 EQU 587
f2 EQU 622
g2 EQU 698
a2 EQU 784
b2 EQU 880
s1 EQU 1 ;休止符
;频率(每节换一行)
FREQ DW g1
DW c2, b1, d2, c2, g1, e1
DW a1, f1, s1, a1
DW d2, c2, b1, a1, g1, f1
DW e1, g1
DW c2, b1, d2, c2, g1, e1
DW a1, f1, a1, d2, c2
DW b1, d2, f2, b1
DW c2, c2, s1, e2, d2
DW b1, a1, b1, c2, a1
DW b1, g1, g1, f1, g1
DW a1, a1, d2, c2
DW b1, b1, s1, d2
DW d2, b1, g1, g1, f1, g1
DW e2, c2, a1, b1, c2
DW b1, d2, c2, c2, a1
DW g1, g1, s1, e2, d2
DW c2, g1, e1
DW a1, f1, s1, d2, c2
DW b1, a1, g1
DW g1, g1, s1, g1
DW e2, d2, g1
DW c2, b1, b1
DW a1, g1, a1, d2
DW d2, d2, s1, e2, d2
DW c2, g1, e1
DW a1, f1, s1, d2, c2
DW b1, a1, g1
DW e2, e2
DW g2, f2, e2
DW d2, e2, f2, s1, f2
DW e2, e2, d2, d2
DW c2, s1
DW 0
;节拍(设4分音符1拍100ms)
QUATERBEAT EQU 12 ;四分音符
OCTABEAT EQU QUATERBEAT/2 ;八分音符
DICHOTOMOUSBEAT EQU QUATERBEAT*2 ;二分音符
TIME DW QUATERBEAT
DW QUATERBEAT + OCTABEAT, OCTABEAT, OCTABEAT, OCTABEAT, OCTABEAT, OCTABEAT
DW DICHOTOMOUSBEAT, QUATERBEAT, OCTABEAT, OCTABEAT
DW QUATERBEAT + OCTABEAT, OCTABEAT, OCTABEAT, OCTABEAT, OCTABEAT, OCTABEAT
DW QUATERBEAT * 3, QUATERBEAT
DW QUATERBEAT + OCTABEAT, OCTABEAT, OCTABEAT, OCTABEAT, OCTABEAT, OCTABEAT
DW QUATERBEAT * 2, OCTABEAT, OCTABEAT, OCTABEAT, OCTABEAT
DW QUATERBEAT, QUATERBEAT, QUATERBEAT, QUATERBEAT
DW QUATERBEAT * 2, OCTABEAT, OCTABEAT, OCTABEAT, OCTABEAT
DW QUATERBEAT * 2, OCTABEAT, OCTABEAT, OCTABEAT, OCTABEAT
DW QUATERBEAT * 2, OCTABEAT, OCTABEAT, OCTABEAT, OCTABEAT
DW QUATERBEAT + OCTABEAT, OCTABEAT, QUATERBEAT + OCTABEAT, OCTABEAT
DW QUATERBEAT + OCTABEAT, OCTABEAT, OCTABEAT, QUATERBEAT
DW QUATERBEAT + OCTABEAT, OCTABEAT, OCTABEAT, OCTABEAT, OCTABEAT, OCTABEAT
DW QUATERBEAT * 2, OCTABEAT, OCTABEAT, OCTABEAT, OCTABEAT
DW QUATERBEAT, QUATERBEAT, OCTABEAT + OCTABEAT/2, OCTABEAT/2, QUATERBEAT
DW QUATERBEAT * 2, OCTABEAT, OCTABEAT, OCTABEAT + OCTABEAT/2, OCTABEAT/2
DW QUATERBEAT * 2, QUATERBEAT + OCTABEAT, OCTABEAT
DW QUATERBEAT * 2, OCTABEAT, OCTABEAT, OCTABEAT + OCTABEAT/2, OCTABEAT/2
DW QUATERBEAT * 2, QUATERBEAT, QUATERBEAT
DW QUATERBEAT * 2, OCTABEAT, OCTABEAT, QUATERBEAT
DW QUATERBEAT * 2, QUATERBEAT, QUATERBEAT
DW QUATERBEAT * 2, QUATERBEAT + OCTABEAT, OCTABEAT
DW QUATERBEAT + OCTABEAT, OCTABEAT, QUATERBEAT, QUATERBEAT
DW QUATERBEAT * 2, OCTABEAT, OCTABEAT, OCTABEAT + OCTABEAT/2, OCTABEAT/2
DW QUATERBEAT * 2, QUATERBEAT + OCTABEAT, OCTABEAT
DW QUATERBEAT * 2, OCTABEAT, OCTABEAT, OCTABEAT + OCTABEAT/2, OCTABEAT/2
DW QUATERBEAT * 2, QUATERBEAT, QUATERBEAT
DW QUATERBEAT * 3, QUATERBEAT
DW QUATERBEAT * 2, QUATERBEAT, QUATERBEAT
DW QUATERBEAT + OCTABEAT, OCTABEAT, QUATERBEAT, OCTABEAT, OCTABEAT
DW QUATERBEAT + OCTABEAT, OCTABEAT, QUATERBEAT + OCTABEAT, OCTABEAT
DW QUATERBEAT * 3, QUATERBEAT
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE, SS:STACK, DS:DATA
SING PROC ;从数据段取出每个音符的频率数据和节拍时间数据
;供SOUND子程序发声
PUSH DI
PUSH SI
PUSH BP
PUSH BX
REPT:
MOV DI, DS:[SI]
CMP DI, 0
JZ ENDSING ;是否读到结束标志
MOV BX, DS:[BP]
CALL SOUND
ADD SI, 2
ADD BP, 2
JMP REPT
ENDSING:
POP BX
POP BP
POP SI
POP DI
RET
SING ENDP
SOUND PROC
PUSH AX
PUSH BX ;节拍时间
PUSH CX
PUSH DX
PUSH DI ;入口参数DI给定频率数据
CMP DI, 1 ;是否为休止符
JZ STDEL
MOV AL, 0B6H ;8253初始化(通道2,方波信号)
OUT 43H, AL
MOV DX, 12H
MOV AX, 34DCH ;计算时间常数
DIV DI
OUT 42H, AL ;设置时间常数
MOV AL, AH
OUT 42H, AL
IN AL, 61H
MOV AH, AL
OR AL, 3 ;开喇叭,8255I/0端口61H的低两位置
OUT 61H, AL
DL10ms:
CALL DELAY
DEC BX
JNZ DL10ms
MOV AL, AH
OUT 61H, AL ;关喇叭
POP DI
POP DX
POP CX
POP BX
POP AX
RET
STDEL:
CALL DELAY
DEC BX
JNZ STDEL
POP DI
POP DX
POP CX
POP BX
POP AX
RET
SOUND ENDP
DELAY PROC
PUSH AX
PUSH BX
PUSH CX
PUSH DX
MOV AH, 2CH
INT 21H
MOV BX, DX ; 现在的时间:秒.百分秒
MOV AH, 2CH
CMP BH, 00H
JNZ CHECK
CHECK: ;取当前时间进行判断
INT 21H
CMP DH, 0
JNZ NOEXP
ZJUDGE: ;现在时间为0秒不需要+60S判断
CMP BH, 0
JZ NOEXP
ADD DH, 60H ;59秒到0秒时的判断
NOEXP:
SUB DX, BX ; 时差
CMP DX, 0001H ;精度为1百分秒
JBE CHECK
POP DX
POP CX
POP BX
POP AX
RET
DELAY ENDP
START:
MOV AX, DATA
MOV DS, AX
MOV AX, STACK
MOV SS, AX
MOV AH, 09H
LEA DX, OPENSTR
INT 21H
LEA SI, FREQ
LEA BP, TIME
CALL SING
MOV AH, 4CH
INT 21H
CODE ENDS
END START