xref: /openbmc/qemu/include/hw/audio/asc.h (revision b86c6ba6)
1 /*
2  * QEMU Apple Sound Chip emulation
3  *
4  * Apple Sound Chip (ASC) 344S0063
5  * Enhanced Apple Sound Chip (EASC) 343S1063
6  *
7  * Copyright (c) 2012-2018 Laurent Vivier <laurent@vivier.eu>
8  * Copyright (c) 2022 Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>
9  *
10  * SPDX-License-Identifier: GPL-2.0-or-later
11  */
12 
13 #ifndef HW_AUDIO_ASC_H
14 #define HW_AUDIO_ASC_H
15 
16 #include "hw/sysbus.h"
17 #include "audio/audio.h"
18 
19 #define ASC_FREQ 22257
20 
21 enum {
22     ASC_TYPE_ASC    = 0,  /* original discrete Apple Sound Chip */
23     ASC_TYPE_EASC   = 1   /* discrete Enhanced Apple Sound Chip */
24 };
25 
26 #define ASC_FIFO_OFFSET    0x0
27 #define ASC_FIFO_SIZE      0x400
28 
29 #define ASC_REG_OFFSET     0x800
30 #define ASC_REG_SIZE       0x60
31 
32 #define ASC_EXTREG_OFFSET  0xf00
33 #define ASC_EXTREG_SIZE    0x20
34 
35 typedef struct ASCFIFOState {
36     int index;
37 
38     MemoryRegion mem_fifo;
39     uint8_t fifo[ASC_FIFO_SIZE];
40     uint8_t int_status;
41 
42     int cnt;
43     int wptr;
44     int rptr;
45 
46     MemoryRegion mem_extregs;
47     uint8_t extregs[ASC_EXTREG_SIZE];
48 
49     int xa_cnt;
50     uint8_t xa_val;
51     uint8_t xa_flags;
52     int16_t xa_last[2];
53 } ASCFIFOState;
54 
55 struct ASCState {
56     SysBusDevice parent_obj;
57 
58     uint8_t type;
59     MemoryRegion asc;
60     MemoryRegion mem_fifo;
61     MemoryRegion mem_regs;
62     MemoryRegion mem_extregs;
63 
64     QEMUSoundCard card;
65     SWVoiceOut *voice;
66     uint8_t *mixbuf;
67     int samples;
68     int shift;
69 
70     uint8_t *silentbuf;
71 
72     /* Time when we were last able to generate samples */
73     int64_t fifo_empty_ns;
74 
75     qemu_irq irq;
76 
77     ASCFIFOState fifos[2];
78 
79     uint8_t regs[ASC_REG_SIZE];
80 };
81 
82 #define TYPE_ASC "apple-sound-chip"
83 OBJECT_DECLARE_SIMPLE_TYPE(ASCState, ASC)
84 
85 #endif
86