MPWでClassic Mac OSなプログラムをビルドする
(歴史と伝統のある開発プラットフォームを斜めから見る企画。MS-CとMPW、Watcomかな。HX DOS Extenderが見事に消滅していてショックだったのでできるうちから。。)
MPW(Macintosh Programmer's Workshop)はApple公式のClassic MacOSのための開発環境で、MPW Shellと呼ばれる独特なUIを軸に構築されている。
基本的なインターフェースはシンタックスハイライト等を備えたテキストエディタであり、実行したいコマンドにカーソルを合わせてRETURNキーを叩くことでコマンドが実行でき、結果がその場に挿入される。
Appleはftpサーバをシャットダウンしてしまったので、インストールする簡単な方法は無い。そもそも、OS X 10.5以降にはClassicも無いので良い実行環境も無いが。。
サンプルのビルド
空の書類を作りchdirする。chdirするコマンド(SetDirectory)も有るが、メニューから選ぶなら:
そして、"BuildProgram -e TESample"と入力してRETURNするか左上の"MPW Shell"と書かれている部分をクリックする。
サンプルのinstructionsには、一度makeを実行してスクリプトを生成し、それを実行する手順が書かれているが、BuildProgramなら一度でこの手順を実行できる。
プログラム環境
Classic Mac OSにはコンソールに相当する概念が存在せず、プログラムは基本的にGUIを持つことが期待されている。このため、プログラムを書くためのハードルはそれなりに高い。ただし、MPWはいくつかの配慮を提供している。
MPW Shellは一種のコマンドライン環境を構成する。いわゆるCのstdioと、main(argc,argv[])を提供することで、MPW Shell上で使用できるコマンドを実装することができる。
また、MPWにはSIOWと呼ばれるライブラリが付属しており、stdioを使ったプログラムに簡単なログウインドウを付けることでMacintoshアプリケーションを直ぐに仕立てることができるようになっている。
(gets()のためのプロンプトが出ているところ。stderrは色分けされる。)
(メトロワークスのCodeWarriorではSIOWよりインライン入力やファイルリダイレクトが可能になるなど多少改善されたSIOUXが提供されていた。PhotoShopで出現したりしたらしい http://apatheticthursday.net/2007/05/30/photoshop-fails-to-assert/ )
プログラミング環境はWindowsとかXとよく似ている。つまり、ライブラリプレフィクスを持つCamlCaseなC APIと、イベントドリブンなプログラミングを行う。ただし、MacはPascalで書かれたので、コールバック類はPascal呼び出し規約を使用し、いわゆるToolbox APIはPascal文字列(str255型 - pascalの文字列は先頭1バイトで長さを表わす)を取る。
ドキュメンテーションは基本的に書籍 Inside Macintosh や技術情報でカバーされる。ヘッダにも多少のリファレンスは有るが、あまり充実していない。技術情報(の一部)は https://developer.apple.com/legacy/library/navigation/ から今でも閲覧できる(最古のものは1984年!)。
例えばUI関連の機構は以下のInside Macintoshに纏まっている:
- https://developer.apple.com/legacy/library/documentation/mac/pdf/MacintoshToolboxEssentials.pdf
- https://developer.apple.com/legacy/library/documentation/mac/pdf/MoreMacintoshToolbox.pdf
... 当然の如くサンプルコードはPascalとなっている。後期のIMでは、Cも見られる。
- https://developer.apple.com/legacy/library/documentation/mac/pdf/ImagingWithQuickDraw.pdf
- https://developer.apple.com/legacy/library/documentation/mac/pdf/Text.pdf
- https://developer.apple.com/legacy/library/documentation/mac/pdf/Memory/Memory_Preface.pdf
- https://developer.apple.com/legacy/library/documentation/mac/pdf/Memory/Intro_to_mem_mgmt.pdf
- https://developer.apple.com/legacy/library/documentation/mac/pdf/Memory/Memory_Manager.pdf
- https://developer.apple.com/legacy/library/documentation/mac/pdf/Memory/Virtual_Memory.pdf
- https://developer.apple.com/legacy/library/documentation/mac/pdf/Memory/Memory_Mgmt_Utilities.pdf
- https://developer.apple.com/legacy/library/documentation/mac/pdf/Processes/preface.pdf
- https://developer.apple.com/legacy/library/documentation/mac/pdf/Processes/Intro_to_Procs_Tasks.pdf
- https://developer.apple.com/legacy/library/documentation/mac/pdf/Processes/Process_Manager.pdf
- https://developer.apple.com/legacy/library/documentation/mac/pdf/Processes/Time_Manager.pdf
- https://developer.apple.com/legacy/library/documentation/mac/pdf/Processes/Vertical_Retrace_Mgr.pdf
- https://developer.apple.com/legacy/library/documentation/mac/pdf/Processes/Notification_Manager.pdf
- https://developer.apple.com/legacy/library/documentation/mac/pdf/Processes/Segment_Manager.pdf
- https://developer.apple.com/legacy/library/documentation/mac/pdf/Processes/Shutdown.pdf
- https://developer.apple.com/legacy/library/documentation/mac/pdf/Sound/preface.pdf
- https://developer.apple.com/legacy/library/documentation/Mac/pdf/Sound/Sound_TOC.pdf
- https://developer.apple.com/legacy/library/documentation/Mac/pdf/Sound/Introduction_to_Sound.pdf
- https://developer.apple.com/legacy/library/documentation/Mac/pdf/Sound/Sound_Manager.pdf
- https://developer.apple.com/legacy/library/documentation/Mac/pdf/Sound/Sound_Input_Manager.pdf
- https://developer.apple.com/legacy/library/documentation/Mac/pdf/Sound/Speech_Manager.pdf
- https://developer.apple.com/legacy/library/documentation/Mac/pdf/Sound/Sound_Components.pdf
- https://developer.apple.com/legacy/library/documentation/Mac/pdf/Sound/Audio_Components.pdf
- https://developer.apple.com/legacy/library/documentation/mac/pdf/Operating_System_Utilities/Preface.pdf
- https://developer.apple.com/legacy/library/documentation/mac/pdf/Operating_System_Utilities/Gestalt_Manager.pdf
- https://developer.apple.com/legacy/library/documentation/mac/pdf/Operating_System_Utilities/System_Error.pdf
- https://developer.apple.com/legacy/library/documentation/mac/pdf/Operating_System_Utilities/MLU.pdf
- https://developer.apple.com/legacy/library/documentation/mac/pdf/Operating_System_Utilities/DT_And_M_Utilities.pdf
- https://developer.apple.com/legacy/library/documentation/mac/pdf/Operating_System_Utilities/Control_Panels_Ext.pdf
- https://developer.apple.com/legacy/library/documentation/mac/pdf/Operating_System_Utilities/OS_Queues.pdf
- https://developer.apple.com/legacy/library/documentation/mac/pdf/Operating_System_Utilities/PRAM_Utilities.pdf
- https://developer.apple.com/legacy/library/documentation/mac/pdf/Operating_System_Utilities/Trap_Manager.pdf
- https://developer.apple.com/legacy/library/documentation/mac/pdf/Operating_System_Utilities/Start_Mgr.pdf
- https://developer.apple.com/legacy/library/documentation/mac/pdf/Operating_System_Utilities/Package_Mgr.pdf
- https://developer.apple.com/legacy/library/documentation/mac/pdf/PPC_System_Software/preface.pdf
- https://developer.apple.com/legacy/library/documentation/mac/pdf/PPC_System_Software/Intro_to_PowerPC.pdf
- https://developer.apple.com/legacy/library/documentation/mac/pdf/PPC_System_Software/Mixed_Mode_Mgr.pdf
- https://developer.apple.com/legacy/library/documentation/mac/pdf/PPC_System_Software/Code_Frag_Mgr.pdf
- https://developer.apple.com/legacy/library/documentation/mac/pdf/PPC_System_Software/Exception_Mgr.pdf
- https://developer.apple.com/legacy/library/documentation/Mac/pdf/Interapplication_Communication/IAC_Preface.pdf
- https://developer.apple.com/legacy/library/documentation/Mac/pdf/Interapplication_Communication/Intro_to_IAC.pdf
- https://developer.apple.com/legacy/library/documentation/Mac/pdf/Interapplication_Communication/Edition_Manager.pdf
- https://developer.apple.com/legacy/library/documentation/Mac/pdf/Interapplication_Communication/Intro_to_Apple_Events.pdf
- https://developer.apple.com/legacy/library/documentation/Mac/pdf/Interapplication_Communication/Responding_to_AEs.pdf
- https://developer.apple.com/legacy/library/documentation/Mac/pdf/Interapplication_Communication/Creating_and_Sending_AEs.pdf
- https://developer.apple.com/legacy/library/documentation/mac/pdf/Interapplication_Communication/Specify_And_Find_AE_Objs.pdf
- https://developer.apple.com/legacy/library/documentation/mac/pdf/Interapplication_Communication/Intro_to_Scripting.pdf
- https://developer.apple.com/legacy/library/documentation/mac/pdf/Interapplication_Communication/AE_Term_Resources.pdf
- https://developer.apple.com/legacy/library/documentation/mac/pdf/Interapplication_Communication/Recording_AEs.pdf
- https://developer.apple.com/legacy/library/documentation/mac/pdf/Interapplication_Communication/Scripting_Components.pdf
- https://developer.apple.com/legacy/library/documentation/mac/pdf/Interapplication_Communication/PPC_Toolbox.pdf
- https://developer.apple.com/legacy/library/documentation/mac/pdf/Interapplication_Communication/Data_Access_Mgr.pdf
- https://developer.apple.com/legacy/library/documentation/mac/pdf/Files/Preface.pdf
- https://developer.apple.com/legacy/library/documentation/mac/pdf/Files/Intro_to_files.pdf
- https://developer.apple.com/legacy/library/documentation/mac/pdf/Files/File_Manager.pdf
- https://developer.apple.com/legacy/library/documentation/mac/pdf/Files/stdfilepkg.pdf
- https://developer.apple.com/legacy/library/documentation/mac/pdf/Files/AliasManager.pdf
- https://developer.apple.com/legacy/library/documentation/mac/pdf/Files/Disk_Initialization.pdf
- https://developer.apple.com/legacy/library/documentation/mac/pdf/Networking/preface.pdf
- ...
- https://developer.apple.com/legacy/library/documentation/mac/pdf/Devices/Preface.pdf
- https://developer.apple.com/legacy/library/documentation/mac/pdf/Devices/Device_Manager.pdf
- https://developer.apple.com/legacy/library/documentation/mac/pdf/Devices/Slot_Manager.pdf
- https://developer.apple.com/legacy/library/documentation/mac/pdf/Devices/Scsi_Manager.pdf
- https://developer.apple.com/legacy/library/documentation/mac/pdf/Devices/SCSI_Manager_4.3.pdf
- https://developer.apple.com/legacy/library/documentation/mac/pdf/Devices/ADB_Manager.pdf
- https://developer.apple.com/legacy/library/documentation/mac/pdf/Devices/Power_Manager.pdf
- https://developer.apple.com/legacy/library/documentation/mac/pdf/Devices/Serial_Driver.pdf
- https://developer.apple.com/legacy/library/documentation/macos8/pdf/ThreadManager.pdf
- ...
- (QuickTime)
- (PowerPC Numerics)
- (AOCE)
- (QuickDraw GX)
- (Inside Macintosh: Overview - 消滅 ??)
それ以外、例えばSound ManagerとかQuickTimeは別個のドキュメントで、現状Appleの公式配布には無い。QuickDraw等それなりの数のAPIはCarbonに吸収されたので、コンセプト等のレベルではCarbonのドキュメントが流用できる。 なんとAppleのドキュメント検索で当たらないものがかなり有るようだ。。もしかしたら現状では(MacII以降の)Inside Macintoshは全部PDF版が公開されているのかもしれない。
(TEMP: URLはまだ収集中。後で直す。すごい量になったので後で分割する。)
Trivia
- MPWのメーリングリストはまだAppleのサーバに存在しており、別れのメッセージが今年(2014年に)投稿されている http://lists.apple.com/archives/mpw-dev/2014/Jan/msg00000.html
- コンパイラはシマンテック製。3.0のコンパイラはGreenHills製。2.0のコンパイラはApple内製で、Pascalで書かれていた(!)らしい http://lists.apple.com/archives/MPW-Dev/2005/May/msg00003.html
- Mac自体は(Object)Pascalでデザインされたシステムだが、知る限りではPowerPCのためのPascal処理系は無い。Pascalのためのインターフェースファイルは一通り提供されており、QuickDraw3DやOpenTransportのようなC実装のサブシステムは元より、OS Xにしか存在しないMachポート経由でAppleEventを送受信するインターフェースもbindingが有る。(機械的に変換していると考えられる)
- PowerPC版は"Macintosh On RISC"と呼ばれている。
- makeコマンドはスクリプトを出力するだけで実際のビルド発行をしないし、いくつかの特殊なシンボルをコロン等の一般的なシンボルの代わりに使う。これは、Classic Mac OSのパス区切りがコロンであること等の制約によるものと考えられる。
- - CサンプルのMakefileの一部
- nPOWERのためのヘッダ(Multiprocessing.h)が含まれている。nPOWERはDAYSTAR digitalによる一連のSMP互換機で使用されていたAPIで、デファクトスタンダードとなっていた。SMPのような機構が3rd party製なのは良くも悪くもMacらしい。他に3rd party実装を取り込んだものとしてはMODE32によるCPUアドレッシングモード拡張が有る。
- MPWはCarbonLib経由でOS9/OS Xハイブリッドなアプリケーションを実装できる。もっとも、Win32におけるWin32s同様、CarbonLib自体も絶妙な実装で、特にOS9上では安定しているとは言いづらい。この手法で、MPWはOSX専用アプリを書くことさえでき、MPWの提供するヘッダにはCore Graphics等が含まれている。