xref: /qemu/include/hw/misc/mac_via.h (revision 27a4a30e)
1 /*
2  *
3  * Copyright (c) 2011-2018 Laurent Vivier
4  *
5  * This work is licensed under the terms of the GNU GPL, version 2 or later.
6  * See the COPYING file in the top-level directory.
7  */
8 
9 #ifndef HW_MISC_MAC_VIA_H
10 #define HW_MISC_MAC_VIA_H
11 
12 #include "exec/memory.h"
13 #include "hw/sysbus.h"
14 #include "hw/misc/mos6522.h"
15 
16 
17 /* VIA 1 */
18 #define VIA1_IRQ_ONE_SECOND_BIT 0
19 #define VIA1_IRQ_VBLANK_BIT     1
20 #define VIA1_IRQ_ADB_READY_BIT  2
21 #define VIA1_IRQ_ADB_DATA_BIT   3
22 #define VIA1_IRQ_ADB_CLOCK_BIT  4
23 
24 #define VIA1_IRQ_NB             8
25 
26 #define VIA1_IRQ_ONE_SECOND (1 << VIA1_IRQ_ONE_SECOND_BIT)
27 #define VIA1_IRQ_VBLANK     (1 << VIA1_IRQ_VBLANK_BIT)
28 #define VIA1_IRQ_ADB_READY  (1 << VIA1_IRQ_ADB_READY_BIT)
29 #define VIA1_IRQ_ADB_DATA   (1 << VIA1_IRQ_ADB_DATA_BIT)
30 #define VIA1_IRQ_ADB_CLOCK  (1 << VIA1_IRQ_ADB_CLOCK_BIT)
31 
32 
33 #define TYPE_MOS6522_Q800_VIA1 "mos6522-q800-via1"
34 #define MOS6522_Q800_VIA1(obj)  OBJECT_CHECK(MOS6522Q800VIA1State, (obj), \
35                                     TYPE_MOS6522_Q800_VIA1)
36 
37 typedef struct MOS6522Q800VIA1State {
38     /*< private >*/
39     MOS6522State parent_obj;
40 
41     qemu_irq irqs[VIA1_IRQ_NB];
42     uint8_t last_b;
43     uint8_t PRAM[256];
44 
45     /* external timers */
46     QEMUTimer *one_second_timer;
47     int64_t next_second;
48     QEMUTimer *VBL_timer;
49     int64_t next_VBL;
50 } MOS6522Q800VIA1State;
51 
52 
53 /* VIA 2 */
54 #define VIA2_IRQ_SCSI_DATA_BIT  0
55 #define VIA2_IRQ_SLOT_BIT       1
56 #define VIA2_IRQ_UNUSED_BIT     2
57 #define VIA2_IRQ_SCSI_BIT       3
58 #define VIA2_IRQ_ASC_BIT        4
59 
60 #define VIA2_IRQ_NB             8
61 
62 #define VIA2_IRQ_SCSI_DATA  (1 << VIA2_IRQ_SCSI_DATA_BIT)
63 #define VIA2_IRQ_SLOT       (1 << VIA2_IRQ_SLOT_BIT)
64 #define VIA2_IRQ_UNUSED     (1 << VIA2_IRQ_SCSI_BIT)
65 #define VIA2_IRQ_SCSI       (1 << VIA2_IRQ_UNUSED_BIT)
66 #define VIA2_IRQ_ASC        (1 << VIA2_IRQ_ASC_BIT)
67 
68 #define TYPE_MOS6522_Q800_VIA2 "mos6522-q800-via2"
69 #define MOS6522_Q800_VIA2(obj)  OBJECT_CHECK(MOS6522Q800VIA2State, (obj), \
70                                     TYPE_MOS6522_Q800_VIA2)
71 
72 typedef struct MOS6522Q800VIA2State {
73     /*< private >*/
74     MOS6522State parent_obj;
75 } MOS6522Q800VIA2State;
76 
77 
78 #define TYPE_MAC_VIA "mac_via"
79 #define MAC_VIA(obj)   OBJECT_CHECK(MacVIAState, (obj), TYPE_MAC_VIA)
80 
81 typedef struct MacVIAState {
82     SysBusDevice busdev;
83 
84     VMChangeStateEntry *vmstate;
85 
86     /* MMIO */
87     MemoryRegion mmio;
88     MemoryRegion via1mem;
89     MemoryRegion via2mem;
90 
91     /* VIAs */
92     MOS6522Q800VIA1State mos6522_via1;
93     MOS6522Q800VIA2State mos6522_via2;
94 
95     /* RTC */
96     uint32_t tick_offset;
97 
98     uint8_t data_out;
99     int data_out_cnt;
100     uint8_t data_in;
101     uint8_t data_in_cnt;
102     uint8_t cmd;
103     int wprotect;
104     int alt;
105     BlockBackend *blk;
106 
107     /* ADB */
108     ADBBusState adb_bus;
109     QEMUTimer *adb_poll_timer;
110     qemu_irq adb_data_ready;
111     int adb_data_in_size;
112     int adb_data_in_index;
113     int adb_data_out_index;
114     uint8_t adb_data_in[128];
115     uint8_t adb_data_out[16];
116 } MacVIAState;
117 
118 #endif
119