R. T. RUSSELL BBC BASIC (Z80) Manual Table of Contents Introduction Before You Start System Requirements Technicalities Configuration Running BBC BASIC (Z80) General Information Introduction Line Numbers Statement Separators The Line Editor Expression Priority Order of Evaluation Examples Variables Specification Numeric Variables Real Variables Integer Variables Static Variables Boolean Variables Numeric Accuracy String Variables and Garbage Strings Garbage Generation Memory Allocation Arrays Program Flow Control Introduction Loop Operation Errors Program Structure Limitations Leaving Program Loops REPEAT…UNTIL Loops Changing the Loop Variable Popping the Inner Variable Local Variables Stack Pointer Indirection Introduction Query Byte Access Query as a Byte Variable Exclamation Dollar Use as Binary Operators Power of Indirection Operators Operators and Special Symbols Keywords Error Handling Introduction Types of Errors Trapping Errors Reasons for Trapping Errors Error Trapping Commands Error Reporting ERR ERL REPORT Error Trapping Examples Procedures and Functions Introduction Names Functions and Procedure Definitions Starting a Definition The Function/Procedure Body Ending a Definition Single Line Functions/Procedures Extending the Language Passing Parameters Formal and Actual Parameters Local Variables Re-entrant Functions/Procedures Assembler Introduction Instruction mnemonics Statements Labels Comments Constants Define Byte - DEFB Define Word - DEFW Define Message - DEFM Reserving Memory The Program Counter Using DIM to Reserve Memory Moving HIMEM to Reserve Memory Length of Reserved Memory Initial Setting of the Program Counter The Assembly Process OPT Assembly at a Different Address OPT Summary Code Assembled Starting at P% Code Assembled Starting at O% How the Assembler Works Saving and Loading Machine Code Programs *SAVE *LOAD Conditional Assembly and Macros Introduction Conditional Assembly Macros Statements and Functions Introduction Syntax Symbols ABS ACS ADVAL AND ASC ASN ATN AUTO BGET# BPUT# CALL Parameter Table Parameter Formats CHAIN CHR$ CLEAR CLOSE# CLG CLS COLOUR COS COUNT DATA DEF DEG DELETE DIM Dimensioning Arrays Reserving an Area of Memory DIV DRAW EDIT ELSE END ENDPROC ENVELOPE EOF# EOR ERL ERR EVAL EXP EXT# FALSE FN FOR GCOL GET/GET$ GOSUB GOTO HIMEM IF INKEY/INKEY$ INPUT INPUT LINE INPUT# INSTR INT LEFT$ LEN LET LIST LIST IF Limitations LISTO Bit Settings LN LOAD LOCAL LOG LOMEM MID$ MOD MODE MOVE NEW NEXT NOT OLD ON Limitations ON ERROR OPENIN OPENOUT OPENUP OPT Code Assembled Starting at P% Code Assembled Starting at O% OR OSCLI PAGE PI PLOT POINT POS PRINT General Information Print Format Control STR$ Format Control - SS Format Selection - NN Number of Digits - PP Zone Width - WW Changing the Print Control Variable Examples PRINT# PROC PTR# PUT RAD READ REM RENUMBER REPEAT REPORT RESTORE RETURN RIGHT$ RND RUN SAVE SGN SIN SOUND SPC SQR STEP STOP STR$ STRING$ TAB TAN THEN TIME TO TOP TRACE TRUE UNTIL USR VAL VDU VPOS WIDTH Operating System Interface Introduction File Specifiers Symbols Accessing Star Commands Syntax Case Conversion Special Characters Resident Star Commands *BYE *CPM *DIR *DRIVE *ERA *LOAD *OPT *REN *RESET *SAVE *TYPE BBC BASIC (Z80) Disk Files Introduction The Structure of Files Basics Serial (Sequential) Files Random Access Files Indexed Files Files in BBC BASIC (Z80) Introduction How Data is Read/Written How Data is Stored Numeric Data How Strings are Stored How Files are Referred To File Buffering Disk File Commands Introduction Filenames Organisation of Examples Program File Manipulation SAVE LOAD CHAIN MERGE *ERA *REN *DIR Disk Data Files Introduction Opening Files File Opening Functions OPENOUT OPENIN OPENUP CLOSE# INPUT# PRINT# EXT# PTR# EOF# BGET# BPUT# Serial Files Introduction Character Data Files Ex 1 - Writing Serial Character Data Ex 2 - Reading Serial Character Data Ex 3 - Writing 'AT END' of Character Files Mixed Numeric/Character Data Files Ex 4 - Writing a Mixed Data File Ex 5 - Reading a Mixed Data File Ex 6 - Writing 'AT END' of Mixed Files Compatible Data Files Ex 7 - Writing a Compatible Data File Ex 8 - Reading a Compatible Data File Random (Relative) FIles Introduction Designing the File Record Structure Accessing The Records Ex 9 - Simple Random Access File Ex 10 - Simple Random Access Database Ex 11 - Random Access Inventory Program Indexed Data Files Deficiencies of Random Access Files The Address Book Program File Organisation Program Organisation The Index Ex 12 (the LAST) The Binary Chop Explanation Table of ASCII Codes Mathematical Functions Error Messages and Codes Summary Trappable - Program Trappable - Operating System Untrappable - Error Code 0 Details Accuracy lost Arguments Array Bad call Bad command Bad DIM Bad HEX Bad name Bad program Bad string Can’t match FOR Channel Close error DIM space Directory full Disk full Division by zero Escape Exp range Failed at nnn File exists File not found FOR variable LINE space Log range Missing , Missing " Missing ) Missing # Mistake -ve root No GOSUB No FN No FOR No PROC No REPEAT No room No such FN/PROC No such line No such variable No TO Not LOCAL ON range ON syntax Out of DATA Out of range RENUMBER space Silly String too long Subscript Syntax error Too big Too many open files Type mismatch Format of Program and Variables in Memory Memory Map The Memory Map Memory Management Limiting the Number of Variables String Management Garbage Generation Memory Allocation for String Variables Program Storage in Memory Line Length Line Number Statements Line Terminator Variable Storage in Memory Integer Variables Real Variables String Variables Fixed Strings