Added 10 more gists.

This commit is contained in:
Miguel Astor
2023-06-19 09:38:01 -04:00
parent 8af706e97d
commit 1400a87eab
25 changed files with 1133 additions and 0 deletions

1
TONES.ASM/README.md Normal file
View File

@@ -0,0 +1 @@
DOS (tasm) program that sets a custom handler for interrupt 9h to play a tone on every key press.

59
TONES.ASM/TONES.ASM Normal file
View File

@@ -0,0 +1,59 @@
.model tiny
.386
.code
org 100h
start:
;; Save old interrupt handler
mov ax, 3509h ; DOS function: get address of INT 9h handler
int 21h ; Call DOS
mov [i9_or], bx ; Offset
mov [i9_or + 2], es ; Segment
;; Set new interrupt handler
cli ; Disable interruptions
lea dx, interr ; Load address of custom handler
mov ax, 2509h ; DOS function: replace handler for INT 9h
int 21h ; Call DOS
sti ; Re-enable interruptions
;; End program, TSR style
mov ax, 3100h ; DOS function: Terminate and stay resident
mov dx, 00ffh ; Keep 255 bytes resident
int 21h ; Call DOS
i9_or dw ?, ? ; Here we save the DOS INT 9h handler
interr proc far
sti ; Re-enable interruptions
;; Initialize the speaker
in al, 61h ; Get speaker status word
push ax ; Save status word
or al, 00000011b ; Turn speaker on
out 61h, al ; Send new status word to speaker
mov al, 60 ; Set initial tone
;; Play a tone on the speaker
L2: out 42h, al ; Send tone to timer chip
mov cx, 100 ; Set outer counter
L3: push cx ; Save inner counter
mov cx, 0D00h ; Set inner counter
L3a: loop L3a ; Loop until inner counter is 0
pop cx ; Restore outer counter
loop L3 ; Loop until outer counter is 0
sub al, 1 ; Change tone
jnz L2 ; Repeat until tone is 0
;; Disable speaker
pop ax ; Restore original speaker status word
and al, 11111100b ; Turn speaker off
out 61h, al ; Send status word to speaker
;; Jump to the original keyboard handler
;; The next two instructions set the return address on the stack
push word ptr [cs:i9_or + 2]
push word ptr [cs:i9_or]
retf ; Return from this procedure
interr endp
end start