Search
lxdream.org :: lxdream/src/aica/aica.c
lxdream 0.9.1
released Jun 29
Download Now
filename src/aica/aica.c
changeset 1067:d3c00ffccfcd
prev1024:c67f2d61ab97
prev934:3acd3b3ee6d1
author nkeynes
date Sun Jul 05 13:54:48 2009 +1000 (12 years ago)
permissions -rw-r--r--
last change No-op merge lxdream-mem to tip to remove head (Long since merged in
actuality)
file annotate diff log raw
nkeynes@11
     1
/**
nkeynes@561
     2
 * $Id$
nkeynes@11
     3
 * 
nkeynes@465
     4
 * This module implements the AICA's IO interfaces, as well
nkeynes@465
     5
 * as providing the core AICA module to the system.
nkeynes@11
     6
 *
nkeynes@11
     7
 * Copyright (c) 2005 Nathan Keynes.
nkeynes@11
     8
 *
nkeynes@11
     9
 * This program is free software; you can redistribute it and/or modify
nkeynes@11
    10
 * it under the terms of the GNU General Public License as published by
nkeynes@11
    11
 * the Free Software Foundation; either version 2 of the License, or
nkeynes@11
    12
 * (at your option) any later version.
nkeynes@11
    13
 *
nkeynes@11
    14
 * This program is distributed in the hope that it will be useful,
nkeynes@11
    15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
nkeynes@11
    16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
nkeynes@11
    17
 * GNU General Public License for more details.
nkeynes@11
    18
 */
nkeynes@11
    19
nkeynes@35
    20
#define MODULE aica_module
nkeynes@35
    21
nkeynes@131
    22
#include <time.h>
nkeynes@11
    23
#include "dream.h"
nkeynes@66
    24
#include "dreamcast.h"
nkeynes@15
    25
#include "mem.h"
nkeynes@106
    26
#include "aica/aica.h"
nkeynes@61
    27
#include "armcore.h"
nkeynes@106
    28
#include "aica/audio.h"
nkeynes@11
    29
#define MMIO_IMPL
nkeynes@11
    30
#include "aica.h"
nkeynes@11
    31
nkeynes@11
    32
MMIO_REGION_READ_DEFFN( AICA0 )
nkeynes@11
    33
MMIO_REGION_READ_DEFFN( AICA1 )
nkeynes@975
    34
MMIO_REGION_READ_DEFSUBFNS(AICA0)
nkeynes@975
    35
MMIO_REGION_READ_DEFSUBFNS(AICA1)
nkeynes@975
    36
MMIO_REGION_READ_DEFSUBFNS(AICA2)
nkeynes@975
    37
MMIO_REGION_READ_DEFSUBFNS(AICARTC)
nkeynes@11
    38
nkeynes@23
    39
void aica_init( void );
nkeynes@23
    40
void aica_reset( void );
nkeynes@23
    41
void aica_start( void );
nkeynes@23
    42
void aica_stop( void );
nkeynes@35
    43
void aica_save_state( FILE *f );
nkeynes@35
    44
int aica_load_state( FILE *f );
nkeynes@30
    45
uint32_t aica_run_slice( uint32_t );
nkeynes@23
    46
nkeynes@23
    47
struct dreamcast_module aica_module = { "AICA", aica_init, aica_reset, 
nkeynes@736
    48
        aica_start, aica_run_slice, aica_stop,
nkeynes@736
    49
        aica_save_state, aica_load_state };
nkeynes@15
    50
nkeynes@465
    51
struct aica_state_struct {
nkeynes@465
    52
    uint32_t time_of_day;
nkeynes@465
    53
    /**
nkeynes@465
    54
     * Keep track of what we've done so far this second, to try to keep the
nkeynes@465
    55
     * precision of samples/second.
nkeynes@465
    56
     */
nkeynes@465
    57
    uint32_t samples_done;
nkeynes@465
    58
    uint32_t nanosecs_done;
nkeynes@465
    59
    /**
nkeynes@465
    60
     * Event (IRQ) state
nkeynes@465
    61
     */
nkeynes@465
    62
    int event_pending;
nkeynes@465
    63
    int clear_count;
nkeynes@465
    64
};
nkeynes@465
    65
