2 #include <hw/cpu/cpu.h>
5 /* 2 seems a reasonable max, since 1 is most common */
8 /* maximum sample rate (at 14 or less voices) */
9 #define ULTRASND_RATE 44100
11 #define ULTRASND_VOICE_MODE_IS_STOPPED 0x01
12 #define ULTRASND_VOICE_MODE_STOP 0x02
13 #define ULTRASND_VOICE_MODE_16BIT 0x04
14 #define ULTRASND_VOICE_MODE_LOOP 0x08
15 #define ULTRASND_VOICE_MODE_BIDIR 0x10
16 #define ULTRASND_VOICE_MODE_IRQ 0x20
17 #define ULTRASND_VOICE_MODE_BACKWARDS 0x40
18 #define ULTRASND_VOICE_MODE_IRQ_PENDING 0x80
20 /* data being sent is 16-bit PCM */
21 #define ULTRASND_DMA_DATA_SIZE_16BIT 0x40
22 /* during transfer invert bit 7 (or bit 15) to convert unsigned->signed */
23 #define ULTRASND_DMA_FLIP_MSB 0x80
26 int16_t port; /* NOTE: Gravis ultrasound takes port+0x0 to port+0xF, and port+0x100 to port+0x10F */
27 int8_t dma1,dma2; /* NOTE: These can be the same */
28 int8_t irq1,irq2; /* NOTE: These can be the same */
29 uint32_t total_ram; /* total RAM onboard. in most cases, a multiple of 256KB */
30 uint8_t active_voices;
32 uint8_t boundary256k:1; /* whether all DMA transfers, playback, etc. must occur within 256KB block boundaries */
33 uint8_t use_dma:1; /* whether to use DMA to upload/download data from DRAM */
35 uint8_t voicemode[32]; /* voice modes. because when you enable 16-bit PCM weird shit happens to the DRAM addresses */
36 struct dma_8237_allocation *dram_xfer_a;
39 extern const uint16_t ultrasnd_rate_per_voices[33];
40 extern struct ultrasnd_ctx ultrasnd_card[MAX_ULTRASND];
41 extern struct ultrasnd_ctx *ultrasnd_env;
42 extern int ultrasnd_inited;
44 void ultrasnd_debug(int on);
45 void ultrasnd_select_voice(struct ultrasnd_ctx *u,uint8_t reg);
46 void ultrasnd_select_write(struct ultrasnd_ctx *u,uint8_t reg,uint8_t data);
47 void ultrasnd_select_write16(struct ultrasnd_ctx *u,uint8_t reg,uint16_t data);
48 uint16_t ultrasnd_select_read16(struct ultrasnd_ctx *u,uint8_t reg);
49 uint8_t ultrasnd_select_read(struct ultrasnd_ctx *u,uint8_t reg);
50 uint8_t ultrasnd_selected_read(struct ultrasnd_ctx *u);
51 unsigned char ultrasnd_peek(struct ultrasnd_ctx *u,uint32_t ofs);
52 void ultrasnd_poke(struct ultrasnd_ctx *u,uint32_t ofs,uint8_t b);
53 int ultrasnd_valid_dma(struct ultrasnd_ctx *u,int8_t i);
54 int ultrasnd_valid_irq(struct ultrasnd_ctx *u,int8_t i);
55 void ultrasnd_set_active_voices(struct ultrasnd_ctx *u,unsigned char voices);
56 int ultrasnd_probe(struct ultrasnd_ctx *u,int program_cfg);
57 int ultrasnd_irq_taken(int irq);
58 int ultrasnd_dma_taken(int dma);
59 int ultrasnd_port_taken(int port);
60 void ultrasnd_init_ctx(struct ultrasnd_ctx *u);
61 void ultrasnd_free_card(struct ultrasnd_ctx *u);
62 int ultrasnd_card_taken(struct ultrasnd_ctx *u);
64 struct ultrasnd_ctx *ultrasnd_alloc_card();
65 int ultrasnd_test_irq_timer(struct ultrasnd_ctx *u,int irq);
66 struct ultrasnd_ctx *ultrasnd_try_base(uint16_t base);
67 struct ultrasnd_ctx *ultrasnd_try_ultrasnd_env();
68 uint16_t ultrasnd_sample_rate_to_fc(struct ultrasnd_ctx *u,unsigned int r);
69 unsigned char ultrasnd_read_voice_mode(struct ultrasnd_ctx *u,unsigned char voice);
70 void ultrasnd_set_voice_mode(struct ultrasnd_ctx *u,unsigned char voice,uint8_t mode);
71 void ultrasnd_set_voice_fc(struct ultrasnd_ctx *u,unsigned char voice,uint16_t fc);
72 void ultrasnd_set_voice_start(struct ultrasnd_ctx *u,unsigned char voice,uint32_t ofs);
73 void ultrasnd_set_voice_end(struct ultrasnd_ctx *u,unsigned char voice,uint32_t ofs);
74 void ultrasnd_stop_voice(struct ultrasnd_ctx *u,int i);
75 void ultrasnd_start_voice(struct ultrasnd_ctx *u,int i);
76 void ultrasnd_start_voice_imm(struct ultrasnd_ctx *u,int i);
77 void ultrasnd_set_voice_ramp_rate(struct ultrasnd_ctx *u,unsigned char voice,unsigned char adj,unsigned char rate);
78 void ultrasnd_set_voice_ramp_start(struct ultrasnd_ctx *u,unsigned char voice,unsigned char start);
79 void ultrasnd_set_voice_ramp_end(struct ultrasnd_ctx *u,unsigned char voice,unsigned char end);
80 void ultrasnd_set_voice_volume(struct ultrasnd_ctx *u,unsigned char voice,uint16_t vol);
81 uint32_t ultrasnd_read_voice_current(struct ultrasnd_ctx *u,unsigned char voice);
82 void ultrasnd_set_voice_current(struct ultrasnd_ctx *u,unsigned char voice,uint32_t loc);
83 void ultrasnd_set_voice_pan(struct ultrasnd_ctx *u,unsigned char voice,uint8_t pan);
84 void ultrasnd_set_voice_ramp_control(struct ultrasnd_ctx *u,unsigned char voice,uint8_t ctl);
85 unsigned char FAR *ultrasnd_dram_buffer_alloc(struct ultrasnd_ctx *u,unsigned long len);
86 int ultrasnd_send_dram_buffer(struct ultrasnd_ctx *u,uint32_t ofs,unsigned long len,uint8_t flags);
87 void ultrasnd_dram_buffer_free(struct ultrasnd_ctx *u);