📄 speaker.asm
字号:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Snixos Project version 1.0, 2003.6; (C) Copyright 2003,2004,2005 Jockeyson,KeqiangGao <Snallie@tom.com>; All Rights Reserved.; Distributed under the terms of the GNU General Public License.;; This program is a free and open source software and you can redistribute ; it and/or modify it under the terms of the GNU General Public License as; published by the Free Software Foundation. As no any liability is assumed ; for any incidental or consequential damages in connection with the ; information or program fragments contained herein,so any exception arised; is at your own risk. It is ABSOLUTELY WITHOUT ANY WARRANTY.; Bug report please send to Snallie@tom.com .;;; speaker.asm : PC speaker driver for Snixos Project ; Author : snallie@tom.com; Time : 2003.6;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;bits 32global beep,beep2 extern delayMS, printf ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; startSound; Attaches the pc speaker to the timer, starting a sound; prototype: void startSound( int freq);; args: Push the frequency on stack;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;%ifdef DEBUGfmstr db "h %d l %d",10,0fm2 db "freq=%d",10,0%endifstartSound: ; Load timer 2 with a new countdown value push ebp mov ebp,esp%ifdef DEBUG push dword [ebp+8] push dword fm2 call printf add esp,8%endif push eax push ebx push edx ; Calculate the countdown value for the frequency mov ebx, [ebp+8] ; Save the frequency xor eax,eax mov dx,12h mov ax,0x34dc div bx ; Calculate the countdown mov bx, ax ; save ax%ifdef DEBUG and ax, 0x0fF push eax ; bit 0~7 mov ax, bx xchg ah,al and ax, 0x0fF push eax ;bit 8~15 push dword fmstr call printf add esp,12%endif ; Tell the timer we're changing the countdown mov al, 0x0B6 out 0x43, al ; Change the countdown mov ax, bx and ax, 0x0ff out 0x42,al ; bit 0~7 mov ax, bx xchg ah,al and ax, 0x0ff out 0x42, al ;bit 8~15 ; Attach the timer to the speaker in al, 0x61 or al, 3 out 0x61, al ; The speaker should now be producing your selected annoying tone pop edx pop ebx pop eax leave ret ; End of startSound ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; stopSound; Detaches the speaker from the system timer, stopping the sound;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;stopSound: push ebp mov ebp,esp push eax in al, 0x61 and al, 0xfc out 0x61, al pop eax leave ret; End of stopSound;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; beep ; Beeps the pc speaker for a certain amount of timer; args : Push the amount of ms to beep onto the stack; C prototype: void beep(int duration); to call in C: asm("pushl $1000\t\n" "call beep\t\n" "add $4,%esp\n"); ; or beep(int duration);;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;beep: push ebp mov ebp,esp push dword 1000 ; 1000hz call startSound add esp,4 push dword [ebp+8] call delayMS ; Delay for eax ms add esp,4 call stopSound leave ret ; End of beep;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; beep2 ;; C prototype: void beep2(int duration_MS,int freq);; Beeps the pc speaker with the specified frequency and ; duration in ms. ; args : duration_MS, how long the speaker will beep , freq is ; the frequency for speaker. ; to call in C: beep2(1000,300) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;beep2: push ebp mov ebp,esp push dword [ebp+12] ; frequency call startSound add esp,4 push dword [ebp+8] ; duration call delayMS ; Delay ms add esp,4 call stopSound leave ret ; End of beep
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -