98
RETRO CORE USER’S MANUAL

Retro Core User Manual

Embed Size (px)

Citation preview

Page 1: Retro Core User Manual

RETRO CORE

USER’S MANUAL

Page 2: Retro Core User Manual

Page 2 Copyright © Multilabs – 2009 All rights reserved

INTRODUCTION This user’s manual has been developed as a working tool and reference source for those of you who want to maximize your use of Retro Core. This manual contains the information you need for your programs, from the simplest example all the way to the most complex. This manual is written so that everyone from the beginner to the most advanced BASIC programmer can benefit from Retro Core’s abilities. There is an extensive glossary of terms and a "semi-tutorial" approach to many of the sections in this manual. If you don't already have a working knowledge of BASIC and how to use it to program don’t worry, this manual will walk you through it. This manual gives you an easy to read introduction to the BASIC programming language. You will find in this manual a considerable amount of valuable programming reference information written in easy to read, plain English with the programmer's jargon explained. On the other hand the programming professional will find all the information needed to use the capabilities of Retro Core effectively.

WHAT'S INCLUDED

Our complete "BASIC dictionary" includes Multilabs BASIC language commands, statements and functions listed in alphabetical order.

An explanation of Retro Core’s operating system.

The Input/Output section shows you how to make connections to Retro Core. It describes how to hook-up and use everything from joysticks to your own devices.

You can explore the world of programmable characters and high resolution graphics.

Add another dimension to your programs with sound using Retro Core’s tone generator. Think of this manual as a useful tool to help you enjoy the hours of programming ahead of you.

HOW TO USE THIS MANUAL Throughout this manual certain conventional notations are used to describe the syntax (programming sentence structure) of BASIC commands or statements and to show both the required and optional parts of each BASIC keyword. The rules to use for interpreting statement syntax are as follows:

1. BASIC keywords are shown in capital letters. They must appear where shown in the statement, entered and spelled exactly as shown.

2. Items shown within quotation marks (" ") indicate variable data which you must put in. Both the quotation marks and the data inside the quotes must appear where shown in each statement.

3. Items inside the square brackets ([ ]) indicate an optional statement parameter. A parameter is a limitation or additional qualifier for your statements. If you use an optional parameter you must supply the data for that optional parameter. In addition, an asterisk (*) shows that an optional item can be repeated as many times as a programming line allows.

4. Items inside angle brackets (< >) indicate variable data which you provide. 5. A vertical line (|) means “or”. Either the character to the left or the character to the right must be

provided. When you actually apply the syntax conventions in a practical situation, the sequence of parameters in your statements might not be exactly the same as the sequence shown in syntax examples. The examples are not meant to show every possible sequence. They are intended to present all required and optional parameters. Programming examples in this book are shown with blanks separating words and operators for the sake of readability. Normally though, BASIC doesn't require blanks between words unless leaving them out would give you an ambiguous or incorrect syntax. What can you do with Retro Core? The great thing about your Retro Core is that you can make it do whatever YOU want it to do! Retro Core is a complete computer and it does everything listed in this manual and then some!

Page 3: Retro Core User Manual

Copyright © Multilabs – 2009 All rights reserved Page 3

CHAPTER 1

SETUP

About Retro Core

Initial Connections

Operation

Cursor

Keyboard

Page 4: Retro Core User Manual

Page 4 Copyright © Multilabs – 2009 All rights reserved

The following step-by-step instructions show you how to connect Retro Core and make sure everything is working properly. Before attaching anything to Retro Core check the contents of the container. You should find the following items:

1. Retro Core 2. User CD

If any items are missing please check with Multilabs immediately for a replacement.

ABOUT RETRO CORE Retro Core is a complete single board stand alone computer packaged in a module form. This allows you to use Retro Core however you want. Embed it into your own projects, design your own motherboard around it, place it on a breadboard for experimentation; it's up to you. The versatility of Retro Core ensures that it can be used in a variety of ways. Retro Core comes as a 2.25" by 3" circuit board with a 22-pin male header on each side. These two headers give you access to all of Retro Core. With Retro Core everything is built-in. Just connect whatever connectors you need and get started. Why is it called Retro Core? Because it is just the 'Core' components of the Retro computer system; giving you just the core components gives you more flexibility to make what you want.

INITIAL CONNECTIONS Although there are numerous connections available on Retro Core this section will only deal with two of them to get you started. The two 22-pin headers and all their connections are discussed in detail in Chapter 6 There are a minimum of two connections needed in order to use Retro Core. Every computer needs a user input device, in this case a keyboard, and a user output device, in this case a VGA monitor. Besides these two user interface devices power is also needed. This section will take you through wiring up the proper keyboard and monitor connectors to Retro Core and then applying power. To make things easy all the support circuitry is incorporated into Retro Core. Only the connectors are needed, no external components. Let's start with the keyboard. Retro Core is designed to use a standard PS/2 computer keyboard. The PS/2 protocol uses two lines for communications; one for data and one for a clock. Pin 1 of Retro Core is for the PS/2 clock and pin 2 is for the PS/2 data. Pin 1 is located in the upper left-hand corner of Retro Core and is marked with a '1' (refer to the picture below).

Page 5: Retro Core User Manual

Copyright © Multilabs – 2009 All rights reserved Page 5

The pins of Retro Core are numbered from top to bottom on the left-hand side and bottom to top on the right-hand side. So that means that the top left-hand pin is pin 1, the one below it is pin 2, the next one is 3 and so on until the bottom pin is reached which is pin 22 on the lower left-hand corner. The pin numbers then start again directly across from pin 22 with pin 23 in the lower right-hand corner, the pin above that is 24, the next pin up is 25 and so on until the upper right-hand pin is reached which is number 44. Refer to the drawing below.

A PS/2 keyboard plugs into a 6-pin female mini-din connector like the one shown below. Retro Core is designed to use a standard PS/2 computer keyboard. These keyboards come with a mini-din 6-pin plug connector on them. You can use a mini-din 6-pin receptacle to connect the keyboard to Retro Core. Here are the pin-outs for a mini-din 6-pin receptacle:

Page 6: Retro Core User Manual

Page 6 Copyright © Multilabs – 2009 All rights reserved

PIN TYPE

1 Data

2 NC

3 GND

4 +5VDC

5 Clock

6 NC

Retro core has two pins that are used for communications with the keyboard. Pin 1 connects the keyboard clock and pin 2 connects to the keyboard data. The keyboard has its own power supply connection on pins 3 and 4 as shown above. Ensure that the ground of the keyboard is common with the ground of Retro Core. Below is the connection schematic:

Once the keyboard is connected take a look at the video connections. Retro Core is designed to use a standard VGA computer video monitor. These monitors come with a high density DB15 plug connector on them. You can use a high density DB15 receptacle to connect the video monitor to Retro Core. Here are the pin-outs for a high density DB15 receptacle:

Page 7: Retro Core User Manual

Copyright © Multilabs – 2009 All rights reserved Page 7

PIN TYPE NOTE

1 Red Red video (0V – 0.7V into 75Ω).

2 Green Green video (0V – 0.7V into 75Ω).

3 Blue Blue video (0V – 0.7V into 75Ω).

4 NC

5 GND Common.

6 RGND Common for red video.

7 GGND Common for green video.

8 BGND Common for blue video.

9 NC

10 SGND Common for sync signals.

11 NC

12 NC

13 HSYNC Horizontal sync.

14 VSYNC Vertical sync.

15 NC

Retro core has five pins that are used for video. Pin 13 is the analog red signal, pin 14 is the analog green signal, pin 15 is the analog blue signal, pin 16 is the vertical sync signal, and pin 17 is the horizontal sync signal. Below is the connection schematic:

Page 8: Retro Core User Manual

Page 8 Copyright © Multilabs – 2009 All rights reserved

With the keyboard and video monitor connectors wired there is only one thing left to do and that is to wire the power connections. Retro Core can be connected to any DC power source that will deliver 3.3V at a minimum of 150 milliamps. Now, if you remember back the PS/2 keyboard requires 5VDC for operation and Retro Core requires 3.3VDC. Not to worry, this does not present a problem. Retro Core comes with the necessary components to handle being connected to a 5V keyboard. Make the connections from the power supply but do not yet apply power. Connect the +3.3VDC from the power supply to pin 44 in the upper right-hand corner and the GND (common return) to pin 22 in the lower left-hand corner. When all the above steps are completed, Retro Core is correctly connected and ready for operation. Do a final check to make sure all the connections are made correctly before going on to the next section. It is a good practice to power the keyboard and Retro Core from a common supply so power is simultaneously applied to both at the same time. This can be accomplished by taking the 5VDC supplying the keyboard and connecting a 3.3V regulator to it for Retro Core's supply. This method ensures that both the keyboard and Retro Core are powered-up at the same time.

OPERATION Make sure the video monitor is turned on and then turn on the power supply for Retro Core. After a few seconds the following will be displayed on the monitor (monitor warm-up times may apply):

MULTILABS RETRO CORE

BASIC V2.0

READY

If you don't get the expected results, re-check all the connections.

CURSOR The flashing square under READY is called the cursor and indicates where what you type on the keyboard will be displayed on the screen. As you type, the cursor will move ahead one space, as the original cursor position is replaced with the character you typed. Try typing on the keyboard and watch as characters you type are displayed on the monitor.

KEYBOARD Now that you’ve typed characters on the screen its time to get familiar with the keyboard and how Retro Core uses it. When you first apply power you may notice that the caps lock, number lock, and scroll lock LEDs of the keyboard will flash on and then turn off. This is a self test that is done by every keyboard. However, Retro Core does not use these LEDs or the caps lock, number lock, or scroll lock keys during normal operation so these LEDs will always be off even through the keyboard is operating. Retro Core uses all the letter, number, and most symbol keys of the keyboard. The unused keys are: Ctrl, Alt, Caps Lock, Tab, most function keys, arrow keys, Print Screen, Scroll Lock, Pause/Break, Insert, Home, Page Up, Delete, End, Page Down, and Num Lock.

TIP Retro Core was designed for ease of operation. But we recognize that users may, occasionally, run into difficulties. To help answer your questions please contact our customer support department. Contact information can be found on our website.

Page 9: Retro Core User Manual

Copyright © Multilabs – 2009 All rights reserved Page 9

The number keypad on the right-hand side of the keyboard is used but always defaults to the number on each key. The shift keys work for keys that have two characters, like the number keys. While a shift key is not pressed the lower character on the key is displayed. When the shift key is held down the upper character is used. However, all letter characters that are typed will be displayed in capital letters. The shift keys do not perform lower/upper case changes. Retro Core does have lower case characters and they can be accessed through the CHR$ function. Use of the CHR$ function will be explained later in this manual. The <Esc> key is used to break a program while it is executing. Pressing the <Esc> key during execution will force the program to stop after the current statement is executed and then the READY message is displayed, returning control to the person operating Retro Core. Now just to make sure the keyboard is connected correctly type the following in and then hit the <Enter> key:

PRINT "HELLO WORLD" If everything is working then the message should have printed to the screen.

Page 10: Retro Core User Manual

Page 10 Copyright © Multilabs – 2009 All rights reserved

CHAPTER 2

THE BASIC LANGUAGE AND PROGRAMMING RULES

What is BASIC?

Programs and program entry

The Operating System (OS)

Integer, Floating-Point, and String Constants

Integer, Floating-Point, and String Variables

Integer, Floating-Point, and String Arrays

Expressions and Operators

Arithmetic Expressions

Arithmetic Operations

Relational Operators

Logical Operators

Hierarchy of Operations

String Operations

String Expressions

Using the INPUT Statement

Using the INKEY$ Statement

How to Crunch BASIC Programs

Page 11: Retro Core User Manual

Copyright © Multilabs – 2009 All rights reserved Page 11

This section goes through the fundamentals of the BASIC Language. We’ll explain how the syntax and operation of statements works in detail, and examples are shown to give you an idea as to how to use them in your programs.

