Statistics
| Branch: | Revision:

root / hw / gusemu.h @ 43ad7e3e

History | View | Annotate | Download (5.3 kB)

1 423d65f4 balrog
/*
2 423d65f4 balrog
 * GUSEMU32 - API
3 423d65f4 balrog
 *
4 423d65f4 balrog
 * Copyright (C) 2000-2007 Tibor "TS" Schütz
5 423d65f4 balrog
 *
6 423d65f4 balrog
 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 423d65f4 balrog
 * of this software and associated documentation files (the "Software"), to deal
8 423d65f4 balrog
 * in the Software without restriction, including without limitation the rights
9 423d65f4 balrog
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 423d65f4 balrog
 * copies of the Software, and to permit persons to whom the Software is
11 423d65f4 balrog
 * furnished to do so, subject to the following conditions:
12 423d65f4 balrog
 *
13 423d65f4 balrog
 * The above copyright notice and this permission notice shall be included in
14 423d65f4 balrog
 * all copies or substantial portions of the Software.
15 423d65f4 balrog
 *
16 423d65f4 balrog
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 423d65f4 balrog
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 423d65f4 balrog
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 423d65f4 balrog
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 423d65f4 balrog
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 423d65f4 balrog
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 423d65f4 balrog
 * THE SOFTWARE.
23 423d65f4 balrog
 */
24 423d65f4 balrog
25 423d65f4 balrog
#ifndef GUSEMU_H
26 423d65f4 balrog
#define GUSEMU_H
27 423d65f4 balrog
28 423d65f4 balrog
/* data types (need to be adjusted if neither a VC6 nor a C99 compatible compiler is used) */
29 423d65f4 balrog
30 423d65f4 balrog
#if defined _WIN32 && defined _MSC_VER /* doesnt support other win32 compilers yet, do it yourself... */
31 423d65f4 balrog
 typedef unsigned char GUSbyte;
32 423d65f4 balrog
 typedef unsigned short GUSword;
33 423d65f4 balrog
 typedef unsigned int GUSdword;
34 423d65f4 balrog
 typedef signed char GUSchar;
35 731ba0ce malc
 typedef signed short GUSsample;
36 423d65f4 balrog
#else
37 423d65f4 balrog
 #include <stdint.h>
38 423d65f4 balrog
 typedef int8_t GUSchar;
39 423d65f4 balrog
 typedef uint8_t GUSbyte;
40 423d65f4 balrog
 typedef uint16_t GUSword;
41 423d65f4 balrog
 typedef uint32_t GUSdword;
42 731ba0ce malc
 typedef int16_t GUSsample;
