zxemut: init absolute kmouse coords when "absolute" mode is turned on
[zymosis.git] / src / ZXEmuT / emuutils.h
blobf78f468aecc1aac3aeddd945fda8df75d1990b09
1 /***************************************************************************
3 * ZXEmuT -- ZX Spectrum Emulator with Tcl scripting
5 * Copyright (C) 2012-2022 Ketmar Dark <ketmar@ketmar.no-ip.org>
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, version 3 of the License ONLY.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 **************************************************************************/
20 #ifndef ZXEMUT_UTILS_H
21 #define ZXEMUT_UTILS_H
23 #include <stdint.h>
24 #include <SDL.h>
25 #include <libspectrum.h>
27 #include "../libzymosis/zymosis.h"
28 #include "../libfusefdc/libfusefdc.h"
29 #include "emucommon.h"
30 #include "emuvars.h"
33 ////////////////////////////////////////////////////////////////////////////////
34 extern void zxPageROM (int newpg);
35 extern void zxPageRAM (int pageno, int newpg);
36 extern void zxSetScreen (int newpg);
37 extern void zxTRDOSpagein (void);
38 extern void zxTRDOSpageout (void);
41 ////////////////////////////////////////////////////////////////////////////////
42 extern void emuUPD765Reset (void);
43 extern void emuInitDisks (void);
46 ////////////////////////////////////////////////////////////////////////////////
47 extern void emuBuildContentionTable (void);
48 extern void emuRealizeMemoryPaging (void);
50 extern void emuSetMaxSpeed (int maxsp);
51 extern void emuSetSpeed (int prc);
52 extern void emuSetPaused (int on);
53 extern void emuSetLateTimings (int late);
55 extern int emuSetModel (int model, int forced);
56 extern void emuReset (int flags); // bit0: to tr-dos
57 extern void emuResetAY (void); // reset and mute AY
58 extern void emuResetKeyboard (void); // "unpress" all ZX keys
59 extern void emuClearRAM (void);
61 extern void emuSetMaxSpeed (int maxsp);
62 extern void emuSetSpeed (int prc);
63 extern void emuSetPaused (int on);
64 extern void emuSetDrawFPS (int on);
66 static inline EMU_MAYBE_UNUSED int emuIsPlus3DOSModel (int model) {
67 return (model >= 0 && model < ZX_MACHINE_MAX ? basicMachineInfo[model].p3dos : 0);
70 static inline EMU_MAYBE_UNUSED int emuGetModelFDCType (int model) {
71 return (emuIsPlus3DOSModel(model) ? DIF_P3DOS : DIF_BDI);
74 static inline int emuIsUPD765 (void) {
75 return (upd765_fdc && emuIsPlus3DOSModel(zxModel));
79 void emuDiskEject (int diskidx);
80 void emuDiskInsert (int diskidx);
82 typedef int (*emuDiskReaderFn) (disk_t *d, const void *data, int size);
84 // returns 0 on ok, something that is not zero on error
85 int emuDiskInsertWithReader (int diskidx, const void *buf, int size, emuDiskReaderFn reader);
87 // returns 0 on ok, something that is not zero on error
88 int emuSaveDiskToFile (int diskidx, const char *fname);
91 static __attribute__((unused)) inline int emuGetRAMPages (void) {
92 switch (zxModel) {
93 case ZX_MACHINE_48K:
94 return 3;
95 case ZX_MACHINE_128K:
96 case ZX_MACHINE_PLUS2:
97 case ZX_MACHINE_PLUS2A:
98 case ZX_MACHINE_PLUS3:
99 return 8;
100 case ZX_MACHINE_PENTAGON:
101 return zxPentagonMemory>>4;
102 case ZX_MACHINE_SCORPION:
103 return 16; // 256KB
105 return 3;
109 // ////////////////////////////////////////////////////////////////////////// //
110 void emuHideRealMouseCursor (void);
111 void emuShowRealMouseCursor (void);
112 void emuFullScreenChanged (void);
113 void emuRealizeRealMouseCursorState (void);
114 void emuSetKMouseAbsCoords (void);
116 uint8_t emuGetCursorColor (uint8_t c0, uint8_t c1);
119 // ////////////////////////////////////////////////////////////////////////// //
120 static __attribute__((always_inline)) __attribute__((unused))
121 inline int digitInBase (char ch, int base) {
122 if (!ch || base < 1) return -1;
123 if (ch >= '0' && ch <= '9') {
124 ch -= '0';
125 return (ch < base ? ch : -1);
127 if (base <= 10) return -1;
128 if (ch >= 'a' && ch <= 'z') ch -= 'a';
129 else if (ch >= 'A' && ch <= 'Z') ch -= 'A';
130 else return -1;
131 ch += 10;
132 return (ch < base ? ch : -1);
136 static __attribute__((always_inline)) __attribute__((unused))
137 inline int strEqu (const char *s0, const char *s1) {
138 if (!s0) s0 = "";
139 if (!s1) s1 = "";
140 if (s0 == s1) return 1;
141 return (strcmp(s0, s1) == 0);
145 static __attribute__((unused)) inline int strEquCI (const char *s0, const char *s1) {
146 if (!s0) s0 = "";
147 if (!s1) s1 = "";
148 if (s0 == s1) return 1;
149 const size_t s0len = strlen(s0);
150 const size_t s1len = strlen(s1);
151 if (s0len != s1len) return 0;
152 for (size_t f = s0len; f--; ++s0, ++s1) {
153 uint8_t c0 = *((const uint8_t *)s0);
154 uint8_t c1 = *((const uint8_t *)s1);
155 // try the easiest case first
156 if (c0 == c1) continue;
157 c0 |= 0x20; // convert to ascii lowercase
158 if (c0 < 'a' || c0 > 'z') return 0; // it wasn't a letter, no need to check the second char
159 // c0 is guaranteed to be a lowercase ascii here
160 // c1 will become a lowercase ascii only if it was uppercase/lowercase ascii
161 if (c0 != (c1|0x20)) return 0;
163 return 1;
167 #endif