nkeynes@465
    66
static struct aica_state_struct aica_state;
nkeynes@465
    67
nkeynes@173
    68
nkeynes@11
    69
/**
nkeynes@11
    70
 * Initialize the AICA subsystem. Note requires that 
nkeynes@11
    71
 */
nkeynes@11
    72
void aica_init( void )
nkeynes@11
    73
{
nkeynes@11
    74
    register_io_regions( mmio_list_spu );
nkeynes@11
    75
    MMIO_NOTRACE(AICA0);
nkeynes@11
    76
    MMIO_NOTRACE(AICA1);
nkeynes@66
    77
    aica_reset();
nkeynes@11
    78
}
nkeynes@11
    79
nkeynes@11
    80
void aica_reset( void )
nkeynes@11
    81
{
nkeynes@35
    82
    arm_reset();
nkeynes@465
    83
    aica_state.time_of_day = 0x5bfc8900;
nkeynes@465
    84
    aica_state.samples_done = 0;
nkeynes@465
    85
    aica_state.nanosecs_done = 0;
nkeynes@465
    86
    aica_state.event_pending = 0;
nkeynes@465
    87
    aica_state.clear_count = 0;
nkeynes@736
    88
    //    aica_event(2); /* Pre-deliver a timer interrupt */
nkeynes@11
    89
}
nkeynes@11
    90
nkeynes@23
    91
void aica_start( void )
nkeynes@23
    92
{
nkeynes@1024
    93
    audio_start_driver();
nkeynes@23
    94
}
nkeynes@23
    95
nkeynes@30
    96
uint32_t aica_run_slice( uint32_t nanosecs )
nkeynes@23
    97
{
nkeynes@23
    98
    /* Run arm instructions */
nkeynes@35
    99
    int reset = MMIO_READ( AICA2, AICA_RESET );
nkeynes@66
   100
    if( (reset & 1) == 0 ) { /* Running */
nkeynes@736
   101
        int num_samples = (int)((uint64_t)AICA_SAMPLE_RATE * (aica_state.nanosecs_done + nanosecs) / 1000000000) - aica_state.samples_done;
nkeynes@736
   102
        num_samples = arm_run_slice( num_samples );
nkeynes@736
   103
        audio_mix_samples( num_samples );
nkeynes@73
   104
nkeynes@736
   105
        aica_state.samples_done += num_samples;
nkeynes@736
   106
        aica_state.nanosecs_done += nanosecs;
nkeynes@35
   107
    }
nkeynes@465
   108
    if( aica_state.nanosecs_done > 1000000000 ) {
nkeynes@736
   109
        aica_state.samples_done -= AICA_SAMPLE_RATE;
nkeynes@736
   110
        aica_state.nanosecs_done -= 1000000000;
nkeynes@736
   111
        aica_state.time_of_day++;
nkeynes@73
   112
    }
nkeynes@43
   113
    return nanosecs;
nkeynes@23
   114
}
nkeynes@23
   115
nkeynes@23
   116
void aica_stop( void )
nkeynes@23
   117
{
nkeynes@1024
   118
    audio_stop_driver();
nkeynes@23
   119
}
nkeynes@23
   120
nkeynes@35
   121
void aica_save_state( FILE *f )
nkeynes@35
   122
{
nkeynes@465
   123
    fwrite( &aica_state, sizeof(struct aica_state_struct), 1, f );
nkeynes@35
   124
    arm_save_state( f );
nkeynes@465
   125
    audio_save_state(f);
nkeynes@35
   126
}
nkeynes@35
   127
nkeynes@35
   128
