Recent

Author Topic: Progmem from Pascal  (Read 2025 times)

dseligo

  • Hero Member
  • *****
  • Posts: 578
Progmem from Pascal
« on: January 17, 2022, 05:01:42 am »
I have this definition:

Code: Pascal  [Select][+][-]
  1. type
  2.   TMenuItem = record
  3.     miLevel: Byte;
  4.     miText:  String[20];
  5.   end;
  6.  
  7.   TMenuDef = array of TMenuItem;
  8.  
  9. const
  10.   glavni_izbornik: TMenuDef = (
  11.     (miLevel: 1; miText: '100 Edit'),
  12.     (miLevel: 2; miText: '110 Cut'),
  13.     (miLevel: 2; miText: '120 Copy')
  14.   ); section '.progmem';
  15.  
  16. var
  17.   FMenu: Pointer;
  18.   s:String;

I was hoping that this would work, but I knew there was only a slim chance:

Code: Pascal  [Select][+][-]
  1. FMenu := @glavni_izbornik;
  2. Count := Length(TMenuDef(FMenu));
  3. s := TMenuDef(FMenu)[1].miText;
  4.  

Is there a simpler way to access data in progmem from Pascal, or is using LPM instruction directly only option?
Can I at least get number of elements in array (at compile time)?

Thaddy

  • Hero Member
  • *****
  • Posts: 11517
Re: Progmem from Pascal
« Reply #1 on: January 17, 2022, 06:13:18 am »
Quote
Can I at least get number of elements in array (at compile time)?
Length(TMenuDef); you can set the length with SetLength()

Note the const structure you use is probably wrong.
In general you can get at the resources Through Tmenu.Items[].TMenuItem
Through Tmenu.Items[].TMenuItem
Count := TMenu.Items.count or submenu: TmenuItem.Items.Count
Name is TMenu.Items[index].Name etc. You can iterate through all menu entries
« Last Edit: January 17, 2022, 12:07:55 pm by Thaddy »
Путин преступник. Россияне дезинформированы.

ccrause

  • Hero Member
  • *****
  • Posts: 568
Re: Progmem from Pascal
« Reply #2 on: January 17, 2022, 07:09:09 am »
Currently there is no build-in compiler support to access data not in RAM. So you have to write your own access function, for progmem, using LPM.

There is a merge request to implement support for progmem and eeprom sections. But this doesn't have a high priority on the core team's list.

 

TinyPortal © 2005-2018