Recent

Author Topic: [SOLVED] Files on the Amiga  (Read 2829 times)

chobani

  • New Member
  • *
  • Posts: 24
[SOLVED] Files on the Amiga
« on: February 21, 2023, 01:13:03 pm »
When I try and do basic file operations on the Amiga, I get the result file not found. Is there any notation, folder mapping, no file extensions, or case sensitivity I need to know about?  I can compile fine and run on all the other targets, hopefully I just need to know something basic.

I'm not using any kind of folder structure, all the files live in the same directory. Thank you!

Just something like this:

Code: Pascal  [Select][+][-]
  1. var
  2.   InFile: TextFile;
  3.  
  4. begin
  5.  
  6.     AssignFile(InFile, 'text.txt');
  7.  
  8.     // Open the file for reading
  9.     Reset(InFile);
  10.  
  11.     // Keep reading lines until the end of the file is reached
  12.     while not Eof(InFile) do
  13.     begin
  14.       ReadLn(InFile, S);
  15.       Write(S);
  16.       if Not(Eof(InFile)) then WriteLn;
  17.     end;
  18. end.
  19.  
« Last Edit: February 24, 2023, 09:03:17 pm by chobani »

TRon

  • Hero Member
  • *****
  • Posts: 1508
Re: Files on the Amiga
« Reply #1 on: February 21, 2023, 01:22:48 pm »
When I try and do basic file operations on the Amiga, I get the result file not found. Is there any notation, folder mapping, no file extensions, or case sensitivity I need to know about?  I can compile fine and run on all the other targets, hopefully I just need to know something basic.
Default Amiga used filesystem does not have case sensitive filenames or other special things that you need to be aware of as the RTL should take care of everything automatically for you (path/drive/assign separator conversion etc).

Going by your code I would assume the issue is that you forgot to close the handle. Which means the file is "in use" the second time you try to open it and that might fail. You would have to check IOresult for that.

Edit: an example on how to use IOresult can be found here: https://www.freepascal.org/docs-html/rtl/system/reset.html
« Last Edit: February 21, 2023, 01:35:09 pm by TRon »

chobani

  • New Member
  • *
  • Posts: 24
Re: Files on the Amiga
« Reply #2 on: February 21, 2023, 02:21:01 pm »
I appreciate the quick reply, I just typed that up real quick and forgot the close, but I am closing it and I am checking the file result which is why I know it's not finding it.

This is the actual code and what I get is Error file not found [whatever is passed] only on the Amiga, but works on Linux, Windows, etc.

Code: Pascal  [Select][+][-]
  1. procedure DisplayFile(AFilename: String);
  2. var
  3.   InFile: TextFile;
  4.   S: String;
  5.   Ch: Char;
  6. begin
  7.   // Set the name of the file that will be read
  8.   AssignFile(InFile, AFilename);
  9.  
  10.   // Embed the file handling in a try/except block to handle errors gracefully
  11.   try
  12.     // Open the file for reading
  13.     Reset(InFile);
  14.  
  15.     // Keep reading lines until the end of the file is reached
  16.     while not Eof(InFile) do
  17.     begin
  18.       ReadLn(InFile, S);
  19.       Write(S);
  20.       if Not(Eof(InFile)) then WriteLn;
  21.     end;
  22.  
  23.     // Done so close the file
  24.     CloseFile(InFile);
  25.   except
  26.     on E: EInOutError do
  27.     begin
  28.       WriteLn('Error reading "' + AFilename + '": ' + E.Message);
  29.       WriteLn('Hit a key to continue');
  30.       Ch:=ReadKey;
  31.     end;
  32.   end;
  33. end;    
  34.  

chobani

  • New Member
  • *
  • Posts: 24
Re: Files on the Amiga
« Reply #3 on: February 21, 2023, 02:22:22 pm »
It also fails with that result on first call.

TRon

  • Hero Member
  • *****
  • Posts: 1508
Re: Files on the Amiga
« Reply #4 on: February 21, 2023, 02:26:44 pm »
What happens if you use a fully qualified filename e.g. with drive (or assign):path/filename.extension ?

I do not have my Amiga or emulator around here to be able to check/test atm so unless someone else is able to chime in you would have to wait a at least a day for verification from my hand.

BTW: which exact version of Free Pascal are you using that seems to show this behaviour ?
« Last Edit: February 21, 2023, 02:30:32 pm by TRon »

chobani

  • New Member
  • *
  • Posts: 24
Re: Files on the Amiga
« Reply #5 on: February 21, 2023, 10:12:23 pm »
I'll have a test ready to try that later today, but you bring up a good point. I am using a VM that someone set up for cross compile to Amiga and it's using 3.0.0. I started with that just to make sure it was possible, but I could try and update the box or do a cross compile install on my own if you think it's the FPC version causing an issue. I'll report back tonight on using the fully qualified name.

dseligo

  • Hero Member
  • *****
  • Posts: 1036
