From Sinclair Wiki
Jump to navigation Jump to search

The SAM BASIC is an advanced and structured BASIC dialekt. It was written according the demand of the Miles Gordon Technology by Dr. Andrew Wright for the SAM Coupé computer.

At first glance it looks like and also its program editing enviroment, syntax of commands and some system variables are identical to the ZX BASIC and BETA BASIC. Internally it is a new elaborate programming language, that supports the advanced features of the Coupé (especially graphics modes, colour palette and 64 or 85 characters per line), works with the entire basic memory of 512KB RAM, has 56 mathematical functions and provides hexadecimal and binary conversions.

The SAM BASIC uses the computer's memory completely and effectively, has an allocation table of every 16KB memory page, respect a marked memory layout, fills memory pages with programs, procedures, functions, variables, arrays, graphics screens and system extensions and protects any part from being overwritten. This means, among other things, that SAM BASIC programs can be up to 480 Kbytes long, with individual string variables up to 65520 characters long and up to 65535 items in one dimension of data arrays.

The SAM BASIC paging system can be even extended to support more RAM, the maximum that the Coupé's hardware can control is 32 16KB pages.

This BASIC takes 32KB in two separate ROM pages, main first page at 0000H and the second, switchable if needed, at C000H. The lower ROM is always paged in unless user-loaded software initiates complex paging operations. The lower ROM pages in the upper ROM as required, for example, to handle floating-point calculations, BEEP or tape operations.

The speed of the SAM BASIC is a little slowed down because the ROM needs to hold, in permanently paged RAM, important variables like the PEN colour, screen MODE, the machine stack, information for interrupts, etc. That means that too much code cannot be run in the upper ROM, under the conditions of the Coupé's 32KB paging system. To get round this, some routines need to be copied from the upper ROM to a RAM buffer in the systempage for execution, although their speed is not critical, the copying process obviously imposes a slight delay. Moreover, several routines are quite convoluted. The PRINT routines, for example, start in the lower ROM, use the upper ROM where this is feasible for the interpretation of characters, and then use the lower ROM again for actually putting data on the screen.

Z80 restarts addresses in the SAM BASIC ROM are partly similar to the ZX Spectrum:

  • RST 00H - "start-up" code
  • RST 08H - errors handling
  • RST 10H - PRINT the character in the A register
  • RST 18H - get the current character (pointed to by CHAD variable) from a Basic line
  • RST 20H - get the next character by advancing CHAD
  • RST 28H - call the floating point calculator
  • RST 30H - CALL or JP to the upper ROM
  • RST 38H - maskable interrupt

Standard SAM BASIC routines and whole commands can be extended or replaced easily, by changing some system variables, so-called VECTORS:

  • NMIV - called when the BREAK button is pressed and normally points to an error handler, a temporary stack is provided (speccy emulators change this value to use it as a snapshot button)
  • FRAMIV - called by the frame interrupt every 50th of a second
  • LINIV - called when the value in the line interrupt port (249) matches the line, Y-coordinate (any value greater than 191 to the port disables this interrupt)
  • MIPV - MIDI input interrupt
  • MOPV - MIDI output interrupt
  • RST28V - called by the floating point calculator
  • RST30V - a user RST for anything users like
  • CMDV - called with A=code of character about to be executed or syntax checked (also to add new commands or provide some other actions for existing tokens)
  • EVALUV - called with A=current character in expression to evaluate (to add new functions)
  • MTOKV - called if the ROM does not recognise a potential spelled-out keyword
  • KURV - called before the BASIC editor's cursor is printed

The expansion named MasterBASIC brings some speed improvements, more comfortable program editing and tracing and an interrupt-driven video and sound capabilities.

External links