xref: /qemu/hw/audio/gusemu.h (revision 135f5ae1974ccd8e77f004924a5fe7168be1b9eb)
1423d65f4Sbalrog /*
2423d65f4Sbalrog  * GUSEMU32 - API
3423d65f4Sbalrog  *
4423d65f4Sbalrog  * Copyright (C) 2000-2007 Tibor "TS" Schütz
5423d65f4Sbalrog  *
6423d65f4Sbalrog  * Permission is hereby granted, free of charge, to any person obtaining a copy
7423d65f4Sbalrog  * of this software and associated documentation files (the "Software"), to deal
8423d65f4Sbalrog  * in the Software without restriction, including without limitation the rights
9423d65f4Sbalrog  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10423d65f4Sbalrog  * copies of the Software, and to permit persons to whom the Software is
11423d65f4Sbalrog  * furnished to do so, subject to the following conditions:
12423d65f4Sbalrog  *
13423d65f4Sbalrog  * The above copyright notice and this permission notice shall be included in
14423d65f4Sbalrog  * all copies or substantial portions of the Software.
15423d65f4Sbalrog  *
16423d65f4Sbalrog  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17423d65f4Sbalrog  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18423d65f4Sbalrog  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19423d65f4Sbalrog  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20423d65f4Sbalrog  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21423d65f4Sbalrog  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22423d65f4Sbalrog  * THE SOFTWARE.
23423d65f4Sbalrog  */
24423d65f4Sbalrog 
25423d65f4Sbalrog #ifndef GUSEMU_H
26423d65f4Sbalrog #define GUSEMU_H
27423d65f4Sbalrog 
28423d65f4Sbalrog typedef struct _GUSEmuState
29423d65f4Sbalrog {
300af81c56SJuan Quintela  uint8_t *himemaddr; /* 1024*1024 bytes used for storing uploaded samples (+32 additional bytes for read padding) */
310af81c56SJuan Quintela  uint8_t *gusdatapos; /* (gusdataend-gusdata) bytes used for storing emulated GF1/mixer register states (32*32+4 bytes in initial GUSemu32 version) */
329df34396SGerd Hoffmann  uint32_t gusirq;
339df34396SGerd Hoffmann  uint32_t gusdma;
34423d65f4Sbalrog  unsigned int timer1fraction;
35423d65f4Sbalrog  unsigned int timer2fraction;
36423d65f4Sbalrog  void *opaque;
37423d65f4Sbalrog } GUSEmuState;
38423d65f4Sbalrog 
39423d65f4Sbalrog /* ** Callback functions needed: */
40423d65f4Sbalrog /* NMI is defined as hwirq=-1 (not supported (yet?)) */
41423d65f4Sbalrog /* GUS_irqrequest returns the number of IRQs actually scheduled into the virtual machine */
42423d65f4Sbalrog /* Level triggered IRQ simulations normally return 1 */
43423d65f4Sbalrog /* Event triggered IRQ simulation can safely ignore GUS_irqclear calls */
44423d65f4Sbalrog int  GUS_irqrequest(GUSEmuState *state, int hwirq, int num);/* needed in both mixer and bus emulation functions. */
45423d65f4Sbalrog void GUS_irqclear(  GUSEmuState *state, int hwirq); /* used by gus_write() only - can be left empty for mixer functions */
46423d65f4Sbalrog void GUS_dmarequest(GUSEmuState *state);            /* used by gus_write() only - can be left empty for mixer functions */
47423d65f4Sbalrog 
48423d65f4Sbalrog /* ** ISA bus interface functions: */
49423d65f4Sbalrog 
50423d65f4Sbalrog /* Port I/O handlers */
51423d65f4Sbalrog /* support the following ports: */
52423d65f4Sbalrog /* 2x0,2x6,2x8...2xF,3x0...3x7;  */
53423d65f4Sbalrog /* optional: 388,389 (at least writes should be forwarded or some GUS detection algorithms will fail) */
54423d65f4Sbalrog /* data is passed in host byte order */
55423d65f4Sbalrog unsigned int gus_read( GUSEmuState *state, int port, int size);
56423d65f4Sbalrog void         gus_write(GUSEmuState *state, int port, int size, unsigned int data);
57423d65f4Sbalrog /* size is given in bytes (1 for byte, 2 for word) */
58423d65f4Sbalrog 
59423d65f4Sbalrog /* DMA data transfer function */
60423d65f4Sbalrog /* data pointed to is passed in native x86 order */
61423d65f4Sbalrog void gus_dma_transferdata(GUSEmuState *state, char *dma_addr, unsigned int count, int TC);
62423d65f4Sbalrog /* Called back by GUS_start_DMA as soon as the emulated DMA controller is ready for a transfer to or from GUS */
63423d65f4Sbalrog /* (might be immediately if the DMA controller was programmed first) */
64423d65f4Sbalrog /* dma_addr is an already translated address directly pointing to the beginning of the memory block */
65423d65f4Sbalrog /* do not forget to update DMA states after the call, including the DREQ and TC flags */
66423d65f4Sbalrog /* it is possible to break down a single transfer into multiple ones, but take care that: */
67423d65f4Sbalrog /* -dma_count is actually count-1 */
68423d65f4Sbalrog /* -before and during a transfer, DREQ is set and TC cleared */
6966a0a2cbSDong Xu Wang /* -when calling gus_dma_transferdata(), TC is only set true for call transferring the last byte */
70423d65f4Sbalrog /* -after the last transfer, DREQ is cleared and TC is set */
71423d65f4Sbalrog 
72423d65f4Sbalrog /* ** GF1 mixer emulation functions: */
73423d65f4Sbalrog /* Usually, gus_irqgen should be called directly after gus_mixvoices if you can meet the recommended ranges. */
74423d65f4Sbalrog /* If the interrupts are executed immediately (i.e., are synchronous), it may be useful to break this */
75423d65f4Sbalrog /* down into a sequence of gus_mixvoice();gus_irqgen(); calls while mixing an audio block. */
76423d65f4Sbalrog /* If the interrupts are asynchronous, it may be needed to use a separate thread mixing into a temporary */
77423d65f4Sbalrog /* audio buffer in order to avoid quality loss caused by large numsamples and elapsed_time values. */
78423d65f4Sbalrog 
79*135f5ae1SJuan Quintela void gus_mixvoices(GUSEmuState *state, unsigned int playback_freq, unsigned int numsamples, int16_t *bufferpos);
80423d65f4Sbalrog /* recommended range: 10 < numsamples < 100 */
81423d65f4Sbalrog /* lower values may result in increased rounding error, higher values often cause audible timing delays */
82423d65f4Sbalrog 
83423d65f4Sbalrog void gus_irqgen(GUSEmuState *state, unsigned int elapsed_time);
84423d65f4Sbalrog /* recommended range: 80us < elapsed_time < max(1000us, numsamples/playback_freq) */
85423d65f4Sbalrog /* lower values won´t provide any benefit at all, higher values can cause audible timing delays */
86423d65f4Sbalrog /* note: masked timers are also calculated by this function, thus it might be needed even without any IRQs in use! */
87423d65f4Sbalrog 
88175de524SMarkus Armbruster #endif /* GUSEMU_H */
89