ugBASIC

The place for codemasters or beginners to talk about programming any language for the Spectrum.
User avatar
+3code
Manic Miner
Posts: 456
Joined: Sat Mar 19, 2022 7:40 am

ugBASIC

Post by +3code »

I've discovered this cross-compiler today. Seems interesting, I will take a look later.

https://github.com/spotlessmind1975/ugbasic
User avatar
g0blinish
Manic Miner
Posts: 289
Joined: Sun Jun 17, 2018 2:54 pm

Re: ugBASIC

Post by g0blinish »

32bit need
User avatar
+3code
Manic Miner
Posts: 456
Joined: Sat Mar 19, 2022 7:40 am

Re: ugBASIC

Post by +3code »

You can find the current version 1.13.2 (32 and 64 bits binaries) here: https://spotlessmind1975.itch.io/ugbasic-ide/purchase

Edit: The IDE contains the compilers and assemblers you require, and etc, is all-in-the-pack.

Edit 2: Now I'm not sure if the 32 bits version I pointed previously is really a 32 bits version, I've downloaded the installer labeled as "32 bits without the .NET" and downloaded the .NET package by my own and something is wrong.

Edit 3: Well, seems only the IDE is 32 bits, the console compiler is 64 bits, sorry.
Last edited by +3code on Thu Apr 13, 2023 7:55 pm, edited 2 times in total.
EdToo
Manic Miner
Posts: 228
Joined: Thu Nov 03, 2022 4:23 pm

Re: ugBASIC

Post by EdToo »

It does look very interesting. Thanks for sharing.
spotlessmind1975
Drutt
Posts: 21
Joined: Fri Aug 25, 2023 7:24 am

Re: ugBASIC

Post by spotlessmind1975 »

Hello everyone! :)

I am the author of ugBASIC and I'm really happy that it interests this community!

Allow me to answer and give some clarifications, with respect to the information contained in the previous messages:
+3code wrote: Thu Apr 13, 2023 6:57 pmEdit: The IDE contains the compilers and assemblers you require, and etc, is all-in-the-pack.
Surely this is the simplest and fastest way to use ugBASIC in a Windows environment.
+3code wrote: Thu Apr 13, 2023 6:57 pm Edit 2: Now I'm not sure if the 32 bits version I pointed previously is really a 32 bits version, I've downloaded the installer labeled as "32 bits without the .NET" and downloaded the .NET package by my own and something is wrong.

Edit 3: Well, seems only the IDE is 32 bits, the console compiler is 64 bits, sorry.
With respect to this point, I point out that, in recent days, the installation page has been completely revised, as well as the UBASIC-IDE, and now there is a more "symmetrical" management of the 64-bit and 32-bit versions.

In particular, this page contains, already precompiled, all executables for all targets and for all operating systems (Linux and Windows), both 64-bit and 32-bit, for the official version, for updates and for the beta. At the same time, the IDE is able to download the correct version of the executables, i.e. the 32-bit or 64-bit version, both for the stable version and for the beta version.

I hope it will come in handy!

Thank you, and have a nice day. :D
Wall_Axe
Manic Miner
Posts: 501
Joined: Mon Nov 13, 2017 11:13 pm

Re: ugBASIC

Post by Wall_Axe »

this is the kind of thing i get obsessed with lol

the download gave loads of security warnings but managed to get past them

EDIT-where is drop.png for this example?
https://retroprogramming.iwashere.eu/ug ... example_02

and wouldnt mind sprite.png

https://retroprogramming.iwashere.eu/ug ... example_08

or just what dimensions the png files are?

EDIT2 -
oh they are in the git

The sprite examples seem stuck on a screen that says 'bytes' so it seems they load but dont do anything.

I only need text mode anyway, but wouldnt have minded checking out the sprite demos
Wall_Axe
Manic Miner
Posts: 501
Joined: Mon Nov 13, 2017 11:13 pm

Re: ugBASIC

Post by Wall_Axe »

the wait command doesnt seem to work on spectrum

see the text scrolling demo

https://retroprogramming.iwashere.eu/ug ... dvanced_01

the formatting is messed up on this page:
https://retroprogramming.iwashere.eu/ug ... options_06

Its a very interesting project, just to balance the fault finding out a bit

in this language you dont seem to have to specify the length of strings in an array. Does the program just take the longest string and make it that size?

