diff --git a/include/atari.h b/include/atari.h index deae8fdf5..04cacab33 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); + /*****************************************************************************/ /* Misc. functions */ /*****************************************************************************/ diff --git a/libsrc/atari/sound.s b/libsrc/atari/sound.s new file mode 100644 index 000000000..0c1e80db5 --- /dev/null +++ b/libsrc/atari/sound.s @@ -0,0 +1,37 @@ +; +; Mariano Domínguez +; 2022-12-4 +; +; atari lib +; + .include "atari.inc" + .export __sound + .import popa + .importzp tmp1,tmp2 + +; play sound, arguments: voice, pitch, distortion, volume. same as BASIC +.proc __sound + sta tmp2 ;save volume + jsr popa ;get distortion + sta tmp1 ;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 + sta SKCTL ;init sound + lda tmp1 ;get distortion + asl a ;ignore the high nibble + asl a + asl a + asl a + clc ;setup for adding volume + adc tmp2 ;add volume + sta AUDC1,x ;volume + distortion in control channel + rts +.endproc diff --git a/targettest/atari/Makefile b/targettest/atari/Makefile index dd4f6078f..d5b4d9593 100644 --- a/targettest/atari/Makefile +++ b/targettest/atari/Makefile @@ -39,6 +39,7 @@ EXELIST_atari = \ multi.xex \ ostype.xex \ scrcode.com \ + sound.xex \ sys.xex ifneq ($(EXELIST_$(SYS)),) @@ -74,7 +75,8 @@ scrcode.com: scrcode.s $(CL) -t atari -C atari-asm.cfg -o scrcode.com scrcode.s sys.xex: sys.c $(CL) -t atari -o sys.xex sys.c - +sound.xex: sound.c + $(CL) -t atari -o sound.xex sound.c clean: @$(DEL) charmapping.xex 2>$(NULLDEV) @$(DEL) defdev.xex 2>$(NULLDEV) @@ -85,3 +87,4 @@ clean: @$(DEL) scrcode.o 2>$(NULLDEV) @$(DEL) scrcode.com 2>$(NULLDEV) @$(DEL) sys.xex 2>$(NULLDEV) + @$(DEL) sound.xex 2>$(NULLDEV) diff --git a/targettest/atari/sound.c b/targettest/atari/sound.c new file mode 100644 index 000000000..d1c50e1b4 --- /dev/null +++ b/targettest/atari/sound.c @@ -0,0 +1,20 @@ +/* +** Test program for _sound for atari +** +** January 6 2023 Mariano Domínguez +*/ + +#include +#include +#include +#include + +int main(void) +{ + int i=0; + printf("playing sound \n"); + _sound(1,121,10,15); //voice, pitch, distortion, volume + for(i=0;i<9000;i++); + _sound(1,0,0,0); //silencing, same as Atari Basic + return 0; +}