How to write a program: Basic course #8

Read in: IT 🇮🇹   EN 🇺🇸

Benvenuti all'ottava puntata del corso sul linguaggio Basic! Nel video di oggi, impariamo come scrivere un programma, semplice, a partire da un'idea.

Subscribe my YouTube channel ValorosoIT. Retro technology, vintage audio, retro computers, experiments and tests. Retroprogramming, Basic. Commodore, IBM, Atari, Apple, Texas Instruments, Amstrad, MSX.

https://youtu.be/8sAyWz91-GY

How to write a program: the flowchart

Supponiamo di voler scrivere un programma, molto semplice, per generare le varie righe che compongono una tabellina. Non sempre è necessario scrivere un diagramma di flusso del programma. Per programmi molto semplici, queste operazioni si possono fare a mente. Comunque, per rendere più chiara l'idea, ne scriviamo una bozza.

How to write a program in Basic V2 Commodore 64 Atari Altirra QB64 flowchart

Il diagramma è venuto malissimo! E' brutto! Comunque... gli ellissi identificano l'inizio e la fine del programma.

Parallelograms indicate the inputs and outputs. For example, the questions that the computer asks us and the strings that it returns to monitor.

Rectangles indicate operations. Finally, the rhombuses indicate the conditions.

Let's briefly analyze the flow digram of the program to generate a times table

In the first parallelogram, we immediately ask which tab to print and put the value in the variable T.

To print the value of this times table, the times table T (for example of the 5), what should the computer write to monitor?

5 x 1, 5 x 2, 5 x 3, etc. etc. up to 5 x 10.

Next, we set a counter and call it N. As soon as you start the computer, the memory is clean and N is equal to 0. In the first operation, we set N = N + 1, then, if N = 0, dopo l'operazione N = 1.

Follow me on Instagram channel. Retro technology, Commodore, vintage audio, retro computers, experiments and tests. Retroprogramming, Basic. Commodore, IBM, Atari, Apple, Texas Instruments, Amstrad, MSX.

Nell'esempio della tabellina del 5, la prima riga che il computer deve scrivere è:

5 x 1 = 5