i tried this little program:
CLS
DIM r$(3,3)
r$(0,0)="north of the base entrance"
r$(0,1)="outside the base entrance"
r$(0,2)="south of the base entrance"
r$(1,0)="nw"
r$(1,1)="base entrance"
r$(1,2)="sw"
r$(2,0)="ne"
r$(2,1)="e"
r$(2,2)="se"
PRINT AT$(0,3)+r$(0,2)

but it prints:
'south of the base entranceso'
Wall_Axe
Manic Miner
Posts: 501
Joined: Mon Nov 13, 2017 11:13 pm

Re: ugBASIC

Post by Wall_Axe »

This can be gotten around by using locate instead.
It's a great project thanks.
I was just saying recently that I needed something with long variable names and a lack of line numbers and this comes along.


INKEY$ doesnt seem to work?
spotlessmind1975
Drutt
Posts: 21
Joined: Fri Aug 25, 2023 7:24 am

Re: ugBASIC

Post by spotlessmind1975 »

Hi Wall_Axe, I'm flattered by the interest and by compliments!

Thank you! :D
Wall_Axe wrote: Fri Aug 25, 2023 7:20 pm the download gave loads of security warnings but managed to get past them
Yes, I'm aware of the problem. Using the IDE it should be possible to avoid them, but I haven't actually been able to find a general method, or in any case a method compatible with the "open source" nature of the project.. On the other hand, the alternative is to recompile each compiler by hand. This is quite a tedious task on Windows, due to the lack of a standard build environment.
Wall_Axe wrote: Fri Aug 25, 2023 7:20 pm oh they are in the git
Yes, they are. Actually, using the IDE simplifies the download of the components necessary for compilation but creates a separation between program and repository. I opened an issue on github to keep track of this specific improvement on the IDE, i.e. the ability to download one or more examples directly, so you don't have to search for them on git.
Wall_Axe wrote: Fri Aug 25, 2023 7:20 pm The sprite examples seem stuck on a screen that says 'bytes' so it seems they load but dont do anything.
I only need text mode anyway, but wouldnt have minded checking out the sprite demos
For this example, however, I don't think it works on ZX Spectrum. The reason is simple. The ugBASIC language is an isomorphic language: this means that it puts the programmer in communication with the underlying hardware as much as possible, without abstractions. Which means that if a piece of hardware isn't there, its instructions do nothing. That is, there is no "translation" in some sort of emulated hardware.

Going back to the example, the ZX Spectrum doesn't have hardware sprites so instructions won't do anything. On the other hand, it has the GET IMAGE, PUT IMAGE and BLIT IMAGE instructions, which allow you to emulate software sprites easily. For a simple guide please take a look here
Wall_Axe wrote: Fri Aug 25, 2023 9:04 pm the wait command doesnt seem to work on spectrum
I tried but I think the WAIT...MS command works fine. Probably the problem lies rather with horizontal scrolling, which I'm not sure if it works properly. I opened an issue on github just to keep track of the problem.
Wall_Axe wrote: Fri Aug 25, 2023 9:04 pm the formatting is messed up on this page:
I believe the output is correct, at least compared to what is explained here. Can you be so kind as to tell me what, in your opinion, the expected output would be? So I can open an issue if that's the case.
Wall_Axe wrote: Fri Aug 25, 2023 9:04 pm in this language you dont seem to have to specify the length of strings in an array. Does the program just take the longest string and make it that size?
No, it doesn't. In ugBASIC, string arrays are structures that are fixed in size but composed of strings whose length is dynamic, just like in standard BASIC. In other words, the elements of the array, in turn, are dynamic strings, ie they occupy the effective space of the string (plus some control bytes). So an array of strings occupies a certain number of fixed bytes, related to the array length, and then occupies as many bytes as the strings are long.
Wall_Axe wrote: Fri Aug 25, 2023 9:04 pm i tried this little program:
Yes, I confirm that there is something wrong. I opened an issue on github to track the bug. As soon as it is resolved, the fix will be made available directly on the download page.
Wall_Axe wrote: Sat Aug 26, 2023 12:21 am This can be gotten around by using locate instead.
Yes, generally speaking, the ugBASIC language exposes multiple ways to solve the same problem. It is an approach borrowed from other BASIC languages of the 80s and 90s, and allows to adapt the software to the hardware, and not vice versa, as happens nowadays.
Wall_Axe wrote: Sat Aug 26, 2023 12:21 am INKEY$ doesnt seem to work?
Yes, there is something wrong. I opened an issue to track down the problem.

