libsidplayfp 2.15.0
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
31namespace libsidplayfp
32{
33
34class MOS652X;
35
36class SerialPort : private Event
37{
38private:
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 = false;
62
63private:
64 void event() override;
65
66 void flipCnt();
67 void flipFake();
68
69 void doStartSdr() { (loaded ? pending : loaded) = true; }
70
71 void syncCntHistory();
72
73public:
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 {}
82
83 void reset();
84
85 void setModel4485(bool is4485) { model4485 = is4485; }
86
87 void startSdr() { eventScheduler.schedule(startSdrEvent, 1); }
88
89 void switchSerialDirection(bool input);
90
91 void handle();
92};
93
94}
95
96#endif // SERIALPORT_H
Definition EventCallback.h:36
Definition EventScheduler.h:62
Definition Event.h:39
Definition mos652x.h:154
Definition SerialPort.h:37