int aica_load_state( FILE *f )
nkeynes@35
   129
{
nkeynes@465
   130
    fread( &aica_state, sizeof(struct aica_state_struct), 1, f );
nkeynes@465
   131
    arm_load_state( f );
nkeynes@465
   132
    return audio_load_state(f);
nkeynes@35
   133
}
nkeynes@35
   134
nkeynes@61
   135
/* Note: This is probably not necessarily technically correct but it should
nkeynes@61
   136
 * work in the meantime.
nkeynes@61
   137
 */
nkeynes@61
   138
nkeynes@61
   139
void aica_event( int event )
nkeynes@61
   140
{
nkeynes@465
   141
    if( aica_state.event_pending == 0 )
nkeynes@736
   142
        armr.int_pending |= CPSR_F;
nkeynes@465
   143
    aica_state.event_pending |= (1<<event);
nkeynes@736
   144
nkeynes@61
   145
    int pending = MMIO_READ( AICA2, AICA_IRQ );
nkeynes@61
   146
    if( pending == 0 || event < pending )
nkeynes@736
   147
        MMIO_WRITE( AICA2, AICA_IRQ, event );
nkeynes@61
   148
}
nkeynes@61
   149
nkeynes@61
   150
void aica_clear_event( )
nkeynes@61
   151
{
nkeynes@465
   152
    aica_state.clear_count++;
nkeynes@465
   153
    if( aica_state.clear_count == 4 ) {
nkeynes@736
   154
        int i;
nkeynes@736
   155
        aica_state.clear_count = 0;
nkeynes@61
   156
nkeynes@736
   157
        for( i=0; i<8; i++ ) {
nkeynes@736
   158
            if( aica_state.event_pending & (1<<i) ) {
nkeynes@736
   159
                aica_state.event_pending &= ~(1<<i);
nkeynes@736
   160
                break;
nkeynes@736
   161
            }
nkeynes@736
   162
        }
nkeynes@736
   163
        for( ;i<8; i++ ) {
nkeynes@736
   164
            if( aica_state.event_pending & (1<<i) ) {
nkeynes@736
   165
                MMIO_WRITE( AICA2, AICA_IRQ, i );
nkeynes@736
   166
                break;
nkeynes@736
   167
            }
nkeynes@736
   168
        }
nkeynes@736
   169
        if( aica_state.event_pending == 0 )
nkeynes@736
   170
            armr.int_pending &= ~CPSR_F;
nkeynes@61
   171
    }
nkeynes@61
   172
}
nkeynes@66
   173
nkeynes@86
   174
void aica_enable( void )
nkeynes@86
   175
{
nkeynes@86
   176
    mmio_region_AICA2_write( AICA_RESET, MMIO_READ(AICA2,AICA_RESET) & ~1 );
nkeynes@86
   177
}
nkeynes@86
   178
nkeynes@11
   179
/** Channel register structure:
nkeynes@43
   180
 * 00  4  Channel config
nkeynes@43
   181
 * 04  4  Waveform address lo (16 bits)
nkeynes@11
   182
 * 08  4  Loop start address
nkeynes@11
   183
 * 0C  4  Loop end address
nkeynes@11
   184
 * 10  4  Volume envelope
nkeynes@43
   185
 * 14  4  Init to 0x1F
nkeynes@43
   186
 * 18  4  Frequency (floating point)
nkeynes@43
   187
 * 1C  4  ?? 
nkeynes@43
   188
 * 20  4  ??
nkeynes@11
   189
 * 24  1  Pan
nkeynes@11
   190
 * 25  1  ??
nkeynes@11
   191
 * 26  
nkeynes@11
   192
 * 27  
nkeynes@11
   193
 * 28  1  ??
nkeynes@11
   194
 * 29  1  Volume
nkeynes@11
   195
 * 2C
nkeynes@11
   196
 * 30
nkeynes@431
   197
 */
nkeynes@11
   198
nkeynes@11
   199
/* Write to channels 0-31 */
nkeynes@929
   200
