image ResEx Logo
ResExcellence www : Powered by Google
Cell Phone Themes Icons Mighty Mouse Cursors Software Reviews Widgets & Widgets

Articles
   3D
   Audio
   Custom Controls
   General RB
   Graphics
   Hacks
   Mac OS X
   Menus
   Novelty
   Printing
   REALbasic 2005
   REALbasic 2006
   Registration
   Resources
   Reviews
   Serial
   Speech
   Sockets
   XML
   Video
Resource Links
News
   Current News
   February 2006
   January 2006
   December 2005
   November 2005
   October 2005
   September 2005
   August 2005
   July 2005
   June 2005
   May 2005
   April 2005
   March 2005









REALbasic for Dummies
by Erick Tejkowski


Learning REALbasic through Applications
by Clayton E., Crooks II


REALbasic for Macintosh
by Michael Swaine


REALbasic Cross-Platform Application Development
by Mark S. Choate





Older files are in Stuffit 5 or greater format. Newer files are ".Zip". Download StuffIt Expander
Tell us about a bad link. Thank You!

Build an Applesoft BASIC Simulator by Erick Tejkowsi
09-20-01

Printer Version




After hearing from a few Apple ][ diehards, it occurred to me that some REALbasic newbies might be making the transition to REALbasic from Apple BASIC. Many folks started their programming careers using the venerable Applesoft BASIC on the various models of the Apple ][ (yours truly included).

In their honor, this week we will build a simple Applesoft BASIC simulator, which will allow you to enter and "run" graphics commands from the Applesoft BASIC language. Hang on to your seats as we set the time traveler to 1980...

Preparation

Ok, here we are in 1980 staring at the TV screen of our fancy Apple ][ machine. Each Apple machine at the time came with a copy of Applesoft BASIC, a BASIC intrepreter. One of the first things an Applesoft BASIC programmer learned to do was create low resolution graphics. They were lousy compared to today's standards, but they have a certain retro charm. Our project will simulate some of the low resolution graphics commands of the Applesoft BASIC language.

Command Function
HOME Clear the screen with the current color.
COLOR=x Sets the current color to 'x'. 'x' can be any integer between 0 and 15 inclusive.
HLIN x1,x2 at y Draws a horizontal line from x1 to x2 at the y coordinate.
VLIN y1,y2 at x Draws a vertical line from y1 to y2 at the x coordinate.

Low resolution Applesoft BASIC graphics have a coordinate system much like REALbasic with the origin (0,0) at the top left. Unlike REALbasic, the dimensions of the screen are 40 columns wide by 48 columns high. Look here if you would like to learn more about the Applesoft BASIC commands.

Build the Interface

Launch REALbasic and open the default window, Window1. From the toolbar, add the following controls to the interface:

Control Settings
Canvas Name : tvscreen
(Many people used a TV set as the Apple II's monitor.)
Width=400
Height=480
Listbox Name : programlist
Where we will output any data that normally appeared onscreen in Applesoft BASIC.
EditField Name : codefield
Where we will enter a graphics command.
PushButton Name : PushButton1
Pushing this button executes the command.

Feel free to experiment with the layout, but it might look something like this:

09_20-interface.jpg (18k)

Add the Code

Double click any control to open the Code Editor. Before adding any code, though, select Edit->NewProperty and create the following two Properties:

09_20-properties.jpg (4947bytes)

To begin the coding, navigate to the Open event of Window1 and enter the following code:

09_20-opencode.jpg (17k)

This code initializes the color to black (the same as on an Apple ][) and creates a picture object. The picture, p is where we will draw the graphics for each command. Notice that it is very small (only 40x48 pixels). We will stretch this picture over a larger (but similarly shaped) Canvas to display it to the user. Since this is low resolution graphics, it doesn't matter that we lose resolution.

Next, open the Paint event of the tvscreen Canvas and enter this code:

09_20-paintcode.jpg (14k)

You might guess that this code "stretches" (called scaling in graphics lingo) the picture p over the Canvas.

Select Edit->New Method to add a new method named SetCurrentColor(colornumber as integer). We will pass this method a color number (between 0 and 15) and adjust the current color accordingly:

09_20-setcurrentcolor.jpg (100k)

The final step in this code is to process the commands a user enters. The code is somehwat involved and takes up a lot of space on a web page. For this reason, I will briefly discuss it here, but not display it. To see it, you can download the completed project at the end of this tutorial.

Each time a user enters a command and presses "Enter", we have to figure out which command it was and act appropriately. This occurs in the Action event of PushButton1. We start by looking for the "HOME" command, since it is only four letters long. If we find it, we fill in the picture p and exit the code. If the "HOME" command wasn't entered, then the user may have entered one of the other three commands: COLOR, HLIN, and VLIN. The remainder of the code determines which of these commands has been entered. If the COLOR command is entered, the SetCurrentColor method gets called. If the command is HLIN or VLIN, the code draws the appropriate sized line and refreshes the tvscreen Canvas. If, at any time, our code gets some garbage command or improper syntax, we warn the user that they have entered an invalid command.

Conclusion

09_20-finis.jpg (14k)

This week you need to download the completed project to see all of the code. Go dig up that collection of old Byte magazines and scour them for low resolution graphics code. If you are feeling really daring, you might add some code that allows a user to save their work of art or the sequence of commands used in creating the picture. when you get finished playing with the code set your time machine back to 2001. See you next week!




Cell Phone Themes Icons Mighty Mouse Cursors Software Reviews Widgets & Widgets

Maintained by the Staff of ResExcellence. This entire site ©1997-2006 ResExcellence
Privacy Statement? Sure we gotta Privacy Statement. [an error occurred while processing this directive]