From: io_x on
i find this code in internet

i traslate this NBASM assembly to NASM
but it seems the timer never end
possibily i copy something wrong
but what?
Is it possible use the timer of keyboard like timer?
there is some dx of kind
out dx, ax
that sleep for ax seconds?
thanks

;com file
;nasmw -o m.com m.asm
;;
; from
; SND produces sound on the speaker.
; Version: 1.00b
; Author: Ben Lunt (Forever Young Software(R))
; Date: 09 Dec 1998
; Assembler: NBASM 00.23.xx
;;

%define speaker 061h
%define timer 043h
%define on 03h
%define sendSpeaker 042h
%define off 0FCh

org 100h
main:
push ds
pop es
mov dx, speaker
in al, dx
or al, on
out dx, al
mov dx, timer
mov al, 0B6h
out dx, al

mov si, SomeTune
..0: mov ax, [si]
add si, 2
or ax, ax
jz .9
; r=sendSpeaker|out r, al|ah<->al|out r, al
mov cx, [si]
add si, 2
call PauseIt
jmp short .0
..9: mov dx, speaker
in al, dx
and al, off
out dx, al
mov ax, 0
ret

; this routine waits for specified milliseconds
PauseIt:
push ax
push bx
push cx
push dx
xor dx, dx ; cx = 16 = 1 second
mov ax, 62500
mul cx
mov cx, dx
xor dx, dx
mov bx, PF
mov ax, 08300h
mov word[bx], 0
int 15h
..1: cmp byte[PF], 0
je .1
pop dx
pop cx
pop bx
pop ax
ret

align 2
PF db 0, 0
SomeTune dw 1397, 08
dw 1397, 08
dw 1397, 08
dw 1318, 06
dw 1244, 16
dw 1046, 04
dw 1108, 04
dw 1174, 04
dw 1244, 04
dw 1174, 08
dw 1244, 08
dw 1318, 08
dw 1396, 08
dw 1480, 08
dw 1568, 16
dw 00h, 00h




From: wolfgang kern on

"io_x" wrote:

> i find this code in internet

> i traslate this NBASM assembly to NASM
> but it seems the timer never end
> possibily i copy something wrong
> but what?
> Is it possible use the timer of keyboard like timer?

Sure, but not a big gain without an IRQ-pin.

> there is some dx of kind
> out dx, ax
> that sleep for ax seconds?

Would be fine, but this isn't available at all.
I wrote myself a function that uses the master PIT set to
1 mSec-IRQ, and this got several down until zero counters.

> ;com file
> ;nasmw -o m.com m.asm
> ;;
> ; from
> ; SND produces sound on the speaker.
> ; Version: 1.00b
> ; Author: Ben Lunt (Forever Young Software(R))
> ; Date: 09 Dec 1998
> ; Assembler: NBASM 00.23.xx
> ;;

> %define speaker 061h
> %define timer 043h
> %define on 03h
> %define sendSpeaker 042h
> %define off 0FCh

Port 40..43h are the PIT (8253/8254 chip compliant, see RBIL/ports)
43h is the PIT-control
while 40..42h are 'double-access'-capabile 16-bit (2*8 bit) counters

> org 100h
> main:
> push ds
> pop es
> mov dx, 61h ;speaker
> in al, dx
> or al, 03h ;on
> out dx, al
> mov dx, 43h ;timer /PIT_CTRL
> mov al, 0B6h ;b7,6 10 CNTR=2 (42h) out dx, al
> ;b5,4 11 access is double
;b3..1 011 square-mode
;b0 0 binary mode
RBIL tells us:
_____________
Once a control word has been written (43h), it must be followed
immediately by performing the corresponding action to the counter
registers (40h-42h), else the system may hang!!
_____________
So I'd miss the setup of counter2 (two writes to port 42h)
in the following loop.

> mov si, SomeTune
> .0: mov ax, [si] ;word [si] = frequency divider
> add si, 2 ;word [si+2] = duration or ax, ax
> jz .9
> ; r=sendSpeaker|out r, al|ah<->al|out r, al
> mov cx, [si]
> add si, 2
> call PauseIt
> jmp short .0
> .9: mov dx, speaker
> in al, dx
> and al, fch ;off
> out dx, al
> mov ax, 0
> ret


> ; this routine waits for specified milliseconds

I'm not sure about this int15 delay work on MilliSeconds.

