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