/* corner_r.c (c10.c) - Don Yang (uguu.org) The *only* way to compile this program: forcedos cl /Od /F f000 corner_r.c Explanations: forcedos Program is unstable and you should run it under WinNT. cl Only compiles with MSC 6.0. Od Messed up flow of control and screwy operator precedence is important and must not be changed by optimizer. F f000 Very likely to have stack overflows. Actually, I have debugged the program enough to know that it should run safely, but this kind of programs you can never be sure... I would have taken all 64K of the real mode stack segment if the environment doesn't need it. Features: Better than inline assembly -- inline machine code :) Better than iteration -- recursion ^_^x Almost no keywords used and almost no semicolons! Debug notes: D macro: This program is made to work against symbolic debuggers. There just isn't much to debug since there is really only one statement. Thus you can't rely on the debugger to trace line by line. Instead, insert "+D" or "D+" macro at appropiate locations (e.g. y = D+ 0). Then you can set breakpoint at debug() and check the current line number. Beware, inserting too many of those macros will cause the compiler to run out of heap space at pass 2! Z macro: This macro appears in various places that should never get executed. lint: Heh, this program almost passed lclint ;) Some 45 errors, including but not limited to "test expression for conditional not boolean", "expression has undefined behavior", incompatible types, etc. Okay, not quite, I guess... 11/21/99 */ volatile int far *clock = (int far *)0x0040006c; int far *screen = (int far *)0xb8000000; int far buffer[2048]; int far WaitLoop[] = { 0xc031, 0xc08e, 0x6cbb, 0x2604, 0x178b, 0x3b26, 0x7417, 0xcbfb}; int (far *sync)(int); int seed; int x, y, dx, dy, lx, ly; int far px[2048], far py[2048], pc = 0; int far pi[2048]; int m; /* Debug */ #include void debug1(void) { int i; for(i = 0; i < 2000; i++) screen[i] = 0; for(i = 0; i < pc; i++) screen[py[i] * 80 + px[i]] = pi[i]; } void debug2(void) { int i; for(i = 0; i < 2000; i++) screen[i] = buffer[i]; } int debug(int line, int state) { static int wvar = -1; if( wvar == 0 ) { printf("%3d: x=%-4d y=%-4d lx=%-4d ly=%-4d dx=%-4d dy=%-4d state=%d\n", line, x, y, lx, ly, dx, dy, state); } if( wvar == 1 ) debug1(); if( wvar == 2 ) debug2(); return 0; } int dummy(int line) { printf("assert failed %d\n", line); return 0; } #define D debug(__LINE__, state) #define Z dummy(__LINE__) int main(int state) { return (state > 0) ? (seed = *clock) * (int)(sync = WaitLoop) + ( (seed & 1) ? (y = 24) + (dy = ly = -1) : (y = 0) + (dy = 1) + (ly = 25) ) ? main(-1) & main(-3) ? Z : main(-4) + main(-5) : Z : (state == -1) ? (y != ly) /* for(; y != ly; y += dy) */ ? ( (seed & 2) ? (x = 79) + (dx = lx = -1) : (x = 0) + (dx = 1) + (lx = 80) ) ? main(-2) ? Z : (y += dy) * main(-1) : Z : 1 /* end for(y) */ : (state == -2) ? (x != lx) /* for(; x != lx; x += dx) */ ? ( ((screen[y * 80 + x] & 0xff) > 32) ? (px[pc] = x) * (py[pc] = y) + (pi[pc++] = screen[y * 80 + x]) : 1 ) ? (x += dx) * main(-2) : Z : (x = 0) /* end for(x) */ : (state == -3) ? (x < 2000) /* for(x = 0; x < 2000; x++) */ ? (buffer[x++] = 0) * main(-3) : (x = 0) /* end for(x) */ : (state == -4) ? (x < pc) /* for(x = 0; x < pc; x++) */ ? ( (buffer[py[x] * 80 + px[x]] = pi[x]) ^ (++x) | main(-4) ) : (m = 1) /* end for(x) */ : (state == -5) ? (m) /* while(m) */ ? ( ( (lx = m = 0) | main(-6) ) ? ( main(-7) ? Z : main(-5) /* do{} */ ) : Z ) : 0 : (state == -6) ? (lx < pc) /* for(lx = 0; lx < pc; lx++) */ ? ( ( main(-8) ? (x = px[lx] - dx) : (x = px[lx]) ) * ( main(-9) ? (y = py[lx] - dy) : (y = py[lx]) ) ) + ( (buffer[y * 80 + x]) ? 0 : ( (buffer[py[lx] * (m = 80) + px[lx]] = 0) ? Z : (buffer[(py[lx] = y) * m + (px[lx] = x)] = pi[lx]) ) ) & (++lx) | main(-6) : sync(x = 0) /* end for(lx) */ : (state == -7) ? (x < 2000) /* for(x = 0; x < 2000; x++) */ ? (screen[x] = buffer[x]) * (++x) & main(-7) : 0 /* end for(x) */ : (state == -8) ? ((px[lx] - dx) >= 0) && ((px[lx] - dx) < 80) : /* state == -9 */ ((py[lx] - dy) >= 0) && ((py[lx] - dy) < 25) ; }