ZX Format #07: Comprehensive Guide to BB Commands

BB Commands.  
(End)

music by MIDISOFT
(C)D.Rudovsky
_______________________________

In this article, I will finish the description of BB and give some advice on its use. The Spectrum OS has its own internal clock, i.e., a variable that stores the number of fifty-hundredths of a second (interrupts) that have occurred since the computer was turned on. The creators of BB decided to use this capability to organize a clock in the program. The CLOCK "string" command allows you to set the current time value and set an alarm. To set the alarm, the first character in the string must be the character A (alarm - to wake). The string should be entered in the format: "hh:mm:ss", for the alarm, seconds are not specified. To use the alarm features, an additional format has been introduced: CLOCK n, where:

n=0 - do not display readings, turn off the alarm;
n=1 - display time in the upper corner of the screen, turn off the alarm;
n=2 - do not display time, issue a sound signal for the alarm;
n=3 - display time and issue a sound signal for the alarm;
n=4 - do not display time, switch to the line when the alarm goes off;
n=5 - similar to n=4 with time displayed on the screen;
n=6 - similar to n=4 with a sound signal issued before switching;
n=7 - n=5 and n=6 together;
n=8..9999 - set the line number to which the transition will occur when the alarm goes off.

Example:
10 PRINT " 346*789=? "
20 CLOCK "00:00:00": CLOCK "A00:01"
30 CLOCK 1000: CLOCK 7
F 40 INPUT X
50 IF X=346*789 THEN PRINT "Very Good!" ELSE "Bad result!": GO TO 40
F 60 CLOCK 0
70 STOP
F1000 CLOCK 0
1010 PRINT "No more time!"
1020 STOP

Explanations:
In line 20, we set the system clock to 0, and we set the alarm for 1 minute. In line 30, we set the transition line and the clock operation mode (see above). Then we prompt for a number input, and if the result is correct, and less than a minute has passed, we will get the message "Very Good," the clock will be set to passive mode (line 60), and the program will stop. If the result is incorrect but there is still time, the corresponding message will be displayed, and the program will return to line 40. If time runs out, regardless of the result, a sound signal will be issued, and the program will transition to line 1000. WARNING!!! The transition by alarm occurs only after the entire current line has been executed. Also, this mode does not work during text editing.

The SORT command is used for sorting arrays and strings. Its format:
SORT [INVERSE] var, where:

INVERSE - an optional parameter indicating the sort condition, i.e., if present, the sort will be in descending order of values; otherwise, it will be in ascending order;
var - the name of the array or string.
Sorting occurs for character arrays by the first character by default. To sort by another character, the construction is used: SORT S$() (N TO), where:

S$ - character array;
N - the character number by which the sorting will be performed.
To sort a part of an array, use:
SORT S$(N TO M), where:
N,M - sorting boundaries.

Example:
10 DIM a$(100,10)
20 FOR I=1 TO 100
30 FOR J=1 TO 10
40 LET A$(I,J)= CHR$(RND*25+65)
50 NEXT J: PRINT A$(I)
60 NEXT I
70 PRINT "Sorting for 1st char:"
80 SORT A$
90 FOR I=1 TO 100
100 PRINT A$(I)
110 NEXT I
120 PRINT "Sorting for 2nd char:"
130 SORT A$()(2 TO)
140 FOR I=1 TO 100
150 PRINT A$(I)
160 NEXT I
170 STOP

With this, I will finish the description of BB commands, providing at the end a reference for key and command correspondence (all commands are entered in pseudo-graphics mode):

[A] - ALTER [6] - AUTO
[C] - CLOCK [1] - DEF KEY
[1] - DEF PROC [7] - DELETE
[D] - DO [P] - DPOKE
[0] - EDIT [E] - ELSE
[3] - END PROC [I] - EXIT IF
[F] - FILL [G] - GET
[CS]+[6] - JOIN [CS]+[6] - KEYIN
[8] - KEYWORDS 0 [9] - KEYWORDS 1
[L] - LOOP [O] - ON
[N] - ON ERROR [Q] - POP
[2] - PROC [9] - RENUM
[R] - ROLL [S] - SCROLL
[M] - SORT [T] - TRACE
[P] - USING

BB Functions.
In addition to additional commands, BB offers several new functions that are also entered like ordinary user-defined functions but are perceived by BB as internal. All functions can be conditionally divided into three groups: logical, mathematical, and others.