MMIO_REGION_WRITE_FN( AICA0, reg, val )
nkeynes@11
   201
{
nkeynes@929
   202
    reg &= 0xFFF;
nkeynes@35
   203
    MMIO_WRITE( AICA0, reg, val );
nkeynes@66
   204
    aica_write_channel( reg >> 7, reg % 128, val );
nkeynes@37
   205
    //    DEBUG( "AICA0 Write %08X => %08X", val, reg );
nkeynes@11
   206
}
nkeynes@11
   207
nkeynes@11
   208
/* Write to channels 32-64 */
nkeynes@929
   209
MMIO_REGION_WRITE_FN( AICA1, reg, val )
nkeynes@11
   210
{
nkeynes@929
   211
    reg &= 0xFFF;
nkeynes@35
   212
    MMIO_WRITE( AICA1, reg, val );
nkeynes@66
   213
    aica_write_channel( (reg >> 7) + 32, reg % 128, val );
nkeynes@37
   214
    // DEBUG( "AICA1 Write %08X => %08X", val, reg );
nkeynes@11
   215
}
nkeynes@11
   216
nkeynes@66
   217
/**
nkeynes@66
   218
 * AICA control registers 
nkeynes@66
   219
 */
nkeynes@929
   220
MMIO_REGION_WRITE_FN( AICA2, reg, val )
nkeynes@11
   221
{
nkeynes@35
   222
    uint32_t tmp;
nkeynes@929
   223
    reg &= 0xFFF;
nkeynes@929
   224
    
nkeynes@35
   225
    switch( reg ) {
nkeynes@35
   226
    case AICA_RESET:
nkeynes@736
   227
        tmp = MMIO_READ( AICA2, AICA_RESET );
nkeynes@736
   228
        if( (tmp & 1) == 1 && (val & 1) == 0 ) {
nkeynes@736
   229
            /* ARM enabled - execute a core reset */
nkeynes@736
   230
            DEBUG( "ARM enabled" );
nkeynes@736
   231
            arm_reset();
nkeynes@736
   232
            aica_state.samples_done = 0;
nkeynes@736
   233
            aica_state.nanosecs_done = 0;
nkeynes@736
   234
        } else if( (tmp&1) == 0 && (val&1) == 1 ) {
nkeynes@736
   235
            DEBUG( "ARM disabled" );
nkeynes@736
   236
        }
nkeynes@736
   237
        MMIO_WRITE( AICA2, AICA_RESET, val );
nkeynes@736
   238
        break;
nkeynes@61
   239
    case AICA_IRQCLEAR:
nkeynes@736
   240
        aica_clear_event();
nkeynes@736
   241
        break;
nkeynes@829
   242
    case AICA_FIFOIN: /* Read-only */
nkeynes@829
   243
        break;
nkeynes@35
   244
    default:
nkeynes@736
   245
        MMIO_WRITE( AICA2, reg, val );
nkeynes@736
   246
        break;
nkeynes@35
   247
    }
nkeynes@11
   248
}
nkeynes@66
   249
nkeynes@929
   250
MMIO_REGION_READ_FN( AICA2, reg )
nkeynes@463
   251
{
nkeynes@463
   252
    audio_channel_t channel;
nkeynes@463
   253
    uint32_t channo;
nkeynes@463
   254
    int32_t val;
nkeynes@929
   255
    reg &= 0xFFF;
nkeynes@463
   256
    switch( reg ) {
nkeynes@463
   257
    case AICA_CHANSTATE:
nkeynes@736
   258
        channo = (MMIO_READ( AICA2, AICA_CHANSEL ) >> 8) & 0x3F;
nkeynes@736
   259
        channel = audio_get_channel(channo);
nkeynes@736
   260
        if( channel->loop == LOOP_LOOPED ) {
nkeynes@736
   261
            val = 0x8000;
nkeynes@736
   262
            channel->loop = LOOP_ON;
nkeynes@736
   263
        } else {
nkeynes@736
   264
            val = 0;
nkeynes@736
   265
        }
nkeynes@736
   266
        return val;
nkeynes@463
   267
    case AICA_CHANPOSN:
nkeynes@736
   268
        channo = (MMIO_READ( AICA2, AICA_CHANSEL ) >> 8) & 0x3F;
nkeynes@736
   269
        channel = audio_get_channel(channo);
nkeynes@736
   270
        return channel->posn;
nkeynes@463
   271
    default:
nkeynes@736
   272
        return MMIO_READ( AICA2, reg );
nkeynes@463
   273
    }
nkeynes@463
   274
}
nkeynes@131
   275
