- added instructions how to update the online documentation
[bochs-mirror.git] / iodev / pit82c54.h
blob88e4113550778f44b74e553c9cbc4ace27b39e5e
1 /////////////////////////////////////////////////////////////////////////
2 // $Id: pit82c54.h,v 1.16 2007/09/28 19:52:05 sshwarts Exp $
3 /////////////////////////////////////////////////////////////////////////
4 //
5 /*
6 * Emulator of an Intel 8254/82C54 Programmable Interval Timer.
7 * Greg Alexander <yakovlev@usa.com>
8 */
10 #ifndef _PIT_82C54_H_
11 #define _PIT_82C54_H_ 1
13 //#include "bochs.h"
15 typedef void (*out_handler_t)(bx_bool value);
17 class pit_82C54 : public logfunctions {
18 public:
19 //Please do not use these. They are public because they have to be
20 // to compile on some platforms. They are not to be used by other
21 // classes.
23 enum rw_status {
24 LSByte=0,
25 MSByte=1,
26 LSByte_multiple=2,
27 MSByte_multiple=3
30 private:
32 enum {
33 MAX_COUNTER=2,
34 MAX_ADDRESS=3,
35 CONTROL_ADDRESS=3,
36 MAX_MODE=5
39 enum real_RW_status {
40 LSB_real=1,
41 MSB_real=2,
42 BOTH_real=3
45 enum problem_type {
46 UNL_2P_READ=1
49 struct counter_type {
50 //Chip IOs;
51 bx_bool GATE; //GATE Input value at end of cycle
52 bx_bool OUTpin; //OUT output this cycle
54 //Architected state;
55 Bit32u count; //Counter value this cycle
56 Bit16u outlatch; //Output latch this cycle
57 Bit16u inlatch; //Input latch this cycle
58 Bit8u status_latch;
60 //Status Register data;
61 Bit8u rw_mode; //2-bit R/W mode from command word register.
62 Bit8u mode; //3-bit mode from command word register.
63 bx_bool bcd_mode; //1-bit BCD vs. Binary setting.
64 bx_bool null_count; //Null count bit of status register.
66 //Latch status data;
67 bx_bool count_LSB_latched;
68 bx_bool count_MSB_latched;
69 bx_bool status_latched;
71 //Miscelaneous State;
72 Bit32u count_binary; //Value of the count in binary.
73 bx_bool triggerGATE; //Whether we saw GATE rise this cycle.
74 rw_status write_state; //Read state this cycle
75 rw_status read_state; //Read state this cycle
76 bx_bool count_written; //Whether a count written since programmed
77 bx_bool first_pass; //Whether or not this is the first loaded count.
78 bx_bool state_bit_1; //Miscelaneous state bits.
79 bx_bool state_bit_2;
80 Bit32u next_change_time; //Next time something besides count changes.
81 //0 means never.
82 out_handler_t out_handler; // OUT pin callback (for IRQ0)
85 counter_type counter[3];
87 Bit8u controlword;
89 int seen_problems;
91 void latch_counter(counter_type & thisctr);
93 void set_OUT (counter_type & thisctr, bx_bool data);
95 void set_count (counter_type & thisctr, Bit32u data) BX_CPP_AttrRegparmN(2);
97 void set_count_to_binary (counter_type & thisctr) BX_CPP_AttrRegparmN(1);
99 void set_binary_to_count (counter_type & thisctr) BX_CPP_AttrRegparmN(1);
101 void decrement (counter_type & thisctr) BX_CPP_AttrRegparmN(1);
103 void decrement_multiple(counter_type & thisctr, Bit32u cycles) BX_CPP_AttrRegparmN(2);
105 void clock(Bit8u cnum) BX_CPP_AttrRegparmN(1);
107 void print_counter(counter_type & thisctr);
109 public:
110 pit_82C54 (void);
111 void init (void);
112 void reset (unsigned type);
113 void register_state(bx_param_c *parent);
115 void clock_all(Bit32u cycles);
116 void clock_multiple(Bit8u cnum, Bit32u cycles);
118 Bit8u read(Bit8u address);
119 void write(Bit8u address, Bit8u data);
121 void set_GATE(Bit8u cnum, bx_bool data);
122 bx_bool read_GATE(Bit8u cnum);
124 bx_bool read_OUT(Bit8u cnum);
125 void set_OUT_handler(Bit8u cnum, out_handler_t outh);
127 Bit32u get_clock_event_time(Bit8u cnum);
128 Bit32u get_next_event_time(void);
129 Bit16u get_inlatch(int countnum);
131 void print_cnum(Bit8u cnum);
134 #endif