MPW and Assembly Language Programming for the Macintosh - my erperiences / mini guide

Anything about Mac emulation that does not belong in the above categories.

Moderators: Cat_7, Ronald P. Regensburg

Post Reply
MiaM
Student Driver
Posts: 11
Joined: Wed Oct 23, 2024 8:20 am

MPW and Assembly Language Programming for the Macintosh - my erperiences / mini guide

Post by MiaM »

Hi! First post on the forum, been lurking a while.
Just wanted to post my experiences with reading the book MPW and Assembly Language Programming for the Macintosh from 1987 (available as pdf online).
Maybe this might help someone else who wants to follow along with the examples in this book.

First note:
The book is written for MPW 2. Macintoshgarden clearly states that version 2.0.2 is the one to select for this book, while other sites that share MPW don't state this, and unless you happen to select Macintoshgarden as your source, you won't know this. (Well, you won't know unless you have read this text, obviously).

However at least MPW 3 is required for System 7.x, while MPW 2 only runs in System 6 (or most likely also earlier versions). I really wanted to run System 7 for two reasons. One is multi finder (being able to switch between running applications) and the other is that Basilisk II can't run System 6 as there seems to be no way to turn off 32-bit addressing, and System 6 can only run with 24-bit addressing. The reason that I want to run Basilisk II rather than mini vMac (that can run System 6 fine) is that mini vMac is fixed at the default 9" mac screen resoultion (or other higher resoultions I assume when running the version for emulating a Mac II?), while Basilisk allows resolutions that are suitable for the screen I'm running it on.

The quick work-around is to take all the files from MPW 2, and replace the MPW Shell application (and possibly some of the script files) with files from MPW 3 (I used 3.x).

The more complicated solution is to update the examples in the book. Currently I have only tried the first "Coin" example in Assembler, Pascal and C.

The Pascal version is the simplest to get going, you just have to add Interface.o to the libraries you link with.

The C version is the second simplest to get going. String constants have to start with a backslash and the letter p right after the first quotation mark, to indicate that it's a Pascal string rather than a C string. Also the function PtInRect should be called with (pt,&r) rather than (&pt,&r).

The Assembler version is the hardest to get going. There is a tech note describing the problem:
https://preterhuman.net/macstuff/techno ... pt_16.html
The tech note suggest taking a look at sample.a that comes with MPW 3.x, and that is exactly what I did.
In particular I had to replace the lines

Code: Select all

	MAIN
	PEA		-4(A5)
with
	EXPORT	(QD):DATA
QD	DS	QDGlobals
	MAIN
	PEQ	QD.thePort
I also added more include files, not sure if all are required but I'm including ToolEqu.a, Traps.a, PackMacs.a, QuickEqu.a, SysEqu.a. It's okay if you think that I'm too lazy that I don't try removing them one by one to see which is actually necessary or not. I'll leave this to anyone else :)


A few general words on getting things going:
I use BasiliskII-Windows_19-01-2024.zip, which was the latest when I downloaded it.
I use System 7.5.3, US-American English version.
To get the keyboard working I had to install US-American English keyboard for the host. I'll probably post about this separately in the Basilisk II section of this forum.There is a separate file with some key codes, it seems to be the same file as the one included with Basilisk II and no matter what I do, the keys that produce national characters that aren't in the English alphabet, in my case åäöÅÄÖ, don't work at all in Basilisk II, which prevents me from typing the characters [{,:'" and that obviously makes programming impossible. Unfortunately this makes it necessary to allow pressing the windows key to not only go to Basilisk II but also to the host OS (windows + space bar cycles between keyboard layouts). (Or rather, it's probably possible to enable some systray icon that can be used to switch keyboard layout, but I want to use the keyboard shortcut). This in turn makes some key combinations within the emulation "dangerous". For example option+L is interpreted as Windows+L which locks the screen.


I use Stuffit Expander 6.1.3, A trick worth trying in some cases is to unpack some archive with a disk image within Mac OS, and then copy it to the host file system, and the copy the resource part of that image file over to act as a resource for other image fileBinHex 4.0 and Disk Copy 6.1.3, and those in combination with tools running on the host, and Basilisks ability to mount images and access the host file system, allowed me to open most archives. I can't guarantee that this works for unpacking all versions of MPW though. As a rule of thumb, try to get versions of applications that are in sit or hqx format, and get the iso version of stuffit expander. Attach the stuffit expander iso and install it, and then use the sit or hqx files via the host file system access to install other appliaction. Downloading image files that are packed with non-classic Mac tools might work, but might cause you grief. I'll probably start a separate thread asking a bit about this too.

I also used mini vMac with system 6 to do certain things. System 6 and system 7 can access each others hard disks, so it's easy to add both the mini vMac system 6 hard disk and the Basilisk II system 7 hard disks to both emulators, so they can access each others files. I might misremember but unless I messed things up, it seems like some images work in one but not the other, and/or some images works as added disks to the emulators but not as image files within the emulation using disk copy.

I know that there are plenty of other ways to develop software for vintage Macs, both other tools that run within System 7, and also tools that run on a modern computer where you move the result to an emulator (or real hardware). However I wanted to experience MPW. The anecdote here is that over two decades ago I found the book "On Macintosh Programming: Advanced Techniques" at a thrift store, and over the years I've read it perhaps two or three times, without having much Mac experience (back in the days I used ShapeShifter mostly for running Acrobat Reader and not much else). After reading that book again a few months ago, I decided that I really wanted to try out the MPW experience and whatnot, and here I am :)
MiaM
Student Driver
Posts: 11
Joined: Wed Oct 23, 2024 8:20 am

Re: MPW and Assembly Language Programming for the Macintosh - my erperiences / mini guide

Post by MiaM »

An addition:
You might happen to start any of the MPW tools that takes data from standard input, and can't figure out how to exit them.

Turns out that the end of file character is option-enter or option-shift-enter.

I tried searching for this online but couldn't find it, eventually the book I'm following mentioned this. Before this I had to either force quit the emulation (system 6) or select Shutdown in Finder (System 7)...
User avatar
adespoton
Forum All-Star
Posts: 4473
Joined: Fri Nov 27, 2009 5:11 am
Location: Emaculation.com

Re: MPW and Assembly Language Programming for the Macintosh - my erperiences / mini guide

Post by adespoton »

Thanks for sharing! Under System 6 and earlier, I was using Borland and Symantec compilers (mostly Borland's Turbo Pascal), and so avoided all this. I didn't start using MPW until well into v3 (sometime around 1993/94). However, I used the samples and instructions from the ADC developer's CDs, and that generally worked out OK. But by 1996 I'd moved over to Metrowerks completely, except for the odd dabbling in MPW for projects where the source I was tweaking/building on was already MPW-based. It might be worth checking out the Apple Developer Connection resources for further documentation, as I think there were digital copies of most of the useful updated info from that classic book.
MiaM
Student Driver
Posts: 11
Joined: Wed Oct 23, 2024 8:20 am

Re: MPW and Assembly Language Programming for the Macintosh - my erperiences / mini guide

Post by MiaM »

A tiny update:

I've finished the book. I haven't tried the other examples yet. Or rather I started trying another and found that it also needs updating to run properly.

Anyway, my verdict on the book is that it' seems great for anyone like me who want to get going with using MPW and who knows a bit of 68k assembler.
I have to admit that the reference section either taught me some new things about the 68k, or things that I had forgotten. Anyone reading the book might want to not read every detail in the reference section, but rather just browse it, and continue with some more advanced book (and/or continue with their own experiments).


This book, and also "On Macintosh Programming: Advanced Techniques", mentions that it was possible to order a disk with all programs (and some additional stuff, at least for the MPW and Assembly... book). Are these preserved and available anywhere? I tried searching but can only find the books themselves.

This isn't perhaps the biggest problem in the world since the PDFs seem to have the text OCR:ed and it's possible to copy-paste.


Anyway I started reading "On Macintosh Programming: Advanced Techniques" again and now it makes way more sense :)

If there is any interest, I might take the time to ensure that the examples all work with MPW 3.x under System 7.5.x and maybe upload them here (either as attached files or just as CODE things directly).


@adespoton:
I would assume that the differences between versions would had been a thing also for the Borland and Symantec tools, perhaps? Or maybe not :)
User avatar
adespoton
Forum All-Star
Posts: 4473
Joined: Fri Nov 27, 2009 5:11 am
Location: Emaculation.com

