/***********************************************************************/ /* This program demonstrates how to use BIOS calls for programming the */ /* Atari Portfolio in graphics mode. The program should be compiled */ /* with Turbo C 1.0 */ /* Simple 3D engine implementation by RayeR (C) 2000 */ /***********************************************************************/ // budem prekladat pro portfolio ? //#define PORTFOLIO #include #include #include typedef unsigned char Byte; #define GFX 0x04 // videomody #define TXT 0x07 #define XRES 240 #define YRES 64 #define VRAMSIZE 1920 #define MIDX (XRES/2) #define MIDY (YRES/2) #define FP 10 // fixed point 6:10 #define FPR 6 // na kolik bitu bude platny sin/cos #define FPPI (8-FPR) #define XOFFSET (-20) // doladeni polohy 2D obrazu #define YOFFSET (-3) // doladeni polohy 2D obrazu /* camera position */ #define CX 20 #define CY -2 #define CZ 80 /* krychle - 8 vertexu, 12 faces */ #define VNUM 8 #define FNUM 12 #define HEDGE (19<>3; vram[ofs]=vram[ofs]|(0x80>>bytenum); } #endif /*Byte getpix(Byte x, Byte y) // get pixel color 0/1 { union REGS regs; regs.h.ah = 0x0d; regs.h.bh = 0; regs.x.cx = x; regs.x.dx = y; int86(0x10, ®s, ®s); return(regs.h.al); } */ void refresh(void) /* zkopiruje VRAM na displej (do kontroleru HD) */ { asm { cld push ax push cx push dx push bx push si push di push ds mov si,0 mov ax,0b000h mov ds,ax mov di,64 } refresh_2: asm { mov cx,30 mov bx,si mov al,0ah mov dx,8011h cli out dx,al mov al,bl mov dx,8010h out dx,al sti mov al,0bh mov dx,8011h cli out dx,al mov dx,8010h mov al,bh and al,7 out dx,al sti } refresh_1: asm { lodsb ror al,1 mov ah,al and ah,136 ror al,1 ror al,1 mov bl,al and bl,68 or ah,bl ror al,1 ror al,1 mov bl,al and bl,34 or ah,bl ror al,1 ror al,1 and al,17 or al,ah mov ah,al inc dx mov al,0ch cli out dx,al mov al,ah mov dx,8010h out dx,al sti loop refresh_1 dec di jnz refresh_2 pop ds pop di pop si pop bx pop dx pop cx pop ax } } void line(Byte x1, Byte y1, Byte x2, Byte y2, Byte color) /* line */ { int x, y, d, a, b; int dx_diag, dy_diag; int dx_nondiag, dy_nondiag; int diag_inc, nondiag_inc; int i, swap; x = x1; y = y1; a = x2-x1; b = y2-y1; if (a<0) { a = -a; dx_diag = -1; } else dx_diag = 1; if (b<0) { b = -b; dy_diag = -1; } else dy_diag = 1; if (a>FP)+CZ); p[i][0]=(int)( CZ*((v[i][0]>>FP)+CX)/zdivider+MIDX)+XOFFSET; p[i][1]=(int)(-CZ*((v[i][1]>>FP)+CY)/zdivider+MIDY)+YOFFSET; } } void render(Byte color) { Byte i; for (i=0; i0) v[i][0]=v[i][0]<>-xm; if (ym>0) v[i][1]=v[i][1]<>-ym; if (zm>0) v[i][2]=v[i][2]<>-zm; } } */ void iscale(int xm, int ym , int zm) { int i; for (i=0; i0) v[i][0]+=xm; else if (v[i][0]<0) v[i][0]-=xm; if (v[i][1]>0) v[i][1]+=ym; else if (v[i][1]<0) v[i][1]-=ym; if (v[i][2]>0) v[i][2]+=zm; else if (v[i][2]<0) v[i][2]-=zm; } } int isin(char x) { if (x>0) return(sintbl[x]>>FPPI); else return(-sintbl[-x]>>FPPI); } int icos(char x) { if (x>0) return(sintbl[90-x]>>FPPI); else return(sintbl[90+x]>>FPPI); } void rotatex(Byte alfa) { int i,temp; for (i=0; i>FPR)*icos(alfa)-(v[i][1]>>FPR)*isin(alfa); v[i][1]=(v[i][2]>>FPR)*isin(alfa)+(v[i][1]>>FPR)*icos(alfa); v[i][2]=temp; } } void rotatey(Byte alfa) { int i,temp; for (i=0; i>FPR)*icos(alfa)-(v[i][2]>>FPR)*isin(alfa); v[i][2]=(v[i][0]>>FPR)*isin(alfa)+(v[i][2]>>FPR)*icos(alfa); v[i][0]=temp; } } void rotatez(Byte alfa) { int i,temp; for (i=0; i>FPR)*icos(alfa)-(v[i][1]>>FPR)*isin(alfa); v[i][1]=(v[i][0]>>FPR)*isin(alfa)+(v[i][1]>>FPR)*icos(alfa); v[i][0]=temp; } } void makebox(void) { v[0][0]=-HEDGE; v[0][1]=HEDGE; v[0][2]=HEDGE; v[1][0]=HEDGE; v[1][1]=HEDGE; v[1][2]=HEDGE; v[2][0]=HEDGE; v[2][1]=-HEDGE; v[2][2]=HEDGE; v[3][0]=-HEDGE; v[3][1]=-HEDGE; v[3][2]=HEDGE; v[4][0]=-HEDGE; v[4][1]=HEDGE; v[4][2]=-HEDGE; v[5][0]=HEDGE; v[5][1]=HEDGE; v[5][2]=-HEDGE; v[6][0]=HEDGE; v[6][1]=-HEDGE; v[6][2]=-HEDGE; v[7][0]=-HEDGE; v[7][1]=-HEDGE; v[7][2]=-HEDGE; } main() { /* definice faces krychle */ f[0][0]=0; f[0][1]=3; f[0][2]=2; f[1][0]=0; f[1][1]=1; f[1][2]=2; f[2][0]=1; f[2][1]=5; f[2][2]=6; f[3][0]=1; f[3][1]=2; f[3][2]=6; f[4][0]=0; f[4][1]=4; f[4][2]=7; f[5][0]=0; f[5][1]=3; f[5][2]=7; f[6][0]=4; f[6][1]=5; f[6][2]=6; f[7][0]=4; f[7][1]=7; f[7][2]=6; f[8][0]=0; f[8][1]=1; f[8][2]=5; f[9][0]=0; f[9][1]=4; f[9][2]=5; f[10][0]=3; f[10][1]=2; f[10][2]=6; f[11][0]=3; f[11][1]=7; f[11][2]=6; makebox(); setmode(GFX); j=0; while (!kbhit()) { for (i=0; i<16; i++) { rotatey(6); iscale(220,0,220); // korekce XZ chyby rotace transform(); #ifndef PORTFOLIO setmode(GFX); // jako cls line(0,0,XRES-1,0,1); line(XRES-1,0,XRES-1,YRES-1,1); line(XRES-1,YRES-1,0,YRES-1,1); line(0,YRES-1,0,0,1); #else cls(0); #endif render(1); refresh(); printf("Diz iz da Reel Hardk0re!"); #ifndef PORTFOLIO delay(20); #else pfdelay(1000); #endif } makebox(); j++; if ((j%4)==0) j=0; for (l=0; l