Re: Files on the Amiga
« Reply #6 on: February 21, 2023, 10:49:07 pm »
I don't know Amiga's file system, but you may try something like this to see what fpc see of files:
Code: Pascal  [Select][+][-]
  1. var sr: TSearchRec;
  2.  
  3. If FindFirst ('*', faAnyFile, sr) = 0 then
  4.   repeat
  5.     Writeln (sr.Name);
  6.   until FindNext(sr) <> 0;
  7.  
  8. FindClose(sr);

Maybe you have some attributes set on file that prevent reading it?

chobani

  • New Member
  • *
  • Posts: 24
Re: Files on the Amiga
« Reply #7 on: February 21, 2023, 11:55:38 pm »
That's a great idea, thank you. I'll try that too.

TRon

  • Hero Member
  • *****
  • Posts: 1508
Re: Files on the Amiga
« Reply #8 on: February 22, 2023, 12:10:48 am »
A word of warning wrt using FindFirst/FindNext combination: back in those days there was disambiguity when to call FindClose  (always or only after a successful findfirst). I do not remember exactly when that was fixed.

TRon

  • Hero Member
  • *****
  • Posts: 1508
Re: Files on the Amiga
« Reply #9 on: February 22, 2023, 12:21:24 am »
I am using a VM that someone set up for cross compile to Amiga and it's using 3.0.0.
You are probably referring to ALB42's virtual Lazarus setup, see https://blog.alb42.de/virtual-lazarus/

Quote
I started with that just to make sure it was possible, but I could try and update the box or do a cross compile install on my own if you think it's the FPC version causing an issue. I'll report back tonight on using the fully qualified name.
It is also possible to update the FPC installation in your VM, although in that case I would probably opt for making a second install for FPC (in order to not break anything else that relies on the specifc FPC version 3.0.0). For an updated version of FPC, see https://blog.alb42.de/fpc-amigaaros-m68k/

Building your own (up to date) cross compiler has preference. In case you run into issues then make sure to post the build-log with the error (besides mentioning your host configuration, build options and what binutils (and version) you use, gnu or vasm/vlink).

TRon

  • Hero Member
  • *****
  • Posts: 1508
Re: Files on the Amiga
« Reply #10 on: February 22, 2023, 08:43:15 am »
@chobani:
Verified your code to be working with Free Pascal 3.2.2 on OS3.x (see attached picture).

chobani

  • New Member
  • *
  • Posts: 24
Re: Files on the Amiga
« Reply #11 on: February 22, 2023, 03:44:15 pm »
Ah!  Thank you so much!  Part of my issue is that I am doing this for Amiga enthusiasts and I haven't been able to find my way around an Amiga. So I am taking your suggestions, compiling them, and then asking for them to be tested on Amigas. So I guess what I am going to have to do is figure out how to make my own cross compiler instead of depending on ALB42's (you were right on that as well). I just have not had very much success setting up cross compiler and was trying to go the path of least resistance.

Bogen85

  • Hero Member
  • *****
  • Posts: 590
Re: Files on the Amiga
« Reply #12 on: February 22, 2023, 04:19:18 pm »
All this makes me want to buy the kickstart ROM images and get an emulator.

This is very cool!

PascalDragon

  • Hero Member
  • *****
  • Posts: 5197
  • Compiler Developer
Re: Files on the Amiga
« Reply #13 on: February 22, 2023, 09:44:31 pm »
All this makes me want to buy the kickstart ROM images and get an emulator.

You could also use AROS which provides the same API ;)

TRon

  • Hero Member
  • *****
  • Posts: 1508
Re: Files on the Amiga
« Reply #14 on: February 23, 2023, 06:06:18 am »
Ah!  Thank you so much!  Part of my issue is that I am doing this for Amiga enthusiasts and I haven't been able to find my way around an Amiga.
You're welcome.

An A500 mini or emulator will do as well.

Quote
So I am taking your suggestions, compiling them, and then asking for them to be tested on Amigas.
Then I would assume the Amiga enthusiasts can test as well  :P

Quote
So I guess what I am going to have to do is figure out how to make my own cross compiler instead of depending on ALB42's (you were right on that as well). I just have not had very much success setting up cross compiler and was trying to go the path of least resistance.
On the same page from ALB42 is also a more up to date docker container.

Personally I have no experience with it but you might want to try it. The time it cost me to understand/setup docker container I find better spend compiling a cross-compiler and configure things the way I like them to be but that is just a personal preference.

In case you do wish to create your own cross compiler then ALB42 has that covered as well, see https://fpcamigawiki.alb42.de/index.php?title=Installation_Classic

I do not know what kind of experience you have with setting up cross-compilers but in case those instruction raises more question then it solves then feel free to drop a note.

The only thing I would do differently from those instructions is to not depend on your distributions package manager to install Free Pascal, but instead setup everything yourself from source. It circumvents your distro from updating your FPC installation unexpectedly (yes, I know you can prevent that), it also circumvent your distro from dictating the locations where to put all the Free Pascal related files. On top of that, creating your own setup allows you to place it everywhere you want to (home directory for example) or copy it over to another installation/distro.
« Last Edit: February 23, 2023, 06:24:14 am by TRon »

 

TinyPortal © 2005-2018