• Updated 2023-07-12: Hello, Guest! Welcome back, and be sure to check out this follow-up post about our outage a week or so ago.

Autorun - System 1-6 INIT System Extension

Hello Everyone,

I am looking into creating a small system extension that mimics "autorun" on windows for System 1 to System 6. I have scoured the internet and I cannot find an example for anything pre system 7 written in C or C++. I am not against writing code in another language, but what I found has very minimal explanation on how it works, how to build it and how it is installed. I really want to dive into this, but I can't seem to find enough information to fully understand the process. The goal will to have this work from System 1 to OS 9.2.2, but I want to start with the one which has much less documentation (1-6)

What I would love to have:

A small working example code example that beeps when a Disk/CD/HardDrive is mounted/detected (C or C++ if possible, but I will take anything I can get)
What tools to use to build it.
How to install it on System 1-6

I know I am asking for a lot, but I have never programmed on a classic mac before and I am really in the dark. I have recently compiled Mini vMac from source and have a platform to work on. I have also been reading lots of material over at https://vintageapple.org/macprogramming/ which helps me understand basic programming on a mac classic. It is very familiar, which is good, but the only thing I can find about INIT functions is in Pascal and I don't really understand how it works (or install/build it)

I apologize for being clueless about all of this, I really wanted to be more prepared than I am before I started asking questions, but I have spent days looking through material, and I can't find any documentation on this.

Thanks,

 
Last edited by a moderator:

LaPorta

Well-known member
I am trying to figure out just what you want to do with this: you want a program that will open something automatically when a disk is inserted?

 
Yes, so disk is inserted, it runs the application automatically, no human interaction needed. Possibly a file on the disk required for the autorun to read, much like windows autorun.inf.

I have seen the disc menu open as a folder, but I would like an automated way to start the app on the disk inserted itself,
If there is another way I don't know about, that would be great!

 
Last edited by a moderator:

LaPorta

Well-known member
I don’t think it exists you are right. There’s no OS provision for it so it would be very difficult I think.

 

Crutch

Well-known member
Am I understanding correctly that you want to boot from disk A, then you want to be able to insert disk B, and some program on disk B (e.g. an application in the root directory called “Autorun”) is run automatically?

To do that, you would need something installed and running on disk A.

Pre-System 7, the canonical way to do this would be to write an INIT that starts a DRVR that sits in the background and uses EventAvail() or similar to poll for the presence of a diskInsertedEvt, then gracefully checks the inserted disk for the desired file name and runs the app if it exists.  Of course, in a non-MultiFinder environment, this would mean quitting the current application, which I assume you don’t want.  Or did you want the code on disk B to be in the form of a DRVR or something else that could run without quitting the foreground app?  Or were you thinking this would only run under MultiFinder?  If you want a UI fort your INIT, you’d have to write a CDEV also.  None of this is particularly simple and I’m not sure I’d recommend it as a first project in Classic Mac Toolbox programming.  

In System 7, I would personally do this by putting a small application in the Startup Items folder and having it drop to the background on boot.  It could then silently poll for a diskInsertedEvt and launch the appropriate app on disk B, if it exists, gracefully, perhaps even launching it into the background if you like.  This is much easier to do and the app itself could have a UI you could pull up from a menu item.  I wrote a freeware screensaver like this for PowerPC Macs called FirePower using a similar approach back in the day, which I now see is not on the Garden, I will have to fix that ....

I can add some detail on how to do either of these things if you’d like (it’s been a while obviously).

EDIT: it occurs to me my first approach might not actually work because there’s no guarantee someone else (the foreground application) didn’t process the diskInsertedEvt first. You might need to patch a trap to do this, perhaps PBMountVol (just shooting from the hip here), then set a flag or something to allow your driver’s Prime function to notice that a volume has been mounted. This would need to be done from assembly language. Or probably better, skip the event handling and just occasionally poll through the list of all mounted volumes to see if there’s a new one you hadn’t noticed before. You would still need to do this from a DRVR in System 6. 

 
Last edited by a moderator:
You need to read the first 2 volumes of Inside Macintosh.
Thanks! I will take a look at these in particular, are there specific chapters or sections I should pay the most attention to? Do these books in particular describe INIT and System Extensions, or is it a general life cycle of a program on a mac?
 

