Technical Manual

Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 151

Technical manual

Go back to the main site

Read this first!


Very important information about this manual

This is the technical manual for the CB2 microcomputer. It describes the more technical things related to
this computer. However, this manual describes the initial version built by Joerg Wolfram (called AVR
ChipBasic2). Since the firmware of the CB2 micro is identical to Joerg's computer, all of the things
mentioned here apply to the CB2 micro, but the CB2 micro hardware is different, so don't rely on the
information on this page on it. This manual should be used only as a reference by more skilled people
that want to learn more or experiment further with the CB2 micro.
Here is what Joerg writes:

AVR-ChipBasic2: A BASIC programmable single-chip computer with the


ATMega644
Originally designed by Joerg Wolfram

This manual is translated in English by Kostantinos Giannopoulos,


sv3ora
1 Legal
All programs are subject to the GPL (GNU General Public License) version 3 or higher, any use of the
software / information non-compliant to the GPL or outside the scope of the GPL is prohibited! This
project is distributed in the hope that it will be useful to you, but WITHOUT ANY WARRANTY, even
without the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. All
trademarks mentioned in the text are the property of their respective owners.

2 Important Notice
Binary programs, libraries and drivers must use the current API and contain the new flag structure in the
header, otherwise the system may be affected so much that it may need to be re-flashed!

3 Story
It started with the idea of using a TV set to test and debug a formula parser, as it was possible to display
several values clearly and simultaneously.
At some point in August 2006, the idea then came to integrate a BASIC interpreter with TV output into the
chip. To keep it simple I limited myself to a TINY-BASIC dialect. And so, one thing came after the other,
color output, a menu, an integrated editor and other functions. Initially, only one program in the EEPROM
memory of the ATMega16 could be accommodated, the Mega32 was already used the flash.
According to the versions for the ATMega16 and ATMega32 microcontrollers, the version for the
ATMega644 represents the logical further development with the same hardware base. Even this program
is still subject to change with later versions, with one or more features added or removed. Where
possible, the compatibility with existing programs will be maintained.

4 Features
As an input device an ordinary PS2 computer keyboard is used, as an output device, a TV with Scart
input (color) or composite video BAS input (grayscale) or various PAL/NTSC-compatible TFT displays
with RGB control.

4.1 Hardware
 30x23 characters with a maximum of 16 foreground and background colors and pseudographics
in standard mode
 PAL/NTSC and Sync signals adjustable via jumper

 8 video modes, 4 of which are full graphics, 2 custom characters and a user mode

 PS2 keyboard for input, loadable keyboard layout

 1-channel audio output (notes in 2 tones, noise) with envelope and volume adjustment
 I2C connector for optional data EEPROM, up to 8 LM75 temperature sensors or other I2C
devices

 Serial RS232 interface with 1200/2400 baud and charge pump

 Second serial interface available on ATMega644P

 Parallel printer interface, also usable as I/O and analogue inputs

 Memory expansions can be connected to the parallel port

4.2 BASIC
 Tiny-Basic programming language with extensions
 Own error handling with ONERR, periodic subroutine call with ONSYNC ...

 95 program lines with a maximum of 32 usable characters, fullscreen editor, 8 programs in the
internal flash

 Sprites in text mode, number is only limited by array

 Fast bitblock-transfer in graphics mode

 Simple sequencer running in the background

 Upload/download programs via the serial interface

 Listing print via the printer interface

 Shortcuts for abort, restart, screenshot

 Monitor with variable and stack and array-display, single-step operation

 Universal I2C control

 GOSUB with parameter transfer, RETURN with return value

 Cross-program call of subroutines possible

 Additional BASIC commands can be integrated

4.3 SYSTEM
 Own file system on ATMEL Dataflash
 Loader program for remote control via the serial interface

 X-modem file transfer for binary programs


 Automatic start of the program after switching on (deactivatable by pressing a key), program
selectable

 Extensive API for developing binary programs and libraries

 Additional video drivers can be integrated

5 Hardware and software concept


The heart of the whole project is an ATmega644, the rest of the hardware consists mainly of passive
components and connectors. Timer 1 is responsible for the video timing. Channel A operates as a PWM
and generates the line sync pulse. In CSYNC mode, during the vertical sync pulse, the PWM is
reconfigured so that the output is inverted.
Channel B of timer 1 generates the (horizontal) video interrupt. This contains a synchronization to the
timer, thereby also EEPROM read accesses with 5 clocks CPU-Stop generate no image interference.
Timer 2 generates PWM with the audio signal. This is generated either with the (pseudo) random
generator or via DDS with wavetable and envelope.
Contrary to most other solutions, the PS2 keyboard is connected to the USART of the ATMega. It is not
possible to use external interrupts because of the video timing, you can pull the clock signal to LOW
during the image display and thus make the keyboard to wait, but not every keyboard manages to send a
data packet during the blanking interval and NTSC does not work anymore, because there the blanking
interval is even shorter. The second option would be the SPI interface, but that is also occupied. And
especially during the development phase, it is annoying if you constantly have to unplug and plug in the
keyboard. The use of the USART, however, has the great advantage that everything goes automatically
and you only have to pick up the finished sign.
Of course, the question then arises "and what about serial?" With reduced bit rate (1200/2400Bps), the
serial interface can be implemented in the horizontal interrupt with two port pins. Timer output of timer 0
drives a charge pump which provides approx. -4V for the serial interface, thus no special chips (MAX232
etc.) are necessary. To save power, this function can also be switched off by software and can also be
switched to "standard level", so as to use for example a USB to RX/TX converter. Version 1.27 has also
included support for the second serial interface for the ATMega644P. By default 8 different bit rates are
adjustable. The parallel interface is implemented via port A (+2 control lines from port B). If no printer
interface is required, the 8 pins can be configured as inputs/outputs or as analog inputs. Furthermore,
driver programs can use the parallel interface, for example to control LCDs. In these cases, the "normal"
output functions of the parallel interface are disabled.

5.1 System Requirements Host for assembly


Since almost all I/O functions are provided by different libraries, assembling avr_libmake (runs only under
Linux and organizes the macros for the library functions, but it works without them) and the AVRA
assembler are necessary. The hex file should also burn on other operating systems.

5.2 Program Types


In addition to the BASIC programs, there are other program types. There are native AVR programs, which
are available in binary format. They are recognized by the fact that as 13th byte an "N" stands for native.
This "flag" can usefully not change. The second peculiarity have programs whose name begins with an
underscore. These are not remembered when saving and can therefore not start. The background to this
is having a way to create plain text files. However, these always consist of 95 lines of 32 characters,
always filled with blanks. The binary programs are then differentiated between simple programs, libraries
and drivers. The last group is the serial loader, which has an "L" as the 13th byte.

Chip8 programs can also run, as well as 8080 programs (experimental). For Chip8 programs, note that
you cannot download any Chip8 program from the internet and run it directly on the microcomputer, as it
has to be first converted into a special format for the micro to be able to run. Such a conversion program
is supplied inside the TOOLS folder, but the Chip8 programs available for download in this page, have
been already converted, so just load them to run them.
To run Chip8 programs, firstly the Chip8 emulator has to be loaded into position P2 on the microcomputer
screen and the library XMEM IRAM2 must be loaded into position P8. Run the Chip8 emulator and while
the emulator is running, press F3 to load any Chip8 program from the DFLASH into it. The Chip8
emulator can only load programs from the DFLASH, so if you do not have a DFLASH installed, you
cannot use this option.

6 Changelog
26.3.2017 Version 1.51

 Added sources for drivers/binaries

11.1.2015 Version 1.50

 Bugfix: after screenshot the menu bar was partially destroyed


 Max. 4 different system baud rates, 1200 bps is available again

 Checksum calculation in the Configpage removed for space reasons

16.6.2014 Version 1.49

 Bugfix: CTEXT often copied too many characters into the array
 New command: TLEN, determines the length of texts

 New command: TFIND, search function in texts

 Binary for the ATMega1284P

23.5.2014 Version 1.48

 Bugfix: SPISEL did not work properly


 Bugfix: Cursor keys could cause INPUT to freeze

 System interface is now configurable

 IRAM12 driver for Mega1284P


 Sample programs are again included in the BINARY package

3.1.2013 Version 1.45

 Bugfix: Multiselect extension could corrupt DataFlash file systems


 Bugfix: Source files were partially incomplete, drivers had wrong version

 Conversion of the directory tree, /usr/local/include/chipbasic2 is no longer required

13.11.2012 Version 1.44

 Multiselect extension and other behavior of SPISEL

27.4.2012 Version 1.43

 Bugfix: DIR always brought a syntax error


 Bugfix: Parallel port is now set to input with PullUp on restart

7.3.2012 Version 1.42

 Bugfix: Binary programs and libraries crashed (wrong API version)


 Bugfix: Video mode 1 did not work because of errors in jump table

 Bugfix: The starting point at PIE has been set to the top left of the origin

 Bugfix: The test program for the tilemode was faulty (wrong library calls)

 TOOLS folder added in binary package

 Fixed a few bugs in the documentation

8.10.2011 Version 1.39

 Bootloader removed for storage space reasons


 Separation of video and memory drivers

 Modification of the library and driver concept (2nd flagbyte)

 Drivers can now be located on any program slots

 External file system drivers can be integrated

 Revised LCD drivers now support additional buttons

 New libraries and programs (8080 emulator)

 New example program: Component tester

 Extended API

 Bugfix: When the EEPROM is deleted, a default configuration will be written at the first start

 Bugfix: Loader now checks the system version before starting


 Bugfix: Tokenizer could "crash" on long lines

15.1.2011 Version 1.36

 Search function in the editor


 The shift commands partially replaced by shift operators (<<, >>)

 XOR operator ^

 Support of up to 64 Kbytes of external memory at the parallel port

 Modification of the library and driver concept (coding via flagbyte)

 For the PWM drivers, BUSY and STROBE can be used as I/O

 New video drivers

 Monitor from all video modes out, but with limited functionality

 Expandability of the BASIC with additional commands

 extended ADC setting over the parameter range 0x100 ... 0x1ff

 extended bitrate setting for the second serial interface

 BIN programs are now displayed as AVR

 Corrections and extensions in the documentation

 Example programs revised

 Extended API

 New binary programs (Chip8 emulator)

 Bugfix: Alertbox masked program icons when deleting programs

 Bugfix: Baud rates for second serial interface were too low by a factor of 2

 Bugfix: In some cases the channel number was output instead of variable value during output
redirection

11.4.2010 Version 1.28

 Bugfix: SPI() and Clone did not work properly because of problems with include file
 Bugfix: Documentation contained some wrong pictures

7.4.2010 Version 1.27

 Hardware change: additional 5V on the parallel interface


 Redesign of the main menu

 Additional keyboard shortcuts in the editor

 Cursor positions are saved in the EEPROM when leaving the editor
 Only one keyboard layout table, but changeable

 Small changes in the character set

 New shift commands (LSHIFT, ASHIFT)

 Baud rate setting (BAUD)

 Screen adjustment (WRAP)

 Support of the second serial interface of the ATMega644P (EBAUD, ESPUT, ESGET)

 CALL can be abbreviated by CA.

 CALL alternatively with string as 2nd parameter

 LFIND for finding binary libraries

 Binary programs with their own symbols

 API extended (readout of keyboard status, text parser, driver functions)

 Video mode 7 removed, own driver can be loaded to program slot 8

 Loader program for remote control, independent of Autostart

 Bugfix: In some cases the wrong line was displayed for errors

 Bugfix: ACOPY can hang in an endless loop

 Bugfix: Bootloader did not work in the serial setting "standard"

5.9.2009 Version 1.10

 GOSUB with two parameters becomes CALL, because of flexible parameter lists
 GOSUB and CALL can have up to 5 parameters

 RETURN may contain a return value

 API revised and expanded

 Bugfix: Tilde sign for US keyboards was missing

27.7.2009 Version 1.03

 Added two more API functions for copying characters into the user character set
 API functions for using BASIC routines

 Bugfix in the api_dataptr function

 Programs can also be stored untoken (program name starts with underscore)

16.7.2009 Version 1.02

 New config page


 New command SCALE to convert measured values
 API revised and expanded, documentation is now complete

 PLAY now has fourth parameters to control the number of sequencer cycles

 2 bug fixes in the area, which can not be updated by the bootlaoder

 Bugfix: GOSUB in FOR/NEXT loop generated error message at RETURN

26.6.2009 Version 1.00

 3 new video modes, mode 1 has been extended


 Conversion to 16 instead of 8 colors

 More possibilities in the sound output

 ONSYNC for the time-controlled calling of subroutines

 Support for native AVR applications, API is implemented

 Drawing functions for circular and elliptic segments

 A few new features

 Line ends (send serially) are configurable

 Serial interface can be switched to "standard level"

 Autostart function now configurable, no autorun jumper required

 Free spaces filled in the character set

 Keyboard test when switching on

 Revised documentation

 REPEAT-UNTIL grinding

8.1.2009 Version 0.89

 Lots of bugfixes (Many thanks to Wolfgang Gunther for testing)


 Array view in the debugger

 Clone function should work well with Mega644P

 Troubleshooting interplay with keyboards (US layout)

 Bugfix "IO DISABLED" when accessing IO port

 Conversion program for screenshots received in text mode

21.12.2008 Version 0.87

 Bugfixes, redundancies removed


 Improved tokenizer, higher speed at runtime

 Data EEPROM address can be set


 Serial 1200 and 2400Bps adjustable

 Configuration of I2C and SPI speed

 Data transmission on binary level via X-modem

 Bootloader for upcoming updates

 Native (binary) programs are prepared, API is still missing

 MENU function for custom menus at the bottom of the screen

 Array write accesses are only possible via DATA

 EMIT and YEMIT have been discontinued (can be realized via PRINT)

 RREAD/RWRITE for direct access to the dataflash

 Revised documentation

 New video modem (128x64 monochrome) compatible with the AVR handheld computer

 Second font (6x4) in the graphics modes

28.04.2008 Bugfix-Version (0.75)

 Revision of the file structure in the project directory


 A few adjustments to the AVRASM32

 For 16-bit write accesses to the array, 2x the LOW byte was written

 Dataflash-Delete no longer displays a selection box

 EEPROM writes sometimes failed

 Palette was partially set wrong

 RND(n) only generated random numbers between 0 and n/2

 Changed video timing, therefore quieter picture

 Intro Screen

 Instead of LPIX and LCHAR there is now SCROLL in text mode

 Access to the SPI interface also from the BASIC

 Revised documentation

 A few new example programs

16.02.2008 Third Public Mega644 Version (0.72)

 A few bugfixes
 Clear and Copy for programs
 SIN() and COS() now only work with whole degrees as arguments

 Revised documentation and website

 A few example programs

31.01.2008 Second public Mega644 version (0.69)

 A few bugfixes
 New sprite routines

 Background note sequencer

14.01.2008 First public Mega644 version (0.65)

 A few features are not fully tested yet


 Sample programs are still missing

AVR-ChipBasic2: Hardware

1 Minimal hardware

1.1 Black and white BAS (composite video) version


For a minimal wiring a breadboard or a veroboard is sufficient. Only the connectors do not fit in most
cases. For problems with the keyboard, it is recommended to provide a pullup resistor of approx. 4.7K for
the clock (PB0) and data line (PD0).
1.2 Color version (SCART)
However, this can only output a grayscale image. For color on the TV you need either a CVBS encoder or
a Scart connection. The latter is the simpler solution and can be easily implemented. The 180 ohm
resistor on pin 18 of the Scart connector tells the TV to use the RGB inputs. For some TVs with multiple
scart inputs, RGB only goes at the first one, in which case only one grayscale image is displayed when
using a different scart input.
1.3 The universal version
To be more flexible, a 9-pin SUB-D socket was chosen as the video connector on the board. A grayscale
BAS, a Scart, a CVBS encoder or a PAL/NTSC compatible TFT can be connected here. Port 9 of the
socket should only be used when using the CPLD-CVBS encoder, otherwise picture framing may occur.
For the same reason, no longer lines may be connected to this connection.
In order to be able to develop adapters yourself, it is important to know the assignment of the 9-pin SUB-
D socket:

connection signal
1 Video blue
2 Video red
3 Video green
4 VSYNC
5 HSYNC / CSYNC
6 + 5V
7 Audio
8 Video BAS
9 Clock Sync
casing GND (0V)
2 Video adapters for the universal connection

2.1 BAS signal


Simply connect the cables for the BAS signal (optional: audio) and ground. The main drawback is that the
display is only in black and white (grayscale).

2.2 SCART connection


The 180 ohm resistor on pin 18 of the Scart connector tells the TV again that it should use the RGB
inputs. For some TVs with multiple scart inputs, RGB only goes at the first one, in which case only one
grayscale image is displayed when using a different scart input. The blue scart connector in the image, is
shown as seen from the TV side (female connector on the TV chassis).
2.3 TFT display
The example shows an example of the connection of NTSC TFT displays, as they are partly used or
available as spare parts. The wiring is only a minimal variant, in particular, any protection of the display is
missing before signal failures. In fact, the HSYNC signal is critical. If it fails (eg when flashing the
microcontroller via the ISP interface or if the 5V supply fails), permanent damage to the display can occur.
3 The interfaces
In addition to keyboard, video and ISP/SPI, AVR-ChipBasic has three additional interfaces to
communicate with the "outside world".

3.1 The serial interface


Since the USART is already used for the keyboard connection, the serial interface is implemented in
software. Due to the system, the TX (transmission) line can only be updated once per screen line. This
results in the rather low speed of only 1200 or 2400 bps. Unlike other solutions, no extra interface IC is
needed. A timer output forms with two Schottky diodes and two capacitors a charge pump, which
generates approx. -4 V. This is connected to the TX connection via a resistor. If a "0" is to be output, the
output of the microcontroller switches a PNP transistor. As a result, the TX connection now has 5V (-
Vcesat).
At the receiving end, the input voltage is limited to 0..5V by means of a series resistor and two Schottky
diodes. The signal at the port pin is negated thereby, since the interpretation is done in software this does
not pose a problem.
Alternatively, the signal levels can also be configured (configuration page) so that a "normal" interface
converter (eg MAX232) can be connected.

3.2 The second serial interface (only ATMega644P)


As of version 1.25, the second serial interface of the ATMega644P can also be used. For example, level
converters or a MIDI interface can be connected here. However, this interface can not be used as a
system interface. Please note that the input signal of the system interface is now connected to PD1 (pin
15) and not to PD3 (pin 17). Unfortunately, this change has become necessary to use the second UART
of the ATMega644P. The configuration page can be used to switch between the two pin variants,
whereby the second serial interface can only be used if the input of the first is on PD1. Of course, this
wiring can also be used with the ATMega644.

3.3 The parallel interface


With the parallel interface not only printers can be controlled, but also digital signals can be output and
input. In addition, analog voltages in the range 0-5V can be measured. The two control signals (Strobe
and Busy) can not be controlled directly from the BASIC but are only needed to connect printers. At pin
16 (/INIT), the internal +5V voltage can be led out, so that small I/O circuits can be fed from the internal
power supply. All data signals are routed to the outside via resistors for current limitation in the event of a
short circuit.

3.4 The I2C interface


The I2C interface uses the TWI interface in the Mega644. This is identical to I2C, but is different for
licensing reasons.
The signal exchange takes place via two lines, SCL (Serial Clock) and SDA (Serial Data). In addition,
serial EEPROMs, temperature sensors, etc. can be connected. To ensure that the connected peripherals
do not always require an extra power supply, +5V and GND is also available on the I2C connector on the
board.
Also on the board are two 8-pin sockets for serial EEPROMs type 24C64 ... 24C512 where addresses 0
and 1 are pre-wired. The used address can be set in the configuration menu, whereby XPOKE and
XPEEK only work with the default address.

3.5 The SPI interface


The SPI interface is identical to the programming interface (ISP) to which the Dataflash module is also
connected. As of version 1.38, it is possible to connect up to 8 devices to the SPI port. This requires the
following hardware:
The functionality is the following:

 The 8-bit register (eg HCT374) will be wired to work as an 8 bit shift register with tristate output.
 As long as CS=HIGH, CS0...CS7 are high-impedance and are pulled to HIGH via the pull-ups.

 SPI data output during CS=HIGH will end up in the "shift register" U1.

 If now CS goes LOW, the outputs of the register serve as CS0 to CS7 and select the desired
device
The output CS0 is reserved for the data flash, the output CS1 for the clone program. The remaining 6
outputs can be used for own purposes. For the selection there is the command SPISEL and the
corresponding API functions.

4 An example circuit board layout

4.1 The example layout


Although the circuit is so simple that it can easily be mounted on a breadboard or a breadboard or strip
PCB, a compact assembly is quite useful for the permanent operation and to add extensions. The PCB is
designed as an 8-color version for universal connection and works with both the Mega16 (AVR-
ChipBasic) and the Mega32 (AVR-ChipBasic32) and of course with the Mega644 (AVR-ChipBasic2), the
first two use 16MHz Quartz instead of the Mega644 that uses 20MHz quartz. The layout was created with
the program "PCB", the corresponding file can be found in the folder hardware, as well as a PNG file with
300dpi resolution. Of course, everyone is free to make their own PCB layout.

4.2 Assembly of the printed circuit board


The circuit board contains only DIP components with a few exceptions, which are not mandatory for it to
function. The SMD capacitors and the 4K7 resistor for the RESET line, however, improve the stability and
should, if possible, installed. In addition, there is a simple voltage regulator on the board for the 5V, so
that the supply voltage can be approximately between 6.5 and 15V. At voltages higher than 9V and when
connecting additional hardware, we recommend a cooling plate or heat sink for the voltage regulator
(7805).
4.3 The extension to 16 colors
The original printed circuit board was/is designed universally for 8 colors, since the versions with the
Mega16 and the Mega32 as well as older ChipBasic2 versions do not know the 16-color mode. Also the
commercially available printed circuit board is designed in the current version only on 8 colors. With 4
additional resistors, the module can be easily upgraded to 16 colors, the corresponding points are already
marked violet on the PCB. The 10KOhm resistance from point (A) to +5V has no effect on the function
and does not need to be removed. Please note the connection of the 6.8K in the PCB is different than that
in the schematic. Either way will work, but the PCB connection is recommended.
--- (A note from Kostas) Translated text verified
correctly up to this point ---
You can always download Joerg's manual in German to compare with.

AVR-ChipBasic2: Internals

1 Organization of the video memory

1.1 differences in 8 and 16 colors


The I (intensity) bits are only relevant if the 16-color extension is connected. The somewhat unusual
distribution of the bits (intensity as LSB) is due to the compatibility with the 8-color mode of the "normal"
hardware.

1.2 video mode 0 (standard mode)

This mode is a text mode with a fixed character set of 256 characters. Each character can be
assigned separately foreground and background color. There are 23 lines of 30 characters, this is
simply because the project was partly developed with a 37 cm TV set with a fairly large margin.
The image memory contains one after the other:

start address end address bytes function


0 689 690 character
690 1379 690 attributes
1380 2759 1380 Backup for monitor
For the pseudographic, the characters 0 ... 15 are divided into 4 "pixels". With 23 lines of 30 characters
this results in a working area of 60x46 points.

1.3 Video mode 1

The pixel resolution is 168x116 pixels, whereby for each 8x8 (at the bottom only 4x8) pixels
foreground and background color can be adjusted.

start address end address bytes function


0 2435 2436 pixel information
2436 2750 315 attributes
2751 2759 9 unused
The pixel bytes are organized from left to right as well as from top to bottom. Within the byte, bit 0
corresponds to the left-most pixel.

1.4 video mode 2

The pixel resolution is 120x76 pixels, each pixel can accept one of 4 colors that can be adjusted
via the palette.

start address end address bytes function


0 2279 2280 pixel information
2280 2759 480 unused
The pixel bytes are organized from left to right as well as from top to bottom. Within the byte, bits 0 and 1
correspond to the leftmost pixel. Each pixel is represented by two bits pointing to one of the first 4 palette
entries. The pallet entry then determines the color.

1.5 video mode 3

The pixel resolution is 84x58 pixels, each pixel can have one of 16 colors that can be adjusted
via the palette.

start address end address bytes function


0 2435 2436 pixel information
2436 2759 324 unused

The pixel bytes are organized from left to right as well as from top to bottom. Each byte is divided into 2 4-
bit nibbles pointing to one of the 16 palette entries. The pallet entry then determines the color.
1.6 video mode 4

This mode is a text mode with variable character set of 128 characters. Each character can be
assigned separately foreground and background color. When switching to video mode, the lower
128 characters are copied from the fixed character set to the variable character set. The image
memory contains one after the other:

start address end address bytes function


0 689 690 character
690 1379 690 attributes
1448 2727 1280 character set
2728 2759 32 unused
In the character set, the bytes are arranged according to character lines, ie 128 bytes for the first
character line, then 128 bytes for the second character line ...
The pixels within a character line are still differentially stored, bit 7 is the pixel on the left, bit 6 is "0", the
next pixel has the same color, with a "1" it changes. One byte results in a character line of 6 pixels, with
bits 0 and 1 ignored, one character consists of 10 of these character lines.

1.7 Video Mode 5

The pixel resolution is 128x64 pixels, each pixel can assume one of 2 colors that can be set via
the palette. This mode is mainly used to emulate graphics LCD with the appropriate resolution.

start address end address bytes function


0 1023 1024 pixel information
1024 2759 1736 Backup for monitor

The pixel bytes are organized from left to right as well as from top to bottom. Within the byte, bit 0
corresponds to the left-most pixel. For each pixel, there is just one bit pointing to one of the first two
palette entries. The pallet entry then determines the color.
1.8 video mode 6

This mode is a variable character text mode of 64 characters. Each pixel in each character can be
assigned one of the 8 colors. When switching to video mode, the lower characters are copied
from the fixed character set to the variable character set. The image memory contains one after
the other:

start address end address bytes function


0 689 690 character
690 2609 1920 character set
2610 2759 150 unused

In the character set, the 30 bytes of each character lie directly behind each other. Each pixel is
represented by three bits, within the byte bits 1 ... 3 correspond to the right and bits 5 ... 7 to the left pixel.
Three bytes result in a character line of 6 pixels, one character consists of 10 of these character lines.
1.9 Video Mode 7
Video mode 7 has been removed in the current version. Instead, a separate driver can be installed on
program slot 8. For video drivers, the ID range 0xc0 to 0xdf is reserved in the HIGH byte. If no such ID
exists, a VMODE 7 only causes a constant error. For binary programs, however, care must be taken to
ensure that a suitable driver is installed.

2 The API for binary programs


2.1 General
Hmmm ..., API - what is it? API is the abbreviation for "Application Programming Interface" and is used in
this case to run native (eg with an assembler generated) binary programs on the ChipBasic2 computer.

2.2 Possibilities and limitations


There is first the program size. This is limited to 3072 bytes, whereby even at the beginning of the memory area 12
bytes for the program name, 1 byte for the distinction to BASIC programs (in binary programs always "N") and 19
more bytes for eg the program icon are reserved.
So that the programs still function after an update of the system, direct subprogram calls (without detouring through
the API functions) should be avoided. Likewise, the information functions should be used to query the addresses of
certain memory areas, instead of working with the current addresses. In addition, it does not make sense to work
with JMP or CALL within the program since the program address varies depending on the program location.
Unfortunately, this does not make it easy to access eg tables included in the source code. However, this is possible
via the API:

.include "M644Pdef.inc"
.include "api.inc"
.org 0x4000
start: .db "TestprogrammN",0xec,0xff,0xff
.db "+--+"
.db "ABCD"
.db "+--+"
.org 0x4010
lese: call api_getvram ;setzt Y auf den Anfang des Bildspeichers
ldi XL,LOW(daten-start) ;Bestimmung des Offsets
ldi XH,HIGH(daten-start)
call api_dataptr ;setzt Z auf die Adresse von "daten:"
call api_orom ;ROM-Text ab (Z) ausgeben
ret
daten: .db "Mein Text",0
At the beginning there must be 12 bytes of program name and an "N" (0x4E) followed by 3 bytes for
different flags and library / driver number. This is followed by 12 bytes for the program icon. The actual
program starts with an offset of 32 bytes (16 words). Instead of calling the API functions via CALL or JMP
, it is more convenient to use the macros. However, they do not work correctly with all assemblers (only
tested with AVRA):

.include "M644Pdef.inc"
.include "api_macros.inc"
.org 0x4000
start: .db "TestprogrammN",0xec,0xff,0xff
.db "+--+"
.db "ABCD"
.db "+--+"
.org 0x4010
lese: api_getvram ;setzt Y auf den Anfang des Bildspeichers
ldi XL,LOW(daten-start) ;Bestimmung des Offsets
ldi XH,HIGH(daten-start)
api_dataptr ;setzt Z auf die Adresse von "daten:"
api_orom ;ROM-Text ab (Z) ausgeben
ret
daten: .db "Mein Text",0
But the code generated with the assembler is ultimately the same.

2.3 The flags in the header


Byte 13 of the header contains several flags and the foreground color of the icon.

bit Surname function

7 --- currently not used

6 UPAR 0 = driver uses parallel port

5 ISLIB 0 = program is a library

4 EXEC 0 = Program can be started from the main menu

3 ... 0 ICOL ICON foreground color

The ICON foreground color can theoretically use any of the 16 values, but for clarity and consistency
within the system, the following mapping should be maintained when developing new programs:

color code colour file type

0000 black not used (invisible)

x001 blue not used (lack of contrast)

X010 red Reserved for loader

x011 magenta Default for drivers

x100 green Default for libraries


x101 cyan Default for binary programs

x110 yellow Reserved for non-bootable BASIC programs (text)

x111 White Reserved for BASIC programs

Here are some examples of useful byte combinations:

Type flag byte program type

"B" 0xF7 dates

"N" 0xE5 binary

"N" 0xd4 Binary library

"N" 0xf3 driver

"N" 0xB3 Driver, uses parallel port

"L" 0xF2 Loader

Byte 14 contains another 8 flags. These stand for various extensions. If a program or a library offers one
or more extensions, the corresponding bit is set to 0. At system startup and when a program is loaded or
unloaded, the flag bytes of all programs are read in and the program is stored in a table with the last
occurrence. This table can then be used to call the functions. If there is no corresponding extension in
memory, the corresponding byte = 0xff, otherwise it corresponds to the high address in words of the last
program with active flag. If, for example, there are video drivers on program locations 4 and 6, table entry
0 contains the value 0x66 for the start address of program position 6. The API function api_getprg sets
the Y register at the beginning of the table. If the content of the program memory (program 1-8) is
modified from a binary program, the function api_extdisable should be called first. This blocks the
external functions that are called cyclically (video output, sound, frame) to prevent program calls to invalid
routines from being executed. Then, the table must be refreshed with a call to api_extsearch .
The assignment of the bits is shown in the following table, the bit number corresponds to the offset at the
same time as the beginning of the table:

bit function

7 Not occupied
6 Program contains a font

5 Program contains a file system driver

4 Program contains drivers for external / internal memory

3 Program contains BASIC extension

2 Program contains sound routines

1 Program contains cyclic routine called in every frame

0 Program contains video drivers

Byte 15 contains the library number. For programs that do not provide a library function, this should be set
to 0xff. The BASIC command LFIND can then be used to determine whether the library you are looking
for is in memory.

2.4 Examples of program headers


The following examples contain program headers for different program types. If programs, libraries or
drivers provide additional functions, the associated bits in flag byte 2 must be deleted.

2.4.1 Program header of simple binary programs


Binary programs are normally started from the main menu, alternatively a start via XCALL P, n is also possible,
where P stands for the program position 1 ... 8 and n is not evaluated.

WORD BYTE Length


function
Offset offset (bytes)

0x00 0x00 12 program name

--- 0x0c 1 "N" as identifier for binary programs

--- 0x0d 1 Flagbyte 1, usually 0xe5

--- 0x0e 1 Flagbyte 2, usually 0xff


--- 0x0f 1 Library number, should be 0xff

0x08 0x10 12 Icon data

0x0e 0x1c 2 can be used arbitrarily

0x0f 0x1e 2 can be used arbitrarily

0x10 0x20 2 Start the program

2.4.2 Program header of binary libraries


The individual functions of binary libraries are started from the BASIC, either numeric parameters or a string can be
passed. How the parameter transfer takes place is determined by the T flag. If it has been deleted, numerical
parameters have been passed. If the T flag is set, the address of the string in Y is in RAM. The end of the string is
marked either by "Gansefusschen" (0x22) or by 0xff.

WORD BYTE Length


function
Offset offset (bytes)

0x00 0x00 12 program name

--- 0x0c 1 "N" as identifier for binary programs

--- 0x0d 1 Flag byte 1 = 0xd4

--- 0x0e 1 Flagbyte 2 = 0xff or additional functions

--- 0x0f 1 library number

0x08 0x10 12 Icon data

0x0e 0x1c 2 can be used arbitrarily

0x0f 0x1e 2 can be used arbitrarily

0x10 0x20 2 Jump to the routine Nr.0

0x11 0x22 2 Jump to the routine Nr.1


0x12 0x24 2 Jump to routine no.2, further routines up to 119 possible

2.4.3 Program header of BASIC extensions


The BASIC can be supplemented with BASIC extensions with own commands. If an external command (begins
with underscore) is detected then the parser routine is called.

WORD BYTE Length


function
Offset offset (bytes)

0x00 0x00 12 program name

--- 0x0c 1 "N" as identifier for binary programs

--- 0x0d 1 Flagbyte 1 = 0xf4

--- 0x0e 1 Flag byte 2 = 0xf7

--- 0x0f 1 library number

0x08 0x10 12 Icon data

0x0e 0x1c 2 should be 0xffff

0x0f 0x1e 2 should be 0xffff

0x10 0x20 2 (Jump to) parser routine

0x11 0x22 2 Jump to the routine Nr.1

0x12 0x24 2 Jump to routine no.2, further routines up to 119 possible

2.4.4 Program Header of Video Drivers


Unused routines should be terminated with a RET.
WORD BYTE Length
function
Offset offset (bytes)

0x00 0x00 12 program name

--- 0x0c 1 "N" as identifier for binary programs

--- 0x0d 1 Flag byte 1 = 0xd3

--- 0x0e 1 Flag byte 2 = 0xfe

--- 0x0f 1 library number

0x08 0x10 12 Icon data

0x0e 0x1c 2 Jump to IN expansion or R24 (ereg) set to 40

0x0f 0x1e 2 Jump to OUT expansion or R24 (ereg) set to 40

0x10 0x20 2 Jump to the (demo) application if program can be started

Jump to INIT video mode (T flag set) or EXIT video mode (T


0x11 0x22 2
flag cleared)

0x12 0x24 2 Jump to the CLS routine

0x13 0x26 2 Jump to the character output, characters in R20

0x14 0x28 2 Jump to the routine to set cursor position to XH: XL

0x15 0x2a 2 Jump to the plot XH: XL

Jump to the newline routine, cursor to the beginning of the


0x16 0x2c 2
next line

0x17 0x2e 2 Jump to the video output routine

0x18 0x30 2 Jump to init routine at system startup

0x19 0x32 2 Jump to routine # 9, can go to 119


2.4.5 XMEM extensions
By means of memory extensions, the usable memory can be increased. A maximum of 64 kilobytes of additional
memory is possible, which is displayed page by page in the array cells 768 ... 1023. Bit 4 must be deleted in the
flagbyte.

WORD BYTE Length


function
Offset offset (bytes)

Jump to the array READ routine (Page / R20 = pointer, XL =


0x19 0x32 2
data)

Jump to array WRITE routine (Page / R20 = pointer, XL =


0x1a 0x34 2
data)

0x1b 0x36 2 Jump to byte READ routine (X +) -> r18

0x1c 0x38 2 Jump to byte WRITE routine r18 -> (X +)

0x1d 0x3a 2 Jump to the Word-READ routine (X +) -> r19 / r18

0x1e 0x3c 2 Jump to Word-WRITE routine r19 / r18 -> (X +)

Jump to the XMEM-CHEXK routine (X = address of the last


0x1f 0x3E 2
memory cell or 0 if no XMEM exists)

Jump to the XMEM-CLEAR routine (describes complete


0x20 0x40 2
XMEM with 0x00)

0x21 0x42 2 Jump to routine No.17, can go to 119

2.4.6 Frame Interrupts


Using the frame interrupt extension, a custom routine at the bottom of the colored border (Border) can be called. An
application example would be, for example, the query of a real-time clock or the sampling of DCF77 signals. In flag
byte 2 bit 1 must be deleted.

WORD BYTE Length function


Offset offset (bytes)

0x21 0x42 2 Jump to the frame-INT routine

2.4.7 SOUND extensions


By means of sound extensions, the sound output can be adjusted within certain limits to your own needs. So own
tables can be used for tone generation and the volume calculation can be modified. In flag byte 2 bit 2 must be
deleted.

WORD BYTE Length


function
Offset offset (bytes)

0x22 0x44 2 Jump to Envelope Routine (at the end of the frame)

0x23 0x46 2 Jump to the notes routine

2.5 Transfer of parameters and results


In order to write extensions for the BASIC, the transfer parameters and the result value can be accessed. This is done
with the function api_getvalues , which returns a pointer to the following structure in the Y-register:

offset format content

0 INTEGER Return value of the function

2 INTEGER Call parameter 1

4 INTEGER Call parameter 2

6 INTEGER Call parameter 3


8 INTEGER Call parameter 4

10 INTEGER Call parameter 5

Number of transferred
12 BYTE
parameters

The parameter values are only valid if the T flag is cleared (numerical parameters), but the return value
can be used in both cases.

2.6 Address range for I / O extensions


To make I / O extensions as universal as possible, standardization is necessary, at least for the most important
address ranges. The present table is only a minimal basis and will probably need to be supplemented over time. All
drivers must return the value 40 (0x28) in register R24 (ereg) for address ranges which they do not serve.

start address end address meaning

0x800 0x809 Level of usable output pins when I / O is disabled (0/1)

Data direction of the usable output pins when I / O is disabled


0x810 0x819
(0/1)

0x900 0xbff Driver specific I / O

0x0c00 0xffff currently not used

2.7 Build process for creating your own application


Creating a binary program is a bit different from the "normal" approach. The following list describes the
procedure under Linux and will be limited or will not work under other operating systems. The necessary
include files for the programs and libraries I have created are expected in the directory / usr / local /
include / chipbasic2 , if necessary, the path must be adapted.
The following steps are necessary to create a binary file:

1. Creation of the program


2. Assembly with AVRA

3. Conversion to binary format with hex2bin

4. Control that the binary file is a maximum of 3072 bytes in size

5. Creation of any file which, together with the binary file from the previous step, is exactly 3072
bytes long

6. Attach the created file to the binary file

7. The file created in step 5 can now be deleted again

To avoid having to do this manually each time, there is a small build script that does a lot of the work. It is
called with build-bin name , where name stands for the ASM file (without .asm).
After completion, there should be a file name.bin in the directory, which can then be transferred to the
AVR computer via XModem.

3 Directory of API functions

3.1 Structure of the function table

Function name Name of the API function, also corresponds to the macro call

Call without macro Calling the function when working without macros

function Description Brief description of the function

Parameter Register assignment to the parameters

Return values Register assignment to the return values

Register Registers whose content is changed (except return values)

Video modes in which the function is useful. If this table row is


Video Modes
missing, the function is applicable in all video modes.

In addition to the specified registers, registers R0 and R1 and error register R24 are partially overwritten
by the API functions.
3.2 Backing up and restoring registers

function name api_pushxyz

Call without macro call api_pushxyz

function Description saves the registers X, Y and Z on the stack

parameter ---

return values ---

register R0, R1

function name api_popxyz

Call without macro jmp api_popxyz

function Description gets the registers X, Y and Z from the stack and executes a RET

parameter ---

return values ---

register X, Y, Z

function name api_pushregs


Call without macro call api_pushregs

function Description saves the registers X, Y and Z as well as R20-R23 on the stack

parameter ---

return values ---

register R0, R1

function name api_popxyz

Call without macro jmp api_popregs

gets the registers X, Y and Z as well as R20-R23 from the stack


function Description
and executes a RET

parameter ---

return values ---

register X, Y, Z, R20, R21, R22, R23

function name api_pushregs


Call without macro call api_pushregs
function Description saves the registers X, Y and Z as well as R20-R23 on the stack
parameter ---
return values ---
register R0, R1

function name api_popxyz


Call without macro jmp api_popregs
gets the registers X, Y and Z as well as R20-R23 from the stack
function Description
and executes a RET
parameter ---
return values ---
register X, Y, Z, R20, R21, R22, R23

3.3 Calculation functions

All calculation functions (except the square root) refer to signed 16-bit numbers. The X-register
forms a kind of "accumulator", as a second operand the register pair R16 / R17 is used. R24 is
either 0 (no error) after the operation or contains an error code. The error codes correspond to
those in the BASIC program.

function name api_add


Call without macro call api_add
function Description X = X + R16 / R17
parameter X, R16, R17
return values X
register R18

function name api_sub


Call without macro call api_sub
function Description X = X - R16 / R17
parameter X, R16, R17
return values X
register R16 / R17 = -R16 / R17

function name api_mul


Call without macro call api_mul
function Description X = X * R16 / R17
parameter X, R16, R17
return values X
register R16 ... R21
function name api_div
Call without macro call api_div
function Description X = X / R16 / R17
parameter X, R16, R17
return values X = quotient, R18 / R19 = remainder
register R20, R21

function name api_sin


Call without macro call api_sin
function Description X = 256 * SIN (X)
parameter X (in degrees)
return values X
register Z, R16, R17

function name api_cos


Call without macro call api_cos
function Description X = 256 * COS (X)
parameter X (in degrees)
return values X
register Z, R16, R17

function name api_eq


Call without macro call api_eq
function Description returns 1 if X == R16 / R17, otherwise 0
parameter X, R16, R17
return values X
register ---
function name api_gt
Call without macro call api_gt
function Description returns 1 if X> R16 / R17, otherwise 0
parameter X, R16, R17
return values X
register ---

function name api_lt


Call without macro call api_lt
function Description returns 1 if X <R16 / R17, otherwise 0
parameter X, R16, R17
return values X
register ---

function name api_sqr


Call without macro call api_sqr
function Description returns the square root of X, in this case X is unsigned
parameter X
return values X
register R16, R17, R18, R19

function name api_abs


Call without macro call api_abs
function Description returns the absolute value of X
parameter X
return values X
register ---
function name api_rnd
Call without macro call api_rnd
function Description returns a random number between 0 and X-1
parameter X
return values X
register R16 ... R19

function name api_dbit


Call without macro call api_dbit
calculates bit patterns for fonts in video mode 4, corresponds to
function Description
the DBIT () function in BASIC
parameter X
return values X
register ---

function name api_adc


Call without macro call api_adc
function Description starts the ADC and returns the ADC value.
parameter X = channel (0 ... 7)
return values X = ADC value
register ---

function name api_scale


Call without macro call api_scale
function Description scaling function
parameter The parameters are in the range defined with api_getpartab
return values R16 / R17 = result
register R4-R7, R18, R19

The function corresponds to the SCALE command in BASIC. Is calculated

Y = Y0 + ((Y1 - Y0) * (X - X0) / (X1 - X0))


The parameters are consecutively in the parameter area of the interpreter, which can be
determined by api_getpartab , whereby always first the LSB and then the MSB is in the
memory. The order of the parameters is defined as follows:

offset parameter
0 Y0
2 Y1
4 X0
6 X
8th X1

3.4 Program control


function name api_sync
Call without macro call api_sync
waiting for the end of the currently displayed field (lower edge of
function Description
the used area)
parameter ---
return values ---
register ---

function name api_fast


Call without macro call api_fast
function Description turns off the picture output
parameter ---
return values ---
register ---

function name api_slow


Call without macro call api_slow
function Description turns on the picture output
parameter ---
return values ---
register ---

function name api_wpage


Call without macro call api_wpage
function Description writes a flash page
parameter Y = RAM address, Z = flash address
return values ---
register R20 ... R23, X, Y, Z

3.5 Information functions


function name api_version
Call without macro call api_version
function Description determines the API version
parameter ---
return values R20 = API version (currently 6)
register ---

function name api_getvram


Call without macro call api_getvram
function Description determines the start address of the image memory
parameter ---
return values Y points to the beginning of the image memory
register ---

function name api_getsysram


Call without macro call api_getsysram
function Description determines the start address of the system memory
parameter ---
return values Y points to the beginning of the system memory
register ---

function name api_getpal


Call without macro call api_getpal
function Description determines the start address of the pallet memory
parameter ---
return values Y points to the beginning of the pallet memory
register ---

function name api_getarray


Call without macro call api_getarray
function Description determines the start address of the array
parameter ---
return values Y points to the beginning of the array
register ---

function name api_getvar


Call without macro call api_getvar
function Description determines the start address of the BASIC variable
parameter ---
return values Y points to the beginning of the BASIC variable (variable "A")
register ---

function name api_getprg


Call without macro call api_getprg
function Description determines the start address of the program assignment
parameter ---
return values Y points to the beginning of the assignment table (Word)
register ---

The assignment table consists of 8 values. These are assigned to 8 possible functionalities. If at
least one program / driver / library offers the functionality, the HIGH address is the
corresponding memory cell. The address refers to 16-bit values, so the value can be used directly
in the ZH register for jumps and subprogram calls. If a functionality is not offered, the value 0 is
in the corresponding memory cell

function name api_getvalues


Call without macro call api_getvalues
function Description determines the start address of the function parameter block
parameter ---
return values Y points to the beginning of the block
register ---

function name api_getpartab


Call without macro call api_getpartab
function Description determines the start address of the (internal) parameter block
parameter ---
return values Y points to the beginning of the block
register ---

function name api_getchart0


Call without macro call api_getchart0
determines the starting address of the character table for font 0 in
function Description
Flash
parameter ---
return values Z points to the beginning of the character table for font 0
register ---

function name api_getchart1


Call without macro call api_getchart1
determines the starting address of the character map for font 1 in
function Description
Flash
parameter ---
return values Z points to the beginning of the character map for font 1
register ---

function name api_getbuffer


Call without macro call api_getbuffer
function Description determines the start address of the two BASIC buffers
parameter ---
return values Y points to the beginning of the two memory areas
register ---

 The BASIC buffer area consists of two buffers a 40 bytes. The first area is the text buffer, which
contains eg the text entered at INPUT. It also serves as a source buffer for the api_token and
api_untoken routines.
 The second area is the code buffer for the BASIC. On the one hand, the BASIC lines are
interpreted from this memory area, on the other hand it serves as a code buffer for the api_token
and api_untoken routines.

function name api_getprog


Call without macro call api_getprog
function Description determines the number of the calling program in Flash
parameter ---
return values ZL = program number (0 ... 7)
register ZH

function name api_getbase


Call without macro call api_getbase
function Description determines the start address of the calling program in Flash
parameter ---
return values Z points to the beginning of the calling program
register ---

function name api_dataptr


Call without macro call api_dataptr
function Description determines the address of a data block in the calling program
parameter X = offset
Z points to the absolute address of a data block in the calling
return values
program
register ---

function name api_drvcode


Call without macro call api_drvcode
function Description determines the flagbyte and drivercode of a loaded driver
parameter ---
return values R20 = flagbyte, R21 = drivercode
register ---

 3.6 Keyboard
function name api_waitkey
Call without macro call api_waitkey
function Description waits for a keystroke (except SHIFT, CTRL, ALT)
parameter ---
return values R20 = Keycode of the pressed key
register ---

function name api_nokey


Call without macro call api_nokey
function Description waits until no key is pressed (except SHIFT, CTRL, ALT)
parameter ---
return values ---
register ---

function name api_kstate


Call without macro call api_kstate
function Description returns the current state of the SHIFT, CTRL and ALT keys
parameter ---
R20 (Bit0 = LSHIFT, Bit1 = RSHIFT, Bit2 = LCTRL, Bit3 =
return values
RCTRL, Bit4 = ALT)
register ---

function name api_keycode


Call without macro call api_keycode
returns the keycode of the key being pressed or 0x00 (no key
function Description
pressed)
parameter ---
return values R20 = Keycode
register ---

function name api_lastkey


Call without macro call api_lastkey
returns the keycode of the last pressed key or 0x00 (no key
function Description
pressed yet)
parameter ---
return values R20 = Keycode
register ---

function name api_scancode


Call without macro call api_scancode
function Description returns the scan code of the last key pressed
parameter ---
return values R20 = scan code
register ---

 3.7 screen output


function name api_clrscr
Call without macro call api_clrscr
function Description clears the screen with the current color setting
parameter ---
return values ---
register R20
Video Modes 0 ... 6

function name api_clearvec


Call without macro call api_clearvec
function Description deletes the vector area in graphic mode 7
parameter ---
return values ---
register ---
Video Modes 7

function name api_cleartext


Call without macro call api_cleartext
deletes the text area in graphic mode 7 with the current color
function Description
setting
parameter ---
return values ---
register ---
Video Modes 7

function name api_gotoxy


Call without macro call api_gotoxy
function Description sets the position of the text cursor (also in the graphics modes)
parameter XL = X position, XH = Y position, in the graphics modes as pixel
position
return values ---
In text mode, XL and XH are limited to the maximum screen
register
coordinates
Video Modes all

For the output functions, R25 determines the mode, the values are explained in more
detail in the PRINT command. Similarly, the channel set determines where to go.

function name api_outchar


Call without macro call api_outchar
function Description gives a sign
parameter R20 = character, R25 = mode
return values ---
register R20, R21
Video Modes all

function name api_newline


Call without macro call api_newline
function Description returns a line feed
parameter ---
return values ---
register R20, R21
Video Modes 0, 4, 6

function name api_outdez


Call without macro call api_outdez
function Description outputs the contents of X decimal (-32768 ... 32767)
parameter X = 16-bit value, R25 = mode / format
return values ---
register R20, R21
Video Modes all

function name api_outhex
Call without macro call api_outhex
function Description outputs the contents of X hexadecimal (00 ... FF or 0000 ... FFFF)
parameter X = 16-bit value, R25 = mode / format
return values ---
register R20, R21
Video Modes all

function name api_romtext


Call without macro call api_romtext
function Description returns a null-terminated string from the flash
parameter Z = Pointer to the string in Flash
return values ---
register Z, R20, R21
Video Modes all

function name api_thistext


Call without macro call api_thistext
returns a null-terminated string from the Flash that immediately
function Description
follows the call.
If the first byte is 0xFF, the string to be output directly follows,
parameter otherwise the first byte is evaluated as the Y coordinate and the
second as the X coordinate before the actual string follows.
return values ---
register Z, R20, R21
Video Modes all

function name api_cbox


Call without macro call api_cbox
function Description Deletes a rectangular area with the set color
parameter YL = X1, YH = Y1, ZL = X2, ZH = Y2
return values ---
register ---
Video Modes 0, 1, 4

function name api_ibox


Call without macro call api_ibox
Inverts a rectangular area (exchanges foreground with
function Description
background color)
parameter YL = X1, YH = Y1, ZL = X2, ZH = Y2
return values ---
register ---
Video Modes 0, 1, 4

function name api_scroll


Call without macro call api_scroll
function Description Scrolls the inner screen area, see SCROLL command
parameter R20 = direction (0 = up, 1 = to the right, 2 = down, 3 = to the left)
return values ---
register ---
Video Modes 0, 4, 6

function name api_sprite


Call without macro call api_sprite
function Description represents a sprite (see BASIC Reference)
parameter XL = X, XH = Y, Y = pointer to sprite data
return values ---
register ---
Video Modes 0, 4, 6

function name api_copychar4


Call without macro call api_copychar4
copies a character from the system character set into the user
function Description
character set for video mode 4
parameter R20 = system character, R21 = user character (0 ... 127)
return values ---
register ---
Video Modes 4

function name api_copychar6


Call without macro call api_copychar6
copies a character from the system character set into the user
function Description
character set for video mode 6
R20 = system character, R21 = user character (0 ... 63), R22 =
parameter
VG / HG color
return values ---
register ---
Video Modes 6

function name api_sbackup


Call without macro call api_sbackup
function Description copies the visible screen area to the monitor backup screen
parameter ---
return values ---
register R20, X, Y, Z
Video Modes only useful at 1 and 5

function name api_srestore


Call without macro call api_srestore
function Description copies the monitor backup screen to the visible screen area
parameter ---
return values ---
register R20, X, Y, Z
Video Modes only useful at 1 and 5
3.8 graphic

function name api_plot


Call without macro call api_plot
function Description Draws a point in the set foreground color
parameter XL = X, XH = Y
return values ---
register ---
Video Modes 0, 1, 2, 3, (4), 5

function name api_draw


Call without macro call api_draw
function Description Draws a line in the set foreground color
parameter YL = X1, YH = Y1, ZL = X2, ZH = Y2
return values ---
register ---
Video Modes 0, 1, 2, 3, (4), 5

function name api_box


Call without macro call api_box
function Description Draws a rectangle in the foreground color
parameter YL = X1, YH = Y1, ZL = X2, ZH = Y2
return values ---
register ---
Video Modes 0, 1, 2, 3, (4), 5

function name api_fbox


Call without macro call api_fbox
function Description Draws a filled rectangle in the set foreground color
parameter YL = X1, YH = Y1, ZL = X2, ZH = Y2
return values ---
register ---
Video Modes 0, 1, 2, 3, (4), 5

function name api_circle


Call without macro call api_circle
function Description Draw a circle / ellipse in the set foreground color
parameter YL = X, YH = Y, ZL = RX, ZH = RY
return values ---
register ---
Video Modes 0, 1, 2, 3, (4), 5

function name api_fcircle


Call without macro call api_fcircle
function Description Draw a filled circle in the set foreground color
parameter YL = X, YH = Y, ZL = RX, ZH = RY
return values ---
register ---
Video Modes 0, 1, 2, 3, (4), 5

function name api_bcopy1


Call without macro call api_bcopy1
function Description Copies a screen section to another location
YL = SRCX, YH = SRCY, ZL = DESTX, ZH = DESTY, R21 =
parameter
bytes / line, R22 = lines
return values ---
register R4ldotsR7
Video Modes 1, 2, 3, 5

function name api_bcopy2


Call without macro call api_bcopy2
function Description Copies a screen section from the image memory to the RAM
YL = SRCX, YH = SRCY, Z = RAM address, R21 = bytes / line,
parameter
R22 = lines
return values ---
register R4ldotsR7
Video Modes 1, 2, 3, 5

function name api_bcopy3


Call without macro call api_bcopy3
function Description Copies a screen section RAM into the image memory
parameter YL = DESTX, YH = DESTY, Z = RAM address
return values ---
register R4ldotsR7
Video Modes 1, 2, 3, 5

3.9 communication
function name api_putpar
Call without macro call api_putpar
function Description Outputs a character via the parallel interface
parameter R20 = characters
return values ---
register ---

function name api_getser


Call without macro call api_getser
function Description waits for a character from the serial interface, no abort option
parameter ---
return values R20 = characters
register ---
function name api_getserb
Call without macro call api_getserb
waiting for a character from the serial interface, abort with ESC
function Description
possible
parameter ---
return values R20 = character or 0x1B (if canceled with ESC)
register ---

function name api_putser


Call without macro call api_putser
function Description Outputs a character via the serial interface
parameter R20 = characters
return values ---
register ---

function name api_putsernl


Call without macro call api_putsernl
function Description outputs a line feed via the serial interface
parameter ---
return values ---
register Y = Y + 128

function name api_hexline


Call without macro call api_hexline
outputs a memory area as a hex string with a final line feed via
function Description
the serial interface
parameter Y = address RAM block, ZL = number of bytes
return values ---
register ZL, R20, Y = Y + 128
function name api_putxm
Call without macro call api_putxm
function Description outputs an X-Modem block via the serial interface
parameter R22 = block number, Y = address RAM block
return values ---
register Y = Y + 128

function name api_getxm


Call without macro call api_getxm
function Description reads in an X-Modem block via the serial interface
parameter Y = address RAM block
return values R22 = block number
register Y = Y + 128

function name api_preceive


Call without macro call api_preceive
function Description loads a program (in binary mode) via the X-Modem protocol
parameter R15 = program number 1 (0 ... 7]
return values
register R20 ... R23, X, Y, Z

function name api_psend


Call without macro call api_psend
function Description sends a program (in binary mode) via the X-modem protocol
parameter R15 = program number 1 (0 ... 7]
return values
register R20 ... R23, X, Y, Z

3.10 Audio
function name api_note
Call without macro call api_note
function Description Plays a note at the current volume
parameter XL = note value, according to the BASIC command note
return values ---
register ---

function name api_setvolume


Call without macro call api_setvolume
function Description sets the global volume
parameter XL = volume value (0 ... 15)
return values ---
register ---

function name api_startseq


Call without macro call api_startseq
function Description starts the sequencer
parameter ---
Y = start address (RAM), Z = end address + 1 (RAM), XL =
return values
speed, XH = number of cycles
register ---

function name api_setseq


Call without macro call api_setseq
function Description sets the cyclic error of the sequencer
parameter XL = new cycle value
return values ---
register ---

function name api_getseq


Call without macro call api_getseq
function Description reads the cyclic error of the sequencer
parameter XL = current cycle value
return values ---
register ---

3.11 Access to the internal EEPROM

The functions for the internal EEPROM only work with the memory cells 0 ... 2047, if the
address (Y-register) is outside this range, the error register (R24) is set to 34. Since the memory
cells are used from 2040 for system settings, they should not be overwritten if possible.
Before each write, the EEPROM cell is read, if the setpoint and actual state already match, the
write process is aborted.

function name api_eep_read


Call without macro call api_eep_read
function Description reads a byte from the internal EEPROM
parameter Y = Address
return values R20 = Byte
register Y=Y+1

function name api_eep_write


Call without macro call api_eep_write
function Description writes a byte to the internal EEPROM
parameter Y = address, R20 = byte
return values ---
register Y=Y+1

3.12 Functions for the I2C bus

The I2C bus can only be used as master via the API functions.

function name api_i2c_start


Call without macro call api_i2c_start
function Description creates a start condition on the I2C bus
parameter ---
return values ---
register R20

function name api_i2c_stop


Call without macro call api_i2c_stop
function Description creates a stop condition on the I2C bus
parameter ---
return values ---
register R20

function name api_i2c_rbyte


Call without macro call api_i2c_rbyte
function Description reads a byte from the I2C bus and sends an ACK
parameter ---
return values R21 = byte, R22 = I2C status register
register R20

function name api_i2c_rbyten


Call without macro call api_i2c_rbyten
function Description reads a byte from the I2C bus without sending an ACK
parameter ---
return values R21 = byte, R22 = I2C status register
register R20

function name api_i2c_wbyte


Call without macro call api_i2c_wbyte
function Description sends a byte to the I2C bus and waits for ACK / NAK
parameter R21 = Byte
return values R22 = I2C status register
register R20

function name api_i2c_read


Call without macro call api_i2c_read
function Description reads in a data byte from an external EEPROM
X = memory address in EEPROM, R23 = EEPROM address (0 ...
parameter
7)
return values R21 = byte R24 = error status
register X = X + 1, R20, R22

function name api_i2c_write


Call without macro call api_i2c_write
function Description writes a byte of data to an external EEPROM
R21 = byte X = memory address in EEPROM, R23 = EEPROM
parameter
address (0 ... 7)
return values R24 = Error Status
register X = X + 1, R20, R22

function name api_i2c_rlm75


Call without macro call api_i2c_rlm75
reads the temperature value from a connected LM75 temperature
function Description
sensor
parameter R23 = LM75 address (0 ... 7)
return values R24 = error status, X = temperature value in 1/2 degree
register R20, R21, R22

3.13 Alert and query boxes

function name api_alert


Call without macro call api_alert
function Description outputs an alert box, after ENTER the screen is restored
parameter Y points to color byte (FG / HG) and zero-terminated text in RAM
return values ---
register R20

function name api_alert_nb


Call without macro call api_alert_nb
function Description outputs an alert box, after ENTER the screen is NOT restored
parameter Y points to color byte (FG / HG) and zero-terminated text in RAM
return values ---
register R20

function name api_alertthis


Call without macro call api_alertthis
function Description outputs an alert box, after ENTER the screen is restored
parameter the color byte and the text are null terminated after the call
return values ---
register R20

function name api_alertthis_nb


Call without macro call api_alertthis_nb
function Description outputs an alert box, after ENTER the screen is NOT restored
parameter the color byte and the text are null terminated after the call
return values ---
register R20

function name api_ask


Call without macro call api_ask
outputs a question box, after Y / N / ENTER / ESC the screen is
function Description
restored
parameter Y points to color byte (FG / HG) and zero-terminated text in RAM
return values T flag is set at Y / ENTER
register R20

function name api_ask_nb


Call without macro call api_ask_nb
outputs a question box, after Y / N / ENTER / ESC the screen is
function Description
NOT restored
parameter Y points to color byte (FG / HG) and zero-terminated text in RAM
return values T flag is set at Y / ENTER
register R20

function name api_askthis


Call without macro call api_askthis
outputs a question box, after Y / N / ENTER / ESC the screen is
function Description
restored
parameter the color byte and the text are null terminated after the call
return values T flag is set at Y / ENTER
register R20

function name api_askthis_nb


Call without macro call api_askthis_nb
outputs a question box, after Y / N / ENTER / ESC the screen is
function Description
NOT restored
parameter the color byte and the text are null terminated after the call
return values T flag is set at Y / ENTER
register R20

3.14 Accessing the Dataflash File System


function name api_fs_size
Call without macro call api_fs_size
function Description determines the size of the connected Dataflash module
parameter ---
return values R20 = (number of sectors / 256) or 0
register ---

function name api_fs_create


Call without macro call api_fs_create
function Description creates a file
parameter R20 = file number, R21 = number of sectors, R22 = file type
return values R24 (error code or 0)
register Array (512-767)

function name api_fs_delete


Call without macro call api_fs_delete
function Description deletes a file
parameter R20 = file number
return values R24 (error code or 0)
register ---

function name api_fs_read


Call without macro call api_fs_read
function Description reads a file sector into an area of the array
parameter R20 = file number, R21 = sector number, R22 = array third (0,1,2)
return values R24 (error code or 0)
register ---

function name api_fs_write


Call without macro call api_fs_write
function Description writes a file sector from an area of the array
parameter R20 = file number, R21 = sector number, R22 = array third (0,1,2)
return values R24 (error code or 0)
register ---

function name api_fs_cfree


Call without macro call api_fs_cfree
function Description Counts the free program slots and data sectors
parameter ---
return values Z = free program slots, Y = free data sectors
register ---

function name api_fs_checkf


Call without macro call api_fs_checkf
function Description determines if the Dataflash module is formatted
parameter ---
return values R20 (1 = formatted, otherwise 0)
register ---

function name api_fs_gettype


Call without macro call api_fs_gettype
function Description determines the file type of a file
parameter R20 = file number
return values R20 = File Type Code
register ---

function name api_fs_fsize


Call without macro call api_fs_fsize
determines the size of a file (in pages) or the free space on the
function Description
Dataflash module
parameter X = file number or -1 (free files) or -2 (free pages)
return values X = number of pages / files
register YZ

function name api_fs_ffind


Call without macro call api_fs_ffind
function Description searches for a file
parameter X = Arrayposition (see FFIND function)
return values X = file number or -1
register YZ

function name api_fs_check


Call without macro call api_fs_check
function Description tests the dataflash for a valid file system
parameter
return values
register R20

This function is used to prepare the file selector box and set the necessary internal variables. If an
error occurs then the return address is removed from the stack and jumped back to the address of
the previous call after displaying an appropriate alert box. For this reason it makes sense, for
example, to load load and memory functions together with the file selector box calls in their own
subroutine. In the case of errors, this is then simply left and jumped back to the higher-level
program.

function name api_fs_fsel


Call without macro call api_fs_fsel
function Description calls the Fileselectorbox (only in video mode 0)
parameter the header is null terminated after the call
return values R23 = file number, R20 = file type
register ---

If the file selection is aborted by pressing the ESC key, the file type returned in R20 is 0xed.
function name api_fs_fsel_nb
Call without macro call api_fs_fsel_nb
calls the Fileselectorbox without screen backup (only in video
function Description
mode 0)
parameter the header is null terminated after the call
return values R23 = file number, R20 = file type
register ---

If the file selection is aborted by pressing the ESC key, the file type returned in R20 is 0xed.
3.15 Direct Access to the Dataflash

function name api_fs_rread


Call without macro call api_fs_rread
function Description reads a sector from the dataflash
parameter X = sector number, Y = address in RAM
return values R24 (error code or 0)
register Y = Y + 256

function name api_fs_rwrite


Call without macro call api_fs_rwritw
function Description writes a sector in the dataflash
parameter X = sector number, Y = address in RAM
return values R24 (error code or 0)
register Y = Y + 256

3.16 BASIC / SYSTEM functions


function name api_lfind
Call without macro call api_lfind
function Description searches the system for a library
parameter X = library code
return values R21 = program slot (1 ... 8) or 0 for not found
register Z, R22-R23
function name api_lcall
Call without macro call api_lcall
function Description Invokes a function in a Libarary
parameter R20 = library (1 ... 8), R21 = function number
return values possibly from called function
register Z, R0, R1 and registers of the function call

function name api_token


Call without macro call api_token
function Description tokenizes a line from the source buffer into the code buffer
parameter Source text in the source buffer
return values tokenized line in the code buffer
register X, Y, Z, R20-R23

function name api_untoken


Call without macro call api_untoken
function Description translates a tokenized line back into the source code
parameter tokenized line in the code buffer
return values Source text in the source buffer
register X, Y, Z, R20 ... R23

function name api_basrun


Call without macro call api_basrun
function Description executes the line in the code buffer
parameter R12 = line number, R13 = first statement, line in the code buffer
return values ---
register X, Y, Z, R4 ... R7, R20 ... R23
function name api_exparser
Call without macro call api_exparser
function Description interprets a formula in text format
parameter Z = Pointer to function text
return values X = result (16 bit signed)
register Y, Z, R4 ... R7, R20 ... R23

function name api_tparser


Call without macro call api_tparser
function Description provides a token parser
Z = pointer to token table in flash, Y = pointer to text in RAM, R22
parameter
= length of an entry in bytes
return values R20 = found token or 0
register Y stands behind the found text

The token table always contains the token value first, followed by the token text, which is filled
with dots. Finally, an entry should only consist of points, which then intercepts invalid words.
The function can also be called several times in succession, as a separator the space and the
comma can be used.
In the following example, the length of an entry would be 6 bytes (1 byte token value and 5 bytes
of text):
tokentab:
.db 0x01,"LOAD."
.db 0x02,"ADD .."
.db 0x03,"SUB .."
.db 0x00,"....."

function name api_arrview


Call without macro call api_arrview
function Description Array View
parameter R23 = display position (* 64)
return values ---
register ---

This feature is only useful in video mode 0.


3.17 Using video mode 0

The following functions are used to use program routines of video mode 0 in their own drivers.

function name api_vm0cls


Call without macro jmp api_vm0cls
function Description jumps to the CLS routine of video mode 0
parameter usable only in drivers
return values ---
register ---

function name api_vm0char


Call without macro jmp api_vm0char
function Description jumps to the character output routine of video mode 0
parameter usable only in drivers
return values ---
register ---

function name api_vm0gotoxy


Call without macro jmp api_vm0gotoxy
function Description jumps to the positioning routine of video mode 0
parameter usable only in drivers
return values ---
register ---

function name api_vm0plot


Call without macro jmp api_vm0plot
function Description jumps to pixel network routine of video mode 0
parameter usable only in drivers
return values ---
register ---
function name api_vm0line
Call without macro jmp api_vm0line
function Description outputs a pixel line in video mode 0
parameter usable only in drivers
return values ---
register ---

function name api_vm0newline


Call without macro jmp api_vm0newline
function Description outputs a line feed in video mode 0.
parameter usable only in drivers
return values ---
register ---

3.18 Array Functions

These functions can use both the internal array and external memory. If the corresponding array
cell can not be addressed, error 18 (OUT OF ARRAY) is returned in the error register.

function name api_aread


Call without macro call api_aread
function Description reads a ByteWord from the array
parameter Y = Arraypointer
return values XL / X = content of the array cell
register R21

function name api_awrite


Call without macro call api_awrite
function Description writes a byte / word into the array
parameter Y = Arraypointer, XL / X = value to be written
return values ---
register R21

function name api_pageset


Call without macro call api_pageset
function Description sets the array page for external storage
parameter XL = new array page (after system startup 0)
return values ---
register ---

AVR-ChipBasic2 - libraries

1 The fixed-point library FIXLIB (library code 0x10)

1.1 General
This library extends the BASIC computer with fixed-point calculations. Fixed-point means that the
positions before and after the comma are fixed. With this library, the number of digits can be set via the
initialization command. Internally, a representation is selected that combines 2 digits each (value range
0 ... 99) in one byte. Thus, before and after decimal places are adjustable only in 2-steps.

 2 ... 32 pre-comma and 0 ... 30 decimal places selectable


 Number of available variables depends on the number of digits

 Occupies the array area 256 ... 511

 Formatted text output

 Input via text in the array possible

 Integer data exchange with the BASIC system

 4 basic calculations, comparisons and other functions


Due to the system, only parameters that have been specified have a defined value. With a CALL L, 2.0
only the parameter 1 is defined, but the parameter 2 necessary for the function is not. Thus, variable 0 is
assigned the value that is currently in RAM at this point.

1.2 Function overview

function number function

0 Dummy function if the library is called from the main menu

1 initialization

2 Integer assignment variable = value

3 Assignment via text string in the array

4 returns integer value of the variable

5 Text output of the variable

6 Absolute value of a variable

7 Inverse value (0 variable)

8 Addition V3 = V1 + V2

9 Subtracking V3 = V1 - V2

10 Multiplication V3 = V1 * V2

11 Division V3 = V1 / V2

12 Constant assignment with predefined constants

13 Pre-comma portion of a variable (INT)

14 Fractional part of a variable (FRAC)

15 Comparison of two variables

16 Copy variable

17 Variable / 2

18 Variable * 2
19 Start script in the array memory

1.2.1 Function 0: Dummy


This is a dummy function that returns only 0 if the library is called from the main menu.

parameter meaning

Parameter 1 ---

Parameter 2 ---

Parameter 3 ---

return value 0

1.2.2 Function 1: Initialization


This function must be called before all other functions in order to carry out the necessary initializations. The return
value corresponds to the number of variables that have been set up and depends on the number of digits before and
after the decimal point.

parameter meaning

Parameter 1 Number of pre-bytes bytes - 1 (0 ... 15)

Parameter 2 Number of decimal bytes

Parameter 3 ---

return value Number of initialized variables


1.2.3 Function 2: Value assignment of integer value
Sets a variable to an integer value. The decimal places are set to 0

parameter meaning

Parameter 1 variable number

Parameter 2 variable value

Parameter 3 ---

return value 0

1.2.4 Function 3: Value assignment of text string


Sets a variable to a value defined by a text string in the array. The comma as well as the dot can be used as separator
between pre-comma and decimal places. The first non-numeric character in the string terminates the conversion.

parameter meaning

Parameter 1 variable number

Parameter 2 Text start in the array

Parameter 3 ---

return value 0

1.2.5 Function 4: Integer value of the variables


Returns the integer value of the variable. It is rounded according to the decimal places.

parameter meaning
Parameter 1 variable number

Parameter 2 ---

Parameter 3 ---

return value Integer value of the variable

1.2.6 Function 5: Text output of the variables


Returns the contents of the variable as a text string. By specifying a minimum of the occurrence bytes, a right-
justified representation can be effected. If the number of maximum post-decimal bytes is smaller than that of the
variables, it is rounded accordingly.

parameter meaning

Parameter 1 variable number

Parameter 2 Bit 7 ... 4: minimum precom-byte -1 bit 3 ... 0: post-decimal byte

Parameter 3 (optional output channel)

return value 0

1.2.7 Function 6: Absolute value of a variable


The absolute value of variable 1 is stored in variable 2. V2 = ABS (V1)

parameter meaning

Parameter 1 Variable number of variable 1

Parameter 2 Variable number of variable 2

Parameter 3 ---
return value 0

1.2.8 Function 7: Inverse value of a variable


The inverse value of variable 1 is stored in variable 2. V2 = -V1

parameter meaning

Parameter 1 Variable number of variable 1

Parameter 2 Variable number of variable 2

Parameter 3 ---

return value 0

1.2.9 Function 8: Addition


The sum of variable 1 and variable 2 is stored in variable 3. V3 = V1 + V2

parameter meaning

Parameter 1 Variable number of variable 1

Parameter 2 Variable number of variable 2

Parameter 3 Variable number of variable 3

return value 0

1.2.10 Function 9: Subtraction


The difference between variable 1 and variable 2 is stored in variable 3. V3 = V1 - V2
parameter meaning

Parameter 1 Variable number of variable 1

Parameter 2 Variable number of variable 2

Parameter 3 Variable number of variable 3

return value 0

1.2.11 Function 10: Multiplication


The product of variable 1 and variable 2 is stored in variable 3. V3 = V1 * V2

parameter meaning

Parameter 1 Variable number of variable 1

Parameter 2 Variable number of variable 2

Parameter 3 Variable number of variable 3

return value 0

1.2.12 Function 11: Division


The quotient of variable 1 and variable 2 is stored in variable 3. V3 = V1 / V2

parameter meaning

Parameter 1 Variable number of variable 1

Parameter 2 Variable number of variable 2


Parameter 3 Variable number of variable 3

return value 0

1.2.13 Function 12: Constant assignment


For 8 predefined constants, the value assignment can be simplified using this function.

parameter meaning

Parameter 1 variable number

Parameter 2 Constant number (0 ... 7)

Parameter 3 ---

return value 0

The 8 constants have 15 valid decimal places and are defined as follows:

constant number value

0 0

1 1

2 PI

3 e (Euler number)

4 ln (2)

5 ln (10)

6 SQRT (2)
7 SQRT (3)

1.2.14 Function 13: Pre-comma part of a variable


The precomport part of variable 1 is stored in variable 2. Strictly speaking, only the decimal bytes are set to 0 V2 =
INT (V1)

parameter meaning

Parameter 1 Variable number of variable 1

Parameter 2 Variable number of variable 2

Parameter 3 ---

return value 0

1.2.15 Function 14: Decimal portion of a variable


The precomport part of variable 1 is stored in variable 2. Strictly speaking, only the pre -ommand bytes are set to 0
V2 = FRAC (V1)

parameter meaning

Parameter 1 Variable number of variable 1

Parameter 2 Variable number of variable 2

Parameter 3 ---

return value 0
1.2.16 Function 15: Comparison of two variables
Variable 1 is compared with variable 2. If variable 1 is greater than variable 2, then the return value is 1, if variable
1 is smaller than variable 2, the result is 2 and if both variables are equal, 0 is returned.

parameter meaning

Parameter 1 Variable number of variable 1

Parameter 2 Variable number of variable 2

Parameter 3 ---

return value Comparison result (1,0,2)

1.2.17 Function 16: Copy variable


Variable 1 is copied to variable 2.

parameter meaning

Parameter 1 Variable number of variable 1

Parameter 2 Variable number of variable 2

Parameter 3 ---

return value 0

1.2.18 Function 17: Multiplication by 2


Variable 1 is multiplied by 2 by bit shifting and the result is stored in variable 2. This function is much faster than a
corresponding multiplication. V2 = V1 * 2

parameter meaning
Parameter 1 Variable number of variable 1

Parameter 2 Variable number of variable 2

Parameter 3 ---

return value 0

1.2.19 Function 18: Division by 2


Variable 1 is divided by 2 by bit shifting and the result is stored in variable 2. This feature is much faster than a
corresponding division. V2 = V1 / 2

parameter meaning

Parameter 1 Variable number of variable 1

Parameter 2 Variable number of variable 2

Parameter 3 ---

return value 0

1.2.20 Function 19: Starting a script in the array


Since the library essentially only provides the basic arithmetic operations, there is a small script engine with which
even more complex functions can be calculated relatively easily. To do this, the code must be in the first third of the
array (cells 0 ... 255).

parameter meaning

Parameter 1 Start address in the array

Parameter 2 opt. Parameter 1


Parameter 3 opt. Parameter 2

Parameter 4 opt. Parameter 3

return value Return value, depending on the exit command

For loops, etc., four 8-bit counter variables are available. Each command consists of 2 bytes, which are
still divided into nibbles. An x indicates that the value of the corresponding nibble is not evaluated.
Nevertheless, it makes sense to set these nibbles to 0. For loops, etc., there are four 8-bit counter
variables available. When starting a script, the first three are pre-assigned the LOW bytes of parameters 1
... 3, Countervariable 4 is set to 0. Due to the system, only parameters that have been specified have a
defined value. With a CALL 7,19,17 only parameter 1 is set to 17, parameters 2 and 3 are undefined.

code meaning

000V End script, variable value (integer) of variable v is returned

01xM End script, the value of Counter M is returned

0 2 nn E is jumped to the script position nn

0 3 CV Variable V is initialized with the constant C

04xV Variable V is initialized with the value of optional parameter 1

05xV Variable V is initialized with the value of optional parameter 2

06xV Variable V is initialized with the value of optional parameter 3

1 0 WV W=V

1 1 WV W = ABS (V)

1 2 WV W = -V

1 3 WV W = INT (V)

1 4 WV W = FRAC (V)
1 5 WV W=V*2

1 6 WV W=V/2

1 8 WV skips the next statement if V is equal to W.

1 9 WV skips the next statement if V is not equal to W.

1 AWV skips the next statement if V is greater than W.

1 BWV skips the next statement if V is less than W.

4 UWV W=U+V

5 UWV W=U-V

6 UWV W=U*V

7 UWV W=U/V

8 mnn the counter M is set to nn

9 mnn to the counter M nn is added

AM nn skips the next statement if the counter M is equal to nn

BM nn skips the next statement if the counter M is not nn

CM xn Counter M is initialized with parameter N.

other codes No function (NOP)

1.3 A fractal program as an example


In lines 7 to 10, the coordinates for X1, X2, Y1 and Y2 are entered.
PROGRAM :Fractal 2
01 LFIND L,16:A=120:B=76
02 IF L=0 ? "keine Matlib":END
03 A=120:B=76:C=4:VM 2:VID 0
04 Z=80:PAL 0,0,1,5,7
05 CALL L,1,1,3:CALL L,2,16,4
06 'Koordinatenvorgaben
07 DA 0,"-0.95#":CALL L,3,0,0
08 DA 0,"-0.72#":CALL L,3,1,0
09 DA 0,"0.17#":CALL L,3,2,0
10 DA 0,"0.33#":CALL L,3,3,0
11
12 'DX(V4) und DY(V5) berechnen
13 CALL L,2,6,A
14 CALL L,9,1,0,7:CALL L,11,7,6,4
15 CALL L,2,6,B
16 CALL L,9,3,2,7:CALL L,11,7,6,5
17 CALL L,16,0,15
18 TSET 0
19 FOR Y=0 TO B-1:FOR X=0 TO A-1
20 CALL L,12,8,0:CALL L,12,9,0
21 I=0
22 CALL L,10,8,8,10:'X^2
23 CALL L,10,9,9,11:'Y^2
24 CALL L,8,10,11,6:CALL L,15,6,16
25 R=~R:IF R=1 GOTO 34
26 CALL L,9,10,11,13:'XT
27 CALL L,8,0,13,13
28 CALL L,10,8,9,14:'YT
29 CALL L,17,14,14:CALL L,8,2,14,14
30 CALL L,16,13,8:CALL L,16,14,9
31 'Iteration zu ende
32 I=I+1:IF I<Z GOTO 22
33 PLOT Y,X,0:GOTO 35
34 D=I%(C-1):PLOT Y,X,D+1
35 IF KEY(0)=$F5 THEN VID 0
36 IF KEY(0)=$F6 THEN VID 1
37 CALL L,8,0,4,0:NEXT
38 CALL L,8,2,5,2
39 CALL L,16,15,0:NEXT
40 TGET S
41 ? @0,0;(S-T)/10;"s ":VID 1
42 GOTO 41
#

2 The measuring routines library MEASLIB (library
code 0x12)

2.1 General
This library extends the BASIC computer with measuring routines for resistors, diodes, capacitors and
inductors in different measuring ranges. The following measuring ranges are achieved with the circuit
below:

 Resistance measuring range from 5 ohms to 1 MOhm


 Diode flux voltage up to 4,88V, maximum current 5mA

 Capacity measuring range from 100pF to 1000uF

 Inductance measuring range from 20uH to 800mH

 Space for your own measurement program

2.2 Required hardware


Even if the required hardware is rather minimalistic, without it is unfortunately not possible. Only the four
lower pins of Port A are used, so that at the same time an LCD module can be connected to the display.
The necessary connection circuit is limited to two resistors and two Schottky diodes to protect the port
pins. In the following, the pins are referred to as PA.0 to PA.3. If the whole thing is to be set up directly
(without ChipBasic board), additional 180 ohm resistors should be connected in series to the four port
pins.
2.3 Function overview

function number function

0 Start of the demonstration program (currently not used)

1 PA.1 to HIGH, voltage measurement to PA.0 and PA.1

2 PA.2 to HIGH, voltage measurement to PA.0 and PA.2

3 PA.3 to HIGH, voltage measurement to PA.0 and PA.3

4 PA.3 from LOW to HIGH, time measurement to U (PA.0)> Uref (resolution 300ns)

5 PA.3 from LOW to HIGH, time measurement to U (PA.0)> Uref (resolution 500ns)

6 PA.2 from LOW to HIGH, time measurement to U (PA.0)> Uref (resolution 300ns)

7 PA.2 from LOW to HIGH, time measurement to U (PA.0)> Uref (resolution 64us)

8 PA.1 from LOW to HIGH, time measurement to U (PA.0) <Uref (resolution 300ns)

9 PA.1 from LOW to HIGH, time measurement to U (PA.0) <Uref (resolution 500ns)

10 PA.2 from LOW to HIGH, time measurement to U (PA.0) <Uref (resolution 500ns)
11 PA.3 from LOW to HIGH, time measurement to U (PA.0) <Uref (resolution 300ns)

2.3.1 Function 0: Demo


Starts the built-in demonstration program. In the current version, this only consists of a "RET"

parameter meaning

Parameter 1 ---

Parameter 2 ---

Parameter 3 ---

return value 0

2.3.2 Function 1: PA.1 to HIGH, voltage measurement to PA.0 and PA.1


Sets the port pins of port A and performs measurements with the ADC on pins PA.0 and PA.1. To
improve the accuracy, the results of each 32 individual measurements are added up. With the example
circuit, it is possible to measure resistances of approx. 5 ohms to 5 K ohms with acceptable accuracy.
The process is as follows:

 The pins PA.0, PA.2 and PA.3 are switched as input without pullup, PA.1 as output with HIGH
level
 Measure voltage at pin PA.1 with AVCC as reference 32 times and total the values

 Measure voltage at pin PA.0 with AVCC as reference 32 times and total the values

 Set PA.1 to LOW level

The return value is the measured value of PA.0, the measured value of PA.1 is stored in the array cell 1024.

parameter meaning

Parameter 1 ---

Parameter 2 ---
Parameter 3 ---

return value 32 x measured value of PA.0, measured value of PA.1 in AR (1024)

2.3.3 Function 2: PA.2 to HIGH, voltage measurement to PA.0 and PA.2


This function corresponds to function 1 with the difference that, instead of pin PA.2, here pin PA.2 is used
as the source and AR (1024) is the measured value of pin PA.2.

2.3.4 Function 3: PA.3 to HIGH, voltage measurement to PA.0 and PA.3


This function corresponds to function 1 with the difference that instead of pin PA.2 here the pin PA.3 is
used as the source and in AR (1024) is the measured value of pin PA.3.

2.3.5 Function 4: PA.3 from LOW to HIGH, time measurement to U (PA.0)> Uref
(resolution 300ns)
Pin PA.0 is connected to the analog comparator, the reference voltage is the internal bandgap reference
source with approx. 1.1 volts. Pin PA.3 is switched from 0 to 1 and the time is measured until the voltage
at PA.0 is greater than the voltage of the reference voltage source. The time resolution is 300ns, the
maximum measuring range is 60 microseconds. 16 measurements are taken every 20ms and the values
are added up. The maximum value returned is thus 3200. The procedure is as follows:

 The pins PA.0, PA.1 and PA.2 are switched as input without pullup, PA.3 as output with LOW
level
 Set PA.3 to HIGH and set the time until the voltage at PA.0> Uref.

 Stop the measurement after 60 microseconds and set PA.3 to LOW level

 Repeat 15 times

Return value is the sum of the individual time measurements.

parameter meaning

Parameter 1 ---

Parameter 2 ---

Parameter 3 ---
return value 16 x measured value (in 300 nanosecond steps)

2.3.6 Function 5: PA.3 from LOW to HIGH, time measurement to U (PA.0)> Uref
(resolution 500ns)
This function corresponds to function 4, but with a different time resolution and a larger measuring range.
The time resolution is 500ns, the maximum measuring range is 6.4 milliseconds. 16 measurements are
taken every 20ms and the values are added up. Finally, the result is divided by 8. The maximum returned
value is therefore 25600. The process is as follows:

 The pins PA.0, PA.1 and PA.2 are switched as input without pullup, PA.3 as output with LOW
level
 Set PA.3 to HIGH and set the time until the voltage at PA.0> Uref.

 After 6.4 milliseconds, stop the measurement and set PA.3 to LOW level

 Repeat 15 times, add up the readings

 Divide the sum of the readings by 8.

Return value is the sum of the individual time measurements divided by 8.

parameter meaning

Parameter 1 ---

Parameter 2 ---

Parameter 3 ---

return value 2 x measured value (in 500 nanosecond steps)

2.3.7 Function 6: PA.2 from LOW to HIGH, time measurement to U (PA.0)> Uref
(resolution 500ns)
This function corresponds to function 5, but the LOW-HIGH transition takes place at pin PA.2.
parameter meaning

Parameter 1 ---

Parameter 2 ---

Parameter 3 ---

return value 2 x measured value (in 500 nanosecond steps)

2.3.8 Function 7: PA.2 from LOW to HIGH, time measurement to U (PA.0)> Uref
(resolution 64us)
This function corresponds to function 5, the LOW-HIGH transition takes place at pin PA.2. The temporal
resolution is 64us (line frequency), the maximum measuring range is 262 milliseconds. Two
measurements are taken at intervals of 20 ms and the values are added up. The maximum returned value
is therefore 8192. The process is as follows:

 The pins PA.0, PA.1 and PA.3 are switched as input without pullup, PA.2 as output with LOW
level
 Set PA.2 to HIGH and set the time until the voltage at PA.0> Uref.

 After 262 milliseconds, stop the measurement and set PA.3 to LOW level

 Repeat the whole thing 1 time

Return value is the sum of the individual time measurements.

parameter meaning

Parameter 1 ---

Parameter 2 ---

Parameter 3 ---

return value 2 x measured value (in 64 microsecond steps)


2.3.9 Function 8: PA.1 from LOW to HIGH, time measurement to U (PA.0) <Uref
(resolution 300ns)
Pin PA.0 is connected to the analog comparator, the reference voltage is the internal bandgap reference
source with approx. 1.1 volts. Pin PA.1 is switched from 0 to 1 and the time measured until the voltage at
PA.0 is again lower than the voltage of the reference voltage source. The time resolution is 300ns, the
maximum measuring range is 60 microseconds. 16 measurements are taken every 20ms and the values
are added up. The maximum returned value is therefore 3200. The procedure is the following:

 The pins PA.0, PA.2 and PA.3 are switched as input without pullup, PA.1 as output with LOW
level
 PA.1 switch to HIGH and wait 300ns

 Determine the time until the voltage at PA.0 <Uref.

 After 60 microseconds, stop the measurement and set PA.1 to LOW level

 Repeat 15 times

Return value is the sum of the individual time measurements.

parameter meaning

Parameter 1 ---

Parameter 2 ---

Parameter 3 ---

return value 16 x measured value (in 300 nanosecond steps)

2.3.10 Function 9: PA.1 from LOW to HIGH, time measurement to U (PA.0) <Uref
(resolution 500ns)
This function corresponds to function 4, but with a different time resolution and a larger measuring range.
The time resolution is 500ns, the maximum measuring range is 6.4 milliseconds. 16 measurements are
taken every 20ms and the values are added up. Finally, the result is divided by 8. The maximum returned
value is thus 25600. The procedure is the following:

 The pins PA.0, PA.2 and PA.3 are switched as input without pullup, PA.1 as output with LOW
level
 PA.1 switch to HIGH and wait 300ns

 Determine the time until the voltage at PA.0 <Uref.


 After 6.4 milliseconds, stop the measurement and set PA.1 to LOW level

 Repeat 15 times, add up the readings

 Divide the sum of the readings by 8.

Return value is the sum of the individual time measurements divided by 8.

parameter meaning

Parameter 1 ---

Parameter 2 ---

Parameter 3 ---

return value 2 x measured value (in 500 nanosecond steps)

2.3.11 Function 10: PA.2 from LOW to HIGH, time measurement to U (PA.0) <Uref
(resolution 500ns)
This function corresponds to function 9, but the LOW-HIGH transition takes place at pin PA.2.

2.3.12 Function 11: PA.3 from LOW to HIGH, time measurement to U (PA.0) <Uref
(resolution 500ns)
This function corresponds to function 9, but the LOW-HIGH transition takes place at pin PA.3.

2.4 An application example


The following example shows the complete circuit including LCD and a button for measuring range
switching. Of course, you could build this standalone and transfer the program system by means of the
clone program or the loader. That would be a compact meter, of course only if the accuracy is sufficient.
In addition to the measurement library, an LCD driver is needed, the LCD itself does not necessarily have
to be connected because the output is in parallel via TV.
With the following program, the following measuring ranges result, which can be selected by means of the button.

Type of
measuring range
measurement

resistance 10Ω ... 1MΩ

diode 0 ... 4.8V

capacity 100pF ... 1000μF

inductance 10 uH ... 100mH

The scaling factors are stored in lines 9 to 13. These were determined empirically with reference
components, but depend to a large extent on manufacturing tolerances in the components used (including
controllers). The following table gives an assignment over the scaling values to the measuring ranges, for
the calibration a component should be taken, which lies approximately in the middle of the measuring
range by value. The specified measuring ranges are to be regarded as approximate values only:

address row measuring range


1026 9 Resistors 6,5KΩ <R <1MΩ

1027 9 Resistors 200Ω <R <6,5KΩ

1028 9 Resistors 10Ω <R <200Ω

1029 10 Diode voltage 0V <U <4.8V

1030,1031 (final value, offset) 11 Capacitors 0.1nF <C <72nF

1032,1033 (final value, offset) 11 Capacitors 72nF <C <740nF

1034,1035 (final value, offset) 12 Capacitors 740nF <C <22μF

1036,1037 (final value, offset) 12 Capacitors 22μF <C <1000μF

1038 13 Inductors 50μH <L <6.7mH

1038 13 Inductors 6,7mH <L <830mH

PROGRAM:Mess4
01 E=30:F=31:LFIND V,160
02 IF V=0 GOTO ~L+2
03 VM 7:COLOR 1,5:E=8:F=9
04 LFIND L,18:IF L>0 GOTO ~L+2
05 ? "Keine Messlib ";:END
06 GOSUB 89
07 ? "CB2 KOMPO-Meter":WAIT 20
08 'Korrektur-Faktoren
09 DATA 1026,3320,12000,2150
10 DATA 1029,5000
11 DATA 1030,740,96,7660,6
12 DATA 1034,2190,0,1043,0
13 DATA 1038,6710,8300
14 OUT $47E,15:'disable INPUT
15 GOSUB 25:GOSUB 80:'R
16 IF T=0 GOTO ~L-1
17 GOSUB 41:GOSUB 80:'D
18 IF T=0 GOTO ~L-1
19 GOSUB 48:GOSUB 80:'C
20 IF T=0 GOTO ~L-1
21 GOSUB 70:GOSUB 80:'L
22 IF T=0 GOTO ~L-1
23 GOTO ~L-8
24 'R Messung
25 CALL L,3
26 X=~R:N=AR(1024)-X:Y=AR(1026)
27 IF X>31000 GOTO ~L+4
28 IF X<200 GOTO ~L+4
29 X=X/10:SCALE R,0,Y,0,X,N:CLS
30 ? "(R) ";!$1D;R;" K";%F:RET
31 CLS :? "(R) > 1 M";%F:RET
32 CALL L,2
33 X=~R:N=AR(1024)-X:Y=AR(1027)
34 IF X<200 GOTO ~L+3
35 X=X/10:SCALE R,0,Y,0,X,N:CLS
36 ? "(R) ";!$0D;R;" ";%F:RET
37 CALL L,1
38 X=~R:N=AR(1024)-X:Y=AR(1028)
39 SCALE R,0,Y,0,X,N:CLS
40 ? "(R) ";!$1D;R;" ";%F:RET
41 'D-Messung
42 CALL L,2:Y=AR(1029)
43 X=~R:IF X>32000 GOTO ~L+3
44 SCALE R,0,Y,0,X,32767:CLS
45 ? "(D) ";!$3D;R;" V":RET
46 CLS :? "(D) > 4.88 V":RET
47 'C-Messung
48 CALL L,4
49 Y=AR(1030):O=AR(1031)
50 X=~R:IF X>3199 GOTO ~L+3
51 SCALE R,0,Y,0,X-O,32000:CLS
52 ? "(C) ";!$1D;R;" nF":RET
53 CALL L,5
54 Y=AR(1032):O=AR(1033)
55 X=~R:IF X>25000 GOTO ~L+3
56 SCALE R,0,Y,0,X-O,25600:CLS
57 ? "(C) ";!$1D;R;" nF":RET
58 CALL L,6
59 Y=AR(1034):O=AR(1035)
60 X=~R:IF X>25000 GOTO ~L+3
61 SCALE R,0,Y,0,X-O,25600:CLS
62 ? "(C) ";!$2D;R;" ";%E;"F"
63 CALL L,7
64 Y=AR(1036):O=AR(1037)
65 X=~R:IF X>4090 GOTO ~L+3
66 SCALE R,0,Y,0,X-O,4096:CLS
67 ? "(C) ";!$0D;R;" ";%E;"F":RET
68 CLS :? "(C) OVERFLOW ":RET
69 'L-Messung
70 ? @0,0;:CALL L,8:Y=AR(1038)
71 X=~R:IF X>3199 GOTO ~L+3
72 SCALE R,0,Y,0,X,3200:CLS
73 ? "(L) ";!$0D;R;" ";%E;"H":RET
74 ? @0,0;:CALL L,9:Y=AR(1039)
75 X=~R:IF X>25599 GOTO ~L+3
76 SCALE R,0,Y,0,X,25600:CLS
77 ? "(L) ";!$1D;R;" mH":RET
78 CLS :? "(L) OVERFLOW ":RET
79 'Test auf Tastendruck
80 I=0:T=0
81 'IF IN($807)=0 GOTO ~L-2
82 IF KEY(0)>0 GOTO ~L+3
83 IF IN($807)=0 GOTO ~L+2
84 RETURN
85 SYNC 1:I=I+1:IF I<50 GOTO ~L-3
86 T=1
87 RETURN
88 'my and omega symbols
89 DA 100,0,0,9,9,9,14,8,16
90 DA 108,0,0,14,17,17,10,27,0
91 FOR I=0 TO 15:J=I+100
92 OUT $A00+I,AR(J):NEXT
93 RETURN
#

3 An RTC command extension (library code 0x1F)

3.1 General
This demo library shows how to extend the scope of the BASIC computer. For this the following
commands are implemented:
3.2 Function overview
command function
_SETSEC n sets the seconds value to parameter n, while the limits are monitored.
_SETMIN n sets the minute value to the parameter n, while the limits are monitored.
_SETHOUR n sets the hour value to the parameter n, while the limits are monitored.
_SETDAY n sets the day value to the parameter n, while the limits are monitored.
_SETMONTH n sets the monthly value to the parameter n, while the limits are monitored.
_SETYEAR n sets the year value to the parameter n (0..99)
_GETSEC V reads the second value into variable V
_GETMIN V reads the minute value into variable V
_GETHOUR V reads the hour value into variable V
_GETDAY V reads the day value into variable V
_GETMONTH V reads the month value into variable V
_GETYEAR V reads the year value into variable V

All commands have only one dummy function, but a connection to a specific RTC (eg via I2C) should not
be a problem.

1 video driver without external hardware

1.1 24x40 character driver (library code 0x80)

1.1.1 General
This mode allows the display of text and pseudo-graphics with a resolution of 24 lines of 40 characters each.
However, the representation is only monochrome (green on black) possible, the output pins for the red and blue
color channel are switched to high impedance. One line in screen memory consists of 45 bytes. First, there are 5
bytes, each of which is responsible for inverting one of the following characters. This is followed by 40 character
bytes, bit 7 of the characters is ignored. The characters are defined with 8 pixels horizontally and 10 pixels
vertically, the character set with a total of 128 characters is in the RAM and can also be changed. Since the character
set has no longer fit into the driver due to the memory requirement, it must be loaded to program location 7. A
matching character set is charset10.bin . The image memory is divided as follows:

start address end address bytes function

0 1079 1080 24 lines characters

1080 1319 240 used internally

1320 2599 1280 character set

2600 2759 160 unused

The character set in the RAM is constructed line by line, first 128 bytes for the first line, then 128 bytes for
the second line and so on up to 128 bytes for the tenth and thus last line. The character set on program
location 7, which serves as the source, has a similar structure, except that here a line has 256 bytes. This
also means that the driver uses only the lower 128 characters of the character set.

1.1.2 Functions
The current driver has no additional functions installed, the control is via the "normal" BASIC output
commands. To activate the driver, you only need to switch to the USER video mode using VMODE 7 .
The character set of program location 7 is then copied to the RAM. With COLOR 0 , the characters are
output inverted, COLOR 1 returns to non-inverted mode.
It is also possible to use 16 (0x00 ... 0x0f) user-defined characters. For this the I / O area is reserved from
0xa00 to 0xaff. In each case 16 consecutive bytes are responsible for one character, only the first 10
bytes are used. Within the bytes, bits 7 ... 0 are used, with bit 7 corresponding to the leftmost pixel.
Alternatively, VPOKE can also be written directly into the screen memory , but there is no linear
relationship between the character bytes and the address as in the OUT command, which already
performs the conversion of the addresses.

1.2 24x50 character driver (library code 0x81)

1.2.1 General
This mode allows the display of text and pseudo-graphics with a resolution of 24 lines of 50 characters each.
However, the representation is only monochrome (green on black) possible, the output pins for the red and blue
color channel are switched to high impedance. One line in screen memory consists of 50 bytes. The associated
character set with 6 pixels horizontally and 10 pixels vertically must be loaded on program slot 7. It contains 256
characters where the characters from 128 correspond to those from 0 ... 127 but are displayed inverted. A matching
character set is charset_50z.bin . The image memory is divided as follows:

start address end address bytes function

0 1199 1200 24 lines characters

1200 2759 1560 unused

The character set in the Flash is constructed line by line, first 256 bytes for the first line, then 256 bytes
for the second line and so on up to 256 bytes for the tenth and thus last line. The character set must be in
program position 7, the start address is permanently coded in the driver.
1.2.2 Functions
The current driver has no additional functions installed, the control is via the "normal" BASIC output
commands. To activate the driver, you only need to switch to the USER video mode using VMODE 7 .
With COLOR 0 , the characters are output inverted, COLOR 1 returns to non-inverted mode.

1.3 24x60 character driver (library code 0x82)

1.3.1 General
This mode allows the display of text and pseudographics with a resolution of 24 lines of 60 characters each.
However, the representation is only monochrome (green on black) possible, the output pins for the red and blue
color channel are switched to high impedance. One line in screen memory consists of 50 bytes. The associated
character set with 6 pixels horizontally and 10 pixels vertically must be loaded on program slot 7. It contains 256
characters where the characters from 128 correspond to those from 0 ... 127 but are displayed inverted. A matching
character set is charset_60z.bin . The image memory is divided as follows:

start address end address bytes function

0 1439 1440 24 lines characters

1440 2759 1320 unused

The character set in the Flash is constructed line by line, first 256 bytes for the first line, then 256 bytes
for the second line and so on up to 256 bytes for the tenth and thus last line. The character set must be in
program position 7, the start address is permanently coded in the driver. The last pixel of each character
is repeated 2 times, thus, for example, the pseudographics are applied unbalanced. {Functions The
current driver has no additional functions built in, the control is carried out via the "normal" BASIC output
commands. To activate the driver, you only need to switch to the USER video mode using VMODE 7 .
With COLOR 0 , the characters are output inverted, COLOR 1 returns to non-inverted mode.

1.4 Tile / Sprite Mode Driver (library code 0x90)

1.4.1 General
The tile-and-sprite driver is primarily intended for programming games. There is a tilemap that repeats in both the X
and Y directions. From this map a window of 16 tiles horizontal and 13 tiles vertical is visible, the position of this
window can be moved over the entire area pixel by pixel. Each of the 1024 tile positions contains an index on one of
the 49 tiles. Each of these tiles ("tiles") consists of 8 x 8 pixels, each of which can have one of 16 displayable colors.
In addition to extensive Tile manipulation options, there are also software sprites, which themselves consist of one
tile and can move pixel-wise throughout the tilemap. At the top and bottom of the screen, there is still one line of
text that behaves like the first two lines in mode 0.

The image memory is divided as follows:

start address end address bytes function

0 39 40 system

40 1063 1024 tilemap

1064 2599 1568 49 tiled definitions

2632 2691 60 2 lines characters

2692 2751 60 2 lines of attributes

2752 2759 8th not used

The Tilemap has a size of 32 times 32 tiles and repeats in both X and Y direction.
Each of the 49 tiles of 8 x 8 pixels is represented by 32 bytes, with 4 bits each for one pixel.

1.4.2 System variables


The system variables are all in the first 40 bytes of the image memory and can be addressed with VPOKE and
VPEEK () .

address size function

0 byte Y-coordinate (top left) of the visible section

1 byte X-coordinate (top left) of the visible section

4 Word Start address of the sprite area in memory is initialized by function 24

6 byte Number of initialized sprites is initialized by function 24


1.4.3 The sprite structure in the array
Each of the sprites occupies 16 bytes in the array

offset meaning

0 New Y coordinate

1 New X coordinate

2 Old Y coordinate

3 Old X coordinate

4 Sprite Tile

5 Start of the 4 backup tiles

6 Transparency Color

7 visible (0/1)

8 Sprite active (0/1)

9 Kollisionsflag

10 horizontal step size

11 vertical increment

12 Tile index 1 for restore

13 Tile index 2 for restore

14 Tile index 3 for restore

15 Tile index 4 for restore


1.4.4 Functions
To activate the driver, you only need to switch to the USER video mode using VMODE 7 . The two text lines at
the top and bottom of the screen are controlled via the "normal" BASIC output commands. The line at the top
corresponds to the text line 0 and the one at the bottom of the text line 1.
Furthermore, the following functions are available via CALL :

function number function

9 Fill tile map with constant tile index

10 Tile map with a tile bitmap set

11 Fill Tile Map area with constant tile index

12 Set a tile index in the tile map

13 Query a tile index in the tile map

14 Fill tile with paint

15 Draw a predefined pattern in tile

16 Draw an array-defined pattern in tile

17 Draw patterns from character set in tile

18 Mirror tile horizontally

19 Mirror tiles vertically

20 Tile 90 degrees clockwise

21 Turn the tile 90 degrees counterclockwise

22 Copy Tile

23 Join together tiles

24 Rotate 2 tiles
25 Initialize sprites

26 Define sprite

27 Position sprite

28 Enable sprite

29 Disable sprite

30 Draw a single sprite

31 Delete a drawn sprite

32 Draw all sprites sequentially

33 Delete all sprites sequentially

34 Recalculate all sprites coordinates

35 Move all sprites

36 ---

37 ---

1.4.5 Function 9: Fill Tile Map with Constant Tile Index


This function sets the entire tile area to the specified tile.

parameter meaning

Parameter 1 Tile number (0 ... 48)

Parameter 2 ---

Parameter 3 ---

return value 0
1.4.6 Function 10: Set Tile Map with a Tile Bitmap
This function sets the specified tile in the entire tile area if the corresponding bit in the array is set to "1".
The bitmap area in the array is 128 bytes and is organized as follows:

 The 32 lines are organized from top to bottom


 Each line consists of 4 bytes, from left to right

 Within each byte, bit 7 represents the leftmost tile

parameter meaning

Parameter 1 Bitmap position in the array (0 ... 640)

Parameter 2 Tile number (0 ... 48)

Parameter 3 ---

return value 0

1.4.7 Function 11: Fill Tile Map Area with Constant Tile Index
This function sets the specified tile area to the specified tile. Start and end positions result from 32 * line + column .
There are no restrictions in either X or Y directions because the tile map repeats almost infinitely.

parameter meaning

Parameter 1 starting position

Parameter 2 end position

Parameter 3 Tile number (0 ... 48)

return value 0

1.4.8 Function 12: Set a Tile Index in the Tilemap


Sets a tile index in the tilemap to the specified value.
parameter meaning

Parameter 1 Y-coordinate (0 ... 31)

Parameter 2 X-coordinate (0 ... 31)

Parameter 3 Tile number (0 ... 48)

return value 0

1.4.9 Function 13: Query a tile index in the tilemap


Returns the tile index at the specified location.

parameter meaning

Parameter 1 Y-coordinate (0 ... 31)

Parameter 2 Y-coordinate (0 ... 31)

Parameter 3 ---

return value Tile Index

1.4.10 Function 14: Fill tile with paint


Fill the tile parameter 1 with the color parameter 2 .

parameter meaning

Parameter 1 Tile number (0 ... 48)

Parameter 2 Color (0 ... 15)


Parameter 3 ---

return value 0

1.4.11 Function 15: Draw Predefined Pattern in Tile


The driver already defines 32 different (two-color) patterns that can be used to create tiles. Parameters are the tile
number, the pattern number and a byte for defining the character color. The pixels in the tile are set with the set
color, which has a "1" in the pattern, all other pixels remain unchanged.

parameter meaning

Parameter 1 Tile number (0 ... 48)

Parameter 2 Sample number (0 ... 31)

Parameter 3 Character color (0 ... 15)

return value 0

1.4.12 Function 16: Draw Array Defined Pattern in Tile


You can also define patterns in the array to create tiles. The first parameter is the tile to be filled. The second
parameter specifies the array cell from which the pattern is stored. This consists of 8 consecutive (byte) cells, where
bit 7 determines the leftmost pixel and bit 0 determines the rightmost pixel. The third parameter is again a byte for
the definition of the character color. The pixels in the tile are set with the set color, which has a "1" in the pattern, all
other pixels remain unchanged.

parameter meaning

Parameter 1 Tile number (0 ... 48)

Parameter 2 Array start cell (0 ... 760)

Parameter 3 Character color (0 ... 15)

return value 0
1.4.13 Function 17: Draw Pattern from Character Set in Tile
With this function characters from the character set can be used as patterns for tiles. Since the tiles have a size of
8x8 pixels, but the character set is one of 6x10 pixels, one pixel row is cut off at the top and bottom and one empty
pixel row is added to the right and left. The first parameter is the tile to be filled. The second parameter specifies the
character from the system character set that determines the pattern. The third parameter is again a byte for defining
the character color, with only the pixels in the tile being set with the set color having a "1" in the pattern. All other
pixels remain unchanged.

parameter meaning

Parameter 1 Tile number (0 ... 48)

Parameter 2 Characters (0 ... 255)

Parameter 3 Character color (0 ... 15)

return value 0

1.4.14 Function 18: Mirror tiles horizontally


The specified tile will be mirrored horizontally. What was left before is then right and vice versa.

parameter meaning

Parameter 1 Tile number (0 ... 48)

Parameter 2 ---

Parameter 3 ---

return value 0
1.4.15 Function 19: Mirror Tile Vertically
The specified tile will be mirrored vertically. What was above above is down afterwards and vice versa.

parameter meaning

Parameter 1 Tile number (0 ... 48)

Parameter 2 ---

Parameter 3 ---

return value 0

1.4.16 Function 20: Turn Tile 90 degrees clockwise


The specified tile is rotated 90 degrees clockwise.

parameter meaning

Parameter 1 Tile number (0 ... 48)

Parameter 2 ---

Parameter 3 ---

return value 0

1.4.17 Function 21: Turn the tiles 90 degrees counterclockwise


The specified tile is rotated 90 degrees counterclockwise.

parameter meaning
Parameter 1 Tile number (0 ... 48)

Parameter 2 ---

Parameter 3 ---

return value 0

1.4.18 Function 22: Copy Tile


This function copies the contents of one tile to another.

parameter meaning

Parameter 1 Source Tile (0 ... 48)

Parameter 2 Target Tile (0 ... 48)

Parameter 3 ---

return value 0

1.4.19 Function 23: Join Tiles


This function draws the contents of the second tile in the first. Pixels that have the transparency color in the second
tile remain unchanged.

parameter meaning

Parameter 1 Source and destination tiles (0 ... 48)

Parameter 2 Character Tile (0 ... 48)

Parameter 3 Transparency color (0 ... 15)

return value 0
1.4.20 Function 24: Rotate tiles
This function rotates the content of two tiles. The two tiles are meant to be next to each other or on top of each other,
which is postponed at one end, reappears at the other end. The first parameter specifies the tile that is up or to the
left in the imaginary union, the second parameter specifies the tile that is below or to the right in the imaginary
union.

parameter meaning

Parameter 1 Tile 1 (0 ... 48)

Parameter 2 Tile 2 (0 ... 48)

Parameter 3 Shift direction (0 ... 3)

return value 0

The third parameter indicates the direction:

Parameter 3 direction

0 Shift / rotation upwards

1 Shift / rotation to the right

2 Shift / rotation down

3 Shift / rotation to the left

1.4.21 Function 25: Initializing Sprites


This function can be used to initialize up to 8 sprites. The sprite data are then in the array from the specified address,
for each sprite 16 bytes are needed.
parameter meaning

Parameter 1 Array position (0 ... 511)

Parameter 2 Number of sprites (1 ... 8)

Parameter 3 ---

return value Maximum sprite number

1.4.22 Function 26: Define Sprite


This feature allows you to define the appearance of sprites initialized in function 24. The first parameter is the sprite
number, the second is the tile to be used for display. Finally, the third parameter specifies the color that should be
transparent when the sprite is displayed. At the same time, the relevant sprite is activated.

parameter meaning

Parameter 1 Sprite number (0 ... 7)

Parameter 2 Tile number (0 ... 48)

Parameter 3 Transparency color (0 ... 15)

return value 0

1.4.23 Function 27: Position Sprite


This function positions the sprites initialized in function 24. The first parameter is the sprite number, the second and
third parameters indicate the position of the sprite in the map. The 4th and 5th parameters specify the increment by
which the sprite is moved in the motion functions. The value 1 means a shift to the right or down by 1 pixel, the
value 255 a shift to the left or up by 1 pixel.

parameter meaning
Parameter 1 Sprite number (0 ... 7)

Parameter 2 Y position (0 ... 255)

Parameter 3 X position (0 ... 255)

Parameter 4 Y movement (0 ... 255)

Parameter 5 X movement (0 ... 255)

return value 0

1.4.24 Function 28: Enable Sprite


Activate the sprite within the sequence so that it will be drawn next time.

parameter meaning

Parameter 1 Sprite number (0 ... 7)

Parameter 2 ---

Parameter 3 ---

return value 0

1.4.25 Function 29: Disable Sprite


Disables the sprite within the sequence so that it will not be recorded next time.

parameter meaning

Parameter 1 Sprite number (0 ... 7)


Parameter 2 ---

Parameter 3 ---

return value 0

1.4.26 Function 30: Draw a single sprite


Draws a single sprite, data is at the specified array address. The original tiles are copied into the 4 backup tiles, the
sprite is drawn in there and the tile indices for the 4 tiles are "bent over" to the backup tiles. In addition, the Visible
flag is set.

parameter meaning

Parameter 1 Array address (0 ... 752)

Parameter 2 Y position

Parameter 3 X position

return value 0

1.4.27 Function 31: Delete a drawn sprite


Deletes a single sprite, data is at the specified array address. Only the 4 tile indexes are reset to the original values
and the visible flag is reset.

parameter meaning

Parameter 1 Array address (0 ... 752)

Parameter 2 ---

Parameter 3 ---

return value 0
1.4.28 Function 32: Draw all sprites sequentially
Draws all enabled sprites in ascending order.

parameter meaning

Parameter 1 ---

Parameter 2 ---

Parameter 3 ---

return value 0

1.4.29 Function 33: Delete all sprites sequentially


Deletes all activated sprites in descending order.

parameter meaning

Parameter 1 ---

Parameter 2 ---

Parameter 3 ---

return value 0

1.4.30 Function 34: Recalculate all Sprites coordinates


Recalculates the coordinates of all activated sprites.
parameter meaning

Parameter 1 ---

Parameter 2 ---

Parameter 3 ---

return value 0

1.4.31 Function 35: Move all sprites


Moves all enabled sprites. To do this, all sprites are deleted, the coordinates are recalculated and then drawn again.
This is done by deleting in descending order and drawing in ascending order.

parameter meaning

Parameter 1 ---

Parameter 2 ---

Parameter 3 ---

return value 0

1.5 Vector Mode Driver (library code 0x91)

1.5.1 General
This mode could be called a "vector mode" or "differential mode". It corresponds to video mode 7 in earlier
versions. At the top and bottom of the screen there is a line of text that behave in the same way as the first two lines
in mode 0. But then the similarity already stops. Then there are 105 byte pointers followed by 105 line definitions a
24 bytes. Each of the pointers indicates which of the 105 row definitions is relevant to the current row. Thus, all
lines can have their own definition or all lines have the same definition. Values greater than 104 should not be set,
because then the behavior is not defined.
The image memory is divided as follows:
start address end address bytes function

0 59 60 2 lines characters

60 119 60 2 lines of attributes

120 224 105 105 line pointers

225 2744 2520 105 line definitions

2745 2759 15 unused


 The line definitions consist of 12 entries of 2 bytes each. The first byte determines the distance to
the left edge of the screen, to which 160 must be added. The highest value is 254, so the
horizontal resolution is 95 pixels. The second byte indicates the colors to be displayed. The color
values from the upper and lower nibble are displayed alternately. It should also be noted that the
smallest distance must be 160 and each following distance value at least 1 greater than the
previous one.

1.5.2 Functions
To activate the driver, you only need to switch to the USER video mode using VMODE 7 . The two text lines at
the top and bottom of the screen are controlled via the "normal" BASIC output commands. The line at the top
corresponds to the text line 0 and the one at the bottom of the text line 1.
Further functions are available via CALL :

function number function

16 deletes the vector area

17 Fill line pointer constantly

18 Fill row pointer in ascending order

19 Fill the line pointer in descending order

20 Fill row pointer with array values

21 Copy line pointer ranges

22 Fill lines with constant array values


23 Fill rows with consecutive array values

24 ---

25 ---

26 ---

27 ---

1.5.3 Function 16: Delete vector area


This function deletes only the entire vector area, whereas a CLS deletes only the text area.

parameter meaning

Parameter 1 ---

Parameter 2 ---

Parameter 3 ---

return value 0

1.5.4 Function 17: Fill the line pointer constantly


Sets the row pointer from parameter 1 to parameter 2 to the value of parameter 3 . The values are automatically
limited to the valid range, as is an overflow from 104 to 0 instead.

parameter meaning

Parameter 1 start row

Parameter 2 number of lines

Parameter 3 value
return value 0

1.5.5 Function 18: Fill the line pointer in ascending order


Sets the row pointer from parameter 1 to parameter 2 to the value of parameter 3 , which is increased by 1 from
line to line. The values are automatically limited to the valid range, as is an overflow from 104 to 0 instead.

parameter meaning

Parameter 1 start row

Parameter 2 number of lines

Parameter 3 start value

return value 0

1.5.6 Function 19: Fill the line pointer in descending order


Sets the line pointer from parameter 1 to parameter 2 to the value of parameter 3 , which is decremented by 1
from line to line. The values are automatically limited to the valid range, an overflow from 104 to 0 takes place at
the addresses and from 0 to 104 at the value.

parameter meaning

Parameter 1 start row

Parameter 2 number of lines

Parameter 3 start value

return value 0
1.5.7 Function 20: Fill row pointer with array values
Copies the values of the array cells from parameter 3 into the row pointers from parameter 1 , the number is in
parameter 2. The values are automatically limited to the valid range, as well as an overflow from 104 to 0 at the
addresses and one from 767 to 0 at the array cells instead.

parameter meaning

Parameter 1 Start-row pointer

Parameter 2 number of lines

Parameter 3 Array start position

return value 0

1.5.8 Function 21: Copy line pointer ranges internally


Copies row pointers within the row pointer range. Parameter 1 specifies the first row pointer of the source area and
parameter 2 the first row pointer of the destination area. The third parameter specifies the number of row pointers to
be copied, with positive values copying the range beginning with the first row pointer, with negative values
beginning with the last row pointer of the range to be copied.
The values are automatically limited to the valid range, and an overflow from 104 to 0 (as well as vice versa) takes
place at the addresses.

parameter meaning

Parameter 1 Start line source area

Parameter 2 Start line Target

Parameter 3 number of lines

return value 0
1.5.9 Function 22: Fill Lines with Constant Array Values
Copies the values of the array cells from parameter 3 into the lines from parameter 1 , the number is in parameter
2. The same 24 bytes are copied per line. There is an overflow from 104 to 0 in the rows and one from 767 to 0 in
the array cells.

parameter meaning

Parameter 1 start row

Parameter 2 number of lines

Parameter 3 Array start position

return value 0

1.5.10 Function 23: Fill rows with consecutive array values


Copies the values of the array cells from parameter 3 into the lines as of parameter 1 , the number is in parameter
2. 24 bytes are copied per line. There is an overflow from 104 to 0 in the rows and one from 767 to 0 in the array
cells.

parameter meaning

Parameter 1 start row

Parameter 2 number of lines

Parameter 3 Array start position

return value 0

2 video drivers for external displays


2.1 DUAL text LCD driver (library code 0xA0 ... 0xA3)

2.1.1 General
These drivers can be used to control various single-line and multi-line text LCDs. The data lines D4 ... D7
are used, the data lines D0 ... D3 can be freely used via the I / O address range from 0x800 or the IN and
ADC functions.
The actual output is done with PRINT or direct writing into the video RAM in the address range from
0x0000. A cyclic update function ensures that all characters are transmitted to the LCD.
It is also possible to use the custom characters. For this the I / O range from 0xa00 to 0xa40 is reserved.
For each 8 consecutive bytes are responsible for a character. Within the bytes, bits 4 ... 0 are used, with
bit 4 corresponding to the leftmost pixel. These characters are usefully used in the range of 8 ... 15, the
range of 0 ... 7 is also possible, but in some cases a 0x00 in the string leads to the abort of the output.
Parallel to the LCD, the contents of the display will also be displayed on the TV output, the display should
match that of the LCD, and characters larger than 128 may differ in character sets. The foreground and
background colors can be easily set via the COLOR command, whereby the setting is immediately
applied to the entire (TV) display.

2.1.2 Hardware
The display is connected to the parallel port, but also the + 5V must be led out with it. The lines Strobe,
Busy and the data lines D4 ... D7 are used.
Buttons, etc. can still be connected to the data lines D4 ... D7. These must switch the signals over approx.
1Kohm to ground. The status of the four data lines can be queried using IN ($ 804) ... IN ($ 807) .

2.1.3 supported displays


Since only a (relatively slow) initialization with 4-bit data bus and direct writing to the DD and CG RAM are used,
the driver should work with most displays available on the market. If you have had experience with a display not
shown in the table below, I would ask for a brief message so that I can insert it into the table below. Currently the
following display types are supported:

driver driver code display Display works Display does not work

lcd116.bin 0xA0 1 x 16 characters Powertip PC1601A ,

lcd216.bin 0xA1 2 x 16 characters , ,


lcd220.bin 0xA2 2 x 20 characters Powertip PC2002-M ,

2.1.4 Functions
The current driver has no additional functions installed, the control is via the "normal" BASIC output
commands. To activate the driver, you only need to switch to USER video mode using VMODE 7 . When
switching to another video mode, the display remains on the LCD. However, there should be a small
break between the last write and the change of the video mode (0.1s), so that the data can be safely
updated on the LCD. There is no need to connect an LCD to test the driver.

2.2 DUAL graphic LCD driver 128x64 PIXEL (library code 0xA8)

2.2.1 General
With this driver, various KS0107 / 0108 based or compatible graphics displays with 128x64 pixels can be
controlled. The output is parallel to the TV output, functionally, the video mode is the same as the built-in
mode 5. For the control of the entire parallel port is used, in addition a 4-bit wide latch (H transparent) or
register (both edges possible) is necessary , Furthermore, 7 keys can be connected. There are two
versions of the driver, which differ in the polarity of the chip-select signals. The version with the extension
_ncs is suitable for displays with LOW-active chip-select signals, with the suffix _pcs correspondingly for
displays with HIGH-active chip-select signals. A cyclic update function ensures that the screen content is
transferred to the LCD approx. 12 times per second. The foreground and background colors are
permanently assigned with blue and cyan and can not be changed.

2.2.2 Hardware
The display is connected to the parallel port, but also the + 5V must be led out with it. The data lines are
led directly to the display, the control lines I / D, CS1 and CS2 and the driver signal for the additional keys
are buffered via a 4-bit latch / register. The purpose of this is the BUSY signal, which is used as output.
The E-signal is supplied by the STROBE output, the R / W line is grounded, it is only written to the
display.
2.2.3 Output functions
The current driver has no additional functions installed, the control is via the "normal" BASIC output
commands. To activate the driver, you only need to switch to USER video mode using VMODE 7 . When
switching to another video mode, the display remains on the LCD. However, there should be a small
break between the last write and the change of the video mode (0.1s), so that the data can be safely
updated on the LCD. There is no need to connect an LCD to test the driver.

2.2.4 Key functions


Up to 7 buttons can be connected. The function KEY (8) or the API function api_scancode can be used to read the
status directly, whereby a "1" stands for a depressed key. In addition, different keystrokes are emulated, this is
indicated in the diagram next to the buttons.

button Bit in scancode keycode


left 0 0xE2

right 1 0xE3

up 2 0xE4

down 3 0xE5

enter 4 0xEA

esc 5 0xED

F5 6 0xF5

ATTENTION! Once one of the buttons is pressed, a connected PS2 keyboard will not work properly.

2.3 DUAL graphic LCD driver 24x40 characters (library code 0xA9)

2.3.1 General
This mode allows the display of text and pseudo-graphics with a resolution of 24 lines of 40 characters each.
However, the representation is only monochrome (green on black) possible, the output pins for the red and blue
color channel are switched to high impedance. Optionally, the display contents can be output to a graphic display
connected to the parallel port. Monochrome displays without their own controller with 320x240 pixels are
supported. The display can only be done one way, TV out or display, simultaneous display is not possible. The
respective non-active display is then turned off, the LCD, there is a control pin with which the LCD voltage can be
turned off and should. One line in screen memory consists of 45 bytes. First, there are 5 bytes, each of which is
responsible for inverting one of the following characters. This is followed by 40 character bytes, bit 7 of the
characters is ignored. The characters are defined with 8 pixels horizontally and 10 pixels vertically, the character set
with a total of 128 characters is in the RAM and can also be changed. Since the character set has no longer fit into
the driver due to the memory requirement, it must be loaded to program location 7. A matching character set is
charset10.bin . The image memory is divided as follows:

start address end address bytes function

0 1079 1080 24 lines characters


1080 1319 240 used internally

1320 2599 1280 character set

2600 2759 160 unused

The character set in the RAM is structured line by line, first 128 bytes for the first line, then 128 bytes for
the second line and so on up to 128 bytes for the tenth and thus last line. The character set on program
location 7, which serves as the source, has a similar structure, except that here a line has 256 bytes. This
also means that the driver uses only the lower 128 characters of the character set.

2.3.2 Hardware
The parallel port is used to connect the display. The data signals D0 ... D3 (at the port pins of the same
name), CP at pin D7, LOAD at pin D6 and FLM / FRAME at pin D5 are available. A switching signal
(LOW active) is also available at the BUSY pin, with which the display voltages VEE and VO should be
switched. Otherwise, damage to the display may occur, both at the moment of switching on until the video
mode 7 is switched on and when changing to another video mode.
2.3.3 Functions
The current driver has no additional functions installed, the control is via the "normal" BASIC output
commands. To activate the driver, you only need to switch to the USER video mode using VMODE 7 .
The character set of program location 7 is then copied to the RAM. With COLOR 0 , the characters are
output inverted, COLOR 1 returns to non-inverted mode.
It is also possible to use 16 (0x00 ... 0x0f) user-defined characters. For this the I / O area is reserved from
0xa00 to 0xaff. In each case 16 consecutive bytes are responsible for one character, only the first 10
bytes are used. Within the bytes, bits 7 ... 0 are used, with bit 7 corresponding to the leftmost pixel.
Alternatively, VPOKE can also be written directly into the screen memory , but there is no linear
relationship between the character bytes and the address as in the OUT command, which already
performs the conversion of the addresses. With the command OUT $ 900,1 the display can be switched
to the connected LCD, with OUT $ 900,0will switch back to TV output. By default, the video mode starts
with TV display.

3 video drivers with PWM functions


3.1 PWM 4 x 8 bit driver (library code 0xB0)

3.1.1 General
This driver provides 4 pulse width modulated outputs. These have a resolution of 8 bits and a frequency
of about 61 Hz. In addition, there is a video video to 0 as far as possible compatible display, however, of
each line only the erten 24 characters are visible.

3.1.2 Hardware
The 4 PWM channels are connected to the data bits D4 ... D7, the data bits D0 ... D3 can be set via the
address ranges 0x800 ... 0x803 (data) and 0x810 ... 0x813 (data direction) as well as via the IN ( ) and
ADC () functions freely.

3.1.3 Functions
The current driver has no additional functions installed, the control is via the "normal" BASIC output
commands. To activate the driver, you only need to switch to USER video mode using VMODE 7 . When
activating and exiting the video mode, all PWM channels are set to 0.
The individual channels are controlled by means of OUT commands to the addresses 0x900 ... 0x903, a
read back is possible via the IN () function. The following table shows an overview of the usable I / O
addresses:

I / O address access function

0x800 R/W Data signal D0

0x801 R/W Data signal D1

0x802 R/W Data signal D2

0x803 R/W Data signal D3

0x808 R/W Data signal STROBE

0x809 R/W Data signal BUSY

0x810 W Data direction D0 (0 = IN, 1 = OUT)

0x811 W Data direction D1 (0 = IN, 1 = OUT)

0x812 W Data direction D2 (0 = IN, 1 = OUT)

0x813 W Data direction D3 (0 = IN, 1 = OUT)

0x818 R/W Data direction STROBE

0x819 R/W Data direction BUSY

0x900 R/W Pulse width at D4 (0 ... 255)

0x901 R/W Pulse width at D5 (0 ... 255)

0x902 R/W Pulse width at D6 (0 ... 255)

0x903 R/W Pulse width at D7 (0 ... 255)

3.2 PWM 8 x 8 bit driver (library code 0xB1)


3.2.1 General
This driver provides 8 pulse width modulated outputs. These have a resolution of 8 bits and a frequency
of about 61 Hz. In addition, there is a video video to 0 as far as possible compatible display, however, of
each line only the erten 24 characters are visible.

3.2.2 Hardware
The 8 PWM channels are connected to the data bits D0 ... D7.

3.2.3 Functions
The current driver has no additional functions installed, the control is via the "normal" BASIC output commands. To
activate the driver, you only need to switch to USER video mode using VMODE 7 . When activating and exiting
the video mode, all PWM channels are set to 0.
The individual channels are controlled by means of OUT commands to the addresses 0x900 ... 0x907, data can be
read back via IN (). The following table shows an overview of the usable I / O addresses:

I / O address access function


0x808 R/W Data signal STROBE

0x809 R/W Data signal BUSY

0x818 R/W Data direction STROBE

0x819 R/W Data direction BUSY

0x900 R/W Pulse width at D0 (0 ... 255)

0x901 R/W Pulse width at D1 (0 ... 255)

0x902 R/W Pulse width at D2 (0 ... 255)

0x903 R/W Pulse width at D3 (0 ... 255)

0x904 R/W Pulse width at D4 (0 ... 255)

0x905 R/W Pulse width at D5 (0 ... 255)

0x906 R/W Pulse width at D6 (0 ... 255)

0x907 R/W Pulse width at D7 (0 ... 255)

3.3 PWM 2 x 8 bit + 2 x pulse driver (library code 0xB2)

3.3.1 General
This driver provides 2 pulse width modulated outputs. These have a resolution of 8 bits and a frequency
of about 61 Hz. In addition, there are two pulse outputs with which periodic pulses can be generated in
the range of 0 ... 2.24 milliseconds. The repetition frequency corresponds to the vertical synchronizing
frequency, ie approx. 50Hz for PAL and 60Hz for NTSC. In addition, there is a video mode 0 as far as
possible compatible display, however, only the first 20 lines are displayed of which only 28 characters are
visible.

3.3.2 Hardware
The 2 PWM channels are applied to the lines D6 and D7, the two pulse channels on the data lines D4 and
D5. The data lines D0 ... D3 as well as BUSY and STROBE can be set via the address ranges 0x800 ...
0x809 (data) and 0x810 ... 0x819 (data direction) as well as via the IN () and ADC () functions (the latter
only D0 .. .D3) use freely.
3.3.3 Functions
The current driver has no additional functions installed, the control is via the "normal" BASIC output commands. To
activate the driver, you only need to switch to the USER video mode using VMODE 7 . When activating and
exiting the video mode, all PWM channels are set to 0.
The individual channels are controlled by means of OUT commands to the addresses 0x900 ... 0x903, the set values
can also be read back via IN (). The following table shows an overview of the usable I / O addresses:

I / O address access function

0x800 R/W Data signal D0

0x801 R/W Data signal D1

0x802 R/W Data signal D2

0x803 R/W Data signal D3

0x808 R/W Data signal STROBE

0x809 R/W Data signal BUSY


0x810 W Data direction D0 (0 = IN, 1 = OUT)

0x811 W Data direction D1 (0 = IN, 1 = OUT)

0x812 W Data direction D2 (0 = IN, 1 = OUT)

0x813 W Data direction D3 (0 = IN, 1 = OUT)

0x818 R/W Data direction STROBE

0x819 R/W Data direction BUSY

0x900 R/W Pulse width at D4 (0 ... 559)

0x901 R/W Pulse width at D5 (0 ... 559)

0x902 R/W Pulse width at D6 (0 ... 255)

0x903 R/W Pulse width at D7 (0 ... 255)

4 drivers for additional memory

4.1 Memory driver for 2K internal RAM (library code 0xF0)


This driver uses 2K of internal memory, using part of the screen memory and part of the array. This driver
is mainly used to test programs that need XMEM. Only the video modes 0 and 5 are usable, with the
video drivers at least the LCD drivers should work.

4.2 Memory driver for 64K external RAM (library code 0xF1)
This driver allows the use of the XRAM64 memory module as described in the extensions. Pages 0 ... 255
can be used, with only 32K RAM pages 0 ... 127.

4.3 Memory driver for 12K internal RAM (library code 0xF2)
This driver uses the free 12K of internal memory when using an ATMega1284P. Pages 0 to 48 are
available.

AVR-ChipBasic2 programs

1 Program overview
In the current version the following programs are included with the system:

 SETKBD -DE-
 SETKBD -US-

 Serial Load

 CBTerm mini

 Clone644

 Bench

 chip-8

2 keyboard configuration
By means of these programs it is possible to install alternative keyboard assignments. The currently set
layout is displayed in the lower part of the main menu. After the start of the corresponding program, the
display in the main menu changes and the new keyboard layout is effective immediately.

2.1 SETKBD -DE-


Sets the keyboard layout to German layout. This assignment is also set after flashing a new version.

2.2 SETKBD -US-


Sets the keyboard layout to US layout.

3 The serial charger


The serial charger makes it possible to remotely control the system to a certain extent. This also enables use cases
without screen output. This is the case, for example, when "only" an LCD is to be controlled. The outputs and
keystrokes described below relate to the computer connected to the ChipBasic2 system via the serial system
interface and running a terminal program.
The loader takes a certain special position within the programs. With a special signature ("L" as 13th byte) it can
neither be started nor edited. At system startup, a loader is searched for and the first one found is started. This is
independent of a set autostart function.
Both the program upload (ASCII and X-modem) and the configuration of the system are possible.
After starting the system, the serial loader reports via the serial system interface with the following message:

Press space to start!


If only "nonsensical" characters are received here, it should be checked whether the settings of 1200 or
2400 bps, 8 bit, 2 stop bits are correct.
The loader is started by means of the space bar, this must be done within approx. 2 seconds. The central
point in the loader is the main menu, to which you can return from almost any position with the space bar.

----------------------------
ChipBasic2 Serial Loader
----------------------------
S = Show Status
U = Upload (XMODEM)
T = Text Upload (ASCII)
A = Set Autostart
C = Config Hardware
Q = Quit

3.1 Show Status


The S key can be used to display a list of internally stored programs. After the program number are the program
name, the program type and the marking for an active autostart.
With the spacebar (and also all other letter, number and character keys) you get back to the main menu

----------------------------
Status
----------------------------
P1: SerialLoader LOADER
P2: BASIC
P3: BASIC
P4: BASIC (A)
P5: BASIC
P6: BASIC
P7: BASIC
P8: BASIC
Space returns to main menu
Press any key!

3.2 Upload (XMODEM)


The U key is used to switch to the upload menu.

----------------------------
XModem Upload
----------------------------
P1: SerialLoader LOADER
P2: BASIC
P3: BASIC
P4: BASIC (A)
P5: BASIC
P6: BASIC
P7: BASIC
P8: BASIC
Space returns to main menu
Select Program (1..8) :
The upload is started by selecting one of the programs (buttons 1 ... 8 ), with the space bar you get back
to the main menu. If the loader has been selected, there is still a security prompt, because you can lock
yourself out by overwriting the loader itself.
The actual upload starts after 10 seconds, so that enough time is available on the terminal program to
start the upload there as well. When all data have been transferred, the upload menu is displayed again.
Only if the loader has been overwritten will the system be restarted.

3.3 Text Upload


The T key is used to switch to the text upload menu. This can be used to transmit BASIC source programs. These
are translated to the binary form after the transfer, if the first character of the file name is not an underscore _ .

----------------------------
Text Upload
----------------------------
P1: SerialLoader LOADER
P2: BASIC
P3: BASIC
P4: BASIC (A)
P5: BASIC
P6: BASIC
P7: BASIC
P8: BASIC
Space returns to main menu
Select Program (1..8) :
The upload is started by selecting one of the programs (buttons 1 ... 8 ), with the space bar you get back
to the main menu. The loader can not be overwritten in this way, if you select this for overwriting, an error
message is displayed.
Since the image memory is used as a text buffer, a colorful "letter clutter" will appear on the screen (if
connected) of the ChipBasic2 system. This is normal.

3.4 Autostart
The A button can be used to set the autostart function. Autostart is programmable for programs 1 to 7, it can not be
turned off. The autostart function can not be set to a loader.

----------------------------
Autostart
----------------------------
P1: SerialLoader LOADER
P2: BASIC
P3: BASIC
P4: BASIC (A)
P5: BASIC
P6: BASIC
P7: BASIC
P8: BASIC
Space returns to main menu
Select Autostart (1..7) :2
Autostart is now set to program 2.

3.5 config hardware


The key C can be used to configure the hardware of the target system. The settings correspond to the "normal"
configuration page. With the key 8 , the settings made are saved and the system is restarted. If the menu is left with
the space bar, the settings made are lost.

----------------------------
ChipBasic2 Configuration
----------------------------
(1) Serial speed: 2400 Bps
(2) I2C speed : 400 kHz
(3) SPI speed : 5 MHz
(4) EEPROM addr : 0
(5) Line end : only LF
(6) Serial I/O : simple
(7) Serial Input: PD3
(8) Store
Space returns to main menu
Select Parameter (1..8) :

3.6 Quit
With the key Q , the loader is stopped and the autostart function is executed.

----------------------------
Serial Loader Quit
----------------------------

4 The communication program CBTerm mini


This section is now part of the user manual. Please read the user manual for more information on this.
5 system clones (Mega644 / P)
The structure of the Clone program is similar to the configuration page, where the current configuration is
taken as default.

5.1 The assignment of the function keys


The currently active function is shown inverted, the selection is made using the cursor up and cursor down keys. The
bottom line contains the possible commands, the colors correspond again to the keys ESC and F1 ... F4 and have the
following functions:

Leave program

Change selected setting

Clone system
5.1.1 Exit (ESC)
After a query whether to exit the program, the system returns to the main menu.

5.1.2 Change (F1)


Each time the button is pressed, the currently selected setting changes.

5.1.3 Serial speed


At this point, the speed of the serial interface can be switched between 1200 and 2400 bps. With the
BASIC command BAUD the speed can be temporarily adjusted in the program, after the end of the
program it is reset to the value set here.

5.1.4 I2C speed


Here, the speed of the I2C interface between 100 and 400 kHz can be switched. Most I2C devices handle
400kHz, for compatibility reasons the slow speed can be used.

5.1.5 SPI speed


Here, the speed of the SPI interface between 156 kHz and 5 MHz can be switched.

5.1.6 EEPROM address


This allows to set the EEPROM address for the data EEPROM (XPOKE / XPEEK).

5.1.7 End of line


This key can be used to specify the type of line end for the serial and parallel interface. LF only (Unix /
Linux), CR only (Mac) and CR + LF (Windows) are possible.

5.1.8 Serial Interface - Type


If, for example, you want to use a different RS232 level converter than the existing circuit, you can switch
this here. Simple is the original circuit, with standard RX and TX working like any other UART.

5.1.9 Serial interface - input pin


Since the original wiring of the serial interface already occupies the TX1 pin (PD3) of the ATMega644P,
there is the possibility to switch the input pin of the serial system interface between PD1 (necessary for
ATMega644P) and PD3 (compatibility mode). Switching is possible for both types, but the 644P's second
serial interface can not be used in compatibility mode.
5.1.10 Autostart
If no key is pressed in the intro screen, a program can be started automatically. The autostart jumper
provided in earlier versions is no longer queried and should be left open. The programs 1 ... 7 as well as a
decibation of the autostart function can be selected.

5.1.11 Clone System (F4)


This button starts cloning. The target microcontroller must also be a Mega644 and have a crystal or
external oscillator connected. Because in addition to the Flash and the Fusebits are programmed. Any
existing BASIC programs are of course also transmitted. This makes it possible to build another computer
without a PC to have / use.
After selecting the function, a security prompt follows, after which the copying process is started. To clone
the system, a cable with a special assignment is necessary, with which the SPI / ISP interfaces of both
systems are connected.

Host signal Host PIN Target signal Target PIN

GND 4,6,8,10 GND 4,6,8,10

VCC 2 VCC 2

MOSI 1 MOSI 1

MISO 9 MISO 9

SCK 7 SCK 7

SS 3 RESET 5

6 system benchmark
With Benchmark you can determine the effective clock frequency in MHz for all 8 video modes. Effective
clock frequency means at which clock frequency the microcontroller would be just as fast if he does not
have to do any video output etc. When the display appears, the program can be stopped by pressing any
key.
The displayed results are measured in NTSC mode (without mode 7 driver). For PAL, the results are
slightly better because the total number of lines is higher for the same number of visible lines.

7 The Chip8 interpreter


Chip8 is an interpreter that can run Chip8 or S-Chip programs in video mode 5 or video mode 7 (driver
code 0xA8 only).

7.1 The assignment of the function keys


The bottom line contains the possible commands, the colors correspond again to the keys ESC and F1 ... F4 and
have the following functions:
Leave program

Chip8 program received via X-modem

Save Chip8 program

Load Chip8 program

Start Chip8 program

7.1.1 Exit (ESC)


After a query whether to exit the program, the system returns to the main menu.

7.1.2 Recv (F1)


It is possible to transmit a Chip8 program via XMODEM. However, the program must be prepared
accordingly (see below). With the iram2 driver the upper 2K are ignored.

7.1.3 Save (F2)


A Chip8 program can be stored on the DataFlash module. Only empty memory locations or existing Chip8
programs can be overwritten. The file selection is made via the file selector box, the file name
corresponds to the program name and the type is automatically set to CH8 .

7.1.4 Load (F3)


A Chip8 program can be loaded from the DataFlash module. The file selection is done via the file selector
box, only CH8 files can be loaded.

7.1.5 Run (F4)


The loaded program is started. With CTRL-C the program execution can be aborted. If a program is in an
endless loop (eg at the end of the game), it can be restarted with the F10 key.
By holding down the left CTRL key you can access other functions:

Decrease delay, program execution becomes faster

Increase delay, program execution slows down

Since the Chip8 interpreter is much faster than the original, a delay can be set.  It corresponds to the
number of image lines that are being serviced before each command and is stored with the program.
Values between 6 and 20 are meaningful.

7.2 "Processing" of Chip8 programs


The Chip8 interpreter needs the data in a specific format, a 4Kbyte large memory image. In addition, the
delay and the key assignment are stored.
For this purpose, the programs must be downloaded from the Internet and converted using the programs
in the TOOL folder.

8 The 8080 emulator


The 8080 emulator is still at an early stage of development. It currently only supports the XRAM64
module and can serve as a template for your own applications.

You might also like