more scanline shader parameters
[zxemut.git] / zxinfo.d
blob42bf41c27e8908d84921e36f6b9cf9be2c3664fb
1 /* This file is paritally taken from libspectrum,
2 * Copyright (c) 2003 Philip Kendall ( philip-fuse@shadowmagic.org.uk )
3 * Copyright (c) 2016 Stuart Brady
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 module zxinfo;
22 // ////////////////////////////////////////////////////////////////////////// //
23 //public __gshared ZXTimings curmachine = baseTimings[0];
26 // ////////////////////////////////////////////////////////////////////////// //
27 public struct FrameTimigs {
28 // line timings in tstates
29 ushort leftBorder, horizontalScreen, rightBorder, horizontalRetrace;
30 // frame timings in lines
31 ushort topBorder, verticalScreen, bottomBorder, verticalRetrace;
32 // how long does an interrupt last in tstates
33 ubyte interruptLength;
34 // how long after interrupt is the top-level pixel of the main screen displayed
35 uint topLeftPixel;
37 uint tstatesPerLine;
38 uint linesPerFrame;
39 uint tstatesPerFrame;
41 this (ushort alb, ushort ahs, ushort arb, ushort ahr, ushort atb, ushort avs, ushort abb, ushort avr, ubyte ailen, uint atlp) pure nothrow @safe @nogc {
42 leftBorder = alb;
43 horizontalScreen = ahs;
44 rightBorder = arb;
45 horizontalRetrace = ahr;
46 topBorder = atb;
47 verticalScreen = avs;
48 bottomBorder = abb;
49 verticalRetrace = avr;
50 interruptLength = ailen;
51 topLeftPixel = atlp;
52 tstatesPerLine = leftBorder+horizontalScreen+rightBorder+horizontalRetrace;
53 linesPerFrame = topBorder+verticalScreen+bottomBorder+verticalRetrace;
54 tstatesPerFrame = tstatesPerLine*linesPerFrame;
59 // ////////////////////////////////////////////////////////////////////////// //
60 private:
61 static immutable FrameTimigs frameTimingFerranti5C6C = FrameTimigs(
62 24, 128, 24, 48, /* Horizontal, 224 clocks per line */
63 48, 192, 48, 24, /* Vertical, 312 lines per frame */
64 32, 14336
67 static immutable FrameTimigs frameTimingFerranti7C = FrameTimigs(
68 24, 128, 24, 52, /* Horizontal, 228 clocks per line */
69 48, 192, 48, 23, /* Vertical, 311 lines per frame */
70 36, 14362
73 static immutable FrameTimigs frameTimingAmstradAsic = FrameTimigs(
74 24, 128, 24, 52, /* Horizontal, 228 clocks per line */
75 48, 192, 48, 23, /* Vertical, 311 lines per frame */
76 32, 14365
79 static immutable FrameTimigs frameTimingPentagon = FrameTimigs(
80 36, 128, 28, 32, /* Horizontal, 224 clocks per line */
81 64, 192, 48, 16, /* Vertical 320 lines per frame */
82 36, 17988
86 // ////////////////////////////////////////////////////////////////////////// //
87 public enum ZXContention {
88 None,
89 C48,
90 C128,
93 /// the frame timings of a machine
94 public struct ZXTimings {
95 string name;
96 uint cpuSpeed; // processor speed in Hz
97 uint aySpeed; // AY clock speed in Hz
98 ushort mem; // memory, kb
99 bool pentagon;
100 ZXContention contention;
101 immutable(FrameTimigs)* timings;
105 // ////////////////////////////////////////////////////////////////////////// //
106 // the actual data from which the full timings are constructed
107 public static immutable ZXTimings[18] baseTimings = [
108 ZXTimings("48", 3500000, 0, 48, false, ZXContention.C48, &frameTimingFerranti5C6C),
109 ZXTimings("128", 3546900, 1773400, 128, false, ZXContention.C128, &frameTimingFerranti7C),
110 ZXTimings("Plus2", 3546900, 1773400, 128, false, ZXContention.C128, &frameTimingFerranti7C),
111 ZXTimings("Plus2A", 3546900, 1773400, 128, false, ZXContention.C128, &frameTimingAmstradAsic),
112 ZXTimings("Plus3", 3546900, 1773400, 128, false, ZXContention.C128, &frameTimingAmstradAsic),
113 ZXTimings("Plus3e", 3546900, 1773400, 128, false, ZXContention.C128, &frameTimingAmstradAsic),
114 ZXTimings("Pentagon", 3584000, 1792000, 128, true, ZXContention.None, &frameTimingPentagon),
115 ZXTimings("Pentagon512", 3584000, 1792000, 512, true, ZXContention.None, &frameTimingPentagon),
116 //ZXTimings("Pentagon1024", 3584000, 1792000, 1024, true, ZXContention.None, &frameTimingPentagon),
120 // ////////////////////////////////////////////////////////////////////////// //
121 import iv.strex;
123 public immutable(ZXTimings) zxFindMachine (const(char)[] name, bool* found=null) nothrow @trusted @nogc {
124 int firstAbbr = -1;
125 foreach (immutable idx, const ref bt; baseTimings[]) {
126 if (strEquCI(bt.name, name)) {
127 if (found !is null) *found = true;
128 return bt;
130 if (firstAbbr < 0 && name.length < bt.name.length && strEquCI(bt.name[0..name.length], name)) { firstAbbr = cast(int)idx; }
132 if (found !is null) *found = (firstAbbr >= 0);
133 if (firstAbbr < 0) firstAbbr = 0;
134 return baseTimings[firstAbbr];
138 // ////////////////////////////////////////////////////////////////////////// //
139 public struct ZXKeyInfo {
140 string name;
141 //ubyte port;
142 //ubyte mask;
143 ushort portmask;
145 pure nothrow @safe @nogc:
146 this (string aname, ubyte aport, ubyte amask) { name = aname; portmask = cast(ushort)((aport<<8)|amask); }
147 @property ubyte port () const { pragma(inline, true); return cast(ubyte)(portmask>>8); }
148 @property ubyte mask () const { pragma(inline, true); return cast(ubyte)portmask; }
152 public static immutable ZXKeyInfo[49] zxKeyInfo = [
153 // keyboard
154 ZXKeyInfo("cap", 0, 0x01),
155 ZXKeyInfo("cs", 0, 0x01),
156 ZXKeyInfo("z", 0, 0x02),
157 ZXKeyInfo("x", 0, 0x04),
158 ZXKeyInfo("c", 0, 0x08),
159 ZXKeyInfo("v", 0, 0x10),
160 ZXKeyInfo("a", 1, 0x01),
161 ZXKeyInfo("s", 1, 0x02),
162 ZXKeyInfo("d", 1, 0x04),
163 ZXKeyInfo("f", 1, 0x08),
164 ZXKeyInfo("g", 1, 0x10),
165 ZXKeyInfo("q", 2, 0x01),
166 ZXKeyInfo("w", 2, 0x02),
167 ZXKeyInfo("e", 2, 0x04),
168 ZXKeyInfo("r", 2, 0x08),
169 ZXKeyInfo("t", 2, 0x10),
170 ZXKeyInfo("1", 3, 0x01),
171 ZXKeyInfo("2", 3, 0x02),
172 ZXKeyInfo("3", 3, 0x04),
173 ZXKeyInfo("4", 3, 0x08),
174 ZXKeyInfo("5", 3, 0x10),
175 ZXKeyInfo("0", 4, 0x01),
176 ZXKeyInfo("9", 4, 0x02),
177 ZXKeyInfo("8", 4, 0x04),
178 ZXKeyInfo("7", 4, 0x08),
179 ZXKeyInfo("6", 4, 0x10),
180 ZXKeyInfo("p", 5, 0x01),
181 ZXKeyInfo("o", 5, 0x02),
182 ZXKeyInfo("i", 5, 0x04),
183 ZXKeyInfo("u", 5, 0x08),
184 ZXKeyInfo("y", 5, 0x10),
185 ZXKeyInfo("ent", 6, 0x01),
186 ZXKeyInfo("enter", 6, 0x01),
187 ZXKeyInfo("l", 6, 0x02),
188 ZXKeyInfo("k", 6, 0x04),
189 ZXKeyInfo("j", 6, 0x08),
190 ZXKeyInfo("h", 6, 0x10),
191 ZXKeyInfo("spc", 7, 0x01),
192 ZXKeyInfo("space", 7, 0x01),
193 ZXKeyInfo("sym", 7, 0x02),
194 ZXKeyInfo("ss", 7, 0x02),
195 ZXKeyInfo("m", 7, 0x04),
196 ZXKeyInfo("n", 7, 0x08),
197 ZXKeyInfo("b", 7, 0x10),
198 // kempston
199 ZXKeyInfo("kright", 8, 0x01),
200 ZXKeyInfo("kleft", 8, 0x02),
201 ZXKeyInfo("kdown", 8, 0x04),
202 ZXKeyInfo("kup", 8, 0x08),
203 ZXKeyInfo("kfire", 8, 0x10),