-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdirc.cpp
40 lines (35 loc) · 907 Bytes
/
dirc.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
#include <cstdio>
#include <cstdlib>
int main(int argc, char** argv)
{
if(argc != 2)
{
std::fprintf(stderr, "usage: %s [outfile]\n", argv[0]);
return EXIT_FAILURE;
}
FILE* fp = std::fopen(argv[1], "wb");
if(!fp)
{
std::fprintf(stderr, "can't open file %s\n", argv[1]);
return EXIT_FAILURE;
}
std::fprintf(fp, ".include\"globals.inc\"\n");
std::fprintf(fp, ".segment \"RODATA\"\n");
std::fprintf(fp, "dx:\n");
for(unsigned i = 0; i != 256; ++i)
{
int x = (i & 0b00001111) - 8;
if(x >= 0)
++x;
std::fprintf(fp, ".byt .lobyte(%i)\n", x*1);
}
std::fprintf(fp, "dy:\n");
for(unsigned i = 0; i != 256; ++i)
{
int y = ((i & 0b11110000) >> 4) - 8;
if(y >= 0)
++y;
std::fprintf(fp, ".byt .lobyte(%i)\n", y*1);
}
std::fclose(fp);
}