////////////////////////////////////////////////////////////////////// // // // gfxDraw1D16Sprite.pas: Render metacode for 16 color sprites with // // 1D mapping // // // // The contents of this file are subject to the Bottled Light // // Public License Version 1.0 (the "License"); you may not use this // // file except in compliance with the License. You may obtain a // // copy of the License at http://www.bottledlight.com/BLPL/ // // // // Software distributed under the License is distributed on an // // "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or // // implied. See the License for the specific language governing // // rights and limitations under the License. // // // // The Original Code is the Mappy VM Core, released April 1st, 2003 // // The Initial Developer of the Original Code is Bottled Light, // // Inc. Portions created by Bottled Light, Inc. are Copyright // // (C) 2001 - 2003 Bottled Light, Inc. All Rights Reserved. // // // // Author(s): // // Michael Noland (joat), michael@bottledlight.com // // // // Changelog: // // 1.0: First public release (April 1st, 2003) // // // ////////////////////////////////////////////////////////////////////// // Draw a 16 color sprite using 1D mapping var hsize, vsize: byte; pix: uint16; sx, sy: integer; x, x0, base: integer; pal: uint32; {$INCLUDE gfxDrawPixelInc.pas} sx := entry^.x; sy := entry^.y; hsize := entry^.width; vsize := entry^.height; // Calculate the sprite image base if entry^.b and SPRITE_B_FLIP_Y <> 0 then y := vsize-y-1; base := (entry^.c and $3FF) shl 5; base := base + (y shl 2) and 31 + (y shr 3) * hsize * 4; base := base + $10000; // Calculate the palette base pal := (entry^.c shr 12) shl 5 + 512; // Do some clipping if sx < 0 then x0 := -sx else x0 := 0; if sx+entry^.run > 240 then Exit; ids := @(Puint8Array(ids)^[sx+x0]); wins := @(Puint8Array(wins)^[sx+x0]); line := @(Puint16Array(line)^[sx+x0]); // Draw a 16 color sprite using 1D mapping if entry^.b and SPRITE_B_FLIP_X <> 0 then begin for x := x0 to entry^.run-1 do begin pix := VRAM[base + (7-x and 7) shr 1 + ((hsize-x-1) shr 3) shl 5]; if Odd(x) then pix := pix and $F else pix := pix shr 4; if (pix <> 0) {$IFNDEF OBJWIN}and (wins^ and mask <> 0){$ENDIF} or ((pix = 0) and (not latchXparent) and (mclock > 0)) then begin pix := Puint16(@(palette[pix shl 1 + pal]))^; {$INCLUDE gfxDrawPixel.pas} end; end else begin for x := x0 to entry^.run-1 do begin pix := VRAM[base + (x and 7) shr 1 + (x shr 3) shl 5]; if Odd(x) then pix := pix shr 4 else pix := pix and $F; if (pix <> 0) {$IFNDEF OBJWIN}and (wins^ and mask <> 0){$ENDIF} or ((pix = 0) and (not latchXparent) and (mclock > 0)) then begin pix := Puint16(@(palette[pix shl 1 + pal]))^; {$INCLUDE gfxDrawPixel.pas} end; end; end;