Logical functions include:
AND(n,m) [FN A(] - logical AND;
OR(n,m) [FN O(] - logical OR;
XOR(n,m) [FN X(] - exclusive OR.

Mathematical functions include:

a) Format conversion functions:
BIN$(n) [FN B(] - conversion of a decimal number to a binary string;
DEC(string) [FN D(] - conversion of a string containing a hexadecimal number to decimal.
HEX$(n) [FN H(] - conversion of a decimal number to a hexadecimal string;
USING$(format, number) [FN U$(] - signed representation of a number in the specified format.

b) Extended standard functions:
COSE(n) [FN C(] - a faster and coarser version of cos;
SINE(n) [FN S(] - analogous for sin;
DPEEK(n) [FN P(] - analogous: 256*PEEK(N+1)+PEEK(N);
RNDM(n) [FN R(] - analogous: n*RND.

Other functions include functions for determining memory size, screen content, etc.

CHAR$(n) [FN C$(] - converts a number in the range 0-65535 to an equivalent two-character string;
FILLED() [FN F(] - the number of image elements filled by the last FILL command;
INSTRING(n,str1,str2) [FN I(] - returns the position of the first character of string 2 when viewing string 1, starting from a specified starting position. If string 2 is not found within string 1, it returns 0.
MEM() [FN M(] - returns the amount of free memory;
MEMORY$() [FN M$(] - returns the value of all memory from 0 to 65535 interpreted as one string;
MOD(n1,n2) [FN V(] - returns the remainder of dividing n1 by n2;
NUMBER(string) [FN N(] - converts a two-character string into a two-byte number, where each byte contains a number corresponding to the specified ASCII code;
SCRN$(y,x) [FN K$(] - returns the character located on the screen at the specified position;
STRING$(n,string) [FN S$(] - repeats the string a specified number of times;
TIME$() [FN T$(] - returns a string containing the current time.

Features of programming in BB.

Expanding the capabilities of standard Basic, BB also changes the programming methods themselves, so when working in the BB environment, it is advisable to consider the following points:
1) As a result of changing the operation of the FOR...NEXT operator, its execution speed significantly increases when working with integers in the range 0..65535, so try to stick to integer loops.
2) The introduction of procedures and associated local variables has made it possible to significantly save memory through variable localization. This also allows you to move towards the concept of program structuring.
3) The availability of formatted output and the introduction of a window interface allows for the orderly display of necessary information on the screen.
4) The sorting command allows for more efficient use of BB in organizing databases.

_______________________________

Contents of the publication: ZX Format #07

  • From the Authors
    Update on SMUC, distribution issues, and plans for future ZX Format issues. Authors address outdated SMUC info and distribution problems of ZF-6. Upcoming content includes game descriptions and new projects.
  • Аторы журнала
    Contact information and editorial team details for ZX-Format No.7. Provides mailing and electronic addresses, as well as contact phone numbers. Information on the availability of their website and specific contact instructions.
  • Содержание номера
    The article provides an overview of notable software releases on the St. Petersburg market for autumn. It also includes detailed descriptions of games, programming tips, and hardware projects. Interviews, philosophical tales, and reader letters enrich the issue.
  • Игрушки - Welcome
    An overview of software novelties for ZX Spectrum, including games like 'Los Angeles Drugs Bust' and 'Jungle Warfare'. Each game description provides insights into graphics, gameplay, and features. A variety of genres from action to strategy are covered, showcasing the diversity of software offerings.
  • Игрушки - Алешкин А.В.
    The article describes the game 'TAI-PAN' as an arcade-economic game set in the 19th-century East, focusing on trading and survival amidst pirates and danger. It details the gameplay mechanics, such as trading goods, managing finances, and navigating seas with different ships. Despite its engaging plot and interface, the game didn't achieve much popularity in Russia.
  • Игрушки - Soft
    A whimsical narrative in a fantastical world where colors converse with the Last, a character recounting tales of ancient humans, coders, and a mysterious past. The story explores themes of language, translation, and the creation of 'the Last' amidst fantastical beings like flying hippos and sea giraffes. It serves as a fictional narrative with humorous elements, blending science fiction with satire.
  • Игрушки - Alex ASP
    A parody on Tolkien's 'The Lord of the Rings' named 'Bored of the Rings' by Delta 4 is explored. The text references adaptations, humorous adventures of characters like Fordo and Bimbo, and differing versions from Delta 4 over the years. Anticipated prequels and correspondence excerpts with Delta 4's Fergus McNeill are mentioned.
  • Игрушки - Гил-Гелад
    The article provides a detailed guide on navigating the 3D Construction Kit interface for ZX Spectrum. It explains menu options for file management, game setup, and in-game conditions. Additionally, it covers object creation, editing, and logic implementation within the program.
  • Программистам - Дмитрий Рудовский
    The article concludes the description of BB commands and provides tips on their usage. It details the usage of the CLOCK command for time and alarm management on ZX Spectrum. Additionally, it explains the SORT command for array sorting and introduces new logical and mathematical functions.
  • Программистам - Angel
    Introduction to assembly programming for beginners, covering basic concepts and commands. Detailed explanation of processor registers and flags, with examples. Offers practical advice on transitioning from Basic to assembly language.
  • Программистам - GreenFort
    Discussion on fast calculations in assembler for tasks like vector graphics and astronomy. Describes procedures for binary division and multiplication, with examples for different byte sizes. Highlights the adaptability of these methods for increased precision.
  • Программистам - TP, Stinger
    Detailed technical description of the Mod file format for music composition on ZX Spectrum, focusing on structure and data offsets for title, instruments, and patterns.
  • Программистам - Research
    The article describes the capabilities and limitations of the Convert program, focusing on its use for converting images to the BMC format. It includes technical details about the program's functions, such as dithering methods, sprite and screen format output, and the removal of extraneous dots. Additionally, the article briefly discusses the source code of X-Color and its potential applications.
  • Обзор
    The article discusses the ENLiGHT'97 demo-party held in St. Petersburg on August 24, 1997, featuring platforms like Spectrum, Amiga, and PC. The event attracted around 1100 delegates, leading to overcrowding and technical issues, which caused the cancellation of the second day. Despite these issues, the event was generally enjoyable, and there is hope for another event in 1998.
  • Обзор
    Review of VideoFAIR exhibition in Manezh with highlights on video and audio equipment. Amiga-service and various companies showcased their technological advancements in video editing and broadcast systems. Notable innovations include 3D laser-scanned displays and professional audio solutions.
  • Железо - Nemo
    Discussion of KAY technology export to decentralize Spectrum production. Highlights potential benefits and challenges of local manufacturing. Emphasizes quality assurance and support systems.
  • Железо
    The article describes the development of a new Scorpion motherboard, focusing on enhancing graphics, speed, and compatibility with modern peripherals like IBM keyboards and mice. It introduces the GMX (Graphic Memory Extension) board, designed to upgrade existing Scorpion models to match the capabilities of the new motherboard. The GMX board offers significant improvements in memory, graphics, and processing speed, while maintaining compatibility with ZX Spectrum and Pentagon standards.
  • Железо
    The article provides a detailed overview of two popular audio amplifiers for ZX Spectrum users in St. Petersburg. It highlights the advantages and specifications of the 2 X 2W low-voltage amplifier and the 2 X 22W car amplifier. The article also includes a price list and ordering instructions through the 'Nemo' company.
  • Примьера
    The article describes the improvements and features of the Turbo Assembler version 1.1 for ZX Spectrum. It highlights the differences from version 1.0, such as bug fixes, screen size changes, and added features like line editor and syntax checking. It also details the memory allocation and provides a guide on using the editor and compiler functions.
  • Примьера - STS
    Description of the Riff Tracker MOD-editor for General Sound, its features, and functionalities. Provides detailed instructions on using editing and sample management. Notes on the current version limitations and expected improvements.
  • Примьера - Paul Atrides, Alex Noman
    Presentation of Oberon Creative Pack, consisting of ZX-WinWord and Sprite Cutter. ZX-WinWord is a text editor combining text and graphics with advanced features. Sprite Cutter allows sprite creation and manipulation in various formats.
  • Примьера
    Presentation of the second demo version of the game Headball by ZX-Masters, discussing its features and improvements since the first demo. The game offers two-player mode, four levels, three types of projectiles, various options, and computer difficulty settings. Availability of Turbo mode and enhanced synchronization and animation make it unique among other Spectrum games.
  • Интервью - Ruster
    Interview with Digital Reality about ongoing projects like DOOM and Paradise Lost. Discussion of challenges and progress in game development. Preview of their submissions for the ENLiGHT event.
  • Интервью - Ruster
    Interview with members of the newly formed group EXTREME. They work on demos for Spectrum and Amiga platforms and discuss their team members and activities. The interview also touches upon the state of the Amiga scene in Moscow.
  • Интервью - Борис Прытков
    Interview with Samara-based Spectrum enthusiasts discussing their achievements and challenges. Emphasis on community building and publication of Oberon magazine. Efforts to establish a Spectrum network and convert the game WALKER.
  • Интервью - Борис Прытков
    The article is an interview with members of the group Flash inc. discussing their projects for ZX Spectrum and PC, including a music editor with an innovative interface and a new multicolor graphic editor.
  • Интервью - Михаил Акимов
    Interview with Moscow-based group Progress discussing their current work on Spectrum demos, plans for future projects on Amiga, and opinions on the Russian demoscene.
  • Интервью - Михаил Акимов
    Interview with Felix about changes in the tech landscape, the enduring appeal of Amiga despite PC dominance, and his work on 'Winnie the Pooh - 2' for Spectrum.
  • Интервью - Ruster
    Interview with Slash about the ENLiGHT event, including sponsorship issues, attendee behavior, and the quality of music and demos. Discussion of the current state of the Spectrum and Amiga markets. Commentary on music trackers and the future of hardware development.
  • Интервью - Ruster
    Interview with V. Mednonogov after ENLiGHT'97 discussing impressions of the event, future of Spectrum, and his current project 'Black Raven'. Mednonogov shares his views on new hardware and software development and the importance of copyright. He also discusses his plans for upcoming projects and the challenges faced in game development.
  • Здесь был ты
    A satirical guide to gaining power and invisibility using magical rituals and Orbit gum.
  • Здесь был ты - Saggitarius
    A contemplative novella about a man's existential journey after encountering a mysterious individual offering a device called the Stop Crane. Through flashbacks, the protagonist reflects on his life, uniqueness, and his desire to break free from societal constraints. Ultimately, he faces the moral dilemma of using the Stop Crane to transcend time and existence.
  • Почта - Eagle Soft
    Critique of ZX-Spectrum software, highlighting the limitations of current programs and recommending the removal of outdated tools. Discussion on the limitations of assembly programs and the need for more efficient assemblers like M80. Evaluation of current music and graphic editors, with a focus on the redundancy of certain applications.
  • Почта
    Discussion of reader inquiries on ZX Format distribution and content. Responses include details on acquiring issues and technical insights on the KAY-256 computer. The magazine also addresses criticism of its market outlook article.
  • Почта
    This advertisement highlights XL Design Inc.'s software distribution campaign, offering games like 'Plutonia' and upcoming releases such as 'Mortal Kombat'. Mouse controllers are promoted with humorous selling points and pricing details. Studio LOGROS provides a wide range of software and peripherals, with options for local and remote purchases.
  • Разное - Александр Сысоев
    The article discusses the creation of an RPG game by the OBERON GROUP, inspired by 'Eye of Beholder'. It describes the game's humorous plot set in a distant galaxy and the battle against invaders on a planet named Agima. The team invites musicians, artists, coders, and scriptwriters for collaboration.
  • Разное - Viator
    The article describes the development of a new graphics editor called STATE OF THE ART for ZX Spectrum, aiming to improve upon existing editors like ART-STUDIO and ARTIST-2. The team AVALON, inspired by feedback from the SPECCY artist community, incorporates features from editors on Amiga and PC, while also addressing specific user requests. Key features include a user-friendly interface, enhanced magnify mode, advanced shape and window manipulation, and optimized performance.
  • Разное
    Discussion on enhancing consumer quality of Spectrum computers without altering their technical specifications. Suggestions include improving existing support, developing platform ideology, and structural changes. The article also touches on the potential of electronic books and their commercial viability.
  • Amiga Club - Максим Петров
    The article describes the author's admiration for the Amiga computer, emphasizing its aesthetic and technical merits compared to other platforms. It explores the author's programming experiences on Amiga, highlighting its efficiency and the impressive capabilities of its new hardware upgrades. The article concludes by reflecting on the unique community and passion of Amiga enthusiasts.