WHAT IS BASIC BASIC (an acronym for Beginner's All-purpose Symbolic Instruction Code) refers to a family of high-level programming languages. The original BASIC was designed in 1963, by John George Kemeny and Thomas Eugene Kurtz at Dartmouth College. At the time, nearly all use of computers required writing custom software, which was something only scientists and mathematicians tended to do. BASIC was intended to address the complexity issues of older languages with a new language design specifically for a new class of computer users — that is, a less technical user who did not have the mathematical background of the more traditional users and was not interested in acquiring it. The eight design principles of BASIC were:

1. Be easy for beginners to use. 2. Be a general-purpose programming language. 3. Allow advanced features to be added for experts (while keeping the language simple for

beginners). 4. Be interactive. 5. Provide clear and friendly error messages. 6. Respond quickly for small programs. 7. Not to require an understanding of computer hardware. 8. Shield the user from the operating system.

BASIC remains popular to this day in a handful of highly modified dialects and new languages based on BASIC. This section also explains the BASIC functions built into the BASIC Language Interpreter. Built-in functions can be used in direct mode statements or in any program, without having to define the function further. The results of built-in BASIC functions can be used as immediate output or they can be assigned to a variable name of an appropriate type. There are two types of BASIC functions:

1. NUMERIC 2. STRING

Arguments of built-in functions are always enclosed in parentheses (). The parentheses always come directly after the function keyword and NO SPACES between the last letter of the keyword and the left parenthesis '('. The type of argument needed is generally decided by the data type in the result. Functions which return a string value as their result are identified by having a dollar sign ($) as the last character of the keyword. In some cases string functions contain one or more numeric arguments. Numeric functions will convert between integer and floating-point format as needed. In the descriptions that follow, the data type of the value returned is shown with each function name. The types of arguments are also given with the statement format.

PROGRAMS AND PROGRAM ENTRY Computer programs are a set of instructions that tell the computer what to do. These instructions can consist of statements, functions, operators, variables, constants, numeric expressions, and string expressions. With Retro Core each line of a program has a line number associated with it that the computer will use to execute the instructions in numeric order. A typical line in a program will first consist of a statement which is an instruction to the computer to perform a task. Following the statement will be an expression which represents the data you want the computer to act upon. Take this simple program for example:

10 PRINT "HELLO WORLD"

20 GOTO 10

Page 12: Retro Core User Manual

Page 12 Copyright © Multilabs – 2009 All rights reserved

The first line contains the statement PRINT which tells the computer that it will be printing data to the screen. The statement is followed by the expression to be printed. In this case it is a string constant. The second line starts with the statement GOTO which tells the computer that it will be GOing TO a different line number. This statement is followed by a numeric constant which represents the line number to GOTO. All of the programs executed in Retro Core are entered on the screen. When a program is not executing Retro Core is in “Editing” mode. This means that anything typed on the screen will be analyzed and acted upon when you hit the <Enter> key. As you enter lines of a program they will be analyzed and stored in the RAM memory. Before getting too deep into programming let’s first look at the inner workings of Retro Core and some of the rules for programming.

THE OPERATING SYSTEM (OS) The Operating System is contained in the central processor and is a combination of three separate, but interrelated, program modules:

1. The BASIC Interpreter – The BASIC Interpreter is responsible for analyzing BASIC statement syntax and for performing the required calculations and/or data manipulation. The BASIC Interpreter has a vocabulary of over 53 "keywords" which have special meanings. Certain punctuation characters and special symbols also have meanings for the Interpreter. The table below lists the special characters and their uses.

2. The Monitor – The Monitor handles most of the interrupt level processing in the system and also does the actual input and output of data.

3. The Screen Editor – The Screen Editor controls the output to the video screen and the editing of BASIC program text.

CHARACTER NAME AND DESCRIPTION

BLANK – Separates keywords and variable names.

; SEMI-COLON – Used in variable lists to format output.

= EQUAL SIGN – Value assignment and relationship testing.

+ PLUS SIGN – Arithmetic addition or string concatenation (concatenation: linking together in a chain).

- MINUS SIGN – Arithmetic subtraction, unary minus.

* ASTERISK – Arithmetic multiplication.

/ SLASH – Arithmetic division.

^ CARET – Arithmetic exponentiation.

( LEFT PARENTHESIS- Expression evaluation and functions.

) RIGHT PARENTHESIS – Expression evaluation and functions.

$ DOLLAR SIGN – Declares variables and functions as a string.

, COMMA – Used in variable lists to format output and also separates parameters.

. PERIOD – Decimal point in floating point numbers.

“ QUOTATION MARK – Encloses strings.

: COLON – Separates multiple BASIC statements in a line.

< LESS THAN – Used in relationship tests.

> GREATER THAN – Used in relationship tests.

The Operating System gives you two modes of BASIC operation:

1. DIRECT Mode – When you're using the DIRECT mode, BASIC statements don't have line numbers in front of the statement. They are executed whenever the <Enter> key is pressed.

2. PROGRAM Mode – The PROGRAM mode is the one you use for running programs. When using the PROGRAM mode, all of your BASIC statements must have line numbers in front of them.

Page 13: Retro Core User Manual

Copyright © Multilabs – 2009 All rights reserved Page 13

You can have more than one BASIC statement in a line of your program, but the number of statements is limited by the fact that you can only put 79 characters on a line. This means that if you are going to go over the 79 character limit you have to put the entire BASIC statement that doesn't fit on a new line with a new line number. Always type NEW and hit <Enter> before starting a new program.

INTEGER, FLOATING-POINT, AND STRING CONSTANTS Constants are the data values that you put in your BASIC statements. BASIC uses these values to represent data during statement execution. Retro Core’s BASIC can recognize and manipulate two types of constants:

1. NUMBERS – Integer and floating point 2. STRINGS

Integer constants are whole numbers (numbers without decimal points). Integer constants must be between -8,388,607 and +8,388,607. Integer constants do not have decimal points or commas between digits. If the plus (+) sign is left out, the constant is assumed to be a positive number. Zeros coming before a constant are ignored and shouldn't be used since they waste memory and slow down your program. However, they won't cause an error. Some examples of integer constants are: 8765 -32768 +44 0

Floating-point constants are positive or negative numbers and can contain fractions. Fractional parts of a number may be shown using a decimal point. Once again remember that commas are not used between numbers. If the plus sign (+) is left off the front of a number, it is assumed that the number is positive. If you leave off the decimal point the computer will assume that it follows the last digit of the number. As with integers, zeros that come before a constant are ignored. Floating-point constants will show you up to eight characters on your screen in the following formats: .XXXXXXX X.XXXXXX XX.XXXXX XXX.XXXX XXXX.XXX XXXXX.XX XXXXXX.X XXXXXXXX Floating-point numbers are stored, using four bytes of memory, and are manipulated in calculations with rounding accuracy. However, numbers are rounded to nine digits when results are printed. Some examples of simple floating-point numbers are: 1.23 +3.1459 -.01 String constants are groups of alphanumeric information like letters, numbers and symbols. When you enter a string from the keyboard, it can have any length up to 79 characters. A string constant can contain blanks, letters, numbers, and punctuation in any combination. You can even put commas between numbers. The only character which cannot be included in a string is the double quote mark (").

NOTE Do not put commas inside any number. For example, always type 32,000 as 32000. If you put a comma in the middle of a number you will get a syntax error.

Page 14: Retro Core User Manual

Page 14 Copyright © Multilabs – 2009 All rights reserved

This is because the double quote mark is used to define the beginning and end of the string. A string can also have a null value which means that it can contain no character data. Some examples of string constants are: "" (a null string) "HELLO" "$25,000.00"

INTEGER, FLOATING-POINT, AND STRING VARIABLES Variables are names that represent data values used in your BASIC statements. The value represented by a variable can be assigned by setting it equal to a constant, or it can be the result of calculations in the program. Variable data, like constants, can be integers, floating-point numbers, or strings. If you refer to a variable name in a program before a value has been assigned, the BASIC Interpreter will automatically create the variable with a value of zero if it is numeric. Or it will create a variable with a null value if you're using strings. Variable names are single characters. The character must be a letter. The string data type declaration character ($) can be used after the letter. If no type declaration character is used the Interpreter will assume that the variable is numeric. Some examples of variable names, value assignments and data types are: A$ = "GROSS SALES" (string variable) M$ = "JAN" + A$ (string variable) K=5 (numeric variable) C=C + 1.15 (numeric variable)

INTEGER, FLOATING-POINT AND STRING ARRAYS An array is a list of associated data items referred to by a single variable name. In other words, an array is a sequence of related variables. A list of numbers can be seen as an array, for example. The individual numbers within the list become "elements" of the array. Arrays are a useful shorthand way of describing a large number of related variables. Take a list of numbers for instance. Let's say that the list has 20 numbers. Without a single array name to call on you would have to assign a unique name to each value in the list. But because you can use arrays you only need one name for the array and all the elements in the array are identified by their individual locations within the array. Arrays can be numeric or string data types and all elements in the array have the same data type as the array name. Arrays can only have a single dimension (as in a simple list). Each element of an array is uniquely identified and referred to by a subscript (or index variable) following the array name, enclosed within parentheses ( ). The maximum number of subscripts an array can have in theory is 256. But for practical purposes array sizes are limited by the memory space available to hold their data. The DIM statement must be used to define the name and size of the array. Subscripts can be constants, variables, or an arithmetic expression which gives an integer result. Subscripts can have values from 0 up to 255. Values outside that range will cause the BASIC error message BAD SUBSCRIPT. Some examples of array names, value assignments and data types are: A$(0)="GROSS SALES" (string array) M$(K)="JAN" (string array) G(X)=5 (integer array) A(5)=0 (sets the 5th element in the array called "A" equal to 0)

EXPRESSIONS AND OPERATORS

NOTE Use CHR$(34) to include quotes (“) in a string.

Page 15: Retro Core User Manual

Copyright © Multilabs – 2009 All rights reserved Page 15

Expressions are formed using constants, variables and/or arrays. An expression can be a single constant, simple variable, or an array variable of any type. It can also be a combination of constants and variables with arithmetic, relational or logical operators designed to produce a single value. How operators work is explained below. Expressions can be separated into two classes: ARITHMETIC STRING Expressions are normally thought of as having two or more data items called operands. Each operand is separated by a single operator to produce the desired result. This is usually done by assigning the value of the expression to a variable name. All of the examples of constants and variables that you've seen so far were also examples of expressions. An operator is a special symbol the BASIC Interpreter recognizes as representing an operation to be performed on the variables or constant data. One or more operators, combined with one or more variables and/or constants form an expression. Arithmetic, relational, and logical operators are recognized by BASIC.

ARITHMETIC EXPRESSIONS Arithmetic expressions, when solved, will give an integer or floating-point value. The arithmetic operators (+, -, *, /,^) are used to perform addition, subtraction, multiplication, division, and exponentiation operations respectively.

ARITHMETIC OPERATIONS An arithmetic operator defines an arithmetic operation which is performed on the two operands on either side of the operator. ADDITION (+): The plus sign (+) specifies that the operand on the right is added to the operand on the left. EXAMPLES: 2 + 2 A + B + C X + 1 SUBTRACTION (-): The minus sign (-) specifies that the operand on the right is subtracted from the operand on the left. EXAMPLES: 4 - 1 A - B D – 4 The minus can also be used as a unary minus. That means that it is the minus sign in front of a negative number. This is equal to subtracting the number from zero (0). EXAMPLES: -5 -B 4 - (-2) same as 4+2 MULTIPLICATION (*): An asterisk (*) specifies that the operand on the left is multiplied by the operand on the right. EXAMPLES:

Page 16: Retro Core User Manual

Page 16 Copyright © Multilabs – 2009 All rights reserved

100 * 2 A * X R * 14 DIVISION (/): The slash (/) specifies that the operand on the left is divided by the operand on the right. EXAMPLES: 10 / 2 A / B V / 5

EXPONENTIATION (^): The caret (^) specifies that the operand on the left is raised to the power specified by the operand on the right (the exponent). If the operand on the right is a 2, the number on the left is squared; if the exponent is a 3, the number on the left is cubed, etc. EXAMPLES: 2 ^ 2 (Equivalent to: 2 * 2) 3 ^ 3 (Equivalent to: 3 * 3 * 3) 4 ^ 4 (Equivalent to: 4 * 4 * 4 * 4) 3 ^ -2 (Equivalent to: 1/3 * 1/3)

RELATIONAL OPERATORS The relational operators (<, =, >, <=, >=, <>) are primarily used to compare the values of two operands, but they also produce an arithmetic result. The relational operators and the logical operators (AND, OR, XOR, and NOT), when used in comparisons, actually produce an arithmetic true/false evaluation of an expression. If the relationship stated in the expression is true the result is assigned an integer value of – 1 and if it's false a value of 0 is assigned. These are the relational operators: < (less than) = (equal to) > (greater than) <= (less than or equal to) >= (greater than or equal to) <> (not equal to) EXAMPLES: 1 = 5 – 4 result true (-1) 14 > 66 result false (0) 15 >= 15 result true (-1) Relational operators can be used to compare strings. For comparison purposes, the letters of the alphabet have the order A < B < C < D, etc. Strings are compared by evaluating the relationship between corresponding characters from left to right (see String Operations). EXAMPLES: "A" < "B" result true (-1) "X" = "YY" result false (0) B$ <> C$ Numeric data items can only be compared (or assigned) to other numeric items. The same is true when comparing strings, otherwise the BASIC error message TYPE MISMATCH will occur. The relationship of

NOTE Division by zero is an illegal mathematical operation. Any division by zero will cause a DIVISION BY ZERO error message to be created.

Page 17: Retro Core User Manual

Copyright © Multilabs – 2009 All rights reserved Page 17

floating-point values is evaluated to give a true/false result. At the end of all comparisons, you get an integer no matter what data type the operand is (even if both are strings). Because of this, a comparison of two operands can be used as an operand in performing calculations. The result will be - 1 or 0 and can be used as anything but a divisor, since division by zero is illegal.

LOGICAL OPERATORS The logical operators (AND, OR, XOR, NOT) can be used to modify the meanings of the relational operators or to produce an arithmetic result. Logical operators can produce results other than -1 and 0, though any nonzero result is considered true when testing for a true/false condition. The logical operators (sometimes called Boolean operators) can also be used to perform logic operations on individual binary digits (bits) in two operands. But when you're using the NOT operator, the operation is performed only on the single operand to the right. The operands must be in the integer range of values (-8,388,607 to +8,388,607) (floating-point numbers are converted to integers) and logical operations give an integer result. Logical operations are performed bit-by-corresponding-bit on the two operands. The logical AND produces a bit result of 1 only if both operand bits are 1. The logical OR produces a bit result of 1 if either operand bit is 1. The logical XOR produces a bit result of 1 if both operand bits are opposites. The logical NOT is the opposite value of each bit as a single operand. In other words, it's really saying, "if it's NOT 1 then it is 0. If it's NOT 0 then it is 1." Logical operations are defined by groups of statements which, taken together, constitute a Boolean "truth table" as shown below.

OPERATION RESULTS

AND 1 AND 1 = 1 0 AND 1 = 0 1 AND 0 = 0 0 AND 0 = 0

OR 1 OR 1 = 1 0 OR 1 = 1 1 OR 0 = 1 0 OR 0 = 0

XOR 1 XOR 1 = 0 0 XOR 1 = 1 1 XOR 0 = 1 0 XOR 0 = 0

NOT NOT 1 = 0 NOT 0 = 1

The logical operators AND, OR, XOR, and NOT specify a Boolean arithmetic operation to be performed on the two operand expressions on either side of the operator. In the case of NOT, only the operand on the right is considered. Logical operations (or Boolean arithmetic) are not performed until all arithmetic and relational operations in an expression have been completed. EXAMPLES: IF A=100 AND B=100 THEN GOTO 10 (if both A and B have a value of 100 then the result is true) A=96 AND 32: PRINT A (A = 32) IF A=100 OR B=100 THEN GOTO 20 (if A or B is 100 then the result is true) A=64 OR 32: PRINT A (A = 96) IF NOT X<Y THEN GOTO 30 (if X>=Y the result is true) X = NOT 96 (result is -97 (two's complement))

HIERARCHY OF OPERATIONS

Page 18: Retro Core User Manual

Page 18 Copyright © Multilabs – 2009 All rights reserved

All expressions perform the different types of operations according to a fixed hierarchy. In other words, certain operations are performed before other operations. The normal order of operations can be modified by enclosing two or more operands within parentheses ( ), creating a "sub expression". The parts of an expression enclosed in parentheses will be reduced to a single value before working on parts outside the parentheses. When you use parentheses in expressions, they must be paired so that you always have an equal number of left and right parentheses. Otherwise, the BASIC error message SYNTAX ERROR will appear. Expressions which have operands inside parentheses may themselves be enclosed in parentheses, forming complex expressions of multiple levels. This is called nesting. The inner-most expression has its operations performed first. Some examples of expressions are: A + B C^(D + E) / 2 ((X – C ^ (D + E) / 2) * 10) + 1 G$ > H$ J$ + "MORE" The BASIC Interpreter will normally perform operations on expressions by performing arithmetic operations first, relational operations second, and then logical operations last. Both arithmetic and logical operators have an order of precedence (or hierarchy of operations) within themselves. On the other hand, relational operators do not have an order of precedence and will be performed as the expression is evaluated from left to right. If all remaining operators in an expression have the same level of precedence then operations happen from left to right. When performing operations on expressions within parentheses, the normal order of precedence is maintained. The hierarchy of arithmetic and logical operations is shown in the following table from first to last in order of precedence.

OPERATOR DESCRIPTION EXAMPLE

^ Exponentiation B ^ A

- Unary Minus (Negation)

-A

* /

Multiplication Division

A * 6 6 / H

+ -

Addition Subtraction

C + 2 7 – K

> = < Relational Operators A <= B

NOT Logical NOT NOT Z

AND Logical AND J AND 128

OR XOR

Logical OR Logical XOR

Q OR 15 P XOR 56

STRING OPERATIONS Strings are compared using the same relational operators (=, <>, <=, >=, <, >) that are used for comparing numbers. String comparisons are made by taking one character at a time (left-to-right) from each string and evaluating each character code position from the ASCII character set. If the character codes are the same, the characters are equal. If the character codes differ, the character with the lower code number is lower in the character set. The comparison stops when the end of either string is reached. All other things being equal, the shorter string is considered less than the longer string. Leading or trailing blanks are significant. Regardless of the data types, at the end of all comparisons you get an integer result. This is true even if both operands are strings. Because of this a comparison of two string operands can be used as an operand in performing calculations. The result will be - 1 or 0 (true or false) and can be used as anything but a divisor since division by zero is illegal.

Page 19: Retro Core User Manual

Copyright © Multilabs – 2009 All rights reserved Page 19

STRING EXPRESSIONS Expressions are treated as if an implied "<>0" follows them. This means that if an expression is true then the next BASIC statements on the same program line are executed. If the expression is false the rest of the line is ignored and the next line in the program is executed. Just as with numbers, you can also perform operations on string variables. The only string arithmetic operator recognized by BASIC is the plus sign (+) which is used to perform concatenation of strings. When strings are concatenated, the string on the right of the plus sign is appended to the string on the left, forming a third string as a result. The result can be printed immediately, used in a comparison, or assigned to a variable name. If a string data item is compared with (or set equal to) a numeric item, or vice-versa, the BASIC error message TYPE MISMATCH will occur. Some examples of string expressions and concatenation are:

10 A$="FILE": B$="NAME"

20 N$=A$+B$ (gives the string: FILENAME)

30 R$="NEW "+A$+B$ (gives the string: NEW FILENAME)

USING THE INPUT STATEMENT Now that you know what variables are, let's take that information and put it together with the INPUT statement for some practical programming applications. In our first example, you can think of a variable as a "storage compartment" where Retro Core stores the user's response to your prompt question. To write a program which asks the user to type in a name, you might assign the variable N$ to the name typed in. Now every time you PRINT N$ in your program, Retro Core will automatically PRINT the name that the user typed in. Type the word NEW on your Retro Core, hit the <Enter> key and try this example:

10 INPUT "YOUR NAME";N$

20 PRINT "HELLO "+N$ In this example you used N to remind yourself that this variable stands for "NAME". The dollar sign ($) is used to tell the computer that you're using a string variable. It is important to differentiate between the two types of variables:

1. NUMERIC 2. STRING

You probably remember from the earlier sections that numeric variables are used to store number values such as 1, 100, 4000, etc. A numeric variable can be a single letter (A). Now let's look at a few examples that use different types of variables and expressions with the INPUT statement:

10 INPUT "ENTER A NUMBER",A

20 PRINT A

10 INPUT "ENTER A WORD",A$

20 PRINT A$

10 INPUT "ENTER A NUMBER",A

20 PRINT A " TIMES 5 EQUALS" A*5 Calculations are important in most programs. You have a choice of using "actual numbers" or variables when doing calculations, but if you're working with numbers supplied by a user you must use numeric variables. Begin by asking the user to type in two numbers like this:

10 INPUT "TYPE 2 NUMBERS SEPARATED BY COMMAS",A,B Now multiply those two numbers together to create a new variable C as shown in line 20 below:

20 C = A * B

Page 20: Retro Core User Manual

Page 20 Copyright © Multilabs – 2009 All rights reserved

To PRINT the result as a message type:

30 PRINT A " TIMES" B " EQUALS" C Enter these 3 lines and RUN the program. Notice that the messages are inside the quotes while the variables are not. Now let's say that you wanted a dollar sign ($) in front of the number represented by variable C. The $ must be PRINTed inside quotes and in front of variable C. To add the $ to your program type in line 40 as follows:

40 PRINT"$" C Now run the program. The dollar sign goes in quotes because the variable C only represents a number and can't contain a $. If the number represented by C was 100 then Retro Core would display $ 100. But, if you tried to PRINT $C without using the quotes, you would get a SYNTAX ERROR message. One last tip about $: You can create a variable that represents a dollar sign which you can then substitute for the $ when you want to use it with numeric variables. For example:

10 Z$="$" Now whenever you need a dollar sign you can use the string variable Z$. Try this:

10 Z$ = "$":INPUT A

20 PRINT Z$ A Line 10 defines the $ as a string variable called Z$, and then INPUTs a number called A. Line 20 PRINTs Z$ ($) next to A (number). You'll probably find that it's easier to assign certain characters, like dollar signs, to a string variable than to type "$" every time you want to calculate dollars.

USING THE INKEY$ STATEMENT Most simple programs use the INPUT statement to get data from the person operating the computer. When you're dealing with more complex needs, like protection from typing errors, the INKEY$ statement gives you more flexibility and your program more "intelligence". This section shows you how to use the INKEY$ statement to add some special screen editing features to your programs. Retro Core has a keyboard buffer that holds up to 10 characters. This means that if the computer is busy doing some operation and it's not reading the keyboard, you can still type in up to 10 characters, which will be used as soon as Retro Core finishes what it was doing. To demonstrate this, type in this program on your Retro Core:

NEW

READY

10 FOR T=1 TO 100000:NEXT

20 A$=INKEY$

30 IF A$<>"" THEN PRINT A$;

40 GOTO 20 Now type RUN, hit <Enter> and while the loop in line 10 is running for 10 seconds type in the word HELLO. After the 10 second loop is complete you’ll see the HELLO appear on the screen. The stack is only used during program execution. It is not used during program entry or immediate execution. Imagine standing in line for a movie. The first person in the line is the first to get a ticket and leave the line. The last person in line is last for a ticket. The INKEY$ statement acts like a ticket taker. First it looks to see if there are any characters "in line". In other words have any keys been typed. If the answer is yes then that character gets placed in the appropriate variable. If no key was pressed then a null value is assigned to a variable.

Page 21: Retro Core User Manual

Copyright © Multilabs – 2009 All rights reserved Page 21

At this point it's important to note that if you try to put more than 10 characters into the buffer at one time, all those over the 10

th character will be lost. Since the INKEY$ statement will keep going even when no

character is typed, it is often necessary to put the INKEY$ statement into a loop so that it will have to wait until someone hits a key or until a character is received through your program. Below is the recommended form for the INKEY$ statement. Type NEW to erase your previous program:

10 A$ = INKEY$:IF A$ ="" THEN GOTO 10 Notice that there is no space between the quote marks("") on this line. This indicates an empty value and sends the program back to the INKEY$ statement in a continuous loop until someone hits a key on the computer. Once a key is hit the program will continue with the line following line 10. Add this line to your program:

100 PRINT A$;: GOTO 10 Now RUN the program. Notice that no cursor appears on the screen, but any character you type will be printed on the screen. This 2-line program can be turned into part of a screen editor program. There are many things you can do with a screen editor.

HOW TO CRUNCH BASIC PROGRAMS You can pack more instructions - and power - into your BASIC programs by making each program as short as possible. This process of shortening programs is called "crunching". Crunching programs lets you squeeze the maximum possible number of instructions into your program. It also helps you reduce the size of programs which might not otherwise run in a given size; and if you're writing a program which requires the input of data such as inventory items, numbers or text, a short program will leave more memory space free to hold data. Putting Multiple Instructions On Each Line – You can put more than one instruction on each numbered line in your program by separating them by a colon. The only limitation is that all the instructions on each line, including colons, should not exceed the 79-character line length. Here is an example of two programs, before and after crunching: Before Crunching:

10 PRINT "HELLO...";

20 FOR T=1 TO 500:NEXT

30 PRINT "HELLO, AGAIN..."

40 GOTO 10 After Crunching (takes 19 less bytes of memory):

10 PRINT "HELLO...";:FORT=1 TO 500:NEXT:

PRINT "HELLO, AGAIN...":GOTO 10 Removing REM Statements – REM statements are helpful in reminding yourself, or showing other programmers, what a particular section of a program is doing. However, when the program is completed and ready to use, you probably won't need those REM statements anymore and you can save quite a bit of space by removing the REM statements. If you plan to revise or study the program structure in the future, it's a good idea to keep a copy on file with the REM statements intact. Using Variables – If a number, word or sentence is used repeatedly in your program it's usually best to define those long words or numbers with a variable. Numbers can be defined as single letters. Words and sentences can be defined as string variables using a letter and dollar sign. Using Arrays – Arrays can handle large amounts of data as a list, with the data handling portion of the program drawing from that list, in sequence.

Page 22: Retro Core User Manual

Page 22 Copyright © Multilabs – 2009 All rights reserved

Eliminating Spaces – One of the easiest ways to reduce the size of your program is to eliminate all the spaces. Although we often include spaces in sample programs to provide clarity, you actually don't need any spaces in your program and will save space if you eliminate them. Using GOSUB Routines – If you use a particular line or instruction over and over, it might be wise to GOSUB to the line from several places in your program, rather than write the whole line or instruction every time you use it.

Page 23: Retro Core User Manual

Copyright © Multilabs – 2009 All rights reserved Page 23

CHAPTER 3

BEGINNING BASIC PROGRAMMING

Your First Program

Editing Tips

Variables

IF … THEN

FOR … NEXT Loops

Page 24: Retro Core User Manual

Page 24 Copyright © Multilabs – 2009 All rights reserved

Up to now much of the programming has been performed through simple operations by entering a single line of instructions into Retro Core. Once <Enter> was pressed, the operation was performed immediately. This is called the DIRECT mode. But to accomplish anything significant, we must be able to have the computer operate with more than a single line statement. A number of statements combined together is called a PROGRAM and allows you to use the full power of Retro Core.

YOUR FIRST PROGRAM To see how easy it is to write your first program, try this: Clear the screen by typing in CLS and pressing the <Enter> key. Type NEW and press <Enter> to clear out any data that might have been left in the computer from your experimenting. Now type the following exactly as shown:

10 PRINT "RETRO CORE"

20 GOTO 10 Now, type RUN and hit <Enter> and watch what happens. Your screen will come alive with RETRO CORE. After you've finished watching the display, hit <Esc> to stop the program. A number of important concepts were introduced in this short program that is the basis for all programming. Notice that here we preceded each statement with a number. This LINE NUMBER tells the computer in what order to work with each statement. These numbers are also a reference point, in case the program needs to get back to a particular line. Line numbers can be any whole number (integer) value between 1 and 8388607.

It is good programming practice to number lines in increments of 10 (or so) in case you need to insert some statements later on. Besides PRINT, our program also used another BASIC command, GOTO. This instructs the computer to go directly to a particular line and perform it, then continue from that point. In our example, the program prints the message in line 10, goes to the next line (20), which instructs it to go back to line 10 and print the message over again. Then the cycle repeats. Since we didn't give the computer a way out of this loop, the program will cycle endlessly, until we physically stop it with the <Esc> key. Once you've stopped the program, type LIST. Your program will be displayed, intact, because it's still in the computer's memory. The program can now be changed, saved, or run again. Another important difference between typing something in the DIRECT mode and writing a program is that once you execute and clear the screen of a DIRECT statement, it's lost. However, you can always get a program back by just typing LIST.

EDITING TIPS If you make a mistake on a line, you have a number of editing options: You can retype a line anytime, and the computer will automatically substitute the new line for the old one. An unwanted line can be erased by simply typing the line number and hitting <Enter>. You can also easily edit the current line using the backspace key to go back and erase the error and re-type it. To verify that changes were entered, type LIST again, and the corrected program will be displayed. Also, lines don't have to be entered in numerical order. The computer will automatically place them in the proper sequence. Try editing our sample program by changing line 10 and adding a comma to the end of the line:

NOTE Number 0 can not be used as a line number. Doing so will cause an error to occur.

Page 25: Retro Core User Manual

Copyright © Multilabs – 2009 All rights reserved Page 25

10 PRINT "RETRO CORE", Now type RUN. You’ll notice that line 10 was changed so that RETRO CORE is printed across the screen now.

VARIABLES Variables are some of the most used features of any programming language, because variables can represent much more information in the computer. Understanding how variables operate will make computing easier and allow us to accomplish feats that would not be possible otherwise. Imagine a number of boxes within the computer that can hold a number or a string of text characters. Each of these boxes is to be labeled with a name that we choose. That name is called a variable and represents the information in the respective box. For example, if we say:

10 X = 15

20 Y = 23.5

30 X$ = "THE SUM OF X + Y =" The computer might represent the variables like this: X 15 Y 23.5 X$ THE SUM OF X + Y = A variable name represents the box, or memory location, where the current value of the variable is stored. As you can see, we can assign either an integer number, floating point number, or a text string to a variable. The '$' following the variable name indicates the variable will represent a text string. The following are examples of string variables: A$ X$ M$ Numeric variables follow the same format, without the type indicator: A X M A variable name can only be one character. A second character can be used to indicate the type of variable (string '$'). To see how variables can be put to work, type in the following program and RUN it. Remember to first type in NEW to clear the computer memory:

10 X = 15

20 Y = 23.5

30 X$ = "THE SUM OF X + Y ="

40 PRINT "X ="; X, "Y ="; Y

50 PRINT X$; X + Y If you did everything as shown, you should get the following result printed on the screen:

X = 15 Y = 23.5

THE SUM OF X + Y = 38.5

READY

Page 26: Retro Core User Manual

Page 26 Copyright © Multilabs – 2009 All rights reserved

We've put together all the tricks learned so far to format the display as you see it and print the sum of the two variables. In lines 10 and 20 we assigned an integer value to X and assigned a floating point value to Y. This puts the number associated with the variable in its box. In line 30, we assigned a text string to X$. Line 40 combines the two types of PRINT statements to print a message and the actual value of X and Y. Line 50 prints the text string assigned to X$ and the sum of X and Y.

But variables are much more powerful. If you change their value, the new value replaces the original value in the same box. This allows you to write a statement like: X = X + 1 This would never be accepted in normal algebra, but is one of the most used concepts in programming. It means: take the current value of X, add one to it, and place the new sum into the box representing X.

IF ... THEN Armed with the ability to easily update the value of variables, we can now try a program such as:

NEW

READY

10 C = 0

20 PRINT "RETRO CORE"

30 C = C + 1

40 IF C < 5 THEN GOTO 20

50 END When you type RUN you’ll see that RETRO CORE is only printed 5 times. What we've done is introduce two new BASIC commands, and provided some control over our runaway little print program introduced at the start of this chapter. IF ... THEN adds some logic to the program. If says IF a condition holds true THEN do something. IF the condition no longer holds true, THEN do the next line in the program. A number of conditions can be set up in using an IF ... THEN statement:

SYMBOL MEANING

< Less Than

> Greater Than

= Equal To

<> Not Equal To

>= Greater Than or Equal To

<= Less Than or Equal To

The use of any one of these conditions is simple, yet surprisingly powerful. In the sample program, we've set up a "loop" that has some constrains placed on it by saying: IF a value is less than some number THEN do something. Line 10 sets C (Count) equal to 0. Line 20 prints our message. Line 30 adds one to the variable C. This line counts how many times we do the loop. Each time the loop is executed, C goes up by one. Line 40 is our control line. If C is less than 5, meaning we've executed the loop less than 5 times, the program goes back to line 20 and prints again. When C becomes equal to 5, indicating 5 RETRO CORE's were printed, the program goes to line 50 which signals to END the program.

NOTE Even though X is used as part of a numeric and string variable name, the identifier ‘$’ make X and X$ unique, thus representing two distinct variables.

Page 27: Retro Core User Manual

Copyright © Multilabs – 2009 All rights reserved Page 27

Try re-programming and see what we mean. By changing the C limit in line 40 you can have any number of lines printed. IF ... THEN has a multitude of other uses, which we'll see in future examples.

FOR ... NEXT LOOPS There is a simpler and preferred way to accomplish what we did in the previous example by using a FOR ... NEXT loop. Consider the following:

NEW

READY

10 FOR C = 1 TO 5

20 PRINT "RETRO CORE"

30 NEXT As you can see, the program has become much smaller and more direct. C starts at 1 in line 10. Then, line 20 does some printing. In line 30 C is incremented by 1. The NEXT statement in line 30 automatically sends the program back to line 10 where the FOR part of the FOR ... NEXT statement is located. This process will continue until C reaches the limit you entered. The variable used in a FOR ... NEXT loop can be incremented by smaller amounts than 1, if needed. Try this:

NEW

READY

10 FOR N = 1 TO 10 STEP .5

20 PRINT N,

30 NEXT If you enter and run this program, you'll see the numbers from 1 to 10, by 0.5, printed across the display. All we're doing here is printing the values that N assumes as it goes through the loop. You can even specify whether the variable is increasing or decreasing. Substitute the following for line 10:

10 FOR N = 10 TO 1 STEP -.5 Now RUN the program and watch the opposite occur, as N goes from 10 to 1 in descending order.

Page 28: Retro Core User Manual

Page 28 Copyright © Multilabs – 2009 All rights reserved

CHAPTER 4

ADVANCED BASIC PROGRAMMING

Simple Animation

INPUT

INKEY$

Random Numbers and Other Functions

Guessing Game

Your Roll

ASCII Codes

Page 29: Retro Core User Manual

Copyright © Multilabs – 2009 All rights reserved Page 29

This chapter has been written for people who have become relatively familiar with the BASIC programming language and the concepts necessary to write more advanced programs. For those of you who are just staring to learn how to program, you may find some of the information a bit too technical to understand completely. But take heart because for this chapter we've set up some simple examples that are written for the new user. The examples will give you a good idea of how to use Retro Core to its fullest. If you are already familiar with BASIC programming, this chapter will help you get started with advanced BASIC programming techniques.

SIMPLE ANIMATION Let's exercise some of Retro Core's graphic capabilities by putting together what we've seen so far, together with a few new concepts. If you're ambitious, type in the following program and see what happens. You’ll notice a new statement is introduced, LOCATE:

NEW

READY

10 REM BOUNCING BALL

20 CLS

30 REM MOVE BALL LEFT TO RIGHT

40 FOR B=0 TO 39

50 LOCATE B,14

60 PRINT "O"

70 FOR T=1 TO 250:NEXT

80 LOCATE B,14

90 PRINT " "

100 NEXT

110 REM MOVE BALL RIGHT TO LEFT

120 FOR B=38 TO 1 STEP -1

130 LOCATE B,14

140 PRINT "O"

150 FOR T=1 TO 250:NEXT

160 LOCATE B,14

170 PRINT " "

180 NEXT

190 GOTO 40 The program will display a bouncing ball moving from left to right, and back again, across the screen. If we look at the program closely, you can see how this feat was accomplished: Line 10 is a REMark that just tells what the program does; it has no effect on the program itself. Line 20 clears the screen. Line 30 is another REMark that indicates what this section of the program does. Line 40 setups up a loop that will execute 40 times. Line 50 introduces the LOCATE statement which moves the cursor to a specific position. In this case the X position is taken from the variable B and the Y position is a constant of 14. Line 60 PRINTs a ‘O’ at the position specified by LOCATE. Line 70 forms a simple time delay. Line 80 relocates the cursor back to the original position. Since the cursor is moved after a print command is executed it must be moved back. Line 90 PRINTs a space where the ‘O’ character was to clear it from the screen. Line 100 continues the B loop. Lines 110 – 180 are identical to lines 30 – 100 except that the outer loop goes in descending order. Line 190 goes back and starts the left to right loop over again.

Page 30: Retro Core User Manual

Page 30 Copyright © Multilabs – 2009 All rights reserved

As you notice from the program, we have set up a loop within a loop; this is called “nesting”. This is perfectly acceptable. The only time you get in trouble is when the loops cross over each other. It's helpful in writing programs to check and make sure the logic of a loop is correct. To stop the program hit the <Esc> key. When you are comfortable with the program change the values in lines 70 and 150. Larger numbers will slow down the animation and smaller numbers will speed it up. Eventually it will move so fast that it isn’t visible all the time on the screen.

INPUT Up to now, everything within a program has been set before it is run. Once the program was started, nothing could be changed. INPUT allows us to pass new information to a program as it is running and have that new information acted upon. To get an idea of how INPUT works, type NEW <Enter> and enter this short program:

10 INPUT A$

20 PRINT "YOU TYPED: ";A$

30 PRINT

40 GOTO 10 What happens when you run this simple program? A question mark will appear, indicating that the computer is waiting for you to type something. Enter any character, or group of characters, from the keyboard and hit <Enter>. The computer will then respond with "YOU TYPED:" followed by the information you entered. This may seem very elementary, but imagine what you can have the computer do with any information you enter. You can INPUT either numeric or string variables, and even have the INPUT statement prompt the user with a message. The format of INPUT is: INPUT [;] [“<prompt>”;|,] <variable> [,<variable>]*

The following program is not only useful, but demonstrates a lot of what has been presented so far, including the new INPUT statement:

NEW

READY

1 REM TEMPERATURE CONVERSION PROGRAM

5 CLS

10 INPUT “CONVERT FROM FAHRENHEIT OR CELSIUS (F/C): ",A$

20 IF A$ = "" THEN GOTO 10:REM CATCH NOTHING WAS ENTERED

30 IF A$ = "F" THEN GOTO 100

40 IF A$ <> "C" THEN GOTO 10:REM IF NEITHER F OR C TRY AGAIN

50 INPUT "ENTER DEGREES CELSIUS: ",C

60 F = (C*9)/5+32

70 PRINT C;" DEG. CELSIUS ="; F ;" DEG. FAHRENHEIT"

80 PRINT

90 GOTO 10

100 INPUT "ENTER DEGREES FAHRENHEIT: ",F

110 C = (F-32)*5/9

NOTE To get out of this program hit the <Esc> key while the cursor is blinking next to the question mark. Then type anything in and hit <Enter> and program execution will stop. When the <Esc> key is hit Retro will make note of this and will end the program when the current statement, in this case INPUT, is completed.

Page 31: Retro Core User Manual

Copyright © Multilabs – 2009 All rights reserved Page 31

120 PRINT F;" DEG. FAHRENHEIT ="; C ;" DEG. CELSIUS"

130 PRINT

140 GOTO 10 If you entered and run this program, you'll see INPUT in action. Line 10 uses the input statement to not only gather information, but also print our prompt. Also notice that we can ask for either a number or string (by using a numeric or string variable). Lines 20, 30, and 40 do some checks on what is typed in. In line 20, if nothing is entered (just <Enter> is hit), then the program goes back to line 10 and requests the input again. In line 30, if F is typed, you know the user wants to convert a temperature in degrees Fahrenheit to Celsius, so the program branches to the part that does that conversion. Line 40 does one more check. We know there are only two valid choices the user can enter. To get to line 40, the user must have typed some character other than F. Now, a check is made to see if that character is a C; if not, the program requests input again. This may seem like a lot of detail, but it is good programming practice. A user not familiar with the program can become very frustrated if it does something strange because a mistake was made entering information. Once we determine what type of conversion to perform, the program does the calculation and prints out the temperature entered and the converted temperature. The calculation is just straight math, using the established formula for temperature conversion. After the calculation is finished and answer printed, the program loops back and starts over. After running, the screen might look like this:

CONVERT FROM FAHRENHEIT OR CELSIUS (F/C): F

ENTER DEGREES FAHRENHEIT: 32

32 DEG. FAHRENHEIT = 0 DEG. CELSIUS

CONVERT FROM FAHRENHEIT OR CELSIUS (F/C): After running the program, make sure to save it. This program, as well as others presented throughout the manual, can form the base of your program library.

INKEY$ INKEY$ allows you to input one character at a time from the keyboard without hitting <Enter>. This really speeds entering data in many applications. Whatever key is hit is assigned to the variable you specify with INKEY$. The following routine illustrates how INKEY$ works:

NEW

READY

1 CLS

10 A$ = INKEY$:IF A$ = "" THEN GOTO 10

20 PRINT A$;

30 GOTO 10 If you RUN the program, the screen will clear and each time you hit a key, line 20 will print it on the display, and then get another character. It is important to note that the character entered will not be displayed unless you specifically PRINT it to the screen, as we've done here. The second statement on line 10 is also important. INKEY$ continually works, even if no key is pressed (unlike INPUT that waits for a response), so the second part of this line continually checks the keyboard until a key is hit. To stop this program you hit the <Esc> key. The first part of the temperature conversion program could easily be rewritten to use INKEY$. LOAD the temperature conversion program, and modify lines 10 and 20 as shown:

10 PRINT "CONVERT FROM FAHRENHEIT OR CELSIUS (F/C)?"

20 A$ = INKEY$:IF A$ = "" THEN GOTO 20

Page 32: Retro Core User Manual

Page 32 Copyright © Multilabs – 2009 All rights reserved

This modification will make the program operate smoother, as nothing will happen unless the user types in one of the desired responses to select the type of conversion. Once this change is made, make sure you save the new version of the program.

RANDOM NUMBERS AND OTHER FUNCTIONS Retro Core contains a number of functions that are used to perform special operations. Functions could be thought of as built-in programs included in BASIC. But rather than typing in a number of statements each time you need to perform a specialized calculation, you just type the command for the desired function and the computer does the rest. Many times when designing a game or educational program, you need to generate a random number, to simulate the throw of dice, for example. You could certainly write a program that would generate these numbers, but an easier way is to call upon the RaNDom number function. To see what RND actually does, try this short program:

NEW

READY

10 FOR X = 1 TO 10

20 PRINT RND

30 NEXT After running the program you will see 10 numbers printed on the screen. Your numbers don't match? Well, if they did we would all be in trouble, as they should be completely random! Run the program a few more times to verify that the results are different each time. Even if the numbers don't follow any pattern, you should start to notice that some things remain the same every time the program is run. First, the results are greater than or equal to 0 and less than 1. This will certainly never do if we want to simulate the random toss of dice, since we're looking for numbers from 1 to 6. The other important feature to look for is that we are dealing with real numbers (with decimal places). This could also be a problem since whole (integer) numbers are often needed. There are a number of simple ways to produce numbers from the RND function in the range desired. Replace line 20 with the following and run the program again:

20 PRINT 6*RND That cured the problem of not having results larger than 1, but we still have the decimal part of the result to deal with. Now, another function can be called upon. The INTeger function converts real numbers into integer values. Once more, replace line 20 with the following and run the program to see the effect of the change:

20 PRINT INT(6*RND) That took care of a lot, getting us closer to our original goal of generating random numbers between 1 and 6. If you examine closely what we generated this last time, you'll find that the results range from 0 to 5 only. As a last step, add a one to the statement, as follows:

20 PRINT INT(6*RND)+1 Now, we have achieved the desired results. In general, you can place a number, variable, or any BASIC expression within the parentheses of the INT function. Depending on the range desired, you just multiply the upper limit by the RND function. For example, to generate random numbers between 1 and 25, you could type:

20 PRINT INT(25*RND)+1 The general formula for generating a set of random numbers in a certain range is:

Page 33: Retro Core User Manual

Copyright © Multilabs – 2009 All rights reserved Page 33

NUMBER=INT(LOWER+(UPPER-LOWER+1)*RND)

GUESSING GAME Since we've gone to some lengths to understand random numbers, why not put this information to use? The following game not only illustrates a good use of random numbers, but also introduces some additional programming theory. In running this program, a random number, N, will be generated:

NEW

READY

1 REM NUMBER GUESSING GAME

2 CLS

5 INPUT "ENTER UPPER LIMIT FOR GUESS ";L

10 N = INT(L*RND)+1

15 C = 0

20 PRINT "I'VE GOT THE NUMBER.":PRINT

30 INPUT "WHAT'S YOUR GUESS "; G

35 C = C + 1

40 IF G > N THEN PRINT "MY NUMBER IS LOWER.":PRINT:GOTO 30

50 IF G < N THEN PRINT "MY NUMBER IS HIGHER.":PRINT:GOTO 30

60 PRINT "GREAT! YOU GOT MY NUMBER"

65 PRINT "IN ONLY"; C ;" GUESSES.":PRINT

70 PRINT "DO YOU WANT TO TRY ANOTHER (Y/N) ?"

80 A$ = INKEY$ : IF A$ = "" THEN GOTO 80

90 IF A$ = "Y" THEN GOTO 2

100 IF A$ <> "N" THEN GOTO 70

110 END You can specify how large the number will be at the start of the program. Then, it's up to you to guess what the number is. A sample run follows along with an explanation:

ENTER UPPER LIMIT FOR GUESS ? 25

I'VE GOT THE NUMBER.

WHAT'S YOUR NUMBER GUESS ? 15

MY NUMBER IS HIGHER.

WHAT'S YOUR NUMBER GUESS ? 20

MY NUMBER IS LOWER.

WHAT'S YOUR NUMBER GUESS ? 19

GREAT! YOU GOT MY NUMBER

IN ONLY 3 GUESSES.

DO YOU WANT TO TRY ANOTHER (Y/N) ? IF … THEN statements compare your guess to the number generated. Depending on your guess, the program tells you whether your guess was higher or lower than the random number generated. From the formula given for determining random number range, see if you can add a few lines to the program that allow the user to also specify the lower range of numbers generated. Each time you make a guess, C is incremented by 1 to keep track of the number of guesses. In using the program, see if you can use good reasoning to guess a number in the least number of tries. When you get the right answer, the program

Page 34: Retro Core User Manual

Page 34 Copyright © Multilabs – 2009 All rights reserved

prints out the "GREAT! YOU GOT MY NUMBER" message, along with the number of tries it took. You can then start the process over again. Remember, the program generates a new random number each time.

YOUR ROLL The following program simulates the throw of two dice. You can enjoy it as it stands, or use it as part of a larger game:

5 PRINT "CARE TO TRY YOUR LUCK?"

10 PRINT "RED DICE =";INT(6*RND)+1

20 PRINT "WHITE DICE =";INT(6*RND)+1

30 PRINT "HIT SPACE BAR FOR ANOTHER ROLL":PRINT

40 A$ = INKEY$:IF A$ = "" THEN GOTO 40

50 IF A$ = CHR$(32) THEN GOTO 10

60 END From what you've learned about random numbers and BASIC, see if you can follow what is going on.

ASCII CODES CHR$ (Character String), gives you a character, based on a standard code number from 1 to 255 (0 is a null value with no character associated with it). Every character Retro Core can print is encoded this way (see Appendix A). To quickly find out the code for any character, just type:

PRINT ASC("X") Where X is the character you're checking (this can be any printable character). The response is the code for the character you typed. As you probably figured out, ASC is another function, which returns the standard "ASCII" code for the character you typed. You can now print that character by typing:

PRINT CHR$(X) Try typing:

PRINT CHR$(65); CHR$(66) You will see the “A” and “B” characters.

PROGRAMMING TIPS 1. In lines 40, 50, 60, and 80 a colon is used to separate multiple statements on a single line.

This not only saves typing, but in long programs will conserve memory space. 2. Notice in the IF … THEN statements we instructed the computer to PRINT something, rather

than immediately branching to some point in the program. 3. Why use line numbers in increments of 10? After the program was written, we decided to add

the count part. By just adding those new lines at the program, numbered to fall between the proper existing lines, the program was easily modified.

Page 35: Retro Core User Manual

Copyright © Multilabs – 2009 All rights reserved Page 35

CHAPTER 5

GRAPHICS AND SOUND

Screen Maps

Colors

Programmable Characters

Bitmapping

Sound

Page 36: Retro Core User Manual

Page 36 Copyright © Multilabs – 2009 All rights reserved

Up to now we’ve explored some of the computing capabilities of Retro Core. But some of the most fascinating and fun features are the ability to produce color graphics and sound. You’ve seen a quick example of graphics in the “Bouncing Ball” program. But this only touched on the abilities of Retro Core. A number of new concepts will be introduced in this section to explain graphic and sound programming. Because we’ve concentrated on the computing capabilities of the machine, all the displays we’ve generated so far were a single color. In this chapter we’ll see how to add color to programs and control the graphics and sound of Retro Core.

SCREEN MAPS Retro Core has two screen maps, one for characters and one for pixels used in bitmapping (discussed later). Both of the screens are active at the same time and both characters and bitmap graphics can be displayed at the same time. The video memory is not directly accessible by the system. It is controlled by the ezVGA-LV Graphics Controller. Since this memory is not directly accessible all of the color, character, and graphics of Retro Core are accessed through BASIC commands. This makes programming more simple since it allows you to concentrate on what you want your program to do while allowing the operating system to control the complex graphic memory control functions. When placing characters on the screen using the PRINT statement you will be drawing to the character screen map. The screen can hold 40 characters across and 30 up and down. The character map is laid out like this:

Page 37: Retro Core User Manual

Copyright © Multilabs – 2009 All rights reserved Page 37

0 COLUMN 39

0

RO

W

29

Character 0,0 is in the upper left-hand corner and character 39,29 is in the lower right-hand corner. By using the LOCATE statement along with the PRINT statement you can place characters anywhere you want on the screen in any color. When a character is printed it will overwrite any character that is already there. The character will be printed in the current foreground color which you can specify through the COLOR statement. Try the following program:

10 CLS

20 FOR L = 0 TO 9

30 LOCATE L,L

40 PRINT "O";

50 NEXT

60 END Run this program and you’ll see a diagonal line of ten “O”s starting from the upper left-hand corner of the screen. Using the LOCATE statement along with PRINT you are able to control where each character is printed instead of just left to right. Combining those two statements together can be used to create some powerful graphic character programs. As stated before there is also a bitmap screen map that you can use to draw pixels to the screen and read pixel values from the screen. This map is laid out like this:

Page 38: Retro Core User Manual

Page 38 Copyright © Multilabs – 2009 All rights reserved

Using a little imagination you can fill in all the individual pixels. There are 320 pixels across and 240 pixels up and down for a total of 76,800. From the above drawing you will see that pixel 0,0 is in the upper left-hand corner and pixel 319,239 is in the lower right-hand corner. To draw a pixel on the screen you use the PSET statement. Try the following program:

10 CLS

20 FOR L = 0 TO 100

30 PSET(L,L)

40 NEXT

50 END Run this program and you’ll see a diagonal line drawn from the upper left-hand corner. The line is drawn in the current foreground color but the PSET statement has an optional color identifier that can be used to draw pixels in a color other than the current foreground color. With the POINT statement you can read the color value of individual pixels on the screen. This can be helpful in collision detection programs. The character and bitmaps screens are present at the same time and overlap each other. This allows both characters and bitmap graphics to be drawn to the screen at the same time. The last drawn character or pixel takes precedence on the screen. For example, lets say you print character 127 (solid block) in position 0,0 in color green. A green block will appear in the upper left-hand corner of the screen. Now, using the PSET statement you draw a red pixel in position 0,0. The green block that was on the screen now has a small red dot in its upper left-hand corner. Since the character and bitmap screens are overlaid anything drawn to one will affect the other. Now, reprint the green block (character 127) to space 0,0 and you’ll see that the little red dot will disappear. At this point you can print characters and dots to the screen however you want. Let’s add some color.

COLORS Retro Core comes with a color palette of 64 colors. Samples of the colors can be found in Appendix F. There are two way to use colors, the COLOR statement and the PSET statement. The COLOR statement can be used to change the foreground and background colors. Only the foreground color is required in the statement, the background color is optional. A list of the colors and their numbers can be found in Appendix F. Here are some basic colors and their values just to get you started:

COLUMN 0 319

RO

W

0

239

Page 39: Retro Core User Manual

Copyright © Multilabs – 2009 All rights reserved Page 39

Black – 0 Red – 3 Green – 12 Yellow – 15 Blue – 48 White – 63 When the COLOR statement is executed anything currently on the screen will not be changed. However, any newly printed information after the COLOR statement will be printed in the new foreground and background color. To demonstrate this and show a useful application try this simple program:

10 COLOR 3,0

20 CLS

30 PRINT "THIS TEXT IS RED"

40 COLOR 15,48

50 PRINT "THIS TEXT IS HIGHLIGHTED"

60 COLOR 3,0

70 END When you run this program the screen will be cleared and the first line will be printed in red on a black background. The next line will be printed in yellow with a blue background. This is a very useful way to use the COLOR statement to highlight text on the screen. But you’ll note that the original line was not altered. With the COLOR statement many different color characters and backgrounds can be displayed on the screen at one time. As stated in the previous section the color can also be controlled on the pixel level through the PSET command. We’ve seen that the PSET statement has an X,Y coordinate where a pixel is to be drawn and it was drawn with the current foreground color. The PSET statement has an optional color expression that allows the pixel being drawn to override the current foreground color. Try this program:

10 COLOR 63,0

15 CLS

20 PRINT "THE CURRENT FOREGROUND COLOR IS WHITE"

30 FOR X=0 TO 319

40 PSET(X,11),3

50 NEXT

60 LOCATE 0,2

70 PRINT "BUT THIS LINE WAS DRAWN IN RED!"

80 END When this program is run you’ll see the first line of text printed in white with a red line underneath it. Then the second line of text is printed in white. The PSET statement in line 40 uses the optional color to override the current foreground color.

PROGRAMMABLE CHARACTERS Retro Core comes with a standard ASCII character set which works well for doing simple stuff. But what if we want to create our own characters or change the look of some of the ASCII characters. Retro Core provides a way to add your own characters, print them, and even change the look of the built-in character set. At this point we’ll introduce a simple version of the Retro Core memory map and the POKE statement.

NOTE The color used in the PSET statement merely overrides the foreground color for that pixel. It does not change the foreground color.

Page 40: Retro Core User Manual

Page 40 Copyright © Multilabs – 2009 All rights reserved

Retro Core has a 16 bit address bus that it uses to communicate with the RAM, ezVGA-LV Graphics Controller, and the expansion port. This means that it can address 65536 different locations to read and write data to/from. A detailed version of the memory map is shown in Chapter 6. A memory map shows what bus addresses are used for what data inside a system. For now we are only interested in the addresses used for the RAM since this is where the character data is stored. When Retro Core first powers up, one of its tasks is to transfer the ASCII character data from the permanent memory into the RAM. This way the character data can be used and changed by the user.

The RAM memory addresses range from 32768 to 65535. In other words, the RAM occupies the upper 32K of address space. The lower 32K is used for the ezVGA-LV Graphics Controller and the expansion port, but more about that later. Inside the RAM the character address spaces range from 63488 to 65535. There are 8 pieces of data for each character and 256 characters so the characters take up 2K of the RAM space. Knowing where each character is in the RAM is a mater of simple math. Character 0 (null) starts at 63488 and is made up of 8 bytes. Therefore, 63488 + 8 gives you the starting address for character 1. Whereas 63488 + 16 gives you the starting address for character 2 and so on. The starting location for each character can be represented as: Starting Address = 63488 + (8 * Character Number) Now that we know how to locate each character lets take a look at what’s in there. The standard ASCII character set defines characters 0 through 127 (see Appendix A). However, only characters 32 through 127 are printable and used by Retro Core. This means that characters 1 through 31 (Character 0 is a null and it not printable), and 128 through 255 are all yours! To celebrate let’s draw a happy face.

As stated before each character is made up of 8 bytes of data. Each byte contains 8 bits so each character is 8 by 8 pixels for a total of 64 pixels. This character worksheet will help you design your own characters:

NOTE Character 8 is used for backspaces and 13 is used for carriage returns and should not be altered in any way. Characters 32 and 127 are used by the system for the cursor. All four of these should remain unaltered.

NOTE The RAM is also where your program and variable data is stored so care must be taken to only write data to the character addresses. Writing data to any unknown address of the RAM can corrupt the program or variable data.

Page 41: Retro Core User Manual

Copyright © Multilabs – 2009 All rights reserved Page 41

There are 8 row numbers which represent the 8 bytes for each character and the numbers at the top of each column represent the value of that bit position; each is a power of 2. The leftmost bit is equal to 128 or 2

7, the next is equal to 64 or 2

6, and so on, until you reach the rightmost bit (bit 0) which is equal to 1 or

20. Fill in each square on the matrix at every location where you want a pixel in your character. When

your character is ready you can create the data for your character. Let’s try our smiley face:

7 6 5 4 3 2 1 0

0

1

2

3

4

5

6

7

7 6 5 4 3 2 1 0

0

1

2

3

4

5

6

7

Page 42: Retro Core User Manual

Page 42 Copyright © Multilabs – 2009 All rights reserved

Begin with the first row. Wherever you filled in a square, add the bit values together to get the data byte. Row 0 = 2

5 + 2

4 + 2

3 + 2

2 = 32 + 16 + 8 + 4 = 60

Row 1 = 26 + 2

1 = 64 + 2 = 66

Row 2 = 27 + 2

5 + 2

2 + 2

0 = 128 + 32 + 4 + 1 = 165

Row 3 = 27 + 2

0 = 128 + 1 = 129

Row 4 = 27 + 2

5 + 2

2 + 2

0 = 128 + 32 + 4 + 1 = 165

Row 5 = 27 + 2

4 + 2

3 + 2

0 = 128 +16 + 8 + 1 = 153

Row 6 = 26 + 2

1 = 64 + 2 = 66

Row 7 = 25 + 2

4 + 2

3 + 2

2 = 32 + 16 + 8 + 4 = 60

Now that we have the eight data bytes that make up the character lets put them to use. First, the character number needs to be determined. For this example we’ll use character 128. Using the formula shown above, calculate the starting position in RAM for character 128: 63488 + (8 * 128) = 64512 Now that we have the starting position for character 128 try this program:

10 FOR L=64512 TO 64519

20 READ D

30 POKE L,D

40 NEXT

50 PRINT CHR$(128)

60 END

70 DATA 60,66,165,129,165,153,66,60 When you run the above program you should see the smiley face printed on the screen. The first four lines of the program are used to write the data for the character into the RAM. The POKE statement takes the data and places it in the location specified in the address. Once the character data has been written it can be printed using the CHR$ function. That’s it! Any character that is created will remain that way till either changed by the user or power is removed.

BITMAPPING We’ve briefly touched on bitmapping up till this point but let's get a bit more into it. It's well known at this point that using the PRINT statement can be used to place characters on the screen. This can be referred to as character graphics. Bitmap graphics can be defined as drawing on the screen using the individual pixels instead of characters. To do this the PSET statement is used. The PSET statement is used to draw a pixel at a specified X,Y coordinate on the screen. Refer to the bitmap screen drawing earlier for the allowable coordinates. The PSET statement also has an optional color expression that overrides the current foreground color. To see bitmapping in action try this program:

10 CLS

20 X=RND*320

30 Y=RND*240

40 C=RND*64

50 PSET(X,Y),C

60 GOTO 20

HINT If custom characters are not being used in your program then some of the character space in the RAM can be used to store data via the POKE statement. It can be read back through the PEEK function. Just a small hint…

Page 43: Retro Core User Manual

Copyright © Multilabs – 2009 All rights reserved Page 43

When you run this program you’ll see random pixels drawn in random colors. To stop the program just hit the <Esc> key. Notice that when the program stops and the ready line is printed both characters and bitmap graphics can be displayed on the screen at the same time. This allows for some powerful graphic combinations to be made.

SOUND Retro Core comes with a simple tone generator that you can use to add another dimension to your programs, sound. This tone generator can be accessed through the SOUND statement. The first expression in the statement is the tone to play and the second expression is the duration to play it. The sound is played in the background and is controlled through the operating system. This means that if you play a tone for 10 seconds program execution does not stop for 10 seconds. Once the SOUND statement is executed the tone and duration are passed off to the operating system so the next lines in the program can be executed while the tone is playing. However, only one tone can be played at a time. If a tone is playing and the program comes to another SOUND statement then program execution will stop until the current tone duration is complete. The new tone will then start and program execution can continue. A complete chart of the tone values and their corresponding frequencies in hertz can be found in Appendix D. Some common tone values are 89, 79, 75, 66, 59, 56, and 50. The second expression, duration, is in increments of approximately 0.05 second. This means that a duration value of 10 will last about ½ second. Try this program to hear an example of the sounds:

10 FOR L=1 TO 7

20 READ D

30 SOUND D,10

40 NEXT

50 END

60 DATA 89,79,75,66,59,56,50 Sound is accessed through the pin headers of Retro Core. The connection for sound output is discussed in Chapter 6. This output MUST be connected to an external amplifier. Do not directly connect a speaker to this pin. Connecting a speaker directly to this pin could damage some the sound circuitry. To try out the full range of the SOUND statement try this simple program:

10 FOR L=1 TO 255

20 SOUND L,10

30 NEXT

40 END When you run this program each tone, starting with the highest frequency, will be played for ½ second a piece.

Page 44: Retro Core User Manual

Page 44 Copyright © Multilabs – 2009 All rights reserved

CHAPTER 6

RETRO CORE IN MORE DETAIL

File System

Memory Map

Who Says Characters Have to be Characters

Connections

Page 45: Retro Core User Manual

Copyright © Multilabs – 2009 All rights reserved Page 45

At this point some basic programming skills and techniques have been discussed and developed. The features of Retro Core’s BASIC, graphics, and sound capabilities have been shown and detailed. Everything you need to get started programming Retro Core and having fun is in your hands now. But where do you go from there? Loading and saving programs? What if you want to try some fancy programming or have Retro Core communicate with the outside world? What if you want to hook up your own electronic circuits to Retro Core and write programs to control them with? If this sounds appealing to you then read on. In this chapter we’ll introduce you to the filing system, addressing, and memory organization of Retro Core. Also, an explanation of all the connections will be given. This will serve as a prelude to the next chapter that will show you some examples of the input and output functions of Retro Core.

FILE SYSTEM Retro Core comes with the ability to save and load your program files. Programs are stored in non-volatile memory which means that they will not be lost when power is removed. Retro Core also comes with the ability to automatically load a program upon power-up and run it. This handy feature allows Retro Core to automatically run a program without any user intervention. But first let's take a look at the basics. Retro Core comes with a storage device built into it from the factory. This is called 'Device 0'. If more program storage is needed an external device can be connected to Retro Core. This is called 'Device 1'. Refer to the connections section later in this chapter for more information on connecting an external storage device. There are four statements that Retro Core uses to access the filing system. LOAD is used to load a program from the storage device into RAM memory. SAVE is used to save a program from RAM memory into the storage device. DELETE is used to delete a program from the storage device to make room for other programs. DIR is used to list a directory of files in the storage device. Here is an example of each statement:

LOAD "PROGRAM 1",0

SAVE "PROGRAM 2",0

DELETE "PROGRAM 3",0

DIR 0 The file name can be any length and can contain any character that can be typed in from the keyboard. With each statement there is a device number at the back. In the samples above device 0 is used. To use these statements with an external device the 0 is changed to a 1 to represent device 1. Programs are stored in the ordered that they are saved with the first saved program appearing at the top of a directory list. When a file is loaded and then resaved it will be moved from its current location down to the bottom of the list. If, during a save, the storage device runs out of storage space an OUT OF MEMORY error will occur. To create a program that is automatically loaded and run upon power-up put an asterisk (*) as the first character of the file name. For example:

SAVE "*PROGRAM 4",0 The asterisk must be the first character of the file name. An asterisk anywhere else in the file name will be ignored by the startup routine. If multiple files are saved with a asterisk as the first character Retro Core will run the first one it encounters. To see the order of the programs in a storage device you use the DIR statement. Secondly, the program must be stored in device 0. Programs stored in device 1 are not checked by the startup routine. Once the program is loaded it will automatically begin running. Exiting the program is the same as any other program; use the <Esc> key to break the program.

MEMORY MAP

Page 46: Retro Core User Manual

Page 46 Copyright © Multilabs – 2009 All rights reserved

As discussed earlier, Retro Core has a 16-bit address bus to control the memory, graphics controller, and expansion port. There are other devices on Retro Core that have their own dedicated bus that are not part of the system address bus. These devices can not be directly controlled through any program so they will not be discussed. What is an address? An address is a single location that a byte of data can be written to or read from. Having a 16-bit address bus means that there are 65536 addresses that data can be written/read from. Does that mean that you can type in the following program and run it?

10 FOR L = 0 TO 65535

20 PRINT PEEK(L)

30 NEXT Yes it does. Will all the data be meaningful? No. In some cases, the data will be completely worthless. Can you do this program?

10 FOR L = 0 TO 65535

20 POKE L,0

30 NEXT Yes you can. Just don’t expect it to work or do anything of value except crash the computer. Running this program would erase the program, perhaps even print gibberish to the screen, before crashing the system. The point to be made here is that understanding and using the memory map of any computer system takes great care. It can unleash a great power over the computer system. But as always, with great power comes great responsibility. Before you try PEEKing and POKEing anything with Retro Core lets first look at how the addresses are organized in the system with the following memory map:

There it is. All 64K of address space summed up in a simple table. The addresses shown on the left hand side are represented in hexadecimal format. If you’re not familiar with it don’t worry. Here are the decimal conversions: 0xFFFF = 65535 0xF800 = 63488 0xF7FF = 63487 0x8000 = 32768 0x7FFF = 32767 0x4000 = 16384 0x3FFF = 16383 0x0000 = 0

NOTE Even through the ezVGA-LV Graphics Controller is connected to the main system address bus it can only be accessed with the print and graphic commands built into BASIC for any drawing or character placement.

2K of RAM Used For Character Bitmaps

30K of RAM Used For Program Storage, Variables, and System

Stack

16K Used To Access the ezVGA-LV Graphics Controller

16K of Open Address Space for Expansion

0xFFFF

0xF800 0xF7FF

0x8000 0x7FFF

0x4000 0x3FFF

0x0000

Page 47: Retro Core User Manual

Copyright © Multilabs – 2009 All rights reserved Page 47

Addresses 0 through 16383 are all yours. These can be used with the expansion port to access and control external circuits. We’ll discuss this more in detail in the next chapter. Addresses 16384 through 32767 are dedicated to controlling the ezVGA-LV Graphics Controller. However, as stated in the above note it can only be accessed through the BASIC statements. That leaves the RAM addresses. With care these can be experimented with; even while your program is running. Program storage starts at address 32768 and expands upward towards the character storage area. If the program, variables, and system stack get so large that they will go into the character storage space (starting address 63488) an OUT OF MEMORY error will occur. However, if the program is small and not many variables are used then there will be some open space for you to play with. Unfortunately, there is no way to know where it all stops at. You can print the FRE function to get a good idea at how much program space is left once the program is entered but variables and stacks are dynamic and change during program execution. Here are some helpful guidelines:

1. Once the entire program is entered print the FRE function to see how much memory is left. 2. Take a count of all the variables and arrays used in your program. Each numeric variable takes

up 5 bytes of memory, each string variable takes up 81 bytes of memory, each numeric array takes up 6 bytes of memory, and each string array takes up 82 bytes of memory. You can add up all your variables and arrays and get a good idea of how much memory they will take.

3. There are no rules for the stack. This is dynamic and how much space is needed at any given point will depend on the needs of the program. If you have simple equations in your program, say no more than 2 levels deep of parenthesis, allocating 256 bytes for the stack would be a safe guess; but there are no guarantees!

Why go through all of this? Well, unused RAM can be used by your program to store data. Storing data can, of course, be done with variables and arrays but it’s good to know that it can be done if needed. If you do want to PEEK and POKE data in and out of RAM a good rule of thumb, besides the three mentioned above, is to start your storage at the top address starting at 63487 and work your way down. Since the operating system stores the program, variables, and stack starting at 32768 you’ll be as far away from them as you can be so there is less chance of crossing the data.

WHO SAYS CHARACTERS HAVE TO BE CHARACTERS Well, you just wrote a long program and the program itself took up most of the RAM. There isn’t enough room left for all your variables. What do you do now? Does your program use any custom characters? If no, or uses only a few, then there is a solution. As shown in the memory map the upper 2K of address space is reserved for 256 characters. Some characters are the ASCII characters used by the operating system to display characters, numbers, symbols, etc. but the rest are for the programmer. If you’re not going to use them for character data then use them for your other data. Characters 32 through 127 are the ASCII characters used by the system but characters 1 through 31 and 128 through 255 are open. The exception to this, as previously stated, are characters 8, 13, 32, and 127. These are used by the system and should not be altered in any way. In the previous chapter we discussed custom characters and how to locate the starting address for each character and that each character is 8 bytes. With this information you can PEEK and POKE data into these memory locations for your own data.

CONNECTIONS At the beginning of this manual only the connections for the keyboard, video monitor, and power were briefly introduced. This section will give you a bit more detail about each connection. Power Connection – Retro Core is designed to work from a +3.3VDC power supply. Pin 44 connects to the +3.3V and pin 22 is the common ground. Refer to the below table and highlighted block diagram:

PIN TYPE NOTE

22 GND Common ground for Retro Core and any device connected to it.

Page 48: Retro Core User Manual

Page 48 Copyright © Multilabs – 2009 All rights reserved

PIN TYPE NOTE

44 +3.3VDC Use a power supply with a minimum source current of 150mA.

Keyboard Connection – Retro Core is designed to use a standard PS/2 computer keyboard. These keyboards come with a mini-din 6-pin plug connector on them. You can use a mini-din 6-pin receptacle to connect the keyboard to Retro Core. Here are the pin-outs for a mini-din 6-pin receptacle:

Page 49: Retro Core User Manual

Copyright © Multilabs – 2009 All rights reserved Page 49

PIN TYPE

1 Data

2 NC

3 GND

4 +5VDC

5 Clock

6 NC

Retro core has two pins that are used for communications with the keyboard. Pin 1 connects the keyboard clock and pin 2 connects to the keyboard data. The keyboard has its own power supply connection on pins 3 and 4 as shown above. Ensure that the ground of the keyboard is common with the ground of Retro Core. Below is the connection schematic:

Optional Extra Program Storage Connection (Device 1) – Retro Core comes with non-volatile memory built on board for program storage. If additional program storage is needed or if programs need to be transferred Retro Core comes with pins for connecting an external program storage device. This is referred to a device 1, with device 0 being the built on storage. Any standard 24LC32, 24LC64, 24LC128, 24LC256, and 24LC512 EEPROM can be used. Retro Core has two pins that are used for communications with the external storage device. Pin 3 connects the device clock and pin 4 connects to the device data. Below is the connection schematic:

Page 50: Retro Core User Manual

Page 50 Copyright © Multilabs – 2009 All rights reserved

Joystick Connection – Retro Core is designed to interface with a 5-switch digital joystick. These joysticks come with a DB9 receptacle on them. You can use a DB9 plug to connect the joystick to Retro Core. Here are the pin-outs for a DB9 plug:

PIN TYPE

1 Up

2 Down

3 Left

4 Right

5 NC

6 Fire

7 NC

8 GND

9 NC

Retro core has five pins that are used for the joystick. Pin 5 connects to the up button, pin 6 to the right button, pin 7 to the down button, pin 8 to the left button, and pin 9 to the fire button. Below is the connection schematic:

Page 51: Retro Core User Manual

Copyright © Multilabs – 2009 All rights reserved Page 51

These pins are used for detecting contact closures. So even though it was original designed for use with digital style switch joysticks these pins can be used for detecting any contact closure. This makes them useful as general input pins. These pins are pulled logic high by Retro Core. A closure is detected by pulling the pin logic low. Sound Connection – Retro Core comes with a tone generator that outputs on pin 10. This is a line level output and needs to be connected to an external amplifier. Connecting a speaker directly to this pin could damage the pre-amp circuitry on Retro Core. Below is the connection schematic:

Page 52: Retro Core User Manual

Page 52 Copyright © Multilabs – 2009 All rights reserved

Serial Communications Connection – Retro Core comes with an asynchronous communications port. There are two pins associated with it. Pin 11 is for transmission and pin 12 is for reception. The voltage levels for these communication pins are LVTTL (0 to 3.3V). If RS232 levels are required (±12V with inverted logic) then a level converter chip is needed. Below is a schematic for connecting such a chip to Retro Core. If Retro Core is communicating with another device that uses the same LVTTL communication levels then direct connections can be made between them.

NOTE The maximum current that can be sourced or sunk through Retro Core's Tx serial communications pin is 2mA.

Page 53: Retro Core User Manual

Copyright © Multilabs – 2009 All rights reserved Page 53

Video Connection – Retro Core is designed to use a standard VGA computer video monitor. These monitors come with a high density DB15 plug connector on them. You can use a high density DB15 receptacle to connect the video monitor to Retro Core. Here are the pin-outs for a high density DB15 receptacle:

PIN TYPE NOTE

1 Red Red video (0V – 0.7V into 75Ω).

2 Green Green video (0V – 0.7V into 75Ω).

3 Blue Blue video (0V – 0.7V into 75Ω).

4 NC

5 GND Common.

6 RGND Common for red video.

7 GGND Common for green video.

8 BGND Common for blue video.

9 NC

10 SGND Common for sync signals.

11 NC

12 NC

13 HSYNC Horizontal sync.

14 VSYNC Vertical sync.

15 NC

Retro core has five pins that are used for video. Pin 13 is the analog red signal, pin 14 is the analog green signal, pin 15 is the analog blue signal, pin 16 is the vertical sync signal, and pin 17 is the horizontal sync signal. Below is the connection schematic:

Page 54: Retro Core User Manual

Page 54 Copyright © Multilabs – 2009 All rights reserved

Expansion Connections – Retro Core comes with a means for connecting external devices to the address and data buses. Refer to the below table for a list of the pins and the highlighted block diagram showing the pin locations. These connections are discussed in more detail in the next chapter.

PIN TYPE NOTE MAX CURRENT SOURCED/SUNK

18 R/W Logic high for a read, low for a write. 1mA

19 D0 Data line. 24mA

20 D1 Data line. 24mA

21 D2 Data line. 24mA

23 D3 Data line. 24mA

24 D4 Data line. 24mA

25 D5 Data line. 24mA

26 D6 Data line. 24mA

27 D7 Data line. 24mA

28 A0 Address line. 7mA

29 A1 Address line. 7mA

30 A2 Address line. 7mA

31 A3 Address line. 7mA

32 A4 Address line. 7mA

33 A5 Address line. 7mA

34 A6 Address line. 7mA

35 A7 Address line. 7mA

36 A8 Address line. 7mA

37 A9 Address line. 7mA

38 A10 Address line. 7mA

39 A11 Address line. 7mA

40 A12 Address line. 7mA

Page 55: Retro Core User Manual

Copyright © Multilabs – 2009 All rights reserved Page 55

PIN TYPE NOTE MAX CURRENT SOURCED/SUNK

41 A13 Address line. 7mA

42 A14 Address line. 7mA

43 A15 Address line. 7mA

Page 56: Retro Core User Manual

Page 56 Copyright © Multilabs – 2009 All rights reserved

CHAPTER 7

INPUT/OUTPUT GUIDE

Serial Communications

Joystick

Who Says the Joystick Has to be a Joystick

Expansion

Addressing

RW Line

Selecting Different Devices

Data Bus

Sample Addressing Circuit

IOPA-LV Chip

Timing Diagrams

Page 57: Retro Core User Manual

Copyright © Multilabs – 2009 All rights reserved Page 57

The world inside of Retro Core has been covered front to back. The entire manual up until this point has been dedicated to it. What about the outside world? Its now time to let Retro Core touch the outside world, this chapter will cover communications and control. There are three ways Retro Core has to communicate and control things outside of the system. There is a serial communications pins which will perform simple transmission and reception of data via RS232 signals, the joystick pins are read only pins that are used to detect user feedback, and the expansion pins give you the greatest control of passing parallel data into and out of Retro Core.

SERIAL COMMICATIONS The asynchronous mode of operation uses standard non-return-to-zero (NRZ) format (one start bit, eight data bits, and one stop bit). The serial pins transmit and receive the least significant bit first. The transmitter and receiver are functionally independent and can work as full duplex. Parity is not supported. Retro Core uses LVTTL signals for transmission and reception of serial data. If connecting to a device that uses RS232 signal levels then a converter, such as the MAX3232, will need to be used. RS232 is an electrical specification for signals used by many computer serial ports. Unlike normal LVTTL logic, in which a 1 is represented by 3.3V and a 0 by 0V, RS232 uses -12V for 1 and +12V for 0. When converting between logic level signals and RS232 signals most circuits use a line-receiver. This does two things. First, it converts the ±12V to logic compatible levels. Secondly, it inverts the relationship of the voltage levels so that 5V is logic high and 0V is logic low. If you’re communicating with another Retro Core the two can be connected together without any conversion circuitry. However, if you are communicating with a PC, or another device that uses RS232 level signals, then a line-receiver chip, such as the MAX3232, will be needed. There are 4 BASIC statements and 1 function that you use in conjunction with serial communications. The first thing that is needed is to “open” the port. This can be accomplished with the SOPEN statement. With this statement you also specify the baud rate for the serial port. The baud rate for Retro Core must be between 2400 and 115K. Once the port is open you can transmit data with the SPUT statement and receive data with the SGET statement. For both of these statements both numeric and string expressions can be used. Retro Core will convert the data to the correct type automatically. In most cases it is helpful to know if there is data waiting to be read. Retro Core comes with a 2 byte first-in-first-out (FIFO) buffer for data reception. The status of this buffer can be read using the SINBUFFER function. If there is data waiting SINBUFFER will have a value of -1 or true. If there is no data waiting then it will have a value of 0 or false. This can be very useful since reading data while the buffer is empty will return a zero. Since zero can be a valid piece of data you would have no means to determine if it is data or the buffer is empty.

Finally, when the serial port is no longer needed it can be closed using the SCLOSE statement. This needs to be done if you are also switching baud rates. In order to change baud rates first the port must be closed and then re-opened with the new baud rate. Executing a SOPEN statement while the port is open will result in an error. To practice with serial communications connect Retro Core to your PC serial port using a line-receiver chip or similar circuit to convert the LVTTL signals of Retro Core to RS232 level signals. With the two connected open a terminal program on the PC set for 9600 baud and try this reception program first:

10 CLS

NOTE When the receive FIFO buffer is full any data received afterwards will be lost. It is wise to check the buffer often or setup a “handshaking” routine where the program transmits data to indicate it is ready to receive data.

Page 58: Retro Core User Manual

Page 58 Copyright © Multilabs – 2009 All rights reserved

20 SOPEN 9600

30 IF SINBUFFER=0 THEN GOTO 30

40 SGET A$

50 PRINT A$

60 GOTO 30 When you run this program the screen will clear and Retro Core will open the serial port at 9600 baud and then wait for data to arrive. When it does it is retrieved and printed. Press the <Esc> key to exit the program. Send some characters with the PC terminal program and watch them appear on Retro Core’s screen. Since Retro Core only has a two stage buffer it can fill up quite quickly. If the data is coming in faster than the buffer can be cleared than data will be lost. For example, the above program works with a continuous data stream at 9600 baud. However, if higher baud rates are used (i.e. 14400, 19200, 28800, etc) then a delay should be put between each character to allow Retro Core to retrieve the data and process it. With this program a delay of 1 to 2 milliseconds between data bytes is sufficient. Now, let’s go in the opposite direction. Try this program out:

10 CLS

20 SOPEN 9600

30 A$=INKEY$

40 IF A$="" THEN GOTO 30

50 SPUT A$

60 GOTO 30 Run this program and type characters on Retro Core’s keyboard and watch them appear on the PC’s terminal program. Press the <Esc> key to exit the program.

JOYSTICK The joystick pins can be connected to work with a standard digital 5-switch joystick (see the previous chapter). These types of joysticks were quite popular in the earlier days of computers but are still easy to find on the internet for reasonable costs in factory new condition. Unlike the serial communications and expansion pins these pins are one-way only; read only. Inside a digital joystick are five switches. One for up movement, down movement, left movement, right movement, and the fire button. The five inputs of Retro Core are held at logic high while none of these switches is active. When a switch inside the joystick is pressed through either movement or pressing the fire button that line will go logic low into Retro Core since all five switches are connected to ground. The state of the switches can be read with the JOY function. When the JOY function is executed it reads the value of the joystick pins and returns a value. This function has a single expression that indicates which joystick port to read. Retro Core only has pins for one joystick and it is indicated as 0 so this number needs to be used for the expression. With a joystick connected try this little program:

10 CLS

20 A=JOY(0)

30 IF A=0 THEN GOTO 20

40 PRINT A

50 GOTO 20 When you run the program nothing will be printed on the screen since there is no joystick movement or fire button pressing. This results in a 0 being returned by the JOY function. Now move the joystick in

Page 59: Retro Core User Manual

Copyright © Multilabs – 2009 All rights reserved Page 59

different directions and press the fire button to see what happens. Hitting the <Esc> key will exit the program. Numbers should have appeared on the screen. What do they mean? Here is a list of number associations: Up = 1 Right = 2 Down = 4 Left = 8 Fire Button = 16 Move the joystick up and 1 will be written to the screen. Move it down and 4 will be written to the screen. The numbers can also be added together. For example, if you move the joystick up and to the right a 3 will be printed. If you move left while pressing the fire button a 24 will be printed.

WHO SAYS THE JOYSTICK HAS TO BE A JOYSTICK As was said, the joystick is a device with 5 switches in it. The joystick pins can also be used to read data or switch status from your own project. Connect 5 switches to the joystick port and experiment. Or better yet, 5 magnetic switches and move a magnet slowly over them one by one. Now you have yourself a position sensor. You can take it from here.

EXPANSION We’ve saved the best for last. With the expansion pins there is an almost limitless possibility. This subject could be a book within itself but we’ll give you the basics of addressing devices and show you some working examples of how to read and write data to external devices. With the expansion pins Retro Core can be used to control and monitor your own circuits. A MUST READ: Before we begin the discussion about the expansion pins it is important to go over a few rules. First and foremost the expansion pins give you access to the data and address buses of Retro Core. These buses are the “central nervous system” of any computer. If one or both are damaged the system fails. When you are connected to the expansion pins of Retro Core you are connected to the central processor, graphics processor, and the RAM memory directly. Extreme caution must be taken while connected. Any short circuits, power surges, illegal writes to the data bus, etc. may damage one or all of these parts and damage Retro Core to where it is no longer useful. If the examples are followed and the rules of addressing and data transfer are observed there will be no problems and everything will work solid for as long as you would like it to. To avoid shorts do not work on your circuit while it is connected to Retro Core and make sure all your electrical connections are sound. Proper practices in design and construction will ensure that this will be a fun experience. I, the author, know this from first hand experience. I blew out my first computer playing with its user port. Four of the chips, including the CPU, were blown and the computer was destroyed. Since then I’ve connected countless circuits to computers of all kinds with no problems. To was a hard way to learn the rules.

ADDRESSING The concept of an address in not new to any us, we each have a street address or a post office box number where mail can be sent to us. The address uniquely identifies us from our neighbors. The system works the exact same way in a computer system. Each address uniquely identifies a device and the location in that device to read/write data to/from. For example, remember the memory map from the previous chapter. Let’s take a closer look at that now.

Page 60: Retro Core User Manual

Page 60 Copyright © Multilabs – 2009 All rights reserved

As discussed before the address bus of Retro Core is 16 bits which gives it 65536 unique addresses. From the memory map above we see that the RAM takes up the upper 32K of address space. This means that when bit A15 of the address bus is logic high then the RAM is selected. Address lines A0 through A14 are used to select which memory location data is written to/read from. Address line A15 sole purpose is to select/enable the RAM chip and make sure that all other devices connected to the bus system are disabled so that the RAM has control over the data bus. When a logic device is unselected/disabled it should make all its output lines high-impedance. This means that the outputs are turned off and a high resistance is seen at the output pins. This brings us to expansion rule number #1: When address line A15 is logic high any device connected to the data bus must be disabled and have high-impedance outputs. Continuing to look at the memory map we see that the ezVGA-LV Graphics Controller is located in the high 16K of the lower 32K of address space. This means that when bit A15 of the address bus is logic low and A14 of the address bus is logic high then the ezVGA-LV Graphics Controller is selected. Address lines A0 through A13 are used to select which memory location data is written to/read from. Address lines A15 and A14 sole purpose is to select/enable the graphics chip and make sure that all other devices connected to the bus system are disabled so that the graphics chip has control over the data bus. This brings us to expansion rule number #2: When address line A14 is logic high any device connected to the data bus must be disabled and have high-impedance outputs. From the first two rules we can surmise that if either A15 or A14 are logic high then any devices connected to the expansion pins must be disabled. In other words, both A15 and A14 must be logic low. When they are both logic low that means the lower 16K of the lower 32K of address space is selected and from our memory map we see that this where the expansion pins comes in. This lower 16K is unused by anything in the Retro Core system. So when A15 and A14 are both logic low the data bus is up for grabs.

READ/WRITE LINE So both A15 and A14 are logic low and the data bus is yours for the taking. There is one more line for you to monitor. The read/write (RW) line is the traffic cop of the data bus. This signal indicates whether data is being written to or read from the central processor. When the RW line is logic high the data bus is in read mode. This means that the central processor is in input mode and data is being written to it. When the RW line is logic low the data bus is in write mode. This means that the central processor is in output mode and data is being read from it. When a logic low is present on the RW line any logic device connected to the data bus should make all its output lines high-impedance. This brings us to expansion rule number #3: When the RW line is logic low any device connected to the data bus must have high-impedance outputs.

SELECTING DIFFERENT DEVICES

2K of RAM Used For Character Bitmaps

30K of RAM Used For Program Storage, Variables, and System

Stack

16K Used To Access the ezVGA-LV Graphics Controller

16K of Open Address Space for Expansion

0xFFFF

0xF800 0xF7FF

0x8000 0x7FFF

0x4000 0x3FFF

0x0000

Page 61: Retro Core User Manual

Copyright © Multilabs – 2009 All rights reserved Page 61

At this point we know to monitor address lines A15 and A14 along with the RW line. From these three we can tell if the data bus is free and what direction the data is flowing from the central processor. The last step is learning how to use address lines A0 through A13. To take advantage of all these address you need a logic device called an address decoder. Take the 32K RAM that is part of Retro Core as an example. The RAM is enabled through address line A15. Address lines A0 through A14 are used to select which of the 32768 memory locations is used for the read/write operation. To do this the RAM comes with a built-in address decoder that turns those 15 address lines into a single signal for each memory location. While this takes a lot of logic to accomplish there are some easy ways to do this with simple logic gates and decoder chips. One simple logic device is called a decoder. They come in 2-line to 4-line, 3-line to 8-line, and 4-line to 16-line packages just to name a few popular ones. In the low voltage logic series these chips are 74LVC139, 74LVC138, and 74HC154 respectively. With a 2-line to 4-line decoder 2 address lines are used to select 4 devices. The 3-line to 8-line decoder uses 3 address lines to select 8 devices. A 4-line to 16-line decoder monitors 4 address lines to select 16 devices. If you look at datasheets for these devices you’ll see the logic that is used to decode the address lines. It is far easier to use one of these devices then to use discrete logic.

DATA BUS While in write mode (data is being written from the central processor) the levels of each data bit are roughly 3.3V for logic high and 0V for logic low. In read mode (data is being written to the central processor) the logic levels outputted from your device must be observed. The central processor uses Schmitt Trigger input buffers. This means that logic high must be greater than 2.64V and a logic low must be lower than 0.66V. Some devices may fall outside of these parameters and should be avoided.

SAMPLE ADDRESSING CIRCUIT Let's take a look at a simple addressing circuit.

In this example we won’t use all the lines available, just the ones necessary to get us started. Any noise your projects generate can be transmitted into Retro Core. It is a good practice to use decoupling

Page 62: Retro Core User Manual

Page 62 Copyright © Multilabs – 2009 All rights reserved

capacitors and filter capacitors such as the one connected to VCC of chip U1. Too much noise introduced into Retro Core may cause improper operation; this should be monitored. The chip in the sample is the decoder that was previously discussed; the 74LVC138. On the address side of the chip inputs A, B, and C are connected to address lines A0, A1, and A2 respectively. Inputs G2A and G2B are connected to address lines A15 and A14 respectively. Input G1 is not used and is tied high. All three inputs G1, G2A, and G2B are used to select the chip. In order for the chip to be selected G1 must be logic high, G2A must be logic low, and G2B must be logic low. If these conditions are not met all eight outputs will remain logic high no matter what data is present on A, B, and C. This satisfies the first 2 expansion rules, both address lines A15 and A14 must be logic low. Since G1 is permanently tied logic high address lines A15 and A14 determine when this chip is selected. They both have to be logic low for that to happen. So what happens when both address lines A15 and A14 are logic low? The chip is selected and the three address inputs A, B, and C determine which of the three outputs are active. On the 74LVC138 an output is said to be active when it is outputting a logic low signal; this is called active low. Remember, when the chip is not selected, all outputs are logic high no matter what. Refer to the following truth table:

C B A ACTIVE OUTPUT

0 0 0 Y0

0 0 1 Y1

0 1 0 Y2

0 1 1 Y3

1 0 0 Y4

1 0 1 Y5

1 1 0 Y6

1 1 1 Y7

This simple circuit can be used to address up to 8 devices using the 8 active low outputs. With this circuit address 0 would activate output Y0, address 1 would activate output Y1, and so on until address 7 which would activate Y7. However, if you look closely at the schematic you’ll see we’re only monitoring address lines A0 through A2. With address 8, for example, A3 is logic high and A0 through A2 are all logic low. So to the 74LVC138 it looks like address 0. In order to expand upon this and ensure that this chip is only selected with addresses 0 through 7 you would need to add logic circuitry that monitored address lines A3 through A13 and would keep the 74LVC138 deselected if any of them were logic high. Remember from the schematic that G1 is permanently tied high? Well, put A3 through A13 into a NOR gate so that if any of them are logic high the output of the NOR gate would be logic low. Since G1 has to be logic high in order for the chip to be selected tie the output of the NOR gate to G1 and you got it. Now the chip would not be selected on addresses 8 and higher. These discrete logic chips work out for a lot of circuits. However, as the circuit become more complex more discrete chips and needed and the connection schematics can become quickly unorganized. Retro Core has an accessory chip that allows you to easily access 16 general purpose I/O pins and the best part is all the logic is provided in a single chip.

IOPA-LV CHIP The following schematic shows a typical setup for an IOPA-LV chip connected to Retro Core.

Page 63: Retro Core User Manual

Copyright © Multilabs – 2009 All rights reserved Page 63

Page 64: Retro Core User Manual

Page 64 Copyright © Multilabs – 2009 All rights reserved

To simplify the example only Port A is used. Port A has four LEDs to drive as outputs and 4 switches to read as inputs. Addressing the IOPA-LV is a matter of connecting the addressable inputs to the correct address lines of Retro Core. As was discussed before both address lines A15 and A14 need to be logic low before anything connected to the expansion pins can be addressed. So those two address lines connect to the two active low chip select inputs of the IOPA-LV. The third chip select line, CS3 which is active high, is connected to address line A2. The rest of the connections are direct connections between the IOPA-LV and Retro Core. The data bus, R/W line, address lines A1 and A0 are all connected to their counterparts. With the IOPA-LV connected this way the following addresses are used when programming Retro Core:

A2 A1 A0 ADDRESS REGISTER

1 0 0 4 Port A

1 0 1 5 Port A Data Direction

1 1 0 6 Port B

1 1 1 7 Port B Data Direction

When first powered the IOPA-LV Data Direction Registers default to inputs. This means that all I/O pins are in input mode. The Data Direction Register for Port A needs to setup for the configuration shown in the schematic. This means making pins PA0, PA1, PA4, and PA5 outputs while leaving the rest as inputs. An input is represented with a 1 and an output with a 0. Writing 11001100 (with the least significant bit, or PA0, on the right) to the Data Direction Register of Port A will correctly configure the port. To calculate the number the following formula will be used: 2

7 + 2

6 + 2

3 + 2

2 = 204. To calculate

the value of a bit that is on (1) take 2 and raise it to the power of the bit position. The most significant bit is: 2

7 = 128. The least significant bit is: 2

0 = 1. To write the value to the Data Direction Register of Port A

simply use the address shown above. The following line will write the data to the proper address:

POKE 5,204 With the data written there was still no noticeable change. This is because on power-up the data output registers of each port default to 0. This means that each pin that is made an output will output a logic low until it is changed. This is why none of the LEDs turned on when the pins were made into outputs. In this example two LEDs will be turned on, LED1 and LED3. LED1 is connected to pin PA0 and LED3 is connected to pin PA4. To turn them use the same formula that was used to calculate the value for the Data Direction Register: 2

4 + 2

0 = 17. Write this data to Port A:

POKE 4,17 The two LEDs are now on. From the schematic it can be noted that when any switch (SW1 – SW4) is open a logic low will be seen on an input pin. When a switch is closed logic high will appear. Close switch SW1 so a logic high is applied to pin PA2. Reading Port A can be done through the following line:

PRINT PEEK(4) A number is returned but what if only the status of SW1 is needed? When a port is read the status of all 8 pins is returned. If the status of a particular pin is required then the other pins need to be removed from the data. To remove the unwanted data all the bits that are not needed need to be logically AND'ed with 0. Only the bit that is needed is logically AND'ed with 1. So for this example switch SW1 is on pin PA2 so logically AND the data with 4 (2

2). Modify the above line with the following:

PRINT PEEK(4) AND 4 Only the status of the bit in question remains now. If the value is 2

X, where X equals the bit position, then

the pin is logic high, if the value is 0 than the bit is logic low. This can be confirmed by opening the switch and reading it again. The following two lines can be easily used in a program:

IF (PEEK(4) AND 4)<>0 THEN PRINT "SWITCH SW1 IS CLOSED"

IF (PEEK(4) AND 4)=0 THEN PRINT "SWITCH SW1 IS OPEN"

Page 65: Retro Core User Manual

Copyright © Multilabs – 2009 All rights reserved Page 65

Suppose one of the LEDs needs to turned on or off and the status of the other LEDs is not known. The goal is to change the status of one of the LEDs without changing the others. This is done through a Read-Modify-Write operation. First the port data is read with the PEEK statement that was just used in the previous example. The bit that needs to be changed to changed and then the entire 8-bit piece of data is written back to the register using the POKE statement. If a bit needs to be turned on then it needs to be logically OR'ed with 1. If it needs to be turned off then it needs to be logically AND'ed with 0. First try turning on an LED. Both LED2 and LED 4 are off. In this example LED4 will be turned on while the states of the other three LEDs will not be changed. When the data is read in through the PEEK statement the status of all the pins is presented. Only bit 5 is of concern since LED4 is connected to pin PA5. To turn this bit on logically OR the data with the value for bit 5 (2

5 = 32). Because this is a logical OR the

other bits in the data will remain unaffected. Only bit 5 will be forced on. The Read-Modify-Write method can be done in a single simple line:

POKE 4,PEEK(4) OR 32 The data from Port A is read, it is logically OR'ed with 32, and then it is written. Now turn it off without changing the others. When the data is read turn this bit off by logically AND'ing the data with all bits=1 except bit 5. Because the data is being logical AND'ed with 1's the other bits in the data will remain unaffected. Only bit 5 will be forced off because it is being AND'ed with a 0. Use the standard formula to calculate the value: 2

7 + 2

6 + 2

4 + 2

3 + 2

2 + 2

1 + 2

0 = 223. Notice 5 is missing in the formula. Again, the

Read-Modify-Write method can be done in a single simple line:

POKE 4,PEEK(4) AND 223 LED4 should now be off. All of these methods can be used singularly or in combination to control the IOPA-LV and give general purpose I/O pin capabilities to Retro Core. There is one more piece of information that you’ll need for the expansion pins. Address and data bus timing.

TIMING DIAGRAMS Everything on Retro Core is clocked from the central processor. This means that there is a certain “window” in which data can be read from and written to the expansion pins. After the address lines are stable this starts the countdown. The data to be written will only appear for a certain time and any data to be read has to appear on the data bus before a certain time expires. For the most part, most logic chips on the market will be able to keep up with these speeds. This data will be presented to you for your reference so any chip that you may be using can be checked to make sure it meets the timing requirements. There are two diagrams. One for writing data (POKE statement) and one for reading data (PEEK function).

Data Write Timing Diagram

Address Valid

Data Valid

RW Line

TAD

TDRWL

TRWL

TDHRWH

TAHRWH

Page 66: Retro Core User Manual

Page 66 Copyright © Multilabs – 2009 All rights reserved

PARAMETER MIN TYP MAX UNIT

TAD 1 µS

TDRWL 100 nS

TRWL 100 nS

TDHRWH 100 nS

TAHRWH 100 nS

Data Write Timing Table

Data Read Timing Diagram

PARAMETER MIN TYP MAX UNIT

TADR 1 µS

TDH 100 nS

TAH 100 nS

Data Read Timing Table

Address Valid

Data Valid

TADR

TDH

TAH

Page 67: Retro Core User Manual

Copyright © Multilabs – 2009 All rights reserved Page 67

CONCLUSION We’ve made it to the end of the manual! Now that you've become more intimately involved with your Retro Core, we want you to know that it does not stop here. All of the information, examples, and data presented will get you on your way to programming and using your Retro Core; its now time for your creativity and imagination to take over. Use what you’ve learned and build upon it. Whether it’s simple programming or controlling complex circuits with Retro Core we know that you’ll find it rewarding on any level. Retro Core has a wide array of applications that invite you to explore the possibilities. Just remember, what ever it is that you do with Retro Core, have fun doing it!

Page 68: Retro Core User Manual

Page 68 Copyright © Multilabs – 2009 All rights reserved

APPENDICES

Page 69: Retro Core User Manual

Copyright © Multilabs – 2009 All rights reserved Page 69

APPENDIX A

ASCII TABLE This appendix shows you what characters will appear if you PRINT CHR$(X). It will also show the values obtained by typing PRINT ASC(“x”) where x is any character you can type. Characters 0 through 31 have no displayable characters and not shown here.

NUMBER CHAR NUMBER CHAR NUMBER CHAR

32 Space 64 @ 96 `

33 ! 65 A 97 a

34 “ 66 B 98 b

35 # 67 C 99 c

36 $ 68 D 100 d

37 % 69 E 101 e

38 & 70 F 102 f

39 ‘ 71 G 103 g

40 ( 72 H 104 h

41 ) 73 I 105 i

42 * 74 J 106 j

43 + 75 K 107 k

44 , 76 L 108 l

45 - 77 M 109 m

46 . 78 N 110 n

47 / 79 O 111 o

48 0 80 P 112 p

49 1 81 Q 113 q

50 2 82 R 114 r

51 3 83 S 115 s

52 4 84 T 116 t

53 5 85 U 117 u

54 6 86 V 118 v

55 7 87 W 119 w

56 8 88 X 120 x

57 9 89 Y 121 y

58 : 90 Z 122 z

59 ; 91 [ 123

60 < 92 \ 124 |

61 = 93 ] 125

62 > 94 ^ 126 ~

63 ? 95 _ 127

Page 70: Retro Core User Manual

Page 70 Copyright © Multilabs – 2009 All rights reserved

APPENDIX B

ERROR MESSAGES This appendix contains a complete list of the error messages generated by Retro Core, with a description of causes. BAD SUBSCRIPT: The program was trying to reference an element of an array whose number is outside of the range specified in the DIM statement. DEVICE NOT FOUND: An attempt was made to LOAD, SAVE, DELETE, or DIR a file from a program memory that is not present. This is most common when using device 1 when a chip is not installed in the device 1 location. DIVIDE BY ZERO: Division by zero is a mathematical oddity and is not allowed. FILE NOT FOUND: An attempt was made to LOAD or DELETE a file that does not exist. FOR STACK OVERFLOW: An attempt was made to nest more than four FOR … NEXT loops at one time. GOSUB STACK OVERFLOW: An attempt was made to nest more than five subroutines at one time. ILLEGAL QUANTITY: A number used as the argument of a function or statement is out of the allowable range. This error can also occur if an attempt is made to use 0 as a line number. NEXT WITHOUT FOR: This is caused by incorrectly nesting loops. It will occur when a NEXT or EXIT statement is reached before a FOR statement is executed. NO FILE NAME: An attempt was made to use the LOAD, SAVE, or DELETE statements without a file name. OUT OF DATA: A READ statement was executed but there is no data left unread in a DATA statement. OUT OF MEMORY: There is no more RAM available for program storage, variables, or stack data. OVERFLOW: The result of a computation is larger than the largest number allowed or smaller than the smallest number allowed. PORT NOT OPEN: An attempt was made to use the SPUT, SGET, or SCLOSE statements without first opening the serial communications port with the SOPEN statement. PORT OPEN: An attempt was made to execute the SOPEN statement while the serial communications port was already opened. REDIMENSIONED ARRAY: An array may only be DIMensioned once. Any subsequent DIMs to the same variable name will cause this error. REDO FROM START: Either 1) character data was typed in during an INPUT statement when numeric data was expected; 2) numeric data was typed in during an INPUT statement when character data was expected; or 3) not the right amount of data was entered during an INPUT statement separated by commas. When the data is correct the program will continue itself. RETURN WITHOUT GOSUB: A RETURN statement was encountered and no GOSUB statement had been executed.

Page 71: Retro Core User Manual

Copyright © Multilabs – 2009 All rights reserved Page 71

SYNTAX ERROR: A statement is unrecognizable by Retro Core. A missing or extra parenthesis, misspelled keywords, etc. TYPE MISMATCH: This error occurs when a number is used in place of a string, or a sting is used in place of a number. UNDEFINED ARRAY: An attempt was made to use an array that was not first DIMensioned. UNDEFINED STATEMENT: An attempt was made to GOTO or GOSUB a line number that doesn’t exist.

Page 72: Retro Core User Manual

Page 72 Copyright © Multilabs – 2009 All rights reserved

APPENDIX C

BASIC LANGUAGE VOCABULARY This manual has given you an introduction to the BASIC language – enough for you to get a feel for computer programming and some of the vocabulary involved. This appendix gives a complete list of the syntax of Retro Core BASIC version 1.0, along with concise descriptions. Please experiment with these commands. Remember, you can’t do any permanent damage to the computer by just typing in programs, and the best way to learn computing is by doing. ABS TYPE: Function – Numeric FORMAT: ABS(<expression>) Action: Returns the absolute value of the number, which is its value without any signs. The absolute value of a negative number is that number multiplied by -1. EXAMPLE:

PRINT ABS(-1.5)

1.5

PRINT ABS(3.65)

3.65 AND TYPE: Logical Operator FORMAT: <expression> AND <expression> Action: AND is used in Boolean operations to test bits. It is also used in operations to check the truth of both operands. In Boolean algebra, the result of an AND operation is 1 only if both numbers being ANDed are 1. The result is 0 if either or both are 0 (false). Examples of 1-Bit AND Operation: 0 1 0 1 AND 0 AND 0 AND 1 AND 1 ------------- ------------- ------------- ------------- 0 0 0 1 Retro Core performs the AND operation on numbers in the range from -8,388,607 to +8,388607. Any fractional values are not used, and numbers beyond the range will cause an OVERFLOW error. ASC TYPE: Function – Numeric FORMAT: ASC(<expression>) Action: ASC will return a number from 1 to 255 which corresponds to the ASCII value of the first character in the string. The table of ASCII values is shown in Appendix A. EXAMPLE:

PRINT ASC(“A”)

65 If there are no characters in the string, an ILLEGAL QUANTITY error results.

Page 73: Retro Core User Manual

Copyright © Multilabs – 2009 All rights reserved Page 73

CHR$ TYPE: Function – String FORMAT: CHR$(<expression>) Action: This function converts an ASCII code to its character equivalent. See Appendix A for a list of characters and their codes. This function is used to access the lower case characters in the Retro Core character set. The number must have a value between 0 and 255, or an ILLEGAL QUANTITY error message results. Although 0 is allowed it is a null character and will not display anything. EXAMPLE:

PRINT CHR$(65)

A CLS TYPE: Statement FORMAT: CLS Action: This statement is used to clear the entire screen. The screen is cleared to the current background color. COLOR TYPE: Statement FORMAT: COLOR <expression> [,<expression>] Action: The COLOR Statement is used to change the foreground and background colors of the screen. The first expression is mandatory and is used to define the foreground color. The color can be any number from 0 to 63. Refer to Appendix F for a palette of colors used by Retro Core. The second expression is optional and is used to define the background color. When the COLOR statement is used only the text and background area following the statement will be changed. In other words, if you use COLOR to change the foreground and background color and then use the PRINT statement to print text only the foreground and background colors of that text will be changed. This can be helpful when printing highlighted text on the screen. To change the entire background color execute the CLS statement after a COLOR statement. This will refresh the entire screen with the new foreground and background color. EXAMPLE:

COLOR 63 (Text will be white)

COLOR 63,0 (White text will be shown on a black background)

COS TYPE: Function – Numeric FORMAT: COS(<expression>) Action: This mathematical function calculates the cosine of a number where the number is an angle in radians. EXAMPLE:

PRINT COS(1)

.5403023

Page 74: Retro Core User Manual

Page 74 Copyright © Multilabs – 2009 All rights reserved

CSRLIN TYPE: Function – Numeric FORMAT: CSRLIN Action: Returns the current row position of the cursor. This value will be from 0 to 29 from top to bottom with 0 representing the top-most row. The value will be returned regardless of whether the cursor is being displayed or not. EXAMPLE:

PRINT CSRLIN

20 DATA TYPE: Statement FORMAT: DATA <constant>[,<constant>]* Action: DATA Statements store information within a program. The program uses the information by means of the READ statement (explained later), which pulls successive constants from the DATA statements. The DATA statements don’t have to be executed by the program, they only have to be present. Therefore, they are usually placed at the end of the program. All DATA statements in a program are treated as a continuous list. Data is READ from left to right, from the lowest numbered line to the highest. If the READ statement encounters data that doesn’t fit the type requested (if it needs a number and finds a string for example) a TYPE MISMATCH error occurs. All the data must be constants. Only numbers and strings enclosed in quote marks (“ “) can be used. Anything else will generate a SYNTAX error. EXAMPLE:

10 DATA 1,10,5,8

20 DATA "MULTILABS","RETRO CORE" DELETE TYPE: Statement FORMAT: DELETE <expression>,<expression> Action: The DELETE Statement deletes a program file from the storage memory. This can be used to free up memory by removing old and unused programs. The first expression is a string indicating the file name. The second expression is a numeric expression indicating the storage device. Retro Core has two storage devices. The first device comes with Retro Core and is permanently attached, this is device 0. The second device can be installed by the user, this is device 1. Once deleted, a file can not be recovered. So care must be taken when using this statement. EXAMPLE:

DELETE "HELLO WORLD",0

NOTE

To convert degrees to radians multiply by (π / 180).

Page 75: Retro Core User Manual

Copyright © Multilabs – 2009 All rights reserved Page 75

DIM TYPE: Statement FORMAT: DIM <variable>(<expression>) [, <variable>(<expression>)]* Action: This statement defines an array of variables. This allows you to use the variable name with a subscript. The subscript points to the element being used. The lowest element number in an array is zero, and the highest is the number given in the DIM statement, which has a maximum of 255. The DIM statement must be executed only and only once for each array. A REDIMENSIONED ARRAY error occurs if this line is re-executed. Therefore, most programs perform all DIM operations at the very beginning. Retro Core only allows a single dimension array. The array may be made up of normal numeric variables or of string variables. If the variable is a string use the $ sign after the variable name to indicate string. If an array is referenced in a program before it is DIMensioned a UNDEFINED ARRAY error occurs. EXAMPLE:

DIM A(100)

DIM B$(20) DIR TYPE: Statement FORMAT: DIR <expression> Action: The DIR Statement can be used to list the program files currently in program storage memory. This can be used to look up the names of your program files. The expression is a numeric expression indicating the storage device. Retro Core has two storage devices. The first device comes with Retro Core and is permanently attached, this is device 0. The second device can be installed by the user, this is device 1. This statement does not change the contents of the RAM program memory when the list is printed. EXAMPLE:

DIR 0 END Type: Statement FORMAT: END Action: This finishes a program’s execution and displays the READY message, returning control to the person operating Retro Core. There may be any number of END statements within a program. While it is not necessary to include any END statements at all, it is recommended that a program does conclude with one, rather than just running out of lines. EXIT Type: Statement FORMAT: EXIT FOR Action: This statement exits a block of FOR … NEXT code. It transfers control to the statement following the NEXT statement. When used within nested FOR … NEXT loops it will transfer control to the

Page 76: Retro Core User Manual

Page 76 Copyright © Multilabs – 2009 All rights reserved

loop that is one nested level above the loop where it occurs. Do not confuse the EXIT statements with the END statement. EXIT does not define the end of a program. EXAMPLE:

10 FOR A=1 TO 2

20 FOR B=1 TO 10

30 IF B=5 THEN EXIT FOR

40 PRINT A,B

50 NEXT

60 NEXT

70 END

1 1

1 2

1 3

1 4

2 1

2 2

2 3

2 4 EXP Type: Function – Numeric FORMAT: EXP(<expression>) Action: This mathematical function calculates the constant e (2.71828183) raised to the power of the number given. A valve of 16 or greater causes an OVERFLOW error to occur. EXAMPLE:

PRINT EXP(2)

7.389056 FOR … TO … [STEP … ] Type: Statement FORMAT: FOR <variable> = <expression> TO <expression> [STEP <expression>] Action: This is a special BASIC statement that lets you easily use a variable as a counter. You must specify certain parameters: the variable name, starting value, and ending value, and as a option how much to add during each cycle. When the FOR statement is executed, several operations take place. The starting value is placed in the variable being used as the counter. When a NEXT statement (discussed later) is reached, the optional increment value is added to the variable. If a STEP was not included, the increment value is automatically set to +1. Each time the variable is added to it is compared to the ending value. If the ending value has not been exceeded the lines in between the FOR and NEXT statements are executed. Eventually, the ending value is exceeded. At that time, the loop is concluded and the program continues with the line following the NEXT statement.

EXAMPLE:

NOTE A loop will always execute at least once.

Page 77: Retro Core User Manual

Copyright © Multilabs – 2009 All rights reserved Page 77

10 FOR L = 1 TO 10

20 PRINT L

30 NEXT The above program prints the numbers 1 through 10 on the screen. FRE TYPE: Function – Numeric FORMAT: FRE Action: This function tells you how much RAM is available for your program and its variables. If a program tries to use more space than is available an OUT OF MEMORY error is printed. EXAMPLE:

PRINT FRE

28743 GOSUB TYPE: Statement FORMAT: GOSUB <expression> Action: This is a specialized form of the GOTO statement (discussed later), with one important difference, GOSUB remembers where it came from. When a RETURN statement (discussed later) is reached in the program the program jumps back to the statement immediately following the original GOSUB statement. The major use of the GOSUB statement is for subroutines. A subroutine is a small section of the program that is used by different sections of the program. By using subroutines rather than repeating the same lines over and over at different places in the program, you can save program space. Each time your program executes a GOSUB, the position in the program line are save is a special area called the “stack”. This limits the amount of data that can be stored. When a RETURN is reached in the program the data is removed from the stack. With Retro Core, the total number of GOSUB statements that can be active at one time is 5. EXAMPLE:

10 PRINT "THIS PROGRAM PRINTS"

20 GOSUB 100

30 PRINT "SLOWLY ON THE SCREEN"

40 GOSUB 100

50 PRINT "USING A SIMPLE LOOP"

60 GOSUB 100

70 PRINT "AS A TIME DELAY"

80 END

100 FOR L=1 TO 10000 : NEXT

110 RETURN The above program prints each line with an approximate 1 seconds delay between each print statement. Some versions of BASIC include an addition GOSUB statement with the syntax: ON … GOSUB … This allows the programmer to make a jump table based on a variable. This can be used in the following way: 10 FOR X=1 TO 3 20 ON X GOSUB 100,200,300 30 NEXT

Page 78: Retro Core User Manual

Page 78 Copyright © Multilabs – 2009 All rights reserved

40 END 100 PRINT “FIRST JUMP” 110 RETURN 200 PRINT “SECOND JUMP” 210 RETURN 300 PRINT “THIRD JUMP” 310 RETURN Retro Core provides a different way of doing the same thing. With Retro Core the line number following the GOSUB does not need to be a constant. It can be an expression that is calculated at run-time. With Retro Core the above program would look like this:

10 FOR X=1 TO 3

20 GOSUB X*100

30 NEXT

40 END

100 PRINT "FIRST JUMP"

110 RETURN

200 PRINT "SECOND JUMP"

210 RETURN

300 PRINT "THIRD JUMP"

310 RETURN

GOTO TYPE: STATEMENT FORMAT: GOTO <expression> Action: This statement allows the BASIC program to execute lines out of numerical order. The word GOTO followed by a number will make the program jump to the line with that number. It is possible to create loops with GOTO that will never end. The simplest example of this is a line that Goes TO itself, like 10 GOTO 10. The loops can be stopped by hitting the <Esc> key on the keyboard. EXAMPLE:

10 GOTO 100

20 GOTO 900 Some versions of BASIC include an addition GOTO statement with the syntax: ON … GOTO … This allows the programmer to make a jump table based on a variable. This can be used in the following way: 10 X=INT((RND*3)+1) 20 ON X GOTO 100,200,300 100 PRINT “THE NUMBER IS 1” 110 END 200 PRINT “THE NUMBER IS 2” 210 END 300 PRINT “THE NUMBER IS 3” 310 END Retro Core provides a different way of doing the same thing. With Retro Core the line number following the GOTO does not need to be a constant. It can be an expression that is calculated at run-time. With Retro Core the above program would look like this:

10 X=INT((RND*3)+1)

20 GOTO X*100

100 PRINT "THE NUMBER IS 1"

110 END

Page 79: Retro Core User Manual

Copyright © Multilabs – 2009 All rights reserved Page 79

200 PRINT "THE NUMBER IS 2"

210 END

300 PRINT "THE NUMBER IS 3"

310 END IF … THEN … TYPE: Statement FORMAT: IF <expression> THEN <statement> [:<statement>]* Action: This is the statement that gives BASIC most of its “intelligence”. With this statement your program has the ability to evaluate conditions and take different actions depending on the outcome. The word IF is followed by an expression, which can include variables, strings, numbers, comparisons, and logical operators. The word THEN appears on the same line and is followed by a BASIC statement or statements. When the expression is false, everything after the word THEN on that line is ignored, and execution continues with the next line number in the program. A true result executes the BASIC statement or statements that follow THEN. EXAMPLE:

10 L = 0

20 L = L + 1

30 IF L = 5 THEN GOTO 50

40 GOTO 20

50 PRINT "L HAS REACHED 5" The above program will loop until L is equal to 5 then the program jumps to the print statement. INKEY$ TYPE: Function – String FORMAT: INKEY$ Action: Returns a single character from the keyboard buffer. The Retro Core keyboard buffer is 10 characters and is a first-in-first-out (FIFO) buffer. The INKEY$ function reads the character at the top of the buffer. If the buffer is empty at the time of the read then a null character (“”) is returned. EXAMPLE:

PRINT INKEY$

C INPUT TYPE: Statement FORMAT: INPUT [;] [“<prompt>”;|,] <variable> [,<variable>]* Action: This statement allows the user to “feed” information into Retro Core. When the statement is executed a cursor is shown. Retro Core waits, cursor blinking, for the user to type in the answer and then pres the <Enter> key on the keyboard. All of the options for the INPUT statement are discussed below. EXAMPLE: If INPUT is only followed by a variable then a question mark (?) will be printed on the screen to indicate user input:

Page 80: Retro Core User Manual

Page 80 Copyright © Multilabs – 2009 All rights reserved

INPUT A

? When the INPUT statement is followed by a semicolon (;) the cursor will stay on the same line after the <Enter> key is pressed on the keyboard.

10 INPUT ; A

20 PRINT A

? If the user typed in the number 5 and hit the <Enter> key on the keyboard the following would appear:

? 5 5 The INPUT statement can have a prompt to provide the user with a question or statement. The prompt must be followed by either a semicolon (;) or a comma (‘). The semicolon will append a question mark (?) to the end of the prompt and a comma will not. If a comma is used there will be no space between the prompt and the cursor:

INPUT "WHAT IS THE NUMBER"; A

WHAT IS THE NUMBER?

INPUT "WHAT IS THE NUMBER", A

WHAT IS THE NUMBER The INPUT statement can be followed by multiple variables. Each variable must be followed by a comma and the variable types can be mixed; numeric and string. If the user types in string data when a number is expected then a TYPE MISMATCH ERROR will occur. If the INPUT statement requires 3 pieces of data and the user only supplies 1 or 2 then a REDO FROM START error will be shown. The user must use a comma (,) between each piece of data:

INPUT A, A$

? The user would type in a number followed by a comma (,) and then a string. INT TYPE: Function – Numeric FORMAT: INT(<expression>) Action: Returns the integer value of the expression. If the expression is positive, the fractional part is left off. If the expression is negative, any fraction causes the next lower integer to be returned. EXAMPLE:

PRINT INT(65.543)

65

PRINT INT(-12.65)

-13

PRINT INT(-12)

-12 LEFT$ TYPE: Function – String FORMAT: LEFT$(<expression>,<expression>)

Page 81: Retro Core User Manual

Copyright © Multilabs – 2009 All rights reserved Page 81

Action: Returns a string comprised of the leftmost number of characters specified in the second expression of the string specified in the first expression. The second expression must be in the range of 0 to 79. If a value of zero is used then a null string (of zero length) is returned. EXAMPLE:

10 A$="RETRO CORE COMPUTER"

20 PRINT LEFT$(A$,10)

RETRO CORE LOG TYPE: Function – Numeric FORMAT: LOG(<expression>) Action: Returns the natural logarithm (log to the base of e) of the argument. If the value of the argument is zero or negative an ILLEGAL QUANTITY error will occur. EXAMPLE:

PRINT LOG(45/7)

1.860752

JOY TYPE: Function – Numeric FORMAT: JOY(<expression>) Action: Returns the value of the joystick connected to Retro Core’s joystick pins. The single numeric expression represents the joystick port to read. Retro Core only has pins for one joystick and it is designated 0. The following values are used: 1 = Up 2 = Right 4 = Down 8 = Left 16 = Fire Button EXAMPLE:

PRINT JOY(0)

0 LEN TYPE: Function – Numeric FORMAT: LEN(<expression>) Action: Returns the number of characters in the string expression. Non-printed characters and blanks are counted. EXAMPLE:

PRINT LEN("HELLO WORLD")

NOTE To calculate the LOG of an argument to the base of 10 use the following equation where x is the argument: LOG(x) / LOG(10)

Page 82: Retro Core User Manual

Page 82 Copyright © Multilabs – 2009 All rights reserved

11 LIST TYPE: Statement FORMAT: LIST [[<expression>] – [<expression>]] Action: The LIST statement allows you to look at lines of the BASIC program currently in the RAM memory of Retro Core. The LIST statement displays all or part of the program. LIST can appear in a program, but BASIC always returns to the system READY message after a LIST is executed. If no line numbers are given the entire program is listed. The listing can be stopped by pressing the <Esc> key on the keyboard. If a line number is specified than only that line is listed. If that line number is followed by a hyphen (-) than that line followed by the remaining lines in the program are listed. If a line number follows the hyphen (-) than the entire range, including those line numbers, are displayed. If LIST is followed by a hyphen (-) and a line number than all the program lines starting from the first, up to and including the line number, are listed. EXAMPLE:

LIST

LIST 10

LIST 10 –

LIST 10 – 100

LIST – 100 LOAD TYPE: Statement FORMAT: LOAD <expression>,<expression> Action: The LOAD Statement reads the contents of a program file from the storage memory into RAM memory. This way you can use the information loaded or change the information in some way. The first expression is a string indicating the file name. The second expression is a numeric expression indicating the storage device. Retro Core has two storage devices. The first device comes with Retro Core and is permanently attached, this is device 0. The second device can be installed by the user, this is device 1. When a program is loaded the current contents of the RAM will be erased; just as if a NEW statement (discussed later) had been executed. So care must be taken that any program in RAM memory is saved before a new one is loaded. EXAMPLE:

LOAD "HELLO WORLD",0 LOCATE TYPE: Statement FORMAT: LOCATE <expression>,<expression> Action: The LOCATE Statement is used to move the cursor to a specified location on the screen. This statement can be executed whether the cursor is visible or not. The first expression is the X location from left to right and can be a number from 0 to 39; with 0 being the left-most side. The second expression is the Y location from top to bottom and can be a number from 0 to 29; with 0 being the top-most position. The statement can be used in conjunction with the PRINT statement to place text anywhere on the screen. EXAMPLE:

LOCATE 39,29 (put the cursor in the lower right-hand corner)

Page 83: Retro Core User Manual

Copyright © Multilabs – 2009 All rights reserved Page 83

MID$ TYPE: Function – String FORMAT: MID$(<expression>,<expression> [,<expression>]) Action: The MID$ function returns a sub-string which is taken from within a larger string expression. The first expression is this string expression. The starting position of the sub-string is defined by the second numeric expression and the length of the sub-string by the last, optional, numeric expression. If the starting position is greater than the length of the string then a null string (“”) is returned. If the length if left out then Retro Core will assume that a length of the rest of the string is to be used. If the source string has fewer characters than the length expression, from the starting position to the end of the string, then the whole rest of the string is used. EXAMPLE:

PRINT MID$("HI HELLO",4)

HELLO

PRINT MID$("OHIO",2,2)

HI NEW TYPE: Statement FORMAT: NEW Action: The NEW statement is used to delete the program currently in memory and clear all variables. Before typing in a new program, NEW should be used in direct mode to clear memory.

NEXT TYPE: Statement FORMAT: NEXT Action: The NEXT statement is used with the FOR statement to establish the end of a FOR … NEXT loop. The NEXT need not be physically the last statement in the loop, but it is always the last statement executed in a loop. The NEXT does not use a variable name to identify the loop but instead will act on the last FOR statement executed. If a variable is placed after NEXT a SYNTAX ERROR message will be shown. When the NEXT is reached the counter value is incremented by 1 or by the value indicated in the optional STEP statement. It is then tested against an end-value to see if it’s time to stop the loop. A loop will be stopped when a NEXT is found which has its counter value greater than the end-value. Having a loop within is loop is called nested loops. The maximum amount of nested loops Retro Core can handle is 4. EXAMPLE:

10 FOR A = 1 TO 10

20 FOR B = 1 TO 20

30 PRINT A,B

40 NEXT

50 NEXT

NOTE Not clearing out an old program before typing a new one can result in a confusing mix of the two programs.

Page 84: Retro Core User Manual

Page 84 Copyright © Multilabs – 2009 All rights reserved

The above program will execute the inner (B) loop from 1 to 20. When it is done the outer loop (A) will increment and then the inner loop is done all over again. The program will end when A is greater than 10 and B is greater than 20. NOT TYPE: Logical Operator FORMAT: NOT <expression> Action: The NOT logical operator “compliments” the value of each bit in its single expression, producing an integer “twos-compliment” result. When working with a floating-point number, the expression is converted to an integer and any fractions are lost. The NOT operator can also be used in a comparison to reverse the true/false value which was the result of a relationship test and therefore it will reverse the meaning of the comparison. EXAMPLE:

PRINT NOT 3

-4

IF NOT(3 = 4) THEN PRINT "3 IS EQUAL TO 4"

3 IS EQUAL TO 4

OR TYPE: Logical Operator FORMAT: <expression> OR <expression> Action: Just as the relational operators can be used to make decisions regarding program flow, logical operators can connect two or more relations and return a true or false value which can then be used in a decision. When used in calculations the logical OR gives you a bit result of 1 if the corresponding bit of either or both expressions is 1. This will produce an integer as a result depending on the values of the expressions. When used in comparisons the logical OR operator is also used to link two expressions into a single compound expression. If either of the expressions are true, the combined expression value is true. Examples of 1-Bit OR Operation: 0 1 0 1 OR 0 OR 0 OR 1 OR 1 ------------- ------------- ------------- ------------- 0 1 1 1 Retro Core performs the OR operation on numbers in the range from -8,388,607 to +8,388,607. Any fractional values are not used, and numbers beyond the range will cause an OVERFLOW error. PEEK TYPE: Statement FORMAT: PEEK(<expression>) Action: Returns an integer in the range of 0 to 255 which is read from a location on the address bus. The expression is an address bus location which must be in the range of 0 to 65535. If it isn’t then the

NOTE To find the value of NOT use the expression X=(-(X+1)). The twos compliment of any integer is the bit compliment plus one.

Page 85: Retro Core User Manual

Copyright © Multilabs – 2009 All rights reserved Page 85

error message ILLEGAL QUANTITY is shown. The PEEK statement can be used to read a single byte of data from RAM or to read data from an external device connected to the expansion pins of Retro Core. EXAMPLE:

PRINT PEEK (15342)

175 PI TYPE: Function – Numeric FORMAT: PI

Action: This function returns the value of PI (π).

EXAMPLE:

PRINT PI

3.141593 POINT TYPE: Function – Numeric FORMAT: POINT(<expression>,<expression>) Action: Returns the color of a specified pixel. The first expression represents the X coordinate. This can be a value from 0 to 319 from left to right with 0 representing the left-most pixel. The second expression represents the Y coordinate. This can be a value from 0 to 239 from top to bottom with 0 representing the top-most pixel. EXAMPLE:

PRINT POINT(0,0)

34 POKE TYPE: Statement FORMAT: POKE <expression>,<expression> Action: The POKE statement is used to write a one-byte value into a given address location. The address, which is the first expression, must equal a value in the range of 0 to 65535. The value to be written, which is the second expression, must be a value of 0 to 255. If either value is out of its respective range the error message ILLEGAL QUANTITY will be shown. The POKE statement can be used to write a single byte of data to RAM or to write data to an external device connected to the expansion pins of Retro Core. It can be used to change any character or all the characters. A complete memory map of useful locations is given later in this manual. EXAMPLE:

POKE 14211,24

POS

NOTE It can be dangerous to change any data byte in RAM that you don’t have any knowledge about. Changing a value in RAM might affect a stored program or variable. Although this will not damage Retro it can cause the program to behave erratically.

Page 86: Retro Core User Manual

Page 86 Copyright © Multilabs – 2009 All rights reserved

TYPE: Function – Numeric FORMAT: POS Action: The POS function returns the current column position of the cursor. It is in the range of 0 to 39 with 0 representing the left-most position. The value will be returned regardless of whether the cursor is being displayed or not. EXAMPLE:

PRINT POS

12 PRINT TYPE: Statement FORMAT: PRINT [<expression>] [,|; <expression>]* Action: The PRINT statement is used to write data to the screen. The expression(s) in the output list are expressions of any type. If no output list is present a blank line is printed. The position of each printed item is determined by the punctuation used to separate items in the output list. The punctuation characters that you can use are blanks, commas (,), or semicolons (;). The screen is divided into zones of 10 spaces each. In the list of expressions a comma causes the next value to be printed at the beginning of the next zone. A semicolon causes the next value to be printed immediately following the previous value. However, there is an exception to this rule: positive numbers have a space preceding them. When you use blanks between expressions it has the same effect as a semicolon. If a comma or semicolon is at the end of the output list the next PRINT statement begins printing on the same line, and spaced accordingly. If no punctuation finishes the list a carriage-return and a line-feed are printed at the end of the data. The next PRINT statement will begin on the next line. PRINT is a statement in BASIC that has a lot of variety. EXAMPLE:

10 X = 5

20 PRINT -5*X, X-5, X+5, X/5

-25 0 10 1

PRINT "9 SQUARED IS"; 9*9

9 SQUARED IS 81

10 PRINT "HELLO ";

20 PRINT "WORLD"

HELLO WORLD PSET TYPE: Statement FORMAT: PSET(<expression>,<expression>)[,<expression>] Action: The PSET Statement draws a single pixel anywhere on the screen. This can be used to draw pictures, figures, or characters on the screen. The first and second expressions are the X and Y coordinates of the pixel to draw and they are within parenthesis. The X coordinate can be any number from 0 to 319 from left to right; with 0 being the left-most pixel. The Y coordinate can be any number from 0 to 239 from top to bottom; with 0 being the top-most pixel. The third expression is optional and is the

Page 87: Retro Core User Manual

Copyright © Multilabs – 2009 All rights reserved Page 87

color of the pixel. If omitted the current foreground color will be used. This optional color can be used to draw a pixel in another color other than the current foreground color. This value can be from 0 to 63. EXAMPLE:

PSET(0,0),3 (prints a pixel in the upper left-hand corner in bright red)

RANDOMIZE TYPE: Statement FORMAT: RANDOMIZE <expression> Action: The RANDOMIZE Statement is used to re-seed the random number generator. The random number generator is seeded on system power-up but can also be changed using the RANDOMIZE statement. The seed value can be any number from 1 to 65535. EXAMPLE:

RANDOMIZE 1020 READ TYPE: Statement FORMAT: READ <variable> [,<variable>]* Action: The READ statement is used to fill variable names from constants in DATA statements. The data actually read must agree with the variable types specified or a TYPE MISMATCH error with occur. Variables in the DATA input list must be separated by commas. A single READ statement can access one or more DATA statements, which will be accessed in order (see DATA), or several read statements can access the same DATA statement. If more READ statements are executed than the number of elements in DATA statement(s) in the program, an OUT OF DATA error message will be generated. If the number of variables specified is fewer than the number of elements in the DATA statement(s), subsequent READ statements will continue reading at the next data element. EXAMPLE:

110 READ A,B,C$

120 DATA 1,2,"HELLO"

130 PRINT A,B,C$

1 2 HELLO REM TYPE: Statement FORMAT: REM [<expression>] Action: The REM statement makes your programs more easily understood when listed. It's a reminder to yourself to tell you what you had in mind when you were writing each section of the program. For instance, you might want to remember what a variable is used for, or some other useful information. The REMark can be any text, word, or character, except the colon (:), or BASIC keywords. The REM statement and anything following it are ignored by BASIC until a new line or a colon is reached, but REMarks are printed exactly as entered when the program is listed. A REM statement can be referred to by a GOTO or GOSUB statement, and the execution of the program will continue with the next higher program line having executable statements. EXAMPLE:

Page 88: Retro Core User Manual

Page 88 Copyright © Multilabs – 2009 All rights reserved

10 REM THIS PROGRAM PRINTS HELLO WORLD ON THE SCREEN

20 PRINT "HELLO WORLD"

HELLO WORLD RESTORE TYPE: Statement FORMAT: RESTORE Action: Retro Core maintains an internal pointer to the next DATA constant to be READ. This pointer can be reset to the first DATA constant in a program using the RESTORE statement. The RESTORE statement can be used anywhere in the program to begin re-READing DATA. EXAMPLE:

10 FOR X=1 TO 10:READ A(X):NEXT

20 RESTORE

30 FOR Y=1 TO 10:READ B(Y):NEXT

40 DATA 1,2,3,4,5,6,7,8,9,10 RETURN TYPE: Statement FORMAT: RETURN Action: The RETURN statement is used to exit from a subroutine called for by a GOSUB statement. RETURN restarts the rest of your program at the next executable statement following the GOSUB. If you are nesting subroutines, each GOSUB must be paired with at least one RETURN statement. A subroutine can contain any number of RETURN statements, but the first one encountered will exit the subroutine. EXAMPLE:

10 PRINT "THIS IS THE PROGRAM"

20 GOSUB 1000

30 END

1000 PRINT "THIS IS THE GOSUB"

1010 RETURN RIGHT$ TYPE: Function – String FORMAT: RIGHT$(<expression>,<expression>) Action: Returns a string comprised of the rightmost number of characters specified in the second expression of the string specified in the first expression. The second expression must be in the range of 0 to 79. If a value of zero is used then a null string (of zero length) is returned. If the value is greater than the length of the string then the entire string is returned. EXAMPLE:

10 A$="RETRO CORE COMPUTER"

20 PRINT RIGHT$(A$,8)

COMPUTER RND

Page 89: Retro Core User Manual

Copyright © Multilabs – 2009 All rights reserved Page 89

TYPE: Function – Numeric FORMAT: RND Action: RND creates a floating-point random number greater than or equal to 0 and less than 1. Retro Core generates a random number by performing calculations on a starting number, which in computer jargon is called a seed. That number is then XOR’ed with an internal timer. The RND function is seeded on system power-up but can also be changed using the RANDOMIZE statement. EXAMPLE:

PRINT RND

0.02354

10 A=RND

20 PRINT A*5

2.6543 RUN TYPE: Statement FORMAT: RUN Action: The system statement RUN is used to start the program currently in memory. The RUN command causes all variables and arrays to be cleared before starting the program. RUN starts at the first line of the program. A running program stops and BASIC returns to direct mode when an END is reached, when the last line of the program is finished, when a BASIC error occurs during execution, or the <Esc> key on the keyboard is pressed. SAVE TYPE: Statement FORMAT: SAVE <expression>,<expression> Action: The SAVE Statement writes the contents of a program file from RAM memory to the storage memory. This way you can save the program you are working on for later use. The first expression is a string indicating the file name. The second expression is a numeric expression indicating the storage device. Retro Core has two storage devices. The first device comes with Retro Core and is permanently attached, this is device 0. The second device can be installed by the user, this is device 1. When a program is saved the current contents of the RAM will remain untouched. EXAMPLE:

SAVE "HELLO WORLD",0 SCLOSE TYPE: Statement FORMAT: SCLOSE Action: The SCLOSE Statement is used to close the serial communications port. This must be done before a new baud rate is selected using the SOPEN statement. Any data waiting in the two-stage buffer will be lost when this statement is executed. SGET TYPE: Statement FORMAT: SGET <variable>

Page 90: Retro Core User Manual

Page 90 Copyright © Multilabs – 2009 All rights reserved

Action: The SGET Statement gets a single byte of data from the serial communications buffer. Retro Core has a two-stage buffer that can hold two pieces of data while receiving another. Executing this statement removed a single byte of data from the buffer. The variable can either be numeric or string. If numeric the value is stored as a ASCII number; otherwise the data is stored as a string character. EXAMPLE:

SGET A$ SIN TYPE: Function – Numeric FORMAT: SIN(<expression>) Action: This function gives you the sine of the argument in radians. EXAMPLE:

PRINT SIN(1.5)

.9974951

SINBUFFER TYPE: Function – Numeric FORMAT: SINBUFFER Action: SINBUFFER returns the status of the inbuffer of the serial communications port. The value will be 0 if the buffer is empty and -1 if there is data in the buffer. This can be used to first check the buffer status before doing a read of the buffer. EXAMPLE:

10 IF SINBUFFER = -1 THEN SGET A$:PRINT A$

20 END SLIST TYPE: Statement FORMAT: SLIST [[<expression>] – [<expression>]] Action: The SLIST statement works exactly the same as the LIST statement discussed earlier except that the program list is sent to the serial port instead of the screen. This can be used to send the program listing to a device external to Retro Core. In order to use this statement the serial port must be opened using the SOPEN statement discussed next. Trying to use SLIST without opening the serial port will result in a PORT NOT OPEN error message. The data bytes are sent to the serial port continuously without any delay between bytes. When SLIST is executed the first character sent is an ASCII “Start of Text” which has a value of 2. The preceding characters will be the ASCII text characters that make up the program listing. When the list is complete an ASCII “End of Text” character will be sent which has a value of 3. This is used to indicate that the listing is complete and no more text is coming. If the <Esc> key is pressed during the listing to stop the listing an “End of Text” character will also be sent.

NOTE

To convert degrees to radians multiply by (π / 180).

Page 91: Retro Core User Manual

Copyright © Multilabs – 2009 All rights reserved Page 91

Most characters sent for the listing will be letters, numbers, and symbols. However, an ASCII “Carriage Return”, which has a value of 13, will be seen at the end of every line. It is assumed that every carriage return should also have a line feed. EXAMPLE:

OPEN 9600:SLIST SOPEN TYPE: Statement FORMAT: SOPEN <expression> Action: The SOPEN Statement is used to open the serial communications port with a specified baud rate. The serial port is 8 data bits, 1 stop bit, no parity, and no handshaking. Any baud rate can be specified in the expression. However, to keep away from timing errors only common baud rates should be used. EXAMPLE:

SOPEN 9600 (Open the serial port with a 9600 baud rate)

SOUND TYPE: Statement FORMAT: SOUND <expression>,<expression> Action: The SOUND Statement plays a tone through Retro Core’s sound pin. The first expression represents the tone. A list of values and their corresponding frequencies can be found in Chapter 5. The second expression is the amount of time to play the tone and is in approximately 50mS increments. The SOUND statement plays in the background. In other words, when the SOUND statement is executed the next statement in the program will begin execution even if the tone is still playing. This way the program can continue execution while the tone is playing. If another SOUND statement is reached while a tone is being played program execution will stop until the next SOUND statement can be executed. There is no buffer for the SOUND statement. EXAMPLE:

SOUND 100,10 SPUT TYPE: Statement FORMAT: SPUT <variable> Action: The SPUT Statement writes a single byte of data to the serial communications port. The variable can either be numeric or string. EXAMPLE:

SPUT A$ SQR TYPE: Function – Numeric FORMAT: SQR(<expression>)

Page 92: Retro Core User Manual

Page 92 Copyright © Multilabs – 2009 All rights reserved

Action: This function gives you the value of the SQuare Root of the argument. If the argument is negative then an ILLEGAL QUANTITY error will occur. EXAMPLE:

PRINT SQR(2)

1.414214 STEP TYPE: Statement FORMAT: STEP <expression> Action: The optional STEP keyword follows the end-value expression in a FOR statement. It defines an increment value for the loop counter variable. Any value can be used as the STEP increment. Of course, a STEP value of zero will loop forever. If the STEP keyword is left out, the increment value will be +1. When the NEXT statement in a FOR loop is reached, the STEP increment happens. Then the counter is tested against the end-value to see if the loop is finished (see FOR statement for more information).

EXAMPLE:

10 FOR X=2 TO 20 STEP 2 (Loop repeats 10 times)

10 FOR Z=0 TO -20 STEP -2 (Loop repeats 11 times)

STR$ TYPE: Function – String FORMAT: STR$(<expression>) Action: STR$ gives you the string representation of the numeric value of the expression. When the STR$ value is converted, if the value is positive, it is preceded by a space. EXAMPLE:

PRINT STR$(20)

20

PRINT STR$(-20)

-20 TAN TYPE: Function – Numeric FORMAT: TAN(<expression>) Action: This function returns the tangent of the argument in radians. If the TAN function overflows the error message DIVISION BY ZERO is displayed. EXAMPLE:

PRINT TAN(.785398163)

1

NOTE The step value can not be changed once it is in the loop.

Page 93: Retro Core User Manual

Copyright © Multilabs – 2009 All rights reserved Page 93

TIMER TYPE: Function – Numeric FORMAT: TIMER Action: The TIMER function reads the internal interval timer. The value is set at zero when Retro Core is first powered-up. The timer will continue to run and increment at 1/60 of a second intervals. It will roll over to zero when it reaches 8388607 which is the highest number Retro Core can use. This will occur about every 38 hours. EXAMPLE:

10 A=TIMER

20 IF TIMER<(A+60) THEN GOTO 20

30 PRINT "IT HAS BEEN 1 SECOND." VAL TYPE: Function – Numeric FORMAT: VAL(<expression>) Action: Returns a numeric value representing the data in the string expression. If the first non-blank character (space) of the string is not a plus sign (+), minus sign (-), decimal point (.), or a digit the value returned is zero. String conversion is finished when the end of the string or any non-digit character is found, except the decimal point (.). EXAMPLE:

PRINT 20 + VAL("5")

25 XOR TYPE: Logical Operator FORMAT: <expression> XOR <expression> Action: Just as the relational operators can be used to make decisions regarding program flow, logical operators can connect two or more relations and return a true or false value which can then be used in a decision. When used in calculations the logical XOR gives you a bit result of 1 if the corresponding bit of both expressions are opposite. This will produce an integer as a result depending on the values of the expressions. When used in comparisons the logical XOR operator is also used to link two expressions into a single compound expression. If either of the expressions are true, the combined expression value is true. Examples of 1-Bit XOR Operation: 0 1 0 1 XOR 0 XOR 0 XOR 1 XOR 1 ------------- ------------- ------------- ------------- 0 1 1 0 Retro Core performs the XOR operation on numbers in the range from -8,388,607 to +8,388,607. Any fractional values are not used, and numbers beyond the range will cause an OVERFLOW error.

NOTE

To convert degrees to radians multiply by (π / 180).

Page 94: Retro Core User Manual

Page 94 Copyright © Multilabs – 2009 All rights reserved

APPENDIX D

SOUND TONES This appendix shows you the tone number used for the SOUND statement and its associated frequency in hertz.

TONE FREQ (HZ) TONE FREQ (HZ) TONE FREQ(HZ)

1 4882.81 2 2441.41 3 1627.60

4 1220.70 5 976.56 6 813.80

7 697.54 8 610.35 9 542.53

10 488.28 11 443.89 12 406.90

13 375.60 14 348.77 15 325.52

16 305.18 17 287.22 18 271.27

19 256.99 20 244.14 21 232.51

22 221.95 23 212.30 24 203.45

25 195.31 26 187.80 27 180.84

28 174.39 29 168.37 30 162.76

31 157.51 32 152.59 33 147.96

34 143.61 35 139.51 36 135.63

37 131.97 38 128.50 39 125.20

40 122.07 41 119.09 42 116.26

43 113.55 44 110.97 45 108.51

46 106.15 47 103.89 48 101.73

49 99.65 50 97.66 51 95.74

52 93.90 53 92.13 54 90.42

55 88.78 56 87.19 57 85.66

58 84.19 59 82.76 60 81.38

61 80.05 62 78.76 63 77.50

64 76.29 65 75.12 66 73.98

67 72.88 68 71.81 69 70.77

70 69.75 71 68.77 72 67.82

73 66.89 74 65.98 75 65.10

76 64.25 77 63.41 78 62.60

79 61.81 80 61.04 81 60.28

82 59.55 83 58.83 84 58.13

85 57.44 86 56.78 87 56.12

88 55.49 89 54.86 90 54.25

91 53.66 92 53.07 93 52.50

94 51.94 95 51.40 96 50.86

97 50.34 98 49.82 99 49.32

100 48.83 101 48.34 102 47.87

103 47.41 104 46.95 105 46.50

106 46.06 107 45.63 108 45.21

109 44.80 110 44.39 111 43.99

112 43.60 113 43.21 114 42.83

115 42.46 116 42.09 117 41.73

118 41.38 119 41.03 120 40.69

121 40.35 122 40.02 123 39.70

124 39.38 125 39.06 126 38.75

127 38.45 128 38.15 129 37.85

130 37.56 131 37.27 132 36.99

Page 95: Retro Core User Manual

Copyright © Multilabs – 2009 All rights reserved Page 95

TONE FREQ (HZ) TONE FREQ (HZ) TONE FREQ(HZ)

133 36.71 134 36.44 135 36.17

136 35.90 137 35.64 138 35.38

139 35.13 140 34.88 141 34.63

142 34.39 143 34.1 144 33.91

145 33.67 146 33.44 147 33.22

148 32.99 149 32.77 150 32.55

151 32.34 152 32.12 153 31.91

154 31.71 155 31.50 156 31.30

157 31.10 158 30.90 159 30.71

160 30.52 161 30.33 162 30.14

163 29.96 164 29.77 165 29.59

166 29.41 167 29.24 168 29.06

169 28.89 170 28.72 171 28.55

172 28.39 173 28.22 174 28.06

175 27.90 176 27.74 177 27.59

178 27.43 179 27.28 180 27.13

181 26.98 182 26.83 183 26.68

184 26.54 185 26.39 186 26.25

187 26.11 188 25.97 189 25.83

190 25.70 191 25.56 192 25.43

193 25.30 194 25.17 195 25.04

196 24.91 197 24.79 198 24.66

199 24.54 200 24.41 201 24.29

202 24.17 203 24.05 204 23.94

205 23.82 206 23.70 207 23.59

208 23.48 209 23.36 210 23.25

211 23.14 212 23.03 213 22.92

214 22.82 215 22.71 216 22.61

217 22.50 218 22.40 219 22.30

220 22.19 221 22.09 222 21.99

223 21.90 224 21.80 225 21.70

226 21.61 227 21.51 228 21.42

229 21.32 230 21.23 231 21.14

232 21.05 233 20.96 234 20.87

235 20.78 236 20.69 237 20.60

238 20.52 239 20.43 240 20.35

241 20.26 242 20.18 243 20.09

244 20.01 245 19.93 246 19.85

247 19.77 248 19.69 249 19.61

250 19.53 251 19.45 252 19.38

253 19.30 254 19.22 255 19.15

Page 96: Retro Core User Manual

Page 96 Copyright © Multilabs – 2009 All rights reserved

APPENDIX E

MECHANICAL DIMENSIONS

2.5

4 (

0.1

)

0.6

6 (

0.0

26)

Sq

ua

re

77.22 (3.04)

57

.15

(2

.25)

73.66 (2.9)

All dimensions are MM (Inch)

Page 97: Retro Core User Manual

Copyright © Multilabs – 2009 All rights reserved Page 97

APPENDIX F

COLORS This is a color swatch of all the available colors on your Retro Core. Colors are approximate. Actual colors will depend on monitor’s color temp setting, brightness, contrast, and other color adjustment controls. Color variance is also subject to component tolerances of the digital to analog conversion circuitry.

0

1 2 3 4 5 6 7

8 9 10 11 12 13 14 15

16 17 18 19 20 21 22 23

24 25 26 27 28 29 30 31

32 33 34 35 36 37 38 39

40 41 42 43 44 45 46 47

48 49 50 51 52 53 54 55

56 57 58 59 60 61 62 63

Page 98: Retro Core User Manual

Page 98 Copyright © Multilabs – 2009 All rights reserved

LIMITED WARRANTY Multilabs warrants to the original consumer purchaser of this product that, for a period of 90 days from the date of purchase, this product will be free from defects in material and workmanship and will perform in substantial conformity to the description of the product in this Owner's Manual. This warranty shall not apply to defects or errors caused by misuse or neglect. If the product is found to be defective in material or workmanship or if the product does not perform as warranted above during the warranty period, Multilabs will repair it, replace it, or refund the purchase price. The repair, replacement, or refund that is provided for above shall be the full extent of Multilabs's liability with respect to this product. For repair or replacement during the warranty period, contact Multilabs customer service by email at [email protected] to receive a return authorization number and return instructions.

LIMITATIONS THE ABOVE WARRANTY IS IN LIEU OF AND MULTILABS DISCLAIMS ALL OTHER WARRANTIES, WHETHER ORAL OR WRITTEN, EXPRESS OR IMPLIED, INCLUDING ANY WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. ANY IMPLIED WARRANTY, INCLUDING ANY WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, WHICH MAY NOT BE DISCLAIMED OR SUPPLANTED AS PROVIDED ABOVE SHALL BE LIMITED TO THE 90 DAYS OF THE EXPRESS WARRANTY ABOVE. NO OTHER REPRESENTATION OR CLAIM OF ANY NATURE BY ANY PERSON SHALL BE BINDING UPON MULTILABS OR MODIFY THE TERMS OF THE ABOVE WARRANTY AND DISCLAIMER. IN NO EVENT SHALL MULTILABS BE LIABLE FOR SPECIAL, INCIDENTAL, CONSEQUENTIAL OR OTHER DAMAGES RESULTING FROM THE POSSESSION OR USE OF THIS PRODUCT, INCLUDING WITHOUT LIMITATION DAMAGE TO PROPERTY AND, TO THE EXTENT PERMITTED BY LAW, PERSONAL INJURY, EVEN IF MULTILABS KNEW OR SHOULD HAVE KNOWN OF THE POSSIBILITY OF SUCH DAMAGES. Some states do not allow limitations on how long an implied warranty lasts and/or the exclusion or limitation of damages, in which case the above limitations and/or exclusions may not apply to you. You may also have other legal rights, which may vary from state to state.