void NoRGBScreenPixelPlot(struct Window *win, double FloatCol, short ColMax, short x, short y) { short Col; Col = FloatCol + ROUNDING_KLUDGE; if(DTable) { if((FloatCol - (double)Col) > DTable[(DMod++ % RENDER_SCREEN_DITHER_SIZE)]) { if (Col < ColMax) Col++; } /* if color less than max for specific gradient range */ } /* if */ SetAPen(win->RPort, AltPen[Col]); WritePixel(win->RPort, x, y); } /* NoRGBScreenPixelPlot() */
LONG FracBlank( struct Screen *Scr, UWORD Wid, UWORD Hei ) { float x = 0, y = 0, xx, yy, a, b, c; LONG i, xe, ye, flg_end = OK, mod = ( 1L << Scr->BitMap.Depth ) - 1; struct RastPort *Rast = &( Scr->RastPort ); SetRast( Rast, 0 ); ScreenToFront( Scr ); a = (float)RangeRand( 1000 ) / 10 - 50.0; do b = (float)RangeRand( 1000 ) / 10 - 50.0; while( b == 0.0 ); c = (float)RangeRand( 1000 ) / 10 - 50.0; for( i = 0; i < 50000 && flg_end == OK; i++ ) { if(!( i % 50 )) { ScreenToFront( Scr ); flg_end = ContinueBlanking(); } if( x < 0 ) xx = y + sqrt( fabs( b * x - c )); else xx = y - sqrt( fabs( b * x - c )); yy = a - x; xe = Wid / 2 + (SHORT)x; ye = Hei / 2 + (SHORT)y; if(( xe >= 0 )&&( ye >= 0 )&&( xe < Wid )&&( ye < Hei )) { SetAPen( Rast, ( ReadPixel( Rast, xe, ye ) + 1 ) % mod + 1 ); WritePixel( Rast, xe, ye ); } x = xx; y = yy; } return flg_end; }
void ScreenPixelPlot(struct Window *win, UBYTE **Bitmap, short x, short y, long zip) { short Col; double FloatCol; FloatCol = 8.0 + 7.999 * (765 - Bitmap[0][zip] - Bitmap[1][zip] - Bitmap[2][zip]) / 765.0; Col = FloatCol + ROUNDING_KLUDGE; if ((x + y) & 0x01) { if((FloatCol - (double)Col) > .5) { if (Col < 15) Col++; } /* if color less than max for specific gradient range */ } /* if */ SetAPen(win->RPort, Col); WritePixel(win->RPort, x, y); } /* PixelPlot */
/********************************************************************* * Function: void PutPixel(SHORT x, SHORT y) * * PreCondition: none * * Input: x,y - pixel coordinates * * Output: none * * Side Effects: none * * Overview: puts pixel * * Note: none * ********************************************************************/ void PutPixel(SHORT x, SHORT y) { if(_clipRgn) { if(x < _clipLeft) return; if(x > _clipRight) return; if(y < _clipTop) return; if(y > _clipBottom) return; } DeviceSelect; SetAddress(x, y); WritePixel(_color); DeviceDeselect; }
/********************************************************************* * Function: void PutPixel(SHORT x, SHORT y) * * PreCondition: none * * Input: x,y - pixel coordinates * * Output: none * * Side Effects: none * * Overview: puts pixel * * Note: none * ********************************************************************/ void PutPixel(SHORT x, SHORT y) { if(_clipRgn) { if(x < _clipLeft) return; if(x > _clipRight) return; if(y < _clipTop) return; if(y > _clipBottom) return; } DisplayEnable(); SetAddress(x, y); WritePixel(_color); DisplayDisable(); }
void GSDrawScanlineCodeGenerator::WriteZBuf() { if(!m_sel.zwrite) { return; } bool fast = m_sel.ztest && m_sel.zpsm < 2; vmovdqa(xmm1, ptr[r11 + offsetof(GSScanlineLocalData, temp.zs)]); if(fast) { // zs = zs.blend8(zd, zm); vpblendvb(xmm1, ptr[r11 + offsetof(GSScanlineLocalData, temp.zd)], xmm4); } WritePixel(xmm1, rbp, dh, fast, m_sel.zpsm, 1); }
/********************************************************************* * Function: void PutPixel(SHORT x, SHORT y) * * PreCondition: none * * Input: x,y - pixel coordinates * * Output: none * * Side Effects: none * * Overview: puts pixel * * Note: none * ********************************************************************/ void PutPixel(SHORT x, SHORT y) { DWORD_VAL address; if(_clipRgn) { if(x < _clipLeft) return; if(x > _clipRight) return; if(y < _clipTop) return; if(y > _clipBottom) return; } CS_LAT_BIT = 0; SetAddress(x, y); WritePixel(_color); CS_LAT_BIT = 1; }
LONG Dragon( struct Screen *Scr, SHORT Wid, SHORT Hei ) { LONG Color = 1, mod = (( 1L << Scr->BitMap.Depth ) - 1 ) * 5; LONG i, RetVal = OK, xd, yd; float a = PI-(( float )RangeRand( 100 )+10.0)/5000, xx, yy, x = 0, y = 0; struct RastPort *RP = &( Scr->RastPort ); SetRast( RP, 0 ); ScreenToFront( Scr ); for( i = 0; i < 1000000 && RetVal == OK; i++ ) { if(!( i % 100 )) { RetVal = ContinueBlanking(); ScreenToFront( Scr ); } xx = y - sin( x ); yy = a - x; xd = Wid / 2 + (SHORT)( 2.0 * x ); yd = Hei / 2 + (SHORT)( 2.0 * y ); Color = ( Color + 1 ) % mod; if(( xd >= 0 )&&( yd >= 0 )&&( xd < Wid )&&( yd < Hei )) { SetAPen( RP, Color/5 + 1 ); WritePixel( RP, xd, yd ); } x = xx; y = yy; } return RetVal; }
// Fills a polygon given 3 points and a color. void Rasterizer::FillPolygon(Vertex v1, Vertex v2, Vertex v3, Gdiplus::Color color) { ScanLine* _scanlines = new ScanLine[_height]; // Set the scanlines to very high and very low values so // they will be set on the first set of interpolation. for (unsigned int i = 0; i < _height; i++) { _scanlines[i].xStart = 99999; _scanlines[i].xEnd = -99999; } // Interpolates between each of the vertexs of the polygon and sets the start // and end values for each of the scanlines it comes in contact with. InterpolateScanline(_scanlines, v1, v2); InterpolateScanline(_scanlines, v2, v3); InterpolateScanline(_scanlines, v3, v1); // Go through each scanline and each pixel in the scanline and // sets its color. for (unsigned int y = 0; y < _height; y++) { for (int x = (int)_scanlines[y].xStart; x <= (int)_scanlines[y].xEnd; x++) { if (x < 0 || x >= (int)_width) continue; WritePixel(x, y, color); //_bitmap->SetPixel(x, y, color); } } // Dispose of dynamic objects. delete[] _scanlines; _polygonsRendered++; }
/********************************************************************* * Function: WORD Bar(SHORT left, SHORT top, SHORT right, SHORT bottom) * * PreCondition: none * * Input: left,top - top left corner coordinates, * right,bottom - bottom right corner coordinates * * Output: none * * Side Effects: none * * Overview: draws rectangle filled with current color * * Note: none * ********************************************************************/ WORD Bar(SHORT left, SHORT top, SHORT right, SHORT bottom) { register SHORT x, y; #ifndef USE_NONBLOCKING_CONFIG while(IsDeviceBusy() != 0); /* Ready */ #else if(IsDeviceBusy() != 0) return (0); #endif if(_clipRgn) { if(left < _clipLeft) left = _clipLeft; if(right > _clipRight) right = _clipRight; if(top < _clipTop) top = _clipTop; if(bottom > _clipBottom) bottom = _clipBottom; } DeviceSelect; for(y = top; y < bottom + 1; y++) { SetAddress(left, y); for(x = left; x < right + 1; x++) { WritePixel(_color); } } DeviceDeselect; return (1); }
void GSDrawScanlineCodeGenerator::WriteZBuf() { if(!m_sel.zwrite) { return; } movdqa(xmm1, xmmword[!m_sel.sprite ? &m_env.temp.zs : &m_env.p.z]); bool fast = false; if(m_sel.ztest && m_sel.zpsm < 2) { // zs = zs.blend8(zd, zm); movdqa(xmm0, xmm4); movdqa(xmm7, xmmword[&m_env.temp.zd]); blend8(xmm1, xmm7); fast = true; } WritePixel(xmm1, xmm0, ebp, dh, fast, m_sel.zpsm); }
/********************************************************************* * Function: WORD Bar(SHORT left, SHORT top, SHORT right, SHORT bottom) * * PreCondition: none * * Input: left,top - top left corner coordinates, * right,bottom - bottom right corner coordinates * * Output: For NON-Blocking configuration: * - Returns 0 when device is busy and the shape is not yet completely drawn. * - Returns 1 when the shape is completely drawn. * For Blocking configuration: * - Always return 1. * * Side Effects: none * * Overview: draws rectangle filled with current color * * Note: none * ********************************************************************/ WORD Bar(SHORT left, SHORT top, SHORT right, SHORT bottom) { DWORD address; register SHORT x, y; #ifndef USE_NONBLOCKING_CONFIG while(IsDeviceBusy() != 0); /* Ready */ #else if(IsDeviceBusy() != 0) return (0); #endif if(_clipRgn) { if(left < _clipLeft) left = _clipLeft; if(right > _clipRight) right = _clipRight; if(top < _clipTop) top = _clipTop; if(bottom > _clipBottom) bottom = _clipBottom; } #if (DISP_ORIENTATION == 0) address = (DWORD) LINE_MEM_PITCH * top + left; DisplayEnable(); for(y = top; y < bottom + 1; y++) { SetAddress(address); for(x = left; x < right + 1; x++) { WritePixel(_color); } address += LINE_MEM_PITCH; } DisplayDisable(); #else top = GetMaxY() - top; bottom = GetMaxY() - bottom; address = (DWORD) LINE_MEM_PITCH * left + top; DisplayEnable(); for(y = bottom; y < top + 1; y++) { SetAddress(address); for(x = left; x < right + 1; x++) { WritePixel(_color); } address -= 1; } DisplayDisable(); #endif return (1); }
/************************************************************************** MUIM_Draw **************************************************************************/ IPTR Levelmeter__MUIM_Draw(struct IClass *cl, Object *obj, struct MUIP_Draw *msg) { struct Levelmeter_DATA *data = INST_DATA(cl, obj); struct RastPort *rp; WORD x1, y1, x2, y2; DoSuperMethodA(cl,obj,(Msg)msg); if (!(msg->flags & (MADF_DRAWOBJECT | MADF_DRAWUPDATE))) return FALSE; x1 = _mleft(obj); y1 = _mtop(obj); x2 = _mright(obj); y2 = _mbottom(obj); rp = _rp(obj); if (msg->flags & MADF_DRAWOBJECT) { /* Transparent edges */ DoMethod(obj, MUIM_DrawParentBackground, x1, y1, 2, 1, x1, y1, 0); DoMethod(obj, MUIM_DrawParentBackground, x1, y1 + 1, 1, 1, x1, y1 + 1, 0); DoMethod(obj, MUIM_DrawParentBackground, x2 - 1, y1, 2, 1, x2 - 1, y1, 0); DoMethod(obj, MUIM_DrawParentBackground, x2, y1 + 1, 1, 1, x2, y1 + 1, 0); DoMethod(obj, MUIM_DrawParentBackground, x1, y2, 2, 1, x1, y2, 0); DoMethod(obj, MUIM_DrawParentBackground, x1, y2 - 1, 1, 1, x1, y2 - 1, 0); DoMethod(obj, MUIM_DrawParentBackground, x2 - 1, y2, 2, 1, x2 - 1, y2, 0); DoMethod(obj, MUIM_DrawParentBackground, x2, y2 - 1, 1, 1, x2, y2 - 1, 0); /* Outer frame */ SetABPenDrMd(rp, _pens(obj)[MPEN_SHINE], 0, JAM1); Move(rp, x1 + 1, y2 - 1); Draw(rp, x1, y2 - 2); Draw(rp, x1, y1 + 2); Draw(rp, x1 + 2, y1); Draw(rp, x2 - 2, y1); Draw(rp, x2 - 1, y1 + 1); SetAPen(rp, _pens(obj)[MPEN_SHADOW]); Move(rp, x2, y1 + 2); Draw(rp, x2, y2 - 2); Draw(rp, x2 - 2, y2); Draw(rp, x1 + 2, y2); SetAPen(rp, _pens(obj)[MPEN_HALFSHINE]); Move(rp, x1 + 1, y2 - 2); Draw(rp, x1 + 1, y1 + 2); Draw(rp, x1 + 2, y1 + 1); Draw(rp, x2 - 2, y1 + 1); SetAPen(rp, _pens(obj)[MPEN_HALFSHADOW]); Move(rp, x2 - 1, y1 + 2); Draw(rp, x2 - 1, y2 - 2); Draw(rp, x2 - 2, y2 - 1); Draw(rp, x1 + 2, y2 - 1); /* Border */ x1 += OUTERFRAME_X; x2 -= OUTERFRAME_X; y1 += OUTERFRAME_X; y2 -= OUTERFRAME_Y; SetAPen(rp, _pens(obj)[MPEN_HALFSHINE]); RectFill(rp, x1, y1, x2, y1 + BORDERSIZE_Y - 1); RectFill(rp, x1, y1 + BORDERSIZE_Y, x1 + BORDERSIZE_X - 1, y2); RectFill(rp, x1 + BORDERSIZE_X - 1, y2 - BORDERSIZE_Y + 1, x2, y2); RectFill(rp, x2 - BORDERSIZE_X + 1, y1 + BORDERSIZE_Y, x2, y2 - BORDERSIZE_Y); /* Inner Frame */ x1 += BORDERSIZE_X; x2 -= BORDERSIZE_X; y1 += BORDERSIZE_Y; y2 = y1 + LEVEL_HEIGHT + INNERFRAME_H - 1; Move(rp, x1, y1); Draw(rp, x1 + 2, y1); Draw(rp, x1, y1 + 2); Draw(rp, x1, y1 + 1); Move(rp, x2, y1); Draw(rp, x2 - 2, y1); Draw(rp, x2, y1 + 2); Draw(rp, x2, y1 + 1); Move(rp, x1, y2); Draw(rp, x1 + 2, y2); Draw(rp, x1, y2 - 2); Draw(rp, x1, y2 - 1); Move(rp, x2, y2); Draw(rp, x2 - 2, y2); Draw(rp, x2, y2 - 2); Draw(rp, x2, y2 - 1); SetAPen(rp, _pens(obj)[MPEN_HALFSHADOW]); Move(rp, x1 + 2, y2 - 1); Draw(rp, x1, y2 - 3); Draw(rp, x1, y1 + 3); Draw(rp, x1 + 3, y1); Draw(rp, x2 - 3, y1); Draw(rp, x2 - 1, y1 + 2); SetAPen(rp, _pens(obj)[MPEN_SHINE]); Move(rp, x2, y1 + 3); Draw(rp, x2, y2 - 3); Draw(rp, x2 - 3, y2); Draw(rp, x1 + 3, y2); SetAPen(rp, _pens(obj)[MPEN_SHADOW]); Move(rp, x1 + 3, y1 + 1); Draw(rp, x2 - 3, y1 + 1); Move(rp, x1 + 1, y1 + 3); Draw(rp, x1 + 1, y2 - 3); Move(rp, x1 + 3, y2 - 1); Draw(rp, x2 - 3, y2 - 1); Move(rp, x2 - 1, y1 + 3), Draw(rp, x2 - 1, y2 - 3); /* Levelmeter bg */ x1 += INNERFRAME_X; x2 -= INNERFRAME_X; y1 += INNERFRAME_Y; y2 -= INNERFRAME_Y; SetAPen(rp, data->levelbgpen); RectFill(rp, x1 + 1, y1, x2 - 1, y1); RectFill(rp, x1, y1 + 1, x2, y2 - 1); RectFill(rp, x1 + 1, y2, x2 - 1, y2); SetAPen(rp, _pens(obj)[MPEN_SHADOW]); WritePixel(rp, x1, y1); WritePixel(rp, x2, y1); WritePixel(rp, x1, y2); WritePixel(rp, x2, y2); /* Levelmeter scale */ DrawScale(rp, x1, y1, x2, y2, _pens(obj)[MPEN_SHINE]); /* Level-Label spacing */ x1 -= INNERFRAME_X; x2 += INNERFRAME_X; y1 = y2 + INNERFRAME_Y + 1; SetAPen(rp, _pens(obj)[MPEN_HALFSHINE]); RectFill(rp, x1, y1, x2, y1 + LEVEL_LABEL_SPACING - 1); /* Label Frame */ y1 += LEVEL_LABEL_SPACING; y2 = _mbottom(obj) - OUTERFRAME_Y - BORDERSIZE_Y; SetAPen(rp, _pens(obj)[MPEN_HALFSHINE]); Move(rp, x1, y1); Draw(rp, x1 + 1, y1); Draw(rp, x1, y1 + 1); Move(rp, x2, y1); Draw(rp, x2 - 1, y1); Draw(rp, x2, y1 + 1); Move(rp, x1, y2); Draw(rp, x1 + 1, y2); Draw(rp, x1, y2 - 1); Move(rp, x2, y2); Draw(rp, x2 - 1, y2); Draw(rp, x2, y2 - 1); SetAPen(rp, _pens(obj)[MPEN_HALFSHADOW]); Move(rp, x1 + 1, y2 - 1); Draw(rp, x1, y2 - 2); Draw(rp, x1, y1 + 2); Draw(rp, x1 + 2, y1); Draw(rp, x2 - 2, y1); Draw(rp, x2 - 1, y1 + 1); SetAPen(rp, _pens(obj)[MPEN_SHINE]); Move(rp, x2, y1 + 2); Draw(rp, x2, y2 - 2); Draw(rp, x2 - 2, y2); Draw(rp, x1 + 2, y2); SetAPen(rp, _pens(obj)[MPEN_SHADOW]); RectFill(rp, x1 + 1, y1 + 2, x1 + 1, y2 - 2); RectFill(rp, x2 - 1, y1 + 2, x2 - 1, y2 - 2); RectFill(rp, x1 + 2, y1 + 1, x2 - 2, y1 + 1); RectFill(rp, x1 + 2, y2 - 1, x2 - 2, y2 - 1); /* Label Bg */ RectFill(rp, x1 + 2, y1 +2, x2 - 2, y2 - 2); } x1 = _mleft(obj) + OUTERFRAME_X + BORDERSIZE_X + INNERFRAME_X; x2 = _mright(obj) - OUTERFRAME_X - BORDERSIZE_X - INNERFRAME_X; y1 = _mtop(obj) + OUTERFRAME_Y + BORDERSIZE_Y + INNERFRAME_Y; y2 = y1 + LEVEL_HEIGHT - 1; if (msg->flags & MADF_DRAWUPDATE) { DrawNeedle(rp, x1, y1, x2, y2, data->prevangle, data->levelbgpen); } data->prevangle = (double)DoMethod(obj, MUIM_Numeric_ValueToScale, 0, 180); DrawNeedle(rp, x1, y1, x2, y2, data->prevangle, _pens(obj)[MPEN_SHINE]); return TRUE; }
/********************************************************************* * Function: void PutImage1BPP(SHORT left, SHORT top, FLASH_BYTE* image, BYTE stretch) * * PreCondition: none * * Input: left,top - left top image corner, * image - image pointer, * stretch - image stretch factor * * Output: none * * Side Effects: none * * Overview: outputs monochrome image starting from left,top coordinates * * Note: image must be located in flash * ********************************************************************/ void PutImage1BPP(SHORT left, SHORT top, FLASH_BYTE *image, BYTE stretch) { register DWORD address; register FLASH_BYTE *flashAddress; register FLASH_BYTE *tempFlashAddress; BYTE temp = 0; WORD sizeX, sizeY; WORD x, y; BYTE stretchX, stretchY; WORD pallete[2]; BYTE mask; #if (DISP_ORIENTATION == 90) top = GetMaxY() - top; #endif // Move pointer to size information flashAddress = image + 2; // Set start address #if (DISP_ORIENTATION == 0) address = (long)LINE_MEM_PITCH * top + left; #else address = (long)LINE_MEM_PITCH * left + top; #endif // Read image size sizeY = *((FLASH_WORD *)flashAddress); flashAddress += 2; sizeX = *((FLASH_WORD *)flashAddress); flashAddress += 2; pallete[0] = *((FLASH_WORD *)flashAddress); flashAddress += 2; pallete[1] = *((FLASH_WORD *)flashAddress); flashAddress += 2; DisplayEnable(); for(y = 0; y < sizeY; y++) { tempFlashAddress = flashAddress; for(stretchY = 0; stretchY < stretch; stretchY++) { flashAddress = tempFlashAddress; SetAddress(address); mask = 0; for(x = 0; x < sizeX; x++) { // Read 8 pixels from flash if(mask == 0) { temp = *flashAddress; flashAddress++; mask = 0x80; } // Set color if(mask & temp) { SetColor(pallete[1]); } else { SetColor(pallete[0]); } // Write pixel to screen for(stretchX = 0; stretchX < stretch; stretchX++) { WritePixel(_color); } // Shift to the next pixel mask >>= 1; } #if (DISP_ORIENTATION == 0) address += LINE_MEM_PITCH; #else address -= 1; #endif } } DisplayDisable(); }
/********************************************************************* * Function: void PutImage4BPP(SHORT left, SHORT top, FLASH_BYTE* image, BYTE stretch) * * PreCondition: none * * Input: left,top - left top image corner, image - image pointer, * stretch - image stretch factor * * Output: none * * Side Effects: none * * Overview: outputs 16 color image starting from left,top coordinates * * Note: image must be located in flash * ********************************************************************/ void PutImage4BPP(SHORT left, SHORT top, FLASH_BYTE *image, BYTE stretch) { register DWORD address; register FLASH_BYTE *flashAddress; register FLASH_BYTE *tempFlashAddress; WORD sizeX, sizeY; register WORD x, y; BYTE temp = 0; register BYTE stretchX, stretchY; WORD pallete[16]; WORD counter; #if (DISP_ORIENTATION == 90) top = GetMaxY() - top; #endif // Move pointer to size information flashAddress = image + 2; // Set start address #if (DISP_ORIENTATION == 0) address = (long)LINE_MEM_PITCH * top + left; #else address = (long)LINE_MEM_PITCH * left + top; #endif // Read image size sizeY = *((FLASH_WORD *)flashAddress); flashAddress += 2; sizeX = *((FLASH_WORD *)flashAddress); flashAddress += 2; // Read pallete for(counter = 0; counter < 16; counter++) { pallete[counter] = *((FLASH_WORD *)flashAddress); flashAddress += 2; } DisplayEnable(); for(y = 0; y < sizeY; y++) { tempFlashAddress = flashAddress; for(stretchY = 0; stretchY < stretch; stretchY++) { flashAddress = tempFlashAddress; SetAddress(address); for(x = 0; x < sizeX; x++) { // Read 2 pixels from flash if(x & 0x0001) { // second pixel in byte SetColor(pallete[temp >> 4]); } else { temp = *flashAddress; flashAddress++; // first pixel in byte SetColor(pallete[temp & 0x0f]); } // Write pixel to screen for(stretchX = 0; stretchX < stretch; stretchX++) { WritePixel(_color); } // Shift to the next pixel //temp >>= 4; } #if (DISP_ORIENTATION == 0) address += LINE_MEM_PITCH; #else address -= 1; #endif }
void GSDrawScanlineCodeGenerator::WriteFrame() { if(!m_sel.fwrite) { return; } if(m_sel.colclamp == 0) { // c[0] &= 0x00ff00ff; // c[1] &= 0x00ff00ff; vpcmpeqd(xmm15, xmm15); vpsrlw(xmm15, 8); vpand(xmm2, xmm15); vpand(xmm3, xmm15); } if(m_sel.fpsm == 2 && m_sel.dthe) { mov(rax, r8); and(rax, 3); shl(rax, 5); vpaddw(xmm2, ptr[r12 + rax + offsetof(GSScanlineGlobalData, dimx[0])]); vpaddw(xmm3, ptr[r12 + rax + offsetof(GSScanlineGlobalData, dimx[1])]); } // GSVector4i fs = c[0].upl16(c[1]).pu16(c[0].uph16(c[1])); vpunpckhwd(xmm15, xmm2, xmm3); vpunpcklwd(xmm2, xmm3); vpackuswb(xmm2, xmm15); if(m_sel.fba && m_sel.fpsm != 1) { // fs |= 0x80000000; vpcmpeqd(xmm15, xmm15); vpslld(xmm15, 31); vpor(xmm2, xmm15); } // xmm2 = fs // xmm4 = fm // xmm6 = fd if(m_sel.fpsm == 2) { // GSVector4i rb = fs & 0x00f800f8; // GSVector4i ga = fs & 0x8000f800; mov(eax, 0x00f800f8); vmovd(xmm0, eax); vpshufd(xmm0, xmm0, _MM_SHUFFLE(0, 0, 0, 0)); mov(eax, 0x8000f800); vmovd(xmm1, eax); vpshufd(xmm1, xmm1, _MM_SHUFFLE(0, 0, 0, 0)); vpand(xmm0, xmm2); vpand(xmm1, xmm2); // fs = (ga >> 16) | (rb >> 9) | (ga >> 6) | (rb >> 3); vpsrld(xmm2, xmm0, 9); vpsrld(xmm0, 3); vpsrld(xmm3, xmm1, 16); vpsrld(xmm1, 6); vpor(xmm0, xmm1); vpor(xmm2, xmm3); vpor(xmm2, xmm0); } if(m_sel.rfb) { // fs = fs.blend(fd, fm); blend(xmm2, xmm6, xmm4); // TODO: could be skipped in certain cases, depending on fpsm and fm } bool fast = m_sel.rfb && m_sel.fpsm < 2; WritePixel(xmm2, rbx, dl, fast, m_sel.fpsm, 0); }
/************************************************************************** Render one item **************************************************************************/ static void RenderRegisterTabItem(struct IClass *cl, Object *obj, WORD item) { struct Register_DATA *data = INST_DATA(cl, obj); struct RegisterTabItem *ri = &data->items[item]; struct TextExtent extent; WORD fitlen; /* text len fitting in alloted space */ WORD fitpix; /* text pixels fitting in alloted space */ WORD x, y; WORD top_item_bar_y; WORD bottom_item_bar_y; WORD left_item_bar_x; WORD right_item_bar_x; WORD item_bar_width; WORD text_y; WORD item_bg_height; WORD fitwidth; if ((item < 0) || (item >= data->numitems)) return; y = data->top + ri->y1; if (data->active == item) { top_item_bar_y = _top(obj) + ri->y1; bottom_item_bar_y = _top(obj) + ri->y2 - 2; left_item_bar_x = _left(obj) + ri->x1 - 1; right_item_bar_x = _left(obj) + ri->x2 + 1; item_bg_height = data->tab_height; text_y = y + data->ty; item_bar_width = right_item_bar_x - left_item_bar_x + 1; /* fill tab with register background */ DoMethod(obj,MUIM_DrawBackground, left_item_bar_x, top_item_bar_y + 4, item_bar_width, item_bg_height - 4, left_item_bar_x, top_item_bar_y + 4, 0); DoMethod(obj,MUIM_DrawBackground, left_item_bar_x + 2, top_item_bar_y + 2, item_bar_width - (2 * 2), 2, left_item_bar_x + 2, top_item_bar_y + 2, 0); DoMethod(obj,MUIM_DrawBackground, left_item_bar_x + 4, top_item_bar_y + 1, item_bar_width - (2 * 4), 1, left_item_bar_x + 4, top_item_bar_y + 1, 0); } else { top_item_bar_y = _top(obj) + ri->y1 + 2; bottom_item_bar_y = _top(obj) + ri->y2 - 1; left_item_bar_x = _left(obj) + ri->x1; right_item_bar_x = _left(obj) + ri->x2; item_bg_height = data->tab_height - 3; text_y = y + data->ty + 1; item_bar_width = right_item_bar_x - left_item_bar_x + 1; SetAPen(_rp(obj), _pens(obj)[MPEN_BACKGROUND]); RectFill(_rp(obj), left_item_bar_x, top_item_bar_y + 4, right_item_bar_x, bottom_item_bar_y); RectFill(_rp(obj), left_item_bar_x + 2, top_item_bar_y + 2, right_item_bar_x - 2, top_item_bar_y + 3); RectFill(_rp(obj), left_item_bar_x + 4, top_item_bar_y + 1, right_item_bar_x - 4, top_item_bar_y + 1); } /* top horiz bar */ SetAPen(_rp(obj), _pens(obj)[MPEN_SHINE]); RectFill(_rp(obj), left_item_bar_x + 4, top_item_bar_y, right_item_bar_x - 4, top_item_bar_y); /* left vert bar */ RectFill(_rp(obj), left_item_bar_x, top_item_bar_y + 4, left_item_bar_x, bottom_item_bar_y); WritePixel(_rp(obj), left_item_bar_x + 1, top_item_bar_y + 3); WritePixel(_rp(obj), left_item_bar_x + 1, top_item_bar_y + 2); WritePixel(_rp(obj), left_item_bar_x + 2, top_item_bar_y + 1); WritePixel(_rp(obj), left_item_bar_x + 3, top_item_bar_y + 1); SetAPen(_rp(obj), _pens(obj)[MPEN_HALFSHINE]); WritePixel(_rp(obj), left_item_bar_x + 3, top_item_bar_y); WritePixel(_rp(obj), left_item_bar_x + 4, top_item_bar_y + 1); WritePixel(_rp(obj), left_item_bar_x + 2, top_item_bar_y + 2); WritePixel(_rp(obj), left_item_bar_x + 3, top_item_bar_y + 2); WritePixel(_rp(obj), left_item_bar_x + 2, top_item_bar_y + 3); WritePixel(_rp(obj), left_item_bar_x, top_item_bar_y + 3); WritePixel(_rp(obj), left_item_bar_x + 1, top_item_bar_y + 4); if (data->active == item) { /* bottom horiz bar */ SetAPen(_rp(obj), _pens(obj)[MPEN_SHINE]); WritePixel(_rp(obj), left_item_bar_x - 1, bottom_item_bar_y + 1); SetAPen(_rp(obj), _pens(obj)[MPEN_SHADOW]); WritePixel(_rp(obj), right_item_bar_x + 1, bottom_item_bar_y + 1); DoMethod(obj,MUIM_DrawBackground, left_item_bar_x - 1, bottom_item_bar_y + 2, item_bar_width + (2 * 1), 1, left_item_bar_x - 1, bottom_item_bar_y + 2, 0); } /* right vert bar */ SetAPen(_rp(obj), _pens(obj)[MPEN_SHADOW]); WritePixel(_rp(obj), right_item_bar_x - 1, top_item_bar_y + 2); RectFill(_rp(obj), right_item_bar_x, top_item_bar_y + 4, right_item_bar_x, bottom_item_bar_y); SetAPen(_rp(obj), _pens(obj)[MPEN_HALFSHADOW]); WritePixel(_rp(obj), right_item_bar_x - 2, top_item_bar_y + 1); WritePixel(_rp(obj), right_item_bar_x - 1, top_item_bar_y + 3); WritePixel(_rp(obj), right_item_bar_x, top_item_bar_y + 3); SetAPen(_rp(obj), _pens(obj)[MPEN_BACKGROUND]); WritePixel(_rp(obj), right_item_bar_x - 3, top_item_bar_y + 1); /* text */ fitwidth = item_bar_width - TEXTSPACING; fitlen = TextFit(_rp(obj), ri->text, ri->textlen, &extent, NULL, 1, fitwidth, data->tab_height); fitpix = extent.te_Width; /* D(bug("extent for %s (len=%d) in %d pix = %d chars, %d pix [%x,%x,%x]\n", */ /* ri->text, ri->textlen, fitwidth, fitlen, fitpix, _rp(obj), _rp(obj)->Font, _font(obj))); */ x = left_item_bar_x + (item_bar_width - fitpix) / 2; SetDrMd(_rp(obj), JAM1); SetAPen(_rp(obj), _pens(obj)[MPEN_TEXT]); Move(_rp(obj), x, text_y); Text(_rp(obj), ri->text, fitlen); }
/********************************************************************* * Function: void PutImage1BPP(SHORT left, SHORT top, FLASH_BYTE* bitmap, BYTE stretch) * * PreCondition: none * * Input: left,top - left top image corner, * bitmap - image pointer, * stretch - image stretch factor * * Output: none * * Side Effects: none * * Overview: outputs monochrome image starting from left,top coordinates * * Note: image must be located in flash * ********************************************************************/ void PutImage1BPP(SHORT left, SHORT top, FLASH_BYTE *bitmap, BYTE stretch) { register FLASH_BYTE *flashAddress; register FLASH_BYTE *tempFlashAddress; BYTE temp; WORD sizeX, sizeY; WORD x, y; BYTE stretchX, stretchY; WORD pallete[2]; BYTE mask; // Move pointer to size information flashAddress = bitmap + 2; // Read image size sizeY = *((FLASH_WORD *)flashAddress); flashAddress += 2; sizeX = *((FLASH_WORD *)flashAddress); flashAddress += 2; pallete[0] = *((FLASH_WORD *)flashAddress); flashAddress += 2; pallete[1] = *((FLASH_WORD *)flashAddress); flashAddress += 2; DeviceSelect; for(y = 0; y < sizeY; y++) { tempFlashAddress = flashAddress; for(stretchY = 0; stretchY < stretch; stretchY++) { flashAddress = tempFlashAddress; SetAddress((WORD) left, (WORD) top); mask = 0; for(x = 0; x < sizeX; x++) { // Read 8 pixels from flash if(mask == 0) { temp = *flashAddress; flashAddress++; mask = 0x80; } // Set color if(mask & temp) { SetColor(pallete[1]); } else { SetColor(pallete[0]); } // Write pixel to screen for(stretchX = 0; stretchX < stretch; stretchX++) { WritePixel(_color); } // Shift to the next pixel mask >>= 1; } top++; } } DeviceDeselect; }
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdLine, int nCmdShow) { char buff[256 + _MAX_PATH]; TGAHeaderInfo TGAHeader; FILE *finput, *foutput; DWORD bytesRead; int x, y; unsigned char *descBytes; pixel pix, *srcImage, *dstImage; float dX, dY, nX, nY, nZ, oolen; // Loop until the user cancels the open dialog while (TRUE) { // Either take the input and output filename from the command line // or grab it from the user. char inFilename[_MAX_PATH]; inFilename[0] = '\0'; char outFilename[_MAX_PATH]; if (!GetFileName (NULL, inFilename)) { return 0; } strcpy (outFilename, inFilename); char *dot = strrchr (outFilename, '.'); if (dot == NULL) { strcat (outFilename, "DOT3.tga"); } else { strcpy (dot, "DOT3.tga"); } //Put filename in here if ((finput = fopen (inFilename, "rb")) == NULL) { sprintf (buff, "Unable to open input TGA file: %s", inFilename); MessageBox (NULL, buff, "Error", MB_OK | MB_ICONERROR); continue; } // Open output file if ((foutput = fopen (outFilename, "wb")) == NULL) { sprintf (buff, "Unable to open output TGA file: %s", inFilename); MessageBox (NULL, buff, "Error", MB_OK | MB_ICONERROR); continue; } //Read TARGA header. if ((bytesRead = fread (&TGAHeader, sizeof (unsigned char), sizeof (TGAHeader), finput)) != sizeof (TGAHeader)) { MessageBox (NULL, "Bad Targa header", "Error", MB_OK | MB_ICONERROR); continue; } //Write to output file TARGA header if ((bytesRead = fwrite (&TGAHeader, sizeof (unsigned char), sizeof (TGAHeader), foutput)) != sizeof (TGAHeader)) { MessageBox (NULL, "Bad Targa header writing out", "Error", MB_OK | MB_ICONERROR); continue; } descBytes = (unsigned char *) malloc (sizeof (unsigned char) * TGAHeader.idlen); if (descBytes == NULL) { MessageBox (NULL, "Unable to allocate enough memory.", "Error", MB_OK | MB_ICONERROR); continue; } // Steal descriptive bytes at end of header if ((bytesRead = fread (descBytes, sizeof (unsigned char), TGAHeader.idlen, finput)) != TGAHeader.idlen) { MessageBox (NULL, "Couldn't seek past Targa header", "Error", MB_OK | MB_ICONERROR); continue; } if ((bytesRead = fwrite (descBytes, sizeof (unsigned char), TGAHeader.idlen, foutput)) != TGAHeader.idlen) { MessageBox (NULL, "Bad Targa descriptive data writing out", "Error", MB_OK | MB_ICONERROR); continue; } gWidth = TGAHeader.imwidth; gHeight = TGAHeader.imheight; // allocate storage srcImage = (pixel *) malloc (sizeof (pixel) * gHeight * gWidth); dstImage = (pixel *) malloc (sizeof (pixel) * gHeight * gWidth); if ((srcImage == NULL) || (dstImage == NULL)) { MessageBox (NULL, "Unable to allocate enough memory.", "Error", MB_OK | MB_ICONERROR); continue; } for (y = 0; y < gHeight; y++) { for (x = 0; x < gWidth; x++) { fread(&pix.blue, sizeof(BYTE), 1, finput); fread(&pix.green, sizeof(BYTE), 1, finput); fread(&pix.red, sizeof(BYTE), 1, finput); if (TGAHeader.imdepth == 32) fread(&pix.alpha, sizeof(BYTE), 1, finput); else pix.alpha = 0xcc; WritePixel(srcImage, &pix, x, y); } } for(y = 0; y < gHeight; y++) { for(x = 0; x < gWidth; x++) { // Do Y Sobel filter ReadPixel(srcImage, &pix, (x-1+gWidth) % gWidth, (y+1) % gHeight); dY = ((float) pix.red) / 255.0f * -1.0f; ReadPixel(srcImage, &pix, x % gWidth, (y+1) % gHeight); dY += ((float) pix.red) / 255.0f * -2.0f; ReadPixel(srcImage, &pix, (x+1) % gWidth, (y+1) % gHeight); dY += ((float) pix.red) / 255.0f * -1.0f; ReadPixel(srcImage, &pix, (x-1+gWidth) % gWidth, (y-1+gHeight) % gHeight); dY += ((float) pix.red) / 255.0f * 1.0f; ReadPixel(srcImage, &pix, x % gWidth, (y-1+gHeight) % gHeight); dY += ((float) pix.red) / 255.0f * 2.0f; ReadPixel(srcImage, &pix, (x+1) % gWidth, (y-1+gHeight) % gHeight); dY += ((float) pix.red) / 255.0f * 1.0f; // Do X Sobel filter ReadPixel(srcImage, &pix, (x-1+gWidth) % gWidth, (y-1+gHeight) % gHeight); dX = ((float) pix.red) / 255.0f * -1.0f; ReadPixel(srcImage, &pix, (x-1+gWidth) % gWidth, y % gHeight); dX += ((float) pix.red) / 255.0f * -2.0f; ReadPixel(srcImage, &pix, (x-1+gWidth) % gWidth, (y+1) % gHeight); dX += ((float) pix.red) / 255.0f * -1.0f; ReadPixel(srcImage, &pix, (x+1) % gWidth, (y-1+gHeight) % gHeight); dX += ((float) pix.red) / 255.0f * 1.0f; ReadPixel(srcImage, &pix, (x+1) % gWidth, y % gHeight); dX += ((float) pix.red) / 255.0f * 2.0f; ReadPixel(srcImage, &pix, (x+1) % gWidth, (y+1) % gHeight); dX += ((float) pix.red) / 255.0f * 1.0f; // Cross Product of components of gradient reduces to nX = -dX; nY = -dY; nZ = 1; // Normalize oolen = 1.0f/((float) sqrt(nX*nX + nY*nY + nZ*nZ)); nX *= oolen; nY *= oolen; nZ *= oolen; pix.red = (BYTE) PackFloatInByte(nX); pix.green = (BYTE) PackFloatInByte(nY); pix.blue = (BYTE) PackFloatInByte(nZ); WritePixel(dstImage, &pix, x, y); } } for(y = 0; y < gHeight; y++) { for(x = 0; x < gWidth; x++) { ReadPixel(dstImage, &pix, x, y); fwrite(&pix.blue, sizeof(BYTE), 1, foutput); fwrite(&pix.green, sizeof(BYTE), 1, foutput); fwrite(&pix.red, sizeof(BYTE), 1, foutput); if(TGAHeader.imdepth == 32) fwrite(&pix.alpha, sizeof(BYTE), 1, foutput); } } free(srcImage); free(dstImage); free(descBytes); fclose(finput); // close the input file fclose(foutput); // close the output file sprintf (buff, "Success! New TGA file: %s", outFilename); MessageBox (NULL, buff, "Success", MB_OK); } return(0); }
/********************************************************************* * Function: void PutImage4BPP(SHORT left, SHORT top, FLASH_BYTE* image, BYTE stretch, PUTIMAGE_PARAM *pPartialImageData) * * PreCondition: none * * Input: left,top - left top image corner, * image - image pointer, * stretch - image stretch factor * pPartialImageData - (currently not implemented in this driver) * * Output: none * * Side Effects: none * * Overview: outputs 16 color image starting from left,top coordinates * * Note: image must be located in flash * ********************************************************************/ void PutImage4BPP(SHORT left, SHORT top, FLASH_BYTE *image, BYTE stretch, PUTIMAGE_PARAM *pPartialImageData) { register FLASH_BYTE *flashAddress; register FLASH_BYTE *tempFlashAddress; WORD sizeX, sizeY; register WORD x, y, currentXLocation; BYTE temp = 0; register BYTE stretchX, stretchY; WORD pallete[16]; WORD counter; // Move pointer to size information flashAddress = image + 2; // Read image size sizeY = *((FLASH_WORD *)flashAddress); flashAddress += 2; sizeX = *((FLASH_WORD *)flashAddress); flashAddress += 2; // Read pallete for(counter = 0; counter < 16; counter++) { pallete[counter] = *((FLASH_WORD *)flashAddress); flashAddress += 2; } DisplayEnable(); for(y = 0; y < sizeY; y++) { tempFlashAddress = flashAddress; for(stretchY = 0; stretchY < stretch; stretchY++) { flashAddress = tempFlashAddress; SetAddress(left, top); for(x = 0, currentXLocation = 0; x < sizeX; x++) { // Read 2 pixels from flash if(x & 0x0001) { // second pixel in byte SetColor(pallete[temp >> 4]); } else { temp = *flashAddress; flashAddress++; // first pixel in byte SetColor(pallete[temp & 0x0f]); } // Write pixel to screen for(stretchX = 0; stretchX < stretch; stretchX++) { #ifdef USE_TRANSPARENT_COLOR if (((GetTransparentColor() == GetColor()) && (GetTransparentColorStatus() == TRANSPARENT_COLOR_ENABLE))) { currentXLocation++; SetAddress(left + currentXLocation, top); } else #endif { WritePixel(_color); currentXLocation++; } } } top++; }
// Fills a polygon using a texture and gouraud shading given 3 points and a color. void Rasterizer::FillPolygonTextured(Vertex v1, Vertex v2, Vertex v3, Gdiplus::Color color, Model3D& model) { ScanLine* _scanlines = new ScanLine[_height]; BYTE* texture; Gdiplus::Color* palette; int textureWidth; // Get the texture properties of the model. model.GetTexture(&texture, &palette, &textureWidth); // Set the scanlines to very high and very low values so // they will be set on the first set of interpolation. for (unsigned int i = 0; i < _height; i++) { _scanlines[i].xStart = 99999; _scanlines[i].xEnd = -99999; } // Interpolates between each of the vertexs of the polygon and sets the start // and end values for each of the scanlines it comes in contact with. InterpolateScanline(_scanlines, v1, v2); InterpolateScanline(_scanlines, v2, v3); InterpolateScanline(_scanlines, v3, v1); // Go through each scanline and each pixel in the scanline and // sets its color. for (unsigned int y = 0; y < _height; y++) { // Work out the color and UV differences between the start and end of the scanline. float redColorDiff = (_scanlines[y].redEnd - _scanlines[y].redStart); float greenColorDiff = (_scanlines[y].greenEnd - _scanlines[y].greenStart); float blueColorDiff = (_scanlines[y].blueEnd - _scanlines[y].blueStart); float uCoordDiff = _scanlines[y].uEnd - _scanlines[y].uStart; float vCoordDiff = _scanlines[y].vEnd - _scanlines[y].vStart; float zCoordDiff = _scanlines[y].zEnd - _scanlines[y].zStart; float diff = (_scanlines[y].xEnd - _scanlines[y].xStart) + 1; for (int x = (int)_scanlines[y].xStart; x <= (int)_scanlines[y].xEnd; x++) { if (x < 0 || x >= (int)_width) continue; int offset = (int)(x - _scanlines[y].xStart); // Work out the UV coordinate of the current pixel. float uCoord = _scanlines[y].uStart + ((uCoordDiff / diff) * offset); float vCoord = _scanlines[y].vStart + ((vCoordDiff / diff) * offset); float zCoord = _scanlines[y].zStart + ((zCoordDiff / diff) * offset); uCoord /= zCoord; vCoord /= zCoord; // Work out the lighting colour of the current pixel. float lightR = (_scanlines[y].redStart + ((redColorDiff / diff) * offset)) / 180.0f; float lightG = (_scanlines[y].greenStart + ((greenColorDiff / diff) * offset)) / 180.0f; float lightB = (_scanlines[y].blueStart + ((blueColorDiff / diff) * offset)) / 180.0f; // Using the UV coordinate work out which pixel in the texture to use to draw this pixel. int pixelIndex = (int)vCoord * textureWidth + (int)uCoord; if (pixelIndex >= textureWidth * textureWidth || pixelIndex < 0) { pixelIndex = (textureWidth * textureWidth) - 1; } int paletteOffset = texture[pixelIndex]; if (paletteOffset >= 255) paletteOffset = 255; Gdiplus::Color textureColor = palette[paletteOffset]; // Apply the lighting value to the texture colour and use the result to set the colour of the current pixel. int finalR = (int)max(0, min(255, textureColor.GetR() * lightR)); int finalG = (int)max(0, min(255, textureColor.GetG() * lightG)); int finalB = (int)max(0, min(255, textureColor.GetB() * lightB)); WritePixel(x, y, Gdiplus::Color(finalR, finalG, finalB)); } } // Dispose of dynamic objects. delete[] _scanlines; _polygonsRendered++; }
LONG Blank( PrefObject *Prefs ) { LONG ToFrontCount = 0, Wid, Hei, i, x, y, Stars, Speed, RetVal = OK; struct RastPort *Rast; struct Screen *Scr; struct Window *Wnd; Coord3D *p; Coord2D *p2; Stars = Prefs[0].po_Level; Speed = Prefs[2].po_Level; Coords = AllocVec( Stars * sizeof( Coord3D ), MEMF_CLEAR ); OldCoords = AllocVec( Stars * sizeof( Coord2D ), MEMF_CLEAR ); Scr = OpenScreenTags( 0L, SA_Depth, 2, SA_Overscan, OSCAN_STANDARD, SA_DisplayID, Prefs[4].po_ModeID, SA_Behind, TRUE, SA_Quiet, TRUE, SA_ShowTitle, FALSE, SA_Title, "Garshnescreen", TAG_DONE ); if( Coords && OldCoords && Scr ) { Wid = Scr->Width; Hei = Scr->Height; Rast = &( Scr->RastPort ); SetRast( Rast, 0 ); for( i = 0; i < 4; i++ ) SetRGB4(&( Scr->ViewPort ), i, 4 * i, 4 * i, 4 * i ); for( i = 0; i < Stars; i++ ) { InitStar( &Coords[i], Speed ); OldCoords[i].x = 0; OldCoords[i].y = 0; } Wnd = BlankMousePointer( Scr ); ScreenToFront( Scr ); while( RetVal == OK ) { WaitTOF(); if(!( ++ToFrontCount % 60 )) ScreenToFront( Scr ); for( p2 = OldCoords, p = Coords, i = 0; i < Stars; i++, p++, p2++ ) { x = p2->x; y = p2->y; SetAPen( Rast, 0 ); switch( p->z / 200 ) { case 0: WritePixel( Rast, x, y+1 ); WritePixel( Rast, x+1, y+1 ); case 1: case 2: case 3: case 4: WritePixel( Rast, x+1, y ); default: WritePixel( Rast, x, y ); } p->z -= p->speed; if( p->z <= -1000 ) InitStar( p, Speed ); x = Wid/2 + ( 200 * p->x ) / ( p->z + 1000 ); y = Hei/2 + ( 200 * p->y ) / ( p->z + 1000 ); if(( x < 0 )||( x > Wid-2 )||( y < 0 )||( y > Hei-2 )) { InitStar( p, Speed ); p2->x = 0; p2->y = 0; } else { p2->x = x; p2->y = y; SetAPen( Rast, 3 ); /* Warning: This is a little twisted. */ switch( p->z/200 ) { case 9: case 8: SetAPen( Rast, 2 ); break; case 0: WritePixel( Rast, x, y+1 ); WritePixel( Rast, x+1, y+1 ); case 4: case 3: case 2: case 1: WritePixel( Rast, x+1, y ); case 7: case 6: case 5: break; default: SetAPen( Rast, 1 ); break; } WritePixel( Rast, x, y ); } } if(!( ToFrontCount % 5 )) RetVal = ContinueBlanking(); } UnblankMousePointer( Wnd ); } else RetVal = FAILED; if( Scr ) CloseScreen( Scr ); if( Coords ) FreeVec( Coords ); if( OldCoords ) FreeVec( OldCoords ); return RetVal; }
/********************************************************************* * Function: void PutImage1BPP(SHORT left, SHORT top, FLASH_BYTE* image, BYTE stretch, PUTIMAGE_PARAM *pPartialImageData) * * PreCondition: none * * Input: left,top - left top image corner, * image - image pointer, * stretch - image stretch factor * pPartialImageData - (currently not implemented in this driver) * * Output: none * * Side Effects: none * * Overview: outputs monochrome image starting from left,top coordinates * * Note: image must be located in flash * ********************************************************************/ void PutImage1BPP(SHORT left, SHORT top, FLASH_BYTE *image, BYTE stretch, PUTIMAGE_PARAM *pPartialImageData) { register FLASH_BYTE *flashAddress; register FLASH_BYTE *tempFlashAddress; BYTE temp = 0; WORD sizeX, sizeY; WORD x, y; BYTE stretchX, stretchY; WORD pallete[2]; BYTE mask; // Move pointer to size information flashAddress = image + 2; // Read image size sizeY = *((FLASH_WORD *)flashAddress); flashAddress += 2; sizeX = *((FLASH_WORD *)flashAddress); flashAddress += 2; pallete[0] = *((FLASH_WORD *)flashAddress); flashAddress += 2; pallete[1] = *((FLASH_WORD *)flashAddress); flashAddress += 2; DisplayEnable(); for(y = 0; y < sizeY; y++) { tempFlashAddress = flashAddress; for(stretchY = 0; stretchY < stretch; stretchY++) { flashAddress = tempFlashAddress; SetAddress(left, top); mask = 0; for(x = 0; x < sizeX; x++) { // Read 8 pixels from flash if(mask == 0) { temp = *flashAddress; flashAddress++; mask = 0x01; } // Set color if(mask & temp) { SetColor(pallete[1]); } else { SetColor(pallete[0]); } // Write pixel to screen for(stretchX = 0; stretchX < stretch; stretchX++) { WritePixel(_color); } // Shift to the next pixel mask <<= 1; } top++; } } DisplayDisable(); }
/** * Initialize the display controller. */ void OSD0201QILK::Enable() { ChipSelect(true); Reset(false); SystemControl::Sleep(500); Reset(true); SystemControl::Sleep(10); // Select the 8-bit interface mode. DisplayData(false); ChipSelect (false); Write (0x24); ChipSelect (true); // Set RGB Interface control. WriteRegister (0x02, 0x0000); // Set entry mode for 262K colors, auto increment address pointer. WriteRegister (0x03, 0x4130); // Standby off. WriteRegister (0x10, 0x0000); // Required delay to allow display converts to come up. SystemControl::Sleep(100); WriteRegister (0x70, 0x2900); WriteRegister (0x71, 0x2A00); WriteRegister (0x72, 0x3700); WriteRegister (0x73, 0x1912); WriteRegister (0x74, 0x1B0D); WriteRegister (0x75, 0x2014); WriteRegister (0x76, 0x1812); WriteRegister (0x77, 0x2118); WriteRegister (0x78, 0x2111); // Set the window size. Window (0, 0, this->sizeX, this->sizeY); // Clear the screen. StartWrite(); uint32_t pixelCount = this->sizeX * this->sizeY; while (pixelCount-- != 0) WritePixel(GUI::ColorBlack); StopWrite(); // Turn on the ARVDD/ARVSS supplies. PowerConverter(true); // Allow the converters time to stabilize. SystemControl::Sleep(32); // Display on. WriteRegister (0x05, 0x0001); }
VOID IterateFire( struct RastPort *Rast ) { LONG l; struct Fire *f, *tf; if(( NumFires < MaxFires )&&( RangeRand( 100 ) > 90 )) { for( tf = FireTable; tf->type; tf++ ); if( tf != LastFire ) { tf->type = FIRE; tf->x = ( Wid / 4 + RangeRand( Wid / 2 )) * SCALE; tf->y = ( Hei - 5 ) * SCALE; tf->color = RangeRand(( 1L << Rast->BitMap->Depth ) - 1 ) + 1; tf->vx = RangeRand( SCALE * Hei / 100 ) - SCALE; tf->vy = -1 * ( Power * SCALE * Hei / 400 ); tf->time = RangeRand( 100 ) + 100; NumFires++; } } for( f = FireTable; f != LastFire; f++ ) { switch( f->type ) { case NONE: break; case FIRE: if( !f->time ) { for( l = 0, tf = FireTable; ( l < MAX_EXPLOSIONS )&& ( tf != LastFire ); tf++ ) { if( !tf->type ) { CopyMem( f, tf, sizeof( struct Fire )); tf->type = EXPLODING; tf->vx = ( RangeRand( 100 ) - 50 ) * ( Radius * Wid / 1000 ); tf->vy = ( RangeRand( 100 ) - 50 ) * ( Radius * Hei / 1000 ); tf->time = RangeRand( 10 ) + 50; l++; } } NumFires--; f->type = NONE; } else { SetAPen( Rast, 0 ); WritePixel( Rast, f->x/SCALE, f->y/SCALE ); f->x += f->vx; f->y += f->vy; if( CheckFire( f )) { f->type = NONE; NumFires--; } else { SetAPen( Rast, f->color ); WritePixel( Rast, f->x/SCALE, f->y/SCALE ); f->vy += ACCEL; f->time--; } } break; case EXPLODING: SetAPen( Rast, 0 ); WritePixel( Rast, f->x/SCALE, f->y/SCALE ); if( !f->time ) f->type = NONE; else { f->x += f->vx; f->y += f->vy; if( CheckFire( f )) f->type = NONE; else { SetAPen( Rast, f->color ); WritePixel( Rast, f->x/SCALE, f->y/SCALE ); f->vy += ACCEL; f->time--; } } break; } } }
void GSDrawScanlineCodeGenerator::WriteFrame(int params) { const int _top = params + 4; if(!m_sel.fwrite) { return; } if(m_sel.colclamp == 0) { // c[0] &= 0x000000ff; // c[1] &= 0x000000ff; pcmpeqd(xmm7, xmm7); psrlw(xmm7, 8); pand(xmm5, xmm7); pand(xmm6, xmm7); } if(m_sel.fpsm == 2 && m_sel.dthe) { mov(eax, dword[esp + _top]); and(eax, 3); shl(eax, 5); paddw(xmm5, xmmword[eax + (size_t)&m_env.dimx[0]]); paddw(xmm6, xmmword[eax + (size_t)&m_env.dimx[1]]); } // GSVector4i fs = c[0].upl16(c[1]).pu16(c[0].uph16(c[1])); movdqa(xmm7, xmm5); punpcklwd(xmm5, xmm6); punpckhwd(xmm7, xmm6); packuswb(xmm5, xmm7); if(m_sel.fba && m_sel.fpsm != 1) { // fs |= 0x80000000; pcmpeqd(xmm7, xmm7); pslld(xmm7, 31); por(xmm5, xmm7); } if(m_sel.fpsm == 2) { // GSVector4i rb = fs & 0x00f800f8; // GSVector4i ga = fs & 0x8000f800; mov(eax, 0x00f800f8); movd(xmm6, eax); pshufd(xmm6, xmm6, _MM_SHUFFLE(0, 0, 0, 0)); mov(eax, 0x8000f800); movd(xmm7, eax); pshufd(xmm7, xmm7, _MM_SHUFFLE(0, 0, 0, 0)); movdqa(xmm4, xmm5); pand(xmm4, xmm6); pand(xmm5, xmm7); // fs = (ga >> 16) | (rb >> 9) | (ga >> 6) | (rb >> 3); movdqa(xmm6, xmm4); movdqa(xmm7, xmm5); psrld(xmm4, 3); psrld(xmm6, 9); psrld(xmm5, 6); psrld(xmm7, 16); por(xmm5, xmm4); por(xmm7, xmm6); por(xmm5, xmm7); } if(m_sel.rfb) { // fs = fs.blend(fd, fm); blend(xmm5, xmm2, xmm3); // TODO: could be skipped in certain cases, depending on fpsm and fm } bool fast = m_sel.rfb && m_sel.fpsm < 2; WritePixel(xmm5, xmm0, ebx, dl, fast, m_sel.fpsm); }
// Fills a polygon using a texture, gouraud shading and a normal map given 3 points and a color. void Rasterizer::FillPolygonTexturedNormalMapped(Vertex v1, Vertex v2, Vertex v3, Gdiplus::Color color, Model3D& model, std::vector<DirectionalLight*> directionalLights, std::vector<AmbientLight*> ambientLights, std::vector<PointLight*> pointLights) { ScanLine* _scanlines = new ScanLine[_height]; BYTE* texture; Gdiplus::Color* palette; BYTE* normalTexture; Gdiplus::Color* normalPalette; int textureWidth; // Get the texture properties of the model. model.GetTexture(&texture, &palette, &textureWidth); model.GetNormalMapTexture(&normalTexture, &normalPalette, &textureWidth); // Set the scanlines to very high and very low values so // they will be set on the first set of interpolation. for (unsigned int i = 0; i < _height; i++) { _scanlines[i].xStart = 99999; _scanlines[i].xEnd = -99999; } // Interpolates between each of the vertexs of the polygon and sets the start // and end values for each of the scanlines it comes in contact with. InterpolateScanline(_scanlines, v1, v2); InterpolateScanline(_scanlines, v2, v3); InterpolateScanline(_scanlines, v3, v1); // Go through each scanline and each pixel in the scanline and // sets its color. for (unsigned int y = 0; y < _height; y++) { // Work out the color and UV differences between the start and end of the scanline. float redColorDiff = (_scanlines[y].redEnd - _scanlines[y].redStart); float greenColorDiff = (_scanlines[y].greenEnd - _scanlines[y].greenStart); float blueColorDiff = (_scanlines[y].blueEnd - _scanlines[y].blueStart); float uCoordDiff = _scanlines[y].uEnd - _scanlines[y].uStart; float vCoordDiff = _scanlines[y].vEnd - _scanlines[y].vStart; float zCoordDiff = _scanlines[y].zEnd - _scanlines[y].zStart; float xNormalDiff = (_scanlines[y].xNormalEnd - _scanlines[y].xNormalStart); float yNormalDiff = (_scanlines[y].yNormalEnd - _scanlines[y].yNormalStart); float zNormalDiff = (_scanlines[y].zNormalEnd - _scanlines[y].zNormalStart); float xDiff = (_scanlines[y].pixelXEnd - _scanlines[y].pixelXStart); float yDiff = (_scanlines[y].pixelYEnd - _scanlines[y].pixelYStart); float zDiff = (_scanlines[y].pixelZEnd - _scanlines[y].pixelZStart); float diff = (_scanlines[y].xEnd - _scanlines[y].xStart) + 1; for (int x = (int)_scanlines[y].xStart; x <= (int)_scanlines[y].xEnd; x++) { if (x < 0 || x >= (int)_width) continue; int offset = (int)(x - _scanlines[y].xStart); // Work out the UV coordinate of the current pixel. float uCoord = _scanlines[y].uStart + ((uCoordDiff / diff) * offset); float vCoord = _scanlines[y].vStart + ((vCoordDiff / diff) * offset); float zCoord = _scanlines[y].zStart + ((zCoordDiff / diff) * offset); uCoord /= zCoord; vCoord /= zCoord; // Work out the normal of the pixel. float xNormal = _scanlines[y].xNormalStart + ((xNormalDiff / diff) * offset); float yNormal = _scanlines[y].yNormalStart + ((yNormalDiff / diff) * offset); float zNormal = _scanlines[y].zNormalStart + ((zNormalDiff / diff) * offset); // Work out the position of the pixel. float pixelX = _scanlines[y].pixelXStart + ((xDiff / diff) * offset); float pixelY = _scanlines[y].pixelYStart + ((yDiff / diff) * offset); float pixelZ = _scanlines[y].pixelZStart + ((zDiff / diff) * offset); // Work out the lighting colour of the current pixel. //float lightR = (_scanlines[y].redStart + ((redColorDiff / diff) * offset)) / 180.0f; //float lightG = (_scanlines[y].greenStart + ((greenColorDiff / diff) * offset)) / 180.0f; //float lightB = (_scanlines[y].blueStart + ((blueColorDiff / diff) * offset)) / 180.0f; // Using the UV coordinate work out which pixel in the texture to use to draw this pixel. int pixelIndex = (int)vCoord * textureWidth + (int)uCoord; if (pixelIndex >= textureWidth * textureWidth || pixelIndex < 0) { pixelIndex = (textureWidth * textureWidth) - 1; } int paletteOffset = texture[pixelIndex]; if (paletteOffset >= 255) paletteOffset = 255; Gdiplus::Color textureColor = palette[paletteOffset]; // Work out the pixel colour of the normalmap. pixelIndex = (int)vCoord * textureWidth + (int)uCoord; if (pixelIndex >= textureWidth * textureWidth || pixelIndex < 0) { pixelIndex = (textureWidth * textureWidth) - 1; } paletteOffset = normalTexture[pixelIndex]; if (paletteOffset >= 255) paletteOffset = 255; Gdiplus::Color normalTextureColor = normalPalette[paletteOffset]; // Calculate normal lighting for the pixel. Vector3D heightMapVector = Vector3D(normalTextureColor.GetR() / 180.0f, normalTextureColor.GetG() / 180.0f, normalTextureColor.GetB() / 180.0f); heightMapVector = Vector3D((heightMapVector.GetX() - 0.5f) * 2.0f, (heightMapVector.GetY() - 0.5f) * 2.0f, (heightMapVector.GetZ() - 0.5f) * 2.0f); // Work out he pixels normal and position. Vector3D pixelNormal = Vector3D(xNormal, yNormal, zNormal);//;Vector3D(heightMapVector.GetX(), heightMapVector.GetY(), heightMapVector.GetZ()); Vertex pixelPosition = Vertex(pixelX, pixelY, pixelZ, 1, Gdiplus::Color::White, Vector3D(0, 0, 0), 0); heightMapVector = Vector3D((pixelNormal.GetX() * heightMapVector.GetX()) , (pixelNormal.GetY() * heightMapVector.GetY()) , (pixelNormal.GetZ() * heightMapVector.GetZ()) ); // Calculate the sum dot product of all lighting vectors for this pixel and divide by the number // of lights. float lightDot = 0.0f; int count = 0; for (unsigned int j = 0; j < pointLights.size(); j++) { PointLight* light = pointLights[j]; if (light->GetEnabled() == false) continue; // Work out vector to light source. Vector3D lightVector = Vertex::GetVector(pixelPosition, light->GetPosition()); float distance = lightVector.GetLength(); lightVector.Normalize(); // Work out dot product. lightDot += Vector3D::DotProduct(heightMapVector, lightVector); count++; } for (unsigned int j = 0; j < directionalLights.size(); j++) { DirectionalLight* light = directionalLights[j]; if (light->GetEnabled() == false) continue; // Work out vector to light source. Vector3D lightVector = Vertex::GetVector(pixelPosition, light->GetPosition()); float distance = lightVector.GetLength(); lightVector.Normalize(); // Work out dot product. lightDot += Vector3D::DotProduct(heightMapVector, lightVector); count++; } lightDot /= count; // Adjust texture colour based on the lighting dot product. Gdiplus::Color pixelColor = textureColor; //pixelColor = model.CalculateLightingAmbientPerPixel(ambientLights, pixelPosition, pixelNormal, pixelColor); //pixelColor = model.CalculateLightingDirectionalPerPixel(directionalLights, pixelPosition, pixelNormal, pixelColor); //pixelColor = model.CalculateLightingPointPerPixel(pointLights, pixelPosition, pixelNormal, pixelColor); float lightR = (_scanlines[y].redStart + ((redColorDiff / diff) * offset)) / 180.0f; float lightG = (_scanlines[y].greenStart + ((greenColorDiff / diff) * offset)) / 180.0f; float lightB = (_scanlines[y].blueStart + ((blueColorDiff / diff) * offset)) / 180.0f; // Apply the lighting value to the texture colour and use the result to set the colour of the current pixel. int finalR = (int)max(0, min(255, (lightR * textureColor.GetR()) - ((lightR * textureColor.GetR()) * lightDot) )); int finalG = (int)max(0, min(255, (lightG * textureColor.GetG()) - ((lightG * textureColor.GetG()) * lightDot) )); int finalB = (int)max(0, min(255, (lightB * textureColor.GetB()) - ((lightB * textureColor.GetB()) * lightDot) )); WritePixel(x, y, Gdiplus::Color(finalR, finalG, finalB)); } } // Dispose of dynamic objects. delete[] _scanlines; _polygonsRendered++; }
IPTR MenuDecorClass__MDM_DRAW_SYSIMAGE(Class *cl, Object *obj, struct mdpDrawSysImage *msg) { struct RastPort *rport = msg->mdp_RPort; UWORD *pens = DRI(msg->mdp_Dri)->dri_Pens; LONG left = msg->mdp_X; LONG top = msg->mdp_Y; LONG width = msg->mdp_Width; LONG height = msg->mdp_Height; LONG right = left + width - 1; LONG bottom = top + height - 1; SetDrMd(rport, JAM1); switch(msg->mdp_Which) { case SUBMENUIMAGE: { if (MENUS_AMIGALOOK) { SetAPen(rport, pens[BARBLOCKPEN]); } else { SetAPen(rport, pens[(msg->mdp_State == IDS_SELECTED) ? FILLPEN : BACKGROUNDPEN]); } RectFill(rport, left, top, right, bottom); SetAPen(rport, pens[BARDETAILPEN]); SetDrMd(rport, JAM1); WORD x = left; Move(rport, x, top + rport->Font->tf_Baseline); Text(rport, ">>", 2); break; } case MENUCHECK: { if (MENUS_AMIGALOOK) { SetAPen(rport, pens[BARBLOCKPEN]); } else { SetAPen(rport, pens[(msg->mdp_State == IDS_SELECTED) ? FILLPEN : BACKGROUNDPEN]); } RectFill(rport, left, top, right, bottom); SetAPen(rport, pens[BARDETAILPEN]); menu_draw_thick_line(rport, left + 1, top + height / 3 , left + 1, bottom, 0); menu_draw_thick_line(rport, left + 2, bottom, right - 2, top, 0); break; } case AMIGAKEY: { struct TextFont *oldfont; UBYTE oldstyle; if (MENUS_AMIGALOOK) { SetAPen(rport, pens[BARDETAILPEN]); } else { SetAPen(rport, pens[SHINEPEN]); } RectFill(rport, left, top, right, bottom); if (MENUS_AMIGALOOK) { SetAPen(rport, pens[BARBLOCKPEN]); oldfont = rport->Font; oldstyle = rport->AlgoStyle; SetFont(rport, GfxBase->DefaultFont); SetSoftStyle(rport, FSF_ITALIC, AskSoftStyle(rport)); Move(rport, left + (width - rport->TxWidth) / 2, top + (height - rport->TxHeight) / 2 + rport->TxBaseline); Text(rport, "A", 1); SetSoftStyle(rport, oldstyle, AskSoftStyle(rport)); SetFont(rport, oldfont); SetAPen(rport, pens[BARBLOCKPEN]); } else { SetAPen(rport, pens[SHADOWPEN]); RectFill(rport, left + 1, top, right - 1, top); RectFill(rport, right, top + 1, right, bottom - 1); RectFill(rport, left + 1, bottom, right - 1, bottom); RectFill(rport, left, top + 1, left, bottom - 1); SetAPen(rport, pens[BACKGROUNDPEN]); RectFill(rport, left + 1, bottom - 1, right - 1, bottom - 1); RectFill(rport, right - 1, top + 1, right - 1, bottom - 2); RectFill(rport, left + 2, top + 2, left + 4, top + 2); RectFill(rport, left + 2, top + 3, left + 2, top + 4); SetAPen(rport, pens[SHADOWPEN]); RectFill(rport, left + 2, bottom - 2, right - 2, bottom - 2); RectFill(rport, right - 2, top + 2, right - 2, bottom - 4); { WORD a_size = height - 7; WORD a_left = left + 5; WORD a_top = top + 2; WORD a_right = a_left + a_size; WORD a_bottom = a_top + a_size; Move(rport, a_left, a_bottom); Draw(rport, a_right, a_top); Draw(rport, a_right, a_bottom); Move(rport, a_right - 1, a_top + 1); Draw(rport, a_right - 1, a_bottom); } SetAPen(rport, pens[(msg->mdp_State == IDS_SELECTED) ? FILLPEN : BACKGROUNDPEN]); } WritePixel(rport, left, top); WritePixel(rport, right, top); WritePixel(rport, right, bottom); WritePixel(rport, left, bottom); } } return TRUE; }
/********************************************************************* * Function: void PutImage4BPP(SHORT left, SHORT top, FLASH_BYTE* bitmap, BYTE stretch) * * PreCondition: none * * Input: left,top - left top image corner, bitmap - image pointer, * stretch - image stretch factor * * Output: none * * Side Effects: none * * Overview: outputs 16 color image starting from left,top coordinates * * Note: image must be located in flash * ********************************************************************/ void PutImage4BPP(SHORT left, SHORT top, FLASH_BYTE *bitmap, BYTE stretch) { register FLASH_BYTE *flashAddress; register FLASH_BYTE *tempFlashAddress; WORD sizeX, sizeY; register WORD x, y; BYTE temp; register BYTE stretchX, stretchY; WORD pallete[16]; WORD counter; // Move pointer to size information flashAddress = bitmap + 2; // Read image size sizeY = *((FLASH_WORD *)flashAddress); flashAddress += 2; sizeX = *((FLASH_WORD *)flashAddress); flashAddress += 2; // Read pallete for(counter = 0; counter < 16; counter++) { pallete[counter] = *((FLASH_WORD *)flashAddress); flashAddress += 2; } DeviceSelect; for(y = 0; y < sizeY; y++) { tempFlashAddress = flashAddress; for(stretchY = 0; stretchY < stretch; stretchY++) { flashAddress = tempFlashAddress; SetAddress(left, top); for(x = 0; x < sizeX; x++) { // Read 2 pixels from flash if(x & 0x0001) { // second pixel in byte SetColor(pallete[temp >> 4]); } else { temp = *flashAddress; flashAddress++; // first pixel in byte SetColor(pallete[temp & 0x0f]); } // Write pixel to screen for(stretchX = 0; stretchX < stretch; stretchX++) { WritePixel(_color); } } top++; }
/********************************************************************* * Function: void PutImage1BPP(SHORT left, SHORT top, FLASH_BYTE* image, BYTE stretch, PUTIMAGE_PARAM *pPartialImageData) * * PreCondition: none * * Input: left,top - left top image corner, * image - image pointer, * stretch - image stretch factor * pPartialImageData - (currently not implemented in this driver) * * Output: none * * Side Effects: none * * Overview: outputs monochrome image starting from left,top coordinates * * Note: image must be located in flash * ********************************************************************/ void PutImage1BPP(SHORT left, SHORT top, FLASH_BYTE *image, BYTE stretch, PUTIMAGE_PARAM *pPartialImageData) { register FLASH_BYTE *flashAddress; register FLASH_BYTE *tempFlashAddress; BYTE temp = 0; WORD sizeX, sizeY; WORD x, y, currentXLocation; BYTE stretchX, stretchY; WORD pallete[2]; BYTE mask; // Move pointer to size information flashAddress = image + 2; // Read image size sizeY = *((FLASH_WORD *)flashAddress); flashAddress += 2; sizeX = *((FLASH_WORD *)flashAddress); flashAddress += 2; pallete[0] = *((FLASH_WORD *)flashAddress); flashAddress += 2; pallete[1] = *((FLASH_WORD *)flashAddress); flashAddress += 2; DisplayEnable(); for(y = 0; y < sizeY; y++) { tempFlashAddress = flashAddress; for(stretchY = 0; stretchY < stretch; stretchY++) { flashAddress = tempFlashAddress; SetAddress((WORD) left, (WORD) top); mask = 0; for(x = 0, currentXLocation = 0; x < sizeX; x++) { // Read 8 pixels from flash if(mask == 0) { temp = *flashAddress; flashAddress++; mask = 0x01; } // Set color if(mask & temp) { SetColor(pallete[1]); } else { SetColor(pallete[0]); } // Write pixel to screen for(stretchX = 0; stretchX < stretch; stretchX++) { #ifdef USE_TRANSPARENT_COLOR if (((GetTransparentColor() == GetColor()) && (GetTransparentColorStatus() == TRANSPARENT_COLOR_ENABLE))) { currentXLocation++; SetAddress(left + currentXLocation , top); } else #endif { currentXLocation++; WritePixel(_color); } } // Shift to the next pixel mask <<= 1; } top++; } } DisplayDisable(); }