// ========================================================================== // draw the shadow projection of a sprite at the zoom 1:div // dst & sprite MUST be 8bpp color depth both // dst & sprite MUST be linear bitmaps both (not plannar) // cmap must point on an array of 256 bytes // offx and offy are the coordinates of the pivot point of the sprite void stretch_trans_shadow_8bpp(BITMAP * dst, BITMAP * sprite, int x0, int y0, int div, UBYTE * cmap, int offy) { int dx1, dy1, dx2, dy2, sx1, sy1, sw, sh; // ridiculous cases if ((bitmap_color_depth(dst) != 8) || (bitmap_color_depth(sprite) != 8)){ return; } if (( ! is_linear_bitmap(dst)) || ( ! is_linear_bitmap(sprite))){ return; } sx1 = 0; sy1 = 0; sw = sprite->w / div; sh = sprite->h / (div * 2); dy1 = y0 + ((offy - y0) / 2); dx1 = x0 - ((offy - y0) / 2); dx2 = dx1 + sw - 1; dy2 = dy1 + sh - 1; // draw { int dx, dy, sx, sy; dx = dx1; dy = dy1; sx = sx1; sy = sy1; for(;;) { if ((dx >= 0) && (dy >= 0) && (dx < dst->w) && (dy < dst->h)) { if (sprite->line[sy][sx]){ dst->line[dy][dx] = cmap[ dst->line[dy][dx] ]; } } dx++; if (dx > dx2) { dx1++; dx2++; dx = dx1; sx = sx1; dy++; if (dy > dy2){ return; } else{ sy += div * 2; } } else{ sx += div; } } } }
int MKS_RamdomFrac1(BITMAP *bmp, unsigned char adj, void (*CallBack)()) { int w,h; if (!is_linear_bitmap(bmp)) return 1; clear(bmp); pl4Scr=bmp->line[0]; w=bmp->w-1; h=bmp->h-1; recadj=adj; Bmp=bmp; CB=CallBack; cont=CB_CONT; // Initialize Random table MA2_InitRTable(); if (w==Xopt-1) { // Set the first corners SetPixel(0,0,MA2_GetRand8()); SetPixel(w,h,MA2_GetRand8()); SetPixel(0,h,MA2_GetRand8()); SetPixel(w,0,MA2_GetRand8()); // Start the recursion SubDivide(0,0,w,h); } else { // Set the first corners SetPixelG(0,0,MA2_GetRand8()); SetPixelG(w,h,MA2_GetRand8()); SetPixelG(0,h,MA2_GetRand8()); SetPixelG(w,0,MA2_GetRand8()); // Start the recursion SubDivideG(0,0,w,h); } return 0; }
int uip_vgamode(void) { int depth, rate; unsigned long screenbase; for (rate = 60; rate <= 70; rate += 10) { for (depth = 15; depth <= 16; depth++) { LOG_VERBOSE(("Trying mode 640x480 depth %d rate %d", depth, rate)); set_color_depth(depth); request_refresh_rate(rate); if ((set_gfx_mode(GFX_AUTODETECT, 640, 480, 0, 480 * 2) < 0)) { LOG_VERBOSE(("Mode not supported")); continue; } if (SCREEN_W != 640 || SCREEN_H != 480) { LOG_CRITICAL(("Screen not approriate for depth %d rate %d", depth, rate)); continue; } goto WHEE; } } LOG_CRITICAL(("Failed to find suitable mode")); return 1; WHEE: uip_vga = 1; if (uip_forceredshift != -1 && uip_forcegreenshift != -1 && uip_forceblueshift != -1) { uip_uipinfo->redshift = uip_forceredshift; uip_uipinfo->greenshift = uip_forcegreenshift; uip_uipinfo->blueshift = uip_forceblueshift; } else { uip_uipinfo->redshift = ui_topbit(makecol(255, 0, 0)) - 4; uip_uipinfo->greenshift = ui_topbit(makecol(0, 255, 0)) - 4; uip_uipinfo->blueshift = ui_topbit(makecol(0, 0, 255)) - 4; } if ((uip_bank0 = create_video_bitmap(640, 480)) == NULL || (uip_bank1 = create_video_bitmap(640, 480)) == NULL) { uip_textmode(); LOG_CRITICAL(("Failed to allocate memory pages")); return 1; } if (is_linear_bitmap(uip_bank0) == 0 || is_linear_bitmap(uip_bank1) == 0 || is_video_bitmap(uip_bank0) == 0 || is_video_bitmap(uip_bank1) == 0) { uip_textmode(); LOG_CRITICAL(("Allocated bitmaps not suitable or linear addressing mode " "not supported by hardware")); return 1; } /* don't you just hate MS platforms? */ __djgpp_nearptr_enable(); __dpmi_get_segment_base_address(uip_bank0->seg, &screenbase); uip_uipinfo->screenmem0 = (uint8 *)(screenbase + uip_bank0->line[0] - __djgpp_base_address); __dpmi_get_segment_base_address(uip_bank1->seg, &screenbase); uip_uipinfo->screenmem1 = (uint8 *)(screenbase + uip_bank1->line[0] - __djgpp_base_address); uip_uipinfo->linewidth = 2 * VIRTUAL_W; /* 16 bit */ uip_displaybank(0); /* set current to 0th bank */ uip_clearscreen(); /* clear bank */ ui_setupscreen(); /* setup bank */ uip_displaybank(-1); /* toggle bank */ uip_clearscreen(); /* clear bank */ ui_setupscreen(); /* setup bank */ if (install_keyboard() == -1) { uip_textmode(); LOG_CRITICAL(("Unable to initialise keyboard")); return 1; } if (uip_bank0->y_ofs != 0 || uip_bank1->y_ofs != 480) { uip_textmode(); LOG_CRITICAL(("sorry, I don't understand this video layout")); return 1; } keyboard_lowlevel_callback = uip_keyboardhandler; uip_keypoll = keyboard_needs_poll()? 1 : 0; return 0; }
// ========================================================================== // draw a sprite at the zoom 1:div // dst & sprite MUST be 8bpp color depth both // dst & sprite MUST be linear bitmaps both (not plannar) // if color_map point to NULL, regular sprite, else transparent one void stretch_trans_sprite_8bpp(BITMAP * dst, BITMAP * sprite, int x0, int y0, int div) { int dx1, dy1, dx2, dy2, sx1, sy1, dw, dh, sw, sh; // ridiculous cases if ((bitmap_color_depth(dst) != 8) || (bitmap_color_depth(sprite) != 8)){ return; } if (( ! is_linear_bitmap(dst)) || ( ! is_linear_bitmap(sprite))){ return; } // clip dw = dst->w; dh = dst->h; if ((x0 >= dw) || (y0 >= dh)){ return; } sw = sprite->w; sh = sprite->h; // start if (x0 < 0) { dx1 = 0; sx1 = (-x0) * div; if (sx1 >= sw) return; } else { dx1 = x0; sx1 = 0; } if (y0 < 0) { dy1 = 0; sy1 = (-y0) * div; if (sy1 >= sh){ return; } } else { dy1 = y0; sy1 = 0; } // end sw /= div; sh /= div; dx2 = dx1 + sw - 1 - (sx1 / div); if (dx2 >= dw){ dx2 = dw - 1; } dy2 = dy1 + sh - 1 - (sy1 / div); if (dy2 >= dh){ dy2 = dh - 1; } if ((dx2 < 0) || (dy2 < 0)){ return; } // draw { int dx, dy, sx, sy; dx = dx1; dy = dy1; sx = sx1; sy = sy1; if (color_map == NULL) { // regular sprite for(;;) { if (sprite->line[sy][sx]){ dst->line[dy][dx] = sprite->line[sy][sx]; } dx++; if (dx > dx2) { dx = dx1; sx = sx1; dy++; if (dy > dy2){ return; } else{ sy += div; } } else{ sx += div; } } } else { // transparent sprite for(;;) { if (sprite->line[sy][sx]) { dst->line[dy][dx] = color_map->data [ dst->line[dy][dx] ] [ sprite->line[sy][sx] ]; } dx++; if (dx > dx2) { dx = dx1; sx = sx1; dy++; if (dy > dy2){ return; }else{ sy += div; } } else{ sx += div; } } } } }