Thank you again for the compliments, and I'm glad it can come in handy! :D
Wall_Axe
Manic Miner
Posts: 501
Joined: Mon Nov 13, 2017 11:13 pm

Re: ugBASIC

Post by Wall_Axe »

Thanks I hope to get back into coding once inkey$ works,as that's all I need.

Is it safe to use return like this:?

Procedure printthis
For C=1to 6
If C=3 then
Return
Endif
Next
End proc

I've used languages in the past that struggle with using return inside of two control structures.

Thanks for ugbasic,I'm looking forward to trying the blit functions.
spotlessmind1975
Drutt
Posts: 21
Joined: Fri Aug 25, 2023 7:24 am

Re: ugBASIC

Post by spotlessmind1975 »

Hi Wall_Axe, thank you for the feedback!

I'm already actively working on solving the problems, together with the development of the features of course.
Wall_Axe wrote: Sat Aug 26, 2023 2:21 pm Thanks I hope to get back into coding once inkey$ works,as that's all I need.
In the meantime, you can use other commands. If you need to wait for a key just use the WAIT KEY command. If you need to control a specific character (eg "A"), try KEY PRESSED (KEY A). Finally, if you need to wait for a string, try INPUT.
Wall_Axe wrote: Sat Aug 26, 2023 2:21 pm Is it safe to use return like this?
I've used languages in the past that struggle with using return inside of two control structures.
Yes, of course. There are no limits to the use of returns within control structures, even the most intricate ones. Actually, it's best to use EXIT PROC instead of RETURN. It is convenient to use RETURN if you want the procedure to return a value. If, on the other hand, you don't care then it's fine to use EXIT PROC. If it can help you, on this page is present a guide that explains how to use and exit from procedures. I hope it will come in handy! :)
Wall_Axe
Manic Miner
Posts: 501
Joined: Mon Nov 13, 2017 11:13 pm

Re: ugBASIC

Post by Wall_Axe »

Thanks I'll give those a try later.

I meant the actual webpage seems messed up
https://retroprogramming.iwashere.eu/ug ... options_06

Usually the code is seperate so it is easy to copy and paste but on this one particular webpage it's doesn't seem formatted.

Thanks for the help
spotlessmind1975
Drutt
Posts: 21
Joined: Fri Aug 25, 2023 7:24 am

Re: ugBASIC

Post by spotlessmind1975 »

Hi Wall_Axe, about this:
Wall_Axe wrote: Sat Aug 26, 2023 2:21 pm Thanks I hope to get back into coding once inkey$ works,as that's all I need.
the problem has been fixed, so you can download again the compiler. :)
Wall_Axe wrote: Sat Aug 26, 2023 4:01 pm I meant the actual webpage seems messed up
Usually the code is seperate so it is easy to copy and paste but on this one particular webpage it's doesn't seem formatted.
Thank you for the report.
I'll check it as soon as possible and correct it.

Thank you again, and have a nice retrocoding! :D
Wall_Axe
Manic Miner
Posts: 501
Joined: Mon Nov 13, 2017 11:13 pm

Re: ugBASIC

Post by Wall_Axe »

Thanks for that, starting up coding again soon
Wall_Axe
Manic Miner
Posts: 501
Joined: Mon Nov 13, 2017 11:13 pm

Re: ugBASIC

Post by Wall_Axe »

i just installed the IDE which installed the compiler..how do i update the compiler?

I tried downloading the IDE again and got the old compiler.

EDIT - oh i downloaded it in the IDe itself thanks.

It's best to use INKEY$ only once per loop.


In Sinclair basic my menu consists of an arrow which you move down by pressing 'a' in sinclair basic it was slow but now its instantaneous. Pretty cool thanks.
spotlessmind1975
Drutt
Posts: 21
Joined: Fri Aug 25, 2023 7:24 am

Re: ugBASIC

Post by spotlessmind1975 »

Hi Wall_Axe, and thank you for your kind feedback.
Wall_Axe wrote: Sun Aug 27, 2023 1:34 pm i just installed the IDE which installed the compiler..how do i update the compiler?
I tried downloading the IDE again and got the old compiler.
EDIT - oh i downloaded it in the IDe itself thanks.
Yeah, IDE exists just for things like that. :D
Wall_Axe wrote: Sun Aug 27, 2023 1:34 pm It's best to use INKEY$ only once per loop.
In Sinclair basic my menu consists of an arrow which you move down by pressing 'a' in sinclair basic it was slow but now its instantaneous. Pretty cool thanks.
In ugBASIC your progam talks directly with the hardware, as much as possible, of course.
So this is probably why things, shall we say, speed up in some ways. 8-)
Wall_Axe
Manic Miner
Posts: 501
Joined: Mon Nov 13, 2017 11:13 pm

