147b43a1fSPaolo Bonzini /* 247b43a1fSPaolo Bonzini * GUSEMU32 - API 347b43a1fSPaolo Bonzini * 447b43a1fSPaolo Bonzini * Copyright (C) 2000-2007 Tibor "TS" Schütz 547b43a1fSPaolo Bonzini * 647b43a1fSPaolo Bonzini * Permission is hereby granted, free of charge, to any person obtaining a copy 747b43a1fSPaolo Bonzini * of this software and associated documentation files (the "Software"), to deal 847b43a1fSPaolo Bonzini * in the Software without restriction, including without limitation the rights 947b43a1fSPaolo Bonzini * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 1047b43a1fSPaolo Bonzini * copies of the Software, and to permit persons to whom the Software is 1147b43a1fSPaolo Bonzini * furnished to do so, subject to the following conditions: 1247b43a1fSPaolo Bonzini * 1347b43a1fSPaolo Bonzini * The above copyright notice and this permission notice shall be included in 1447b43a1fSPaolo Bonzini * all copies or substantial portions of the Software. 1547b43a1fSPaolo Bonzini * 1647b43a1fSPaolo Bonzini * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 1747b43a1fSPaolo Bonzini * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 1847b43a1fSPaolo Bonzini * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 1947b43a1fSPaolo Bonzini * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 2047b43a1fSPaolo Bonzini * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 2147b43a1fSPaolo Bonzini * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 2247b43a1fSPaolo Bonzini * THE SOFTWARE. 2347b43a1fSPaolo Bonzini */ 2447b43a1fSPaolo Bonzini 2547b43a1fSPaolo Bonzini #ifndef GUSEMU_H 2647b43a1fSPaolo Bonzini #define GUSEMU_H 2747b43a1fSPaolo Bonzini 2847b43a1fSPaolo Bonzini typedef struct _GUSEmuState 2947b43a1fSPaolo Bonzini { 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) */ 3247b43a1fSPaolo Bonzini uint32_t gusirq; 3347b43a1fSPaolo Bonzini uint32_t gusdma; 3447b43a1fSPaolo Bonzini unsigned int timer1fraction; 3547b43a1fSPaolo Bonzini unsigned int timer2fraction; 3647b43a1fSPaolo Bonzini void *opaque; 3747b43a1fSPaolo Bonzini } GUSEmuState; 3847b43a1fSPaolo Bonzini 3947b43a1fSPaolo Bonzini /* ** Callback functions needed: */ 4047b43a1fSPaolo Bonzini /* NMI is defined as hwirq=-1 (not supported (yet?)) */ 4147b43a1fSPaolo Bonzini /* GUS_irqrequest returns the number of IRQs actually scheduled into the virtual machine */ 4247b43a1fSPaolo Bonzini /* Level triggered IRQ simulations normally return 1 */ 4347b43a1fSPaolo Bonzini /* Event triggered IRQ simulation can safely ignore GUS_irqclear calls */ 4447b43a1fSPaolo Bonzini int GUS_irqrequest(GUSEmuState *state, int hwirq, int num);/* needed in both mixer and bus emulation functions. */ 4547b43a1fSPaolo Bonzini void GUS_irqclear( GUSEmuState *state, int hwirq); /* used by gus_write() only - can be left empty for mixer functions */ 4647b43a1fSPaolo Bonzini void GUS_dmarequest(GUSEmuState *state); /* used by gus_write() only - can be left empty for mixer functions */ 4747b43a1fSPaolo Bonzini 4847b43a1fSPaolo Bonzini /* ** ISA bus interface functions: */ 4947b43a1fSPaolo Bonzini 5047b43a1fSPaolo Bonzini /* Port I/O handlers */ 5147b43a1fSPaolo Bonzini /* support the following ports: */ 5247b43a1fSPaolo Bonzini /* 2x0,2x6,2x8...2xF,3x0...3x7; */ 5347b43a1fSPaolo Bonzini /* optional: 388,389 (at least writes should be forwarded or some GUS detection algorithms will fail) */ 5447b43a1fSPaolo Bonzini /* data is passed in host byte order */ 5547b43a1fSPaolo Bonzini unsigned int gus_read( GUSEmuState *state, int port, int size); 5647b43a1fSPaolo Bonzini void gus_write(GUSEmuState *state, int port, int size, unsigned int data); 5747b43a1fSPaolo Bonzini /* size is given in bytes (1 for byte, 2 for word) */ 5847b43a1fSPaolo Bonzini 5947b43a1fSPaolo Bonzini /* DMA data transfer function */ 6047b43a1fSPaolo Bonzini /* data pointed to is passed in native x86 order */ 6147b43a1fSPaolo Bonzini void gus_dma_transferdata(GUSEmuState *state, char *dma_addr, unsigned int count, int TC); 6247b43a1fSPaolo Bonzini /* Called back by GUS_start_DMA as soon as the emulated DMA controller is ready for a transfer to or from GUS */ 6347b43a1fSPaolo Bonzini /* (might be immediately if the DMA controller was programmed first) */ 6447b43a1fSPaolo Bonzini /* dma_addr is an already translated address directly pointing to the beginning of the memory block */ 6547b43a1fSPaolo Bonzini /* do not forget to update DMA states after the call, including the DREQ and TC flags */ 6647b43a1fSPaolo Bonzini /* it is possible to break down a single transfer into multiple ones, but take care that: */ 6747b43a1fSPaolo Bonzini /* -dma_count is actually count-1 */ 6847b43a1fSPaolo Bonzini /* -before and during a transfer, DREQ is set and TC cleared */ 6947b43a1fSPaolo Bonzini /* -when calling gus_dma_transferdata(), TC is only set true for call transferring the last byte */ 7047b43a1fSPaolo Bonzini /* -after the last transfer, DREQ is cleared and TC is set */ 7147b43a1fSPaolo Bonzini 7247b43a1fSPaolo Bonzini /* ** GF1 mixer emulation functions: */ 7347b43a1fSPaolo Bonzini /* Usually, gus_irqgen should be called directly after gus_mixvoices if you can meet the recommended ranges. */ 7447b43a1fSPaolo Bonzini /* If the interrupts are executed immediately (i.e., are synchronous), it may be useful to break this */ 7547b43a1fSPaolo Bonzini /* down into a sequence of gus_mixvoice();gus_irqgen(); calls while mixing an audio block. */ 7647b43a1fSPaolo Bonzini /* If the interrupts are asynchronous, it may be needed to use a separate thread mixing into a temporary */ 7747b43a1fSPaolo Bonzini /* audio buffer in order to avoid quality loss caused by large numsamples and elapsed_time values. */ 7847b43a1fSPaolo Bonzini 79*135f5ae1SJuan Quintela void gus_mixvoices(GUSEmuState *state, unsigned int playback_freq, unsigned int numsamples, int16_t *bufferpos); 8047b43a1fSPaolo Bonzini /* recommended range: 10 < numsamples < 100 */ 8147b43a1fSPaolo Bonzini /* lower values may result in increased rounding error, higher values often cause audible timing delays */ 8247b43a1fSPaolo Bonzini 8347b43a1fSPaolo Bonzini void gus_irqgen(GUSEmuState *state, unsigned int elapsed_time); 8447b43a1fSPaolo Bonzini /* recommended range: 80us < elapsed_time < max(1000us, numsamples/playback_freq) */ 8547b43a1fSPaolo Bonzini /* lower values won´t provide any benefit at all, higher values can cause audible timing delays */ 8647b43a1fSPaolo Bonzini /* note: masked timers are also calculated by this function, thus it might be needed even without any IRQs in use! */ 8747b43a1fSPaolo Bonzini 88175de524SMarkus Armbruster #endif /* GUSEMU_H */ 89