diff --git a/utils/gr-sim/dots/Makefile b/utils/gr-sim/dots/Makefile index 069b3014..e913c9a4 100644 --- a/utils/gr-sim/dots/Makefile +++ b/utils/gr-sim/dots/Makefile @@ -4,7 +4,7 @@ CFLAGS = -O2 -Wall -g SDL_LIBS= `sdl-config --libs` SDL_INCLUDE= `sdl-config --cflags` -all: dots dots_dump dots_play +all: dots dots_dump dots_play dots_minimal ### @@ -32,6 +32,15 @@ dots.o: dots.c vga_emulator.h ### +dots_minimal: dots_minimal.o ../gr-sim.a + $(CC) -o dots_minimal dots_minimal.o ../gr-sim.a $(LFLAGS) $(SDL_LIBS) + +dots_minimal.o: dots_minimal.c + $(CC) $(CFLAGS) $(SDL_INCLUDE) -c dots_minimal.c + + +### + 8086_emulator.o: 8086_emulator.c 8086_emulator.h $(CC) $(CFLAGS) -c 8086_emulator.c @@ -43,4 +52,4 @@ vga_emulator.o: vga_emulator.c vga_emulator.h ### clean: - rm -f *~ *.o dots dots_dump dots_play + rm -f *~ *.o dots dots_dump dots_play dots_minimal diff --git a/utils/gr-sim/dots/dots.c b/utils/gr-sim/dots/dots.c index 2e63355b..94c08d73 100644 --- a/utils/gr-sim/dots/dots.c +++ b/utils/gr-sim/dots/dots.c @@ -17,6 +17,8 @@ #define BOTTOM 8000 +#define SKIP 2 + static short gravitybottom=BOTTOM; static short bpmin=30000; @@ -181,6 +183,7 @@ label1: yy=((bx/320)*48)/200; color_equals(0); plot( (bx%320)/8,yy); +// printf("0,%d,%d\n",(bx%320)/8,yy); // printf("Plotting at %d,%d\n",(bx%320)/8,(bx/320)/5); @@ -351,6 +354,7 @@ label_t2: yy=((bx/320)*48)/200; color_equals(6); plot( (bx%320)/8,yy); +// printf("6,%d,%d\n",(bx%320)/8,yy); framebuffer[bx+1]=depthtable1_bytes[bp]; framebuffer[bx+2]=depthtable1_bytes[bp+1]; @@ -371,8 +375,8 @@ label_t2: //labelz: cx=pop(); // pop cx - si=si+1; // add si,16 point to next dot - cx=cx-1; + si=si+SKIP; // add si,16 point to next dot + cx=cx-SKIP; if (cx!=0) goto label1; // loop @@1 label0: return; @@ -422,8 +426,8 @@ label2: bx=pop(); // pop bx cx=pop(); // pop cx - si=si+1; // add si,16 - cx=cx-1; // loop @@1 + si=si+SKIP; // add si,16 + cx=cx-SKIP; // loop @@1 if (cx!=0) goto label1; goto label0; // jmp @@0 @@ -457,8 +461,8 @@ label3: bx=pop(); // pop bx cx=pop(); // pop cx - si=si+1; // add si,16 - cx=cx-1; // loop @@1 + si=si+SKIP; // add si,16 + cx=cx-SKIP; // loop @@1 if (cx!=0) goto label1; goto label0; // jmp @@0 diff --git a/utils/gr-sim/dots/dots_dump.c b/utils/gr-sim/dots/dots_dump.c index 94c08d73..674da32d 100644 --- a/utils/gr-sim/dots/dots_dump.c +++ b/utils/gr-sim/dots/dots_dump.c @@ -17,7 +17,11 @@ #define BOTTOM 8000 -#define SKIP 2 +#define SKIP 4 + +#define FRAME_SKIP 10 + +static int write_frame=-1; static short gravitybottom=BOTTOM; @@ -52,13 +56,14 @@ static char *bgpic; static int depthtable1[128]; static int depthtable2[128]; static int depthtable3[128]; -//static int depthtable4[128]; static unsigned char depthtable1_bytes[512]; static unsigned char depthtable2_bytes[512]; static unsigned char depthtable3_bytes[512]; -//static unsigned char depthtable4_bytes[512]; +static int shadow[40][48]; +static int ball[40][48]; +FILE *output; static void drawdots(void) { int temp32; @@ -183,6 +188,9 @@ label1: yy=((bx/320)*48)/200; color_equals(0); plot( (bx%320)/8,yy); + + shadow[(bx%320)/8][yy]=1; + // printf("0,%d,%d\n",(bx%320)/8,yy); // printf("Plotting at %d,%d\n",(bx%320)/8,(bx/320)/5); @@ -354,6 +362,9 @@ label_t2: yy=((bx/320)*48)/200; color_equals(6); plot( (bx%320)/8,yy); + + ball[(bx%320)/8][yy]=1; + // printf("6,%d,%d\n",(bx%320)/8,yy); framebuffer[bx+1]=depthtable1_bytes[bp]; @@ -602,6 +613,14 @@ int main(int argc,char **argv) { short grav,gravd; short f=0; int ch; + int xx,yy; + unsigned char buffer[10]; + + output=fopen("out","w"); + if (output==NULL) { + fprintf(stderr,"error opening\n"); + exit(1); + } //dis_partstart(); @@ -779,6 +798,13 @@ int main(int argc,char **argv) { while(!dis_exit() && frame<2450) { + for(xx=0;xx<40;xx++) { + for(yy=0;yy<48;yy++) { + shadow[xx][yy]=0; + ball[xx][yy]=0; + } + } + /* code sets border color */ /* then waits for it to end, as a timing thing? */ setborder(0); @@ -895,14 +921,59 @@ int main(int argc,char **argv) { grsim_update(); -#if 0 - for(i=0;i #include -#include "8086_emulator.h" -#include "vga_emulator.h" - #include "../gr-sim.h" #include "../tfv_zp.h" #include "sin1024.h" -#define MAXDOTS 1024 +#define MAXDOTS 512 #define SKIP 2 static short gravitybottom; -static short bpmin=30000; -static short bpmax=-30000; +//static short bpmin=30000; +//static short bpmax=-30000; static short gravity=0; static short dotnum=0; static short gravityd=16; @@ -40,121 +37,120 @@ static void drawdots(void) { int temp32; int transx,transz; int yy; - unsigned short our_x,our_y; + unsigned short ball_x,ball_y,shadow_y; + unsigned short d,sc,newy; + unsigned short ax,bx,cx,dx; + short signed_ax; - for(si=0;si<512;si+=SKIP) { + for(d=0;d<512;d+=SKIP) { - transx=dot[si].x*rotsin; - transz=dot[si].z*rotcos; + transx=dot[d].x*rotsin; + transz=dot[d].z*rotcos; temp32=transz-transx; - bp=(temp32>>16)+9000; + sc=(temp32>>16)+9000; + if (sc==0) sc=1; - transx=dot[si].x*rotcos; - transz=dot[si].z*rotsin; + transx=dot[d].x*rotcos; + transz=dot[d].z*rotsin; temp32=transx+transz; temp32>>=8; ax=temp32&0xffff; dx=(temp32>>16)&0xffff; - bx=ax; // mov bx,ax - cx=dx; // mov cx,dx + bx=ax; // mov bx,ax + cx=dx; // mov cx,dx - ax=(ax>>3)|(dx<<13); // shrd ax,dx,3 + ax=(ax>>3)|(dx<<13); // shrd ax,dx,3 - dx=sar(dx,3); // sar dx,3 - temp32=ax+bx; // add ax,bx - ax=ax+bx; - dx=dx+cx; // adc dx,cx - if (temp32&(1<<16)) dx=dx+1; +// dx=sar(dx,3); // sar dx,3 + signed_ax=dx; + dx=signed_ax>>3; - temp32=(dx<<16)|(ax&0xfffff); - idiv_16(bp); // idiv bp - our_x=ax+160; // add ax,160 + temp32=ax+bx; // add ax,bx + ax=ax+bx; + dx=dx+cx; // adc dx,cx + if (temp32&(1<<16)) dx=dx+1; - /* if off end of screen, no need for shadow */ + temp32=(dx<<16)|(ax&0xffff); + if (sc) ball_x=(temp32/sc)&0xffff; + else ball_x=0; - if (our_x>319) continue; + ball_x+=160; - /**********/ - /* shadow */ - /**********/ + /* if off end of screen, no need for shadow */ - ax=0; // xor ax,ax - dx=8; // mov dx,8 - idiv_16(bp); // idiv bp - ax=ax+100; // add ax,100 + if (ball_x>319) continue; - /* if shadow off screen, don't draw */ - if (ax>199) continue; // cmp ax,199 - // ja @@2 - bx=ax; // mov bx,ax + /**********/ + /* shadow */ + /**********/ - // not needed, it's a C array - bx=rows[bx]; // mov bx,ds:_rows[bx] - bx=bx+our_x; // add bx,ax + shadow_y=0x80000/sc; - /* draw shadow */ + /* center it */ + shadow_y+=100; -// bx/320 -> 200 200->48 *48/200 + /* if shadow off screen, don't draw */ + if (shadow_y>199) continue; - yy=((bx/320)*48)/200; - color_equals(0); - plot( (bx%320)/8,yy); + /* draw shadow */ + yy=(shadow_y*48)/200; + color_equals(0); + plot( (ball_x)/8,yy); /********/ /* ball */ /********/ - dot[si].yadd+=gravity; - ax=dot[si].y+dot[si].yadd; + dot[d].yadd+=gravity; + newy=dot[d].y+dot[d].yadd; - temp32=ax; + temp32=newy; if (temp32&0x8000) temp32|=0xffff0000; if (temp32>=gravitybottom) { - push(ax); // push ax - ax=-dot[si].yadd; - imul_16(gravityd); // imul cs:_gravityd - ax=sar(ax,4); // sar ax,4 - dot[si].yadd=ax; // mov ds:[si+14],ax - ax=pop(); // pop ax - ax+=dot[si].yadd; // add ax,ds:[si+14] + ax=-dot[d].yadd; + temp32=(-dot[d].yadd)*gravityd; + ax=temp32&0xffff; + +// ax=sar(ax,4); + signed_ax=ax; + ax=signed_ax>>4; + + dot[d].yadd=ax; + newy+=dot[d].yadd; } - dot[si].y=ax; // mov ds:[si+2],ax - if (ax&0x8000) { // cwd - dx=0xffff; - } - else { - dx=0; - } - dx=(dx<<6)|(ax>>10); // shld dx,ax,6 - ax=ax<<6; // shl ax,6 - idiv_16(bp); // idiv bp - our_y=ax+100; // add ax,100 - if (our_y>199) continue; // cmp ax,199 + dot[d].y=newy; - bp=bp>>6; // shr bp,6 - bp=bp&(~3L); // and bp,not 3 - - temp32=bp; - if (temp32&0x8000) temp32|=0xffff0000; - if (temp32bpmax) { - bpmax=bp; - } + temp32<<=6; +// dx=(dx<<6)|(newy>>10); // shld dx,ax,6 +// newy=newy<<6; // shl ax,6 +// ax=newy; +// idiv_16(sc); // idiv sc + + if (sc) newy=temp32/sc; + + /* center */ + ball_y=newy+100; // add ax,100 + + /* don't draw if off screen */ + if (ball_y>199) continue; /* plot ball */ - yy=(our_y*48)/200; + /* convert from 320x200 to 40x48 */ + yy=(ball_y*48)/200; color_equals(6); - plot(our_x/8,yy); + plot(ball_x/8,yy); } + return; } diff --git a/utils/gr-sim/dots/dots_play.c b/utils/gr-sim/dots/dots_play.c index 1a4ed699..e801f51e 100644 --- a/utils/gr-sim/dots/dots_play.c +++ b/utils/gr-sim/dots/dots_play.c @@ -1,13 +1,34 @@ #include +#include #include +#include #include "../gr-sim.h" #include "../tfv_zp.h" +int create_gr_files=0; + +int skip_factor=1; +int fps=10; + int main(int argc, char **argv) { - int xx,yy,ch; + + int xx,yy,ch=0,i; int current_row=0; + int frame=0; + int fd; + + if (argc>1) { + skip_factor=atoi(argv[1]); + } + printf("Only playing 1 of every %d frames\n",skip_factor); + + if (argc>2) { + fps=atoi(argv[2]); + } + printf("Playing at %d frames per second\n",fps); + grsim_init(); @@ -24,6 +45,19 @@ int main(int argc, char **argv) { color_equals(0); + /* skip frames */ + for(i=0;i<(skip_factor-1);i++) { + while(1) { + ch=getchar(); + if (ch==0xff) break; + + if (ch==0xfe) break; + } + if (ch==0xff) break; + } + + if (ch==0xff) break; + /* parse loop */ while(1) { ch=getchar(); @@ -47,10 +81,25 @@ int main(int argc, char **argv) { } if (ch==0xff) break; - usleep(14285); + usleep(1000000/fps); grsim_update(); + if (create_gr_files) { + char filename[256]; + + sprintf(filename,"frame%03d.gr",frame); + fd=open(filename,O_WRONLY|O_CREAT,0660); + if (fd<0) { + fprintf(stderr,"Error opening!\n"); + return -1; + } + write(fd,&ram[0x400],1024); + close(fd); + } + + frame++; + //again: ch=grsim_input(); if (ch==27) {