From f9024d132a33ffb62257fbb2bb84b63436eb8996 Mon Sep 17 00:00:00 2001 From: Mariano Dominguez Date: Thu, 5 Jan 2023 21:12:58 -0800 Subject: [PATCH] add sound command this behives the same as BASIC sound(voice, pitch, distortion, volume) --- include/atari.h | 6 ++++++ libsrc/atari/sound.s | 43 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 libsrc/atari/sound.s diff --git a/include/atari.h b/include/atari.h index deae8fdf5..e31463991 100644 --- a/include/atari.h +++ b/include/atari.h @@ -235,6 +235,12 @@ extern void __fastcall__ _scroll (signed char numlines); /* numlines < 0 scrolls down */ +/*****************************************************************************/ +/* Sound function */ +/*****************************************************************************/ + +extern void __fastcall__ sound (unsigned char voice, unsigned char frequency, unsigned char distortion, unsigned char volume); /* plays a sound in the specidied voice, to silence call with in other params*/ + /*****************************************************************************/ /* Misc. functions */ /*****************************************************************************/ diff --git a/libsrc/atari/sound.s b/libsrc/atari/sound.s new file mode 100644 index 000000000..53cb717ff --- /dev/null +++ b/libsrc/atari/sound.s @@ -0,0 +1,43 @@ +; +; Mariano Domínguez +; 2022-12-4 +; +; atari lib +; + .include "atari.inc" + + .export _sound + .import popa +; play sound, arguments: voice, pitch, distortion, volume. same as BASIC +.proc _sound + sta STORE2 ;save volume + jsr popa ;get distortion + sta STORE1 ;save distortion + jsr popa ;get pitch + pha ;save in stack + jsr popa ;get voice + + asl a ;adjust voice *2 for offset in x + tax + pla ;get pitch from stack + sta AUDF1,x ; store pitch + + lda #0 + sta AUDCTL + lda #3 + stx SKCTL ; init sound + + lda STORE1 ;get distortion + asl a ;ignore the high nibble + asl a + asl a + asl a + clc ; setup for adding volume + adc STORE2 ; add volume + sta AUDC1,x ; volume + distortion in control channel + rts +.endproc +; reserve 2 bytes for temp storage + .bss +STORE1: .res 1 +STORE2: .res 1 \ No newline at end of file