libsidplayfp  1.8.3
lightpen.h
1 /*
2  * This file is part of libsidplayfp, a SID player engine.
3  *
4  * Copyright 2011-2014 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 
30 class Lightpen
31 {
32 private:
34  unsigned int lastLine;
35 
37  unsigned int cyclesPerLine;
38 
40  unsigned int lpx;
41 
43  unsigned int lpy;
44 
46  bool isTriggered;
47 
48 public:
55  void setScreenSize(unsigned int height, unsigned int width)
56  {
57  lastLine = height - 1;
58  cyclesPerLine = width;
59  }
60 
64  void reset()
65  {
66  lpx = 0;
67  lpy = 0;
68  isTriggered = false;
69  }
70 
74  uint8_t getX() const { return lpx; }
75 
79  uint8_t getY() const { return lpy; }
80 
88  bool retrigger(unsigned int lineCycle, unsigned int rasterY)
89  {
90  const bool triggered = trigger(lineCycle, rasterY);
91  switch (cyclesPerLine)
92  {
93  case 63:
94  default:
95  lpx = 0xd1;
96  break;
97  case 65:
98  lpx = 0xd5;
99  break;
100  }
101  return triggered;
102  }
103 
111  bool trigger(unsigned int lineCycle, unsigned int rasterY)
112  {
113  if (!isTriggered)
114  {
115  // don't trigger on the last line, except on the first cycle
116  if ((rasterY == lastLine) && (lineCycle > 0)) {
117  return false;
118  }
119 
120  isTriggered = true;
121 
122  // Latch current coordinates
123  lpx = (lineCycle << 2) + 2;
124  lpy = rasterY;
125  return true;
126  }
127  return false;
128  }
129 
133  void untrigger() { isTriggered = false; }
134 };
135 
136 #endif
void untrigger()
Definition: lightpen.h:133
uint8_t getY() const
Definition: lightpen.h:79
void reset()
Definition: lightpen.h:64
Definition: lightpen.h:30
void setScreenSize(unsigned int height, unsigned int width)
Definition: lightpen.h:55
bool retrigger(unsigned int lineCycle, unsigned int rasterY)
Definition: lightpen.h:88
bool trigger(unsigned int lineCycle, unsigned int rasterY)
Definition: lightpen.h:111
uint8_t getX() const
Definition: lightpen.h:74