src/audio/dc/aica.c
author Sam Lantinga <slouken@libsdl.org>
Thu, 02 Mar 2006 13:16:02 +0000
changeset 1461 11134dc42da8
parent 509 dad72daf44b3
child 1662 782fd950bd46
child 1895 c121d94672cb
permissions -rw-r--r--
Updated for Dreamcast KOS June 2005 snapshot: http://cadcdev.sourceforge.net/svn/snapshots/ http://gamedev.allusion.net/softprj/kos/dcsetup.php
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
509
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     1
/* This file is part of the Dreamcast function library.
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     2
 * Please see libdream.c for further details.
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     3
 *
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     4
 * (c)2000 Dan Potter
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     5
 * modify BERO
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     6
 */
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     7
#include "aica.h"
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     8
1461
11134dc42da8 Updated for Dreamcast KOS June 2005 snapshot:
Sam Lantinga <slouken@libsdl.org>
parents: 509
diff changeset
     9
#include <arch/irq.h>
11134dc42da8 Updated for Dreamcast KOS June 2005 snapshot:
Sam Lantinga <slouken@libsdl.org>
parents: 509
diff changeset
    10
#include <dc/spu.h>
11134dc42da8 Updated for Dreamcast KOS June 2005 snapshot:
Sam Lantinga <slouken@libsdl.org>
parents: 509
diff changeset
    11