Re: ugBASIC

Post by Wall_Axe »

I was checking out that other lib that you do .
It can create side scrolling games like flappy bird on all those platforms from only commands found in the lib?

For spectrum side scrolling games, custom machine code might have to be used for each game.
spotlessmind1975
Drutt
Posts: 21
Joined: Fri Aug 25, 2023 7:24 am

Re: ugBASIC

Post by spotlessmind1975 »

Hi Wall_Axe!
Wall_Axe wrote: Sun Aug 27, 2023 4:01 pm It can create side scrolling games like flappy bird on all those platforms from only commands found in the lib?
In general it should be possible, but IMHO it's not the right approach to use with ugBASIC. Being an isomorphic language, its goal is to give the maximum for a single platform, as did the BASICs of the time. The fact that you can reuse the same source on multiple platforms we can see as a "plus" rather than something necessary. So it's possible to do what you want, but it doesn't necessarily mean that you do it the same way.
Wall_Axe wrote: Sun Aug 27, 2023 4:01 pm For spectrum side scrolling games, custom machine code might have to be used for each game.
If ugBASIC doesn't get there with its primitives, it is still possible to use inline assembly, as well. ;)
Wall_Axe
Manic Miner
Posts: 501
Joined: Mon Nov 13, 2017 11:13 pm

Re: ugBASIC

Post by Wall_Axe »

hey here is a question for you.

If I define an array twice (with the same name) does it not take up twice the memory, but just gets initialized in the same place, and does it get filled with zeros?

I have a function called initgame, in which I fill arrays with the state of a new game. I have to put SHARED for every array at the beginning of the PROC, does this take up more memory than doing it out of a PROC?
spotlessmind1975
Drutt
Posts: 21
Joined: Fri Aug 25, 2023 7:24 am

Re: ugBASIC

Post by spotlessmind1975 »

Hi Wall_Axe, I'm just bothering you to tell you that the remaining bugs have been fixed: download the compilers again to get the fixes. :D
Wall_Axe wrote: Mon Aug 28, 2023 6:47 pm If I define an array twice (with the same name) does it not take up twice the memory, but just gets initialized in the same place, and does it get filled with zeros?
As with all BASIC, it is not necessary to declare variables before using them. But when it happens, it is the last that wins over the first. However, the definition does not match where variables are allocated and initialized. This happens, always, at the beginning of the program.

Take this program:

Code: Select all

	CLS
	DIM a AS BYTE(10)
	a(1) = 5
	DIM a AS BYTE(10)
	a(2) = 10
	FOR i = 0 TO 9
		PRINT a(i)
	NEXT
This example program allocates, at the beginning of execution, an array named a of 10 elements (from 0 to 9, ugBASIC has 0-based arrays), each element is just 1 byte large, and setting each value to zero. All this is done at compile time: the array is ready before the program starts. It then assigns the value of 5 to element 1 and the value 10 to element 2. It is like if the program was written like this:

Code: Select all

	DIM a AS BYTE(10)
	'''
	CLS
	a(1) = 5
	a(2) = 10
	FOR i = LBOUND(a) TO UBOUND(a)
		PRINT a(i)
	NEXT
Indeed, there is also a more efficient way to initialize an array: at the level of the declaration itself. For example, that code can be written like this, and if written like this, initialization of the array happens, again, at compile time. That is, before the program starts, the vector will already be ready to be used. Like this:

Code: Select all

	DIM a AS BYTE(10) = #{ 0, 5, 10, 0, 0, 0, 0, 0, 0, 0 }
	'''
	CLS
	FOR i = LBOUND(a) TO UBOUND(a)
		PRINT a(i)
	NEXT
Wall_Axe wrote: Mon Aug 28, 2023 6:47 pm I have a function called initgame, in which I fill arrays with the state of a new game. I have to put SHARED for every array at the beginning of the PROC, does this take up more memory than doing it out of a PROC?
The SHARED statement causes the variable used within the procedure to be the one defined in the main program, instead of the local one. This means that the space to which it will refer is the original one, allocated and prepared at the beginning of the program. If you declare a variable with the same name as one you have defined as SHARED, the declaration will simply be ignored. For example:

