aboutsummaryrefslogtreecommitdiff
path: root/sounds.c
blob: aee73190a341e20408c2e3db7596b72ddf54f564 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/* Sounds for Taipan! Atari 800 port.

	Made by capturing the Apple II audio and taking wild guesses,
	then refining them.

	I'm not shooting for Atari sounds that are identical to the
	Apple ones: (a) it's impossible anyway, and (b) the Apple
	sounds are a bit harsh to the ear. Hopefully these sound
	a little smoother while still being pretty close.
*/

#include <atari.h>
#include <peekpoke.h>

/* to build standalone xex that just plays the 3 sounds:
	cl65 -DTESTXEX -t atari -o sounds.xex sounds.c 
*/
#ifdef TESTXEX
#include <stdio.h>

void jsleep(unsigned int j) {
	POKE(20,0);
	while(PEEK(20) < j)
		;
}
#else
extern void __fastcall__ jsleep(unsigned int j);
#endif

void init_sound(void) {
	/* init POKEY audio */
	POKEY_WRITE.audctl = 0;
	POKEY_WRITE.skctl = 3;
	POKEY_WRITE.audc1 = 0xaa; /* SOUND 0,x,10,10 */
}

void stop_sound(void) {
	POKEY_WRITE.audc1 = 0x00; /* SOUND 0,x,0,0 */
}

void bad_joss_sound() {
	unsigned char i;

	init_sound();
	for(i=0; i<10; i++) {
		POKEY_WRITE.audf1 = 80-i*8;
		jsleep(1);
	}
	stop_sound();
}

void good_joss_sound() {
	unsigned char i, j;

	init_sound();
	for(j=0; j<3; j++) {
		for(i=0; i<4; i++) {
			POKEY_WRITE.audf1 = 20-i*5;
			jsleep(2);
		}
	}
	stop_sound();
}

void under_attack_sound() {
	unsigned char i, j;

	init_sound();
	for(j=0; j<3; j++) {
		for(i=0; i<3; i++) {
			POKEY_WRITE.audf1 = 20-i*3;
			jsleep(3);
		}
	}
	stop_sound();
}

#ifdef TESTXEX
int main(void) {
	for(;;) {
		puts("Bad joss, Taipan!");
		bad_joss_sound();
		jsleep(30);

		puts("Good joss, Taipan!");
		good_joss_sound();
		jsleep(30);

		puts("1.0E+97 hostile ships approaching, Taipan!");
		under_attack_sound();
		jsleep(30);
	}

hang: goto hang;
	return 0;
}
#endif