File: sound_falcon.c

package info (click to toggle)
atari800 0.9.8a-2
  • links: PTS
  • area: contrib
  • in suites: potato, slink
  • size: 1,844 kB
  • ctags: 3,008
  • sloc: ansic: 29,881; asm: 2,142; makefile: 78; sh: 8
file content (173 lines) | stat: -rw-r--r-- 3,548 bytes parent folder | download
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173

#include "config.h"

#ifdef DMASOUND
#include <osbind.h>
#include "pokeysnd.h"

#define FALSE 0
#define TRUE 1

extern int get_cookie(long cookie, long *value);

static char *dsp_buffer1, *dsp_endbuf1;
static char *dsp_buffer2, *dsp_endbuf2;

static sound_enabled = FALSE;

static int dsp_sample_rate = 12517;
static int sndbufsize = 600;
static int AUDCTL = 0x00;
static int AUDF[4] =
{0, 0, 0, 0};
static int AUDC[4] =
{0, 0, 0, 0};

/* Atari DMA sound hardware */
extern void timer_A(void);

#ifndef UBYTE
#define UBYTE	unsigned char
#endif

#define	TIMERA		*(long *)0x134

#define	TACTRL		*(UBYTE *)0xFFFA19
#define	TADATA		*(UBYTE *)0xFFFA1F

#define	IEA			*(UBYTE *)0xFFFA07
#define	ISRA		*(UBYTE *)0xFFFA0F
#define	IMA			*(UBYTE *)0xFFFA13
#define IVECTOR		*(UBYTE *)0xFFFA17

long old_timer_A;
UBYTE old_tactrl, old_tadata, old_ivector, old_iea, old_isra, old_ima;
short *DMActrlptr = (short *) 0xff8900;

void Setbuffer(long bufbeg, long bufsize)
{
	long bufend = bufbeg + bufsize;
	DMActrlptr[1] = (bufbeg >> 16) & 0xff;
	DMActrlptr[2] = (bufbeg >> 8) & 0xff;
	DMActrlptr[3] = bufbeg & 0xff;
	DMActrlptr[7] = (bufend >> 16) & 0xff;
	DMActrlptr[8] = (bufend >> 8) & 0xff;
	DMActrlptr[9] = bufend & 0xff;
}

void timer_A_v_C(void)
{
	static int first = FALSE;	/* start computing second buffer */

	if (first) {
		Setbuffer(dsp_buffer1, sndbufsize);		/* set next DMA buffer */
		Pokey_process(dsp_buffer1, sndbufsize);		/* quickly compute it */
		first = FALSE;
	}
	else {
		Setbuffer(dsp_buffer2, sndbufsize);
		Pokey_process(dsp_buffer2, sndbufsize);
		first = TRUE;
	}
}

void MFP_IRQ_on(void)
{
	Setbuffer(dsp_buffer1, sndbufsize);		/* start playing first buffer */
	DMActrlptr[0x10] = 0x80 | 1;	/* mono 12 kHz */
	DMActrlptr[0] = 0x400 | 3;	/* play until stopped, interrupt at end of frame */

	Mfpint(13, timer_A);
	Xbtimer(0, 8, 1, timer_A);	/* event count mode, interrupt after 1st frame */
	IVECTOR &= ~(1 << 3);		/* turn on AEO */
	Jenabint(13);
}

void MFP_IRQ_off(void)
{
	Jdisint(13);
	DMActrlptr[0] = 0;			/* stop playing */
}

void Sound_Initialise(int *argc, char *argv[])
{
	int i, j;

	for (i = j = 1; i < *argc; i++) {
		if (strcmp(argv[i], "-sound") == 0)
			sound_enabled = TRUE;
		else if (strcmp(argv[i], "-nosound") == 0)
			sound_enabled = FALSE;
		else
			argv[j++] = argv[i];
	}

	*argc = j;

	/* test of Sound hardware availability */
	if (sound_enabled) {
		long val;

		if (get_cookie('_SND', &val)) {
			if (!(val & 2))
				sound_enabled = FALSE;	/* Sound DMA hardware is missing */
		}
		else
			sound_enabled = FALSE;	/* CookieJar is missing */
	}

	if (sound_enabled) {
		dsp_buffer1 = (char *) Mxalloc(2 * sndbufsize, 0);
		dsp_buffer2 = dsp_endbuf1 = dsp_buffer1 + sndbufsize;
		dsp_endbuf2 = dsp_buffer2 + sndbufsize;
		memset(dsp_buffer1, 0, sndbufsize);
		memset(dsp_buffer2, 127, sndbufsize);
		if (!dsp_buffer1) {
			printf("can't allocate sound buffer\n");
			exit(1);
		}

		Pokey_sound_init(FREQ_17_EXACT, dsp_sample_rate, 1);
		Supexec(MFP_IRQ_on);
	}
}

void Sound_Exit(void)
{
	if (sound_enabled) {
		Supexec(MFP_IRQ_off);
		Mfree(dsp_buffer1);
	}
}

void Atari_AUDC(int channel, int byte)
{
	channel--;
	Update_pokey_sound(0xd201 + channel + channel, byte, 0, 4);
}

void Atari_AUDF(int channel, int byte)
{
	channel--;
	Update_pokey_sound(0xd200 + channel + channel, byte, 0, 4);
}

void Atari_AUDCTL(int byte)
{
	Update_pokey_sound(0xd208, byte, 0, 4);
}

#else
void Atari_AUDC(int channel, int byte)
{
}

void Atari_AUDF(int channel, int byte)
{
}

void Atari_AUDCTL(int byte)
{
}

#endif