Code: Select all

	DIM a AS BYTE(10) = #{ 0, 5, 10, 0, 0, 0, 0, 0, 0, 0 }
	'''
PROCEDURE initgame
	SHARED a : ' makes main program's "a" visibile to procedure
	DIM a AS BYTE(5) : ' this declaration will be ignored
	'''
	CLS
	FOR i = LBOUND(a) TO UBOUND(a)
		PRINT a(i)
	NEXT
END PROC

initgame[]

However, if you remove the SHARED, then the program will print an array of 5 elements valued at zero, all made up of zeros, and a total of 15 bytes will be occupied: 10 for the first "a" array, and 5 for the second "a". Note, however, that procedures in ugBASIC are "stackless". This means that, even if you don't define an array as SHARED, each time you enter the routine the array will neither be reallocated nor initialized again.
Wall_Axe
Manic Miner
Posts: 501
Joined: Mon Nov 13, 2017 11:13 pm

Re: ugBASIC

Post by Wall_Axe »

Thanks, I'm progressing with ugBasic quite well

When trying to create a variable with REM in the name it thinks I want to do REM

So for example a variable called areModel will have REM appear in the middle so I cant use that variable name.

Apart from that its going well, thanks.
Wall_Axe
Manic Miner
Posts: 501
Joined: Mon Nov 13, 2017 11:13 pm

Re: ugBASIC

Post by Wall_Axe »

I have a string array.

When I change one of the strings in the array the spectrum crashes.
It was a blank string but then I changed it to something about ten characters long.

I assume its overwriting something?
spotlessmind1975
Drutt
Posts: 21
Joined: Fri Aug 25, 2023 7:24 am

Re: ugBASIC

Post by spotlessmind1975 »

Hi Wall_Axe, and thank you for the feedback.
Wall_Axe wrote: Tue Aug 29, 2023 1:44 am When trying to create a variable with REM in the name it thinks I want to do REM
I fixed this behaviour in the develop version of the IDE, but the IDE itself is released less frequently than compiler, so you have to have a bit of patience. :D

In respect of this:
Wall_Axe wrote: Tue Aug 29, 2023 2:39 pm When I change one of the strings in the array the spectrum crashes.
a piece of code could help conduct a diagnostic, or maybe if you want you can open a bug on github. In any case, check the limits of the array: in ugBASIC, array are 0 based. So if you do

Code: Select all

DIM a AS STRING(42)
you can access from a(0) to a(41). If you have to do FOR...NEXT on arrays, you could use LBOUND and UBOUND, that avoid to go out of the array,

Let me know.
Wall_Axe
Manic Miner
Posts: 501
Joined: Mon Nov 13, 2017 11:13 pm

Re: ugBASIC

Post by Wall_Axe »

Hi

This program illistrates what I think is going on :
DIM marray$(3)
marray$(3)="hi"

PRINT marray$(3)
marray$(2)="this is going to overwrite the previous string in the array"
PRINT marray$(3)
PRINT marray$(3)
PRINT marray$(2)
PRINT marray$(3)
PRINT marray$(3)
PRINT marray$(3)
PRINT marray$(3)
PRINT marray$(3)
When I change the string in an array it just overwrites memory.
So, I need a way of creating an array of strings where each string is say, 20 characters long. SO the memory is reserved.
spotlessmind1975
Drutt
Posts: 21
Joined: Fri Aug 25, 2023 7:24 am

Re: ugBASIC

Post by spotlessmind1975 »

Hi Wall_Axe, and thank you for your feedback.
Wall_Axe wrote: Fri Sep 01, 2023 4:35 pm DIM marray$(3)
marray$(3)="hi"
The DIM marray$(3) means an array of 3 elements, from marray$(0) to marray$(2). By accessing to the index 3, you are accessing outside of the limits of the array, by overwriting memory in some place, and so disrupting the executable.
Wall_Axe wrote: Fri Sep 01, 2023 4:35 pm So, I need a way of creating an array of strings where each string is say, 20 characters long.
By defining DIM marray$(3),you are allocating spaces for 3 dynamic strings, from 0 to 255 characters (under ZX Spectrum). The exact space allocated depends on the size of each string (it is the sum), while the complessive memory allowed by the string subsystem depends on the DEFINE STRING SPACE and DEFINE STRING COUNT commands. By default, on ZX Spectrum, it is allowed to define up to 1024 bytes of strings, with a maximum of 255 separate strings (with about 3.068 bytes of RAM allocated).
Post Reply