Advertisement
Guest User

pro

a guest
Jan 22nd, 2017
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.12 KB | None | 0 0
  1. DosIntr equ 21h
  2. RetToDos equ 4ch
  3. Ok equ 0h
  4. F_C equ 34828 ; (1193000/131Hz)
  5. F_D equ 31028
  6. F_E equ 27643
  7. F_F equ 26091
  8. F_G equ 23245
  9. F_A equ 20709
  10. F_H equ 18449
  11.  
  12. F_Y equ 32873 ;cis
  13. F_I equ 29287 ;dis
  14. F_O equ 26926 ;eis
  15. F_J equ 24627 ;fis
  16. F_K equ 21940 ;gis
  17. F_L equ 19857 ;ais
  18.  
  19. ;---------------------------------------------------------------
  20. Progr segment
  21. assume cs:Progr, ds:dane, ss:stosik
  22.  
  23. ;---------------------------------------------------------------
  24. DisplayText MACRO TextAddress
  25. lea dx,TextAddress
  26. mov ah,09h
  27. int 21h
  28. ENDM
  29. ;---------------------------------------------------------------
  30. FixFileName MACRO
  31. mov bx,80h
  32. mov dl,es:[bx]
  33.  
  34. xor bh,bh
  35. mov bl,dl
  36. mov byte ptr es:[bx+81h],0
  37. ENDM
  38. ;---------------------------------------------------------------
  39. OpenFile MACRO
  40. mov cx, ds
  41. mov bx, es
  42. mov ds, bx
  43.  
  44. mov dx,82h
  45. mov ah,3Dh
  46. mov al,0
  47. int 21h
  48.  
  49. mov ds,cx
  50. mov FILE_HOLDER,ax
  51. ENDM
  52. ;---------------------------------------------------------------
  53. CloseFile MACRO
  54. mov ah,03Eh
  55. mov bx,FILE_HOLDER
  56. int 21h
  57. ENDM
  58. ;---------------------------------------------------------------
  59. ReadFile MACRO
  60. mov bx,FILE_HOLDER
  61. mov cx,0
  62. mov dx,0
  63. mov ax,4202h
  64. int 21h
  65.  
  66. mov FILE_LENGTH,ax
  67.  
  68. mov cx,0
  69. mov dx,0
  70. mov ax,4200h
  71. int 21h
  72.  
  73. mov dx,offset TAB_NOTES
  74. mov cx,FILE_LENGTH
  75. mov ah,3Fh
  76. int 21h
  77. ENDM
  78. ;---------------------------------------------------------------
  79. InitTimer MACRO
  80. mov al,10110110b
  81. out 43h,al
  82. ENDM
  83. ;---------------------------------------------------------------
  84. SpeakerOn MACRO
  85. in al,61h
  86. or al,00000011b
  87. out 61h,al
  88. ENDM
  89. ;---------------------------------------------------------------
  90. SpeakerOff MACRO
  91. in al,61h
  92. and al,11111100b
  93. out 61h,al
  94. ENDM
  95. ;---------------------------------------------------------------
  96. CalculateFreq MACRO sound, octave
  97. push dx
  98. push cx
  99.  
  100. cmp sound,'C'
  101. jz note_c
  102.  
  103. cmp sound,'D'
  104. jz note_d
  105.  
  106. cmp sound,'E'
  107. jz note_e
  108.  
  109. cmp sound,'F'
  110. jz note_f
  111.  
  112. cmp sound,'G'
  113. jz note_g
  114.  
  115. cmp sound,'H'
  116. jz note_h
  117.  
  118. cmp sound,'A'
  119. jz note_a
  120.  
  121. cmp sound,'P'
  122. jz note_pause
  123.  
  124. jmp cf_finish
  125.  
  126. note_c: mov dx,F_C
  127. jmp set_octave
  128.  
  129. note_d: mov dx,F_D
  130. jmp set_octave
  131.  
  132. note_e: mov dx,F_E
  133. jmp set_octave
  134.  
  135. note_f: mov dx,F_F
  136. jmp set_octave
  137.  
  138. note_g: mov dx,F_G
  139. jmp set_octave
  140.  
  141. note_h: mov dx,F_H
  142. jmp set_octave
  143.  
  144. note_a: mov dx,F_A
  145. jmp set_octave
  146.  
  147. note_Y: mov dx,F_Y
  148. jmp set_octave
  149.  
  150. note_I: mov dx,F_I
  151. jmp set_octave
  152.  
  153. note_O:
  154. mov dx,F_O
  155. jmp set_octave
  156.  
  157. note_J: mov dx,F_J
  158. jmp set_octave
  159.  
  160. note_K: mov dx,F_K
  161. jmp set_octave
  162.  
  163. note_L: mov dx,F_L
  164. jmp set_octave
  165.  
  166. note_pause: SpeakerOff
  167. mov PAUSED,1
  168. jmp cf_finish
  169.  
  170. set_octave: sub octave,30h
  171. mov cl,octave
  172. shr dx,cl
  173. mov FREQUENCY,dx
  174.  
  175. cmp PAUSED,1
  176. jnz cf_finish
  177. SpeakerOn
  178. mov PAUSED,0
  179.  
  180. cf_finish: pop cx
  181. pop dx
  182. ENDM
  183. ;---------------------------------------------------------------
  184. SetFrequency MACRO freq
  185. push ax
  186. mov ax,freq
  187. out 42h,al
  188. mov al,ah
  189. out 42h,al
  190. pop ax
  191. ENDM
  192. ;---------------------------------------------------------------
  193. Delay MACRO msb, lsb ;mikrosekundy na jakie ma zatrzymać się program
  194. mov dx,lsb
  195. mov cx,msb
  196. mov al,0
  197. mov ah,86h
  198. int 15h
  199. ENDM
  200. ;---------------------------------------------------------------
  201. DelayByTone MACRO tone
  202. push dx
  203. push cx
  204. push ax
  205.  
  206. CMP tone,'1'
  207. JZ whole_tone
  208. CMP tone,'2'
  209. JZ half_tone
  210. CMP tone,'4'
  211. JZ quarter_tone
  212. CMP tone,'8'
  213. JZ quaver_tone
  214.  
  215. JMP error_tone
  216.  
  217. whole_tone: Delay 8,0
  218. JMP dbtf
  219.  
  220. half_tone: Delay 4,0
  221. JMP dbtf
  222.  
  223. quarter_tone: Delay 2,0
  224. JMP dbtf
  225.  
  226. quaver_tone: Delay 1,0
  227. JMP dbtf
  228.  
  229. error_tone: Delay 1,0
  230.  
  231. dbtf: pop ax
  232. pop cx
  233. pop dx
  234. ENDM
  235. ;---------------------------------------------------------------
  236. start: mov ax,dane
  237. mov ds,ax
  238. mov ax,stosik
  239. mov ss,ax
  240. mov sp,offset szczyt
  241.  
  242. FixFileName
  243. OpenFile
  244.  
  245. JNC no_error ;sprawdzenie czy udało się otworzyć plik
  246. jmp of_error
  247. no_error:
  248.  
  249. ReadFile
  250. CloseFile
  251.  
  252. mov ax,FILE_LENGTH
  253. mov cl,3
  254. div cl
  255. mov FILE_JUMP, ax
  256.  
  257. InitTimer
  258. SpeakerOn
  259.  
  260. mov cx,FILE_JUMP
  261. mov bx,0
  262.  
  263. play_music: mov bx,SONG_POINTER
  264. mov ah,TAB_NOTES[bx]
  265.  
  266. add bx,FILE_JUMP
  267. mov al,TAB_NOTES[bx]
  268.  
  269. CalculateFreq ah,al
  270. SetFrequency FREQUENCY
  271.  
  272. add bx,FILE_JUMP
  273. mov al,TAB_NOTES[bx]
  274.  
  275. DelayByTone al
  276.  
  277. inc SONG_POINTER
  278.  
  279. dec cx
  280. cmp cx,0
  281. jz end_music
  282. jmp play_music
  283.  
  284. end_music: SpeakerOff
  285. jmp finish
  286.  
  287. of_error: DisplayText TEXT_FILE_ERROR
  288.  
  289. finish: mov ah,RetToDos
  290. mov al,Ok
  291. int DosIntr
  292. Progr ends
  293. ;---------------------------------------------------------------
  294. dane segment
  295. TEXT_FILE_ERROR db "Nie udalo sie otworzyc pliku.",10,13,"$"
  296. ;inne
  297. FILE_HOLDER dw ?
  298. SONG_POINTER dw 0
  299. FREQUENCY dw ?
  300. PAUSED db 0
  301. ;tablice nut
  302. FILE_LENGTH dw ?
  303. FILE_JUMP dw ?
  304. TAB_NOTES db 900 dup(0)
  305. dane ends
  306.  
  307. stosik segment
  308. dw 100h dup(0)
  309. szczyt Label word
  310. stosik ends
  311.  
  312. end start
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement