.386
.model flat, stdcall
option casemap:none
include test.inc
.code
DriverEntry proc pDriverObject:PDRIVER_OBJECT,pusRegistryPath:PUNICODE_STRING
invoke DbgPrint, $CTA0("Hello world! ")mov eax,STATUS_DEVICE_CONFIGURATION_ERROR
ret
DriverEntry endp
end DriverEntry
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
; beeper - Kernel Mode Drive
; Makes beep thorough computer speaker
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
.386
.model flat, stdcall
option casemap:none
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
; I N C L U D E F I L E S
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
include w2k\ntstatus.inc
include w2k\ntddk.inc
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
; E Q U A T E S
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
TIMER_FREQUENCY equ 1193167 ; 1,193,167 Hz
OCTAVE equ 2 ; octave multiplier
PITCH_C equ 523 ; C - 523,25 Hz
PITCH_Cs equ 554 ; C# - 554,37 Hz
PITCH_D equ 587 ; D - 587,33 Hz
PITCH_Ds equ 622 ; D# - 622,25 Hz
PITCH_E equ 659 ; E - 659,25 Hz
PITCH_F equ 698 ; F - 698,46 Hz
PITCH_Fs equ 740 ; F# - 739,99 Hz
PITCH_G equ 784 ; G - 783,99 Hz
PITCH_Gs equ 831 ; G# - 830,61 Hz
PITCH_A equ 880 ; A - 880,00 Hz
PITCH_As equ 988 ; B - 987,77 Hz
PITCH_H equ 1047 ; H - 1046,50 Hz
; We are going to play c-major chord
TONE_C equ TIMER_FREQUENCY/(PITCH_C*OCTAVE)
TONE_E equ TIMER_FREQUENCY/(PITCH_E*OCTAVE)
DELAY equ 1800000h ; for my ~800mHz box
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
; M A C R O S
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
DO_DELAY MACRO
mov eax, DELAY
.while eax
dec eax
.endw
ENDM
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
; C O D E
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
.code
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
; MakeBeep
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
MakeBeep proc dwPitch:DWORD
; Direct hardware access
;设置定时器的控制寄存器
cli
mov al, 10110110y
out 43h, al
;操作将初始值的低位字节和高位字节送到42h端口
mov eax, dwPitch
out 42h, al
mov al, ah
out 42h, al
; 打开扬声器
in al, 61h
or al, 11y
out 61h, al
sti
DO_DELAY
cli
; 关闭扬声器
in al, 61h
and al, 11111100y
out 61h, al
sti
ret
MakeBeep endp
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
; DriverEntry
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
DriverEntry proc pDriverObject:PDRIVER_OBJECT, pusRegistryPath:PUNICODE_STRING
invoke MakeBeep, TONE_C
DO_DELAY
invoke MakeBeep, TONE_E
mov eax, STATUS_DEVICE_CONFIGURATION_ERROR
ret
DriverEntry endp
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
end DriverEntry