1
0
mirror of https://github.com/cc65/cc65.git synced 2024-06-07 23:29:39 +00:00

Merge pull request #1962 from marianodominguez/feature_add_sound_command

add sound command
This commit is contained in:
Christian Groessler 2023-01-16 17:59:34 +01:00 committed by GitHub
commit c2e8f75bec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 67 additions and 1 deletions

View File

@ -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 */
/*****************************************************************************/

37
libsrc/atari/sound.s Normal file
View File

@ -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

View File

@ -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)

20
targettest/atari/sound.c Normal file
View File

@ -0,0 +1,20 @@
/*
** Test program for _sound for atari
**
** January 6 2023 Mariano Domínguez
*/
#include <stdio.h>
#include <conio.h>
#include <atari.h>
#include <cc65.h>
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;
}