nkeynes@929
   276
MMIO_REGION_READ_FN( AICARTC, reg )
nkeynes@131
   277
{
nkeynes@173
   278
    int32_t rv = 0;
nkeynes@929
   279
    reg &= 0xFFF;
nkeynes@131
   280
    switch( reg ) {
nkeynes@131
   281
    case AICA_RTCHI:
nkeynes@465
   282
        rv = (aica_state.time_of_day >> 16) & 0xFFFF;
nkeynes@736
   283
        break;
nkeynes@131
   284
    case AICA_RTCLO:
nkeynes@736
   285
        rv = aica_state.time_of_day & 0xFFFF;
nkeynes@736
   286
        break;
nkeynes@131
   287
    }
nkeynes@241
   288
    // DEBUG( "Read AICA RTC %d => %08X", reg, rv );
nkeynes@173
   289
    return rv;
nkeynes@131
   290
}
nkeynes@131
   291
nkeynes@929
   292
MMIO_REGION_WRITE_FN( AICARTC, reg, val )
nkeynes@301
   293
{
nkeynes@929
   294
    reg &= 0xFFF;
nkeynes@301
   295
    switch( reg ) {
nkeynes@301
   296
    case AICA_RTCEN:
nkeynes@736
   297
        MMIO_WRITE( AICARTC, reg, val&0x01 );
nkeynes@736
   298
        break;
nkeynes@301
   299
    case AICA_RTCLO:
nkeynes@736
   300
        if( MMIO_READ( AICARTC, AICA_RTCEN ) & 0x01 ) {
nkeynes@736
   301
            aica_state.time_of_day = (aica_state.time_of_day & 0xFFFF0000) | (val & 0xFFFF);
nkeynes@736
   302
        }
nkeynes@736
   303
        break;
nkeynes@301
   304
    case AICA_RTCHI:
nkeynes@736
   305
        if( MMIO_READ( AICARTC, AICA_RTCEN ) & 0x01 ) {
nkeynes@736
   306
            aica_state.time_of_day = (aica_state.time_of_day & 0xFFFF) | (val<<16);
nkeynes@736
   307
            MMIO_WRITE( AICARTC, AICA_RTCEN, 0 );
nkeynes@736
   308
        }
nkeynes@736
   309
        break;
nkeynes@301
   310
    }
nkeynes@301
   311
}
nkeynes@736
   312
nkeynes@66
   313
/**
nkeynes@66
   314
 * Translate the channel frequency to a sample rate. The frequency is a
nkeynes@66
   315
 * 14-bit floating point number, where bits 0..9 is the mantissa,
nkeynes@66
   316
 * 11..14 is the signed exponent (-8 to +7). Bit 10 appears to
nkeynes@66
   317
 * be unused.
nkeynes@66
   318
 *
nkeynes@66
   319
 * @return sample rate in samples per second.
nkeynes@66
   320
 */
nkeynes@66
   321