Therefore: "T x N = " (nell'esempio "5 x 1 = ") and then (T*N), inteso come il risultato dell'operazione.

After you print the value and then 5 x 1 = 5 the computer should consider whether to continue to the next cycle. With the rhombus we define a condition: N is it less than 10? If the condition is met, then, if N is less than 10 (in the first cycle is worth 1) we redo the program from where the arrow points, so as to get to a N equal to 2, then to a N uguale a 3, ecc...

The computer repeats the cycle until N is not equal to 10. When I got to nine, N = 9, N + 1 = 10, the computer writes 5 x 10 = 50.

N is less than 10? No, because it is equal to 10 and then the computer exits the program. End!

How to write a program in Basic V2 Commodore 64 times table

Additional program specifications

In addition to defining the operating logic of the program, it is also good to define some specifications. Quite simply, we want to indicate:

  • che l'input e l'output del programma siano in formato testo;
  • che il programma deve essere compatibile con tutti i Commodore a 8 bit, il basic dell'Atari, il QB64, QuickBasic, GwBasic e PC-Basic.

La seconda condizione ci complica un po' la vita, in quanto possiamo solamente utilizzare i comandi di base, comuni a tutti i Basic.

How to write a program in Basic C128 Commodore 128 dual monitor times tables graphic WinVICE VICE emulator

How to write a program: convert the flowchart to Basic

Dopo aver avuto l'idea ed aver definito la logica e le specifiche, possiamo scrivere il programma, codificandolo in Basic.

This is the first version of the program, adhering to the flowchart.

10 REM IL MIO OTTAVO PROGRAMMA IN BASIC
20 REM VISUALIZZAZIONE TABELLINA
30 REM (C) 2021, WWW.VALOROSO.IT
50 PRINT "TABELLINA";
60 INPUT T
100 N = N + 1
110 PRINT STR$(T); " X"; STR$(N); " ="; STR$(T * N)
120 IF N < 10 THEN GOTO 100

After the implementation of the program, in an attempt to improve it, a cycle was implemented FOR... NEXT instead of condition IF... THEN. So here is the second version of the program:

10 REM IL MIO OTTAVO PROGRAMMA IN BASIC
20 REM VISUALIZZAZIONE TABELLINA
30 REM (C) 2021, WWW.VALOROSO.IT
50 PRINT "TABELLINA";
60 INPUT T
100 FOR N = 1 TO 10
110 PRINT STR$(T); " X"; STR$(N); " ="; STR$(T * N)
120 NEXT N

The third version of the program is improved, including a control of the number of the table to be generated. In fact, previous versions also generated non-existent boards, for example that of 20 and that of -3. In this latest version, the computer writes only boards 1 through 10.

Follow me on Instagram channel. Retro technology, Commodore, vintage audio, retro computers, experiments and tests. Retroprogramming, Basic. Commodore, IBM, Atari, Apple, Texas Instruments, Amstrad, MSX.

10 REM IL MIO OTTAVO PROGRAMMA IN BASIC
20 REM VISUALIZZAZIONE TABELLINA
30 REM (C) 2021, WWW.VALOROSO.IT
50 PRINT "TABELLINA";
60 INPUT T
70 IF T < 1 OR T > 10 THEN GOTO 50
100 FOR N = 1 TO 10
110 PRINT STR$(T); " X"; STR$(N); " ="; STR$(T * N)
120 NEXT N

With the third version of the program, we also need to revise the flowchart, which, from ugly, now becomes very ugly!

How to write a program in Basic V2 Commodore 64 Atari Altirra QB64 modified flowchart

Analyzing the program in Basic to generate the boards

Le prime tre righe del programma, la 10, la 20 e la 30 contengono dei commenti. Abbiamo visto l'istruzione REM, per includere dei commenti, nella first episode of the course on Basic.

The computer asks what tab number to generate at lines 50 and 60. It doesn't matter how many numbers we jump between rows, but what matters is that the rows are all in a row. The computer, however, puts the rows in order autonomously.

The computer enters the number of tabs we want and print in the variable T. I split PRINT from INPUT to make the program also compatible with the Basic of ATARI. We have already studied these two instructions in the first episode of the course on Basic.

So, now, we find ourselves with the first step achieved: we have the value T of the table that we want to print. We also leave here some spaces, you never know that they come in handy afterwards.

How to Write a Program in QuickBasic QB64 PC BASIC Compiler GwBasic times table

At line 70, the computer checks that the required tab is between 1 and 10. If this is not the case, it again requires the table to be generated.

At line 100 the loop begins FOR N... NEXT N, which closes at line 120. We have already talked about the cycle FOR in the third video of the course on Basic.

The times table line is printed at line 110.

Follow me on Instagram channel. Retro technology, Commodore, vintage audio, retro computers, experiments and tests. Retroprogramming, Basic. Commodore, IBM, Atari, Apple, Texas Instruments, Amstrad, MSX.

Through PRINT, il computer scrive a monitor "T X N = (T*N)", ad esempio: 5 X 1 = 5.

To convert the number into a text, we use the STR$, which we talked about in the episode 2 of the course on Basic.

T is the times table number (e.g. 5). The computer writes 5, semicolon to concatenate strings, X (multiplication symbol), semicolon again N, and then the result of multiplication T*N. The result is also converted to a string with STR$(T*N).

The computer repeats the writing of the table line 10 times as indicated in the loop FOR.

How to write a program in basic Atari 800XL Altirra emulator

Documentation

I have prepared a brief compendium with all the commands in Basic V2 of the Commodore 64. You can find it if you follow This link.

Ecco il programma, scritto in minuscolo, adatto ad essere copiato ed incollato all'interno dell'emulatore VICE per Commodore 16, C64, C128, Commodore PET, Vic20, nonché nel QB64 ed emulatore Altirra per Atari.

10 rem il mio ottavo programma in basic
20 rem visualizzazione tabellina
30 rem (c) 2021, www.valoroso.it
50 print "tabellina";
60 input t
70 if t < 1 or t > 10 then goto 50
100 for n = 1 to 10
110 print str$(t); " x"; str$(n); " ="; str$(t * n)
120 next n

Credits: In the video tutorial, SID music is ACE II by Rob Hubbard.

To be notified when I publish other episodes of the course on the Basic language, or when I publish other videos, experiments and reviews related to retro computers and vintage electronics, I invite you to subscribe to the YouTube channel and activate the notification bell.

Subscribe my YouTube channel ValorosoIT. Retro technology, vintage audio, retro computers, experiments and tests. Retroprogramming, Basic. Commodore, IBM, Atari, Apple, Texas Instruments, Amstrad, MSX.

Posted in Retro Computer, Retro Technology and Vintage Electronics, All articles.

2 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *