Recent

Author Topic: Things Lazarus/FPC can do Delphi cannot?  (Read 36265 times)

teos

  • Full Member
  • ***
  • Posts: 157
Re: Things Lazarus/FPC can do Delphi cannot?
« Reply #45 on: January 26, 2013, 09:33:37 pm »
Thanks for pointing me in that direction, something to investigate.

I have no intention to damage the project. I seem to have something in my health that lets me read my comments a lot more positive than others do...

But before this is gonna go completely off topic: it think the compiler directives can be an reason for one issue, and the load of packages in CodeTyphon, together with the low amount of memory could be reason for the other (and the "out of memory" issues).

Thanks for replying and the patience!

Kamau

  • Jr. Member
  • **
  • Posts: 67
  • Old Delphi programmer
Re: Things Lazarus/FPC can do Delphi cannot?
« Reply #46 on: February 06, 2013, 05:21:11 am »
bitpacked record like c/c++

type
bit = 0..1;

BitsInaByte = bitpacked record
        bit0   : bit;
        bit1   : bit;
        bit2   : bit;
        bit3   : bit;
        bit4   : bit;
        bit5   : bit;
        bit6   : bit;
        bit7   : bit;
    end;

Could you, ttomas, or someone else give a short sample code to explain the use of this.

I fail to see any practical use of it.

Curious and interested :-)

/Kamau
« Last Edit: February 06, 2013, 05:37:00 am by Kamau »

Leledumbo

  • Hero Member
  • *****
  • Posts: 8746
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: Things Lazarus/FPC can do Delphi cannot?
« Reply #47 on: February 06, 2013, 11:18:35 am »
Quote
Could you, ttomas, or someone else give a short sample code to explain the use of this.
This is mostly useful for low level access (for example, if you access certain hardware or writing a kernel) or data exchange that requires exact bit structure. With this, you don't need to play with bitwise operators in your code.

Kamau

  • Jr. Member
  • **
  • Posts: 67
  • Old Delphi programmer
Re: Things Lazarus/FPC can do Delphi cannot?
« Reply #48 on: February 06, 2013, 12:18:01 pm »
Quote
Could you, ttomas, or someone else give a short sample code to explain the use of this.
This is mostly useful for low level access (for example, if you access certain hardware or writing a kernel) or data exchange that requires exact bit structure. With this, you don't need to play with bitwise operators in your code.

I understand it may be useful. Otherwise it would not exist....

And, can you give a very short example-code?

/Kamau

Leledumbo

  • Hero Member
  • *****
  • Posts: 8746
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: Things Lazarus/FPC can do Delphi cannot?
« Reply #49 on: February 06, 2013, 05:05:04 pm »
Quote
And, can you give a very short example-code?
Taken from virtual memory manager of my fpos kernel (not so very short):
Code: [Select]
const
  PageDirVirtAddr = $FFBFF000;
  PageTableVirtAddr = $FFC00000;

type
  UBit3 = 0..(1 shl 3) - 1;
  UBit20 = 0..(1 shl 20) - 1;

  PPageTableEntry = ^TPageTableEntry;

  TPageTableEntry = bitpacked record
    Present, Writable, UserMode, WriteThrough,
    NotCacheable, Accessed, Dirty, AttrIndex,
    GlobalPage: Boolean;
    Avail: UBit3;
    FrameAddr: UBit20;
  end;

  PPageDirEntry = ^TPageDirEntry;

  TPageDirEntry = bitpacked record
    Present, Writable, UserMode, WriteThrough,
    NotCacheable, Accessed, Reserved, PageSize,
    GlobalPage: Boolean;
    Avail: UBit3;
    TableAddr: UBit20;
  end;

  PPageTable = ^TPageTable;
  TPageTable = array [0..1023] of TPageTableEntry;
  PPageDir = ^TPageDir;
  TPageDir = array [0..1023] of TPageDirEntry;
...
var
  PageDir: PPageDir = PPageDir(PageDirVirtAddr);
  PageTables: PPageTable = PPageTable(PageTableVirtAddr);
...
procedure Map(const va, pa: LongWord;
  const IsPresent, IsWritable, IsUserMode: Boolean);
var
  VirtPage, ptIndex: LongWord;
begin
  {$ifdef debug}
  WriteStrLn('Map $' + HexStr(va, 8) + ' to $' + HexStr(pa, 8));
  {$endif}
  VirtPage := va div PageSize;
  ptIndex := PageDirIndex(VirtPage);
  // Find the appropriate page table for 'va'
  if PageDir^[ptIndex].TableAddr shl 12 = 0 then begin
    // The page table holding this page has not been created yet
    with PageDir^[ptIndex] do begin
      TableAddr := AllocPage shr 12;
      Present := True;
      Writable := True;
    end;
    FillByte(PageTables^[ptIndex * 1024], PageSize, 0);
  end;
  // Now that the page table definately exists, we can update the PTE
  with PageTables^[VirtPage] do begin
    FrameAddr := Align(pa, PageSize) shr 12;
    Present := IsPresent;
    Writable := IsWritable;
    UserMode := IsUserMode;
  end;
end;

Kamau

  • Jr. Member
  • **
  • Posts: 67
  • Old Delphi programmer
Re: Things Lazarus/FPC can do Delphi cannot?
« Reply #50 on: February 06, 2013, 06:32:31 pm »
Thanks!

I'll study it tomorrow.

/Kamau

ttomas

  • Full Member
  • ***
  • Posts: 245
Re: Things Lazarus/FPC can do Delphi cannot?
« Reply #51 on: February 07, 2013, 01:45:19 am »
Last year I convert some c headers for use of OpenLDV LonWorks protocol. Some code from C header
Code: [Select]
        typedef union
        {
            struct {
                Bits queue  :4;          /* Network interface message queue      */
                /* Use value of type 'NI_Queue'         */
                Bits q_cmd  :4;          /* Network interface command with queue */
                /* Use value of type 'NI_QueueCmd'      */
                Bits length :8;          /* Length of the buffer to follow       */
            } q;                       /* Queue option                         */
            struct {
                Byte     cmd;           /* Network interface command w/o queue  */
                /* Use value of type 'NI_NoQueueCmd'    */
                Byte     length;        /* Length of the buffer to follow       */
            } noq;                     /* No queue option                      */
        } NI_Hdr;
        typedef struct {
            Bits   tag       :4;        /* Message tag for implicit addressing  */
            /* Magic cookie for explicit addressing */
            Bits   auth      :1;        /* 1 => Authenticated                   */
            Bits   st        :2;        /* Service Type - see 'ServiceType'     */
            Bits   msg_type  :1;        /* 0 => explicit message                */
            /*      or unprocessed NV               */
            /*--------------------------------------------------------------------------*/
            Bits   response  :1;        /* 1 => Response, 0 => Other            */
            Bits   pool      :1;        /* 0 => Outgoing                        */
            Bits   alt_path  :1;        /* 1 => Use path specified in 'path'    */
            /* 0 => Use default path                */
            Bits   addr_mode :1;        /* 1 => Explicit addressing,            */
            /* 0 => Implicit                        */
            /* Outgoing buffers only                */
            Bits   cmpl_code :2;        /* Completion Code - see 'ComplType'    */
            Bits   path      :1;        /* 1 => Use alternate path,             */
            /* 0 => Use primary path                */
            /*      (if 'alt_path' is set)          */
            Bits   priority  :1;        /* 1 => Priority message                */
            /*--------------------------------------------------------------------------*/
            Byte   length;              /* Length of msg or NV to follow        */
            /* not including any explicit address   */
            /* field, includes code Byte or         */
            /* selector Bytes                       */
        } ExpMsgHdr;
It was nightmare to convert to Delphi  >:D

Leledumbo

  • Hero Member
  • *****
  • Posts: 8746
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: Things Lazarus/FPC can do Delphi cannot?
« Reply #52 on: February 07, 2013, 02:03:15 pm »
Quote
It was nightmare to convert to Delphi
Indeed it doesn't support bitpacking, but (byte) packing is possible, though you will have to play with bitwise operations to access fields' value.

 

TinyPortal © 2005-2018