Am I understanding correctly that you want to boot from disk A, then you want to be able to insert disk B, and some program on disk B (e.g. an application in the root directory called “Autorun”) is run automatically?

To do that, you would need something installed and running on disk A.

Pre-System 7, the canonical way to do this would be to write an INIT that starts a DRVR that sits in the background and uses EventAvail() or similar to poll for the presence of a diskInsertedEvt, then gracefully checks the inserted disk for the desired file name and runs the app if it exists.  Of course, in a non-MultiFinder environment, this would mean quitting the current application, which I assume you don’t want.  Or did you want the code on disk B to be in the form of a DRVR or something else that could run without quitting the foreground app?  Or were you thinking this would only run under MultiFinder?  If you want a UI fort your INIT, you’d have to write a CDEV also.  None of this is particularly simple and I’m not sure I’d recommend it as a first project in Classic Mac Toolbox programming.  

In System 7, I would personally do this by putting a small application in the Startup Items folder and having it drop to the background on boot.  It could then silently poll for a diskInsertedEvt and launch the appropriate app on disk B, if it exists, gracefully, perhaps even launching it into the background if you like.  This is much easier to do and the app itself could have a UI you could pull up from a menu item.  I wrote a freeware screensaver like this for PowerPC Macs called FirePower using a similar approach back in the day, which I now see is not on the Garden, I will have to fix that ....

I can add some detail on how to do either of these things if you’d like (it’s been a while obviously).
I knew it would be hard the moment I started looking into it! I don't mind struggling, I just had no idea about terminology like DRVR or diskInsertedEvt etc.. It is hard (for me at least) to read a 500 page book where most of the information is straight forward or obvious to pull out or identify the nuggets of information I need for this project :) .

I was thinking more of, if the disk has a file on it named "autorun" then I read that and run the program labeled in there, so Disk B, wouldn't have it, I actually wasn't thinking in terms of multiple disks that is a VERY good point. System 7 did seem a lot easier to code for.

Maybe I will make a running app first and then try to convert it into a System Extension for OS 1 - 6.

Thanks for the information!

 

Mu0n

Well-known member
Do you mean to mimick this behavior:

Mac is turned on and shows the insert disk icon.

You insert a disk with your program

Instead of booting to the Finder, it opens your custom app immediately

Kind of like how many games behaved back in 1984-1987 - bootable and automatic. They often didn't carry a full fledged Finder version and rather relied on mini-Finder or multifinder to save space.

 

Crutch

Well-known member
[SIZE=1.4rem]Maybe I will make a running app first and then try to convert it into a System Extension for OS 1 - 6.[/SIZE]


I think that’s a good approach (start by writing an app for Sys 7), most of what you need in terms of how to drop an app into the background will be in Inside Mac Volume VI.  The basics in terms of event handling will be in Volume I, and the File Manager stuff to look for “Autorun” on an inserted disk will be in Volume II.  One thing to be aware of is that writing Extension (INIT) is very different from running an app ... INITs can’t have a UI (you need a CDEV/control panel for that) and don’t get to run an event loop (you need a DRVR for that) so turning any Sys 7 app into INIT/CDEV/DRVR for System 6 will be a major project in itself.

 

Crutch

Well-known member
Do you mean to mimick this behavior:

Mac is turned on and shows the insert disk icon.

You insert a disk with your program

Instead of booting to the Finder, it opens your custom app immediately

Kind of like how many games behaved back in 1984-1987 - bootable and automatic. They often didn't carry a full fledged Finder version and rather relied on mini-Finder or multifinder to save space.
Oh, you can do that with “Set Startup...” in the Special menu or just by naming your app “Finder”... Airborne! did that as I recall.  The application file was called “Finder” and they included the text “Airborne!” in its icon.

 

Mu0n

