-
Notifications
You must be signed in to change notification settings - Fork 148
/
gfx.cpp
142 lines (125 loc) · 3.28 KB
/
gfx.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#include "../interop/interop.hpp"
#include "../environment.h"
#include "../ui.h"
#include "gfx.h"
using namespace openloco::interop;
namespace openloco::gfx
{
loco_global<drawpixelinfo_t, 0x0050B884> _screen_dpi;
loco_global_array<loco_g1_element, LOCO_G1_ELEMENT_COUNT, 0x9E2424> _g1Elements;
drawpixelinfo_t& screen_dpi()
{
return _screen_dpi;
}
// 0x0044733C
void load_g1()
{
auto g1Path = environment::get_path(environment::path_id::g1);
FILE * file;
gfx::loco_g1_header header;
void * g1Buffer;
file = fopen(g1Path.make_preferred().u8string().c_str(), "rb");
if (file != NULL) {
if (fread(&header, 8, 1, file) == 1) {
// Read element headers
fread(_g1Elements, header.num_entries * sizeof(loco_g1_element), 1, file);
// Read element data
g1Buffer = malloc(header.total_size);
fread(g1Buffer, header.total_size, 1, file);
fclose(file);
// Adjust memory offsets
for (uint32_t i = 0; i < header.num_entries; i++)
{
_g1Elements[i].offset += (int)g1Buffer;
}
}
fclose(file);
return;
}
else
{
throw std::exception("Unable to load g1.dat");
}
}
// 0x00447485
// edi: dpi
// ebp: fill
void clear(drawpixelinfo_t &dpi, uint32_t fill)
{
registers regs;
regs.edi = (int32_t)&dpi;
regs.ebp = (int32_t)fill;
call(0x00447485, regs);
}
void clear_single(drawpixelinfo_t &dpi, uint8_t paletteId)
{
auto fill = (paletteId << 24) | (paletteId << 16) | (paletteId << 8) | paletteId;
clear(dpi, fill);
}
// 0x00494B3F
// al: colour
// bx: string id
// cx: x
// dx: y
// esi: args
// edi: dpi
void draw_string_494B3F(
drawpixelinfo_t &dpi,
int16_t x,
int16_t y,
uint8_t colour,
string_id stringId,
const void * args)
{
registers regs;
regs.al = colour;
regs.bx = stringId;
regs.cx = x;
regs.dx = y;
regs.esi = (int32_t)args;
regs.edi = (int32_t)&dpi;
call(0x00494B3F, regs);
}
// 0x00494BBF
// al: colour
// bx: string id
// cx: x
// dx: y
// esi: args
// edi: dpi
// bp: width
void draw_string_494BBF(
drawpixelinfo_t &dpi,
int16_t x,
int16_t y,
int16_t width,
uint8_t colour,
string_id stringId,
const void * args)
{
registers regs;
regs.al = colour;
regs.bx = stringId;
regs.cx = x;
regs.dx = y;
regs.esi = (int32_t)args;
regs.edi = (int32_t)&dpi;
regs.bp = width;
call(0x00494BBF, regs);
}
// 0x004CD406
void invalidate_screen()
{
set_dirty_blocks(0, 0, ui::width(), ui::height());
}
// 0x004C5C69
void set_dirty_blocks(int32_t left, int32_t top, int32_t right, int32_t bottom)
{
registers regs;
regs.ax = left;
regs.bx = top;
regs.dx = right;
regs.bp = bottom;
call(0x004C5C69, regs);
}
}