43 423d65f4 balrog
#endif
44 423d65f4 balrog
45 423d65f4 balrog
typedef struct _GUSEmuState
46 423d65f4 balrog
{
47 423d65f4 balrog
 GUSbyte *himemaddr; /* 1024*1024 bytes used for storing uploaded samples (+32 additional bytes for read padding) */
48 423d65f4 balrog
 GUSbyte *gusdatapos; /* (gusdataend-gusdata) bytes used for storing emulated GF1/mixer register states (32*32+4 bytes in initial GUSemu32 version) */
49 9df34396 Gerd Hoffmann
 uint32_t gusirq;
50 9df34396 Gerd Hoffmann
 uint32_t gusdma;
51 423d65f4 balrog
 unsigned int timer1fraction;
52 423d65f4 balrog
 unsigned int timer2fraction;
53 423d65f4 balrog
 void *opaque;
54 423d65f4 balrog
} GUSEmuState;
55 423d65f4 balrog
56 423d65f4 balrog
/* ** Callback functions needed: */
57 423d65f4 balrog
/* NMI is defined as hwirq=-1 (not supported (yet?)) */
58 423d65f4 balrog
/* GUS_irqrequest returns the number of IRQs actually scheduled into the virtual machine */
59 423d65f4 balrog
/* Level triggered IRQ simulations normally return 1 */
60 423d65f4 balrog
/* Event triggered IRQ simulation can safely ignore GUS_irqclear calls */
61 423d65f4 balrog
int  GUS_irqrequest(GUSEmuState *state, int hwirq, int num);/* needed in both mixer and bus emulation functions. */
62 423d65f4 balrog
void GUS_irqclear(  GUSEmuState *state, int hwirq); /* used by gus_write() only - can be left empty for mixer functions */
63 423d65f4 balrog
void GUS_dmarequest(GUSEmuState *state);            /* used by gus_write() only - can be left empty for mixer functions */
64 423d65f4 balrog
65 423d65f4 balrog
/* ** ISA bus interface functions: */
66 423d65f4 balrog
67 423d65f4 balrog
/* Port I/O handlers */
68 423d65f4 balrog
/* support the following ports: */
69 423d65f4 balrog
/* 2x0,2x6,2x8...2xF,3x0...3x7;  */
70 423d65f4 balrog
/* optional: 388,389 (at least writes should be forwarded or some GUS detection algorithms will fail) */
71 423d65f4 balrog
/* data is passed in host byte order */
72 423d65f4 balrog
unsigned int gus_read( GUSEmuState *state, int port, int size);
73 423d65f4 balrog
void         gus_write(GUSEmuState *state, int port, int size, unsigned int data);
74 423d65f4 balrog
/* size is given in bytes (1 for byte, 2 for word) */
75 423d65f4 balrog
76 423d65f4 balrog
/* DMA data transfer function */
77 423d65f4 balrog
/* data pointed to is passed in native x86 order */
78 423d65f4 balrog
void gus_dma_transferdata(GUSEmuState *state, char *dma_addr, unsigned int count, int TC);
79 423d65f4 balrog
/* Called back by GUS_start_DMA as soon as the emulated DMA controller is ready for a transfer to or from GUS */
80 423d65f4 balrog
/* (might be immediately if the DMA controller was programmed first) */
81 423d65f4 balrog
/* dma_addr is an already translated address directly pointing to the beginning of the memory block */
82 423d65f4 balrog
/* do not forget to update DMA states after the call, including the DREQ and TC flags */
83 423d65f4 balrog
/* it is possible to break down a single transfer into multiple ones, but take care that: */
84 423d65f4 balrog
/* -dma_count is actually count-1 */
85 423d65f4 balrog
/* -before and during a transfer, DREQ is set and TC cleared */
86 423d65f4 balrog
/* -when calling gus_dma_transferdata(), TC is only set true for call transfering the last byte */
87 423d65f4 balrog
/* -after the last transfer, DREQ is cleared and TC is set */
88 423d65f4 balrog
89 423d65f4 balrog
/* ** GF1 mixer emulation functions: */
90 423d65f4 balrog
/* Usually, gus_irqgen should be called directly after gus_mixvoices if you can meet the recommended ranges. */
91 423d65f4 balrog
/* If the interrupts are executed immediately (i.e., are synchronous), it may be useful to break this */
92 423d65f4 balrog
/* down into a sequence of gus_mixvoice();gus_irqgen(); calls while mixing an audio block. */
93 423d65f4 balrog
/* If the interrupts are asynchronous, it may be needed to use a separate thread mixing into a temporary */
94 423d65f4 balrog
/* audio buffer in order to avoid quality loss caused by large numsamples and elapsed_time values. */
95 423d65f4 balrog
96 731ba0ce malc
void gus_mixvoices(GUSEmuState *state, unsigned int playback_freq, unsigned int numsamples, GUSsample *bufferpos);
97 423d65f4 balrog
/* recommended range: 10 < numsamples < 100 */
98 423d65f4 balrog
/* lower values may result in increased rounding error, higher values often cause audible timing delays */
99 423d65f4 balrog
100 423d65f4 balrog
void gus_irqgen(GUSEmuState *state, unsigned int elapsed_time);
101 423d65f4 balrog
/* recommended range: 80us < elapsed_time < max(1000us, numsamples/playback_freq) */
102 423d65f4 balrog
/* lower values won´t provide any benefit at all, higher values can cause audible timing delays */
103 423d65f4 balrog
/* note: masked timers are also calculated by this function, thus it might be needed even without any IRQs in use! */
104 423d65f4 balrog
105 423d65f4 balrog
#endif  /* gusemu.h */