Objective-C, Mandelbrot, Z80 emulation, TestMe

Jeff Avery on the Web

HOME        SITEMAP        ABOUT        CONTACT        INTERESTS

 

Objective-C

In 2011, I decided it was time for me to bite the bullet and learn C and Objective-C. I already owned several books on C that I had picked up at book sales and so I read three of them. After finishing the three books, the next move was to do some programming so I asked Jacquie to buy me for my birthday a book on Objective-C called “Beginning Mac Programming: Develop with Objective-C and Cocoa” by Tim Isted. When my birthday arrived, I immediately waded into the book and shortly afterwards, bought Apple’s development system, Xcode for $4.99 from the App Store. While reading the book, I entered the book’s examples into Xcode and began my learning experience. One problem that I encountered was that the book assumed the reader was using version 3 of Xcode whereas I had bought and was using version 4. Apple had made significant changes in version 4 and so instructions in the book sometimes made no sense. However with a lot of Google searches and much head scratching I was able to overcome these problems and proceed.


When I was about three quarters of the way through the book I felt I knew enough to make a start on an Objective-C version of Mandelbrot. There were the usual obstacles but I managed to overcome them and the programme was eventually finished (hah! is any programme ever finished?); it features many enhancements over my old Pascal programme. With my previous versions, running on older Macintoshes, the calculation time was substantial while the display time was reasonably fast. Therefore, I saved the results of the calculations in a file so that the image could be quickly redisplayed at any time by opening the file. Now, with the new programme running on my MacBook Pro, calculation time is almost instantaneous and so there is no longer a need to store the results in a file. My Objective-C programme therefore stores only the input parameters so the saved file is reduced to a very small size. The faster display time has also enabled me to add an animation feature as the programme draws fast enough to display a Mandelbrot set with changing colours. How times change! Click here to see more output from the new programme.


I knew I was wrong to say that my Mandelbrot programme was finished as several enhancements have since been added. One enhancement is to drag the mouse to denote an area of the display that is to be zoomed to fill the window. Another enhancement is the ability to print the image. Neither dragging the mouse nor printing are covered in Tim Isted’s book. I worked out how to add mouse dragging but it only worked if the dragging increased the size of the selection rectangle. Moving the mouse back to decrease the rectangle’s size led to problems. More searching on the Web led me to a Wiki book called “Programming_Mac_OS_X_with_Cocoa_for_Beginners” which appeared to cover both printing and mouse dragging. I decided to read this book online and follow it’s examples in Xcode as I had for the other book. Immediately I found the same problem: it assumed Xcode 3 but I was using Xcode 4. As before, I had to do a lot of research to overcome the differences I encountered. Eventually, though, I overcome these difficulties and added the new features to my Mandelbrot programme.

macintosh-z80emulator.html

With Mandelbrot finished (hah!) I then rewrote JAssembler and JDisassembler in Objective-C but after that I was at a loss as to what to do next. The answer came in October 2011 when I decided to write a Z80 Exceltronix Multiflex Super System emulator of the hardware described in my Z80 Exceltronix Multiflex Super System project. The new programme would emulate not only the Z80 microprocessor but the Exceltronix Multiflex microcomputer as well. There was much new Objective-C stuff to learn to accomplish this but, after much work, including extensive debugging with the programme Z80 Instruction Exerciser (Zexall/Zexdoc), the project was completed. The programme manages three windows: a Z80 emulator, an Exceltronix Multiflex emulator and a floppy disk drive and terminal screen emulator. A screenshot is shown on the right. To see a larger version with explanatory text, see my Z80 emulator or click on the image.


In February 2012 my Objective-C project was a programme I call TestMe and an image of its window is shown on the left. With TestMe, you create test files (either .txt or .rtf) in a text editor in which each line consists of a question and an answer. The file is then loaded into TestMe which shows you a question and suggests four answers that are randomly chosen from the file. Clicking on an answer provides a response of correct or incorrect and a score is displayed. Menu items provide the means to modify how TestMe works. For instance, the multiple-choice answers can be hidden if required. Also, questions can be selected from the input file either sequentially, randomly, or in a shuffled order.


I wrote this programme to help me improve my French vocabulary but the programme is quite versatile: any questions and answers that you can put into text can be used as input. For instance, you could test other languages, mathematics, geography, technical terms: the possibilities are limited only by the imagination.


There is much help available on the Web for Objective-C programmers. There is extensive Apple documentation but I find it difficult to use. They say a picture is worth a thousand words; I say that an example is worth a thousand words, too. Unfortunately, the Apple documentation is short on examples. One website that I find is really useful in providing examples is Julius Guzy’s website. Thanks, Julius!


In October 2012 I was experimenting with adding a serial port to my Macintosh. To provide terminal emulation and to communicate with the USB serial port, I wrote JTerm with help from Gabe Ghearing’s Xcode example. My program emulates both TTY and VT100 terminals and, for its preferences, I used a drop-down sheet for which I found an excellent example on the Web.

 

<-Computers             Macintosh Page:     <-Prev             1             2             3             4             Next->