From: io_x on

"io_x" <a(a)b.c.invalid> ha scritto nel messaggio
news:4b6139f8$0$827$4fafbaef(a)reader5.news.tin.it...
>
> "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:

Do you like my all in asm composer? is it not a good musician? :)

If i have to write it in serious i have to add all error conditions
and one way for find the timer; for this the pause depend on cpu
so if you want to play well, you have to modify the routine
PauseIt2:
in the place "shl cx, 9" with suitable value of cx example
shl cx, 13
or
shl cx, 4
in the way it return the right pause for your cpu type

;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

; this is the my all in asm music composer for
; one instrument of the range 2200..4000
;;

%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
sub sp, 1024
mov bx, sp
mov bp, 10
..0: push 4000
push 2200
call rndRange ; here find one
mov si, ax
mov [bx], ax
add bx, 2 ; random sequece
push 18
push 8
call rndRange ; of ten note
mov di, ax
mov [bx], ax
add bx, 2
push di
push si
call musicFunction
dec bp
jnz .0
mov bp, 10
mov di, 15 ; here repeat it for 15 times
mov bx, sp
..1: mov ax, [bx]
add bx, 2
mov dx, [bx]
add bx, 2
push dx
push ax
call musicFunction
dec bp
jnz .1
mov bp, 10
mov bx, sp
dec di
jnz .1
..z:
add sp, 1024
popa
ret


align 4
next dd 1
-----------------------
;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

this is the my all in asm music composer for
one instrument of the range 2200..4000
;;

%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
s-=1024
b= s
k=10
..0: rndRange(2200, 4000) ; here find one
i=a|*b=a|b+=2 ; random sequece
rndRange(8, 18) ; of ten note
j=a|*b=a|b+=2
musicFunction(i, j)
--k#.0
k=10|j=15 ; here repeat it for 15 times
b=s
..1: a=*b|b+=2|r=*b|b+=2|musicFunction(a, r)
--k#.1|k=10|b=s|--j#.1
..z:
s+=1024
popa
ret


align 4
next dd 1



From: io_x on

"io_x" <a(a)b.c.invalid> ha scritto nel messaggio
news:4b6139f8$0$827$4fafbaef(a)reader5.news.tin.it...
>
> "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:

what about adding some pause??
i think afther each note is nees some pause, but this is
not the place where i use them, these here are random

;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

; this is the my all in asm music composer for
; one instrument of the range 2200..4000
;;

%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
sub sp, 1024
mov bx, sp
mov bp, 13
..0: push 4500
push 2200
call rndRange ; here find one
cmp ax, 4000
jbe .0a ; for pause
mov ax, 0
..0a: mov si, ax
mov [bx], ax
add bx, 2 ; random sequece
push 23
push 4
call rndRange ; of 13 notes
mov di, ax
mov [bx], ax
add bx, 2
push di
push si
call musicFunction
dec bp
jnz .0
mov bp, 13
mov di, 5 ; here repeat it for 5 times
mov bx, sp
..1: mov ax, [bx]
add bx, 2
mov dx, [bx]
add bx, 2
push dx
push ax
call musicFunction
dec bp
jnz .1
mov bp, 13
mov bx, sp
dec di
jnz .1
push 4
push 0
call musicFunction ; the last note is silent
..z:
add sp, 1024
popa
ret


align 4
next dd 1



From: Benjamin David Lunt on

"Benjamin David Lunt" <zfysz(a)fysnet.net> wrote in message
news:DiY7n.8602$4p5.1713(a)newsfe22.iad...
>

Hi io_x,

Okay, a day late, but I updated my code
http://www.fysnet.net/snd.htm

The problem was that the BIOS didn't support the
delay call anymore.

I simply changed it to use the BIOS timer tick
at 0040:006Ch. This isn't a very good delay, since
it can vary by 55ms. However, it gets the point
across.

To accurately use the example, you would need
to create your own delay routine.

Thanks for bringing this to my attention,
Ben

P.S. I will have to grab your code and see what
changes you made. Thanks.


From: io_x on

"Benjamin David Lunt" <zfysz(a)fysnet.net> ha scritto nel messaggio
news:iQq8n.16192$p66.2418(a)newsfe09.iad...
>
> "Benjamin David Lunt" <zfysz(a)fysnet.net> wrote in message
> news:DiY7n.8602$4p5.1713(a)newsfe22.iad...
>>
>
> Hi io_x,
>
> Okay, a day late, but I updated my code
> http://www.fysnet.net/snd.htm
>
> The problem was that the BIOS didn't support the
> delay call anymore.
>
> I simply changed it to use the BIOS timer tick
> at 0040:006Ch. This isn't a very good delay, since
> it can vary by 55ms. However, it gets the point
> across.

