OSDN Git Service

[VM][General] Merge upstream 2016-04-01 #1.
[csp-qt/common_source_project-fm7.git] / source / src / vm / mz80k / printer.cpp
1 /*
2         SHARP MZ-80K/C Emulator 'EmuZ-80K'
3         SHARP MZ-1200 Emulator 'EmuZ-1200'
4         SHARP MZ-80A Emulator 'EmuZ-80A'
5
6         Author : Hideki Suga
7         Date   : 2016.03.18-
8
9         [ printer ]
10 */
11
12 #include "printer.h"
13
14 void PRINTER::write_io8(uint32_t addr, uint32_t data)
15 {
16         switch(addr & 0xff) {
17         case 0xfe:
18                 d_prn->write_signal(SIG_PRINTER_STROBE, data, 0x80);
19                 d_prn->write_signal(SIG_PRINTER_RESET, data, 0x40);
20                 break;
21         case 0xff:
22 #if defined(_MZ1200) || defined(_MZ80K)
23                 out_ch = data & 0xff;
24 #endif
25                 d_prn->write_signal(SIG_PRINTER_DATA, data, 0xff);
26                 break;
27         }
28 }
29
30 uint32_t PRINTER::read_io8(uint32_t addr)
31 {
32         switch(addr & 0xff) {
33         case 0xfe:
34 #if defined(_MZ1200) || defined(_MZ80K)
35                 if(out_ch == 0x05) {
36                         return 0xf0 | (d_prn->read_signal(SIG_PRINTER_BUSY) ? 1 : 0);
37                 } else
38 #endif
39                 return 0xf2 | (d_prn->read_signal(SIG_PRINTER_BUSY) ? 1 : 0);
40         }
41         return 0xff;
42 }
43
44 #if defined(_MZ1200) || defined(_MZ80K)
45 #define STATE_VERSION   1
46
47 void PRINTER::save_state(FILEIO* state_fio)
48 {
49         state_fio->FputUint32(STATE_VERSION);
50         state_fio->FputInt32(this_device_id);
51         
52         state_fio->FputUint8(out_ch);
53 }
54
55 bool PRINTER::load_state(FILEIO* state_fio)
56 {
57         if(state_fio->FgetUint32() != STATE_VERSION) {
58                 return false;
59         }
60         if(state_fio->FgetInt32() != this_device_id) {
61                 return false;
62         }
63         out_ch = state_fio->FgetUint8();
64         return true;
65 }
66 #endif
67