Elementary BASIC code snippets for Beginner

The place for codemasters or beginners to talk about programming any language for the Spectrum.
firelord
Manic Miner
Posts: 557
Joined: Wed Nov 03, 2021 10:57 am
Location: Greece - Thessaloniki

Re: Elementary BASIC code snippets for Beginner

Post by firelord »

I the lab I have some core2duo with 2 GB and some with 1GB. Basin and SpecBAS are very "heavy" when run with WINE.

The memory problems will continue if I stay with wine so, I re-visited linux port SpecBAS to avoid wine. Linux port of SpecBAS runs smoothly but it is an old version (0.914) and practically not usable in a class enviroment. Dunny said I could convert MainForm.pas to linux but I do not have the knowledge and the time for this task.

So again I must look for a ready native linux solutions.

Is there a native Linux Basin version out there?


(Note: both Basin & SpecBAS run very smoothly in my home PC. ZX Dunny has done an amazing job!!)
Last edited by firelord on Fri Jan 14, 2022 9:59 am, edited 1 time in total.
firelord
Manic Miner
Posts: 557
Joined: Wed Nov 03, 2021 10:57 am
Location: Greece - Thessaloniki

Re: Elementary BASIC code snippets for Beginner

Post by firelord »

{deleted double post}
Last edited by firelord on Fri Jan 14, 2022 9:59 am, edited 1 time in total.
firelord
Manic Miner
Posts: 557
Joined: Wed Nov 03, 2021 10:57 am
Location: Greece - Thessaloniki

Re: Elementary BASIC code snippets for Beginner

Post by firelord »

{deleted double post}
firelord
Manic Miner
Posts: 557
Joined: Wed Nov 03, 2021 10:57 am
Location: Greece - Thessaloniki

Re: Elementary BASIC code snippets for Beginner

Post by firelord »

A selection of some programs posted here plus some more is uploaded in pastebin.com
These can be printed in 1 page and passed to the students.

https://pastebin.com/sFKaJNTg

I Still haven't found a workarround to the problem I have in linux (wine +basin is very heavy for my lab PCs).
The solution is something like basin native in linux or javascript.
I'm trying a javascript vesrion of bas2tap but needs work...
Also,I found a pascal compiler but couldn't use it to compile Basinc .
firelord
Manic Miner
Posts: 557
Joined: Wed Nov 03, 2021 10:57 am
Location: Greece - Thessaloniki

html2tap : Tinymce->html2txt->zmakebas->qaop

Post by firelord »

I found a crude solution for running a simple Basin-like enviroment on low-end linux PCs...
I use tinymce as editor then with php I use Html2txt to filter html elements. Then I run server-side zmakebas to create a TAP file and after that I open the resulting file with qaop ( I 've done it also with jsspeccy-mobile but jsspeccy can't save).

It might seems complex but I already had those subsystems ready so it took me about 10 minutes to glue these together.

I don't really care about security since this will be used in a local server in a school lab LAN.
I will post the code when I find time to remove some useless parts of code &comments. I might also post a live version in my server for a limited time to get sone feedback/ideas.

On another note: I found that bas2tap is not that compatible. It failed on very simple programs (posted in this thread). Zmakebas converted everything I tried.

I'm still trying to figure how to avoid the shell_exec and use native javascriot bas2tap...
firelord
Manic Miner
Posts: 557
Joined: Wed Nov 03, 2021 10:57 am
Location: Greece - Thessaloniki

Re: Elementary BASIC code snippets for Beginner

Post by firelord »

Another code snippet :

Code: Select all

5 INPUT "ENTER YOUR NAME(S) :";b$
10 LET A$=" HELLO "+b$+"! YOU ARE THE BEST!!!! "
20 LET A$=A$(2 TO )+A$(1)
30 PRINT AT 10,1;A$(1 TO 30)
40 GOTO 20
firelord
Manic Miner
Posts: 557
Joined: Wed Nov 03, 2021 10:57 am
Location: Greece - Thessaloniki

Re: html2tap : Tinymce->html2txt->zmakebas->qaop

Post by firelord »

firelord wrote: Sun Feb 06, 2022 3:52 pm I found a crude solution for running a simple Basin-like enviroment on low-end linux PCs...
I use tinymce as editor then with php I use Html2txt to filter html elements. Then I run server-side zmakebas to create a TAP file and after that I open the resulting file with qaop ( I 've done it also with jsspeccy-mobile but jsspeccy can't save).

It might seems complex but I already had those subsystems ready so it took me about 10 minutes to glue these together.

I don't really care about security since this will be used in a local server in a school lab LAN.
I will post the code when I find time to remove some useless parts of code &comments. I might also post a live version in my server for a limited time to get sone feedback/ideas.

On another note: I found that bas2tap is not that compatible. It failed on very simple programs (posted in this thread). Zmakebas converted everything I tried.

