OSDN Git Service

[VM][Qt][UI][EMU][WIP] Use EMU_TEMPLATE:: instead of EMU:: . Some VMs are not apply...
[csp-qt/common_source_project-fm7.git] / source / src / vm / i8259.h
1 /*
2         Skelton for retropc emulator
3
4         Author : Takeda.Toshiya
5         Date   : 2005.06.10-
6
7         [ i8259 ]
8 */
9
10 #ifndef _I8259_H_
11 #define _I8259_H_
12
13 //#include "vm.h"
14 //#include "../emu.h"
15 #include "device.h"
16
17 /*
18         NOTE: I8259_MAX_CHIPS shoud be 1 or 2
19 */
20
21 #define SIG_I8259_IR0   0
22 #define SIG_I8259_IR1   1
23 #define SIG_I8259_IR2   2
24 #define SIG_I8259_IR3   3
25 #define SIG_I8259_IR4   4
26 #define SIG_I8259_IR5   5
27 #define SIG_I8259_IR6   6
28 #define SIG_I8259_IR7   7
29 #define SIG_I8259_CHIP0 0
30 #define SIG_I8259_CHIP1 8
31 //#define SIG_I8259_CHIP2       16
32 //#define SIG_I8259_CHIP3       24
33
34 #define I8259_ADDR_CHIP0        0
35 #define I8259_ADDR_CHIP1        2
36 //#define I8259_ADDR_CHIP2      4
37 //#define I8259_ADDR_CHIP3      6
38
39 struct  i8259_pic_t {
40         uint8_t imr, isr, irr, irr_tmp, prio;
41         uint8_t icw1, icw2, icw3, icw4, ocw3;
42         uint8_t icw2_r, icw3_r, icw4_r;
43         int irr_tmp_id;
44 };
45
46 class I8259 : public DEVICE
47 {
48 private:
49         DEVICE* d_cpu;
50
51         struct i8259_pic_t pic[2];
52         int req_chip, req_level;
53         uint8_t req_bit;
54         uint32_t __I8259_MAX_CHIPS;
55         uint32_t __CHIP_MASK;
56         bool __I8259_PC98_HACK;
57 public:
58         I8259(VM_TEMPLATE* parent_vm, EMU_TEMPLATE* parent_emu) : DEVICE(parent_vm, parent_emu)
59         {
60                 d_cpu = NULL;
61                 __I8259_MAX_CHIPS = 0;
62                 __CHIP_MASK = 0xffffffff;
63                 __I8259_PC98_HACK = false;
64                 for(int c = 0; c < 2; c++) {
65                         memset(&(pic[c]), 0x00, sizeof(struct i8259_pic_t));
66                         pic[c].irr_tmp_id = -1;
67                 }
68                 set_device_name(_T("i8259 PIC"));
69         }
70         ~I8259() {}
71         
72         // common functions
73         void initialize();
74         void reset();
75         void __FASTCALL write_io8(uint32_t addr, uint32_t data);
76         uint32_t __FASTCALL read_io8(uint32_t addr);
77         void __FASTCALL write_signal(int id, uint32_t data, uint32_t mask);
78         uint32_t __FASTCALL read_signal(int id);
79         void event_callback(int event_id, int err);
80         bool process_state(FILEIO* state_fio, bool loading);
81         // interrupt common functions
82         void set_intr_line(bool line, bool pending, uint32_t bit)
83         {
84                 // request from Z80 familly
85                 write_signal(bit, line ? 1 : 0, 1);
86         }
87         uint32_t get_intr_ack();
88         void update_intr();
89         
90         // unique function
91         void set_context_cpu(DEVICE* device)
92         {
93                 d_cpu = device;
94         }
95 };
96
97 #endif
98