libsidplayfp  2.2.2
SerialPort.h
1 /*
2  * This file is part of libsidplayfp, a SID player engine.
3  *
4  * Copyright 2011-2020 Leandro Nini <drfiemost@users.sourceforge.net>
5  * Copyright 2009-2014 VICE Project
6  * Copyright 2007-2010 Antti Lankila
7  * Copyright 2000 Simon White
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22  */
23 
24 #ifndef SERIALPORT_H
25 #define SERIALPORT_H
26 
27 #include "interrupt.h"
28 
29 #include "Event.h"
30 
31 namespace libsidplayfp
32 {
33 
34 class MOS652X;
35 
36 class SerialPort : private Event
37 {
38 private:
40  MOS652X &parent;
41 
43  EventScheduler &eventScheduler;
44 
45  EventCallback<SerialPort> flipCntEvent;
46  EventCallback<SerialPort> flipFakeEvent;
47  EventCallback<SerialPort> startSdrEvent;
48 
49  event_clock_t lastSync;
50 
51  int count;
52 
53  uint8_t cnt;
54  uint8_t cntHistory;
55 
56  bool loaded;
57  bool pending;
58 
59  bool forceFinish;
60 
61  bool model4485;
62 
63 private:
64  void event() override;
65 
66  void flipCnt();
67  void flipFake();
68 
69  void doStartSdr();
70 
71  void syncCntHistory();
72 
73 public:
74  explicit SerialPort(EventScheduler &scheduler, MOS652X &parent) :
75  Event("Serial Port interrupt"),
76  parent(parent),
77  eventScheduler(scheduler),
78  flipCntEvent("flip CNT", *this, &SerialPort::flipCnt),
79  flipFakeEvent("flip fake", *this, &SerialPort::flipFake),
80  startSdrEvent("start SDR", *this, &SerialPort::doStartSdr),
81  model4485(false)
82  {}
83 
84  void reset();
85 
86  void setModel4485(bool is4485) { model4485 = is4485; }
87 
88  void startSdr();
89 
90  void switchSerialDirection(bool input);
91 
92  void handle();
93 };
94 
95 }
96 
97 #endif // SERIALPORT_H
Definition: EventCallback.h:36
Definition: EventScheduler.h:62
Definition: Event.h:39
Event(const char *const name)
Definition: Event.h:59
Definition: mos652x.h:151
Definition: SerialPort.h:37