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
25 #include <libspectrum.h>
27 #include "../libzymosis/zymosis.h"
28 #include "../libfusefdc/libfusefdc.h"
29 #include "emucommon.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
60 extern void emuSetMaxSpeed (int maxsp
);
61 extern void emuSetSpeed (int prc
);
62 extern void emuSetPaused (int on
);
63 extern void emuSetDrawFPS (int on
);
65 static inline EMU_MAYBE_UNUSED
int emuIsPlus3DOSModel (int model
) {
66 return (model
>= 0 && model
< ZX_MACHINE_MAX
? basicMachineInfo
[model
].p3dos
: 0);
69 static inline EMU_MAYBE_UNUSED
int emuGetModelFDCType (int model
) {
70 return (emuIsPlus3DOSModel(model
) ? DIF_P3DOS
: DIF_BDI
);
73 static inline int emuIsUPD765 (void) {
74 return (upd765_fdc
&& emuIsPlus3DOSModel(zxModel
));
78 void emuDiskEject (int diskidx
);
79 void emuDiskInsert (int diskidx
);
81 typedef int (*emuDiskReaderFn
) (disk_t
*d
, const void *data
, int size
);
83 // returns 0 on ok, something that is not zero on error
84 int emuDiskInsertWithReader (int diskidx
, const void *buf
, int size
, emuDiskReaderFn reader
);
86 // returns 0 on ok, something that is not zero on error
87 int emuSaveDiskToFile (int diskidx
, const char *fname
);
90 // ////////////////////////////////////////////////////////////////////////// //
91 void emuHideRealMouseCursor (void);
92 void emuShowRealMouseCursor (void);
93 void emuFullScreenChanged (void);
94 void emuRealizeRealMouseCursorState (void);
96 uint8_t emuGetCursorColor (uint8_t c0
, uint8_t c1
);
99 // ////////////////////////////////////////////////////////////////////////// //
100 static __attribute__((always_inline
)) __attribute__((unused
))
101 inline int digitInBase (char ch
, int base
) {
102 if (!ch
|| base
< 1) return -1;
103 if (ch
>= '0' && ch
<= '9') {
105 return (ch
< base
? ch
: -1);
107 if (base
<= 10) return -1;
108 if (ch
>= 'a' && ch
<= 'z') ch
-= 'a';
109 else if (ch
>= 'A' && ch
<= 'Z') ch
-= 'A';
112 return (ch
< base
? ch
: -1);
116 static __attribute__((always_inline
)) __attribute__((unused
))
117 inline int strEqu (const char *s0
, const char *s1
) {
120 if (s0
== s1
) return 1;
121 return (strcmp(s0
, s1
) == 0);
125 static __attribute__((unused
)) inline int strEquCI (const char *s0
, const char *s1
) {
128 if (s0
== s1
) return 1;
129 const size_t s0len
= strlen(s0
);
130 const size_t s1len
= strlen(s1
);
131 if (s0len
!= s1len
) return 0;
132 for (size_t f
= s0len
; f
--; ++s0
, ++s1
) {
133 uint8_t c0
= *((const uint8_t *)s0
);
134 uint8_t c1
= *((const uint8_t *)s1
);
135 // try the easiest case first
136 if (c0
== c1
) continue;
137 c0
|= 0x20; // convert to ascii lowercase
138 if (c0
< 'a' || c0
> 'z') return 0; // it wasn't a letter, no need to check the second char
139 // c0 is guaranteed to be a lowercase ascii here
140 // c1 will become a lowercase ascii only if it was uppercase/lowercase ascii
141 if (c0
!= (c1
|0x20)) return 0;