gusemu.h 5.3 KB

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