• Hello MLAers! We've re-enabled auto-approval for accounts. If you are still waiting on account approval, please check this thread for more information.

(newbie) write/read/create EXE files in BASIC in 68k mac

plouf

6502
hello
as you understand i have NO knowledge in Macos peculiarities :)

i am experiment with old mac, System 6/7.
i am using FutureBasic and QuickBasic, and try to create some files.
in other OSes, i just use
OPEN "O",1,"filename.txt"
print #1,"tralalala"
CLOSE #1

in Macos a file IS created with proper size, i can see data inside has "tralala" but is not recognised as TEXT neither i can open it with text viewer ?
i have try line "DEF FILE = "TEXT"" , in futurebasic with no success

thanx fo any hint !
 
in Macos a file IS created with proper size, i can see data inside has "tralala" but is not recognised as TEXT neither i can open it with text viewer ?
It's because early Mac OS doesn't use extensions to denote file types. Instead, every Mac OS file is like a file bundle, containing two files: one for data and the other for resources and metadata. The file type is stored in the metadata as a 4-byte / 4-character string along with it's creator code, which is also a 4 byte/ 4 character string. This allows any file to be opened by the right application, and also opened by any other application that also knows the file type.

You would need to use ResEdit (2.1.3 is fine) and choose File:Get File/Folder Info to change the file type to TEXT. It may be possible to define that from Basic (and perhaps that's what the DEF FILE = "TEXT" is supposed to do), but my guess is that whatever you think your code is doing, it's not setting the right file type. Also, you'll want to open it with SimpleText or TeachText first on System 6/7.

-cheers from Julz
 
thanx for quick reply
i was trying to open with teachtext but file requestor do not even list it !

i found tha using
DEF OPEN = "TEXT"
OPEN "OD",1,"text.txt"
O = out / D = data fork according to manual
it does,at least, create something that asking "this is not found app try teachtext"
and text file displayed correct inside there
also when using File=> open in teachtext it DOES diplayed in file requester !

however this creates 2 more, a least, queries,
how to know, if copy , unknown files e.g executable !? how to correct set ?
where, and should ? copy resource fork too !
 
It sounds like you could do with a brief introduction to how file types work on the Mac. I don't use BASIC at all for development but hopefully this might help.

Each file has two four-character codes associated with it, called the type and the creator. The type indicates what kind of data is in the file - text files, for example, have the type TEXT. The creator indicates what application created the file: for example, files created with TeachText have the creator ttxt.

The reason why these are tracked separately is so that when a user double-clicks on a file, it will open in the application that created it, regardless of the file type. So if I had multiple applications that generated text files - say Microsoft Word, BBEdit and TeachText, when I double-click on a text file it will open in the application that I used to make it. This is a big advantage over any system where you only track the file type and have to manage file type associations.

So what you are seeing here is that your BASIC program is creating a file that has the TEXT type but a different creator. You can open it in TeachText using File -> Open, or the OS might offer to open it in TeachText as a fallback. But if you want to make it open in TeachText by default, you need to set its creator to 'ttxt'.

how to know, if copy , unknown files e.g executable !? how to correct set ?

To copy a file, you need to copy both forks (if they exist) and the file metadata. If you want to do this reliably you're probably going to need to call the File Manager API directly; there may not be suitable tools to manipulate the file metadata in BASIC.

where, and should ? copy resource fork too !

The resource fork is an integral part of the file. If it is present you need to copy it.
 
thanx for quick reply <snip> and text file displayed correct inside there
You're welcome!
however this creates 2 more, a least, queries,

how to know, if copy , unknown files e.g executable !? how to correct set ?
where, and should ? copy resource fork too !
Hmm, in Early Mac OS, Exe files don't exist as such. A better question is to ask: "How do I create an Application"? In this era, Applications are stored entirely in the resource fork as multiple types of resources, but most importantly, CODE resources, which contain the application code.

This too, is different to a traditional EXE. On that era of Mac, when an application is launched (e.g. by double-clicking it or selecting it from the Finder and choosing File:Open) the Mac allocates heap space for the application code and its data. At first there's no CODE resources in that heap, except for CODE resource 0, which is essentially a jump table listing all the exported function addresses in the application + loader code if the respective code hasn't been loaded yet. It then calls the Main entry, which because it's not yet loaded; causes CODE 1 to be loaded in the next free heap space; then the Jump table for CODE 1 routines get fixed up to point to the actual addresses, including Main and then finally it can call Main.

At that point, Main can call any function in its code segment, but as soon as it tries to call something in a different, unloaded code segment, the same process happens: the new code segment gets loaded into the next free heap space; its bit of the jump table gets fixed up and then it can call it properly. When the application gets back to a CODE 1 function (probably Main), it calls UnloadSeg which marks other CODE segments as being purgeable or moveable if memory is tight.

It all functions as a clever overlay system so that early Mac applications can reduce space. But it makes 'EXE's far more complex than in a simple Linux, MSDOS or Windows app.
 
Back
Top