Well-known member
Oh, you can do that with “Set Startup...” in the Special menu or just by naming your app “Finder”... Airborne! did that as I recall.  The application file was called “Finder” and they included the text “Airborne!” in its icon.
Wow, that simple? I forgot it was possible. Maybe I knew then forget years later.

 

LaPorta

Well-known member
Yes that works easily enough, that is just built in with "Set Startup..."

However, even if you wrote some kind of INIT, how would you figure out how to start the other application? What if the application is nested in a folder? What if there are multiple applications? How would it know what one to start?

I could conceive of a two-part system possibly: have the INIT search for a certain text document that you would put on the floppy you want the application to run on that points it to that specific application. That could be possible. Otherwise, I'm not sure how it would know which application to open.

 
Thanks for all of the information everyone! I think I found what I needed with all of this new info.
https://www.gryphel.com/c/minivmac/recipes/lnrphntm/index.html

AutoQuit even comes with it's own source, so I can take a look at it as well.

I still want to make my own program, I may not need to do this particular program, but I will play around with this recipe and go from there.

Thanks again for all of the information, I still plan on reading a ton about how the OS works as I am simply interested!

What an amazingly positive forum, that is rare these days :)

 
Last edited by a moderator:

Dog Cow

Well-known member
Thanks! I will take a look at these in particular, are there specific chapters or sections I should pay the most attention to? Do these books in particular describe INIT and System Extensions, or is it a general life cycle of a program on a mac?
Yes, you should read the chapters on the Event Manager and File Manager at least, as that will show you how to detect disk-inserted events and how to mount and access volumes.

INIT and System Extensions are the same thing. An early chapter in Inside Macintosh will show you the basic structure of a Macintosh application. What makes Inside Macintosh difficult is that it's a reference, not a tutorial, so there is very little sample code. And the sample code that you'll find is either in Pascal or 68000 Assembly.

I recommend MacTutor as a great source of sample code.

 
Yes, you should read the chapters on the Event Manager and File Manager at least, as that will show you how to detect disk-inserted events and how to mount and access volumes.

INIT and System Extensions are the same thing. An early chapter in Inside Macintosh will show you the basic structure of a Macintosh application. What makes Inside Macintosh difficult is that it's a reference, not a tutorial, so there is very little sample code. And the sample code that you'll find is either in Pascal or 68000 Assembly.

I recommend MacTutor as a great source of sample code.
Yeah, I noticed how much information they have, they really go into detail about everything. For the most part it seems like any other modern-ish computer, so getting through the stuff where I think to myself "yeah...duh, of course that is how it works" is the frustrating part. But then again, back then this was cutting edge, and I can't fault them for having too much detail  :)

Yeah, it looks like I may have to figure out the binary or logic equivalence of Pascal to C/C++ via learning Pascal... which I am down for, but it may be that any project I attempt may take much longer, haha.

Thanks for more specifics, I am going to try my best to get through ALL of it! I will check out MacTutor too.

INITs are described in the Start Manager chapter of Inside Macintosh: Volume V.  (And previously, in legacy Technical Note #14.)

Or here:  http://dec8.info/Apple/macos8pdfs/InsideMacintosh_PDF/OperatingSystemUtilities/Start_Mgr.pdf
Fantastic, thanks for the specific chapters, I am sure this will make much more sense if I see this and look at code at the same time.

 
Last edited by a moderator:

Dog Cow

Well-known member
 I will check out MacTutor too.
MacTutor was a programming magazine. The articles are now available online at MacTech.com

All the source code samples from the magazine articles were compiled on to a CD. I forget the name of the compilation, but if you search around, you should find it.

 

dr.zeissler

Well-known member
Hi there, where is the definition what files are startet in the system-folder on system6 ?
I did a backup to an external harddrive by dragging the drive icon to an external scsi-hdd.
After a restart the system still boot's from that external backup even if the "system-folder" is not in root and therefore in a directory that is called like the original harddisk. so "Macintosh HD / System folder".
After writing the backup back to the new partitioned disk the system6 boots up but does not load any content of the system folder. What have I done wrong and how can I fix this, or did I catchup a virus?
 
Top