Repository navigation
Expand file tree
/
Copy pathscreen-maps.c
More file actions
145 lines (118 loc) · 3.63 KB
/
Copy pathscreen-maps.c
File metadata and controls
145 lines (118 loc) · 3.63 KB
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
143
144
145
/*
Program for generating simple screen map diagrams for the MEGA65 documentation.
It is designed to produce maps showing screen addresses in various modes, as well
as the memory layout corresponding to various actual displays.
It's basically an ad-hoc tool being developed to save me having to spend hours
making SVG diagrams with the same content.
*/
#include <stdio.h>
#include <hpdf.h>
int logical_columns = 40;
int columns = 40;
int rows = 25;
int screen_address = 0x400;
int show_cell_numbers = 1;
int show_addrs = 0;
int show_chars = 0;
int sixteenbit_mode = 0;
HPDF_Doc pdf;
HPDF_Page page_1;
void reset_settings(void)
{
logical_columns = 40;
columns = 40;
rows = 25;
screen_address = 0x400;
show_cell_numbers = 0;
show_addrs = 0;
show_chars = 0;
sixteenbit_mode = 0;
}
void error_handler(HPDF_STATUS error_no, HPDF_STATUS detail_no, void* user_data)
{
printf("ERROR: error_no=%04X, detail_no=%d\n", (unsigned int)error_no, (int)detail_no);
exit(-1);
}
void setup_pdf(void)
{
pdf = HPDF_New(error_handler, NULL);
if (!pdf) {
printf("ERROR: cannot create pdf object.\n");
exit(-3);
}
/* set compression mode */
HPDF_SetCompressionMode(pdf, HPDF_COMP_ALL);
page_1 = HPDF_AddPage(pdf);
HPDF_Page_SetWidth(page_1, 660);
HPDF_Page_SetHeight(page_1, 420);
for (int x = 0; x <= columns; x++) {
HPDF_Page_MoveTo(page_1, 10 + (x * 640 / columns), 10 + 0);
HPDF_Page_LineTo(page_1, 10 + (x * 640 / columns), 10 + 400);
HPDF_Page_Stroke(page_1);
}
for (int y = 0; y <= rows; y++) {
HPDF_Page_MoveTo(page_1, 10 + 0, 10 + (y * 400 / rows));
HPDF_Page_LineTo(page_1, 10 + 640, 10 + (y * 400 / rows));
HPDF_Page_Stroke(page_1);
}
// const char *font_name = HPDF_LoadTTFontFromFile (pdf, "./fonts/mega40-Regular.ttf", HPDF_TRUE);
HPDF_Font font = HPDF_GetFont(pdf, "Helvetica", "CP1250");
if (show_addrs) {
// Smaller print for addresses
HPDF_Page_SetFontAndSize(page_1, font, 640 / columns / 2 * 0.75);
}
else {
HPDF_Page_SetFontAndSize(page_1, font, 640 / columns / 2);
}
HPDF_Page_BeginText(page_1);
}
void finalise_pdf(char* pdfname)
{
HPDF_Page_EndText(page_1);
HPDF_SaveToFile(pdf, pdfname);
HPDF_Free(pdf);
}
void draw_screen_layout(void)
{
for (int y = 0; y < rows; y++) {
for (int x = 0; x < columns; x++) {
char string[80];
string[0] = 0;
if (show_cell_numbers)
snprintf(string, 80, "%d", (y * columns + x) * (1 + sixteenbit_mode));
if (show_addrs)
snprintf(string, 80, "$%x", screen_address + y * logical_columns + x * (1 + sixteenbit_mode));
HPDF_Page_TextOut(page_1, 10 + 1 + (x * 640 / columns), 400 - (y * 400 / rows), string);
}
}
}
int main(int argc, char** argv)
{
// Draw normal 40x25 grid with cell numbers
reset_settings();
show_cell_numbers = 1;
setup_pdf();
draw_screen_layout();
finalise_pdf("images/illustrations/screen-40x25-cell-numbers.pdf");
// Draw normal 40x25 grid with addresses
reset_settings();
show_addrs = 1;
setup_pdf();
draw_screen_layout();
finalise_pdf("images/illustrations/screen-40x25-addresses.pdf");
// Draw normal 40x25 grid with addresses, 16-bit char mode with 40 byte logical stepping
reset_settings();
show_addrs = 1;
sixteenbit_mode = 1;
setup_pdf();
draw_screen_layout();
finalise_pdf("images/illustrations/screen-40x25-addresses16.pdf");
// Draw normal 40x25 grid with addresses, 16-bit char mode with 80 byte logical stepping
reset_settings();
show_addrs = 1;
sixteenbit_mode = 1;
logical_columns = 80;
setup_pdf();
draw_screen_layout();
finalise_pdf("images/illustrations/screen-40x25-addresses16-80.pdf");
}