libsidplayfp  1.0.3
mos656x.h
1 /*
2  * This file is part of libsidplayfp, a SID player engine.
3  *
4  * Copyright 2011-2013 Leandro Nini <drfiemost@users.sourceforge.net>
5  * Copyright 2007-2010 Antti Lankila
6  * Copyright 2001 Simon White
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21  */
22 
23 #ifndef MOS656X_H
24 #define MOS656X_H
25 
26 #include "sidplayfp/component.h"
27 #include "sidplayfp/EventScheduler.h"
28 
29 
30 class MOS656X: public component, private Event
31 {
32 public:
33  typedef enum
34  {
35  MOS6567R56A = 0 /* OLD NTSC CHIP */
36  ,MOS6567R8 /* NTSC-M */
37  ,MOS6569 /* PAL-B */
38  ,MOS6572 /* PAL-N */
39  } model_t;
40 
41 private:
42  static const char *credit;
43 
44 private:
46  static const int IRQ_RASTER = 1 << 0;
47 
49  static const int IRQ_LIGHTPEN = 1 << 3;
50 
51 protected:
53  static const int FIRST_DMA_LINE = 0x30;
54 
56  static const int LAST_DMA_LINE = 0xf7;
57 
58 protected:
59  event_clock_t m_rasterClk;
60 
63 
65  uint_least16_t cyclesPerLine;
66 
67  uint_least16_t maxRasters;
68 
69  uint_least16_t raster_irq;
70 
72  uint_least16_t lineCycle;
73 
75  uint_least16_t rasterY;
76 
78  uint_least16_t yscroll;
79 
82 
84  bool isBadLine;
85 
87  bool vblanking;
88 
91 
93  uint8_t irqFlags;
94 
96  uint8_t irqMask;
97 
99  uint8_t lpx, lpy;
100 
105  uint8_t sprite_mc_base[8];
107 
109  uint8_t regs[0x40];
110 
111 private:
112  event_clock_t clock();
113 
115  void handleIrqState();
116 
117 protected:
118  MOS656X(EventContext *context);
119  ~MOS656X() {}
120 
121  void event();
122 
123  EventCallback<MOS656X> badLineStateChangeEvent;
124 
126  void badLineStateChange() { setBA(false); }
127 
132  void activateIRQFlag(int flag)
133  {
134  irqFlags |= flag;
135  handleIrqState();
136  }
137 
143  bool readDEN() const { return (regs[0x11] & 0x10) != 0; }
144 
145  bool evaluateIsBadLine() const
146  {
147  return areBadLinesEnabled
148  && rasterY >= FIRST_DMA_LINE
149  && rasterY <= LAST_DMA_LINE
150  && (rasterY & 7) == yscroll;
151  }
152 
153  // Environment Interface
154  virtual void interrupt (bool state) = 0;
155  virtual void setBA (bool state) = 0;
156 
163  uint8_t read(uint_least8_t addr);
164 
173  void write(uint_least8_t addr, uint8_t data);
174 
175 public:
176  void chip(model_t model);
177  void lightpen();
178 
179  // Component Standard Calls
180  void reset();
181 
182  const char *credits() const { return credit; }
183 
184  uint_least16_t getCyclesPerLine() const { return cyclesPerLine; }
185 
186  uint_least16_t getRasterLines() const { return maxRasters; }
187 };
188 
189 #endif // MOS656X_H