libsidplayfp  2.0.2
lightpen.h
1 /*
2  * This file is part of libsidplayfp, a SID player engine.
3  *
4  * Copyright 2011-2015 Leandro Nini <drfiemost@users.sourceforge.net>
5  * Copyright 2009-2014 VICE Project
6  * Copyright 2007-2010 Antti Lankila
7  * Copyright 2001 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 LIGHTPEN_H
25 #define LIGHTPEN_H
26 
27 namespace libsidplayfp
28 {
29 
34 class Lightpen
35 {
36 private:
38  unsigned int lastLine;
39 
41  unsigned int cyclesPerLine;
42 
44  unsigned int lpx;
45 
47  unsigned int lpy;
48 
50  bool isTriggered;
51 
52 public:
59  void setScreenSize(unsigned int height, unsigned int width)
60  {
61  lastLine = height - 1;
62  cyclesPerLine = width;
63  }
64 
68  void reset()
69  {
70  lpx = 0;
71  lpy = 0;
72  isTriggered = false;
73  }
74 
78  uint8_t getX() const { return lpx; }
79 
83  uint8_t getY() const { return lpy; }
84 
92  bool retrigger(unsigned int lineCycle, unsigned int rasterY)
93  {
94  const bool triggered = trigger(lineCycle, rasterY);
95  switch (cyclesPerLine)
96  {
97  case 63:
98  default:
99  lpx = 0xd1;
100  break;
101  case 65:
102  lpx = 0xd5;
103  break;
104  }
105  return triggered;
106  }
107 
115  bool trigger(unsigned int lineCycle, unsigned int rasterY)
116  {
117  if (!isTriggered)
118  {
119  // don't trigger on the last line, except on the first cycle
120  if ((rasterY == lastLine) && (lineCycle > 0))
121  {
122  return false;
123  }
124 
125  isTriggered = true;
126 
127  // Latch current coordinates
128  lpx = (lineCycle << 2) + 2;
129  lpy = rasterY;
130  return true;
131  }
132  return false;
133  }
134 
138  void untrigger() { isTriggered = false; }
139 };
140 
141 }
142 
143 #endif
libsidplayfp::Lightpen::untrigger
void untrigger()
Definition: lightpen.h:138
libsidplayfp::Lightpen
Definition: lightpen.h:35
libsidplayfp::Lightpen::getY
uint8_t getY() const
Definition: lightpen.h:83
libsidplayfp::Lightpen::retrigger
bool retrigger(unsigned int lineCycle, unsigned int rasterY)
Definition: lightpen.h:92
libsidplayfp::Lightpen::setScreenSize
void setScreenSize(unsigned int height, unsigned int width)
Definition: lightpen.h:59
libsidplayfp::Lightpen::trigger
bool trigger(unsigned int lineCycle, unsigned int rasterY)
Definition: lightpen.h:115
libsidplayfp::Lightpen::reset
void reset()
Definition: lightpen.h:68
libsidplayfp::Lightpen::getX
uint8_t getX() const
Definition: lightpen.h:78