Jump to content
petteri

Getting started with application development for System 6/7

Recommended Posts

I have a little coding challenge in my mind. The requirements are that it should have some input and output for the text - could be proper UI components or just plain terminal like text screen. I should also read some data from resource fork (text for example) and its target environment should be System 6 or 7.

 

I have some programming experience and now I'm looking for a toolchain to get this done. I have SE/30, IIcx/ci and Beige G3 available in addition of new laptop running Catalina OS X. Any recommendations for the tools? Also some simple skeleton application would be pretty helpful.

Edited by petteri

Share this post


Link to post
Share on other sites

Depends, to an extent, whether you want to develop on your modern machine and cross-compile, or use an IDE on your old macs (or on an emulator, which is what I tend to do).

 

In the first case, you could try Retro68, at https://github.com/autc04/Retro68  This is a gcc-based toolchain for building 68k classic Mac applications.  I've not tried this myself yet, but I hear other people speaking highly of it. Per the readme: "Why? Because there is no decent C++17 Compiler targeting Apple's System 6."

 

In the second case, I personally use CodeWarrior or THINK Pascal, depending on whether I'm writing C or Pascal primarily.  I'm actually quite fond of classic Mac IDEs, but this may be an eccentricity. 

 

It is worth noting in your case that most development tools come with a kind of pseudo-terminal for basic standard text I/O.

Share this post


Link to post
Share on other sites

Yeah, personal preference but I would do that in THINK C on the SE/30.  Why?  Because if you’re going to go retro, actually go really retro!  And THINK C is great and simple and quick.  CodeWarrior is excellent for PPC code generation but is a bit more cumbersome to use and works better on a newer machine (though is perfectly fine on my SE/30 with a 50MHz accelerator).  THINK Pascal is a beautiful product built on the fantastically amazing Mac Pascal GUI, but Pascal is too annoying to use for me these days, even though I grew up on it.  

 

If you want to build a text interface, you don’t really need a sample app or to worry about doing all that crazy Mac initialization, event loop, WaitNextEvent, FindWindow stuff.  Just #include <studio.h> and printf(...) til you’re blue in the face.  It will Just Work. And you can still call GetResource() or whatever you need to access a resource file.

 

(And if you do like Pascal, @cheesestraws is right as usual, you can use THINK Pascal’s built-in terminal functions too.  WriteLn(...) etc.)

 

If you do want to build a Mac-like app, on the other hand, THINK C comes with a nice demo (Bullseye.c) to get you started, which implements a couple menus and a standard Mac window.  And several of us here can help if you have questions.

 

Have fun!  What’s your coding challenge?

Edited by Crutch

Share this post


Link to post
Share on other sites
8 hours ago, Crutch said:

Yeah, personal preference but I would do that in THINK C on the SE/30

Yeah, THINK C is another good option.  I don't use it myself, because I find it annoying, but that's personal taste rather than any reflection on the quality of the software itself.

Share this post


Link to post
Share on other sites

I've been teaching myself Mac programming on a Classic II and in Mini vMac for the past few months and having a blast with it. Both THINK C and THINK Pascal are great and pretty easy to use. THINK Pascal's built in text and graphics windows make for very easy experimenting with QuickDraw and the like without having to learn how to initialize the toolbox and create windows. But it's also easy to turn your experiments into real applications once you start getting the hang of things

 

For tutorials and reference, there's a great collection of scanned books at https://vintageapple.org/macprogramming/ . I'd recommend Macintosh C Programming Primer 1992 or Macintosh Pascal Programming Primer. There's also a great overview with examples of Pascal here https://wiki.xxiivv.com/site/pascal.html and the author has a lot more examples here https://git.sr.ht/~rabbits/macintosh_cookbook/tree/master/examples

 

One thing to note is that the syntax for Think C 5.0 changed to be closer to more modern C. The 1992 book is good, but code from older books will need to be adjusted. Have fun!

Share this post


Link to post
Share on other sites
14 hours ago, petteri said:

I have some programming experience and now I'm looking for a toolchain to get this done.

Which languages do you know? Which one are you most experienced with?

