2011-04-30 12:40:36 +04:00
|
|
|
/*
|
|
|
|
* Julia Fractal Generator
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <syscall.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <time.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
2011-04-30 22:51:33 +04:00
|
|
|
/*
|
|
|
|
* Some of the system calls for the graphics
|
|
|
|
* functionality.
|
|
|
|
*/
|
2011-04-30 12:40:36 +04:00
|
|
|
DEFN_SYSCALL0(getgraphicsaddress, 11);
|
|
|
|
DEFN_SYSCALL1(kbd_mode, 12, int);
|
|
|
|
DEFN_SYSCALL0(kbd_get, 13);
|
|
|
|
DEFN_SYSCALL1(setgraphicsoffset, 16, int);
|
|
|
|
|
2011-12-16 23:16:20 +04:00
|
|
|
DEFN_SYSCALL0(getgraphicswidth, 18);
|
|
|
|
DEFN_SYSCALL0(getgraphicsheight, 19);
|
VESA mode switching support.
BIOS execution is provided through the `v8086` module, which provides
software emulation of an 8086 processor. It is not currently working
with some BIOSes and may (read: probably will be) replaced with another
emulator (x86emu comes to mind) at some point in the near future. In the
meantime, the default video mode for QEMU works with this and it's
enough to get us on real VESA instead of fake VBE. The `bochs` module
will be renamed in a future commit. Userspace programs have been
adjusted to work at bitrates other than 32 *POORLY*. If you write pixels
left-to-right, they should work fine. They only work with 24-bpp
otherwise, and then you need to be careful of what pixels you are
writing when, or you will overwrite things in other pixels.
You may pass a commandline argument like the following to set display
modes:
vid=vesa,1024,768
Or for stranger modes under QEMU or Bochs, use the bochs VBE
initializer:
vid=bochs,1280,720
Note that the address of the linear framebuffer is still found via
hackish probing instead of PCI or trusting the VBE information, so if
you have things in the wrong memory ranges (0xE0000000+), be prepared to
have them get read.
Once again, this entire commit is a massive hack. I am happy that it
worked, and I will continue to make it less hacky, but in the meantime,
this is what we've got.
Happy holidays.
2011-12-25 10:40:40 +04:00
|
|
|
DEFN_SYSCALL0(getgraphicsdepth, 20);
|
2011-12-16 23:16:20 +04:00
|
|
|
|
|
|
|
uint16_t graphics_width = 0;
|
|
|
|
uint16_t graphics_height = 0;
|
VESA mode switching support.
BIOS execution is provided through the `v8086` module, which provides
software emulation of an 8086 processor. It is not currently working
with some BIOSes and may (read: probably will be) replaced with another
emulator (x86emu comes to mind) at some point in the near future. In the
meantime, the default video mode for QEMU works with this and it's
enough to get us on real VESA instead of fake VBE. The `bochs` module
will be renamed in a future commit. Userspace programs have been
adjusted to work at bitrates other than 32 *POORLY*. If you write pixels
left-to-right, they should work fine. They only work with 24-bpp
otherwise, and then you need to be careful of what pixels you are
writing when, or you will overwrite things in other pixels.
You may pass a commandline argument like the following to set display
modes:
vid=vesa,1024,768
Or for stranger modes under QEMU or Bochs, use the bochs VBE
initializer:
vid=bochs,1280,720
Note that the address of the linear framebuffer is still found via
hackish probing instead of PCI or trusting the VBE information, so if
you have things in the wrong memory ranges (0xE0000000+), be prepared to
have them get read.
Once again, this entire commit is a massive hack. I am happy that it
worked, and I will continue to make it less hacky, but in the meantime,
this is what we've got.
Happy holidays.
2011-12-25 10:40:40 +04:00
|
|
|
uint16_t graphics_depth = 0;
|
2011-12-16 23:16:20 +04:00
|
|
|
|
|
|
|
#define GFX_W graphics_width /* Display width */
|
|
|
|
#define GFX_H graphics_height /* Display height */
|
VESA mode switching support.
BIOS execution is provided through the `v8086` module, which provides
software emulation of an 8086 processor. It is not currently working
with some BIOSes and may (read: probably will be) replaced with another
emulator (x86emu comes to mind) at some point in the near future. In the
meantime, the default video mode for QEMU works with this and it's
enough to get us on real VESA instead of fake VBE. The `bochs` module
will be renamed in a future commit. Userspace programs have been
adjusted to work at bitrates other than 32 *POORLY*. If you write pixels
left-to-right, they should work fine. They only work with 24-bpp
otherwise, and then you need to be careful of what pixels you are
writing when, or you will overwrite things in other pixels.
You may pass a commandline argument like the following to set display
modes:
vid=vesa,1024,768
Or for stranger modes under QEMU or Bochs, use the bochs VBE
initializer:
vid=bochs,1280,720
Note that the address of the linear framebuffer is still found via
hackish probing instead of PCI or trusting the VBE information, so if
you have things in the wrong memory ranges (0xE0000000+), be prepared to
have them get read.
Once again, this entire commit is a massive hack. I am happy that it
worked, and I will continue to make it less hacky, but in the meantime,
this is what we've got.
Happy holidays.
2011-12-25 10:40:40 +04:00
|
|
|
#define GFX_B (graphics_depth / 8) /* Display byte depth */
|
2011-04-30 22:51:33 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Macros make verything easier.
|
|
|
|
*/
|
VESA mode switching support.
BIOS execution is provided through the `v8086` module, which provides
software emulation of an 8086 processor. It is not currently working
with some BIOSes and may (read: probably will be) replaced with another
emulator (x86emu comes to mind) at some point in the near future. In the
meantime, the default video mode for QEMU works with this and it's
enough to get us on real VESA instead of fake VBE. The `bochs` module
will be renamed in a future commit. Userspace programs have been
adjusted to work at bitrates other than 32 *POORLY*. If you write pixels
left-to-right, they should work fine. They only work with 24-bpp
otherwise, and then you need to be careful of what pixels you are
writing when, or you will overwrite things in other pixels.
You may pass a commandline argument like the following to set display
modes:
vid=vesa,1024,768
Or for stranger modes under QEMU or Bochs, use the bochs VBE
initializer:
vid=bochs,1280,720
Note that the address of the linear framebuffer is still found via
hackish probing instead of PCI or trusting the VBE information, so if
you have things in the wrong memory ranges (0xE0000000+), be prepared to
have them get read.
Once again, this entire commit is a massive hack. I am happy that it
worked, and I will continue to make it less hacky, but in the meantime,
this is what we've got.
Happy holidays.
2011-12-25 10:40:40 +04:00
|
|
|
#define GFX(x,y) *((uint32_t *)&gfx_mem[(GFX_W * (y) + (x)) * GFX_B])
|
2011-04-30 12:40:36 +04:00
|
|
|
#define SPRITE(sprite,x,y) sprite->bitmap[sprite->width * (y) + (x)]
|
|
|
|
|
2011-04-30 22:51:33 +04:00
|
|
|
/* Pointer to graphics memory */
|
VESA mode switching support.
BIOS execution is provided through the `v8086` module, which provides
software emulation of an 8086 processor. It is not currently working
with some BIOSes and may (read: probably will be) replaced with another
emulator (x86emu comes to mind) at some point in the near future. In the
meantime, the default video mode for QEMU works with this and it's
enough to get us on real VESA instead of fake VBE. The `bochs` module
will be renamed in a future commit. Userspace programs have been
adjusted to work at bitrates other than 32 *POORLY*. If you write pixels
left-to-right, they should work fine. They only work with 24-bpp
otherwise, and then you need to be careful of what pixels you are
writing when, or you will overwrite things in other pixels.
You may pass a commandline argument like the following to set display
modes:
vid=vesa,1024,768
Or for stranger modes under QEMU or Bochs, use the bochs VBE
initializer:
vid=bochs,1280,720
Note that the address of the linear framebuffer is still found via
hackish probing instead of PCI or trusting the VBE information, so if
you have things in the wrong memory ranges (0xE0000000+), be prepared to
have them get read.
Once again, this entire commit is a massive hack. I am happy that it
worked, and I will continue to make it less hacky, but in the meantime,
this is what we've got.
Happy holidays.
2011-12-25 10:40:40 +04:00
|
|
|
uint8_t * gfx_mem;
|
2011-04-30 12:40:36 +04:00
|
|
|
|
2011-04-30 22:51:33 +04:00
|
|
|
/* Julia fractals elements */
|
|
|
|
float conx = -0.74; /* real part of c */
|
|
|
|
float cony = 0.1; /* imag part of c */
|
|
|
|
float Maxx = 2; /* X bounds */
|
2011-04-30 12:40:36 +04:00
|
|
|
float Minx = -2;
|
2011-04-30 22:51:33 +04:00
|
|
|
float Maxy = 1; /* Y bounds */
|
2011-04-30 12:40:36 +04:00
|
|
|
float Miny = -1;
|
2011-04-30 22:51:33 +04:00
|
|
|
float initer = 1000; /* Iteration levels */
|
|
|
|
float pixcorx; /* Internal values */
|
2011-04-30 12:40:36 +04:00
|
|
|
float pixcory;
|
|
|
|
|
2011-04-30 22:51:33 +04:00
|
|
|
int newcolor; /* Color we're placing */
|
|
|
|
int lastcolor; /* Last color we placed */
|
|
|
|
int no_repeat = 0; /* Repeat colors? */
|
2011-04-30 12:40:36 +04:00
|
|
|
|
2011-04-30 22:51:33 +04:00
|
|
|
/*
|
|
|
|
* Color table
|
|
|
|
* These are orange/red shades from the Ubuntu platte.
|
|
|
|
*/
|
2011-04-30 12:40:36 +04:00
|
|
|
int colors[] = {
|
|
|
|
0xeec73e,
|
|
|
|
0xf0a513,
|
|
|
|
0xfb8b00,
|
|
|
|
0xf44800,
|
|
|
|
0xffff99,
|
|
|
|
0xffff00,
|
|
|
|
0xfdca01,
|
|
|
|
0x986601,
|
|
|
|
0xf44800,
|
|
|
|
0xfd3301,
|
|
|
|
0xd40000,
|
|
|
|
0x980101,
|
|
|
|
};
|
|
|
|
|
|
|
|
void julia(int xpt, int ypt) {
|
|
|
|
long double x = xpt * pixcorx + Minx;
|
|
|
|
long double y = Maxy - ypt * pixcory;
|
|
|
|
long double xnew = 0;
|
|
|
|
long double ynew = 0;
|
|
|
|
|
|
|
|
int k = 0;
|
|
|
|
for (k = 0; k <= initer; k++) {
|
|
|
|
xnew = x * x - y * y + conx;
|
|
|
|
ynew = 2 * x * y + cony;
|
|
|
|
x = xnew;
|
|
|
|
y = ynew;
|
|
|
|
if ((x * x + y * y) > 4)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-05-01 07:30:57 +04:00
|
|
|
int color;
|
|
|
|
if (no_repeat) {
|
2011-04-30 22:46:55 +04:00
|
|
|
color = 12 * k / initer;
|
2011-05-01 07:30:57 +04:00
|
|
|
} else {
|
|
|
|
color = k;
|
|
|
|
if (color > 11) {
|
|
|
|
color = color % 12;
|
|
|
|
}
|
2011-04-30 22:46:55 +04:00
|
|
|
}
|
2011-05-01 07:30:57 +04:00
|
|
|
if (k >= initer) {
|
2011-04-30 12:40:36 +04:00
|
|
|
GFX(xpt, ypt) = 0;
|
2011-05-01 07:30:57 +04:00
|
|
|
} else {
|
2011-04-30 12:40:36 +04:00
|
|
|
GFX(xpt, ypt) = colors[color];
|
2011-05-01 07:30:57 +04:00
|
|
|
}
|
2011-04-30 12:40:36 +04:00
|
|
|
newcolor = color;
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char ** argv) {
|
2011-12-16 23:16:20 +04:00
|
|
|
graphics_width = syscall_getgraphicswidth();
|
|
|
|
graphics_height = syscall_getgraphicsheight();
|
VESA mode switching support.
BIOS execution is provided through the `v8086` module, which provides
software emulation of an 8086 processor. It is not currently working
with some BIOSes and may (read: probably will be) replaced with another
emulator (x86emu comes to mind) at some point in the near future. In the
meantime, the default video mode for QEMU works with this and it's
enough to get us on real VESA instead of fake VBE. The `bochs` module
will be renamed in a future commit. Userspace programs have been
adjusted to work at bitrates other than 32 *POORLY*. If you write pixels
left-to-right, they should work fine. They only work with 24-bpp
otherwise, and then you need to be careful of what pixels you are
writing when, or you will overwrite things in other pixels.
You may pass a commandline argument like the following to set display
modes:
vid=vesa,1024,768
Or for stranger modes under QEMU or Bochs, use the bochs VBE
initializer:
vid=bochs,1280,720
Note that the address of the linear framebuffer is still found via
hackish probing instead of PCI or trusting the VBE information, so if
you have things in the wrong memory ranges (0xE0000000+), be prepared to
have them get read.
Once again, this entire commit is a massive hack. I am happy that it
worked, and I will continue to make it less hacky, but in the meantime,
this is what we've got.
Happy holidays.
2011-12-25 10:40:40 +04:00
|
|
|
graphics_depth = syscall_getgraphicsdepth();
|
2011-04-30 12:40:36 +04:00
|
|
|
gfx_mem = (void *)syscall_getgraphicsaddress();
|
|
|
|
|
|
|
|
if (argc > 1) {
|
2011-05-01 07:30:57 +04:00
|
|
|
/* Read some arguments */
|
|
|
|
int index, c;
|
|
|
|
while ((c = getopt(argc, argv, "ni:x:X:c:C:")) != -1) {
|
|
|
|
switch (c) {
|
|
|
|
case 'n':
|
|
|
|
no_repeat = 1;
|
|
|
|
break;
|
|
|
|
case 'i':
|
|
|
|
initer = atof(optarg);
|
|
|
|
break;
|
|
|
|
case 'x':
|
|
|
|
Minx = atof(optarg);
|
|
|
|
break;
|
|
|
|
case 'X':
|
|
|
|
Maxx = atof(optarg);
|
|
|
|
break;
|
|
|
|
case 'c':
|
|
|
|
conx = atof(optarg);
|
|
|
|
break;
|
|
|
|
case 'C':
|
|
|
|
cony = atof(optarg);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2011-04-30 12:40:36 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
printf("initer: %f\n", initer);
|
|
|
|
printf("X: %f %f\n", Minx, Maxx);
|
2011-04-30 22:46:55 +04:00
|
|
|
float _x = Maxx - Minx;
|
2011-04-30 22:51:33 +04:00
|
|
|
float _y = _x / GFX_W * GFX_H;
|
2011-04-30 22:46:55 +04:00
|
|
|
Miny = 0 - _y / 2;
|
|
|
|
Maxy = _y / 2;
|
2011-04-30 12:40:36 +04:00
|
|
|
printf("Y: %f %f\n", Miny, Maxy);
|
|
|
|
printf("conx: %f cony: %f\n", conx, cony);
|
|
|
|
|
|
|
|
pixcorx = (Maxx - Minx) / GFX_W;
|
|
|
|
pixcory = (Maxy - Miny) / GFX_H;
|
|
|
|
int j = 0;
|
|
|
|
do {
|
|
|
|
int i = 1;
|
|
|
|
do {
|
|
|
|
julia(i,j);
|
|
|
|
if (lastcolor != newcolor) julia(i-1,j);
|
|
|
|
else if (i > 0) GFX(i-1,j) = colors[lastcolor];
|
|
|
|
newcolor = lastcolor;
|
|
|
|
i+= 2;
|
|
|
|
} while ( i < GFX_W );
|
|
|
|
++j;
|
|
|
|
} while ( j < GFX_H );
|
|
|
|
|
2011-06-09 07:27:27 +04:00
|
|
|
syscall_kbd_mode(1);
|
|
|
|
|
|
|
|
int playing = 1;
|
|
|
|
while (playing) {
|
2011-04-30 12:40:36 +04:00
|
|
|
char ch = 0;
|
2011-06-09 07:27:27 +04:00
|
|
|
ch = syscall_kbd_get();
|
|
|
|
switch (ch) {
|
|
|
|
case 16:
|
|
|
|
playing = 0;
|
|
|
|
break;
|
|
|
|
default:
|
2011-04-30 12:40:36 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
syscall_kbd_mode(0);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|