509
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    12
/* #define dc_snd_base ((volatile unsigned char *)0x00800000) */ /* arm side */
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    13
#define dc_snd_base ((volatile unsigned char *)0xa0700000) /* dc side */
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    14
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    15
/* Some convienence macros */
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    16
#define	SNDREGADDR(x)	(0xa0700000 + (x))
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    17
#define	CHNREGADDR(ch,x)	SNDREGADDR(0x80*(ch)+(x))
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    18
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    19
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    20
#define SNDREG32(x)	(*(volatile unsigned long *)SNDREGADDR(x))
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    21
#define SNDREG8(x)	(*(volatile unsigned char *)SNDREGADDR(x))
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    22
#define CHNREG32(ch, x) (*(volatile unsigned long *)CHNREGADDR(ch,x))
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    23
#define CHNREG8(ch, x)	(*(volatile unsigned long *)CHNREGADDR(ch,x))
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    24
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    25
#define G2_LOCK(OLD) \
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    26
	do { \
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    27
		if (!irq_inside_int()) \
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    28
			OLD = irq_disable(); \
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    29
		/* suspend any G2 DMA here... */ \
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    30
		while((*(volatile unsigned int *)0xa05f688c) & 0x20) \
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    31
			; \
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    32
	} while(0)
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    33
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    34
#define G2_UNLOCK(OLD) \
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    35
	do { \
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    36
		/* resume any G2 DMA here... */ \
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    37
		if (!irq_inside_int()) \
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    38
			irq_restore(OLD); \
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    39
	} while(0)
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    40
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    41
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    42
void aica_init() {
1461
11134dc42da8 Updated for Dreamcast KOS June 2005 snapshot:
Sam Lantinga <slouken@libsdl.org>
parents: 509
diff changeset
    43
	int i, j, old = 0;
509
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    44
	
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    45
	/* Initialize AICA channels */	
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    46
	G2_LOCK(old);
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    47
	SNDREG32(0x2800) = 0x0000;
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    48
	
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    49
	for (i=0; i<64; i++) {
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    50
		for (j=0; j<0x80; j+=4) {
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    51
			if ((j&31)==0) g2_fifo_wait();
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    52
			CHNREG32(i, j) = 0;
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    53
		}
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    54
		g2_fifo_wait();
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    55
		CHNREG32(i,0) = 0x8000;
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    56
		CHNREG32(i,20) = 0x1f;
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    57
	}
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    58
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    59
	SNDREG32(0x2800) = 0x000f;
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    60
	g2_fifo_wait();
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    61
	G2_UNLOCK(old);
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    62
}
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    63
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    64
/* Translates a volume from linear form to logarithmic form (required by
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    65
   the AICA chip */
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    66
/* int logs[] = {
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    67
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    68
0, 40, 50, 58, 63, 68, 73, 77, 80, 83, 86, 89, 92, 94, 97, 99, 101, 103,
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    69
105, 107, 109, 111, 112, 114, 116, 117, 119, 120, 122, 123, 125, 126, 127,
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    70
129, 130, 131, 133, 134, 135, 136, 137, 139, 140, 141, 142, 143, 144, 145,
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    71
146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 156, 157, 158, 159,
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    72
160, 161, 162, 162, 163, 164, 165, 166, 166, 167, 168, 169, 170, 170, 171,
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    73
172, 172, 173, 174, 175, 175, 176, 177, 177, 178, 179, 180, 180, 181, 182,
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    74
182, 183, 183, 184, 185, 185, 186, 187, 187, 188, 188, 189, 190, 190, 191,
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    75
191, 192, 193, 193, 194, 194, 195, 196, 196, 197, 197, 198, 198, 199, 199,
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    76
200, 201, 201, 202, 202, 203, 203, 204, 204, 205, 205, 206, 206, 207, 207,
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    77
208, 208, 209, 209, 210, 210, 211, 211, 212, 212, 213, 213, 214, 214, 215,
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    78
215, 216, 216, 217, 217, 217, 218, 218, 219, 219, 220, 220, 221, 221, 222,
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    79
222, 222, 223, 223, 224, 224, 225, 225, 225, 226, 226, 227, 227, 228, 228,
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    80
228, 229, 229, 230, 230, 230, 231, 231, 232, 232, 232, 233, 233, 234, 234,
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    81
234, 235, 235, 236, 236, 236, 237, 237, 238, 238, 238, 239, 239, 240, 240,
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    82
240, 241, 241, 241, 242, 242, 243, 243, 243, 244, 244, 244, 245, 245, 245,
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    83
246, 246, 247, 247, 247, 248, 248, 248, 249, 249, 249, 250, 250, 250, 251,
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    84
251, 251, 252, 252, 252, 253, 253, 253, 254, 254, 254, 255
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    85
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    86
}; */
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    87
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    88
const static unsigned char logs[] = {
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    89
	0, 15, 22, 27, 31, 35, 39, 42, 45, 47, 50, 52, 55, 57, 59, 61,
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    90
	63, 65, 67, 69, 71, 73, 74, 76, 78, 79, 81, 82, 84, 85, 87, 88,
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    91
	90, 91, 92, 94, 95, 96, 98, 99, 100, 102, 103, 104, 105, 106,
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    92
	108, 109, 110, 111, 112, 113, 114, 116, 117, 118, 119, 120, 121,
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    93
	122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134,
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    94
	135, 136, 137, 138, 138, 139, 140, 141, 142, 143, 144, 145, 146,
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    95
	146, 147, 148, 149, 150, 151, 152, 152, 153, 154, 155, 156, 156,
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    96
	157, 158, 159, 160, 160, 161, 162, 163, 164, 164, 165, 166, 167,
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    97
	167, 168, 169, 170, 170, 171, 172, 173, 173, 174, 175, 176, 176,
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    98
	177, 178, 178, 179, 180, 181, 181, 182, 183, 183, 184, 185, 185,
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    99
	186, 187, 187, 188, 189, 189, 190, 191, 191, 192, 193, 193, 194,
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   100
	195, 195, 196, 197, 197, 198, 199, 199, 200, 200, 201, 202, 202,
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   101
	203, 204, 204, 205, 205, 206, 207, 207, 208, 209, 209, 210, 210,
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   102
	211, 212, 212, 213, 213, 214, 215, 215, 216, 216, 217, 217, 218,
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   103
	219, 219, 220, 220, 221, 221, 222, 223, 223, 224, 224, 225, 225,
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   104
	226, 227, 227, 228, 228, 229, 229, 230, 230, 231, 232, 232, 233,
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   105
	233, 234, 234, 235, 235, 236, 236, 237, 237, 238, 239, 239, 240,
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   106
	240, 241, 241, 242, 242, 243, 243, 244, 244, 245, 245, 246, 246,
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   107
	247, 247, 248, 248, 249, 249, 250, 250, 251, 251, 252, 252, 253, 254, 255
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   108
};
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   109
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   110
/* For the moment this is going to have to suffice, until we really
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   111
   figure out what these mean. */
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   112
#define AICA_PAN(x) ((x)==0x80?(0):((x)<0x80?(0x1f):(0x0f)))
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   113
#define AICA_VOL(x) (0xff - logs[128 + (((x) & 0xff) / 2)])
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   114
//#define AICA_VOL(x) (0xff - logs[x&255])
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   115
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   116
static inline unsigned  AICA_FREQ(unsigned freq)	{
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   117
	unsigned long freq_lo, freq_base = 5644800;
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   118
	int freq_hi = 7;
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   119
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   120
	/* Need to convert frequency to floating point format
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   121
	   (freq_hi is exponent, freq_lo is mantissa)
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   122
	   Formula is ferq = 44100*2^freq_hi*(1+freq_lo/1024) */
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   123
	while (freq < freq_base && freq_hi > -8) {
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   124
		freq_base >>= 1;
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   125
		--freq_hi;
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   126
	}
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   127
	while (freq < freq_base && freq_hi > -8) {
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   128
		freq_base >>= 1;
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   129
		freq_hi--;
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   130
	}
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   131
	freq_lo = (freq<<10) / freq_base;
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   132
	return (freq_hi << 11) | (freq_lo & 1023);
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   133
}
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   134
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   135
/* Sets up a sound channel completely. This is generally good if you want
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   136
   a quick and dirty way to play notes. If you want a more comprehensive
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   137
   set of routines (more like PC wavetable cards) see below.
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   138
   
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   139
   ch is the channel to play on (0 - 63)
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   140
   smpptr is the pointer to the sound data; if you're running off the
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   141
     SH4, then this ought to be (ptr - 0xa0800000); otherwise it's just
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   142
     ptr. Basically, it's an offset into sound ram.
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   143
   mode is one of the mode constants (16 bit, 8 bit, ADPCM)
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   144
   nsamp is the number of samples to play (not number of bytes!)
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   145
   freq is the sampling rate of the sound
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   146
   vol is the volume, 0 to 0xff (0xff is louder)
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   147
   pan is a panning constant -- 0 is left, 128 is center, 255 is right.
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   148
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   149
   This routine (and the similar ones) owe a lot to Marcus' sound example -- 
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   150
   I hadn't gotten quite this far into dissecting the individual regs yet. */
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   151
void aica_play(int ch,int mode,unsigned long smpptr,int loopst,int loopend,int freq,int vol,int pan,int loopflag) {
1461
11134dc42da8 Updated for Dreamcast KOS June 2005 snapshot:
Sam Lantinga <slouken@libsdl.org>
parents: 509
diff changeset
   152
/*	int i;
11134dc42da8 Updated for Dreamcast KOS June 2005 snapshot:
Sam Lantinga <slouken@libsdl.org>
parents: 509
diff changeset
   153
*/
509
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   154
	int val;
1461
11134dc42da8 Updated for Dreamcast KOS June 2005 snapshot:
Sam Lantinga <slouken@libsdl.org>
parents: 509
diff changeset
   155
	int old = 0;
509
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   156
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   157
	/* Stop the channel (if it's already playing) */
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   158
	aica_stop(ch);
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   159
	/* doesn't seem to be needed, but it's here just in case */
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   160
/*
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   161
	for (i=0; i<256; i++) {
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   162
		asm("nop");
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   163
		asm("nop");
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   164
		asm("nop");
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   165
		asm("nop");
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   166
	}
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   167
*/
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   168
	G2_LOCK(old);
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   169
	/* Envelope setup. The first of these is the loop point,
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   170
	   e.g., where the sample starts over when it loops. The second
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   171
	   is the loop end. This is the full length of the sample when
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   172
	   you are not looping, or the loop end point when you are (though
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   173
	   storing more than that is a waste of memory if you're not doing
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   174
	   volume enveloping). */
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   175
	CHNREG32(ch, 8) = loopst & 0xffff;
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   176
	CHNREG32(ch, 12) = loopend & 0xffff;
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   177
	
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   178
	/* Write resulting values */
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   179
	CHNREG32(ch, 24) = AICA_FREQ(freq);
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   180
	
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   181
	/* Set volume, pan, and some other things that we don't know what
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   182
	   they do =) */
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   183
	CHNREG32(ch, 36) = AICA_PAN(pan) | (0xf<<8);
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   184
	/* Convert the incoming volume and pan into hardware values */
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   185
	/* Vol starts at zero so we can ramp */
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   186
	vol = AICA_VOL(vol);
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   187
	CHNREG32(ch, 40) = 0x24 | (vol<<8);
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   188
	/* Convert the incoming volume and pan into hardware values */
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   189
	/* Vol starts at zero so we can ramp */
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   190
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   191
	/* If we supported volume envelopes (which we don't yet) then
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   192
	   this value would set that up. The top 4 bits determine the
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   193
	   envelope speed. f is the fastest, 1 is the slowest, and 0
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   194
	   seems to be an invalid value and does weird things). The
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   195
	   default (below) sets it into normal mode (play and terminate/loop).
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   196
	CHNREG32(ch, 16) = 0xf010;
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   197
	*/
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   198
	CHNREG32(ch, 16) = 0x1f;	/* No volume envelope */
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   199
	
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   200
	
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   201
	/* Set sample format, buffer address, and looping control. If
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   202
	   0x0200 mask is set on reg 0, the sample loops infinitely. If
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   203
	   it's not set, the sample plays once and terminates. We'll
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   204
	   also set the bits to start playback here. */
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   205
	CHNREG32(ch, 4) = smpptr & 0xffff;
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   206
	val = 0xc000 | 0x0000 | (mode<<7) | (smpptr >> 16);
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   207
	if (loopflag) val|=0x200;
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   208
	
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   209
	CHNREG32(ch, 0) = val;
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   210
	
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   211
	G2_UNLOCK(old);
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   212
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   213
	/* Enable playback */
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   214
	/* CHNREG32(ch, 0) |= 0xc000; */
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   215
	g2_fifo_wait();
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   216
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   217
#if 0
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   218
	for (i=0xff; i>=vol; i--) {
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   219
		if ((i&7)==0) g2_fifo_wait();
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   220
		CHNREG32(ch, 40) =  0x24 | (i<<8);;
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   221
	}
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   222
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   223
	g2_fifo_wait();
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   224
#endif
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   225
}
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   226
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   227
/* Stop the sound on a given channel */
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   228
void aica_stop(int ch) {
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   229
	g2_write_32(CHNREGADDR(ch, 0),(g2_read_32(CHNREGADDR(ch, 0)) & ~0x4000) | 0x8000);
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   230
	g2_fifo_wait();
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   231
}
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   232
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   233
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   234
/* The rest of these routines can change the channel in mid-stride so you
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   235
   can do things like vibrato and panning effects. */
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   236
   
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   237
/* Set channel volume */
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   238
void aica_vol(int ch,int vol) {
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   239
//	g2_write_8(CHNREGADDR(ch, 41),AICA_VOL(vol));
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   240
	g2_write_32(CHNREGADDR(ch, 40),(g2_read_32(CHNREGADDR(ch, 40))&0xffff00ff)|(AICA_VOL(vol)<<8) );
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   241
	g2_fifo_wait();
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   242
}
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   243
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   244
/* Set channel pan */
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   245
void aica_pan(int ch,int pan) {
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   246
//	g2_write_8(CHNREGADDR(ch, 36),AICA_PAN(pan));
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   247
	g2_write_32(CHNREGADDR(ch, 36),(g2_read_32(CHNREGADDR(ch, 36))&0xffffff00)|(AICA_PAN(pan)) );
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   248
	g2_fifo_wait();
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   249
}
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   250
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   251
/* Set channel frequency */
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   252
void aica_freq(int ch,int freq) {
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   253
	g2_write_32(CHNREGADDR(ch, 24),AICA_FREQ(freq));
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   254
	g2_fifo_wait();
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   255
}
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   256
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   257
/* Get channel position */
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   258
int aica_get_pos(int ch) {
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   259
#if 1
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   260
	/* Observe channel ch */
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   261
	g2_write_32(SNDREGADDR(0x280c),(g2_read_32(SNDREGADDR(0x280c))&0xffff00ff) | (ch<<8));
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   262
	g2_fifo_wait();
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   263
	/* Update position counters */
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   264
	return g2_read_32(SNDREGADDR(0x2814)) & 0xffff;
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   265
#else
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   266
	/* Observe channel ch */
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   267
	g2_write_8(SNDREGADDR(0x280d),ch);
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   268
	/* Update position counters */
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   269
	return g2_read_32(SNDREGADDR(0x2814)) & 0xffff;
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   270
#endif
dad72daf44b3 Added initial support for Dreamcast (thanks HERO!)
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   271
}