1 /////////////////////////////////////////////////////////////////////////
2 // $Id: pit82c54.h,v 1.16 2007/09/28 19:52:05 sshwarts Exp $
3 /////////////////////////////////////////////////////////////////////////
6 * Emulator of an Intel 8254/82C54 Programmable Interval Timer.
7 * Greg Alexander <yakovlev@usa.com>
11 #define _PIT_82C54_H_ 1
15 typedef void (*out_handler_t
)(bx_bool value
);
17 class pit_82C54
: public logfunctions
{
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
51 bx_bool GATE
; //GATE Input value at end of cycle
52 bx_bool OUTpin
; //OUT output this cycle
55 Bit32u count
; //Counter value this cycle
56 Bit16u outlatch
; //Output latch this cycle
57 Bit16u inlatch
; //Input latch this cycle
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.
67 bx_bool count_LSB_latched
;
68 bx_bool count_MSB_latched
;
69 bx_bool status_latched
;
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.
80 Bit32u next_change_time
; //Next time something besides count changes.
82 out_handler_t out_handler
; // OUT pin callback (for IRQ0)
85 counter_type counter
[3];
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
);
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
);