;***************************************************************************** ; SOUND.ASM - by David Kühling 1998 * ;----------------------------------------------------------------------------* ; This is an example for the SoundLib sound library, that plays tones with * ; a given frequency. * ; * ; Last modification: 14.8.1998 * ; * ; Contacting me: * ; Email: dkuehlin@hell1og.be.schule.de (don't mix up 'l' and '1') * ; - valid till june 2000 * ; Mail: * ; David Kühling * ; Lion-Feuchtwanger-Str. 44 * ; 12619 Berlin * ; GERMANY * ; * ;***************************************************************************** INCLUDE "tios.h" INCLUDE "flib.h" INCLUDE "soundlib.h" XDEF _main XDEF _comment ;----------------------------------------------------------------------; ; MAIN ; ; Displays some text, and plays tones for 100 milliseconds. The ; ; frequency of those tones can be changed by ([2nd] + ) [+]/[-]. ; ;----------------------------------------------------------------------; _main: jsr soundlib::Init ; initialize SoundLib jsr flib::clr_scr ; clear screen ; frame_rect(rect r) clr.l d7 ; draw screen borders move.l #$00EF0079,-(a7) ; push x2 and y2 move.l d7,-(a7) ; push x1 and y1 (both 0) jsr flib::frame_rect ; 8 bytes on stack ;---------- display some text ----------; lea tios::FontSetSys,a2 ; addresses of often used routines lea tios::DrawStrXY,a3 ; BYTE FontSetSys(BYTE font) move.w #1,-(a7) ; set medium (6x8) font jsr (a2) ; 10 bytes on stack ; void DrawStrXY(WORD x, WORD y, BYTE *string, WORD color) move.w d7,-(a7) pea Title(PC) move.l d7,-(a7) jsr (a3) ; 20 bytes on stack ; void DrawStrXY(WORD x, WORD y, BYTE *string, WORD color) move.w #4,-(a7) pea Keys(PC) move.l #$00020020,-(a7) jsr (a3) ; 30 bytes on stack ; void DrawStrXY(WORD x, WORD y, BYTE *string, WORD color) move.w #4,-(a7) pea Keys1(PC) move.l #$00080028,-(a7) jsr (a3) ; 40 bytes on stack ; void DrawStrXY(WORD x, WORD y, BYTE *string, WORD color) move.w #4,-(a7) pea Keys2(PC) move.l #$00080030,-(a7) jsr (a3) ; 50 bytes on stack ; BYTE FontSetSys(BYTE font) move.w #2,-(a7) ; set big (8x10) font jsr (a2) ; 52 bytes on stack lea 52(a7),a7 ; remove all those arguments ; Registers: ; d7.w = frequency ; d6.w = change of frequency ; a6.l = pointer to keyboard row mask ; a5.l = pointer to keyboard column mask ; a4.l = pointer to buffer for sprintf move.w #440,d7 ; d7 = frequency lea $600018,a6 ; a6 = *keyboard row mask lea 3(a6),a5 ; a5 = *keyboard column mask lea FrqStr_s,a4 ; a4 = *FrqStr_s (sprintf buffer) move.w #$700,d0 ; disable interrupts trap #1 \Loop: tst.w d6 ; if d6 = 0: the frequency didn't change beq \NoChange ; --> don't display frequency again ;---------- display frequency ----------; ; int sprintf(char *buffer, char *format[, argument, ...]) move.w d7,-(a7) pea FrqStr_f(PC) pea (a4) jsr tios::sprintf ; void DrawStrXY(WORD x, WORD y, BYTE *string, WORD color) move.w #4,-(a7) pea (a4) move.l #$00200050,-(a7) ; push x and y jsr (a3) lea 20(a7),a7 \NoChange: clr.w d6 ; d6 = change of frequency ;-------------- check keys -------------; move.w #$0FF,(a6) ; only read row 9 and 10 bsr \LittleDelay ; allow the IO to recover btst #4,(a5) ; check [+] - key bne \NoPlusKey moveq #1,d6 ; change frequency by +1 \NoPlusKey: btst #0,(a5) ; check [-] - key bne \NoMinusKey moveq #-1,d6 ; change frequency by -1 \NoMinusKey: move.w #$3FE,(a6) ; check [2nd] - key bsr \LittleDelay ; allow the IO to recover btst.w #0,(a5) bne \No2ndKey muls #10,d6 ; change frequency by 10*(-1;+1;0) \No2ndKey: ;---------- change frequency -----------; move.w d7,d0 ; store old frequency add.w d6,d7 ; do the change cmpi.w #40,d7 ; if frequency < 40: undo the change bge \LowerBoundOk move.w d0,d7 \LowerBoundOk: cmpi.w #4000,d7 ; if frequency > 4000: undo the change ble \UpperBoundOk move.w d0,d7 \UpperBoundOk: ;------------ play the tone ------------; move.w d7,d0 ; set frequency move.w #102,d1 ; set duration to about 100 milliseconds jsr soundlib::Sound btst #1,-1(a5) ; check [ON] - key bne \Loop ; continue, if it isn't pressed clr.w d0 ; enable interrupts trap #1 rts ;----------------------------------------------------------------------; ; Some delay, used for reading the keyboard directly, to allow the ; ; IO to recover. ; ;----------------------------------------------------------------------; \LittleDelay: move.l (a7),(a7) move.l (a7),(a7) rts ;----------------------------------------------------------------------; ; DATA ; ;----------------------------------------------------------------------; _comment: dc.b "SoundLib Example by D.Kühling",0 Title: dc.b " SoundLib Example by David Kühling 1998 ",0 Keys: dc.b "Keys:",0 Keys1: dc.b "([2nd] + ) [+]/[-] to change frequency",0 Keys2: dc.b "[On] to exit",0 FrqStr_f: dc.b "Frequency: %iHz ",0 BSS FrqStr_s: ds.b 20 END