MusicKit  0.0.0
dsp.h
00001 #ifndef __MK_dsp_H___
00002 #define __MK_dsp_H___
00003 /*
00004         $Id$
00005         Master include file for the DSP library (-ldsp -lsys_s)
00006 
00007         Copyright 1988-1992, NeXT Inc.  All rights reserved.
00008  
00009 */
00010 
00011 #ifndef DSP_H
00012 #define DSP_H
00013 
00014 #define DSP_SYS_VER_C 65
00015 #define DSP_SYS_REV_C 41
00016 
00017 /* Default start address in DSP internal program memory (just after DEGMON) */
00018 #define DSP_PLI_USR_C 0x96
00019 
00020 #define DSPMK_I_NTICK 0x10
00021 
00022 #define DSP_EXT_RAM_SIZE_MIN 8192 /* Minimum external RAM size in 3byte wds */
00023 #define DSP_CLOCK_RATE (25.0E6) /* DSP clock frequency */
00024 #define DSP_CLOCK_PERIOD (40.0E-9) /* Cycle time in seconds. */
00025 
00026 #import "dsp_types.h"
00027 
00028 /****************************** Masks **************************************/
00029 
00030 /* Basic DSP data types */
00031 #define DSP_WORD_MASK           0x00FFFFFF /* low-order 24 bits */
00032 #define DSP_SOUND_MASK          0x0000FFFF /* low-order 16 bits */
00033 #define DSP_ADDRESS_MASK        0x0000FFFF /* low-order 16 bits */
00034 
00035 
00036 /* Bits in the DSP Interrupt Control Register (ICR) */
00037 #define DSP_ICR                 0 /* ICR address in host interface */
00038 #define DSP_ICR_RREQ            0x00000001 /* enable host int. on data->host */
00039 #define DSP_ICR_TREQ            0x00000002 /* enable host int. on data<-host */
00040 #define DSP_ICR_UNUSED          0x00000004
00041 #define DSP_ICR_HF0             0x00000008
00042 #define DSP_ICR_HF1             0x00000010
00043 #define DSP_ICR_HM0             0x00000020
00044 #define DSP_ICR_HM1             0x00000040
00045 #define DSP_ICR_INIT            0x00000080
00046 
00047 #define DSP_ICR_REGS_MASK       0xFF000000
00048 #define DSP_ICR_RREQ_REGS_MASK  0x01000000
00049 #define DSP_ICR_TREQ_REGS_MASK  0x02000000
00050 #define DSP_ICR_HF0_REGS_MASK   0x08000000
00051 #define DSP_ICR_HF1_REGS_MASK   0x10000000
00052 #define DSP_ICR_HM0_REGS_MASK   0x20000000
00053 #define DSP_ICR_HM1_REGS_MASK   0x40000000
00054 #define DSP_ICR_INIT_REGS_MASK  0x80000000
00055 
00056 
00057 /* Bits in the DSP Command Vector Register */
00058 #define DSP_CVR                 1          /* address in host interface */
00059 #define DSP_CVR_HV_MASK         0x0000001F /* low-order  5 bits of CVR */
00060 #define DSP_CVR_HC_MASK         0x00000080 /* HC bit of DSP CVR */
00061 
00062 #define DSP_CVR_REGS_MASK       0x00FF0000 /* Regs mask for CVR */
00063 #define DSP_CVR_HV_REGS_MASK    0x001F0000 /* low-order  5 bits of CVR */
00064 #define DSP_CVR_HC_REGS_MASK    0x00800000 /* Regs mask for HC bit of CVR */
00065 
00066 
00067 /* Bits in the DSP Interrupt Status Register */
00068 #define DSP_ISR              2  /* address in host interface */
00069 #define DSP_ISR_RXDF            0x00000001
00070 #define DSP_ISR_TXDE            0x00000002
00071 #define DSP_ISR_TRDY            0x00000004
00072 #define DSP_ISR_HF2             0x00000008
00073 #define DSP_BUSY                0x00000008 /* "DSP Busy"=HF2 */
00074 #define DSP_ISR_HF3             0x00000010
00075 #define DSP_ISR_UNUSED          0x00000020
00076 #define DSP_ISR_DMA             0x00000040
00077 #define DSP_ISR_HREQ            0x00000080
00078 
00079 #define DSP_ISR_REGS_MASK       0x0000FF00
00080 #define DSP_ISR_RXDF_REGS_MASK  0x00000100
00081 #define DSP_ISR_TXDE_REGS_MASK  0x00000200
00082 #define DSP_ISR_TRDY_REGS_MASK  0x00000400
00083 #define DSP_ISR_HF2_REGS_MASK   0x00000800
00084 #define DSP_BUSY_REGS_MASK      0x00000800
00085 #define DSP_ISR_HF3_REGS_MASK   0x00001000
00086 #define DSP_ISR_DMA_REGS_MASK   0x00004000
00087 #define DSP_ISR_HREQ_REGS_MASK  0x00008000
00088 
00089 /* DSP Interrupt Vector Register */
00090 #define DSP_IVR              3  /* address in host interface */
00091 
00092 #define DSP_UNUSED           4  /* address in host interface */
00093 
00094 /* DSP Receive-Byte Registers */
00095 #define DSP_RXH              5  /* address in host interface */
00096 #define DSP_RXM              6  /* address in host interface */
00097 #define DSP_RXL              7  /* address in host interface */
00098 
00099 /* DSP Transmit-Byte Registers */
00100 #define DSP_TXH              5  /* address in host interface */
00101 #define DSP_TXM              6  /* address in host interface */
00102 #define DSP_TXL              7  /* address in host interface */
00103 
00104 /* Interesting places in DSP memory */
00105 #define DSP_MULAW_SPACE 1       /* memory space code for mulaw table in DSP */
00106 #define DSP_MULAW_TABLE 256     /* address of mulaw table in X onchip memory */
00107 #define DSP_MULAW_LENGTH 128    /* length  of mulaw table */
00108 
00109 #define DSP_ALAW_SPACE 1        /* memory space code for Mu-law table in DSP */
00110 #define DSP_ALAW_TABLE 384      /* address of A-law table */
00111 #define DSP_ALAW_LENGTH 128     /* length  of A-law table */
00112 
00113 #define DSP_SINE_SPACE 2        /* memory space code for sine ROM in DSP */
00114 #define DSP_SINE_TABLE 256      /* address of sine table in Y onchip memory */
00115 #define DSP_SINE_LENGTH 256     /* length  of sine table */
00116 
00117 /* Host commands (cf. DSP56000/1 DSP User's Manual) */
00118 /* To issue a host command, set CVR to (DSP_CVR_HC_MASK|<cmd>&DSP_CVR_HV_MASK) */
00119 
00120 #define DSP_HC_RESET                     (0x0)     /* RESET host command */
00121 #define DSP_HC_TRACE                     (0x4>>1)  /* TRACE host command */
00122 #define DSP_HC_SWI                       (0x6>>1)  /* SWI host command */
00123 #define DSP_HC_SOFTWARE_INTERRUPT        (0x6>>1)  /* SWI host command */
00124 #define DSP_HC_ABORT                     (0x8>>1)  /* DEBUG_HALT */
00125 #define DSP_HC_HOST_RD                   (0x24>>1) /* DMA read done */
00126 #define DSP_HC_HOST_R_DONE               (0x24>>1) /* DMA read done */
00127 #define DSP_HC_EXECUTE_HOST_MESSAGE      (0x26>>1) /* Used for host messages */
00128 #define DSP_HC_XHM                       (0x26>>1) /* abbreviated version */
00129 #define DSP_HC_DMAWT                     (0x28>>1) /* Terminate DMA write */
00130 #define DSP_HC_DMA_HOST_W_DONE           (0x28>>1) /* Terminate DMA write */
00131 #define DSP_HC_HOST_W_DONE               (0x28>>1) /* Terminate DMA write */
00132 #define DSP_HC_KERNEL_ACK                (0x2A>>1) /* Kernel acknowledge */
00133 #define DSP_HC_SYS_CALL                  (0x2C>>1) /* cf <nextdev/snd_dsp.h> */
00134 
00135 #import "dsp_messages.h"
00136 
00137 #define DSP_MESSAGE_OPCODE(x) (((x)>>16)&0xFF)
00138 #define DSP_MESSAGE_SIGNED_DATUM(x) \
00139         ((int)((x)&0x8000?0xFFFF0000|((x)&0xFFFF):((x)&0xFFFF)))
00140 #define DSP_MESSAGE_UNSIGNED_DATUM(x) ((x)&0xFFFF)
00141 #define DSP_MESSAGE_ADDRESS(x) DSP_MESSAGE_UNSIGNED_DATUM(x)
00142 #define DSP_ERROR_OPCODE_INDEX(x) ((x) & 0x7F)   /* Strip MSB on 8-bit field */
00143 #define DSP_IS_ERROR_MESSAGE(x) ((x) & 0x800000) /* MSB on in 24 bits */
00144 #define DSP_IS_ERROR_OPCODE(x) ((x) & 0x80) /* MSB on in 8 bits */
00145 
00146 #define DSP_START_ADDRESS DSP_PLI_USR /* cf. dsp_messages.h */
00147 
00148 /* Be sure to enclose in {} when followed by an else */
00149 #define DSP_UNTIL_ERROR(x) if ((DSPErrorNo=(x))) \
00150   return(_DSPError(DSPErrorNo,"Aborting"))
00151 
00152 #define NOT_YET 1
00153 /* Make alloca() safe */
00154 
00155 /**** Include files ****/
00156 
00157 #import "dsp_structs.h"         /* DSP struct declarations */
00158 #import "dsp_errno.h"           /* Error codes for DSP C functions */
00159 #import "libdsp.h"              /* Function prototypes for libdsp functions */
00160 
00161 #ifdef WIN32
00162 // LMS it turns out -ObjC++ barfs including winsock.h
00163 // so these are taken from winsock.h
00164 typedef unsigned int u_int;
00165 /*
00166  * Structure used in select() call, taken from the BSD file sys/time.h.
00167  */
00168 struct timeval {
00169         long    tv_sec;         /* seconds */
00170         long    tv_usec;        /* and microseconds */
00171 };
00172 #else // WIN32
00173  #import <unistd.h> // LMS do we need this?
00174 #endif
00175 #import <sys/types.h> // LMS replacement
00176 #import <stdio.h>
00177 #import <math.h>
00178 #import <mach/mach.h>
00179 
00180 #define DSP_MAX_HM (DSP_NB_HMS-2) /* Leave room in HMS for begin/end marks */
00181 
00182 #define DSPMK_UNTIMED NULL      /* Denotes untimed, not tick-synchronized */
00183 
00184 /*** GLOBAL VARIABLES ***/      /* defined in DSPGlobals.c */
00185 extern int DSPErrorNo;
00186 extern DSPTimeStamp DSPMKTimeStamp0; /* Tick-synchronized, untimed */
00187 
00188 /* Numerical conversion */
00189 #define DSP_TWO_TO_24   ((double)16777216.0)
00190 #define DSP_TWO_TO_M_24 ((double)5.960464477539063e-08)
00191 #define DSP_TWO_TO_23   ((double)8388608.0)
00192 #define DSP_TWO_TO_M_23 ((double)1.192092895507813e-7)
00193 #define DSP_TWO_TO_48   ((double)281474976710656.0)
00194 #define DSP_TWO_TO_M_48 ((double)3.552713678800501e-15)
00195 #define DSP_TWO_TO_15   ((double)32768.0)
00196 #define DSP_TWO_TO_M_15 ((double)3.0517578125e-05)
00197 
00198 #define DSP_INT_TO_FLOAT(x) ((((float)(x))*((float)DSP_TWO_TO_M_23)))
00199 #define DSP_SHORT_TO_FLOAT(x) ((((float)(x))*((float)DSP_TWO_TO_M_15)))
00200 #define DSP_FIX24_TO_FLOAT(x) ((((float)(x))*((float)DSP_TWO_TO_M_23)))
00201 #define DSP_INT_TO_DOUBLE(x) ((((double)(x))*(DSP_TWO_TO_M_23)))
00202 #define DSP_SHORT_TO_DOUBLE(x) ((((double)(x))*((float)DSP_TWO_TO_M_15)))
00203 #define DSP_FIX48_TO_DOUBLE(x) ((double)((x)->high24)*(DSP_TWO_TO_24) + ((double) (x)->low24))
00204 #define DSP_FLOAT_TO_INT(x) ((int)(((double)(x))*((double)DSP_TWO_TO_23)+0.5))
00205 #define DSP_FLOAT_TO_SHORT(x) ((int)(((double)(x))*((double)DSP_TWO_TO_15)+0.5))
00206 #define DSP_DOUBLE_TO_INT(x) ((int)(((double)(x))*(DSP_TWO_TO_23)+0.5))
00207 #define DSP_DOUBLE_TO_SHORT(x) ((int)(((double)(x))*((double)DSP_TWO_TO_15)+0.5))
00208 
00209 /* Max positive DSP float = (1-1/2^23) */
00210 #define DSP_F_MAXPOS ((double)(1.0-DSP_TWO_TO_M_23))
00211 #define DSP_ONE DSP_F_MAXPOS
00212 
00213 /* Max negative DSP float = -2^23 */
00214 #define DSP_F_MAXNEG (float) -1.0 
00215 
00216 #define DSP_FIX24_CLIP(_x) (((int)_x) & 0xFFFFFF)
00217 
00218 #define DSPMK_LOW_SAMPLING_RATE 22050.0
00219 #define DSPMK_HIGH_SAMPLING_RATE 44100.0
00220 
00221 #ifndef REMEMBER
00222 #define REMEMBER(x) /* x */
00223 #endif
00224 
00225 #define DSPMK_NTICK DSPMK_I_NTICK
00226 
00227 /*** FILE NAMES ***/
00228 /*** These filenames must stay in synch with those in $DSP/Makefile.config ***/
00229 
00230 #define DSP_SYSTEM_DIRECTORY @"/usr/local/lib/dsp/"
00231 #define DSP_FALLBACK_SYSTEM_DIRECTORY @"/usr/lib/dsp/"
00232 #define DSP_BIN_DIRECTORY "/usr/local/bin/"
00233 #define DSP_AP_BIN_DIRECTORY "/apbin/"
00234 #define DSP_INSTALL_ROOT "/usr/local/lib/dsp/"
00235 #define DSP_ERRORS_FILE "/tmp/dsperrors"
00236 #define DSP_WHO_FILE "/tmp/dsp.who"
00237 
00238 extern const char *DSPGetDSPDirectory();        /* as above or $DSP if $DSP set */
00239 extern char *DSPGetSystemDirectory();   /* /u/l/l/monitor|$DSP/monitor */
00240 extern char *DSPGetImgDirectory();      /* /u/l/l/dsp/img or $DSP/img */
00241 extern char *DSPGetAPDirectory();       /* /u/l/l/dsp/imgap or $DSP/imgap */
00242 extern char *DSPGetMusicDirectory();    /* DSP_MUSIC_DIRECTORY */
00243 extern char *DSPGetLocalBinDirectory(); /* /usr/bin or $DSP/bin */
00244 
00245 /* 
00246    Convert Y-space address in DSP "XY memory partition" 
00247    (where X and Y memories are each 4K long addressed from 0xA000)
00248    into an equivalent address in the "overlaid memory partition"
00249    (where memory addresses are irrespective of space).
00250    *** NOTE: This macro depends on there being 8K words of DSP static RAM ***
00251    Behaves like a function returning int.
00252 */
00253 #define DSPMapPMemY(ya) ((int) ((ya) & 0x7FFF))
00254 
00255 /* 
00256    Convert X-space address in DSP "XY memory partition" 
00257    into an equivalent address in the "overlaid memory partition"
00258    *** NOTE: This macro depends on there being 8K words of DSP static RAM ***
00259    Behaves like a function returning int.
00260 */
00261 #define DSPMapPMemX(xa) ((int) (((xa)|0x1000) & 0x7FFF))
00262 
00263 /* 
00264    File names below are ALL assumed to exist in the directory returned by
00265    DSPGetSystemDirectory(): 
00266 */
00267 
00268 /* Default AP and MK monitors installed with the system */
00269 
00270 /* dsp0 */
00271 
00272 /* All these should be NSConstantStrings but currently they are included in C source - LMS */
00273 
00274 /* The following are used by _DSPRelocate.c for backward 2.0 compatibility */
00275 #define DSP_MUSIC_SYSTEM_MEM "/mkmon8k.mem" 
00276 #define DSP_AP_SYSTEM_MEM "/apmon8k.mem"
00277 
00278 /* The following are used by DSPObject.c DSPBoot.c */
00279 #define DSP_MUSIC_SYSTEM_BINARY_0 "/mkmon_A_8k.dsp" 
00280 #define DSP_MUSIC_SYSTEM_0 "/mkmon_A_8k.lod"
00281 
00282 #define DSP_AP_SYSTEM_BINARY_0 "/apmon_8k.dsp"
00283 #define DSP_AP_SYSTEM_0 "/apmon_8k.lod"
00284 
00285 /* NeXT 32K word DSP memory expansion SIMM */
00286 #define DSP_32K_MUSIC_SYSTEM_BINARY_0 @"/mkmon_A_32k.dsp"
00287 #define DSP_32K_MUSIC_SYSTEM_0 @"/mkmon_A_32k.lod"
00288 
00289 /* NeXT 32K word DSP memory expansion SIMM */
00290 #define DSP_32K_AP_SYSTEM_BINARY_0 @"/apmon_32k.dsp"
00291 #define DSP_32K_AP_SYSTEM_0 @"/apmon_32k.lod"
00292 
00293 /* UCSF 64K x 3 word DSP memory expansion SIMM */
00294 #define DSP_192K_MUSIC_SYSTEM_BINARY_0 @"/mkmon_A_192k.dsp"
00295 #define DSP_192K_MUSIC_SYSTEM_0 @"/mkmon_A_192k.lod"
00296 
00297 /* Ariel PC56D 16K x 2 + 32K (P) word DSP memory */
00298 #define DSP_64K_SPLIT_MUSIC_SYSTEM_BINARY_0 @"/mkmon_A_192k.dsp"
00299 #define DSP_64K_SPLIT_MUSIC_SYSTEM_0 @"/mkmon_A_192k.lod"
00300 
00301 /* Number of words above which array-reads from the DSP use DMA */
00302 #define DSP_MIN_DMA_READ_SIZE 0
00303 
00304 /* Number of words above which array-writes to the DSP use DMA */
00305 #define DSP_MIN_DMA_WRITE_SIZE 128
00306 
00307 /* New mode for more efficient DMA transfers (cf. <nextdev/snd_msgs.h>) */
00308 #define DSP_MODE32_LEFT_JUSTIFIED 6
00309 
00310 #ifndef MAX
00311 #define  MAX(A,B)       ((A) > (B) ? (A) : (B))
00312 #endif
00313 
00314 #ifndef MIN
00315 #define  MIN(A,B)       ((A) < (B) ? (A) : (B))
00316 #endif
00317 
00318 #ifndef ABS
00319 #define  ABS(A)         ((A) < 0 ? (-(A)) : (A))
00320 #endif
00321 
00322 #define  DSP_MALLOC( VAR, TYPE, NUM ) ((VAR) = (TYPE *) malloc( (unsigned)(NUM)*sizeof(TYPE)))
00323 
00324 #define  DSP_REALLOC( VAR, TYPE, NUM )                          \
00325    ((VAR) = (TYPE *) realloc((char *)(VAR), (unsigned)(NUM)*sizeof(TYPE)))
00326 
00327 #define  DSP_FREE( PTR ) free( (char *) (PTR) );
00328 
00329 /* Exports from DSPGlobals.c */
00330 
00331 extern int DSPErrorNo;           /* Last DSP error */
00332 extern int DSPDefaultTimeLimit;  /* Default is 1000 which is 1 second */
00333 extern int DSPAPTimeLimit;       /* Default is 0 which means "forever" */
00334 extern DSPFix48 DSPMKTimeStamp0; /* Always {0,0} (tick-synchronizer) */
00335 
00336 #define DSP_ATOMIC 1
00337 #define DSP_NON_ATOMIC 0
00338 #define DSP_TIMEOUT_FOREVER 0
00339 #define _DSP_MSG_READER_TIMEOUT 30
00340 
00341 #endif DSP_H
00342 
00343 #endif