flat assembler
Message board for the users of flat assembler.
Index
> Main > PC speaker issue + code |
Author |
|
Matrix 20 Oct 2004, 03:01
Howdy folk,
are you sure this won't hurt anybody? Code: ; create stack mov ax, 0x0000 mov ss, ax mov sp, 0xFFFF what do you say using this instead? Code: ; create stack push cs pop ss mov sp, 0xFFFF or if you need large stacks: Code: ; create stack mov ax,cs add ax,4096 ; + 64 kB @ offset side mov ss,ax mov sp, 0xFFFF Last edited by Matrix on 21 Oct 2004, 14:43; edited 1 time in total |
|||
20 Oct 2004, 03:01 |
|
Matrix 20 Oct 2004, 04:06
I have made a simple PC speaker note player, Privalov, could you take a look at the times at the end? it is not working like this, my file is 256 bytes !
Code: ; Program: Simple Note Player by MATRIX org 256 call setup_pit_timer mov si,msg call Print mov bx,tonedata call Play call reset_pit_timer int 20h ;************************************************************ ; Procedure print ; prints a zero terminated string pointed to by si ;************************************************************ Print: push ax mov ah,14; BIOS code for screen display cld print_loop:lodsb; moving the character to be displayed to al or al, al; checking if the char is NULL jz printdone int 10h; Calling BIOS routine JMP print_loop printdone:pop ax ret ; End of print procedure... ;************************************************************ ; Procedure Play ; plays a sick and demented melody ;************************************************************ Play: pusha ;save regs localloop: mov ax,[bx] ;load sound data add bx,2 or ax,ax jz finished jns notdelay delay: push bx neg ax mov cx,ax call pit_tick_delay pop bx jmp localloop notdelay: ; not delay, its a note push bx call sound ;play it pop bx jmp localloop finished: call nosound popa ret ;end Play nosound: ; Silences the speaker. in al,0x61 and al,0xFC out 0x61,al ret sound: ; AX = frequency Starts the speaker emiting a sound of a given frequency mov bx,ax ; RETURNS: AX,BX,DX = undefined mov dx,0x12 mov ax,0x34DD ; ;mov ax,0x34DC ; which is more accurate? div bx mov bl,al mov al,0xB6 out 0x43,al mov al,bl out 0x42,al mov al,ah out 0x42,al in al,0x61 or al,3 out 0x61,al ret pit_tick_delay: ; waits cx ticks, destroys: ax bx ;cli ;if you need accurate timing uncomment this call read_pit_value mov bx,ax .below: call read_pit_value cmp ax,bx jl .below .above: call read_pit_value cmp ax,bx jg .above loop .below ;sti ;if you need accurate timing uncomment this ret reset_pit_timer: mov al,00110110b ; count down twice generator jmp setupcommon setup_pit_timer: ; returns status in al mov al,00110100b ; rate generator setupcommon: cli ;if you need accurate timing comment this refer to above out 43h,al xor al,al out $40,al out $40,al .waitlatch: mov al,11100010b ; get timer 0 status out 43h,al in al,40h bt ax,6 jc .waitlatch sti ;if you need accurate timing comment this refer to above ret read_pit_value: ;.waitlatch: ; if you have early 8253s comment ; mov al,11100010b ; get timer 0 status ; this part out ; out 43h,al ; ( wais for latch to be valid ) ; in al,40h ; ;bt ax,6 ; ;jc .waitlatch ; mov al,11010010b cli out 43h,al in al,40h mov ah,al in al,40h sti xchg al,ah ret msg: db 'Playing sound',0 tonedata: ; negatives are delay dw 440,-7,880,-4,440,-4,330,-15 dw 440,-7,880,-4,440,-4,330,-15 dw 550,-7,440,-4,330,-4,440,-15 dw 0 ; stop ! ; Make the file 512 bytes long ;times 512+256-$ Db 0 ; file is org 256 based so Last edited by Matrix on 20 Oct 2004, 08:24; edited 1 time in total |
|||
20 Oct 2004, 04:06 |
|
Matrix 20 Oct 2004, 08:29
Here's the latest version, i have added some stuff:
|
|||||||||||||||||||||
20 Oct 2004, 08:29 |
|
Paul6253 22 Oct 2004, 15:59
yeah I mean I still trying to figure why my linux code dont work no more...
_________________ Plez xcuce mi spelng |
|||
22 Oct 2004, 15:59 |
|
Matrix 22 Oct 2004, 17:31
I don't know what you mean,
my code should work without an operating system, only a few modifcations whould be needed, since it is writing to ports. You could substract the parts you need no? |
|||
22 Oct 2004, 17:31 |
|
oveja 21 Apr 2005, 17:48
¿How play Midi File whit pcSpeaker?
|
|||
21 Apr 2005, 17:48 |
|
Matrix 22 Apr 2005, 16:16
Hy!
its not that simple task, first you have to make a midi player, then decide a way to render on pc speaker, this will probably work only on dos, none multitask os. you might laugh on this but some simple linux has the ability to emulate soundblaster on pc speaker, you can play mp3 on pc speaker. i have a mod player somewhere able to play mod files on pcspeaker with fair quality (16KHz sampling rate) but with no source codes, just dos executable ( software ) |
|||
22 Apr 2005, 16:16 |
|
rugxulo 12 Jul 2007, 23:00
http://www.ibiblio.org/pub/micro/pc-stuff/freedos/files/distributions/1.0/pkgs/
MIDIPLAX.LSM wrote:
I think it used Pacific C plus PCC's weird assembly, so it may be a bit quirky to understand. But it does include a simple sample .MID file. |
|||
12 Jul 2007, 23:00 |
|
DOS386 12 Jul 2007, 23:05
WOW ! Does it work ?
|
|||
12 Jul 2007, 23:05 |
|
rugxulo 12 Jul 2007, 23:33
Uh, yes, of course, why would I post otherwise?
Of course, it only plays mono-channel ones, so you won't hear a bunch of "instruments" at the same time (or whatever). And, I know of at least one (slightly imperfect) .MOD / .STM / .S3M / .XM etc. player for DOS (even XTs) for soundcards and PC speaker (direct d/l): Galaxy Music Player. And here's a .WAV player for DOS via PC speaker too: LxVox. P.S. But if you want soundcard .MID players for DOS, try there: RealMIDI (w/ src) or GSplay. |
|||
12 Jul 2007, 23:33 |
|
DOS386 12 Jul 2007, 23:53
rugxulo wrote:
(much) Thanks. > why would I post otherwise? You tend to uncritically (?) advertise stuff > And here's a .WAV player for DOS via PC speaker I have my own ... written in FASM OTOH none of audio codecs has FASM source so I have to deal with all the silly C code ... at least there is a usable and well supported C compiler around by now _________________ Bug Nr.: 12345 Title: Hello World program compiles to 100 KB !!! Status: Closed: NOT a Bug |
|||
12 Jul 2007, 23:53 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.