-#define s_printf(x, y, fmt, ...) \
- basic_text_out16(g_screen, WIDTH, x, y, fmt, ##__VA_ARGS__);
+static void default_config(void)
+{
+ g_layer.x = SCREEN_WIDTH - WIDTH;
+ g_layer.y = 0;
+ g_layer.w = WIDTH;
+ g_layer.h = HEIGHT;
+}
+
+static void handle_config(void)
+{
+ char buf[256], *p;
+ int x, y, v;
+ FILE *f;
+
+ default_config();
+
+ f = fopen("config.cfg", "r");
+ if (f == NULL)
+ return;
+
+ while ((p = fgets(buf, sizeof(buf), f))) {
+ while (isspace(*p))
+ p++;
+ if (*p == '#' || *p == ';' || *p == 0)
+ continue;
+
+ if (sscanf(p, "position = %d %d", &x, &y) == 2) {
+ g_layer.x = x;
+ g_layer.y = y;
+ }
+ else {
+ printf("unhandled config entry: '%s'\n", p);
+ }
+ }
+ fclose(f);
+
+ v = SCREEN_WIDTH - g_layer.x;
+ if (v <= 0) {
+ printf("bad x position in config: %d\n", g_layer.x);
+ default_config();
+ return;
+ }
+ if (v < WIDTH)
+ g_layer.w = v;
+
+ v = SCREEN_HEIGHT - g_layer.y;
+ if (v <= 0) {
+ printf("bad y position in config: %d\n", g_layer.y);
+ default_config();
+ return;
+ }
+ if (v < HEIGHT)
+ g_layer.h = v;
+}
+
+#define s_printf(x, y, fmt, ...) do { \
+ if ((y) <= g_layer.h - 8) \
+ basic_text_out16(g_screen, g_layer.w, x, y, fmt, ##__VA_ARGS__); \
+} while (0)