uint32_t aica_frequency_to_sample_rate( uint32_t freq )
nkeynes@66
   322
{
nkeynes@66
   323
    uint32_t exponent = (freq & 0x3800) >> 11;
nkeynes@66
   324
    uint32_t mantissa = freq & 0x03FF;
nkeynes@82
   325
    uint32_t rate;
nkeynes@66
   326
    if( freq & 0x4000 ) {
nkeynes@736
   327
        /* neg exponent - rate < 44100 */
nkeynes@736
   328
        exponent = 8 - exponent;
nkeynes@736
   329
        rate = (44100 >> exponent) +
nkeynes@736
   330
        ((44100 * mantissa) >> (10+exponent));
nkeynes@66
   331
    } else {
nkeynes@736
   332
        /* pos exponent - rate > 44100 */
nkeynes@736
   333
        rate = (44100 << exponent) +
nkeynes@736
   334
        ((44100 * mantissa) >> (10-exponent));
nkeynes@66
   335
    }
nkeynes@82
   336
    return rate;
nkeynes@66
   337
}
nkeynes@66
   338
nkeynes@434
   339
void aica_start_stop_channels()
nkeynes@434
   340
{
nkeynes@434
   341
    int i;
nkeynes@434
   342
    for( i=0; i<32; i++ ) {
nkeynes@736
   343
        uint32_t val = MMIO_READ( AICA0, i<<7 );
nkeynes@736
   344
        audio_start_stop_channel(i, val&0x4000);
nkeynes@434
   345
    }
nkeynes@434
   346
    for( ; i<64; i++ ) {
nkeynes@736
   347
        uint32_t val = MMIO_READ( AICA1, (i-32)<<7 );
nkeynes@736
   348
        audio_start_stop_channel(i, val&0x4000);
nkeynes@434
   349
    }
nkeynes@434
   350
}
nkeynes@434
   351
nkeynes@82
   352
/**
nkeynes@82
   353
 * Derived directly from Dan Potter's log table
nkeynes@82
   354
 */
nkeynes@82
   355
uint8_t aica_volume_table[256] = {
nkeynes@736
   356
        0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   1,
nkeynes@736
   357
        1,   1,   1,   1,   1,   1,   2,   2,   2,   2,   2,   3,   3,   3,   3,   4,
nkeynes@736
   358
        4,   4,   4,   5,   5,   5,   5,   6,   6,   6,   7,   7,   7,   8,   8,   9,
nkeynes@736
   359
        9,   9,  10,  10,  11,  11,  11,  12,  12,  13,  13,  14,  14,  15,  15,  16,
nkeynes@736
   360
        16,  17,  17,  18,  18,  19,  19,  20,  20,  21,  22,  22,  23,  23,  24,  25,
nkeynes@736
   361
        25,  26,  27,  27,  28,  29,  29,  30,  31,  31,  32,  33,  34,  34,  35,  36,
nkeynes@736
   362
        37,  37,  38,  39,  40,  40,  41,  42,  43,  44,  45,  45,  46,  47,  48,  49,
nkeynes@736
   363
        50,  51,  52,  52,  53,  54,  55,  56,  57,  58,  59,  60,  61,  62,  63,  64,
nkeynes@736
   364
        65,  66,  67,  68,  69,  70,  71,  72,  73,  74,  76,  77,  78,  79,  80,  81,
nkeynes@736
   365
        82,  83,  85,  86,  87,  88,  89,  90,  92,  93,  94,  95,  97,  98,  99, 100,
nkeynes@736
   366
        102, 103, 104, 105, 107, 108, 109, 111, 112, 113, 115, 116, 117, 119, 120, 121,
nkeynes@736
   367
        123, 124, 126, 127, 128, 130, 131, 133, 134, 136, 137, 139, 140, 142, 143, 145,
nkeynes@736
   368
        146, 148, 149, 151, 152, 154, 155, 157, 159, 160, 162, 163, 165, 167, 168, 170,
nkeynes@736
   369
        171, 173, 175, 176, 178, 180, 181, 183, 185, 187, 188, 190, 192, 194, 195, 197,
nkeynes@736
   370
        199, 201, 202, 204, 206, 208, 210, 211, 213, 215, 217, 219, 221, 223, 224, 226,
nkeynes@736
   371
        228, 230, 232, 234, 236, 238, 240, 242, 244, 246, 248, 250, 252, 253, 254, 255 };
