Recent

Author Topic: How do I access data memory in Lazarus?  (Read 544 times)

TBMan

  • New Member
  • *
  • Posts: 42
How do I access data memory in Lazarus?
« on: January 12, 2025, 06:44:02 pm »
I'm trying to learn Lazarus/Free Pascal and I'm a Borland Pascal programmer. Years ago I created a sprite class that could have different sizes. I would access  memory using getmem, mem, seg and ofs and freemem in my routines. However, in this new (to me) Pascal the memory accessing abilities are different. Here's my code. Any help would be appreciated.  In this example there is no error checking for opening the sprite file. The loadsprite function used to use the "searchrec" type from the old DOS unit of Turbo/Borland pascal, but that will be something else I have to learn.

Code: Pascal  [Select][+][-]
  1.  
  2.  
  3.  
  4. TYPE
  5.   rt_spritetop = RECORD
  6.     version,
  7.     width,depth:BYTE;
  8.   END;
  9.  
  10.   rt_spriteclass = RECORD
  11.     loaded:BOOLEAN;
  12.     description:rt_spritetop;
  13.     s_segment,s_offset:WORD;
  14.     data:POINTER;
  15.   END;
  16.  
  17.  
  18. FUNCTION loadsprite(s:STRING;VAR sprite:rt_spriteclass):INTEGER;
  19.     VAR
  20.      f:FILE;
  21.      w,D:BYTE;
  22.  
  23.     BEGIN
  24.         Assign(f,s);
  25.         Reset(f,1);
  26.  
  27.         BlockRead(f,sprite.description,SizeOf(rt_SPRITEtop));
  28.         w := sprite.description.width;
  29.         D := sprite.description.depth;
  30.  
  31.         GetMem(sprite.data,w*D);
  32.  
  33.           Sprite.s_segment := Seg(sprite.data^);
  34.           Sprite.s_offset  := Ofs(sprite.data^);
  35.           BlockRead(f,sprite.data^,w*D);
  36.           sprite.loaded := TRUE;
  37.           Close(F);
  38.           loadsprite := 0;
  39.     END;
  40.  
  41. PROCEDURE killsprite(VAR n:rt_spriteclass);
  42. BEGIN
  43.   IF n.loaded THEN
  44.   BEGIN
  45.     n.loaded := FALSE;
  46.     FreeMem(n.data,n.description.width*n.description.depth);
  47.   END;
  48. END;
  49.  
  50.  
  51.  
  52.  PROCEDURE displaysprite(n:rt_spriteclass;X,Y:INTEGER);
  53. VAR
  54.  xx,
  55.  w,D,
  56.  r,c:INTEGER;
  57. BEGIN
  58.   w := n.description.width-1;
  59.   D := n.description.depth-1;
  60.   FOR r := 0 TO D DO
  61.   BEGIN
  62.     xx :=X;
  63.     FOR c := 0 TO w DO
  64.     BEGIN
  65.       PutPixel(xx,Y,mem[n.s_segment:n.s_offset+(r*(w+1)+c)]);
  66.       Inc(xx);
  67.     END;
  68.     Inc(Y);
  69.   END;
  70. END;                    

jamie

  • Hero Member
  • *****
  • Posts: 6801
Re: How do I access data memory in Lazarus?
« Reply #1 on: January 12, 2025, 06:50:47 pm »
That code is no longer valid unless you have an old 16-bit box around.

Today we use TBitmaps for images and TImageList to store a series of images.

use the Canvas to paint them.

 Maybe you should look into the OpenGL, there are samples that comes with the install.

The only true wisdom is knowing you know nothing

TBMan

  • New Member
  • *
  • Posts: 42
Re: How do I access data memory in Lazarus?
« Reply #2 on: January 12, 2025, 08:10:18 pm »
That code is no longer valid unless you have an old 16-bit box around.

Today we use TBitmaps for images and TImageList to store a series of images.

use the Canvas to paint them.

 Maybe you should look into the OpenGL, there are samples that comes with the install.

Thanks, there's a lot to learn there. I'm making progress with the Lazarus package. It's nice to be able to code in a windows app instead of DOSBOX. I'm working with the Graph unit in Lazarus right now which is fun.

 

TinyPortal © 2005-2018