psid64 1.3
Loading...
Searching...
No Matches
psid64.h
1// SPDX-License-Identifier: GPL-2.0-or-later
2/*
3 psid64 - create a C64 executable from a PSID file
4 Copyright (C) 2001-2023 Roland Hermans <rolandh@users.sourceforge.net>
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
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.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19*/
20
22// I N C L U D E S
24
25#ifndef PSID64_H
26#define PSID64_H
27
28#include <iostream>
29#include <string>
30
31#include <sidplay/utils/SidDatabase.h>
32#include <sidplay/utils/SidTuneMod.h>
33
34
36// F O R W A R D D E C L A R A T O R S
38
39class Screen;
40class SidId;
41class STIL;
42
43
45// D E F I N I T I O N S
47
51class Psid64
52{
53public:
54 enum Theme {
55 THEME_DEFAULT,
56 THEME_BLUE,
57 THEME_C1541_ULTIMATE,
58 THEME_COAL,
59 THEME_DUTCH,
60 THEME_KERNAL,
61 THEME_LIGHT,
62 THEME_MONDRIAAN,
63 THEME_OCEAN,
64 THEME_PENCIL,
65 THEME_RAINBOW
66 };
67
72
77
82 bool setHvscRoot(const std::string &hvscRoot);
83
87 inline const std::string getHvscRoot() const
88 {
89 return m_hvscRoot;
90 }
91
95 bool setDatabaseFileName(const std::string &databaseFileName);
96
100 inline const std::string getDatabaseFileName() const
101 {
102 return m_databaseFileName;
103 }
104
108 bool setSidIdConfigFileName(const std::string &sidIdConfigFileName);
109
113 inline const std::string getSidIdConfigFileName() const
114 {
115 return m_sidIdConfigFileName;
116 }
117
122 inline void setNoDriver(bool noDriver)
123 {
124 m_noDriver = noDriver;
125 }
126
130 inline bool getNoDriver() const
131 {
132 return m_noDriver;
133 }
134
142 inline void setBlankScreen(bool blankScreen)
143 {
144 m_blankScreen = blankScreen;
145 }
146
150 inline bool getBlankScreen() const
151 {
152 return m_blankScreen;
153 }
154
159 inline void setCompress(bool compress)
160 {
161 m_compress = compress;
162 }
163
167 inline bool getCompress() const
168 {
169 return m_compress;
170 }
171
176 inline void setInitialSong(int initialSong)
177 {
178 m_initialSong = initialSong;
179 }
180
184 inline int getInitialSong()
185 {
186 return m_initialSong;
187 }
188
193 inline void setUseGlobalComment(bool useGlobalComment)
194 {
195 m_useGlobalComment = useGlobalComment;
196 }
197
201 inline bool getUseGlobalComment() const
202 {
203 return m_useGlobalComment;
204 }
205
210 inline void setVerbose(bool verbose)
211 {
212 m_verbose = verbose;
213 }
214
218 inline bool getVerbose() const
219 {
220 return m_verbose;
221 }
222
226 inline void setTheme(Theme theme)
227 {
228 m_theme = theme;
229 }
230
234 inline Theme getTheme()
235 {
236 return m_theme;
237 }
238
243 inline const char* getStatus() const
244 {
245 return m_statusString;
246 }
247
251 bool load(const char* fileName);
252
256 bool convert();
257
261 bool save(const char* fileName);
262
266 bool write(std::ostream& out = std::cout);
267
268private:
269 Psid64(const Psid64&);
270 Psid64 operator=(const Psid64&);
271
272 static const unsigned int MAX_BLOCKS = 5;
273 static const unsigned int MAX_PAGES = 256; // number of memory pages
274 static const unsigned int NUM_MINDRV_PAGES = 2; // driver without screen display
275 static const unsigned int NUM_EXTDRV_PAGES = 5; // driver with screen display
276 static const unsigned int NUM_SCREEN_PAGES = 4; // size of screen in pages
277 static const unsigned int NUM_CHAR_PAGES = 4; // size of charset in pages
278 static const unsigned int STIL_EOT_SPACES = 10; // number of spaces before EOT
279 static const unsigned int BAR_X = 15;
280 static const unsigned int BAR_WIDTH = 19;
281 static const unsigned int BAR_SPRITE_SCREEN_OFFSET = 0x300;
282
283 // error and status message strings
284 static const char* txt_relocOverlapsImage;
285 static const char* txt_notEnoughC64Memory;
286 static const char* txt_fileIoError;
287 static const char* txt_noSidTuneLoaded;
288 static const char* txt_noSidTuneConverted;
289 static const char* txt_sidIdConfigError;
290
291 // configuration options
292 bool m_noDriver;
293 bool m_blankScreen;
294 bool m_compress;
295 int m_initialSong;
296 bool m_useGlobalComment;
297 bool m_verbose;
298 std::string m_hvscRoot;
299 std::string m_databaseFileName;
300 std::string m_sidIdConfigFileName;
301 Theme m_theme;
302
303 // state data
304 bool m_status;
305 const char* m_statusString; // error/status message of last operation
306
307 // other internal data
308 std::string m_fileName;
309 SidTuneMod m_tune;
310 SidTuneInfo m_tuneInfo;
311 SidDatabase m_database;
312 STIL *m_stil;
313 SidId *m_sidId;
314
315 // conversion data
316 Screen *m_screen;
317 std::string m_stilText;
318 uint_least8_t m_songlengthsData[4 * SIDTUNE_MAX_SONGS];
319 size_t m_songlengthsSize;
320 uint_least8_t m_driverPage; // startpage of driver, 0 means no driver
321 uint_least8_t m_screenPage; // startpage of screen, 0 means no screen
322 uint_least8_t m_charPage; // startpage of chars, 0 means no chars
323 uint_least8_t m_stilPage; // startpage of stil, 0 means no stil
324 uint_least8_t m_songlengthsPage; // startpage of song length data, 0 means no song lengths
325 std::string m_playerId;
326
327 // converted file
328 uint_least8_t *m_programData;
329 unsigned int m_programSize;
330
331 // member functions
332 int_least32_t roundDiv(int_least32_t dividend, int_least32_t divisor);
333 bool convertNoDriver();
334 bool convertBASIC();
335 bool formatStilText();
336 bool getSongLengths();
337 uint_least8_t findSonglengthsSpace(const bool* pages, uint_least8_t scr,
338 uint_least8_t chars,
339 uint_least8_t driver,
340 uint_least8_t stil,
341 uint_least8_t stil_pages,
342 uint_least8_t size) const;
343 uint_least8_t findStilSpace(const bool* pages, uint_least8_t scr,
344 uint_least8_t chars,
345 uint_least8_t driver,
346 uint_least8_t size) const;
347 uint_least8_t findDriverSpace(const bool* pages, uint_least8_t scr,
348 uint_least8_t chars,
349 uint_least8_t size) const;
350 void findFreeSpace();
351 uint8_t iomap(uint_least16_t addr);
352 void initDriver(uint_least8_t** mem, uint_least8_t** ptr, int* n);
353 void addFlag(bool &hasFlags, const std::string &flagName);
354 std::string toHexWord(uint_least16_t value) const;
355 std::string toNumStr(int value) const;
356 void drawScreen();
357 bool compress();
358};
359
360
361inline std::ostream& operator << (std::ostream& out, Psid64 &psid64)
362{
363 psid64.write(out);
364 return out;
365}
366
367#endif // PSID64_H
Definition: psid64.h:52
bool getVerbose() const
Definition: psid64.h:218
const std::string getDatabaseFileName() const
Definition: psid64.h:100
bool getCompress() const
Definition: psid64.h:167
void setCompress(bool compress)
Definition: psid64.h:159
bool write(std::ostream &out=std::cout)
bool setSidIdConfigFileName(const std::string &sidIdConfigFileName)
int getInitialSong()
Definition: psid64.h:184
bool getBlankScreen() const
Definition: psid64.h:150
void setNoDriver(bool noDriver)
Definition: psid64.h:122
bool convert()
bool save(const char *fileName)
bool load(const char *fileName)
void setTheme(Theme theme)
Definition: psid64.h:226
void setInitialSong(int initialSong)
Definition: psid64.h:176
void setBlankScreen(bool blankScreen)
Definition: psid64.h:142
const char * getStatus() const
Definition: psid64.h:243
Theme getTheme()
Definition: psid64.h:234
bool setHvscRoot(const std::string &hvscRoot)
const std::string getSidIdConfigFileName() const
Definition: psid64.h:113
const std::string getHvscRoot() const
Definition: psid64.h:87
void setUseGlobalComment(bool useGlobalComment)
Definition: psid64.h:193
bool setDatabaseFileName(const std::string &databaseFileName)
void setVerbose(bool verbose)
Definition: psid64.h:210
bool getNoDriver() const
Definition: psid64.h:130
bool getUseGlobalComment() const
Definition: psid64.h:201