#!/usr/bin/perl open TABLE, ">", "table/linedraw.h"; select TABLE; my $ch = 0x2500; # coordinate system: # # 0..8 (equally spaced) 9,11 mid-1,mid+1, makes 4 bit # one point = 8 bit, two points = 16 bit # 8 bit opcode 0 line, 1 rect, 2 arc # 8 bit opcode arg # OOOOOOOO AAAABBBB X1X1Y1Y1 X2X2Y2Y2 my $offs = 0; my @offs; sub emit { my ($code, $x1, $y1, $x2, $y2, $a, $b) = @_; $offs++; printf " 0x%08lx,", ($code << 24) | ($x1 << 12) | ($y1 << 8) | ($x2 << 4) | ($y2 << 0) | ($a << 20) | ($b << 16); } print "static uint32_t linedraw_command[] = {\n"; while () { next if /^\//; next unless /\S/; push @offs, $offs; my ($v, $V, $h, $H, $s); for (;;) { /\G-/gc and last; /\G$/gc and last; /\G([123])/gc and $w = $1; /\Gh/gc and $h = $w; /\GH/gc and $H = $w; /\Gv/gc and $v = $w; /\GV/gc and $V = $w; /\G\//gc and emit 0, 0, 8, 8, 0; /\G\\/gc and emit 0, 0, 0, 8, 8; /\GA/gc and emit 2, 8, 8, 0, 0, 2, 2; /\GB/gc and emit 2, 0, 8, 0, 0, 1, 2; /\GC/gc and emit 2, 0, 0, 0, 0, 1, 0; /\GD/gc and emit 2, 8, 0, 0, 0, 0, 0; /\Gi/gc and emit 1, 0, 0, 4, 4; /\Gj/gc and emit 1, 4, 0, 8, 4; /\Gk/gc and emit 1, 0, 4, 4, 8; /\Gl/gc and emit 1, 4, 4, 8, 8; /\Gs(\d)/gc and $s = $1; /\Gr(\d+),(\d+),(\d+),(\d+)/gc and emit 1, $1, $2, $3, $4, $s; /\G\s/gc; } if ($h) { emit 0, 0, 9,10, 9 if $h > 1; emit 0, 0, 10,10, 10 if $h & 1; emit 0, 0, 11,10, 11 if $h > 1; } if ($H) { emit 0,10, 9, 8, 9 if $H > 1; emit 0,10, 10, 8, 10 if $H & 1; emit 0,10, 11, 8, 11 if $H > 1; } if ($v) { emit 0, 9, 0, 9, 10 if $v > 1; emit 0,10, 0,10, 10 if $v & 1; emit 0,11, 0,11, 10 if $v > 1; } if ($V) { emit 0, 9, 10, 9, 8 if $V > 1; emit 0,10, 10,10, 8 if $V & 1; emit 0,11, 10,11, 8 if $V > 1; } $offs[-1] = ($offs[-1] << 4) | ($offs - $offs[-1]); printf " // %04x\n", $ch; $ch++; } print <