Share this post


Link to post
Share on other sites
15 hours ago, cheesestraws said:

In the second case, I personally use CodeWarrior or THINK Pascal, depending on whether I'm writing C or Pascal primarily.  I'm actually quite fond of classic Mac IDEs, but this may be an eccentricity. 

I'm also a fan of classic IDEs as well – because they bundle frameworks (like PowerPlant etc.) that make writing apps considerably more simpler. Plain Toolbox C/Pascal gets unwieldy for a modern programmer pretty quickly.

Edited by rplacd

Share this post


Link to post
Share on other sites

For the record, CodeWarrior 6 works quite well on my unaccelerated SE/30, and I recently used it to develop the control panel for my ROM disk. My impression is that CodeWarrior is basically a THINK C clone but the compiler is a bit more modern. Only issue was that I had to hook up a SCSI CD-ROM drive (which I do not normally use) to install CW6 from a burned CD. THINK C is smaller and will be easier to install if you are using a Floppy Emu or similar, although the CodeWarrior 6 CD includes something like 30 1.44MB floppy images to install the software from floppy disk.

Share this post


Link to post
Share on other sites

Does CodeWarrior allow embedded asm{...} blocks in C? My recollection was that it doesn’t, which was another reason I have preferred THINK C except when trying to generate PPC code, but I could be wrong. 

Share this post


Link to post
Share on other sites
8 hours ago, Crutch said:

Does CodeWarrior allow embedded asm{...} blocks in C?

Yes, I believe so, but you have to break it up into its own function like so:

asm void foo() { ... }

Share this post


Link to post
Share on other sites
11 hours ago, Dog Cow said:

Which languages do you know? Which one are you most experienced with?

Java, Scala, Python, JavaScript mostly but also some C, Go and whatever required. Done programming for money last 16 years.

 

17 hours ago, Crutch said:

Have fun!  What’s your coding challenge?

Building a CTF challenge for a hacking event actually. The idea is to hand over a disk image and see how people proceed with that one. There will be a hidden flag somewhere. Might require some disassembler or not, haven't decided that yet. And I should not write the walk through here, those guys are pretty darn good with OSINT.

Edited by petteri

Share this post


Link to post
Share on other sites
14 hours ago, ZaneKaminski said:

Yes, I believe so, but you have to break it up into its own function like so:

IIRC you can get it not to emit prologues/epilogues for those, though, so you can use them for things like custom headers on code resources, which is quite handy.

 

We are getting a bit over-the-top for the OP's actual request, though :-)

Share this post


Link to post
Share on other sites

