Terminal control/Ringing the terminal bell: Difference between revisions

m
(Added solution for Action!)
Line 39:
.en</lang>
=={{header|8086 Assembly}}==
This is a software version of the terminal bell (printing the BEL ascii code (7) to stdout on DOSBox doesn't make any sound). Code is called as a subroutine, i.e. <code>MOV AL,7 CALL PRINTCHAR</code>.
This is for MS-DOS
<lang asm>movPrintChar: ;Print ah,02hAL to screen
push cx
mov dl,07h
push bx
int 21h</lang>
push ax
cmp al,7
jne skipBEL
call RingBell
jmp done_PrintChar
skipBEL:
mov bl,15 ;text color will be white
mov ah,0Eh
int 10h ;prints ascii code stored in AL to the screen
done_PrintChar:
pop ax
pop bx
pop cx
ret
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
RingBell:
push ax
push cx
push dx
;if BEL is the argument passed to PrintChar, it will call this function and not actually print anything or advance the cursor
;this uses the built-in beeper to simulate a beep
 
mov al,10110110b ;select counter 2, 16-bit mode
out 43h, al
mov ax,0C00h ;set pitch of beep - this is somewhat high but isn't too annoying. Feel free to adjust this value
out 42h,al
mov dlal,07hah
out 42h,al
 
 
mov al,3
out 61h,al ;enable sound and timer mode
 
mov cx,0FFFFh
mov dx,0Fh ;set up loop counters
beepdelay: ;delay lasts about half a second
loop beepdelay
mov cx,0FFFFh
dec dx
jnz beepdelay
mov al,0 ;mute
out 61h,al ;cut the sound
 
; mov bl,15
; mov ax,0E20h ;print a spacebar to the terminal
; int 10h ;uncomment these 3 lines if you want the BEL to "take up space" in the output stream
pop dx
pop cx
pop ax
int 21h ret</lang>
 
=={{header|Action!}}==
1,489

edits