thanks

> To accurately use the example, you would need
> to create your own delay routine.
>
> Thanks for bringing this to my attention,
> Ben
>
> P.S. I will have to grab your code and see what
> changes you made. Thanks.

free to do it



From: io_x on

"io_x" <a(a)b.c.invalid> ha scritto nel messaggio
news:4b6139f8$0$827$4fafbaef(a)reader5.news.tin.it...
>
> "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:

could be ok that timer?

in the few i understand all rand 10-12 notes are ok if one repeat them
because the human should understand them

for more notes there is need to break them
in the way they are understendable.

i have no study music but it seems to me that there is something of kind

|-------|---|--------|-------|

where | are random pause where + melodies meet themself
but this is not clear to me much (is possible
if one see something for doing that with 2 melodies
it could increase the number of notes
and write the true music machine)

;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

; this is the my all in asm music composer for
; one instrument of the range 2200..4000
;;

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

org 100h
main:
push ds
pop es
push 32
call sleep ; here it should wait 32/16 == 2 seconds
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

; 0i, 2ra, 4P_seconds
sleep:
push si
mov si, sp
mov cx, [si+4]
cmp cx, 0
je .1
and ecx, 0FFFFh
mov eax, 181250000
mul ecx
mov [result], eax
mov [result+4], edx
RDTSC

xor ecx, ecx
add eax, [result] ; where end?
adc edx, [result+4]
adc ecx, 0
cmp ecx, 0
jne .1

mov [result], eax
mov [result+4], edx ; end using result
..0: RDTSC
wait
cmp [result+4], edx
ja .0
cmp [result+4], edx
jb .1
cmp [result], eax
ja .0 ; doing the double loop
..1:
pop si
ret 2

outputString:
mov ah, 0Eh
..1: mov al, [di]
cmp al, 0
je .z
inc di
int 10h
jmp short .1
..z:
ret

; 0k, 2j,4i,6b,8ra,10P_IntValue +256
HexPrint:
push bx
push si
push di
push bp
sub sp, 256
mov bx, sp
mov di, [bx+266]
xor si, si
xor ax, ax
mov cx, 12 ; c=16-4
mov byte[bx+si], '0'
inc si
mov dx, 0F000h
..0: mov bp, dx
and bp, di
shr bp, cl
mov al, [ I0123456789ABCDEF +bp]
mov [bx+si], al
inc si
shr dx, 4
sub cx, 4
jge .0
mov byte[bx+si], 'h'
inc si
mov byte[bx+si], 0
mov di, sp
call outputString
add sp, 256
pop bp
pop di
pop si
pop bx
ret 2


; in a the number
HxPrintA:
pusha
push ax
call HexPrint
popa
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]
push cx
call sleep
pop si
ret 4

Componi:
pusha
sub sp, 1024
pusha
mov di, title
call outputString
popa
mov si, 3
..a: mov bx, sp
mov bp, 12
..0: push 4100
push 2200
call rndRange ; here find one
cmp ax, 4000
jbe .0a
mov ax, 0
..0a:
mov di, ax
mov [bx], ax
add bx, 2 ; random sequece
pusha
mov di, par1
call outputString
popa
call HxPrintA
push 9
push 4
call rndRange ; of some note
mov [bx], ax
add bx, 2
pusha
mov di, space
call outputString
popa
call HxPrintA
pusha
mov di, par2
call outputString
popa
push ax
push di
call musicFunction
dec bp
jnz .0
mov di, nl
call outputString
mov bp, 12
mov di, 4 ; here repeat it for 4 times
mov bx, sp
..1: mov ax, [bx]
add bx, 2
mov dx, [bx]
add bx, 2
push dx
push ax
call musicFunction
dec bp
jnz .1
mov bp, 12
mov bx, sp
dec di
jnz .1
dec si
jnz .a
push 9
push 0
call musicFunction
..z:
add sp, 1024
popa
ret

align 4
result dd 0, 0
memory dd 123, 124
next dd 1
I0123456789ABCDEF db "0123456789ABCDEF" , 0, 0
par1 db '[' , 0
par2 db '] ' , 0
space db ':' , 0
title db "3 little 'music' play (it should take 1 min +-)"
db " [N.Note:TimeForNote]"
nl db 13, 10, 0