--- /dev/null
+*.o
+*.swp
+*.d
+regis_test
--- /dev/null
+src = $(wildcard *.c)
+obj = $(src:.c=.o)
+bin = regis_test
+
+CFLAGS = -pedantic -Wall -g
+LDFLAGS = -lm
+
+$(bin): $(obj)
+ $(CC) -o $@ $(obj) $(LDFLAGS)
+
+.PHONY: clean
+clean:
+ rm -f $(obj) $(bin)
--- /dev/null
+#include "regis.h"
+
+#define OUT (out ? out : stdout)
+static FILE *out;
+
+void regis_set_output(FILE *fp)
+{
+ out = fp;
+}
+
+void regis_enter(void)
+{
+ fprintf(OUT, "\033P0p\n");
+}
+
+void regis_leave(void)
+{
+ fprintf(OUT, "\033\\");
+ fflush(OUT);
+}
+
+void regis_draw_page(int x)
+{
+ fprintf(OUT, "P(P%d)\n", x ? 1 : 0);
+}
+
+void regis_show_page(int x)
+{
+ fprintf(OUT, "S(P%d)\n", x ? 1 : 0);
+}
+
+void regis_clear(void)
+{
+ fprintf(OUT, "S(E)\n");
+}
+
+void regis_abspos(int x, int y)
+{
+ fputc('P', OUT);
+ regis_absv(x, y);
+}
+
+void regis_relpos(int x, int y)
+{
+ fputc('P', OUT);
+ regis_relv(x, y);
+}
+
+void regis_absv(int x, int y)
+{
+ fprintf(OUT, "[%d,%d]\n", x, y);
+}
+
+void regis_relv(int x, int y)
+{
+ fprintf(OUT, "[%+d,%+d]\n", x, y);
+}
+
+void regis_nullv(void)
+{
+ fprintf(OUT, "[]\n");
+}
+
+static unsigned int cur_mode;
+
+void regis_begin_vector(unsigned int mode)
+{
+ if(mode & REGIS_FILL) {
+ fprintf(OUT, "F(");
+ }
+ fputc('V', OUT);
+ if(mode & REGIS_BOUNDED) {
+ fprintf(OUT, "(B)");
+ }
+ fputc('\n', OUT);
+ cur_mode = mode;
+}
+
+void regis_end_vector(void)
+{
+ fprintf(OUT, "(E)");
+ if(cur_mode & REGIS_FILL) {
+ fputc(')', OUT);
+ }
+ fputc('\n', OUT);
+}
--- /dev/null
+#ifndef REGIS_H_
+#define REGIS_H_
+
+#include <stdio.h>
+
+enum {
+ REGIS_BOUNDED = 1,
+ REGIS_UNBOUNDED = 0,
+ REGIS_FILL = 2,
+ REGIS_WIRE = 0
+};
+
+void regis_set_output(FILE *fp);
+
+void regis_enter(void);
+void regis_leave(void);
+void regis_draw_page(int x);
+void regis_show_page(int x);
+void regis_clear(void);
+void regis_abspos(int x, int y);
+void regis_relpos(int x, int y);
+void regis_absv(int x, int y);
+void regis_relv(int x, int y);
+void regis_nullv(void);
+
+void regis_begin_vector(unsigned int mode);
+void regis_end_vector(void);
+
+#endif /* REGIS_H_ */
--- /dev/null
+#include "rgl.h"
+#include "regis.h"
+
+struct vec2 {
+ int x, y;
+};
+
+static void flush_verts(void);
+static void draw_lines(struct vec2 *v, int nverts);
+
+static int cur_mode = -1;
+#define VBUF_SIZE 64
+static struct vec2 vbuf[VBUF_SIZE];
+static int nverts;
+
+void rgl_begin(int mode)
+{
+ cur_mode = mode;
+ nverts = 0;
+}
+
+void rgl_end(void)
+{
+ flush_verts();
+ cur_mode = -1;
+}
+
+void rgl_vertex(int x, int y)
+{
+ vbuf[nverts].x = x;
+ vbuf[nverts].y = y;
+
+ if(++nverts >= VBUF_SIZE) {
+ flush_verts();
+ }
+}
+
+static void flush_verts(void)
+{
+ switch(cur_mode) {
+ case REGIS_LINES:
+ draw_lines(vbuf, nverts);
+ break;
+
+ default:
+ break;
+ }
+ nverts = 0;
+}
+
+static void draw_lines(struct vec2 *v, int nverts)
+{
+ if(nverts <= 0) return;
+
+ regis_enter();
+
+ regis_leave();
+}
--- /dev/null
+#ifndef RGL_H_
+#define RGL_H_
+
+enum {
+ REGIS_LINES,
+ REGIS_LINE_STRIP,
+ REGIS_LINE_LOOP
+};
+
+void rgl_begin(int mode);
+void rgl_end(void);
+
+void rgl_vertex(int x, int y);
+
+#endif /* RGL_H_ */
--- /dev/null
+#include <stdio.h>
+#include <signal.h>
+#include <math.h>
+#include <unistd.h>
+#include "regis.h"
+
+static void sig(int s);
+
+static volatile int done;
+
+int main(int argc, char **argv)
+{
+ int pg = 1;
+ float tm = 0.0f;
+ signal(SIGINT, sig);
+
+ while(!done) {
+ float dx = cos(tm) * 50.0;
+ float dy = sin(tm * 2.0) * 50.0;
+ tm += 0.01f;
+
+ regis_enter();
+ regis_draw_page(pg);
+ regis_clear();
+ regis_abspos(100 + dx, 100 + dy);
+ regis_begin_vector(REGIS_BOUNDED | REGIS_FILL);
+ regis_absv(300 + dx, 300 + dy);
+ regis_absv(80 + dx, 400 + dy);
+ regis_end_vector();
+ regis_show_page(pg);
+ pg = (pg + 1) & 1;
+ regis_leave();
+
+ usleep(10000);
+ }
+
+ regis_enter();
+ regis_clear();
+ regis_leave();
+ return 0;
+}
+
+static void sig(int s)
+{
+ done = 1;
+}