Re: MPW and Assembly Language Programming for the Macintosh - my erperiences / mini guide

Post by adespoton »

MiaM wrote: Tue Nov 19, 2024 7:07 pm @adespoton:
I would assume that the differences between versions would had been a thing also for the Borland and Symantec tools, perhaps? Or maybe not :)
Yeah, the differences were probably a thing... but I generally found those platforms to be a bit more stable; possibly because Borland and Symantec were writing their compilers as cross-platform tools, so they had had longer to mature and didn't respond as quickly to new hardware features available. MPW was always "cutting edge" -- at least, until Metrowerks took over that niche.

Also, Borland and Symantec did a really good job of producing manuals and reference material to go along with each version of their IDEs. Since it all came as one package you could buy at the store, it was a bit different than Apple sending you random mailers that incrementally updated both the software and the documentation. You could get started with whatever package you purchased, instead of having to start at the beginning and track how things changed over time.
User avatar
adespoton
Forum All-Star
Posts: 4473
Joined: Fri Nov 27, 2009 5:11 am
Location: Emaculation.com

Re: MPW and Assembly Language Programming for the Macintosh - my erperiences / mini guide

Post by adespoton »

MiaM wrote: Tue Nov 19, 2024 7:07 pm If there is any interest, I might take the time to ensure that the examples all work with MPW 3.x under System 7.5.x and maybe upload them here (either as attached files or just as CODE things directly).
Might I suggest uploading them to one of The Macintosh Garden, 68k Macintosh Liberation Armyor System 7 Today?
User avatar
sentient06
Apple Corer
Posts: 248
Joined: Tue Mar 29, 2011 8:57 pm
Location: London, UK

