Recent

Author Topic: Different word sizes?  (Read 4873 times)

andyross63

  • Newbie
  • Posts: 2
Different word sizes?
« on: October 19, 2016, 11:14:55 pm »
Since getting a new computer with 64-bit Windows, I'm trying to convert an old TP6 program to run as 32-bit. I was able to get it to compile with little issue, but it cannot read the data file.

The program is a little gas mileage and similar program I wrote ages ago. I still use it. It stores the data in binary format as a record, which is set as this:
Code: Pascal  [Select][+][-]
  1. type
  2.   alpha = string[8];
  3.   b_type = string[11];
  4.   menu_line = string[20];
  5.   d_type = string[35];
  6.   screen_line = string[80];
  7.   path_string = PathStr;
  8.   char2 = string[2];
  9.   gasrec = record
  10.     case info_type: char of
  11.       'X': (last_acc  : word;
  12.             start_mile: longint;
  13.             fil_size  : longint);
  14.       '1': (gas_date  : word;
  15.             odometer  : longint;
  16.             gas_used  : longint;
  17.             price_gal : word;
  18.             price_paid: longint;
  19.             brand     : b_type);
  20.        '2': (spcl_date : word;
  21.              spcl_odom : longint;
  22.              spcl_price: longint;
  23.              spcl_descr: d_type;
  24.              spcl_wrnty: char)
  25.   end;
  26.  

The problem is that it doesn't seem to read it in properly. Looking at the binary data, it looks like the word and longint sizes may not match. I'm not sure how to force word to 16-bit and longint to 32-bit, as it seems to be reading them in as 32-bit and maybe 64-bit?

This is the piece of code that reads the first entry:
Code: Pascal  [Select][+][-]
  1.   with data_info[0] do
  2.     begin
  3.     last_accessed:=last_acc;
  4.     start_mileage:=start_mile;
  5.     file_size:=fil_size
  6.     end;
  7.  

This is what the watch on data_info shows:
Code: [Select]
data_info = {{INFO_TYPE = 88 'X', LAST_ACC = 947, START_MILE = 0, FIL_SIZE = 0, GAS_DATE = 947, ODOMETER = 0, GAS_USE
This is the view of the file:
Code: [Select]
00000000  58 42 E9 C6  B3 03 00 37  00 00 00 00  00 00 00 00  XB·····7········
 00000010  00 00 00 00  00 00 00 00  00 00 00 00  00 00 00 00  ················
 00000020  00 00 00 00  00 00 00 00  00 00 00 00  00 00 00 00  ················
 00000030  31 24 E4 6C  BD 03 00 ED  04 00 00 A1  0D 31 11 00  1$·l·········1··
 00000040  00 05 53 68  65 6C 6C 00  00 00 00 00  00 00 00 00  ··Shell·········
 00000050  00 00 00 00  00 00 00 00  00 00 00 00  00 00 00 00  ················
 00000060  32 3A E4 C0  C3 03 00 4B  45 00 00 17  42 61 74 74  2:·····KE···Batt
 00000070  65 72 79 2F  65 6C 65 63  74 72 69 63  61 6C 20 74  ery/electrical t
 00000080  65 73 74 00  00 00 00 00  00 00 00 00  00 00 00 20  est············
 00000090  31 49 E4 12  C7 03 00 0F  05 00 00 47  0D 30 11 00  1I·········G·0··
 000000A0  00 0A 54 68  6F 72 6E 74  6F 6E 27 73  00 00 00 00  ··Thornton's····
 000000B0  00 00 00 00  00 00 00 00  00 00 00 00  00 00 00 00  ················
 000000C0  31 68 E4 2A  D2 03 00 6E  05 00 00 AF  0E 69 14 00  1h·*···n·····i··
 000000D0  00 09 54 68  6F 72 6E 74  6F 6E 73 00  00 00 00 00  ··Thorntons·····
 000000E0  00 00 00 00  00 00 00 00  00 00 00 00  00 00 00 00  ················
 000000F0  31 7E E4 F6  DD 03 00 37  05 00 00 3B  0F 56 14 00  1~·····7···;·V··
 00000100  00 05 4D 6F  62 69 6C 00  00 00 00 00  00 00 00 00  ··Mobil·········
 00000110  00 00 00 00  00 00 00 00  00 00 00 00  00 00 00 00  ················
 00000120  32 98 E4 C2  E9 03 00 00  1F 01 00 21  42 72 61 6B  2··········!Brak

Basically, last_accessed should be $E942 (59714), start_mileage should be $0003B3C6 (242630, which is divided by 10 later in the program to be 24,263.0), and file_size should be $00000037 (55), which means 55 records.


« Last Edit: October 19, 2016, 11:27:39 pm by andyross63 »

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: Different word sizes?
« Reply #1 on: October 19, 2016, 11:53:24 pm »
You could try
gasrec = packed record
 case info_type ...

andyross63

  • Newbie
  • Posts: 2
Re: Different word sizes?
« Reply #2 on: October 20, 2016, 12:04:58 am »
Thanks. That actually seems to have worked.

Remy Lebeau

  • Hero Member
  • *****
  • Posts: 1314
    • Lebeau Software
Re: Different word sizes?
« Reply #3 on: October 20, 2016, 05:17:58 am »
I'm not sure how to force word to 16-bit and longint to 32-bit

Use UInt16 and Int32 instead.
Remy Lebeau
Lebeau Software - Owner, Developer
Internet Direct (Indy) - Admin, Developer (Support forum)

User137

  • Hero Member
  • *****
  • Posts: 1791
    • Nxpascal home
Re: Different word sizes?
« Reply #4 on: October 20, 2016, 06:07:40 am »
Word is always 16 bit and longint 32-bit on all compilers. Issue was in the record spacing.

Remy Lebeau

  • Hero Member
  • *****
  • Posts: 1314
    • Lebeau Software
Re: Different word sizes?
« Reply #5 on: October 20, 2016, 07:48:25 am »
Word is always 16 bit and longint 32-bit on all compilers.

For now, but who knows what the future will hold. For example, Delphi's Longint is also 32bit on all compilers - EXCEPT for iOS64, where it is 64bit instead. That change took a lot of people by surprise, and required some uncomfortable code updates to account for.
Remy Lebeau
Lebeau Software - Owner, Developer
Internet Direct (Indy) - Admin, Developer (Support forum)

User137

  • Hero Member
  • *****
  • Posts: 1791
    • Nxpascal home
Re: Different word sizes?
« Reply #6 on: October 20, 2016, 08:51:14 am »
I don't believe fpc devs would ever change core types like that. 32-64 bit scaling happens currently on integer type. There is no need for another.

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11458
  • FPC developer.
Re: Different word sizes?
« Reply #7 on: October 20, 2016, 09:55:06 am »
For now, but who knows what the future will hold. For example, Delphi's Longint is also 32bit on all compilers - EXCEPT for iOS64, where it is 64bit instead. That change took a lot of people by surprise, and required some uncomfortable code updates to account for.

One could argue that the Nextgen compilers are simply a different product, just like Delphi.NET once was.

 

TinyPortal © 2005-2018