forked from larsbrinkhoff/pdp10-its-disassembler
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcalcomp.c
More file actions
86 lines (75 loc) · 1.83 KB
/
calcomp.c
File metadata and controls
86 lines (75 loc) · 1.83 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
/* Copyright (C) 2025 Lars Brinkhoff <lars@nocrew.org>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
#include <stdio.h>
//#include <unistd.h>
#include "dis.h"
#include "svg.h"
static int x, y;
static void (*plot)(FILE *f, int x, int y);
static void fatal(const char *message)
{
fputs(message, stderr);
exit(1);
}
static void just_move(FILE *f, int x, int y)
{
(void)f;
(void)x;
(void)y;
}
static void process(int data)
{
if ((data & 060) == 060)
fatal ("Pen both up and down.");
if (data & 040) {
if (plot != just_move)
svg_polyline_end(stdout);
plot = just_move;
}
if (data & 020) {
if (plot == just_move)
plot = svg_polyline_begin;
}
if (data & 010)
y--;
if (data & 004)
y++;
if (data & 002)
x--;
if (data & 001)
x++;
plot (stdout, x, y);
if (plot == svg_polyline_begin)
plot = svg_polyline_point;
}
static void calcomp(FILE *f)
{
word_t data;
int i;
for (;;) {
data = get_word(f);
if (data == -1)
return;
for (i = 0; i < 6; i++, data <<= 6)
process((data >> 30) & 077);
}
}
int main(void)
{
input_word_format = &aa_word_format;
x = y = 0;
plot = just_move;
svg_file_begin(stdout);
calcomp(stdin);
svg_file_end(stdout);
return 0;
}