forked from pete-gordon/oricutron
-
Notifications
You must be signed in to change notification settings - Fork 0
/
8912.h
124 lines (108 loc) · 3.34 KB
/
8912.h
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
/*
** Oricutron
** Copyright (C) 2009-2014 Peter Gordon
**
** This program is free software; you can redistribute it and/or
** modify it under the terms of the GNU General Public License
** as published by the Free Software Foundation, version 2
** of the License.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
**
** General Instruments AY-8912 emulation (including oric keyboard emulation)
*/
// Integer fraction bits to use when mapping
// clock cycles to audio samples
#define FPBITS 10
// Audio buffer size
#ifndef AUDIO_BUFLEN
#define AUDIO_BUFLEN 2048
#endif
#define WRITELOG_SIZE (AUDIO_BUFLEN*12)
#define TAPELOG_SIZE (AUDIO_BUFLEN)
#define CYCLESPERSECOND (312*64*50)
// We now calculate this using the actual obtained frequency
//#define CYCLESPERSAMPLE ((CYCLESPERSECOND<<FPBITS)/AUDIO_FREQ)
// GI addressing
#define AYBMB_BC1 0
#define AYBMF_BC1 (1<<AYBMB_BC1)
#define AYBMB_BDIR 1
#define AYBMF_BDIR (1<<AYBMB_BDIR)
// 8912 registers
enum
{
AY_CHA_PER_L = 0,
AY_CHA_PER_H,
AY_CHB_PER_L,
AY_CHB_PER_H,
AY_CHC_PER_L,
AY_CHC_PER_H,
AY_NOISE_PER,
AY_STATUS,
AY_CHA_AMP,
AY_CHB_AMP,
AY_CHC_AMP,
AY_ENV_PER_L,
AY_ENV_PER_H,
AY_ENV_CYCLE,
AY_PORT_A,
NUM_AY_REGS
};
struct aywrite
{
Uint32 cycle;
Uint8 reg;
Uint8 val;
};
struct tnchange
{
Uint32 cycle;
Uint8 val;
};
struct ay8912
{
Uint8 bmode, creg;
Uint8 regs[NUM_AY_REGS], eregs[NUM_AY_REGS];
SDL_bool keystates[8], newnoise;
SDL_bool soundon;
SDL_bool soundloopon;
Uint32 toneper[3], noiseper, envper;
Uint16 tonebit[3], noisebit[3], vol[3], newout;
Sint32 ct[3], ctn, cte;
Uint32 tonepos[3], tonestep[3];
Sint32 sign[3], out[3], envpos;
unsigned char *envtab;
struct machine *oric;
Uint32 currnoise, rndrack;
Sint16 output;
Sint16 tapeout;
Uint32 ccycle, lastcyc, ccyc;
Uint32 keybitdelay, currkeyoffs;
SDL_bool audiolocked;
SDL_bool do_logcycle_reset;
Sint32 logged, tlogged;
Uint32 logcycle, newlogcycle;
struct aywrite writelog[WRITELOG_SIZE];
struct tnchange tapelog[TAPELOG_SIZE];
};
void queuekeys( char *str );
SDL_bool ay_init( struct ay8912 *ay, struct machine *oric );
void ay_callback( void *dummy, Sint8 *stream, int length );
void ay_ticktock( struct ay8912 *ay, int cycles );
void ay_update_keybits( struct ay8912 *ay );
void ay_keypress( struct ay8912 *ay, SDL_COMPAT_KEY key, SDL_bool down );
void ay_set_bc1( struct ay8912 *ay, unsigned char state );
void ay_set_bdir( struct ay8912 *ay, unsigned char state );
void ay_set_bcmode( struct ay8912 *ay, unsigned char bc1, unsigned char bdir );
void ay_modeset( struct ay8912 *ay );
void ay_lockaudio( struct ay8912 *ay );
void ay_unlockaudio( struct ay8912 *ay );
void ay_flushlog( struct ay8912 *ay );
void ay_soundloop( struct ay8912 *ay, unsigned char oldval, unsigned char newval);