]> wirehaze git hosting - MS-DOS.git/blob - v4.0/src/MAPPER/BEEP.ASM

wirehaze git hosting

MZ is back!
[MS-DOS.git] / v4.0 / src / MAPPER / BEEP.ASM
1 page 80,132
2
3 title CP/DOS DosBeep mapper
4
5 dosxxx segment byte public 'dos'
6 assume cs:dosxxx,ds:nothing,es:nothing,ss:nothing
7
8 ;**********************************************************************
9 ;*
10 ;* MODULE: dosbeep
11 ;*
12 ;* FUNCTION: generate a tone with desired frequency and duration
13 ;*
14 ;* CALLING SEQUENCE:
15 ;*
16 ;* push word frequency
17 ;* push word duration (in milliseconds)
18 ;* call dosbeep
19 ;*
20 ;* MODULES CALLED: none
21 ;*
22 ;*********************************************************************
23
24 public dosbeep
25 .sall
26 include macros.inc
27
28 inv_parm equ 0002h ;invalid parameter return code
29
30 str struc
31 old_bp dw ?
32 return dd ?
33 duratn dw ? ; duration
34 frqncy dw ? ; frequency
35 str ends
36
37 dosbeep proc far
38 Enter DosBeep
39
40 mov al,10110110b ; Set 8253 chip channel 2
41 out 43h,al ; to proper mode for tone
42
43 ; Channel 2 is now set up as a frequency divider. The sixteen bit
44 ; value sent to that port (in low-high format) is divided into
45 ; 1.19 MHz, the clock speed. In order to send the proper value
46 ; to the register, then, the frequency requested must be divided
47 ; into 1,190,000.
48
49 mov dx,012h ; MSB of 1.19M
50 mov ax,2970h ; LSB of 1.19M
51 mov cx,[bp].frqncy ; divisor
52 mov bx,025h ; check frequency range
53 cmp cx,bx ; frequency ok ??
54 jl error ; branch if error
55
56 mov bx,7fffh
57 cmp cx,bx
58 jg error
59 div cx ; then divide
60
61 out 42h,al ; and output
62 mov al,ah ; directly to
63 out 42h,al ; the 8253 port.
64
65 ; Turn on speaker
66
67 in al,61h ; Save original value
68 mov ah,al ; in ah
69 or al,3 ; Turn on control bit
70 out 61h,al ; in 8255 chip
71
72 ; Now loop for DURATN milliseconds
73
74 mov cx,[bp].duratn ; load value
75 delay: mov bx,196 ; inner loop count
76 del2: dec bx ; a millisecond
77 jne del2 ; for each
78 loop delay ; iteration
79
80 ; Turn speaker off
81
82 mov al,ah ; replace
83 out 61h,al ; original value
84
85 sub ax,ax ; set no error code
86 jmp exit ; return
87
88 error: mov ax,inv_parm
89
90 exit: MExit ; pop registers
91 ret size str - 6 ; return
92
93 dosbeep endp
94
95 dosxxx ends
96
97 end