summaryrefslogtreecommitdiff
path: root/bcc/misc/test/hilbert.t
blob: e18dc6395c2c4826b9e0887dc76d7a1fd12d8fe2 (plain)
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
/* hilbert.c */

/* S1 stuff

#define PIFBUF ( *(struct IFBUF **) 0xf010 )
#define PSET 2

struct IFBUF
{
	char ERR;
	char COMMAND;
	char COLOR;
	char PLOTOPTION;
	int LINESTYLE;
	int X1;
	int Y1;
	int X2;
	int Y2;
	char BFFLAG;
};
end of S1 stuff */

/* L3 stuff */

#define PIFBUF ( (struct IFBUF *) 0xa1 )
#define PSET 1

struct IFBUF
{
	char PLOTOPTION;
	char junk1[0xa8-0xa2];
	int X1;
	int Y1;
	int X2;
	int Y2;
	char junk2[0xf0-0xb0];
	char ERR;				/* this to BFFLAG are dummies to keep S1 code */
	char COMMAND;
	int LINESTYLE;
	char BFFLAG;
	char junk3[0x3ea-0xf5];
	char COLOR;
};

#define H0 512				/* square size */
#define XOFFS 80			/* offset to centre square */
#define XNUM 15				/* scale 512 * 15/16 = 480 */
#define XDENOM 16
#define YNUM 25				/* scale 512 * 25/64 = 200 */
#define YDENOM 64			/* to give max height, dot ratio 480/200 = 2.4 */

int h, x, y;

main()
{
	int i, x0, y0;
	char color;

	PIFBUF->PLOTOPTION = PSET;
	PIFBUF->LINESTYLE = 			/* normal */
	PIFBUF->COMMAND =				/* ?? */
	PIFBUF->BFFLAG = 0;				/* not a box */
	color = i = 0;
	x0 = y0 = (h = H0)/2;
	while ( h > 1 )
	{
		++i;
		h = h/2;
		if ( ++color > 7 )
			color = 1;
		gcolor( color );
		x = x0 += h/2;
		y = y0 += h/2;
		glocate();
		a( i );
	}
}

a( i )
int i;
{
	if ( --i >= 0 )
	{
		d( i ); x -= h; plot();
		a( i ); y -= h; plot();
		a( i ); x += h; plot();
		b( i );
	}
}

b( i )
int i;
{
	if ( --i >= 0 )
	{
		c( i ); y += h; plot();
		b( i ); x += h; plot();
		b( i ); y -= h; plot();
		a( i );
	}
}

c( i )
int i;
{
	if ( --i >= 0 )
	{
		b( i ); x += h; plot();
		c( i ); y += h; plot();
		c( i ); x -= h; plot();
		d( i );
	}
}

d( i )
int i;
{
	if ( --i >= 0 )
	{
		a( i ); y -= h; plot();
		d( i ); x -= h; plot();
		d( i ); y += h; plot();
		c( i );
	}
}

glocate()
{
	PIFBUF->X2 = x - x * (XDENOM - XNUM) / XDENOM + XOFFS;
	PIFBUF->Y2 = (y * YNUM) / YDENOM;
}

/* S1 gcolor and plot

gcolor( color )
int color;
{
	PIFBUF->COLOR = color;
}

plot()
{
	PIFBUF->X1 = PIFBUF->X2;
	PIFBUF->Y1 = PIFBUF->Y2;
	glocate();
#asm
	SWI2
	FDB	$4201		call LINEMA
#endasm
}

end S1 plot */

gcolor( color )
int color;
{
	PIFBUF->COLOR = color | 0x10;
}

plot()
{
	PIFBUF->X1 = PIFBUF->X2;
	PIFBUF->Y1 = PIFBUF->Y2;
	glocate();
#asm
	JSR	$D709
	JSR	$D79A
#endasm
}