Re: pc speaker in asm



On Feb 7, 1:48 am, Frank Kotler <fbkot...@xxxxxxxxxxx> wrote:
bushido wrote:
I had search in google , not found
plese help

For dos, I'm guessing? You probably want to obtain "Ralf Brown's
Interrupt List" (google will find that), if you haven't. Besides the
eponymous "interrup.lst", there are lots of other goodies - "ports.lst"
would be what you'd want for more information on this...

Here's a Nasm example that "used to work". Should still work in "real
dos". No guarantees in a modern "dos box"... worked in win98, IIRC,
doesn't work (no sound) in dosemu (I have a Linux version, too)... If
this isn't what you're looking for, tell us more about what you're doing.

(simplest way to beep the speaker is to print ascii character 7, if
that's all you want)

Best,
Frank

; Plays a tune, of sorts - sound, anyway.
; It is said that I'm not artistic.
;
; nasm -f bin -o play.com play.asm
;
; or add proprietary junk as required

org 100h ; we are a .com file
; (nasm defaults to "section .text")

; set up PIT
mov al, 10111110b
;.......|------ binary 16-bit counter
;....|||------- square wave generator
;..||---------- r/w bits 0-7, then 8-15
;||------------ select counter 2
out 43h, al

mov si, melody ; "offset" - if p.j.

playit_sam: ; if she can take it, so can I.
in al, 61h ; enable speaker
or al, 00000011b
;.......|------- enable speaker on timer 2 gate
;......|-------- enable speaker data
out 61h, al

lodsw ; get a note
or ax, ax ; check for zero
jz egress ; coda

out 42h, al ; play it
mov al, ah
out 42h ,al

lodsw ; for this long
call delay

in al, 61h ; Turn Speaker OFF
and al, 11111100b
out 61h, al

lodsw ; for this long
call delay

jmp short playit_sam ; play more

egress:
in al, 61h
and al, 0FCh ; Turn Speaker OFF. Please.
out 61h, al

ret
;------------------

;------------------
delay:
mov cx, ax ; this trashes ax, cx, dx, too :)
cmp cx, byte 1 ; special case, no delay
jz no_delay

shr cx, 3 ; because it sounds okay :)
xor dx, dx

mov ah, 86h ; bios delay - cx:dx microseconds
int 15h
no_delay:
ret
;------------------

; Some equates, for your compositional assistance
; It is said that I'm not artistic.

A0 equ 21728
B0 equ 19328
C0 equ 18244
D0 equ 16144
E0 equ 14080
F0 equ 13668
G0 equ 12176
A1 equ 10864
B1 equ 9664
C1 equ 9122
D1 equ 8072
E1 equ 7040
F1 equ 6834
G1 equ 6088
A2 equ 5432
B2 equ 4832
C2 equ 4561
D2 equ 4063
E2 equ 3520
F2 equ 3417
G2 equ 3044
A3 equ 2712
B3 equ 2416
C3 equ 2280
D3 equ 2032
E3 equ 1810
F3 equ 1708
G3 equ 1522
A4 equ 1356
B4 equ 1208
C4 equ 1140
D4 equ 1016
E4 equ 905
F4 equ 854
G4 equ 762
A5 equ 678
B5 equ 604
C5 equ 558

; Some "durations"
Z equ 1
S equ 10
Q equ 20
P equ 40
R equ 80
L equ 320

; The opus itself.
;
; It is said that I'm not artistic.
;
; Format is "note", "duration", "pause", "note", ... , 0
; Write your own!

melody:
%if 1
dw G2, P, Z, E2, Q, Z, G2, Q, Q, G1, Q, Q
dw G1, Q, Q, C2, Q, Q, B2, Q, Z, C2, Q, Z
dw D2, Q, Q, G2, Q, Q, A3, Q, Z, G2, Q, Z
dw A3, Q, Q, A2, Q, Q, A2, Q, Q, G2, Q, Q
dw E2, Q, Z, G2, Q, Z, F2, Q, Z
dw E2, Q, Z, D2, Q, Q, F2, Q, Z, G2, Q, Z
dw A3, Q, Z, G2, Q, Z, F2, Q, Z, E2, Q, Z
dw F2, Q, Z, E2, Q, Z, D2, Q, Z, B2, Q, Z
dw C2, Q, Z, D2, Q, Z, E2, Q, Z, C2, Q, Z
dw D2, Q, Q, G3, Q, Z, F3, Q, Z, E3, Q, Z
dw D3, Q, Z, C3, Q, Z, B3, Q, Z, A3, Q, Z
dw B3, Q, Z, C3, Q, Z, D3, Q, Z, B3, Q, Q
dw G0, Q, Q, G0, R, Z, 0
%endif
dw C5, R, Q, A0, R, Z, 0

;--- tell your assembler you're done, if it doesn't know ---

tasm
.



Relevant Pages

  • Re: which book to start with...?
    ... linux and i dont have windows. ... will i miss something important if i dont start in dos? ... orig equ $08048000 ... trap $80 ...
    (alt.lang.asm)
  • Re: pc speaker in asm
    ... mov al, 10111110b ... call delay ... A0 equ 21728 ...
    (alt.lang.asm)
  • Re: Post build events
    ... realized the events work like DOS and you can use the IF XXX EQU ... cpu arch is 64bit for the compiled output... ...
    (microsoft.public.dotnet.languages.vb)
  • Re: my first .dll: why doesnt it work ...
    ... WM_DESTROY equ 2h; WM_CLOSE equ 10h; WM_NCPAINT equ ... /* il numero e' preso. ... /* eax St0ToAscii(char* string, uint intPart, uint decPart) ...
    (alt.lang.asm)
  • Re: AltairZ80 simulator updated
    ... programming is no longer taught. ... 1000 evcod equ $ ... 1030 evco1 mov a,m ... 1120 ret ...
    (comp.os.cpm)