Skip to content

Instantly share code, notes, and snippets.

@Deguerre
Last active May 20, 2019 04:13
Show Gist options
  • Save Deguerre/aedc784a3066c801f2f3dfb5f9bff52a to your computer and use it in GitHub Desktop.
Save Deguerre/aedc784a3066c801f2f3dfb5f9bff52a to your computer and use it in GitHub Desktop.
#include <stdio.h>
#define WIDTH 320
#define HEIGHT 200
int main(int argc, char** argv)
{
char Pixels[HEIGHT][WIDTH] = {};
short Cx = 160;
short Cy = 100;
short R = 30;
short X = -R;
short Y = 0;
short Ep = 0;
char* Cursor = &Pixels[Cx][Cy];
// si = X
// di = Y
// bx = Ep
// bp is a scratch register (we don't need a frame pointer)
// this leaves ax,cx,dx free for pixel fill (and bp is available too)
// jmp loop_test
// loop_top:
while (X + Y < 0) {
Cursor[Y * WIDTH + X] = 1;
Cursor[Y * WIDTH - X] = 1;
Cursor[-Y * WIDTH + X] = 1;
Cursor[-Y * WIDTH - X] = 1;
Cursor[X * WIDTH + Y] = 1;
Cursor[X * WIDTH - Y] = 1;
Cursor[-X * WIDTH + Y] = 1;
Cursor[-X * WIDTH - Y] = 1;
// lea bx,[bx+di+1]
// add bx,di
Ep += (Y << 1) + 1;
// mov bp,bx
// add bp,si
// jg no_x_inc
if (Ep + X > 0) {
// lea bx,[bp+si]
Ep += X << 1;
// inc si
++X;
}
// no_x_inc:
// inc di
++Y;
// loop_test:
// mov bp,si
// add bp,di
// jl loop_top
}
for (int Y = 0; Y < HEIGHT; ++Y) {
for (int X = 0; X < WIDTH; ++X) {
printf(Pixels[Y][X] ? "*" : ".");
}
printf("\n");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment