Updated: May 19. 2018                            CHIP-12 BASIC Compiler

(*****Still being developed therefore contents will be updated as new commands, statements and functions are added*****)

 

Table of Contents

IDE Overview   4

Guidelines and special instructions for using the compiler  7

General Format  7

Identifiers  7

Line Labels  8

Numeric Representations  9

Dimensioning Numeric Variables  9

Dimensioning String Variables  9

Initializing Numeric and String Variables  9

Using Arrays in CHIP-12  10

Relational Operators  11

Boolean Logic Operators  11

Compiling Errors and Warnings  11

Using Data In Your Program    12

Variables Used by BASIC Compiler  15

Known Issue With Keyboard CAPS LOCK in CHIP-12  15

Using CHIP-12 Background and Foreground Color Registers  15

Commands, Statements and Functions Overview   16

ASC   16

BackGnd   16

Call 16

CHIP12BEGIN   20

CHIP12END   20

CHR   20

CLS   20

Color  22

CopyBlock  23

DefMemPtr  24

DefNewChar  25

Delay  26

DeleteSprite  26

Dim    27

DisplaySprite  29

Do Loop   30

Do Inkey  30

DrawPattern   32

END   36

ERASETEXTFLAGOFF   36

ERASETEXTFLAGON   36

For Next  37

GetFile  38

GInput  39

Gosub   39

Goto   40

GPrint  41

HEX   41

If Then   42

If Inkey  44

If SpriteX   45

If SpriteY   45

If PlayEnd   46

If Timer  47

Inkey  48

Input  49

INSTR   52

LEFT   54

LEN   55

LoadLargeFont  56

LoadSmallFont  56

LoadPlaySound   62

LoadSoundFile  62

LoadSprite  62

MID   63

MoveSpriteDown   64

MoveSpriteLeft  65

MoveSpriteRight  66

MoveSpriteUp   67

Palette  69

Peek  70

PlaySound   73

Poke  74

Print  75

Random    75

RIGHT   78

SCREEN   79

SetSpriteXY   86

SetSpriteX   87

SetSpriteY   87

SHIFT (Right or Left)  88

ShowSprite  89

STOP   90

STRDUP   91

Sub End Sub   91

Val 92

WriteFile  92

How to setup DOSBox  94

How to setup and use CHIP-12  97

How to setup and use the CHIP-12 BASIC Compiler  100

Understanding Sprites  107

Tutorial - How to create and use Sprites  108

Tutorial - How to create and use Sprites (Part 2) 111

ASCII Character Codes - Chart 1 (codes 0–127) 118

ASCII Character Codes - Chart 2 (codes 128–255) 119

 

IDE Overview

 

This compiler converts easy to use BASIC commands, statements and functions into CHIP-12 instruction codes.

The Interactive Development Environment (IDE) is pretty much simple to use.

You can use any text editor, such as Microsoft® Notepad or Word, to enter the BASIC program.

 

 

 

File has two options:
Open -
The source file is a text file of the BASIC program.
Exit - Program.

 

Compile - The compiler will create the following files:

 '.ASM' , '.C12' , '.CHP' , '.LST'

Once a program has successfully compiled, the compiler will remember the last source filename so that if you are working on the same program, you don't need to Open it each time you launch the application.

 

Open and Assemble a CHIP-12 File - The compiler will create the following 2 files:

 '.ASM' , '.C12'

This allows you to assemble a program written with CHIP-12 instructions. Since you are not using the 'A'   - ASSEMBLE A CHIP12 ASSEMBLY TEXT FILE command, you are no longer limited to 256† 896 address labels and labels can be longer than 13† 29 characters.

As of Version 11.5 changes were made to allow more labels and longer names.

 

 

The assembly '.ASM' file shows the Memory Address, Opcode, Instruction and the Address Label Table with Memory Addresses at the end.


The binary '.C12' file. To run this, you must change to Segment 2 and 'G'et file, load at 0000 and run 'Z' or use the short cut '0' which will ask you for the binary file and execute it.

 

 

 

The '.LST' file comments all BASIC lines so that you can see how the statements and function were compiled in CHIP-12 instructions.

All BASIC and CHIP-12 comments are removed in the '.CHP' file thus making it smaller.

 

 


Guidelines and special instructions for using the compiler

 

Note: It is highly recommended to read the DOSBOX CHIP12 Instruction document to familiarize yourself with all of its features, commands and instructions set.

In the directory where you unzipped the CHIP12 files and demos, you'll find a Word document named 'DOSBOX CHIP12_105 Instructions.doc' on how to use and learn CHIP-12.

 

General Format

The compiler is case sensitive. Therefore the syntax for commands and statements must be observed.

Dim Var1 As Byte

'The following If-Then statement will generate compile errors

If Var1 = 1 then

  Print "Hello!"

End If

 

Identifiers

An identifier is a programmer-chosen name to identify a variable, a memory address label or a subroutine name.

There are a few rules on how they can be formed:

• They may contain between 1 and 127 characters.

• They are case sensitive.

Variable and Labels must only contain alphanumeric characters.

The following table shows the valid characters you may use:

Group

Example

Uppercase letters

Lowercase letters

A,B,C...

a,b,c..

Numerals

0,1,2,3,4,5,6,7,8,9

 

You may also use the underscore '_', but please be aware that the compiler uses this symbol in auto-generated labels.

The following non-alphanumeric characters and symbols are not be used in labels or when dimensioning numeric and string variables:

( ) ` ~ ! # $ % ^ & * - + = | \ { } [ ] : ; " ' < > , . ? /

 

NOTE 1: If you intend to use the 'A' command in CHIP-12, Variable and Label lengths cannot be longer than 13 29† characters.

As of Version 11.5 changes were made to allow more labels and longer names.

NOTE 2: When using some BASIC functions and statements such as the Peek function or the Poke statement, since they can have either a variable or label, you must prefix labels with the @ symbol to differentiate them with variables.

• An identifier cannot be the same as a BASIC reserved word.

 

In general, it’s a good idea to use descriptive names for identifiers.

Sure, there's nothing wrong in using something like ABCD1234 as a variable or label, but

there’s no reason to make your identifiers hard to understand!

Here are some examples of well-formed names:

LineCount; firstValue; index; line_count; myFile; xCoord; Main; x_Coord

 

Example

'Var1 and var1 are not the same variable

Dim Var1 As Byte = 123

Dim var1 As Word = 456

 

Main:

Print var1

Print Var1

Goto main 'This will generate an error

 

Line Labels

You use line labels to mark statements that the program will reference with BASIC functions and statements like the Goto, Gosub, DefMemPtr, Peek , or Poke.

 

A line label is identified by a colon ':'.

Label:

Print "Hello World"

Goto Label

 

Numeric Representations

The compiler recognises several different numeric representations:

Binary is prefixed by %. i.e. %0101...

Character byte is surrounded by single quotes. i.e. 'a' represents a value of 97

Decimal values have no prefix.

Hexadecimal is prefixed by $. i.e. $0A

 

Dimensioning Numeric Variables

 

See also the Dim statement.

 

CHIP-12 has 256 variables designated as V00 to VFF.

Some variables are used by CHIP-12 and the BASIC compiler.

The following variables are reserved:

V00 to V0F.

The V7F register doubles as a flag for some instructions, thus you should avoid using it.

For example, in math operations, V7F is used as a carry/borrow flag.

In the draw instructions, V7F is set upon pixel/color collision.

In Shift or Rotate instructions, V7F is used as a carry flag.

The BASIC compiler will skip V7F when assigning CHIP-12 variables to your numeric variables.

Variables VC0 to VFF are dedicated to hold the X and Y coordinates when sprites are used.

You may use any variables that are not being used for the sprite(s).

For Sprite 00, the X coordinate is VC0 and the Y coordinate is VC1.

For Sprite 01, the X coordinate is VC2 and the Y coordinate is VC3 and so forth.

The compiler will give you a warning message to alert you when a numeric variable in your program uses a CHIP-12 variable that has exceeded 191.

Therefore, when variables are created with the Dim statement, depending on their data type - Byte, SByte, Word, SWord, DWord, SDWord, and Float - the first variable the compiler will use will be V10.

Byte type variables hold an unsigned value from 0 to 255. Uses one CHIP-12 variable.

SByte type variables hold the 2's complemented signed value from -128 to +127. Uses one CHIP-12 variable.

Word type variables hold an unsigned value from 0 to 65535. Uses two CHIP-12 variables.

SWord type variables hold a 2's complemented signed value from -32768 to +32767. Uses two CHIP-12 variables.

DWord type variables hold an unsigned value from 0 to 4294967295 making this the largest of the numeric integer variable family types. Uses four CHIP-12 variables.

SDWord type variables hold a 2's complemented signed value from -2147483648 to +2147483647.

Uses four CHIP-12 variables.

Float type variables hold a IEEE-754 32-bit value. Uses four CHIP-12 variables.

When a float number gets printed, if it is larger than 9 digits, the number gets printed in exponential format. i.e. 1,234,000,000,000,000,000 = 1.234E18

Use also exponential format when entering a number using the Input command.

 

Dimensioning String Variables

The compiler supports string variables.

You specify the length by adding the size in brackets at the end of the String directive in the Dim statement. If size is not defined, the compiler will assume the maximum length of 79 characters.

All strings are terminated by the ETX - End of Text ASCII character code $03.

In other words, the actual size of string is size + 1.


Initializing Numeric and String Variables

The following shows different ways in which variables can be initialized.

General Format for Numeric Variables:

Variable = {Number (Dec, Hex, or Binary) } {Variable} {+,-,*,/} {Number (Dec, Hex, or Binary) } {Variable}

 

Examples on how to initialize Numeric Variables:

Dim Tries As Word = 10 - You can initialize a variable when you Dimension it.

Mask = $F0 - When using a numeric type identifier

Counter = Counter + 15

Counter2 = Counter

Final_Result = 200 - Counter

Result = Num1 * Num2 - You can Add, Subtract, Multiply or Divide 2 variables, or a variable and a number, or 2 numbers.

All math operations of addition, subtraction, multiplication, and division use 32-bit floating point precision.

 

Note: I have not worked out an algorithm for complex math operations on one line, therefore for now, only one math operation can be done at once.

A math operation like this ((2 + 3) - 1) * 10 / 5 must be done in 4 steps (not counting the Dim and Print in the example):

Dim TempVar As Byte

TempVar = 2 + 3

TempVar = TempVar - 1

TempVar = TempVar * 10

TempVar = TempVar / 5

Print TempVar

 

General Format for String Variables:

{Dim} String Variable {As String(size)} = {"Alphanumeric Text"}{String Variable}{&}{"Alphanumeric Text"}{String Variable}

 

Examples on how to initialize String Variables:

Dim VarStr As String="Hello, my name is " - You can initialize when you Dimension it.

VarStr=VarStr & CHR(1) & "CHIP-12" & CHR(1) - Use the ampersand '&' to add strings together

Dim TestStr As String(15)="Marc Bertrand" - TestStr cannot be larger than 15 characters

VarStr=LEFT(VarStr,7) & RIGHT(TestStr,8) & ". Do you like " & MID(VarStr,20,7) & "?"

 

With following modifiers:

Variable = @Label - Get the memory address of Label.

Variable = ASC('ASCII Code' or String Variable) - See appropriate section

Variable = CHR(Number or Variable) - See appropriate section

Variable = HEX(Number or Variable) - See appropriate section

Variable = Inkey - See appropriate section

Variable = INSTR(String Variable) - See appropriate section

Variable = LEFT(String Variable,) - See appropriate section

Variable = LEN(String Variable) - See appropriate section

Variable = MID(String Variable,,) - See appropriate section

Variable = Peek(n),Address - See appropriate section

Variable = Random(Number or Variable) - See appropriate section

Variable = RIGHT(String Variable) - See appropriate section

Variable = STRDUP(Number or Variable, "Character" or String Variable) - See appropriate section

Variable = Val(String Variable) - See appropriate section

Variable = Variable And {Number (Dec, Hex, or Binary) } {Variable} - Logically AND's the contents

Variable = Variable Or {Number (Dec, Hex, or Binary) } {Variable} - Logically OR's the contents

Variable = Variable Xor {Number (Dec, Hex, or Binary) } {Variable} - Logically XOR's the contents

NOTE: When using the logical operations, the first parameter must be a variable.

 

Using Arrays in CHIP-12

The compiler supports 1-dimensional arrays for the following numeric data types - Byte, SByte, Word, SWord, DWord, SDWord, and Float.

You declare an array variable the same way as any other variable, by using the Dim statement.

In your declaration, you specify the array size inside a pair of parentheses after the variable name:

Dim ArrayName(arraysize) As DataType - See also Example 2 in Dim statement for using arrays.

The arraysize defines the maximum number of elements the array will have. The arraysize is 0-based.

Therefore, when declaring the array the maximum number of elements will be arraysize+1.

Arrays are stored in Segment 1 starting at memory address 0000.

The number of arrays you can have depends on the array size and the data type.

For instance, if you only have 1 array and the data type is Byte or SByte, then the maximum number of elements you can have is 65536.

If that 1 array data type is changed to Word or SWord, then the maximum number of elements you can have is 32768.

If that 1 array data type is changed to DWord or SDWord, then the maximum number of elements you can have is 16384.

When you use arrays, the compiler reserves 12 of the CHIP-12 variables to perform operations such as addition, subtraction, copying values to/from variables or arrays, etc.

You cannot use arrays with all Sprite functions and statements such as DeleteSprite, DisplaySprite, LoadSprite, MoveSpriteRight, MoveSpriteUp, MoveSpriteDown, SetSpriteXY, SetSpriteX, SetSpriteY, ShowSprite, If SpriteX, If SpriteY

 

Relational Operators

Relational operators are used to compare two values. The result can be used to make a decision

regarding program flow.

The list below shows the valid relational operators accepted by the compiler:

 

Operator

Relation

Expression Type

=

Equality

X = Y

<> 

Inequality

 X <> Y

< 

 Less than

X < Y

> 

Greater than

X > Y

<=

 Less than or Equal to

X <= Y

>=

Greater than or Equal to

X >= Y

 

 

Boolean Logic Operators

The If-Then-Else-End If and Do-Loop statements support the logical operators And, Or, and Xor.

You may use as many test conditions as you want.

Dim Var1 As Byte

Dim Var2 As Byte

 

Main:

Input "Var1=",Var1

Input "Var2=",Var2

If Var1 = 50 And Var2 <> Var1 Or Var2 <= 20 Or Var1 >=40  Then

  Print "Condition is True."

Else

  Print "Condition is False."

End If

Goto Main

 

Compiling Errors and Warnings

I've written the compiler to be able to catch most errors I could think of. It will also display warnings to alert you that the result will most likely not be what you expect.

Errors are demonstrated by showing the line of text in your program with a brief explanation all highlighted in  red .

Warnings are also demonstrated by showing the line of text in your program with a brief explanation all highlighted in  yellow .

 

 

Using Data In Your Program

You insert data in your program using the CHIP12BEGIN and CHIP12END directives.

Labels are designated by the '@' symbol.

Data strings are designated by the '$' symbol.

Data bytes are designated by the '*' symbol.

Technically, data should be put at the end of your BASIC program. If you put it any where else, make sure to put a Goto statement to 'skip over' the data area as shown in the following example:

 

Goto Jump_Over_Random_Number

CHIP12BEGIN

@Get_Random_Number

* 1E 56 B8 00 20 8E D8 B8 95 00 8B F0 B4 2C CD 21

* 52 B8 E8 03 33 C9 8A CE F7 E1 89 44 03 5A B8 0A

* 00 33 C9 8A CA F7 E1 01 44 03 33 DB 8A 1C 83 FB

* 00 0F 84 4C 00 83 7C 01 00 0F 85 0B 00 C7 44 01

* 5A A5 BA 5A A5 EB 04 90 8B 54 01 8B 44 03 F7 E2

* 05 5A 5A F7 E2 89 44 01 8B CB 3B C3 0F 86 05 00

* 2B C3 49 79 F5 3B C3 0F 86 07 00 25 FF 01 D1 E8

* EB E6 3B C3 0F 85 09 00 83 E2 01 0F 85 02 00 B0

* 00 88 04 5E 1F CB

@Random_Number_Parameters

* FF 5A 5A 00 00

CHIP12END

Jump_Over_Random_Number:

 

Dim Iterations As Word

Dim RndLimit As Word

 

Dim ExitVal As Byte=2

Do Until ExitVal=0

  If ExitVal = 2 Then

    Input"Enter maximum limit for Random",RndLimit

    Input"Enter number of iterations",Iterations

  End If

  CLS

  Dim Table_Start As Word

  Table_Start = @Random_Number_Table

  Print"Table_Start=";HEX(Table_Start)

  Print At 40,0,"Table_Offset=";

  Print At 40,1,"Random#=";

  Print At 40,2,"Seed=";

  Print At 0,1,"Iterations=";

 

  Print At 20,2, "Random Results";

  Print At 20,3, "--------------";

  Color Blue, Bright White

  Print At 5,4,"00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F";

  Dim Loop As Word

  Gosub Random_Results

  For Loop=1 To Iterations

    Print At 11,1;Loop;

    Poke(A),@Random_Number_Parameters,RndLimit

    Call Get_Random_Number

    Dim Count As Byte

    Count = Peek(A),@Random_Number_Parameters

    Print At 48,1,HEX(Count);

    Dim Table_Offset As Word

    Table_Offset = Table_Start + Count

    Print At 53,0;HEX(Table_Offset);

    Count = Peek(A), Table_Offset

    Count = Count + 1

    Poke(A),Table_Offset, Count

 

    Dim seedMemAddPtr As Word

    seedMemAddPtr=@Random_Number_Parameters

    seedMemAddPtr = seedMemAddPtr + 4

    Dim MemByte As Byte

    MemByte = Peek(5),seedMemAddPtr

    Print At 45,2,HEX(MemByte);

    seedMemAddPtr = seedMemAddPtr - 1

    MemByte = Peek(5),seedMemAddPtr

    Print HEX(MemByte);

    Gosub Random_Results

  Next

  'Clear table

  Position = 0

  For Ypos = 5 To 20

    For Xpos = 3 To 48 Step 3

      Table_Offset = Table_Start + Position

      Position = Position + 1

      Poke(A),Table_Offset, 0

    Next

  Next

  Color Black,Bright White

  Print At 0,22,"Press 0 to quit"

  Print"      1 to run with same parameters"

  Input"      2 to run with new parameters",ExitVal

Loop

END

 

Sub Random_Results

  Dim Xpos As Byte

  Dim Ypos As Byte

  Dim Position As Word = 0

  For Ypos = 5 To 20

    Color Blue, Bright White

    Print At 0,Ypos, HEX(Position);" ";

    For Xpos = 3 To 48 Step 3

      Table_Offset = Table_Start + Position

      Position = Position + 1

      Count = Peek(A), Table_Offset

      If Count = 0 Then

        Color Black,Yellow

      Else

        Color Black,Bright White

      End If

      Print HEX(Count);" ";

    Next

    Print

  Next

End Sub

 

CHIP12BEGIN

@Random_Number_Table

*00000000000000000000000000000000

*00000000000000000000000000000000

*00000000000000000000000000000000

*00000000000000000000000000000000

*00000000000000000000000000000000

*00000000000000000000000000000000

*00000000000000000000000000000000

*00000000000000000000000000000000

*00000000000000000000000000000000

*00000000000000000000000000000000

*00000000000000000000000000000000

*00000000000000000000000000000000

*00000000000000000000000000000000

*00000000000000000000000000000000

*00000000000000000000000000000000

*00000000000000000000000000000000

CHIP12END

 

NOTE: The compiler has its own Random function. The above example also shows how you can write your own machine language subroutine to accomplish any desired task.


Variables Used by BASIC Compiler

 

As mentioned earler in the Dimensioning Numeric Variables section, CHIP-12 variables V00 to V0F are reserved for BASIC compiler.

V00, V01, and V7F are used by some CHIP-12 instructions, therefore they should only be used as temporary variables.

Memory pointers 0,1 and F are used by BASIC compiler.

V05 serves for two purposes:

In alphanumeric modes 0 to 6, it is used for the maximum number of display lines before scrolling the characters on the screen

In graphic modes 7 to 9, it's used to select the small (V05=9) or large fonts (V05=16).

V03 and V04 keeps track of the X and Y coordinates when printing characters.

 

Known Issue With Keyboard CAPS LOCK in CHIP-12

 

There was difficulty getting the CAPS LOCK to work properly in CHIP-12.

Therefore, we decided to use the left SHIFT key to turn CAPS LOCK on and the right SHIFT key to turn CAPS LOCK off.

In order to enter uppercase letters, you'll need to press the left SHIFT key, press the desired key, then press the right SHIFT key.

The same goes to print the upper characters on the following keys:

 

Understanding CHIP-12 Background and Foreground Color Registers

 

The following diagram shows how to use the color registers:

In alphanumeric modes 0 to 6, two bytes are used to show each character on the screen. The first byte shows the character and the second byte describes its color and background attribute. The BackGround register is used to set the attribute byte as shown in the Color section.

In graphic modes 7 to 9, each byte sent to the screen memory represents a colored pixel. The color is determined by the value of the byte sent which is the ForeGround color register COLR.
Commands, Statements and Functions Overview

 

ASC

 

Syntax

ASC('ASCII character' or String variable)

 

Overview

Returns a Byte value that represents the character code corresponding to a character.

Operators

'ASCII character' - must be a single alpha-numeric character.

String variable -  only the first character of the string variable is used.

 

Example

Dim TestStr As String = "CHIP-12"

Dim Var1 As Byte = ASC('M')

Print "The ASCII code for TestStr is ";ASC(TestStr)

Print "The ASCII code for Var1 is ";ASC(Var1)

 

 

_______________________________________________________________________________________________________________

 

BackGnd

 

Syntax

BackGnd(Number or Variable)

 

Overview

Changes the background color in alphanumeric modes 0 to 6.

 

Operators

Number or Variable - value can be from 0 to 255, but only multiples of 16 up to 112 will select one of the following 8 colors:

0=Black, 16=Blue, 32=Green, 48=Cyan, 64=Red, 80=Magenta, 96=Brown, 112=White

If data type for variable is greater than Byte, the compiler will only use the value contained in LSB.

 

The following program will demonstrate the multiples of 16 up to 112.

Example

SCREEN 4

Dim BGColor As Byte

Do Until BGColor = 255

  Input BGColor

  BackGnd(BGColor)

Loop

_______________________________________________________________________________________________________________

 

Call

 

Syntax

Call Label

 

Overview

Calls a machine language subroutine at Label.

 

Operators

Label must comprise of alphanumeric characters.

 

Example

CAUTION: Don't press the 'ESC' key until you have stopped this program by entering anything or than 'Y' or 'y'.

The program must restore interrupt vector 1C before returning to CHIP-12. Failure to let the program terminate properly will crash DOSBox.

 

Goto Jump_Over_Interrupt_Vector

'        .MODEL SMALL

'        .STACK 100h

'        .DATA

'CountByte   db 0AAh

'oldvectorseg dw 1234h     ;old vector segment

'            dw 5678h     ;old vector offset

'      .CODE

'start:             push ds

'            push es

'            push di

'            mov ax,SEG oldvectorseg

'            mov ds,ax

'            mov ax,OFFSET oldvectorseg

'            mov di,ax

'            mov ax,351Ch

'            int 21h

'            mov [di],es

'            mov [di+2],bx

'            mov ax,SEG new_iv_handler

'            mov ds,ax

'            mov dx,OFFSET new_iv_handler

'            mov ax,251Ch

'            int 21h

'            pop di

'            pop es

'            pop ds

'            retf

'resetiv1C:  push ds

'            push si

'            mov ax,SEG oldvectorseg

'            mov ds,ax

'            mov ax,OFFSET oldvectorseg

'            mov si,ax

'            mov cx,[si]  ;Get old vector segment

'            mov dx,[si+2] ;Get old vector offset

'            mov ds,cx

'            mov ax,251Ch

'            int 21h

'            pop si

'            pop ds

'            retf

'new_iv_handler:push ds

'            push si

'            mov ax,SEG CountByte

'            mov ds,ax

'            mov si,OFFSET CountByte

'            mov al,[si]

'            inc al

'            mov [si],al

'            pop si

'            pop ds

'            iret

'            END    start

CHIP12BEGIN

@Set_New_Interrupt_Vector

* 1E 06 57 B8 00 20 8E D8 B8 66 00 8B F8 B8 1C 35

* CD 21 8C 05 89 5D 02 B8 00 20 8E D8 BA 52 00 B8

* 1C 25 CD 21 5F 07 1F CB

@Reset_Interrupt_Vector

* 1E 56 B8 05 00 8E D8 B8 66 00 8B F0 8B 0C 8B 54

* 02 8E D9 B8 1C 25 CD 21 5E 1F CB

;New Interrupt Vector 1C

* 1E 56 B8 00 20 8E D8 BE 65 00 8A 04 FE C0 88 04 5E 1F CF

@IV_Counter

* AA

;Old Vector Segment

* 34 12

;Old Vector Offset

* 78 56

CHIP12END

Jump_Over_Interrupt_Vector:

Call Set_New_Interrupt_Vector

 

Dim Loop As Word

Print"Counter  = ";

For Loop=0 To 100

  Dim Counter As Byte

  Counter = Peek(A), @IV_Counter

  Print HEX(Counter);" ";

  Delay(5)

Next

Print

Print "Done loop"

Dim KeyStr As String

Input"Run again (Y/N)",KeyStr

If KeyStr = "Y" Or KeyStr = "y" Then

  Goto Jump_Over_Interrupt_Vector

End If

Call Reset_Interrupt_Vector

Print "Program STOPPED"

STOP

 

_______________________________________________________________________________________________________________


 

CHIP12BEGIN

>...

CHIP12END

 

Syntax

CHIP12BEGIN

> - Instruction

>...

>...

CHIP12END

 

Overview

Incorporate in-line CHIP-12 Instruction codes and labels in the BASIC program. The instructions are compiled exactly as they are in between the CHIP12BEGIN and CHIP12END. Any syntax or formatting errors will be flagged by the compiler.

This allows a great deal of flexibility that cannot always be achieved using BASIC commands alone. The compiler will resolve all label and offset addresses.

Note: You can also use these directives for data and calling machine language subroutines.

 

Example 1

See Example 1 in Call

 

Example 2

See Examples for LoadLargeFont and LoadSmallFont

_______________________________________________________________________________________________________________

 

CHR

 

Syntax

CHR(Number or Variable)

 

Overview

Returns a String containing the ASCII character associated with the specified character code.

 

Operators

Number  - a value from  0 to 255. If number is greater than 255, only the least significant byte (LSB) will be used.

Variable  - if data type is larger than a byte, only the LSB will be used.

 

Example

Dim TestCHR As Word=12345

Print "The hex value of TestCHR is ",HEX(TestCHR)

Print "The ASCII character code of TestCHR is ";CHR(TestCHR)

Print "The ASCII character code 66 is ";CHR(66)

 

_______________________________________________________________________________________________________________

 

CLS

 

Syntax 1

CLS

 

Syntax 2

CLS({Number1,Number2} or {Variable1,Variable2})

 

Syntax 3

CLS(Number or Variable)

 

Overview

Syntax 1 and 2 are used only for alphanumeric graphic modes 0 to 6.

Clears the screen, resets cursor at X,Y coordinates to 0,0 (Top - Left),background is Black, character or foreground is White.

 

Syntax 3 is used only for graphic modes 7 to 9.

Clears or sets the background to Color in Number or Variable, resets cursor at X,Y coordinates to 0,0 (Top - Left)

 

Operators

Syntax 1

None

Syntax 2 and 3

Number or Variable - Range is from 0 to 255. Anything larger, the compiler will take the LSB.

Syntax 2

NOTE: Parameters must be of the same type. It's either 2 numbers or 2 variables

Number1 or Variable1 is the ASCII character code that will be displayed (See Character Table at the end of document).

Number2 or Variable2 is Color. See Color statement.

 

Example 1

'Not much to this one right! :)

CLS

 

Example 2

Dim BackGround As Byte=3

Dim ForeGround As Byte=2

DoItAgain:

SCREEN 2

'Displays ASCII character code 2 in Yellow

CLS(2,14)

Delay(500)

'Displays ASCII character code 3 in Green

CLS(BackGround,ForeGround)

Delay(500)

SCREEN 8

'Background is Cyan

CLS(BackGround)

Delay(500)

'Background is Magenta

CLS(5)

Delay(500)

Goto DoItAgain

 

 

_______________________________________________________________________________________________________________

 


Color

 

Syntax 1

Color BackgroundColor, CharacterColor, {Blink}

Syntax 2

Color(Number or Variable)

 

Overview

Syntax 1 is used to set the background color, character color, and blink in alphnumeric modes 0 to 6.

If you use syntax 1 in modes 7 to 9, the BackgroundColor stays black and the CharacterColor is set to the index color of the current palette. Usually the colors are as contained in the default VGA palette as shown in the Palette section unless another custom palette was loaded.

Can use Syntax 2 for all video modes.

Use table shown below to find the appropriate color attribute byte in alphnumeric modes 0 to 6.

In modes 7 to 9, the color is set to the index color of the current palette as described above.

 

Operators

BackgroundColor - may be a variable or one of the following constants: Black, Blue, Green, Cyan, Red, Magenta, Brown, White

CharacterColor -  may be a variable or one of the following constants: Black, Blue, Green, Cyan, Red, Magenta, Brown, White, Gray, Light Blue, Light Green, Light Cyan, Light Red, Light Magenta, Yellow, Bright White

Blink - Optional. Value may be a number or variable;

         - a value of zero (0) will turn character blinking off - default if missing

         - a non-zero value will turn character blinking on

Number or Variable - value can be from 0 to 255. If number is greater than 255, the compiler will use 255.

If data type for variable is greater than Byte, the compiler will only use the value contained in LSB.

 

The following table shows the color display attributes byte:

Background

 

 

Foreground

 

 

Bits (7,6,5,4)

F  R  G  B

Number

Color

Bits (3,2,1,0)

I  R  G  B

Number

Color

0  0  0  0

0  0  0  1

0  0  1  0

0  0  1  1

0  1  0  0

0  1  0  1

0  1  1  0

0  1  1  1

1  0  0  0

1  0  0  1

1  0  1  0

1  0  1  1

1  1  0  0

1  1  0  1

1  1  1  0

1  1  1  1

0

1

2

3

4

5

6

7

8

9

A

B

C

D

E

F

Black

Blue

Green

Cyan (Cyan)

Red

Magenta

Brown

White

Black blink

Blue blink

Green blink

Cyan blink

Red blink

Magenta blink

Brown blink

White blink

0  0  0  0

0  0  0  1

0  0  1  0

0  0  1  1

0  1  0  0

0  1  0  1

0  1  1  0

0  1  1  1

1  0  0  0

1  0  0  1

1  0  1  0

1  0  1  1

1  1  0  0

1  1  0  1

1  1  1  0

1  1  1  1

0

1

2

3

4

5

6

7

8

9

A

B

C

D

E

F

Black

Blue

Green

Cyan (Cyan)

Red

Magenta

Brown

White

Gray

Light Blue

Light Green

Light Cyan

Light Red

Light Magenta

Yellow

Bright White

F = Flashing bit

R = Red bit

G = Green bit

I = Intensity bit

B = Blue bit

 

 

Example

Color Blue, Yellow  'Blue background, Yellow character and since 3rd parameter missing - no blinking

Print "Blue background, Yellow character and since 3rd parameter missing - no blinking"

Color Red, Bright White, 1 'Red background, Bright White character and blinking on

Print "Red background, Bright White character and blinking on"

 

(Of course, if you compile and run this example, the white text in the red background will be flashing)

 

_______________________________________________________________________________________________________________

 

CopyBlock

 

Syntax

CopyBlock(Source Memory Address, Destination Memory Address, Number of Bytes To Copy)

 

Overview

Copies a number of bytes from one place to another.

 

Operators

Source Memory Address - can be a Number, Variable or @Label. Must use '@' symbol to differentiate between a Variable and Address Label. Uses CHIP-12 Memory Pointer 0. Therefore, if you need to access any other Segment besides the default Segment 2, use DefMemPtr(MH0)=Segment Address.

Destination Memory Address - can be a Number, Variable or @Label. Uses CHIP-12 Memory Pointer 1. Therefore, if you need to access any other Segment besides the default Segment 2, use DefMemPtr(MH1)=Segment Address.

Number of Bytes To Copy - can be a Number or Variable. Maximum number of bytes that can be copied is 65535.

 

Example

Sub Display_Mem_Block

  For StartMem=StartMem To EndMem

    Dim BlockByte As Byte

    BlockByte=Peek(2),StartMem

    Print CHR(BlockByte);

  Next

  Print

End Sub

 

Color Blue,Yellow

Print "Block1 Contents=";

Dim StartMem As Word=@Block1

Dim EndMem As Word=@Block1End

Gosub Display_Mem_Block

 

Color Green,Bright White

Print "Block2 before copy=";

StartMem=@Block2

EndMem=@Block2End

Gosub Display_Mem_Block

 

CopyBlock(@Block1,@Block2,20)

 

Color Red,Bright White,1

Print "Block2 after copy=";

StartMem=@Block2

Gosub Display_Mem_Block

STOP

 

CHIP12BEGIN

@Block1

* 01

$ Copy Block Example

@Block1End

* 01

@Block2

* 02

$ Thistextwillchange

@Block2End

* 02

CHIP12END

 

_______________________________________________________________________________________________________________

 

DefMemPtr

 

Syntax

DefMemPtr(MHn or MLn) = Address

 

Overview

Defines High or Low CHIP-12 Memory Pointer.

 

Operators

MH or  ML - Must select if defining the High or Low CHIP-12 Memory Pointer.

n - choose a hexadecimal digit from 2 to F for CHIP-12 Memory Pointer.

Address - can either be a Number(Dec or Hex), Variable or @Label.

 

See Also

Peek, Poke

 

Example

'This program will print the following characters

'0123456789:;<=>?@ABCDEFGHIJKLMONPQRSTUVWXYZ

'directly to the top-left corner screen.

DefMemPtr(MHA) = $B000

Dim MemAddPtr As Word = $8000

Dim Varbyte1 As Byte = 48

Dim Lop As Byte

For Lop = 1 To 43

  'Print character

  Poke(A),MemAddPtr,Varbyte1

  Varbyte1 = Varbyte1 + 1

  MemAddPtr = MemAddPtr + 1

  'Character color will be Bright White

  Poke(A),MemAddPtr,15

  MemAddPtr = MemAddPtr + 1

Next

 

 

_______________________________________________________________________________________________________________

 


DefNewChar

 

Syntax

DefNewChar(CharacterToBeChanged,@NewCharLabel)

 

Overview

Defines a new ASCII character.

 

Operators

CharacterToBeChanged - Required. Can be a number or variable. If numeric variable, only the first Byte will be used.

If string variable, only the first character of the expression will be used.

 

@NewCharLabel - Required. Points to the memory label where the new character data is. The pixel matrix is 8x16.

 

Example 1

 

Print "The following char ':' will change in a couple seconds."

Delay(200)

DefNewChar(":" ,@NEWCHAR)

STOP

CHIP12BEGIN

@NEWCHAR

* FF 18 3C 66 66 C3 99 A5

* A5 99 C3 66 66 3C 18 FF

CHIP12END

 

 

Example 2

Print "The following characters ':', '[', ']' and '";CHR(128);"' will change in a couple seconds."

Delay(200)

DefNewChar(":" ,@NEWCHAR_0)

Dim ChrToChange_1 As String="["

DefNewChar(ChrToChange_1 , @NEWCHAR_1)

Dim ChrToChange_2 As Byte=93  ' Change ] character

DefNewChar(ChrToChange_2,  @NEWCHAR_2)

DefNewChar(128,  @NEWCHAR_3)  ' Change ç character

STOP

CHIP12BEGIN

@NEWCHAR_0

* FF 81 81 81 81 81 81 81

* 81 81 81 81 81 81 81 FF

@NEWCHAR_1

* FF FF FF FF FF FF FF FF

* 81 81 81 81 81 81 81 FF

@NEWCHAR_2

* FF 81 81 81 81 81 81 81

* 81 FF FF FF FF FF FF FF

@NEWCHAR_3

* FF AA AA AA AA AA AA AA

* AA AA AA AA AA AA AA FF

CHIP12END

 


 

_______________________________________________________________________________________________________________

 

Delay

 

Syntax

Delay(Number or Variable)

 

Overview

Delays execution of program

 

Operators

Number or Variable - value can be from 0 to 65535

 

Example

Delay(72) 'Pause execution for 1 second

Delay(4240) 'Pause execution for 1 minute

Delay(Var1) 'Pause execution as per value in Var1

_______________________________________________________________________________________________________________

 

DeleteSprite

 

Syntax

DeleteSprite(Sprite Variable)

 

Overview

Delete the sprite which was shown with ShowSprite.

 

Operators

SpriteVariable - Specify which variable holds the sprite number.

 

See Also

DisplaySprite, LoadSprite, MoveSpriteRight, MoveSpriteLeft, MoveSpriteUp, MoveSpriteDown, Palette, SetSpriteXY, SetSpriteX, SetSpriteY, ShowSprite

 

Example

SCREEN 9

Dim Sprite10 As Byte=10 'Use SPRITE 10

LoadSprite(Sprite10,20,15,$B1) 'Load B1.SPR sprite file

ShowSprite(Sprite10,WVRT)

Delay(100)

'Even though this will delete the sprite, it will still show until the next WVRT instruction

DeleteSprite(Sprite10)

_______________________________________________________________________________________________________________

 


Dim

 

Syntax 1

Dim Variable As DataType {=Number or String}

 

Syntax 2

Dim [CHIP-12 Variable] As Numeric Size {=Number}

 

Syntax 3

Dim ArrayName(arraysize) As DataType

 

Overview

Declare either a numeric or string variable.

You can use the Dim statement any where in the program.

With the exception of arrays, you can also initialize the variable at the same time.

In other words, if you assign a value to the variable in the statement, the compiler will generate the instruction code(s) to initialize it at that particular place in your program.

Numeric and String variables are Global. Meaning that once they have been dimensioned, they are accessible throughout the program.

 

Operators

Variable - Required. Can be any alphanumeric character or string.

[CHIP-12 Variable] - Required. Must be 3 characters specifying which CHIP-12 variable enclosed in these open and closed brackets [ ]. In other words, a capital V followed by a hexdecimal byte - [V00] to [VFF].

DataType - Required. The physical size of the variable. Enter one of the following numeric data types: Byte, SByte, Word, SWord, DWord, SDWord, Float, or string data type: String. Variable string size can be from 1 to 79 characters by specifying the desired length in brackets.

Numeric Size - Required. The physical size of the CHIP-12 variable. Enter one of the following: Byte, SByte, Word, SWord, DWord, SDWord. The CHIP-12 variables will be sequential if data type is bigger than Byte. For example, if you select [V7F], and a size Word, the compiler will use V7F and V80 in all instructions and functions. Cannot use String.

Number - Optional. Any numeric representation as previously explained in the Guidelines and special instructions for using the compiler section.

String - cannot be larger than 79 characters or String(size).

 

Example 1

Dim VarByte As Byte

Dim VarWord As Word = 1234

'StrVar1 defaults to maximum size (79 characters)

Dim StrVar1 As String

'StrVar2 cannot be larger than 12 characters

Dim StrVar2 As String(12) = "Hello World!"

Dim [V7F] As Byte 'Allows access to Flag

Dim [VA0] As DWord 'Compiler will use VA0, VA1, VA2 and VA3 in all instructions and functions

 

Example 2

'This program will store 21 random numbers from 0 to 50 in an array

'then it will show all numbers that appear 2 or more times.

'To help differentiate the numbers, 6 different colors is used.

'Press any key to show next series of numbers.

Dim Array1(20) As Byte

Dim Array1Shadow(20) As Byte

Dim [V04] As Byte

Dim ColourCharacter(5) As Byte

ColourCharacter(0)=$9E 'Blue,Yellow,Blink

ColourCharacter(1)=$AF 'Green,Bright White,Blink

ColourCharacter(2)=$BE 'Cyan,Yellow,Blink

ColourCharacter(3)=$CF 'Red,Bright White,Blink

ColourCharacter(4)=$DF 'Magenta,Bright White,Blink

ColourCharacter(5)=$EF 'Brown,Bright White,Blink

Dim ColourIndex As Byte=0

Main:

For Index = 0 To 20

  Array1(Index) = Random(50)

  Array1Shadow(Index) = 0

Next

Dim Index As Byte

For Index = 0 To 20

  Gosub  ShowArrayValueWhite

Next

Dim Position As Byte=0

Do While Position < 20

  If PositionFlag = 1 Then

    ColourIndex = ColourIndex + 1

    If ColourIndex = 6 Then

      ColourIndex=0

    End If

  End If

  Color(ColourCharacter(ColourIndex))

  Dim PositionFlag As Byte=0

  Dim TempVar As Byte=Position

  TempVar=TempVar + 1

  For Index = TempVar To 20

    If Array1(Position) = Array1(Index) And Array1Shadow(Index) = 0 Then

      Array1Shadow(Index) = Array1(Index)

      If PositionFlag = 0 Then

        Dim Xpos As Byte=Position * 3

        'Using [V04] allows you to use Print At without affecting the Y position

        Print At Xpos,[V04];

        Dim SaveIndex As Byte=Index

        Index=Position

        Gosub PrintArray

        Index=SaveIndex 'Restore Index

        PositionFlag = 1

      End If

      Xpos = Index * 3

      Print At Xpos,[V04];

      Gosub PrintArray

    End If

  Next

  Position = Position +1

Loop

Print

Dim KeyVal As Byte

KeyVal=Inkey

Goto Main

 

Sub PrintArray

  Print HEX(Array1(Index));" ";

End Sub

 

Sub ShowArrayValueWhite

  Color(15)

  Gosub PrintArray

End Sub

 

 

Example 3

SCREEN 3

Dim Tries As Word = 10 ' You can initialize a variable when you Dimension it.

Dim Mask As Byte

Mask = $F0 ' When using a numeric type identifier

Dim Counter As DWord

Counter = $ABCD0123

Counter = Counter + 1234567890

Dim Counter2 As SByte

Counter2 = Counter

Dim Final_Result As Float

Final_Result = 12340000000000000000- Counter

Dim Result As SDWord

Dim Num1 As Word = %1111101001011111

Dim Num2 As Word = $EF

' You can Add, Subtract, Multiply or Divide 2 variables, or a variable and a number, or 2 numbers.

Result = Num1 * Num2

Print Mask

Print Counter

Print Counter2

Print Final_Result

Print Result

_______________________________________________________________________________________________________________

 

DisplaySprite

 

Syntax

DisplaySprite(Sprite Variable,Sprite File,WVRT or NO_WVRT)

 

Overview

Display a sprite file. Use this if sprite does not need to be moved as it cannot be deleted with DeleteSprite.

 

Operators

SpriteVariable - Specify which variable will hold the sprite number.

Sprite File - can use either a number or variable to specify which sprite file to use.

WVRT or NO_WVRT - specify if the WVRT instruction is needed to show the sprite right away or not. In other words, use NO_WVRT if you want to show the sprite now (WVRT instruction not needed)

 

See Also

DeleteSprite, LoadSprite, MoveSpriteRight, MoveSpriteLeft, MoveSpriteUp, MoveSpriteDown, Palette, SetSpriteXY, SetSpriteX, SetSpriteY, ShowSprite

 

Example

SCREEN 9

Dim Sprite14 As Byte=20 'Use SPRITE 20

SetSpriteXY(Sprite14,46,37)

DisplaySprite(Sprite14,202,NO_WVRT) 'Display CA.SPR sprite file

_______________________________________________________________________________________________________________

 

Do Loop

 

Syntax

Do {Until or While} test condition(s)

   [ statements ] 

Loop

 

Overview

Execute a block of instructions {Until or While} the test condition(s) is(are) true.

Do Loop's may be nested.

 

Operators

The first parameter in the test condition must be a variable followed by a valid logical operator as explained in the Relational Operators and Boolean Operators sections under the Guidelines and special instructions for using the compiler.

Test condition(s) is(are) evaluated from left to right. Consider the following example.

 

NOTES: Test condition(s) is(are) also evaluated from left to right for the If-Then-Else-End If statement.

              When using logical operators such as And, Or, and Xor, put at least one space to seperate each parameters.

              For example must have at least one space as shown in red:

                If Var1 And $80=128 Then 'OK

                If Var1 And $80=128 Then 'Not OK

 

Example

Dim Var1 As Byte

Dim Var2 As Byte

Dim Var3 As Byte=128

 

Do While Var1 <> 40 And Var2 >= 180 Or Var3 = 128

  Print "Var1=",Var1 ," Var2=",Var2," Var3=",Var3

  Input "Var1=",Var1

  Input "Var2=",Var2

  Input "Var3=",Var3

Loop

Print "Done"

 

The compiler will first evaluate if 'Var1 <> 40' is TRUE (1) or FALSE (0). Lets call the result x.

Then it will evaluate if 'Var2 >= 180' is TRUE or FALSE. Lets call the result y.

Then it will And both x and y to produce result, lets call this (x&y).

Then it will evaluate if 'Var3 = 128' is TRUE or FALSE. Lets call the result z.

Then it will Or both (x&y) and z to produce the final result.

_______________________________________________________________________________________________________________

 

Do Inkey

 

Syntax

Do {While or Until}  Inkey{= or <>}'ASCII char' or Variable

    [ statements ] 

Loop

 

Overview

Conditionally executes a group of statements, depending on the character read from the keyboard.

NOTE: Unlike the Do Loop, you can only have one condition. In other words, you cannot use the logical operators And,Or,Xor because this is a special Do statement which will use these CHIP-12 instructions:

42 00 kk       EXIF KEY = #kk                EXEC NEXT INSTR IF KEY = kk

43 00 xx       EXIF KEY = Vxx                EXEC NEXT INSTR IF KEY = Vxx

32 00 kk       SKIF KEY = #kk                SKIP NEXT INSTR IF KEY = kk

33 00 xx       SKIF KEY = Vxx                SKIP NEXT INSTR IF KEY = Vxx

 

Operators

The first parameter in expression must begin with Inkey.

The second parameter can only be equal (=) or not equal (<>).

The third parameter can be an 'ASCII char' or Variable.

statements - One or more statements following Do...Loop that are executed if condition evaluates to True.

Loop - Required. Terminates the Do...Loop...block.

 

See Also

If Inkey

 

Example

Dim ExitVal As Byte=$58

 

Sub EditMemory

  Print "Now in EditMemory Sub"

  Do Until Inkey <> 'M'

    'Wait till 'M' key released

  Loop

End Sub

 

Sub EditRegs

  Print "Now in EditRegs Sub"

  Do While Inkey = 'R'

    'Wait till 'R' key released

  Loop

End Sub

 

Print "Press 'M' to edit Memory"

Print "      'R' to edit Registers"

Print "      'X' to edit eXit"

Main:

If Inkey = 'M' Then

  Gosub EditMemory

End If

If Inkey = 'R' Then

  Gosub EditRegs

End If

If Inkey = ExitVal Then

  Print "Program is STOPPED"

  STOP

End If

Goto Main

 

_______________________________________________________________________________________________________________


 

DrawPattern

 

Syntax

DrawPattern(Address Label,x_Coordinate,y_Coordinate,Height)

 

Overview

Draws, at the X-Y coordinates, a pattern with the number of bytes starting at the memory address label.

Contents of the pattern are XOR’d with the current data on screen. Therefore an unset pixel in a pattern will have no effect on the data currently on screen. A set pixel in a pattern will cause the pixel on screen to be set if it is currently unset, or unset if it is currently set.

In the latter case, a collision flag will also be set to show the pattern data overlapped with existing data on screen.

CHIP-12 V7F is used as the flag and will be set to $01 if any set pixel in the pattern overwrites an existing set pixel on the display, otherwise V7F = $00. See Example 3 further down below.

The pattern color is set with the Color statement.

For those familiar with CHIP-8, this is the same as the DXYN instruction.

For a more advanced and detailed way of drawing a pattern is using the DisplaySprite function.

 

Operators

Address Label - can be a Number, Variable or @Label. Must use '@' symbol to differentiate between a Variable and Address Label. Uses CHIP-12 Memory Pointer 0. Therefore, if you need to access any other Segment besides the default Segment 2, use DefMemPtr(MH0)=Segment Address.

x_Coordinate,y_Coordinate - can be a Number or Variable.

Height - specifies the number of bytes to draw. Number can be between 1 and15. The width of the pattern is fixed at eight pixels (one byte). You can still have a pattern narrower than a byte by just setting the unwanted pixels to the right of the image to 0, as shown below in Example 2.

 

See Also

DefNewChar

 

Example 1

 

 

 

 

 

 

 

Image courtesy of Laurence Scotford - http://laurencescotford.co.uk/

SCREEN 4

Dim Blue As Byte=1

Color(Blue)

DrawPattern(@FacePattern, 0, 0, 9)

'Erase the blue eyes before drawing red eyes

DrawPattern(@Eyes_Mouth, 0, 3, 1)

Dim Red As Byte=4

Color(Red)

DrawPattern(@Eyes_Mouth, 0, 3, 1)

'Erase the blue mouth before drawing cyan mouth

Color(Blue)

DrawPattern(@Eyes_Mouth, 0, 5, 2)

Dim Cyan As Byte=3

Color(Cyan)

DrawPattern(@Eyes_Mouth, 0, 5, 2)

STOP

CHIP12BEGIN

@FacePattern

* 3C 42 81 A5 81 A5 99 42 3C

@Eyes_Mouth

* 24 18

CHIP12END


 

Example 2

 

 

Image courtesy of Laurence Scotford - http://laurencescotford.co.uk

 

 

 

 

SCREEN 4

'Default draw color is white

DrawPattern(@DownArrowPattern, 0, 0, 9)

STOP

CHIP12BEGIN

@DownArrowPattern

* 20 20 20 20 20 20 F8 70 20

CHIP12END

 

Example 3

 

 

Image courtesy of Laurence Scotford - http://laurencescotford.co.uk

SCREEN 4

'Default draw color is white

'1st draw screen data before pattern is displayed

DrawPattern(@SquareBlock, 0, 4, 5)

'Then draw pattern

DrawPattern(@FacePattern, 0, 0, 9)

STOP

CHIP12BEGIN

@FacePattern

* 3C 42 81 A5 81 A5 99 42 3C

@SquareBlock

* FF FF FF FF FF

CHIP12END

 

Example 4

Sub ShowByte

  HexDigit=Number SHIFT>> 4

  Gosub ShowHexDigit

  x_Coord=x_Coord+5

  HexDigit=Number And 15

  Gosub ShowHexDigit

End Sub

 

Sub ShowHexDigit

  If HexDigit = 0 Then

    DrawPattern(@HexDigit_0,x_Coord,y_Coord,5)

  Else

    If HexDigit = 1 Then

      DrawPattern(@HexDigit_1,x_Coord,y_Coord,5)

    Else

      If HexDigit = 2 Then

        DrawPattern(@HexDigit_2,x_Coord,y_Coord,5)

      Else

        If HexDigit = 3 Then

          DrawPattern(@HexDigit_3,x_Coord,y_Coord,5)

        Else

          If HexDigit = 4 Then

            DrawPattern(@HexDigit_4,x_Coord,y_Coord,5)

          Else

            If HexDigit = 5 Then

              DrawPattern(@HexDigit_5,x_Coord,y_Coord,5)

            Else

              If HexDigit = 6 Then

                DrawPattern(@HexDigit_6,x_Coord,y_Coord,5)

              Else

                If HexDigit = 7 Then

                  DrawPattern(@HexDigit_7,x_Coord,y_Coord,5)

                Else

                  If HexDigit = 8 Then

                    DrawPattern(@HexDigit_8,x_Coord,y_Coord,5)

                  Else

                    If HexDigit = 9 Then

                      DrawPattern(@HexDigit_9,x_Coord,y_Coord,5)

                    Else

                      If HexDigit = 10 Then

                        DrawPattern(@HexDigit_A,x_Coord,y_Coord,5)

                      Else

                        If HexDigit = 11 Then

                          DrawPattern(@HexDigit_B,x_Coord,y_Coord,5)

                        Else

                          If HexDigit = 12 Then

                            DrawPattern(@HexDigit_C,x_Coord,y_Coord,5)

                          Else

                            If HexDigit = 13 Then

                              DrawPattern(@HexDigit_D,x_Coord,y_Coord,5)

                            Else

                              If HexDigit = 14 Then

                                DrawPattern(@HexDigit_E,x_Coord,y_Coord,5)

                              Else

                                DrawPattern(@HexDigit_F,x_Coord,y_Coord,5)

                              End If

                            End If

                          End If

                        End If

                      End If

                    End If

                  End If

                End If

              End If

            End If

          End If

        End If

      End If

    End If

  End If

End Sub

 

Dim y_Coord As Byte=10

Dim Offset As Byte=5

Dim Colour As Byte=1

Dim HexDigit As Byte=0

Dim Number As Byte=0

SCREEN 4

 

Up:

Dim x_Coord As Byte=12

Gosub ShowByte

 

Print At 0,0, "Enter a number(0 to 255)";

Dim Temp As Byte

Input Temp

 

'Erase number

x_Coord=12

Gosub ShowByte

Number=Temp

 

Colour = Colour + 1

If Colour = 16 Then

  Colour=1

End If

Color(Colour)

Goto Up

 

CHIP12BEGIN

@HexDigit_E

* F0 80

@HexDigit_F

* F0 80

@HexDigit_C

* F0 80 80 80

@HexDigit_B

* F0 50 70 50

@HexDigit_D

* F0 50 50 50

@HexDigit_5

* F0 80

@HexDigit_2

* F0 10

@HexDigit_6

* F0 80

@HexDigit_8

* F0 90

@HexDigit_9

* F0 90

@HexDigit_3

* F0 10 F0 10

@HexDigit_A

* F0 90

@HexDigit_0

* F0 90 90 90

@HexDigit_7

* F0 10 10 10 10

@HexDigit_1

* 60 20 20 20 70

@HexDigit_4

* A0 A0 F0 20 20

CHIP12END

 

 

_______________________________________________________________________________________________________________


END

 

Syntax

END

 

Overview

Exits from CHIP-12 program and returns to CHIP-12 Command prompt.

 

Operators

None

 

Example

Dim Count As SByte

 

For Count = 100 To 0 Step -1

  If Count = 49 Then

    END

  End If

  Print "Count=";Count;

Next

'This never gets executed

Print"Done"

 

See Also

STOP

_______________________________________________________________________________________________________________

 

ERASETEXTFLAGOFF

ERASETEXTFLAGON

 

Syntax 1

ERASETEXTFLAGOFF

Syntax 2

ERASETEXTFLAGON

 

Overview

These functions allow you to erase the text that was printed using GPrint and GInput when you are using one or more sprites.

Use these only in graphic modes 7 to 9.

 

Operators

None

 

Example

Copy the HappySprites demo at http://marcpic.com/CHIP12/Happy%20Sprites%20Demo.htm

Add the following at the end:

If Inkey = 't' Then

  ERASETEXTFLAGON

  Dim StrText As String

  GInput "Enter text",StrText

  ERASETEXTFLAGOFF

  GPrint StrText

End If

Goto Main


 

The 'Enter text' will disappear after you press ENTER. What you type will be visible.

(If you put ERASETEXTFLAGOFF after the GPrint StrText, then no text will be visible).

 

_______________________________________________________________________________________________________________

 

For Next

 

Syntax

For Variable = Start To End {Step Number or Variable}

   [ statements ] 

Next

 

Overview

Repeats a group of statements a specified number of times.

For Next's may be nested.

 

Operators

Start - Required. The initial value of counter. It can be a Number (Dec or Hex) or Variable.

End - Required. The final value of counter. It can be a Number (Dec or Hex) or Variable.

End value must be greater than or equal to Start.

Step is Optional. The amount by which counter is incremented or decremented each time through the loop. It can be a Number (Dec or Hex) or Variable.

 

Example

Dim Count As Byte

Dim Max As Byte = 100

 

For Count = 0 To Max Step 20

  Print "Count=",Count

Next

Print "Done"

 

 

 

_______________________________________________________________________________________________________________

 

GetFile

 

Syntax

GetFile(MemPtr,"Filename String" or String Variable)

 

Overview

Retrieves all data bytes from a file and stores them in the memory specified by memory pointer.

You must initialize the Memory Pointer with the DefMemPtr statement before using this statement.

 

Operators

MemPtr - Required. Enter a hexadecimal digit from 2 to E to specify which memory pointer will be used.

"Filename String" or String Variable  - Required. The file name must comprise of only hexadecimal numbers and must have the following format:

HH.AAA - where H is a hexadecimal digit 0 to F and AAA is an alphanumeric character A to Z and/or number 0 to 9.

 

See Also

WriteFile

 

Example

Dim NumOfBytes As Word=$1FF

Dim FileName As String="F1.TXT"

 

DefMemPtr(MH2)=$8000

DefMemPtr(ML2)=0

WriteFile(2,FileName,NumOfBytes)

 

DefMemPtr(MH3)=$2000

DefMemPtr(ML3)=0

WriteFile(3,"A2.C12",255)

 

DefMemPtr(MH4)=$1000

DefMemPtr(ML4)=512

GetFile(4,FileName)

 

DefMemPtr(MH5)=$7000

DefMemPtr(ML5)=8192

GetFile(5,"A2.C12")

_______________________________________________________________________________________________________________

 


GInput

 

Syntax

GInput {At xpos,ypos}{SKIPQM}{"Prompt String"}{,}Variable or String{,}{Variable or String}...{, or ;}

 

Overview

Accepts keyboard entries. Same as Input except can only be used with Graphics modes 7, 8, and 9.

 

Operators

Variable or String is required.

At xpos,ypos - Optional. Assigns a specified X-Y position for entry or prompt string.

SKIPQM - Optional. Skips printing the '?'.

Prompt String - Optional. Please note that if you are to include a string variable in the prompt, you must use the '&' sign. See Example 2.

comma - must be used to separate between At, Prompt String and Variables.

Ending comma or semicolon - Optional. If you don't want a Carriage Return / Line Feed after entry.

 

See Also

Input

 

Example

SCREEN 7

Dim Xpos As Byte

Dim Ypos As Byte

Dim Colour As Byte

Up:

GInput "Xpos=",Xpos

GInput "Ypos=",Ypos

Colour = Random(14)

Colour = Colour + 1

Color(Colour)

Dim StrText As String

GInput"Enter text Msg",StrText

GPrint At Xpos, Ypos, StrText

Dim KeyVal As Byte

KeyVal=Inkey

CLS(0)

Goto Up

_______________________________________________________________________________________________________________

 

Gosub

 

Syntax

Gosub Subname

 

Overview

Branches to and returns from a subroutine. You can place subroutine(s) anywhere in the program.

 

Operators

SubName can be any valid identifier as explained in the Guidelines and special instructions for using the compiler section.

 

See Also

Sub End Sub

 

Example

Dim Lop As Byte

Dim RandomNum As Word=0

 

Sub GetNewNum

  RandomNum = Random(200)

  Print "Random(200)=",RandomNum

  RandomNum = RandomNum + 150

End Sub

 

For Lop=0 To 14

  Gosub GetNewNum

  Print "RandomNum=",RandomNum

Next

 

 

_______________________________________________________________________________________________________________

 

Goto

 

Syntax

Goto Label

 

Overview

Branches to Label.

 

Operators

Label must comprise of alpha-numeric characters.

 

Example

UpHere:

Print "Hello World"

Goto UpHere

 

_______________________________________________________________________________________________________________

 

GPrint

 

Syntax

GPrint {At xpos,ypos}{; or ,}{HEX(variable or number){; or ,}{; or ,}{CHR(variable or number) {; or ,}{"Prompt String"}

{; or ,}{Variable or String}{; or ,}

 

Overview

Displays textual output on the screen. Same as Print except can only be used with Graphics modes 7, 8, and 9.

 

Operators

At xpos,ypos - Optional. Assigns a specified X-Y position on where to start printing.

Prompt String - Optional.

semicolon or comma - must be used to separate between At, Prompt String and Variables.

Ending semicolon or comma - Optional. If you don't want a Carriage Return / Line Feed after printing.

NOTE: contrary to normal BASIC versions where the comma is used to separate values by advancing the cursor to the next tab stop position, semicolons and commas are interchangeable (See example for Print).

 

See Examples 2 and 3 for LoadLargeFont and LoadLargeFont

_______________________________________________________________________________________________________________

 

HEX

 

Syntax

HEX(Number or Variable)

 

Overview

Returns a String representing the hexadecimal value of a number.

 

Operators

Number or Variable - Any numeric value which results up to a maximum of eight hexadecimal characters.

 

Example

Dim TestHEX1 As Byte = 123

Dim TestHEX2 As SByte = -123

Dim TestHEX3 As Word = 23456

Dim TestHEX4 As SWord = -23456

Dim TestHEX5 As DWord = 987612345

Dim TestHEX6 As SDWord = -987612345

 

Print "The hex value of TestHEX1 is ",HEX(TestHEX1)

Print "The hex value of TestHEX2 is ",HEX(TestHEX2)

Print "The hex value of TestHEX3 is ",HEX(TestHEX3)

Print "The hex value of TestHEX4 is ",HEX(TestHEX4)

Print "The hex value of TestHEX5 is ",HEX(TestHEX5)

Print "The hex value of TestHEX6 is ",HEX(TestHEX6)

Print "The hex value of -12 is ",HEX(-12)

Print "The hex value of -2345 is ",HEX(-2345)

Print "The hex value of -19860617 is ",HEX(-19860617)

 

_______________________________________________________________________________________________________________

 

 

If Then

 

Syntax

If condition {And Or Xor condition ...} Then

    [ statements ] 

{ Else 

    [ elsestatements ] } 

End If

 

Overview

Conditionally executes a group of statements, depending on the value of an expression.

 

Operators

condition is a required expression. Must evaluate to True or False. Can use And,Or,Xor between conditions.

The first parameter in expression must begin with a variable.

The second parameter can be one of any relational or boolean operator as explained in the Relational Operators and Boolean Operators sections under the Guidelines and special instructions for using the compiler.

Test condition(s) is(are) evaluated from left to right.

The third parameter can be a variable or a number.

statements - One or more statements following If...Then that are executed if condition evaluates to True.

elsestatements - Optional. One or more statements that are executed if previous condition evaluates to False.

End If - Required. Terminates the If...Then...Else block.

 

NOTES: Test condition(s) is(are) also evaluated from left to right for the Do-Loop statement.

             You can also mask a variable with a number or variable as shown in example 1.

             You can nest If-Then statements as shown in example 2.

              When using logical operators such as And, Or, and Xor, put at least one space to seperate each parameters.

              For example must have at least one space as shown in red:

                If Var1 And $80=128 Then 'OK

                If Var1 And $80=128 Then 'Not OK

 

Example 1

Dim Num1 As Byte

Dim Mask As Byte = $0F

 

Main:

Input "Enter a number (0 to 255)",Num1

If Num1 And Mask < 10 Then

  Print "Character masks into a number from 0 to 9."

Else

  Print "Character does not mask into a number from 0 to 9."

End If

Print "Hex value of Num1 = ",HEX(Num1)

Goto Main

 

The compiler first And's the value in Num1 with value in Mask, then if the result is less than 10, the condition is True.

 

Example 2

SCREEN 3

Main:

Dim RndNum As Byte

RndNum = Random(7)

If RndNum = 0 Then

  Color White, Black

  Print"Black"

Else

  If RndNum = 1 Then

    Color White, Blue

    Print"Blue"

  Else

    If RndNum = 2 Then

      Color White, Green

      Print"Green"

    Else

      If RndNum = 3 Then

        Color White, Cyan

        Print"Cyan"

      Else

        If RndNum = 4 Then

          Color White, Red

          Print"Red"

        Else

          If RndNum = 5 Then

            Color White, Magenta

            Print"Magenta"

          Else

            If RndNum = 6 Then

              Color White, Brown

              Print"Brown"

            Else

              Color Black, Bright White

              Print"White"

            End If

          End If

        End If

      End If

    End If

  End If

End If

Delay(100)

Goto Main

 

_______________________________________________________________________________________________________________

 

If Inkey

 

Syntax

If Inkey{= or <>}'ASCII char' or Variable Then

    [ statements ] 

End If

 

Overview

Conditionally executes a group of statements, depending on the character read from the keyboard.

NOTE: Unlike the If Then, you can only have one condition. In other words, you cannot use the logical operators And,Or,Xor because this is a special If statement which will use these CHIP-12 instructions:

42 00 kk       EXIF KEY = #kk                EXEC NEXT INSTR IF KEY = kk

43 00 xx       EXIF KEY = Vxx                EXEC NEXT INSTR IF KEY = Vxx

32 00 kk       SKIF KEY = #kk                SKIP NEXT INSTR IF KEY = kk

33 00 xx       SKIF KEY = Vxx                SKIP NEXT INSTR IF KEY = Vxx

 

Operators

The first parameter in expression must begin with Inkey.

The second parameter can only be equal (=) or not equal (<>).

The third parameter can be an 'ASCII char' or Variable.

statements - One or more statements following If...Then that are executed if condition evaluates to True.

End If - Required. Terminates the If...Then...block.

 

See Also

Do Inkey

 

Example

Dim ExitVal As Byte=$58

 

Sub EditMemory

  Print "Now in EditMemory Sub"

  Do Until Inkey <> 'M'

    'Wait till 'M' key released

  Loop

End Sub

 

Sub EditRegs

  Print "Now in EditRegs Sub"

  Do While Inkey = 'R'

    'Wait till 'R' key released

  Loop

End Sub

 

Print "Press 'M' to edit Memory"

Print "      'R' to edit Registers"

Print "      'X' to eXit"

Main:

If Inkey = 'M' Then

  Gosub EditMemory

End If

If Inkey = 'R' Then

  Gosub EditRegs

End If

If Inkey = ExitVal Then

  EXIT

End If

Goto Main

_______________________________________________________________________________________________________________

 

If SpriteX

If SpriteY

 

Syntax 1

If SpriteX(Sprite Variable){= ; <> ; > or < } Number or Variable Then

    { statements }

End If

Syntax 2

If SpriteY(Sprite Variable){= ; <> ; > or < } Number or Variable Then

    { statements }

End If

 

Overview

Conditionally executes a group of statements, depending on if the X or Y is equal to or not equal to zero.

NOTE: Unlike the If Then, you can only have one condition. In other words, you cannot use the logical operators And,Or,Xor because these are special If statements which will use these CHIP-12 instructions:

F0 xx kk       SKIF Vxx X = #kk              SKIP NEXT INSTR IF SPRITE Vxx X = kk

F1 xx kk       SKIF Vxx Y = #kk              SKIP NEXT INSTR IF SPRITE Vxx Y = kk

F2 xx yy       SKIF Vxx X = Vyy              SKIP NEXT INSTR IF SPRITE Vxx X = Vyy

F3 xx yy       SKIF Vxx Y = Vyy              SKIP NEXT INSTR IF SPRITE Vxx Y = Vyy

F4 xx kk       SKIF Vxx X > #kk              SKIP NEXT INSTR IF SPRITE Vxx X > kk

F5 xx kk       SKIF Vxx Y > #kk              SKIP NEXT INSTR IF SPRITE Vxx Y > kk

F6 xx kk       SKIF Vxx X < #kk              SKIP NEXT INSTR IF SPRITE Vxx X < kk

F7 xx kk       SKIF Vxx Y < #kk              SKIP NEXT INSTR IF SPRITE Vxx Y < kk

F8 xx kk       EXIF Vxx X = #kk              EXEC NEXT INSTR IF SPRITE Vxx X = kk

F9 xx kk       EXIF Vxx Y = #kk              EXEC NEXT INSTR IF SPRITE Vxx Y = kk

FA xx yy       EXIF Vxx X = Vyy              EXEC NEXT INSTR IF SPRITE Vxx X = Vyy

FB xx yy       EXIF Vxx Y = Vyy              EXEC NEXT INSTR IF SPRITE Vxx Y = Vyy

FC xx kk       EXIF Vxx X > #kk              EXEC NEXT INSTR IF SPRITE Vxx X > kk

FD xx kk       EXIF Vxx Y > #kk              EXEC NEXT INSTR IF SPRITE Vxx Y > kk

FE xx kk       EXIF Vxx X < #kk              EXEC NEXT INSTR IF SPRITE Vxx X < kk

FF xx kk       EXIF Vxx Y < #kk              EXEC NEXT INSTR IF SPRITE Vxx Y < kk

 

Operators

SpriteVariable - Specify which variable will hold the sprite number.

The second parameter can be equal (=); not equal (<>); greater than (>) or Less than (<).

The third parameter can be a Number or Variable.

statements - Optional. One or more statements following If...Then that are executed if condition evaluates to True.

End If - Required. Terminates the If...Then...block.

 

Example

See Tutorial - How to create and use Sprites

 

_______________________________________________________________________________________________________________

 

If PlayEnd

 

Syntax

If PlayEnd{= or <>}0 Then

    { statements }

End If

 

Overview

Conditionally executes a group of statements, depending on if the sound file that is currently playing has ended.

NOTE: Unlike the If Then, you can only have one condition. In other words, you cannot use the logical operators And,Or,Xor because this is a special If statement which will use these CHIP-12 instructions:

3A 00 00       SKIF PEND = 0                 SKIP NEXT INSTR IF VOC SOUND FILE ENDED PLAY

4A 00 00       EXIF PEND = 0                 EXEC NEXT INSTR IF VOC SOUND FILE ENDED PLAY

 

Operators

The first parameter in expression must begin with PlayEnd.

The second parameter can only be equal (=) or not equal (<>).

The third parameter can only be 0.

statements - Optional. One or more statements following If...Then that are executed if condition evaluates to True.

End If - Required. Terminates the If...Then...block.

 

See Also

LoadPlaySound, LoadSoundFile, PlaySound

 

The sound files for the following demo is in SoundDemo folder in the CHIP12Files.ZIP

Example

'This will loop through and play sound files 0, 2, 4, and 6.

Dim SoundFileNum As Byte=2

Dim SoundFileName As Byte=$0A

Dim SoundFileNum2 As Byte=6

Dim SoundFileName2 As Byte=$0B

LoadSoundFile(0,$F1)

LoadSoundFile(SoundFileNum,SoundFileName)

StartAgain:

PlaySound(0)

Sound0:

If PlayEnd <> 0 Then

  Print "Playing Sound(0)"

  Delay(10)

End If

If PlayEnd = 0 Then

  PlaySound(SoundFileNum)

  Sound2:

  If PlayEnd <> 0 Then

    Print "Playing Sound(",SoundFileNum,")"

    Delay(10)

  End If

  If PlayEnd = 0 Then

    LoadPlaySound(4,$F2)

    DoThisSoundTwice:

    If PlayEnd <> 0 Then

      Delay(10)

      Goto DoThisSoundTwice

    End If

    PlaySound(4)

    Sound4:

    If PlayEnd <> 0 Then

      Print "Playing Sound(4)"

      Delay(10)

    End If

    If PlayEnd = 0 Then

      LoadPlaySound(SoundFileNum2,SoundFileName2)

      Sound6:

      If PlayEnd <> 0 Then

        Print "Playing Sound(",SoundFileNum2,")"

        Delay(10)

      End If

      If PlayEnd = 0 Then

        Goto StartAgain

      End If

      Goto Sound6

    End If

    Goto Sound4

  End If

  Goto Sound2

End If

Goto Sound0

_______________________________________________________________________________________________________________

 

If Timer

 

Syntax

If Timer{= or <>}0 Then

    { statements }

End If

 

Overview

Conditionally executes a group of statements, depending on if the Timer is equal to or not equal to zero.

NOTE: Unlike the If Then, you can only have one condition. In other words, you cannot use the logical operators And,Or,Xor because this is a special If statement which will use these CHIP-12 instructions:

48 00 00       EXIF TIMR = 0                 EXEC NEXT INSTR IF TIMER = 0

38 00 00       SKIF TIMR = 0                 SKIP NEXT INSTR IF TIMER = 0

 

Operators

The first parameter in expression must begin with Timer.

The second parameter can only be equal (=) or not equal (<>).

The third parameter can only be 0.

statements - Optional. One or more statements following If...Then that are executed if condition evaluates to True.

End If - Required. Terminates the If...Then...block.

 

Example

Dim TmrValue As Byte=30

Timer(TmrValue)

Main:

If Timer = 0 Then

  Color Green, Bright White

  Print"Timer is 0"

  Timer(30)

End If

If Timer <> 0 Then

  Color Blue, Yellow

  Print"Timer is not 0"

  Delay(100)

End If

Goto Main

 

_______________________________________________________________________________________________________________

 

Inkey

 

Syntax

Variable = Inkey

 

Overview

Waits for a character from keyboard.

 

Operators

Variable - holds the character value from keyboard.

 

_______________________________________________________________________________________________________________

 


Input

 

Syntax

Input {At xpos,ypos}{SKIPQM}{"Prompt String"}{,}Variable or String{,}{Variable or String}...{, or ;}

 

Overview

Accepts keyboard entries. Same as GInput except can only be used with graphics modes 0 to 6.

 

Operators

Variable or String is required.

At xpos,ypos - Optional. Assigns a specified X-Y position for entry or prompt string.

SKIPQM - Optional. Skips printing the '?'.

Prompt String - Optional. Please note that if you are to include a string variable in the prompt, you must use the '&' sign. See Example 2.

comma - must be used to separate between At, Prompt String and Variables.

Ending comma or semicolon - Optional. If you don't want a Carriage Return / Line Feed after entry.

 

See Also

GInput

 

Example 1

Dim Xpos As Byte=0

Dim Ypos As Byte=0

 

Main:

Input At Xpos,Ypos, "Enter Xpos,Ypos", Xpos,Ypos;

Goto Main

 

 

 


Example 2

Sub Print_Result

  Print "You chose ";StrVar1

End Sub

 

Main:

Dim StrVar1 As String=""

Dim TestStr1 As String="TestStr One"

Dim TestStr2 As String="TestStr Two"

Do Until StrVar1="Hello" Or StrVar1="Good-Bye" Or StrVar1=TestStr1 Or StrVar1=TestStr2

  Print "You must enter 1 of the following:"

  Input "Hello" & CHR(59) & " Good-Bye" & CHR(59) & " " & TestStr1 & CHR(59) & " " & TestStr2,StrVar1

  If StrVar1 = "Hello" Then

    Color Blue, Yellow

    Gosub Print_Result

  Else

    If StrVar1 = "Good-Bye" Then

      Color Green, Bright White

      Gosub Print_Result

    Else

      If StrVar1 = TestStr1 Then

        Color Magenta, Bright White

        Gosub Print_Result

      Else

        If StrVar1 = TestStr2 Then

          Color Cyan, Blue

          Gosub Print_Result

        Else

          Color Red, Bright White,1

          Print"Invalid entry!!!"

        End If

      End If

    End If

  End If

  Color Black, Bright White

Loop

Input "Try Again (y/n)",StrVar1

If StrVar1 = "y" Then

  Goto Main

End If

Print"Program STOPPED"

 

_______________________________________________________________________________________________________________

 

INSTR

 

Syntax

INSTR({Start,}String Variable1, String Variable2 or "String Expression")

 

Overview

Returns an integer specifying the start position of the first occurrence of one string within another.

 

Operators

Start - Optional. Number or Variable expression that sets the starting position for each search. If omitted, search begins at the first character position. The start index is 1-based.

String Variable1 - Required. String expression being searched.

String Variable2 or "String Expression" - Required. String expression sought. If EMPTY or NULL string, 0 is returned.

 

See Also

LEFT, MID, RIGHT, STRDUP

 

Example

Dim Keywords As String="Learning CHIP-12 is great and fun and exciting"

Dim SearchStr As String

Dim StrPos As Byte

Dim StartPos As Byte=1

 

Print "Keywords=";

Color Black,Green

Print CHR(34);Keywords;CHR(34)

Color Blue,Bright White

Print At 10,1; "1234567890123456789012345678901234567890123456"

Color Blue,Yellow

Print At 19,1; "0"

Print At 29,1; "0"

Print At 39,1; "0"

Print At 49,1; "0"

Print At 19,2; "1"

Print At 29,2; "2"

Print At 39,2; "3"

Print At 49,2; "4"

Color Black,Bright White

Dim Flag As Byte=1

Dim NumsFound As Byte=0

Do While SearchStr<>"Quit"

  Print"Enter string to search for?";

  Color Black,Green

  Input SKIPQM; SearchStr

  Color Black,Bright White

  StrPos=255

  Do Until StrPos=0

    StrPos = INSTR(StartPos,Keywords,SearchStr)

    If Flag = 1 And StrPos <> 0 Then

      Print"Found search string at following position(s):"

      Flag=0

    End If

    If StrPos <> 0 Then

      Color Blue,Yellow

      Print StrPos;" ";

      StartPos=StrPos+1

    Else

      Color Black,Bright White

      If StartPos = 1 Then

        Print "Could not find search string"

      Else

        Print

      End If

    End If

  Loop

  Flag=1

  StartPos=1

Loop

SearchStr = ""

Print"Done"

 

_______________________________________________________________________________________________________________

 

LEFT

 

Syntax

LEFT(String Variable, Length)

 

Overview

Returns a string that contains a specified number of characters from the left side of a string.

 

Operators

String Variable - Required. String expression from which the leftmost characters are returned.

Length - Required. Number or Variable expression. Numeric expression indicating how many characters to return. If zero, a zero-length string ("") is returned. If greater than or equal to the number of characters in String, the complete string is returned.

 

See Also

INSTR, MID, RIGHT, STRDUP

 

Example

Dim TestString As String = "Hello World!"

Print "TestString=";CHR(34);TestString;CHR(34)

' Prints complete string.

Print LEFT(TestString, 15)

' Prints "Hello".

Print LEFT(TestString, 5)

' Prints a zero-length string ("").

Print LEFT(TestString, 0)

 

Dim StrPos As Byte=15

TestString = LEFT(TestString, StrPos)

' Oh look it prints complete string also.

Print "TestString=";CHR(34);TestString;CHR(34)

StrPos = 5

TestString = LEFT(TestString, StrPos)

' Oh look it prints "Hello" also.

Print "TestString=";CHR(34);TestString;CHR(34)

StrPos = 0

TestString = LEFT(TestString, StrPos)

' Oh look it prints a zero-length string ("") also.

Print "TestString=";CHR(34);TestString;CHR(34)

 

 

_______________________________________________________________________________________________________________

 

LEN

 

Syntax

LEN(String Variable)

 

Overview

Returns the number of characters in a string variable.

 

Operators

String Variable - Required.

 

Example

Dim TestString As String = "Hello World"

Print "TestString = "; CHR(34); TestString; CHR(34)

' Prints 11.

Print LEN(TestString)

TestString = "Testing with variable"

Print "TestString = "; CHR(34); TestString; CHR(34)

Dim TestLen As Byte

TestLen =  LEN(TestString)

' Prints 21.

Print "TestLen = ";TestLen

 

 

_______________________________________________________________________________________________________________


 

LoadLargeFont

LoadSmallFont

 

Syntax

LoadLargeFont("FileName String" or String Variable )

LoadSmallFont("FileName String" or String Variable )

 

Overview

Loads a .FNT font file to be displayed afterwards with Print or GPrint.

If these are not used, CHIP-12 will use its default small and larger fonts.

You can only use one font at a time in alphanumeric modes 0 - 6 and the desired font must be loaded before changing the SCREEN mode. The reason for that is the VGA card uses its internal memory to display the alphanumeric font.

However, in graphics modes 7 - 9, you can display as many different fonts as you want, but if you want to switch fonts you need to load it each time.

Use LoadLargeFont() in modes 0 to 3.

Use LoadSmallFont() in modes 4 to 6.

Fonts are in Segment 8:

|       0800-0FFF = CHIP-12 8 BYTES FONTS                                   |

|       1000-1FFF = CHIP-12 16 BYTES FONTS                                  |

 

Operators

"Filename String" or String Variable  - Required. The file name must comprise of only hexadecimal numbers and must have the following format:

HH.AAA - where H is a hexadecimal digit 0 to F and AAA is an alphanumeric character A to Z and/or number 0 to 9.

 

Example 1 - Using LoadLargeFont in Alphanumeric Mode 1

Note:Some fonts don't have characters for all ASCII codes.

'The following program will display large font files

'B1.FNT to CD.FNT then F0.FNT to F5.FNT in alphanumeric mode 1.

'If the background and foreground colors are the same or too hard

'to see, press 'c' to change colors. Press any other key to display next font file.

Sub PrintMessage

  FontFile=FontFile & ".FNT"

  LoadLargeFont(FontFile)

  SCREEN 1

  Dim BackGndColour As Byte

  BackGndColour=Random(15)

  BackGndColour=BackGndColour <<SHIFT 4

  Color Black, Bright White

  Print"BackGnd=",HEX(BackGndColour);"  ForeGnd=",HEX(Colour)

  Colour=Colour Or BackGndColour

  Color(Colour)

  Dim ASCIIChar As Word

  Print FontFile

  For ASCIIChar=0 To 255

    If ASCIIChar = 10 Or ASCIIChar = 13 Then

      'Print CR or LF character code instead or performing its action

      CHIP12BEGIN

      > MOVE ML0 = @_BufferArea + #0005

      > POKE ML0 = V0D #1

      > MOVE V00 = #03 ;End of string terminator

      > POKE ML0 = V00 #0

      > MOVE ML0 = @_BufferArea + #0005

      > PRNT V03 V04

      > ADDC V03 + #01

      CHIP12END

    Else

      Print CHR(ASCIIChar);

    End If

  Next

  Dim KeyVal As Byte

  KeyVal=Inkey

End Sub

 

ResetFontNumber:

Dim FontNumber As Byte=$B1

ShowAgain:

Dim Colour As Byte

Colour=Random(14)

Colour=Colour+1

Dim FontFile As String=HEX(FontNumber)

Gosub PrintMessage

If KeyVal = $63 Then

  Goto ShowAgain

End If

FontNumber=FontNumber+1

If FontNumber = $CE Then

  FontNumber=$F0

End If

If FontNumber = $F6 Then

  Goto ResetFontNumber

End If

Goto ShowAgain

 

 

Example 2 - Using LoadSmallFont in Alphanumeric Mode 4

'The following program will display small font files

'81.FNT to 93.FNT in alphanumeric mode 4.

'If the background and foreground colors are the same or too hard

'to see, press 'c' to change colors. Press any other key to display next font file.

Sub PrintMessage

  FontFile=FontFile & ".FNT"

  LoadSmallFont(FontFile)

  SCREEN 4

  Dim BackGndColour As Byte

  BackGndColour=Random(15)

  BackGndColour=BackGndColour <<SHIFT 4

  Color Black, Bright White

  Print"BackGnd=",HEX(BackGndColour);"  ForeGnd=",HEX(Colour)

  Colour=Colour Or BackGndColour

  Color(Colour)

  Dim ASCIIChar As Word

  Print FontFile

  For ASCIIChar=0 To 255

    If ASCIIChar = 10 Or ASCIIChar = 13 Then

      'Print CR or LF character code instead or performing its action

      CHIP12BEGIN

      > MOVE ML0 = @_BufferArea + #0005

      > POKE ML0 = V0D #1

      > MOVE V00 = #03 ;End of string terminator

      > POKE ML0 = V00 #0

      > MOVE ML0 = @_BufferArea + #0005

      > PRNT V03 V04

      > ADDC V03 + #01

      CHIP12END

    Else

      Print CHR(ASCIIChar);

    End If

  Next

  Dim KeyVal As Byte

  KeyVal=Inkey

End Sub

 

ResetFontNumber:

Dim FontNumber As Byte=$81

ShowAgain:

Dim Colour As Byte

Colour=Random(14)

Colour=Colour+1

Dim FontFile As String=HEX(FontNumber)

Gosub PrintMessage

If KeyVal = $63 Then

  Goto ShowAgain

End If

FontNumber=FontNumber+1

If FontNumber = $94 Then

  Goto ResetFontNumber

End If

Goto ShowAgain

 

 

Example 3 - Using LoadLargeFont in Graphics Mode 7

'The following program will display large font files

'B1.FNT to CD.FNT then F0.FNT to F5.FNT in graphics mode 7.

'If colors are too hard to see, press 'c' to change colors.

'Press any other key to display next font file.

SCREEN 7

 

Sub PrintMessage

  FontFile=FontFile & ".FNT"

  LoadLargeFont(FontFile)

  Dim BackGndColour As Byte

  BackGndColour=Random(15)

  CLS(BackGndColour)

  Dim Colour As Byte

  Colour=BackGndColour

  Do While Colour=BackGndColour

    Colour=Random(14)

    Colour=Colour+1

  Loop

  'If background color is white then make text color blue

  If BackGndColour = 15 Then

    Color(1)

  Else

    Color(15)

  End If

  GPrint"BackGnd=",HEX(BackGndColour);"  ForeGnd=",HEX(Colour)

  Dim ASCIIChar As Word

  GPrint FontFile

  Color(Colour)

  For ASCIIChar=0 To 255

    If ASCIIChar = 10 Or ASCIIChar = 13 Then

      'Print CR or LF character code instead or performing its action

      CHIP12BEGIN

      > MOVE V0B X = V03

      > LSPL V0B = V0D ;Show Large Font

      > DISP V0B #1

      > ADDC V03 + #09

      CHIP12END

    Else

      GPrint CHR(ASCIIChar);

    End If

  Next

  Dim KeyVal As Byte

  KeyVal=Inkey

End Sub

 

ResetFontNumber:

Dim FontNumber As Byte=$B1

ShowAgain:

Dim FontFile As String=HEX(FontNumber)

Gosub PrintMessage

If KeyVal = $63 Then

  Goto ShowAgain

End If

FontNumber=FontNumber+1

If FontNumber = $CE Then

  FontNumber=$F0

End If

If FontNumber = $F6 Then

  Goto ResetFontNumber

End If

Goto ShowAgain


 

 

Example 4 - Using LoadSmallFont in Graphics Mode 7

'The following program will display small font files

'81.FNT to 93.FNT in graphics mode 7.

'If colors are too hard to see, press 'c' to change colors.

'Press any other key to display next font file.

SCREEN 7

 

Sub PrintMessage

  FontFile=FontFile & ".FNT"

  LoadSmallFont(FontFile)

  Dim BackGndColour As Byte

  BackGndColour=Random(15)

  CLS(BackGndColour)

  Dim Colour As Byte

  Colour=BackGndColour

  Do While Colour=BackGndColour

    Colour=Random(14)

    Colour=Colour+1

  Loop

  'If background color is white then make text color blue

  If BackGndColour = 15 Then

    Color(1)

  Else