nkeynes@82
   372
nkeynes@82
   373
nkeynes@66
   374
void aica_write_channel( int channelNo, uint32_t reg, uint32_t val ) 
nkeynes@66
   375
{
nkeynes@66
   376
    val &= 0x0000FFFF;
nkeynes@66
   377
    audio_channel_t channel = audio_get_channel(channelNo);
nkeynes@66
   378
    switch( reg ) {
nkeynes@66
   379
    case 0x00: /* Config + high address bits*/
nkeynes@736
   380
        channel->start = (channel->start & 0xFFFF) | ((val&0x1F) << 16);
nkeynes@736
   381
        if( val & 0x200 ) 
nkeynes@736
   382
            channel->loop = LOOP_ON;
nkeynes@736
   383
        else 
nkeynes@736
   384
            channel->loop = LOOP_OFF;
nkeynes@736
   385
        switch( (val >> 7) & 0x03 ) {
nkeynes@736
   386
        case 0:
nkeynes@736
   387
            channel->sample_format = AUDIO_FMT_16BIT;
nkeynes@736
   388
            break;
nkeynes@736
   389
        case 1:
nkeynes@736
   390
            channel->sample_format = AUDIO_FMT_8BIT;
nkeynes@736
   391
            break;
nkeynes@736
   392
        case 2:
nkeynes@736
   393
        case 3:
nkeynes@736
   394
            channel->sample_format = AUDIO_FMT_ADPCM;
nkeynes@736
   395
            break;
nkeynes@736
   396
        }
nkeynes@736
   397
        if( val & 0x8000 ) {
nkeynes@736
   398
            aica_start_stop_channels();
nkeynes@736
   399
        }
nkeynes@736
   400
        break;
nkeynes@736
   401
        case 0x04: /* Low 16 address bits */
nkeynes@736
   402
            channel->start = (channel->start & 0x001F0000) | val;
nkeynes@736
   403
            break;
nkeynes@736
   404
        case 0x08: /* Loop start */
nkeynes@736
   405
            channel->loop_start = val;
nkeynes@736
   406
            break;
nkeynes@736
   407
        case 0x0C: /* End */
nkeynes@736
   408
            channel->end = val;
nkeynes@736
   409
            break;
nkeynes@736
   410
        case 0x10: /* Envelope register 1 */
nkeynes@736
   411
            break;
nkeynes@736
   412
        case 0x14: /* Envelope register 2 */
nkeynes@736
   413
            break;
nkeynes@736
   414
        case 0x18: /* Frequency */
nkeynes@736
   415
            channel->sample_rate = aica_frequency_to_sample_rate ( val );
nkeynes@736
   416
            break;
nkeynes@736
   417
        case 0x1C: /* ??? */
nkeynes@736
   418
        case 0x20: /* ??? */
nkeynes@736
   419
        case 0x24: /* Volume? /pan */
nkeynes@736
   420
            val = val & 0x1F;
nkeynes@736
   421
            if( val <= 0x0F ) 
nkeynes@736
   422
                val = 0x0F - val; /* Convert to smooth pan over 0..31 */
nkeynes@736
   423
            channel->pan = val;
nkeynes@736
   424
            break;
nkeynes@736
   425
        case 0x28: /* Volume */
nkeynes@736
   426
            // This isn't remotely correct, but it will have to suffice until I have
nkeynes@736
   427
            // time to figure out what's actually going on here... 
nkeynes@736
   428
            channel->vol = aica_volume_table[max((val & 0xFF),((val>>8)&0xFF))];
nkeynes@736
   429
            break;
nkeynes@736
   430
        default: /* ??? */
nkeynes@736
   431
            break;
nkeynes@66
   432
    }
nkeynes@66
   433
nkeynes@66
   434
}
.