> PauseIt:
> push ax
> push bx
> push cx
> push dx
> xor dx, dx ; cx = 16 = 1 second
> mov ax, 62500
> mul cx
> mov cx, dx
> xor dx, dx
> mov bx, PF
> mov ax, 08300h
> mov word[bx], 0
> int 15h
> .1: cmp byte[PF], 0
> je .1
> pop dx
> pop cx
> pop bx
> pop ax
> ret
>
> align 2
> PF db 0, 0
> SomeTune dw 1397, 08
> dw 1397, 08
> dw 1397, 08
> dw 1318, 06
> dw 1244, 16
> dw 1046, 04
> dw 1108, 04
> dw 1174, 04
> dw 1244, 04
> dw 1174, 08
> dw 1244, 08
> dw 1318, 08
> dw 1396, 08
> dw 1480, 08
> dw 1568, 16
> dw 00h, 00h

IIRC:
Frank once posted his 'DOS-organ' with a more transparent delay.

__
wolfgang





From: Benjamin David Lunt on

"io_x" <a(a)b.c.invalid> wrote in message
news:4b600a1b$0$819$4fafbaef(a)reader5.news.tin.it...
>i find this code in internet
>
> i traslate this NBASM assembly to NASM
> but it seems the timer never end
> possibily i copy something wrong
> but what?
> Is it possible use the timer of keyboard like timer?
> there is some dx of kind
> out dx, ax
> that sleep for ax seconds?
> thanks
>
> ;com file
> ;nasmw -o m.com m.asm
> ;;
> ; from
> ; SND produces sound on the speaker.
> ; Version: 1.00b
> ; Author: Ben Lunt (Forever Young Software(R))
> ; Date: 09 Dec 1998
> ; Assembler: NBASM 00.23.xx
> ;;

