https://chipwits.com/2024/11/16/chipwits-40th-birthday-original-forth-code-open-sourced/ Skip to content ChipWits Robot Coding Game * Home * About * Devlog * Team * Retro Menu Toggle + ChipWits Emulator + Nostalgia * Sign Up Demo + Wishlist Demo + Wishlist ChipWits Robot Coding Game Main Menu * Home * About * Devlog * Team * Retro Menu Toggle + ChipWits Emulator + Nostalgia * Sign Up ChipWits' 40th Birthday: Original FORTH Code Open Sourced! By Mark Roth / November 16, 2024 Please Wishlist Our ChipWits Reboot! We're so thrilled that our open source announcement is getting so much attention! If you're interested purely in the open source release and how we recovered the original FORTH source code, please read on. If you're curious to try out our reboot of this programming logic / puzzle game as well, please consider wishlisting our project on Steam. It helps support the open source work. Thank you! Open Source Announcement This month marks the 40th anniversary of ChipWits! To celebrate, we're releasing all of the original Mac and Commodore 64 FORTH source code (or as much as we could recover) as open source! [40-anniversary-announcement-1] You can find the code at https://github.com/chipwits/chipwits-forth. Read on for some history and analysis. [mac-chipwits-original-code]ChipWits Mac Source Code on 3.5'' diskettes [c64-chipwits-original-code]ChipWits C64 Source Code on 5.25'' disks Our goal for open sourcing the original version of ChipWits is to ensure its legacy lives on. We also wanted to share an appreciation for what cross-platform software development for 8-bit microcomputers was like in 1984. If you are familiar with these systems, we'd love to hear from you, and you're invited to help us explore and curate the original source code. Please join us on our Discord Server. History of ChipWits and Choosing FORTH ChipWits was one of the first games to be released on the 1984 Macintosh. Co-creators Doug Sharp and Mike Johnston worked part-time porting educational computer games between 8-bit microcomputers to earn enough money to pay rent. During this time, they worked on the design for their first original game called ChipWits, a game about programming robots inspired by Rocky's Boots, Logo and other classic programming games of the time. Choosing FORTH In 1984, with much fanfare, Apple released the Macintosh personal computer. Support for development environments was limited at launch. The primary way to develop for the Mac was to purchase an Apple Lisa, the original version of which retailed for $9,995 ($30,373 in today's dollars). [885px-Apple-lisa-1]An Apple Lisa Was too Expensive (Photo courtesy of Timothy Colegrove, CC-BY-SA 4.0) Because it was far too expensive for an indie game studio to afford one of these systems, Doug and Mike decided to develop ChipWits using the MacForth Plus programming language running directly on the Mac. [macforth-disks]MacForth: The Language of Innovation (photo courtesy of macintoshrepository.org) Variants of FORTH were available on just about every 8-bit microcomputer at the time, which made it a great choice of language if the plan was to later port the game. They started development in April 1984 and it took about 7 months to develop and publish the first version of ChipWits. Development was intense (and we can assume fueled by much coffee and pie), but it was done in time for the Christmas Holiday Season! [image-3]ChipWits running on a Macintosh Plus (Photo courtesy of Maclife.com via WayBackMachine) Porting to Other Platforms Epyx was supposed to be the game publisher for ChipWits, with Commodore 64 as their biggest market. However, it had no Mac games. Brainworks was aiming at the Educational market, which Apple owned at the time. So, Epyx published the game on Commodore 64 only. The C64 port was completed in 1985. [greedville-1]ChipWits on the Mac [vice-screen-2023021023075478]ChipWits on the Commodore 64 The Commodore 64 version was a challenging port, done in Super Forth 64. Doug and Mike wanted to keep the same general User Interface Design but that required developing a pull-down menu system using a joystick instead of a mouse. They added color graphics and SID chip sound and had to squeeze all of it onto a 165 KB disk (instead of 400 KB available on Mac disks). They also had to figure out how to utilize only 64 KB of RAM (instead of the 128 KB available on Mac), not to mention a slower processor. After the success of the Commodore 64 version, they went on to create an Apple II version, also written in a variant of FORTH. [chipwits-title-retro-apple2]ChipWits on the Apple II Reviews and Awards ChipWits was an instant hit and was the subject of many reviews and awards. Here are a few: * "ChipWits is the best, certainly most enjoyable, introduction to programming concepts that we've seen. Its icon based language is wonderfully innovative, and the program's design is both refreshing and highly educational." -- MacUser Editor's Choice 1986 Award * "We predict without hesitation that ChipWits will become a cult favorite among Macintosh users and their children of whatever age". -- Macazine * "Not too many reviews come with a guarantee, but this one guarantees that if you like programming, you'll love ChipWits." -- MacWorld * "Last night my wife came downstairs at 4:30 a.m. only to witness me cursing at a cartoon robot." -- Creative Computing In 2008, Maclife.com named ChipWits one of the Top 10 Apple II / Mac Games of all time! Play the Originals in Emulation! Before we dive into the code, if you're curious to play the original versions of ChipWits, we were able to get them all working in an in-browser emulator (thanks to open source projects Emularity and Apple2js), which you can play right here: [chipwits-retro-emulation]Play Retro ChipWits right from your browser! Recovering the Source Code While working on the new version of ChipWits, Doug Sharp found the original disks in his archive. When you consider the 3.5'' diskettes and 5.25'' floppy disks had been in home storage for 40 years, it's a miracle that any data from the disks could be recovered at all. Not all the data made it, the vast majority of the disks read with no bad sectors at all! Commodore 64 Reading these disks with modern hardware was a bit of an adventure. For the Commodore 64 disks, we ordered an original genuine 1541 Commodore 64 Disk Drive on eBay. The drive came with a USB XoomFloppy adapter so the data can be read by a modern PC. Turning on the drive and listening to the gentle whir of the motor brought back so many memories. [c64-1541]Commodore 1541 Disk Drive Mac For the Mac 3.5'' diskettes, we learned that Mac used a proprietary sector layout to allow them to increase the capacity to 800 KB per disk, which makes them unreadable using modern drives using standard techniques. We ordered a PowerMac G3 WallStreet, a bridge system that still has a 3.5'' diskette drive that can read original Mac disks and also has a networking stack. However, that machine was only able to read the 800 KB disks because they disabled 400 KB support in the later versions of MacOS. [PowerMacG3WallStreet]PowerMac G3 WallStreet, only able to read 800 KB disks unless OS was downgraded Later, a fan gave us a tip to check out the GreaseWeazle, a custom hardware controller for disk drive control over USB, which worked perfectly! [greaseweazle-v4]The GreaseWeazle Drive Controller worked! (photo courtesy of decromancer.ca/greaseweazle) We methodically took block-by-block disk images of every disk in the archive set and compiled them into a GitHub repository. We used the disk label as the filename and prepended "bad" if there were any detected bad sectors. To make it easier for modern computers to read the contents we also wrote some Python scripts to extract blocks from the disks and reformat them as UTF-8 ASCII files. For the Commodore 64 this included converting their proprietary PETSCII to ASCII. Exploring the Source Code You can find all the results of our work: the raw disk images and code at https://github.com/chipwits/chipwits-forth. FORTH code is incredibly concise and, some would say... elegant? The entire ChipWits source code for Mac is approximately 3,000 lines of Forth code. Pretty incredible considering our modernized port of the game is already 35,000 lines of C#. We put together an article with an in-depth analysis of one "screen" of FORTH code which controls electrocrabs. See our post entitled Forth Code for Electrocrabs in 1984 ChipWits Deciphered. Here's a quick peek at some of the other source code we found to be interesting. This really helps put you in the mindset of how game developers needed to think back in 1984. If you don't know how to read FORTH code, just keep in mind it's stack-based (similar to Reverse Polish Notation if you've ever used an RPN calculator), so instead of writing 1 + 1 you would write 1 1 +. Instead of writing if random(3) == 1 you would write 3 irnd 1 = if. Mac: Moving the Robot ( Move) ( 103084 dws) : Move ( ---) Calc.robot.move Check.for.next.room dup square.object dup floor@ = swap door@ = or if init.cw.graphics arg.byte c@ 64 mod check.mov.st forward@ = if 10 0 do Cw.slide loop else 10 0 do Cw.back.slide loop then dup robot.square ! ( Walk on empty floor) draw.background else ( Hit something) square.object dup wall@ = if 1 Bump drop ( wall) else 5 bump ?boom drop then ( obj) then robot.square @ 19 < if 0 add.points then ( in case erased) ; Here's the code for moving the robot in the Mac version of ChipWits. Unlike modern game development, there is no separate rendering loop for each frame. The code is imperative, mixing both game logic and graphics rendering together in a tight loop. Animations are achieved by rendering pixels directly in the loop (CW.anim is defined on another screen as a series of instructions to copy bitmaps directly to the screen). Note the check as to whether the player rolls into an empty floor tile, hits a wall, or rams into a bomb is directly addressed in just a few words of code. The ?boom definition (found in another screen) even decides if the game should end right then and there because the player touched a bomb. The last line of code here is interesting in that, depending on the location of the robot, it explicitly adds 0 to the score in order to force a repaint of the score in case it was erased as the robot went sliding past. Commodore 64: Sprite Definitions ( head.op.w) binary s-def head.op.w 00000000 00000000 00000000 00000111 11111111 11000000 00001001 11111111 11110000 00001110 00000000 00000000 00001111 01111111 11111000 00001111 01111111 11111000 00001111 01111111 11111100 00001111 01111111 11111100 00001111 01111111 11111100 00011111 01111111 11000000 00111111 01111111 10111100 01111110 11111111 01111110 00011101 11111111 01111110 00000011 11111000 01111110 00000000 00000001 11111110 00110000 00001111 11111110 00011100 01111111 10111100 00001110 11111100 00000000 00000111 01100000 00000000 00000001 10000000 00000000 00000000 00000000 00000000 decimal Here's one screen from the Commodore 64 version. First, it was usually not possible or performant to load the entire source program in memory at once so source code in FORTH was not stored in files. It was stored in "screens", each of which was numbered and loaded in a controlled manner. It was common for code to mix asset data segments with source code. In this case, if you squint you can see a binary rendering of the ChipWit's head facing west. Monochrome sprites on the Commodore 64 were 24 x 21 pixels and only 8 sprites could fit on the screen at once. You could choose to use a 4-color sprite but then your resolution would drop to 12 x 21 and pixels would be double-wide. This code reveals that the ChipWit is actually rendered using several sprites which are overlaid to form the character, much like animation cels in vintage cartoons. This design choice sacrificed using all the available sprites for just the ChipWit but you get a crisper image that can be animated in pieces. Mac: Thing Point Values : d, 10 * c, ; create Scenario.play( ( 110584 dws) ( Scen: Greed CW C Doom Peace MemLn Oct Myst Boom) ( crp.ct) 00 c, 08 c, 08 c, 04 c, 03 c, 03 c, 03 c, 03 c, ( crp.pt) 00 d, 05 d, 10 d, 03 d, 03 d, 01 d, 02 d, 04 d, ( bnc.ct) 00 c, 00 c, 02 c, 00 c, 02 c, 02 c, 02 c, 00 c, ( bnc.pt) 00 d, 00 d, 25 d, 06 d, 06 d, 02 d, 04 d, 00 d, ( oil.ct) 10 c, 06 c, 00 c, 04 c, 02 c, 00 c, 00 c, 00 c, ( oil.pt) 05 d, 05 d, 00 d, 02 d, 03 d, 05 d, 15 d, 00 d, ( dsk.ct) 03 c, 02 c, 00 c, 02 c, 00 c, 00 c, 00 c, 00 c, ( dsk.pt) 10 d, 10 d, 00 d, 15 d, 25 d, 25 d, 25 d, 25 d, ( cof.ct) 03 c, 04 c, 02 c, 03 c, 03 c, 01 c, 00 c, 00 c, ( pie.ct) 03 c, 00 c, 02 c, 03 c, 02 c, 04 c, 00 c, 02 c, create room.ct( 4 c, 8 c, 12 c, 54 c, 1 c, 1 c, 100 c, 9 c, First, note the things we keep seeing that look like ( 110584 dws). This bewildered me until Doug pointed out that these are actually date stamps on the screens (110584 = Nov 5, 1984 and dws = Douglass Walter Sharp). We believe this is one of the last screens to be updated before the final release of the game. The last screen to change was on Nov 8. This compact piece of code / data efficiently encodes the count and point values of each type of item for each mission. What stood out to me was the clever definition on the first line of d, to mean "multiply this value by 10" whereas c, means leave the value alone. This allowed Doug to encode point values like 150 as 15 d which made it possible to keep a neatly aligned table that fit in a single screen. It also presumably made it possible to easily scale all point values by some factor (1, 2, 5, 10) as Mike and Doug were experimenting and balancing the scores until release day until it felt right. Please Wishlist Our ChipWits Reboot! Our team wanted to keep this post focused on the open source release of the original FORTH version of ChipWits, but we also wanted to mention that we're hard at work on a modernized version as well. In the reboot of ChipWits, we've tried to preserve the original game's fun factor and computer science rigor while enhancing every aspect of the game from learning curve to competitive global leaderboards. We're hoping the new version of the game inspires a new generation of programmers! Please Wishlist ChipWits Now to be notified when our final version is out! Here's a screenshot of one of our puzzles: [chipwits-reboot]Four Corners Puzzle from the ChipWits Reboot We'd Like Your Help! These are just some of the enjoyable gems in the original FORTH source code for ChipWits. We'd love for you to explore and share what you find. Post your comments below! Also, we've created several issues in our GitHub repo. Our immediate goals are: 1. Make sure we have all the relevant source code extracted from the raw disk images 2. Fix the alignment of some of the source files (some are 40 char width, some are 64 char) 3. Figure out which disk contains the most recent source code 4. Create instructions for how to build from source on Mac and C64 5. Extract the raw sprites and images from the disks into .png files Ultimately, we envision a community-maintained FORTH version of ChipWits for modern PCs. If you're interested in helping, come join our ChipWits Discord Server! Share this: * Facebook * X * Like this: Like Loading... Related Post navigation Previous November Challenge: Happy 40th! Leave a ReplyCancel reply --------------------------------------------------------------------- Join Our Mailing List! Are you interested in learning more about ChipWits and tracking our development? Provide your name and email address below to join our mailing list. We respect your email address and don't spam. You can unsubscribe at any time. We generally send a short email about the game once every week or two. Please leave this field empty[ ] [ ] [ ] [ ] [Subscribe] Check your inbox or spam folder to confirm your subscription. Copyright (c) 2024 ChipWits, Inc. * Contact * Press Kit * Privacy Policy * Terms of Use Discover more from ChipWits Robot Coding Game Subscribe now to keep reading and get access to the full archive. Type your email... [ ] Subscribe Continue reading Loading Comments... Write a Comment... [ ] Email (Required) [ ] Name (Required) [ ] Website [ ] [Post Comment] %d