ym2149reg.h revision 1.3.60.1 1 1.3.60.1 skrll /* $NetBSD: ym2149reg.h,v 1.3.60.1 2005/11/10 13:55:32 skrll Exp $ */
2 1.1 leo
3 1.1 leo /*
4 1.1 leo * Copyright (c) 1996 Leo Weppelman.
5 1.1 leo * All rights reserved.
6 1.1 leo *
7 1.1 leo * Redistribution and use in source and binary forms, with or without
8 1.1 leo * modification, are permitted provided that the following conditions
9 1.1 leo * are met:
10 1.1 leo * 1. Redistributions of source code must retain the above copyright
11 1.1 leo * notice, this list of conditions and the following disclaimer.
12 1.1 leo * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 leo * notice, this list of conditions and the following disclaimer in the
14 1.1 leo * documentation and/or other materials provided with the distribution.
15 1.1 leo * 3. All advertising materials mentioning features or use of this software
16 1.1 leo * must display the following acknowledgement:
17 1.1 leo * This product includes software developed by Leo Weppelman.
18 1.1 leo * 4. The name of the author may not be used to endorse or promote products
19 1.1 leo * derived from this software without specific prior written permission
20 1.1 leo *
21 1.1 leo * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22 1.1 leo * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23 1.1 leo * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24 1.1 leo * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25 1.1 leo * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26 1.1 leo * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 1.1 leo * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 1.1 leo * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 1.1 leo * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30 1.1 leo * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 1.1 leo */
32 1.1 leo
33 1.1 leo #ifndef _YM2149REG_H
34 1.1 leo #define _YM2149REG_H
35 1.1 leo /*
36 1.1 leo * Yahama YM-2149 Programmable Sound Generator
37 1.1 leo */
38 1.1 leo
39 1.1 leo #define YM2149 ((struct ym2149 *)AD_SOUND)
40 1.1 leo
41 1.1 leo struct ym2149 {
42 1.1 leo volatile u_char sdb[4]; /* use only the even bytes */
43 1.1 leo };
44 1.1 leo
45 1.1 leo #define sd_selr sdb[0] /* select register */
46 1.1 leo #define sd_rdat sdb[0] /* read register data */
47 1.1 leo #define sd_wdat sdb[2] /* write register data */
48 1.1 leo
49 1.1 leo /*
50 1.1 leo * Accessing the YM-2149 registers is indirect through ST-specific
51 1.1 leo * circuitry by writing the register number into sd_selr.
52 1.1 leo */
53 1.1 leo #define YM_PA0 0 /* Period Channel A, bits 0-7 */
54 1.1 leo #define YM_PA1 1 /* Period Channel A, bits 8-11 */
55 1.1 leo #define YM_PB0 2 /* Period Channel B, bits 0-7 */
56 1.1 leo #define YM_PB1 3 /* Period Channel B, bits 8-11 */
57 1.1 leo #define YM_PC0 4 /* Period Channel C, bits 0-7 */
58 1.1 leo #define YM_PC1 5 /* Period Channel C, bits 8-11 */
59 1.1 leo #define YM_PNG 6 /* Period Noise Generator, bits 0-4 */
60 1.1 leo #define YM_MFR 7 /* Multi Function Register */
61 1.1 leo #define YM_VA 8 /* Volume Channel A */
62 1.1 leo #define YM_VB 9 /* Volume Channel B */
63 1.1 leo #define YM_VC 10 /* Volume Channel C */
64 1.1 leo #define YM_PE0 11 /* Period Envelope, bits 0-7 */
65 1.1 leo #define YM_PE1 12 /* Period Envelope, bits 8-15 */
66 1.1 leo #define YM_WFE 13 /* Wave Form Envelope */
67 1.1 leo #define YM_IOA 14 /* I/O port A */
68 1.1 leo #define YM_IOB 15 /* I/O port B */
69 1.1 leo
70 1.1 leo /* bits in MFR: */
71 1.1 leo #define SA_OFF 0x01 /* Sound Channel A off */
72 1.1 leo #define SB_OFF 0x02 /* Sound Channel B off */
73 1.1 leo #define SC_OFF 0x04 /* Sound Channel C off */
74 1.1 leo #define NA_OFF 0x08 /* Noise Channel A off */
75 1.1 leo #define NB_OFF 0x10 /* Noise Channel B off */
76 1.1 leo #define NC_OFF 0x20 /* Noise Channel C off */
77 1.1 leo #define PA_OUT 0x40 /* Port A for Output */
78 1.1 leo #define PB_OUT 0x80 /* Port B for Output */
79 1.1 leo
80 1.1 leo /* bits in Vx: */
81 1.1 leo #define VOLUME 0x0F /* 16 steps */
82 1.1 leo #define ENVELOP 0x10 /* volume steered by envelope */
83 1.1 leo
84 1.1 leo /* bits in WFE: */
85 1.1 leo #define WF_HOLD 0x01 /* hold after one period */
86 1.1 leo #define WF_ALTERNAT 0x02 /* up and down (no saw teeth) */
87 1.1 leo #define WF_ATTACK 0x04 /* start up */
88 1.1 leo #define WF_CONTINUE 0x08 /* multiple periods */
89 1.1 leo
90 1.1 leo /* names for bits in Port A (ST specific): */
91 1.1 leo #define PA_SIDEB 0x01 /* select floppy head - if double sided */
92 1.1 leo #define PA_FLOP0 0x02 /* Drive Select Floppy 0 */
93 1.1 leo #define PA_FLOP1 0x04 /* Drive Select Floppy 1 */
94 1.1 leo #define PA_FDSEL (PA_SIDEB|PA_FLOP0|PA_FLOP1)
95 1.1 leo #define PA_SRTS 0x08 /* Serial RTS */
96 1.1 leo #define PA_SDTR 0x10 /* Serial DTR */
97 1.1 leo #define PA_PSTROBE 0x20 /* Parallel Strobe */
98 1.1 leo #define PA_USER 0x40 /* Free Pin on Monitor Connector */
99 1.1 leo #define PA_SER2 0x80 /* Choose between LAN or Ser2 port */
100 1.1 leo
101 1.1 leo /*
102 1.1 leo * Access macro's for Port A
103 1.1 leo * Port A is defined as an output port. Reading the port does not work
104 1.1 leo * reliably so keeping a 'soft-copy' seems to be the only way to make
105 1.1 leo * things work.
106 1.1 leo */
107 1.1 leo extern u_char ym2149_ioa; /* Soft-copy of port-A */
108 1.1 leo
109 1.1 leo #define ym2149_write_ioport(port, value) { \
110 1.3.60.1 skrll int _os = splhigh(); \
111 1.1 leo \
112 1.1 leo YM2149->sd_selr = port; \
113 1.1 leo YM2149->sd_wdat = value; \
114 1.3.60.1 skrll splx(_os); \
115 1.1 leo }
116 1.1 leo
117 1.2 leo #define ym2149_write_ioport2(port, value) { \
118 1.2 leo YM2149->sd_selr = port; \
119 1.2 leo YM2149->sd_wdat = value; \
120 1.2 leo }
121 1.2 leo
122 1.1 leo #define ym2149_fd_select(select) { \
123 1.3.60.1 skrll int _s = splhigh(); \
124 1.2 leo \
125 1.1 leo ym2149_ioa = (ym2149_ioa & ~PA_FDSEL) | (select & PA_FDSEL); \
126 1.1 leo ym2149_write_ioport(YM_IOA, ym2149_ioa); \
127 1.3.60.1 skrll splx(_s); \
128 1.1 leo }
129 1.1 leo
130 1.1 leo #define ym2149_rts(set) { \
131 1.3.60.1 skrll int _s = splhigh(); \
132 1.2 leo \
133 1.1 leo ym2149_ioa = set ? ym2149_ioa | PA_SRTS : ym2149_ioa & ~PA_SRTS;\
134 1.1 leo ym2149_write_ioport(YM_IOA, ym2149_ioa); \
135 1.3.60.1 skrll splx(_s); \
136 1.1 leo }
137 1.1 leo
138 1.1 leo #define ym2149_dtr(set) { \
139 1.3.60.1 skrll int _s = splhigh(); \
140 1.2 leo \
141 1.1 leo ym2149_ioa = set ? ym2149_ioa | PA_SDTR : ym2149_ioa & ~PA_SDTR;\
142 1.1 leo ym2149_write_ioport(YM_IOA, ym2149_ioa); \
143 1.3.60.1 skrll splx(_s); \
144 1.1 leo }
145 1.1 leo
146 1.1 leo #define ym2149_strobe(set) { \
147 1.3.60.1 skrll int _s = splhigh(); \
148 1.2 leo \
149 1.1 leo ym2149_ioa = set ? ym2149_ioa | PA_PSTROBE : ym2149_ioa & ~PA_PSTROBE;\
150 1.1 leo ym2149_write_ioport(YM_IOA, ym2149_ioa); \
151 1.3.60.1 skrll splx(_s); \
152 1.1 leo }
153 1.1 leo
154 1.3 leo #define ym2149_ser2(set) { \
155 1.3.60.1 skrll int _s = splhigh(); \
156 1.2 leo \
157 1.3 leo ym2149_ioa = set ? ym2149_ioa | PA_SER2 : ym2149_ioa & ~PA_SER2;\
158 1.1 leo ym2149_write_ioport(YM_IOA, ym2149_ioa); \
159 1.3.60.1 skrll splx(_s); \
160 1.1 leo }
161 1.2 leo
162 1.2 leo #undef ym2149_write_ioport2
163 1.1 leo
164 1.1 leo #ifdef _KERNEL
165 1.1 leo /*
166 1.1 leo * Prototypes
167 1.1 leo */
168 1.1 leo void ym2149_init __P((void));
169 1.1 leo #endif
170 1.1 leo
171 1.1 leo #endif /* _YM2149REG_H */
172