Re: MPW and Assembly Language Programming for the Macintosh - my erperiences / mini guide

Post by sentient06 »

MiaM wrote: Tue Nov 19, 2024 7:07 pm This book, and also "On Macintosh Programming: Advanced Techniques", mentions that it was possible to order a disk with all programs (and some additional stuff, at least for the MPW and Assembly... book). Are these preserved and available anywhere? I tried searching but can only find the books themselves.
I was recently looking for certain algorithms from a book from 1995 and I bumped across an app called DiskTracker. The app is used to map the contents of discs like CD-ROMs, ZIP drives, floppies, etc. People created vast catalogues from a bunch of different media and posted on a space in the Macintosh Garden. There are 2 larger files there called "mega catalogues" that I downloaded last week, and there I found the files I were looking for in a random collection. I checked the details and lo, there was a URL pointing towards a backup on a cloud service.

I've found "Advanced Techniques" as the name of a directory in something called "MacFormat 36a (Apr 1996)" (presumably a periodical) and file with that name on "MacFormat 47". They all seem to live in a directory called "HyperStudio Preview." Does that mean anything to you?

If you want to see the catalogue information I got, go to Macintosh Garden and search for "Disk Tracker". Open the "disk-catalog compilations" page. You need system 7 to open DiskTracker. Also, remember to install DiskTracker. If you want to find any of the CDs there.. well, try the info option in DiskTracker and if there's nothing there, at least you know the name of the thing. Some stuff are preserved on the web archive.
User avatar
adespoton
Forum All-Star
Posts: 4473
Joined: Fri Nov 27, 2009 5:11 am
Location: Emaculation.com

Re: MPW and Assembly Language Programming for the Macintosh - my erperiences / mini guide

Post by adespoton »

https://en.wikipedia.org/wiki/MacFormat - MacFormat was, to some extent, the UK version of MacAddict, published by Future Publishing starting in 1993. Each magazine came with a floppy disk at the start, and then starting around 1995 with a CD. It's one of the best curated periodical-based software collections available for the Mac, leaning towards actually useful content instead of just demos from large software publishers and a selection of PD software from Info-Mac's archives as was common with other periodicals. Definitely worth keeping a copy of the DiskTracker index for these handy.
User avatar
sentient06
Apple Corer
Posts: 248
Joined: Tue Mar 29, 2011 8:57 pm
Location: London, UK

Re: MPW and Assembly Language Programming for the Macintosh - my erperiences / mini guide

Post by sentient06 »

OK, that MacFormat 47 is a dead end. That thing is a piece of software, not a document. I found out that the Garden has a LOT of these CDs.

A bit on a tangent, I've bumped into some assembly info online, maybe that interests you guys: https://dev.os9.ca/techpubs/mac/PPCNume ... s-161.html
User avatar
adespoton
Forum All-Star
Posts: 4473
Joined: Fri Nov 27, 2009 5:11 am
Location: Emaculation.com

Re: MPW and Assembly Language Programming for the Macintosh - my erperiences / mini guide

Post by adespoton »

sentient06 wrote: Tue Nov 26, 2024 9:23 pm OK, that MacFormat 47 is a dead end. That thing is a piece of software, not a document. I found out that the Garden has a LOT of these CDs.

A bit on a tangent, I've bumped into some assembly info online, maybe that interests you guys: https://dev.os9.ca/techpubs/mac/PPCNume ... s-161.html
MG also has scans of a number of the magazines that go along with those CDs. Not likely to be useful in this case though.

As for Siddhartha's site, yes, that's some useful PPC assembly in the Inside Macintosh volume :)
MiaM
Student Driver
Posts: 11
Joined: Wed Oct 23, 2024 8:20 am

Re: MPW and Assembly Language Programming for the Macintosh - my erperiences / mini guide

Post by MiaM »

I suspected that those MacFormat search hits were false positives, but I gave DiskTracker a try. Turns out that it needs temp space for the mega files, and it filled my disk and it seems like it didn't clean up it's temp files, and I'm not fully sure where to look for them, Setting the temp to the host file system will most likely not work on a Windows host as it would only work if it happens to place files in disk:C: rather than any other disk: place (for a lack of a better way to express this).

Re the tangent: That seems like a good site to browse Inside Macintosh online!
User avatar
sentient06
Apple Corer
Posts: 248
Joined: Tue Mar 29, 2011 8:57 pm
Location: London, UK

Re: MPW and Assembly Language Programming for the Macintosh - my erperiences / mini guide

Post by sentient06 »

MiaM wrote: Thu Nov 28, 2024 12:51 am Turns out that it needs temp space for the mega files, and it filled my disk and it seems like it didn't clean up it's temp files, and I'm not fully sure where to look for them, Setting the temp to the host file system will most likely not work on a Windows host as it would only work if it happens to place files in disk:C: rather than any other disk: place (for a lack of a better way to express this).
Oops. Sorry about that. I didn't know about that side-effect. If I figure out where the files live, I'll let you know.
Post Reply