mirror of
https://github.com/deater/dos33fsprogs.git
synced 2024-09-28 17:55:04 +00:00
tfv: working on fixed point
This commit is contained in:
parent
ef64d2c4ba
commit
3bbe719824
@ -5,10 +5,18 @@ LFLAGS = -lm
|
|||||||
SDL_LIBS= `sdl-config --libs`
|
SDL_LIBS= `sdl-config --libs`
|
||||||
SDL_INCLUDE= `sdl-config --cflags`
|
SDL_INCLUDE= `sdl-config --cflags`
|
||||||
|
|
||||||
all: rainbow sparkle kaleido tfv mode7_demo text
|
all: fixed_point rainbow sparkle kaleido tfv mode7_demo text
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
####
|
||||||
|
|
||||||
|
fixed_point: fixed_point.o
|
||||||
|
$(CC) $(LFLAGS) -o fixed_point fixed_point.o
|
||||||
|
|
||||||
|
fixed_point.o: fixed_point.c
|
||||||
|
$(CC) $(CFLAGS) -c fixed_point.c
|
||||||
|
|
||||||
####
|
####
|
||||||
|
|
||||||
rainbow: rainbow.o gr-sim.o
|
rainbow: rainbow.o gr-sim.o
|
||||||
@ -129,6 +137,6 @@ gr-sim.o: gr-sim.c gr-sim.h apple2_font.h
|
|||||||
$(CC) $(CFLAGS) $(SDL_INCLUDE) -c gr-sim.c
|
$(CC) $(CFLAGS) $(SDL_INCLUDE) -c gr-sim.c
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -f *~ *.o gr-sim rainbow sparkle kaleido tfv text mode7_demo
|
rm -f *~ *.o gr-sim rainbow sparkle kaleido tfv text mode7_demo fixed_point
|
||||||
|
|
||||||
|
|
||||||
|
79
gr-sim/fixed_point.c
Normal file
79
gr-sim/fixed_point.c
Normal file
@ -0,0 +1,79 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
|
|
||||||
|
struct fixed_type {
|
||||||
|
char i;
|
||||||
|
unsigned char f;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
void double_to_fixed(double d, struct fixed_type *f) {
|
||||||
|
|
||||||
|
double temp;
|
||||||
|
|
||||||
|
f->i=(int)d;
|
||||||
|
|
||||||
|
temp=d-(f->i);
|
||||||
|
|
||||||
|
temp*=256;
|
||||||
|
|
||||||
|
f->f=temp;
|
||||||
|
|
||||||
|
printf("%lf=%02x.%02x (%d/0x%x)\n",d,f->i,f->f,(int)temp,(int)temp);
|
||||||
|
}
|
||||||
|
|
||||||
|
void fixed_to_double(struct fixed_type *f, double *d) {
|
||||||
|
|
||||||
|
*d=f->i;
|
||||||
|
*d+=((double)(f->f))/256.0;
|
||||||
|
|
||||||
|
printf("(%02x.%02x)=%lf\n",f->i,f->f,*d);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void fixed_add(struct fixed_type *x, struct fixed_type *y, struct fixed_type *z) {
|
||||||
|
int carry;
|
||||||
|
short sum;
|
||||||
|
|
||||||
|
sum=(short)(x->f)+(short)(y->f);
|
||||||
|
|
||||||
|
if (sum>=256) carry=1;
|
||||||
|
else carry=0;
|
||||||
|
|
||||||
|
z->f=sum&0xff;
|
||||||
|
|
||||||
|
z->i=x->i+y->i+carry;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char **argv) {
|
||||||
|
|
||||||
|
struct fixed_type f,fa,fb,fc;
|
||||||
|
double d,c;
|
||||||
|
|
||||||
|
double_to_fixed(4.25,&f);
|
||||||
|
fixed_to_double(&f,&d);
|
||||||
|
|
||||||
|
double_to_fixed(3.14159265358979,&f);
|
||||||
|
fixed_to_double(&f,&d);
|
||||||
|
|
||||||
|
double_to_fixed(127.333333333,&f);
|
||||||
|
fixed_to_double(&f,&d);
|
||||||
|
|
||||||
|
double_to_fixed(50.9,&f);
|
||||||
|
fixed_to_double(&f,&d);
|
||||||
|
|
||||||
|
|
||||||
|
double_to_fixed(2.75,&fa);
|
||||||
|
double_to_fixed(12.75,&fb);
|
||||||
|
fixed_add(&fa,&fb,&fc);
|
||||||
|
fixed_to_double(&fc,&c);
|
||||||
|
|
||||||
|
double_to_fixed(-1.25,&fa);
|
||||||
|
double_to_fixed(-1.75,&fb);
|
||||||
|
fixed_add(&fa,&fb,&fc);
|
||||||
|
fixed_to_double(&fc,&c);
|
||||||
|
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
@ -59,11 +59,6 @@ static int lookup_map(int x, int y) {
|
|||||||
return color;
|
return color;
|
||||||
}
|
}
|
||||||
|
|
||||||
static double space_z=4.5; // height of the camera above the plane
|
|
||||||
static int horizon=-2; // number of pixels line 0 is below the horizon
|
|
||||||
static double scale_x=20, scale_y=20;
|
|
||||||
|
|
||||||
double BETA=-0.5;
|
|
||||||
|
|
||||||
static int over_water;
|
static int over_water;
|
||||||
|
|
||||||
@ -74,12 +69,16 @@ static char angle=0;
|
|||||||
// map coordinates
|
// map coordinates
|
||||||
double cx=0.0,cy=0.0;
|
double cx=0.0,cy=0.0;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#if 1
|
#if 1
|
||||||
|
|
||||||
|
static double space_z=4.5; // height of the camera above the plane
|
||||||
|
static int horizon=-2; // number of pixels line 0 is below the horizon
|
||||||
|
|
||||||
|
double BETA=-0.5;
|
||||||
|
|
||||||
|
#define SCALE_X 20.0
|
||||||
|
#define SCALE_Y 20.0
|
||||||
|
|
||||||
|
|
||||||
#define ANGLE_STEPS 16
|
#define ANGLE_STEPS 16
|
||||||
|
|
||||||
@ -146,14 +145,13 @@ void draw_background_mode7(void) {
|
|||||||
color_equals(COLOR_GREY);
|
color_equals(COLOR_GREY);
|
||||||
hlin_double(ram[DRAW_PAGE], 0, 40, 6);
|
hlin_double(ram[DRAW_PAGE], 0, 40, 6);
|
||||||
|
|
||||||
|
|
||||||
for (screen_y = 8; screen_y < LOWRES_H; screen_y++) {
|
for (screen_y = 8; screen_y < LOWRES_H; screen_y++) {
|
||||||
// first calculate the distance of the line we are drawing
|
// first calculate the distance of the line we are drawing
|
||||||
distance = (space_z * scale_y) / (screen_y + horizon);
|
distance = (space_z * SCALE_Y) / (screen_y + horizon);
|
||||||
|
|
||||||
// then calculate the horizontal scale, or the distance between
|
// then calculate the horizontal scale, or the distance between
|
||||||
// space points on this horizontal line
|
// space points on this horizontal line
|
||||||
horizontal_scale = (distance / scale_x);
|
horizontal_scale = (distance / SCALE_X);
|
||||||
|
|
||||||
// calculate the dx and dy of points in space when we step
|
// calculate the dx and dy of points in space when we step
|
||||||
// through all points on this line
|
// through all points on this line
|
||||||
@ -170,8 +168,6 @@ void draw_background_mode7(void) {
|
|||||||
|
|
||||||
factor=space_z*BETA;
|
factor=space_z*BETA;
|
||||||
|
|
||||||
// factor=2.0*BETA;
|
|
||||||
|
|
||||||
space_x+=factor*our_cos(angle);
|
space_x+=factor*our_cos(angle);
|
||||||
space_y+=factor*our_sin(angle);
|
space_y+=factor*our_sin(angle);
|
||||||
|
|
||||||
@ -225,23 +221,6 @@ int flying(void) {
|
|||||||
|
|
||||||
if ((ch=='q') || (ch==27)) break;
|
if ((ch=='q') || (ch==27)) break;
|
||||||
|
|
||||||
#if 0
|
|
||||||
if (ch=='g') {
|
|
||||||
BETA+=0.1;
|
|
||||||
printf("Horizon=%lf\n",BETA);
|
|
||||||
}
|
|
||||||
if (ch=='h') {
|
|
||||||
BETA-=0.1;
|
|
||||||
printf("Horizon=%lf\n",BETA);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ch=='s') {
|
|
||||||
scale_x++;
|
|
||||||
scale_y++;
|
|
||||||
printf("Scale=%lf\n",scale_x);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if ((ch=='w') || (ch==APPLE_UP)) {
|
if ((ch=='w') || (ch==APPLE_UP)) {
|
||||||
if (shipy>16) {
|
if (shipy>16) {
|
||||||
shipy-=2;
|
shipy-=2;
|
||||||
@ -374,6 +353,13 @@ int flying(void) {
|
|||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
|
static double space_z=4.5; // height of the camera above the plane
|
||||||
|
static int horizon=-2; // number of pixels line 0 is below the horizon
|
||||||
|
static double scale_x=20, scale_y=20;
|
||||||
|
|
||||||
|
double BETA=-0.5;
|
||||||
|
|
||||||
|
|
||||||
#define ANGLE_STEPS 32
|
#define ANGLE_STEPS 32
|
||||||
|
|
||||||
double our_sin(unsigned char angle) {
|
double our_sin(unsigned char angle) {
|
||||||
|
Loading…
Reference in New Issue
Block a user