2 Skelton for retropc emulator
4 Author : Takeda.Toshiya
15 void PRNFILE::initialize()
19 value = busy_id = ack_id = wait_frames = -1;
20 #ifdef PRINTER_STROBE_RISING_EDGE
29 register_frame_event(this);
32 void PRNFILE::release()
42 busy_id = ack_id = wait_frames = -1;
47 void PRNFILE::event_frame()
49 if(wait_frames > 0 && --wait_frames == 0) {
54 void PRNFILE::write_signal(int id, uint32 data, uint32 mask)
56 if(id == SIG_PRINTER_DATA) {
61 value |= (data & mask);
62 } else if(id == SIG_PRINTER_STROBE) {
63 bool new_strobe = ((data & mask) != 0);
64 #ifdef PRINTER_STROBE_RISING_EDGE
65 bool edge = (!strobe && new_strobe);
67 bool edge = (strobe && !new_strobe);
71 if(edge && value != -1) {
72 if(!fio->IsOpened()) {
79 cancel_event(this, busy_id);
81 register_event(this, EVENT_BUSY, 10000.0, false, &busy_id);
84 // wait 1sec and finish printing
85 #ifdef SUPPORT_VARIABLE_TIMING
86 wait_frames = (int)(vm->get_frame_rate() * 1.0 + 0.5);
88 wait_frames = (int)(FRAMES_PER_SEC * 1.0 + 0.5);
91 } else if(id == SIG_PRINTER_RESET) {
92 bool new_res = ((data & mask) != 0);
100 uint32 PRNFILE::read_signal(int ch)
102 if(ch == SIG_PRINTER_BUSY) {
105 cancel_event(this, busy_id);
111 } else if(ch == SIG_PRINTER_ACK) {
119 void PRNFILE::event_callback(int event_id, int err)
121 if(event_id == EVENT_BUSY) {
124 } else if(event_id == EVENT_ACK) {
130 void PRNFILE::set_busy(bool value)
135 cancel_event(this, ack_id);
137 register_event(this, EVENT_ACK, 10.0, false, &ack_id);
141 write_signals(&outputs_busy, busy ? 0xffffffff : 0);
144 void PRNFILE::set_ack(bool value)
147 write_signals(&outputs_ack, ack ? 0xffffffff : 0);
150 void PRNFILE::open_file()
152 create_date_file_path(file_path, _MAX_PATH, _T("txt"));
153 fio->Fopen(file_path, FILEIO_WRITE_BINARY);
156 void PRNFILE::close_file()
158 if(fio->IsOpened()) {
159 // remove if the file size is less than 2 bytes
160 bool remove = (fio->Ftell() < 2);
163 FILEIO::RemoveFile(file_path);
168 #define STATE_VERSION 2
170 void PRNFILE::save_state(FILEIO* state_fio)
172 state_fio->FputUint32(STATE_VERSION);
173 state_fio->FputInt32(this_device_id);
175 state_fio->FputInt32(value);
176 state_fio->FputInt32(busy_id);
177 state_fio->FputInt32(ack_id);
178 state_fio->FputBool(strobe);
179 state_fio->FputBool(res);
180 state_fio->FputBool(busy);
181 state_fio->FputBool(ack);
184 bool PRNFILE::load_state(FILEIO* state_fio)
188 if(state_fio->FgetUint32() != STATE_VERSION) {
191 if(state_fio->FgetInt32() != this_device_id) {
194 value = state_fio->FgetInt32();
195 busy_id = state_fio->FgetInt32();
196 ack_id = state_fio->FgetInt32();
197 strobe = state_fio->FgetBool();
198 res = state_fio->FgetBool();
199 busy = state_fio->FgetBool();
200 ack = state_fio->FgetBool();