/**************************************************************************** Fill the area covered by the sprite with the given color. ****************************************************************************/ void canvas_fog_sprite_area(struct canvas *pcanvas, struct sprite *psprite, int canvas_x, int canvas_y) { SDL_Rect dst = {canvas_x, canvas_y, GET_SURF(psprite)->w, GET_SURF(psprite)->h}; SDL_Surface *tmp_surf = create_surf_alpha(GET_SURF(psprite)->w, GET_SURF(psprite)->h, SDL_SWSURFACE); SDL_FillRect(tmp_surf, NULL, SDL_MapRGBA(tmp_surf->format, 0, 0, 0, 64)); alphablit(tmp_surf, NULL, pcanvas->surf, &dst); FREESURFACE(tmp_surf); }
/**************************************************************************** Fill the area covered by the sprite with the given color. ****************************************************************************/ void canvas_fill_sprite_area(struct canvas *pcanvas, struct sprite *psprite, struct color *pcolor, int canvas_x, int canvas_y) { SDL_Rect dst = {canvas_x, canvas_y, GET_SURF(psprite)->w, GET_SURF(psprite)->h}; SDL_FillRect(pcanvas->surf, &dst, SDL_MapRGBA(pcanvas->surf->format, pcolor->color->r, pcolor->color->g, pcolor->color->b, pcolor->color->unused)); }
/**************************************************************************** Draw a full sprite onto the canvas. ****************************************************************************/ void canvas_put_sprite_full(struct canvas *pcanvas, int canvas_x, int canvas_y, struct sprite *sprite) { SDL_Rect dst = {canvas_x, canvas_y, 0, 0}; alphablit(GET_SURF(sprite), NULL, pcanvas->surf, &dst); }
/************************************************************************** ... **************************************************************************/ void tilespec_setup_city_gfx(void) { struct sprite *pSpr = theme_lookup_sprite_tag_alt(theme, LOG_FATAL, "theme.city", "", "", ""); pCity_Surf = (pSpr ? adj_surf(GET_SURF(pSpr)) : NULL); assert(pCity_Surf != NULL); }
/**************************************************************************** Draw some or all of a sprite onto the canvas. ****************************************************************************/ void canvas_put_sprite(struct canvas *pcanvas, int canvas_x, int canvas_y, struct sprite *sprite, int offset_x, int offset_y, int width, int height) { SDL_Rect src = {offset_x, offset_y, width, height}; SDL_Rect dst = {canvas_x + offset_x, canvas_y + offset_y, 0, 0}; alphablit(GET_SURF(sprite), &src, pcanvas->surf, &dst); }
int32 rp63 (int32 dev, int32 pulse, int32 dat) { int32 sb = pulse & 060; /* subopcode */ rp_updsta (0, 0); if (pulse & 01) { if ((sb == 000) && /* DPSF */ ((rp_sta & (STA_DON | STA_ERR)) || (rp_stb & STB_ATTN))) dat = IOT_SKP | dat; else if ((sb == 020) && (rp_stb & STB_ATTN)) /* DPSA */ dat = IOT_SKP | dat; else if ((sb == 040) && (rp_sta & STA_DON)) /* DPSJ */ dat = IOT_SKP | dat; else if ((sb == 060) && (rp_sta & STA_ERR)) /* DPSE */ dat = IOT_SKP | dat; } if (pulse & 02) { if (sb == 000) /* DPOSA */ dat = dat | rp_sta; else if (sb == 020) /* DPOSB */ dat = dat | rp_stb; } if (pulse & 04) { if (rp_busy) { /* busy? */ rp_updsta (0, STB_PGE); /* prog error */ return dat; } else if (sb == 000) { /* DPLA */ int32 u = GET_UNIT (rp_sta); rp_da = dat & DMASK; if (GET_SECT (rp_da) >= RP_NUMSC) rp_updsta (STA_NXS, 0); if (GET_SURF (rp_da) >= RP_NUMSF) rp_updsta (STA_NXF, 0); if (GET_CYL(rp_da, rp_unit[u].flags) >= RP_QCYL(rp_unit[u].flags)) rp_updsta (STA_NXC, 0); } else if (sb == 020) { /* DPCS */ rp_sta = rp_sta & ~(STA_HNF | STA_DON); /* clr err, done */ rp_stb = rp_stb & ~(STB_FME | STB_WPE | STB_LON | STB_WCE | STB_TME | STB_PGE | STB_EOP); rp_updsta (0, 0); } else if (sb == 040) /* DPCA */ rp_ma = dat & DMASK; else if (sb == 060) /* DPWC */ rp_wc = dat & DMASK; } return dat; }
/**************************************************************************** Draw a full sprite onto the canvas. If "fog" is specified draw it with fog. ****************************************************************************/ void canvas_put_sprite_fogged(struct canvas *pcanvas, int canvas_x, int canvas_y, struct sprite *psprite, bool fog, int fog_x, int fog_y) { SDL_Rect dst = {canvas_x, canvas_y, 0, 0}; if (fog) { SDL_Surface *tmp_surf = blend_surface(GET_SURF(psprite), 160); alphablit(tmp_surf, NULL, pcanvas->surf, &dst); FREESURFACE(tmp_surf); } else { canvas_put_sprite_full(pcanvas, canvas_x, canvas_y, psprite); } }
/**************************************************************************** Create a new sprite by cropping and taking only the given portion of the image. source gives the sprite that is to be cropped. x,y, width, height gives the rectangle to be cropped. The pixel at position of the source sprite will be at (0,0) in the new sprite, and the new sprite will have dimensions (width, height). mask gives an additional mask to be used for clipping the new sprite. Only the transparency value of the mask is used in crop_sprite. The formula is: dest_trans = src_trans * mask_trans. Note that because the transparency is expressed as an integer it is common to divide it by 256 afterwards. mask_offset_x, mask_offset_y is the offset of the mask relative to the origin of the source image. The pixel at (mask_offset_x,mask_offset_y) in the mask image will be used to clip pixel (0,0) in the source image which is pixel (-x,-y) in the new image. ****************************************************************************/ struct sprite *crop_sprite(struct sprite *source, int x, int y, int width, int height, struct sprite *mask, int mask_offset_x, int mask_offset_y) { SDL_Rect src_rect = {(Sint16) x, (Sint16) y, (Uint16) width, (Uint16) height}; SDL_Surface *pSrc = crop_rect_from_surface(GET_SURF(source), &src_rect); SDL_Surface *pDest = NULL; if (mask) { pDest = mask_surface(pSrc, mask->psurface, x - mask_offset_x, y - mask_offset_y); FREESURFACE(pSrc); return ctor_sprite(pDest); } return ctor_sprite(pSrc); }
/************************************************************************** ... **************************************************************************/ SDL_Surface * get_tech_icon(Tech_type_id tech) { switch(tech) { case A_NONE: case A_UNSET: case A_UNKNOWN: case A_LAST: return SDL_DisplayFormatAlpha(pNone_Tech_Icon); case A_FUTURE: return SDL_DisplayFormatAlpha(pFuture_Tech_Icon); default: if (get_tech_sprite(tileset, tech)) { return adj_surf(GET_SURF(get_tech_sprite(tileset, tech))); } else { return SDL_DisplayFormatAlpha(pNeutral_Tech_Icon); } } return NULL; }
t_stat rp_svc (UNIT *uptr) { int32 f, u, comp, cyl, sect, surf; int32 err, pa, da, wc, awc, i; u = (int32) (uptr - rp_dev.units); /* get drv number */ f = uptr->FUNC; /* get function */ if (f == FN_IDLE) { /* idle? */ rp_busy = 0; /* clear busy */ return SCPE_OK; } if ((f == FN_SEEK) || (f == FN_RECAL)) { /* seek or recal? */ rp_busy = 0; /* not busy */ cyl = (f == FN_SEEK)? GET_CYL (rp_da): 0; /* get cylinder */ sim_activate (uptr, MAX (RP_MIN, abs (cyl - uptr->CYL) * rp_swait)); uptr->CYL = cyl; /* on cylinder */ uptr->FUNC = FN_SEEK | FN_2ND; /* set second state */ rp_updsta (0, 0); /* update status */ return SCPE_OK; } if (f == (FN_SEEK | FN_2ND)) { /* seek done? */ rp_updsta (0, rp_stb | (1 << (STB_V_ATT0 - u))); /* set attention */ return SCPE_OK; } if ((uptr->flags & UNIT_ATT) == 0) { /* not attached? */ rp_updsta (STA_DON, STB_SUFU); /* done, unsafe */ return IORETURN (rp_stopioe, SCPE_UNATT); } if ((f == FN_WRITE) && (uptr->flags & UNIT_WPRT)) { /* write locked? */ rp_updsta (STA_DON | STA_WPE, 0); /* error */ return SCPE_OK; } if (GET_SECT (rp_da) >= RP_NUMSC) rp_updsta (STA_NXS, 0); if (GET_SURF (rp_da) >= RP_NUMSF) rp_updsta (STA_NXF, 0); if (GET_CYL (rp_da) >= RP_NUMCY) rp_updsta (STA_NXC, 0); if (rp_sta & (STA_NXS | STA_NXF | STA_NXC)) { /* or bad disk addr? */ rp_updsta (STA_DON, STB_SUFU); /* done, unsafe */ return SCPE_OK; } pa = rp_ma & AMASK; /* get mem addr */ da = GET_DA (rp_da) * RP_NUMWD; /* get disk addr */ wc = 01000000 - rp_wc; /* get true wc */ if (((uint32) (pa + wc)) > MEMSIZE) { /* memory overrun? */ nexm = 1; /* set nexm flag */ wc = MEMSIZE - pa; /* limit xfer */ } if ((da + wc) > RP_SIZE) { /* disk overrun? */ rp_updsta (0, STB_EOP); /* error */ wc = RP_SIZE - da; /* limit xfer */ } err = fseek (uptr->fileref, da * sizeof (int), SEEK_SET); if ((f == FN_READ) && (err == 0)) { /* read? */ awc = fxread (&M[pa], sizeof (int32), wc, uptr->fileref); for ( ; awc < wc; awc++) M[pa + awc] = 0; err = ferror (uptr->fileref); } if ((f == FN_WRITE) && (err == 0)) { /* write? */ fxwrite (&M[pa], sizeof (int32), wc, uptr->fileref); err = ferror (uptr->fileref); if ((err == 0) && (i = (wc & (RP_NUMWD - 1)))) { fxwrite (fill, sizeof (int), i, uptr->fileref); err = ferror (uptr->fileref); } } if ((f == FN_WRCHK) && (err == 0)) { /* write check? */ for (i = 0; (err == 0) && (i < wc); i++) { awc = fxread (&comp, sizeof (int32), 1, uptr->fileref); if (awc == 0) comp = 0; if (comp != M[pa + i]) rp_updsta (0, STB_WCE); } err = ferror (uptr->fileref); } rp_wc = (rp_wc + wc) & DMASK; /* final word count */ rp_ma = (rp_ma + wc) & DMASK; /* final mem addr */ da = (da + wc + (RP_NUMWD - 1)) / RP_NUMWD; /* final sector num */ cyl = da / (RP_NUMSC * RP_NUMSF); /* get cyl */ if (cyl >= RP_NUMCY) cyl = RP_NUMCY - 1; surf = (da % (RP_NUMSC * RP_NUMSF)) / RP_NUMSC; /* get surface */ sect = (da % (RP_NUMSC * RP_NUMSF)) % RP_NUMSC; /* get sector */ rp_da = (cyl << DA_V_CYL) | (surf << DA_V_SURF) | (sect << DA_V_SECT); rp_busy = 0; /* clear busy */ rp_updsta (STA_DON, 0); /* set done */ if (err != 0) { /* error? */ perror ("RP I/O error"); clearerr (uptr->fileref); return IORETURN (rp_stopioe, SCPE_IOERR); } return SCPE_OK; }
/**************************************************************************** Find the dimensions of the sprite. ****************************************************************************/ void get_sprite_dimensions(struct sprite *sprite, int *width, int *height) { *width = GET_SURF(sprite)->w; *height = GET_SURF(sprite)->h; }