Debian Codegraph @

terps/bocfel/zterp.h

raw symbols SCIP
1 // vim: set ft=cpp:
2
3 #ifndef ZTERP_ZTERP_H
4 #define ZTERP_ZTERP_H
5
6 #include <array>
7 #include <exception>
8 #include <string>
9
10 #include "types.h"
11
12 class Exit : public std::exception {
13 public:
14 explicit Exit(int code) : m_code(code) {
15 }
16
17 int code() const {
18 return m_code;
19 }
20
21 private:
22 int m_code;
23 };
24
25 extern std::string game_file;
26
27 #define ZTERP_VERSION "2.5"
28
29 // v3
30 constexpr uint8_t FLAGS1_STATUSTYPE = 1U << 1;
31 constexpr uint8_t FLAGS1_STORYSPLIT = 1U << 2;
32 constexpr uint8_t FLAGS1_CENSOR = 1U << 3;
33 constexpr uint8_t FLAGS1_NOSTATUS = 1U << 4;
34 constexpr uint8_t FLAGS1_SCREENSPLIT = 1U << 5;
35 constexpr uint8_t FLAGS1_VARIABLE = 1U << 6;
36
37 // v4
38 constexpr uint8_t FLAGS1_COLORS = 1U << 0;
39 constexpr uint8_t FLAGS1_PICTURES = 1U << 1;
40 constexpr uint8_t FLAGS1_BOLD = 1U << 2;
41 constexpr uint8_t FLAGS1_ITALIC = 1U << 3;
42 constexpr uint8_t FLAGS1_FIXED = 1U << 4;
43 constexpr uint8_t FLAGS1_SOUND = 1U << 5;
44 constexpr uint8_t FLAGS1_TIMED = 1U << 7;
45
46 constexpr uint16_t FLAGS2_TRANSCRIPT = 1U << 0;
47 constexpr uint16_t FLAGS2_FIXED = 1U << 1;
48 constexpr uint16_t FLAGS2_STATUS = 1U << 2;
49 constexpr uint16_t FLAGS2_PICTURES = 1U << 3;
50 constexpr uint16_t FLAGS2_UNDO = 1U << 4;
51 constexpr uint16_t FLAGS2_MOUSE = 1U << 5;
52 constexpr uint16_t FLAGS2_COLORS = 1U << 6;
53 constexpr uint16_t FLAGS2_SOUND = 1U << 7;
54 constexpr uint16_t FLAGS2_MENUS = 1U << 8;
55
56 #define status_is_time() (zversion == 3 && (byte(0x01) & FLAGS1_STATUSTYPE))
57 #define timer_available() (zversion >= 4 && (byte(0x01) & FLAGS1_TIMED))
58 #define mouse_available() (zversion >= 5 && (word(0x10) & FLAGS2_MOUSE))
59
60 struct Header {
61 uint16_t pc;
62 uint16_t release;
63 uint16_t dictionary;
64 uint16_t objects;
65 uint16_t globals;
66 uint16_t static_start;
67 uint16_t static_end;
68 uint16_t abbr;
69 uint32_t file_length;
70 uint8_t serial[6];
71 uint16_t checksum;
72 uint32_t routines_offset;
73 uint32_t strings_offset;
74 uint16_t terminating_characters_table;
75 uint16_t extension_table;
76 uint16_t extension_entries;
77 };
78
79 extern int zversion;
80 extern Header header;
81 extern std::array<uint8_t, 26 * 3> atable;
82
83 const std::string &get_story_id();
84
85 enum class Game {
86 Arthur,
87 Infocom1234,
88 Journey,
89 LurkingHorror,
90 Planetfall,
91 Shogun,
92 Stationfall,
93 ZorkZero,
94 ZorkZeroDOS,
95 MysteriousAdventures,
96 };
97
98 bool is_game(Game game);
99
100 void write_header();
101 void start_story();
102
103 uint32_t unpack_routine(uint16_t addr);
104 uint32_t unpack_string(uint16_t addr);
105 void store(uint16_t v);
106
107 void zterp_mouse_click(uint16_t x, uint16_t y);
108
109 void znop();
110 [[noreturn]]
111 void zrestart();
112 [[noreturn]]
113 void zquit();
114 void zverify();
115 void zpiracy();
116 void zsave5();
117 void zrestore5();
118
119 #endif