xref: /openbmc/qemu/include/hw/audio/asc.h (revision b49f4755)
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 "qemu/osdep.h"
17 #include "hw/sysbus.h"
18 #include "audio/audio.h"
19 
20 #define ASC_FREQ 22257
21 
22 enum {
23     ASC_TYPE_ASC    = 0,  /* original discrete Apple Sound Chip */
24     ASC_TYPE_EASC   = 1   /* discrete Enhanced Apple Sound Chip */
25 };
26 
27 #define ASC_FIFO_OFFSET    0x0
28 #define ASC_FIFO_SIZE      0x400
29 
30 #define ASC_REG_OFFSET     0x800
31 #define ASC_REG_SIZE       0x60
32 
33 #define ASC_EXTREG_OFFSET  0xf00
34 #define ASC_EXTREG_SIZE    0x20
35 
36 typedef struct ASCFIFOState {
37     int index;
38 
39     MemoryRegion mem_fifo;
40     uint8_t fifo[ASC_FIFO_SIZE];
41     uint8_t int_status;
42 
43     int cnt;
44     int wptr;
45     int rptr;
46 
47     MemoryRegion mem_extregs;
48     uint8_t extregs[ASC_EXTREG_SIZE];
49 
50     int xa_cnt;
51     uint8_t xa_val;
52     uint8_t xa_flags;
53     int16_t xa_last[2];
54 } ASCFIFOState;
55 
56 struct ASCState {
57     SysBusDevice parent_obj;
58 
59     uint8_t type;
60     MemoryRegion asc;
61     MemoryRegion mem_fifo;
62     MemoryRegion mem_regs;
63     MemoryRegion mem_extregs;
64 
65     QEMUSoundCard card;
66     SWVoiceOut *voice;
67     uint8_t *mixbuf;
68     int samples;
69     int shift;
70 
71     uint8_t *silentbuf;
72 
73     /* Time when we were last able to generate samples */
74     int64_t fifo_empty_ns;
75 
76     qemu_irq irq;
77 
78     ASCFIFOState fifos[2];
79 
80     uint8_t regs[ASC_REG_SIZE];
81 };
82 
83 #define TYPE_ASC "apple-sound-chip"
84 OBJECT_DECLARE_SIMPLE_TYPE(ASCState, ASC)
85 
86 #endif
87