I'm still trying to figure how to avoid the shell_exec and use native javascriot bas2tap...
I've posted (for a limited time) what I made for using in linux (and also in mobiles) : basic2tape.dimotika.tk .
You can post comments ideas here (unless someone believes that it needs to be in a new thread) : viewtopic.php?p=85630#p85630
I will post the source code after I do some clean up...
firelord
Manic Miner
Posts: 557
Joined: Wed Nov 03, 2021 10:57 am
Location: Greece - Thessaloniki

Re: Elementary BASIC code snippets for Beginner

Post by firelord »

In a combination of htm2tap & the impressive https://stever.github.io/jsspeccy3/ I managed to do the first lesson of Sinclair Basic.

In it's final state the program we did was this:

Code: Select all

10 PRINT "Hello! ";
20 PAPER RND*7
30 BORDER  RND*7
40 GO TO 20
The steps of the lesson (each step is one sub-unit) that were followed until we make the final version of the program
https://pastebin.com/raw/vAy6NWMf

I did this lesson in 3rd-6th elementary school classes.
After the 3rd Step (UNIT 1.3) the kids seemed impressed :) . All kids like the zx spectrum colors :)
firelord
Manic Miner
Posts: 557
Joined: Wed Nov 03, 2021 10:57 am
Location: Greece - Thessaloniki

Re: Elementary BASIC code snippets for Beginner - ATM machine

Post by firelord »

The 3rd lesson I desinged is the Bank ATM cash machine.
I have explained them in the first lesson that hackers are always try to stop the execution of a program(Shift+Space BREAKs the program) ,get their code (with LIST command) and modify them -with good or bad results (eg delete a line with 700 +ENTER) !

The code beggins like this:

Code: Select all

20 LET BANKMONEY=10000
500 PRINT "YOU HAVE ";BANKMONEY;" IN BANK"
600 INPUT "HOW MUCH MONEY YOU WANT?";GETMONEY
700 LET BANKMONEY=BANKMONEY-GETMONEY
800 GO TO 500
after a few steps & explanations the code gets to that form:

Code: Select all

10 LET MYPIN=1234
20 LET BANKMONEY=10000
100 PRINT "Welcome to the ATM"'"--------------------"
200 INPUT "ENTER YOUR PIN:";PIN
300 IF PIN=MYPIN THEN GO TO 500
400 PRINT "WRONG PIN!":GO TO 100
500 PRINT "YOU HAVE ";BANKMONEY;" IN BANK"
600 INPUT "HOW MUCH MONEY YOU WANT?";GETMONEY
650 IF GETMONEY>BANKMONEY THEN PRINT "TOO MUCH!!!":GO TO 500
700 LET BANKMONEY=BANKMONEY-GETMONEY
800 GO TO 500

The steps that I have planned so far can be seen here https://pastebin.com/raw/WVvKk9bn.Each time the student must add/modify some lines.

At some point I might tell the students to add colors (eg lines 400&650 should be red) and check the number of PIN tries.
firelord
Manic Miner
Posts: 557
Joined: Wed Nov 03, 2021 10:57 am
Location: Greece - Thessaloniki

Re: Elementary BASIC code snippets for Beginner

Post by firelord »

I don't know if anyone can find these useful but I'll post them here (maybe you could archive them somewhere)

These are the free USBorne.com BASIC books (from 80s) edited so the programs are for the ZX Spectrum (so you do not need to check the combatibillity page for each program).


usborne.com_computer-funKIDS_PDF010ZXOnly.pdf - Here I made changes in many places and removed/cropped some uneeded pages (was for other computers)
https://drive.google.com/file/d/1jL0MEy ... sp=sharing

[email protected] (Here only the RND command was needed to change)
https://drive.google.com/file/d/1noTU3o ... sp=sharing
firelord
Manic Miner
Posts: 557
Joined: Wed Nov 03, 2021 10:57 am
Location: Greece - Thessaloniki

Re: Elementary BASIC code snippets for Beginner

Post by firelord »

I found that https://yohan.es/swbasic/ online interpteter supports in some degree Sinclair Basic and it is very easy to use -eg in a classroom. I uploaded a slight modified version here http://webbasic.dimotika.tk/ (I added some programs from Simple Basic book in Help section)

This support other BASIC variants too but my interest was only about Sinclair Basic.

Disadvantages/Differences of https://yohan.es/swbasic/
- You must write GOTO not GO TO
-

Code: Select all

650 IF GETMONEY>BANKMONEY THEN PRINT "TOO MUCH!!!" : GOTO 500
will ALWAYS run the GOTO 500 part (IF THEN supports only 1 command)
firelord
Manic Miner
Posts: 557
Joined: Wed Nov 03, 2021 10:57 am
Location: Greece - Thessaloniki

Re: Elementary BASIC code snippets for Beginner

Post by firelord »

firelord wrote: Mon Oct 10, 2022 7:05 pm I uploaded a slight modified version here http://webbasic.dimotika.tk/ (I added some programs from Simple Basic book in Help section)

This support other BASIC variants too but my interest was only about Sinclair Basic.
All free dot.tk domains are down so the above script is in https://webbasic.sxoleio.win/
Post Reply