sprite programme - tell me what's wrong with it - sprite.pas [1/1]

--*-*-*- Next Section -*-*-*
Content-Type: Text/Plain; charset=US-ASCII

No, there's no bugs (well, apart from the first sprite always being
rubbish).  What I want to know is this - what better ways can I use for
this prog?  what do you think is bad about it (the whole concept,
perhaps)?

(the vga_grf unit is only needed for the block drawing routine -
a simple icon type tile - it can be removed and replaced with a couple
of lines - sorry, didn't have time to adjust it myself)

squigger hops again
--*-*-*- Next Section -*-*-*
Content-Type: Text/Plain; charset=US-ASCII

uses
    vga_grf;

{
  uses two doubly linked lists to store a sprite of any size up to 255 * 255
  spritetype :  holds info on the on the sprite - its identifier, its
  dimensions, the sprite's position in the list, and a pointer to the list
  which holds its block of data
  spritedata : holds the data of the sprite

Quote
}

type
    spritedatapointer = ^spritedata;                { pointer to sprite data list }
    spritedata = record
               data : byte;                         { single byte of sprite data }
               previous, next : spritedatapointer;   { pointers to first, previous, and next bytes of data }
    end; {spritedata}

    spritepointer = ^spritetype;                    { pointer to sprite structure }
    spritetype = record
               name : string;                       { to identify sprite - alternatively, could be number }
               height, width : byte;                { dimensions for datalist }
               datalist : spritedatapointer;        { the actual sprite data }
               previous, next : spritepointer;      { pointers to the previous and next sprites }
    end; {spritetype}

var
   firstsprite, currentsprite, lastsprite : spritepointer;
   firstdata, currentdata, lastdata : spritedatapointer;
   numberofsprites : integer;
   qw, qw2 : byte;

procedure capturesprite(xpos,ypos: word; width, height:byte; name:string);
var
   w, h, databyte : byte;

begin
     numberofsprites := numberofsprites + 1;
     lastsprite := currentsprite;
     new(currentsprite);
     currentsprite^.name := name;
     currentsprite^.height := height;
     currentsprite^.width := width;
     for h := 0 to (height - 1) do
         for w := 0 to (width - 1) do
         begin
              lastdata := currentdata;
              new(currentdata);
              if (h = 0) and (w = 0) then currentsprite^.datalist := currentdata;
              asm
                 push ds
                 mov ax, 0A000h
                 mov ds, ax
                 mov ax, 320
                 mov bx, ypos
                 add bl, h
                 mul bx
                 add ax, xpos
                 add al, w
                 mov si, ax
                 lodsb
                 mov databyte, al
                 pop ds
              end;
              currentdata^.data := databyte;
              currentdata^.next := nil;
              if numberofsprites = 1 then
              begin
                   currentdata^.previous := nil;
                   firstdata := currentdata;
              end
              else
              begin
                   currentdata^.previous := lastdata;
                   lastdata^.next := currentdata;
              end;
         end;
     currentsprite^.next := nil;
     if numberofsprites = 1 then
     begin
          currentsprite^.previous := nil;
          firstsprite := currentsprite;
     end
     else
     begin
          currentsprite^.previous := lastsprite;
          lastsprite^.next := currentsprite;
     end;
end;

procedure putsprite(xpos,ypos:word;name : string);
var
   q : word;
   vpos, hpos, databyte : byte;

begin
     currentsprite := firstsprite;
     while not (currentsprite^.name = name) do
     begin
          currentsprite := currentsprite^.next;
     end;
     currentdata := currentsprite^.datalist;
     for q := 0 to (currentsprite^.height * currentsprite^.width) - 1 do
     begin
          vpos := q div currentsprite^.height;
          hpos := q - (currentsprite^.height * vpos);
          databyte := currentdata^.data;
          asm
             xor cx, cx
             mov ax, 0A000h
             mov es, ax
             mov ax, 320
             mov bx, ypos
             mov cl, vpos
             add bx, cx
             mul bx
             add ax, xpos
             mov cl, hpos
             add ax, cx
             mov di, ax
             mov al, databyte
             stosb
          end;
          currentdata := currentdata^.next;
     end;
end;

procedure releaseallsprites;
var
   q : byte;

begin
     if numberofsprites > 0 then
     begin
          currentsprite := firstsprite;
          currentdata := firstdata;
          for q := 1 to numberofsprites do
          begin
               lastsprite := currentsprite;
               lastdata := currentdata;
               if not (lastsprite^.next = nil) then currentsprite := currentsprite^.next;
               if not (lastdata^.next = nil) then currentdata := currentdata^.next;
               dispose(lastsprite);
               dispose(lastdata);
          end;
     end;
     numberofsprites := 0;
end;

begin
     asm
        mov ax, 13h
        int 10h
     end;
     numberofsprites := 0;
     icon(0,0,9,9,true);
     capturesprite(0,0,1,1,'bugfix');
     capturesprite(0,0,10,10,'number1');

     readln;

     for qw2 := 0 to 19 do
         for qw := 0 to 31 do
             putsprite(qw * 10, qw2 * 10,'number1');

     releaseallsprites;
     readln;
end.--*-*-*- Next Section -*-*-*--