You guys are such good teachers, I wanted to do something a little more difficult.

I would like to make this workable for Win 98.


;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
;
; beeper.asm - Kernel Mode Driver for Windows NT
; 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 \masm32\include\w2k\ntstatus.inc
include \masm32\include\w2k\ntddk.inc

include \masm32\include\w2k\hal.inc

includelib \masm32\lib\w2k\hal.lib

;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
; E Q U A T E S
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

TIMER_FREQUENCY equ 1193167 ; 1,193,167 ??
OCTAVE equ 2 ; octave multiplier

PITCH_C equ 523 ; c - 523,25 ??
PITCH_Cs equ 554 ; c# - 554,37 ??
PITCH_D equ 587 ; d - 587,33 ??
PITCH_Ds equ 622 ; d# - 622,25 ??
PITCH_E equ 659 ; e - 659,25 ??
PITCH_F equ 698 ; f - 698,46 ??
PITCH_Fs equ 740 ; f# - 739,99 ??
PITCH_G equ 784 ; g - 783,99 ??
PITCH_Gs equ 831 ; g# - 830,61 ??
PITCH_A equ 880 ; a - 880,00 ??
PITCH_As equ 988 ; a# - 987,77 ??
PITCH_H equ 1047 ; h - 1046,50 ??


; We are going to play c-major chord

TONE_1 equ TIMER_FREQUENCY/(PITCH_C*OCTAVE)
TONE_2 equ TIMER_FREQUENCY/(PITCH_E*OCTAVE)
TONE_3 equ (PITCH_G*OCTAVE) ; for HalMakeBeep

DELAY equ 1800000h ; for my ~800mHz machine

;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
; M A C R O S
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

DO_DELAY MACRO
mov eax, DELAY
.while eax
dec eax
.endw
ENDM

;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
; C O D E
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

.code

;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
; MakeBeep1
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

MakeBeep1 proc dwPitch:DWORD

; Direct hardware access

cli

mov al, 10110110y
out 43h, al

mov eax, dwPitch
out 42h, al

mov al, ah
out 42h, al

; Turn speaker ON

in al, 61h
or al, 11y
out 61h, al

sti

DO_DELAY

cli

; Turn speaker OFF

in al, 61h
and al, 11111100y
out 61h, al

sti

ret

MakeBeep1 endp

;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
; MakeBeep2
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

MakeBeep2 proc dwPitch:DWORD

; Hardware access using WRITE_PORT_UCHAR ? READ_PORT_UCHAR
; functions from hal.dll

cli

invoke WRITE_PORT_UCHAR, 43h, 10110110y

mov eax, dwPitch
invoke WRITE_PORT_UCHAR, 42h, al
mov eax, dwPitch
invoke WRITE_PORT_UCHAR, 42h, ah

; Turn speaker ON

invoke READ_PORT_UCHAR, 61h
or al, 11y
invoke WRITE_PORT_UCHAR, 61h, al

sti

DO_DELAY

cli

; Turn speaker OFF

invoke READ_PORT_UCHAR, 61h
and al, 11111100y
invoke WRITE_PORT_UCHAR, 61h, al

sti

ret

MakeBeep2 endp

;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
; DriverEntry
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

DriverEntry proc pDriverObject:PDRIVER_OBJECT, pusRegistryPath:PUNICODE_STRING

invoke MakeBeep1, TONE_1
invoke MakeBeep2, TONE_2

; Hardware access using hal.dll HalMakeBeep function

invoke HalMakeBeep, TONE_3
DO_DELAY
invoke HalMakeBeep, 0

mov eax, STATUS_DEVICE_CONFIGURATION_ERROR
ret

DriverEntry endp

;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
;
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

end DriverEntry

:make

set drv=beeper

\masm32\bin\ml /nologo /c /coff %drv%.bat
\masm32\bin\link /nologo /driver /base:0x10000 /align:32 /out:%drv%.sys /subsystem:native %drv%.obj

del %drv%.obj

echo.
pause
Posted on 2004-02-19 18:39:10 by skywalker
Well, you can lookup Yates' tutorials. What you are looking for is VXD coding... and Yates' has some really nice examples. I think beep is one of them.
Posted on 2004-02-19 18:50:54 by Milos
you can beep the pc speaker on a nt based system using the Beep api call, but you might still want to write the KDM just for the experience.
Posted on 2004-02-19 20:04:43 by ENF

Well, you can lookup Yates' tutorials. What you are looking for is VXD coding... and Yates' has some really nice examples. I think beep is one of them.


Thanks,
Found the tuturials, it'l' be a while till I can use it.
Posted on 2004-02-19 20:37:22 by skywalker