(original NBASM source at http://www.fysnet.net/snd.htm )

Hi io_x,

As you can tell, I wrote that more than 10 years
ago (smile). At the time, I am sure I used a
so called (at that time) modern 286 where the speaker
was used for most of the sound produced on
PC's. I don't think the SB16 had made it to
mass production yet, had it?

I have an old 486DX with a Creative Labs sound
blaster. This machine is dated about 1994 or
so, but it was 'suppose' to be top of the
line at that time.

Anyway, the code worked on the machine I used
for testing (probably that same 486DX) when
I wrote it. Who knows if it works now, since
the internal speaker is a thing of a rarity
now a days.

Also, the interrupt 15h 'wait' service is obsolete,
and I have found that most modern BIOS's don't
even support it anymore.

If I get a chance this afternoon, with other's comments
and a little luck, I will see if I can update that
code.

Thanks,
Ben

--
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Forever Young Software
http://www.fysnet.net/index.htm
http://www.fysnet.net/collections.htm
To reply by email, please remove the zzzzzz's

Batteries not included, some assembly required.


From: io_x on

"io_x" <a(a)b.c.invalid> ha scritto nel messaggio
news:4b600a1b$0$819$4fafbaef(a)reader5.news.tin.it...
>i find this code in internet
>
> i traslate this NBASM assembly to NASM
> but it seems the timer never end
> possibily i copy something wrong
> but what?
> Is it possible use the timer of keyboard like timer?
> there is some dx of kind
> out dx, ax
> that sleep for ax seconds?
> thanks

i not has used timer, just one loop for delay somthing
this program is one digital music (or noise) machine.

Is all that 66-code [the code for using 32 bit registers] ok?
This is my music(or noise) composer:

;com file
;nasmw -o m.com m.asm
;;
; using part of code from
; SND produces sound on the speaker.
; Version: 1.00b
; Author: Ben Lunt (Forever Young Software(R))
; Date: 09 Dec 1998
; Assembler: NBASM 00.23.xx
;;

%define speaker 061h
%define timer 043h
%define on 03h
%define sendSpeaker 042h
%define off 0FCh

org 100h
main:
push ds
pop es
RDTSC
mov dx, ax
shr eax, 16
push dx
push ax
call srand
mov dx, speaker
in al, dx
or al, on
out dx, al

call Componi

..9: mov dx, speaker
in al, dx
and al, off
out dx, al
mov ax, 0
ret

PauseIt2:
cmp cx, 0
je .2
shl cx, 9
mov ax, 0
..0: wait
dec ax
jnz .0
dec cx
jnz .0
..2:
ret

rnd:
mov eax, 214723821
mul dword[next]
add eax, 12345
mov dword[next], eax
shr eax, 3
ret

; 0i, 2ra, 4P1, 6P2
srand:
push si
mov si, sp
mov ax, [si+4]
mov [next], ax
mov ax, [si+6]
mov [next+2], ax
pop si
ret 4

;0i, 2ra, 4P_Min, 6P_Max
rndRange:
push si
mov si, sp
mov cx, [si+6]
sub cx, [si+4]
cmp cx, 0
jle .z
and ecx, 0FFFFh
call rnd
mov edx, 0
div ecx
mov ax, [si+4]
and eax, 0FFFFh
add eax, edx
..z:
pop si
ret 4

; This routine shows how to send sound (freq.) to the internal speaker.
; You can sound a frequency between 1 and 4000+. Please Note that the
; human ear has a hard time hearing a frequency less than about 440.
; musicFunction(u16 value, u16 time)
; 0i, 2ra, 4PValue, 6Ptime
musicFunction:
push si
mov si, sp
mov ax, [si+4]
mov dx, sendSpeaker
out dx, al
xchg ah, al
out dx, al
mov cx, [si+6]
call PauseIt2
pop si
ret 4

Componi:
pusha
mov bp, 50
..0: push 4000
push 2200
call rndRange
mov si, ax
push 18
push 8
call rndRange
mov di, ax
push di
push si
call musicFunction
dec bp
jnz .0
popa
ret


align 4
next dd 1
SomeTune dw 1397, 08
dw 1397, 08
dw 1397, 08
dw 1318, 06
dw 1244, 16
dw 1046, 04
dw 1108, 04
dw 1174, 04
dw 1244, 04
dw 1174, 08
dw 1244, 08
dw 1318, 08
dw 1396, 08
dw 1480, 08
dw 1568, 16
dw 00h, 00h
-----------------
;com file
;nasmw -o m.com m.asm
;;
using part of code from
SND produces sound on the speaker.
Version: 1.00b
Author: Ben Lunt (Forever Young Software(R))
Date: 09 Dec 1998
Assembler: NBASM 00.23.xx
;;

%define speaker 061h
%define timer 043h
%define on 03h
%define sendSpeaker 042h
%define off 0FCh

org 100h
main:
<ds|>es
RDTSC|r=a|eax>>=16
srand(a,r)
r=speaker|in al, r|al|=on|out r, al

Componi()

..9: r=speaker|in al, r|al&= off|out r, al
a=0
ret

PauseIt2:
c==0#.2|c<<=9|a=0
..0: wait |--a|jnz .0|--c|jnz .0
..2:
ret

rnd:
eax=214723821|mul D*next|eax+=12345
D*next=eax|eax>>=3
ret

; 0i, 2ra, 4P1, 6P2
srand:
<i|i=s
a=*i+4|*next=a
a=*i+6|*next+2=a
>i
ret 4

;0i, 2ra, 4P_Min, 6P_Max
rndRange:
<i|i=s
c=*i+6|c-=*i+4|c<=0?#.z
ecx&=0FFFFh
rnd() |edx=0|div ecx
a=*i+4 |eax&=0FFFFh
eax+=edx
..z:
>i
ret 4

; This routine shows how to send sound (freq.) to the internal speaker.
; You can sound a frequency between 1 and 4000+. Please Note that the
; human ear has a hard time hearing a frequency less than about 440.
; musicFunction(u16 value, u16 time)
; 0i, 2ra, 4PValue, 6Ptime
musicFunction:
<i|i=s
a=*i+4
r=sendSpeaker|out r, al|ah<->al|out r, al
c=*i+6|PauseIt2()
>i
ret 4

Componi:
pusha
k=50
..0: rndRange(2200, 4000)
i=a
rndRange(8, 18)
j=a
musicFunction(i, j)
--k#.0
popa
ret


align 4
next dd 1
SomeTune dw 1397,08
dw 1397,08
dw 1397,08
dw 1318,06
dw 1244,16
dw 1046,04
dw 1108,04
dw 1174,04
dw 1244,04
dw 1174,08
dw 1244,08
dw 1318,08
dw 1396,08
dw 1480,08
dw 1568,16
dw 00h,00h





From: io_x on

"Benjamin David Lunt" <zfysz...(a)fysnet.net> ha scritto nel messaggio
news:DiY7n.8602$4p5.1713(a)newsfe22.iad...
>
> "io_x" <a(a)b.c.invalid> wrote in message
> news:4b600a1b$0$819$4fafbaef(a)reader5.news.tin.it...
>>i find this code in internet
> Hi io_x,
>
> As you can tell, I wrote that more than 10 years
> ago (smile). At the time, I am sure I used a
> so called (at that time) modern 286 where the speaker
> was used for most of the sound produced on
> PC's. I don't think the SB16 had made it to
> mass production yet, had it?

yes in my windows XP PC
i have the speaker that answer well, but not the timer