Another vote for THINK C. If you get that, make sure you get the searchable database for standard Mac functions, an absolute time saver (I think it's just called THINK Reference), as well as Popfunc, so you can add a leftmost corner pop-up menu to your window editing a source file, allowing you to go directly to any function from a pull-down menu, if you're a barbarian like me and write too many functions in an individual source file sometimes (I'm trying to break the habit) 

 

If you do target System 6 and less, check out some code examples I did here:

 

https://mu0n.github.io/ForayInto68k/index.html

Share this post


Link to post
Share on other sites
8 hours ago, Mu0n said:

If you do target System 6 and less, check out some code examples I did here:

Oooh, these look nice.

 

8 hours ago, Mu0n said:

it's just called THINK Reference

Yeah, THINK Reference is really handy if you are developing on vintage hardware.

Share this post


Link to post
Share on other sites

After some reading I decided to go with Think Pascal on Beige G3 route. I did a tiny bit Pascal in school (mid 1990s I think) but that was for MS DOS environment. I just hope it will work on OS 9.2 without troubles.

Share this post


Link to post
Share on other sites
23 hours ago, petteri said:

Think Pascal

THINK Pascal has one of the best debuggers I have ever used.  Its editor, not so much.  But its debugger—I wish I had something as good as that for the modern tools I use at work. 

Share this post


Link to post
Share on other sites

I am reading through Macintosh Pascal Programming Primer and Inside Macintosh: Imaging With QuickDraw now. I think I have some kind of idea how to put my challenge together. Too bad I cannot share it here before the event in 2021 February is over :-)

Edited by petteri

Share this post


Link to post
Share on other sites

Thanks guys! I have one public question right away. If I want to draw single pixels on a 1bit depth area, what is the recommended way? MoveTo+Line(0,0) combo seems to be pretty slow.

Edited by petteri

Share this post


Link to post
Share on other sites

I would love to see a tutorial on how to get a "Hello World" on System 6/System 7. If anyone ends up putting together a video, or is willing to jump on a Zoom and walk through it, I'd love to watch. My development experience is pretty thin... I've done a few Arduino projects, and would like to understand how much further I'd need to go to start writing basic applications for 68k Macs.

Share this post


Link to post
Share on other sites
8 hours ago, PotatoFi said:

I would love to see a tutorial on how to get a "Hello World" on System 6/System 7. If anyone ends up putting together a video, or is willing to jump on a Zoom and walk through it, I'd love to watch. My development experience is pretty thin... I've done a few Arduino projects, and would like to understand how much further I'd need to go to start writing basic applications for 68k Macs.

I followed this guide: http://www.think-pascal.org/ and after that https://vintageapple.org/macprogramming/pdf/Macintosh_Pascal_Programming_Primer_1990.pdf

Pascal has already given me some head aches :-D Usually (in modern world) one wouldn't do conditional with single =, as in some programming languages it does assignment inside if clause :sadmac: Also, it took moment to figure out how to if/else syntax works without curly braces or Python like indentation...

Share this post


Link to post
Share on other sites
10 hours ago, petteri said:

Thanks guys! I have one public question right away. If I want to draw single pixels on a 1bit depth area, what is the recommended way? MoveTo+Line(0,0) combo seems to be pretty slow.

Yeah it’s slow if you’re doing it a lot.

 

If you’re on a compact Mac (no graphics card), write directly to screenBits:  (qd.screenBits in some later compilers)

 

I did this from memory so check my math.  I will test it tonight to ensure I got it right!  It also assumes a screen that’s 512 pixels wide:

 

#define SET_PIXEL(x, y)

    *(((short *) screenBits.baseAddr) + ((y) << 5) + ((x) >> 4)) |= (0x8000 >> ((x) & 0x000F))

 

Translation:

- grab start of screenBits bitmap, cast as a short* so we can do pointer arithmetic word-by-word

- advance by y<<5 == y*32, where 32 = #words in a 512-pixel row.  This gets us to the start of the right row

- then advance by x/16 to grab the right word in the row

- now we need to apply a bitwise OR to that word to set one of the bits...

- the thing we will OR it with is 0x8000 = 0b100000000000000, right-shifted by the low 4 bits of x (which tell us which bit to use in the word of interest)

 

For multiple invocations, faster if you put screenBits.baseAddr in a register first of course.  Or do this in an asm{...} and use a BSET instruction rather than the |=.

 

If you’re on a Mac that might have multiple monitors/varying bit depths, it’s just slightly tricker, you have to get the current gDevice first.

 

If you’re on a color screen, uncertain of the PixMap width and use rowBytes, be sure to remember the high 3 bits contain flags and should be stripped off.  This one gets me every time.

Edited by Crutch

Share this post


Link to post
Share on other sites
12 hours ago, PotatoFi said:

I would love to see a tutorial on how to get a "Hello World" on System 6/System 7. [...] and would like to understand how much further I'd need to go to start writing basic applications for 68k Macs.

I've posted a handful of development tutorials on the Mac 512K Blog. They're in assembly language, and will run on any Mac. Even if you don't end up using assembly language for your project, you can still see the Toolbox calls in action and how they're used.

 

Check out MacTutor, especially the first 3 volumes. There are "hello world" type application tutorials in several languages, including C.

Share this post


Link to post
Share on other sites

(I confirmed the code snippet above is correct, but check your rowBytes on any machine with color QuickDraw ... with my grayscale card, the main device Pixmap on my SE30 has rowBytes = 1024 even in 1 bit mode ... if this doesn’t make sense and you’re not running on a black and white compact, I can post a slower but more general code snippet that will work on any screen)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×