ugBASIC

The place for codemasters or beginners to talk about programming any language for the Spectrum.
Wall_Axe
Manic Miner
Posts: 501
Joined: Mon Nov 13, 2017 11:13 pm

Re: ugBASIC

Post by Wall_Axe »

here is my code:


when compiling for the zx spectrum it doesnt seem to do anything.
It should print the character generator screen
the relevant function called is initcharscreen [] which calls CLS
CLS isnt called as the 'bytes' thing is on the screen
spotlessmind1975
Drutt
Posts: 21
Joined: Fri Aug 25, 2023 7:24 am

Re: ugBASIC

Post by spotlessmind1975 »

Hi Wall_Axe, first of all thank you for your example!
Wall_Axe wrote: Thu Sep 07, 2023 1:54 pm here is my code:
I study your code carefully, to understand what's wrong (in the compiler, of course! :D )

Actually, frequent updates to the compiler are coming out these days, as the new version 1.14.2 is about to be released. So I recommend you update the compiler. If you use the IDE just go to Configuration > Compilers, and download the compiler for the ZX Spectrum.

This is the output using directly your source:
Image

It doesn't seem to work properly, but something shows anyway.
Now, however, I'll delve deeper.
Thank you again!
spotlessmind1975
Drutt
Posts: 21
Joined: Fri Aug 25, 2023 7:24 am

Re: ugBASIC

Post by spotlessmind1975 »

Hi Wall_Axe, first of all, thank you again for the source!
Wall_Axe wrote: Thu Sep 07, 2023 1:54 pm here is my code:
From a first analysis, I believe that the problem lies, or rather did lie, in the size of the executable. Due to some optimization failures, including duplication of constant strings and access to arrays with positions calculated at runtime rather than at compile time, the source became a bit too large to fit in the available memory.

I have introduced a preliminary optimization in the compiler for ZX Spectrum (which I recommend you download again, via IDE or from the dedicated page) which allows you to reuse the strings several times while always occupying the same space. At the same time, in the same compiler version, I introduced constants instead of simple numbers when accessing arrays.

For example, instead of writing

Code: Select all

r$(0,1)="outside the base entrance"
you should write

Code: Select all

r$(#0,#1)="outside the base entrance"
This suggests to the compiler that those numbers (0 and 1) are constants, so it can calculate the offset at compile time instead of at runtime. This greatly streamlines the resulting executable. In the future it is possible that these types of optimizations will be automatic, but in the meantime this workaround will help you. However, keep in mind that I am using this example source of yours as a "testbed" for further optimizations, so it is possible that in the next few days the compiler will become even more optimized.

Image

This is the result I get on Speccy.

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,
that was a very quick fix considering the size of the code.

I'll get back to to it then :D
Wall_Axe
Manic Miner
Posts: 501
Joined: Mon Nov 13, 2017 11:13 pm

Re: ugBASIC

Post by Wall_Axe »

this brought it down from 38k to 30k and now it works
Thanks
it still seems like a large executable compared to the size of the code.
Anything further that can be done?
spotlessmind1975
Drutt
Posts: 21
Joined: Fri Aug 25, 2023 7:24 am

Re: ugBASIC

Post by spotlessmind1975 »

Hi Wall_Axe, first of all thank you again for the feedback.

I took a few days to publish version 1.14.2, which already brings some notable improvements. Further optimizations have been made in the beta version, which is currently being tested. However, from a brief examination of the source, I could suggest a series of improvements to the code, and in particular the best one of all, which is to try to use strings as little as possible, especially when comparing options.

For example, it is better to initialize an array or vector at definition time than to do it at run time, especially if it is composed of numeric values. For example, this saves a few hundred bytes:

Code: Select all

DIM encounters(3,3) = _
	#{ 0, 0, 0, _
	    0, 0, 0, _
	    0, 1, 0 }
DIM encountername$(7,10)
DIM encounterstr(7,10) = _
	#{ 0, 0, 0, 0, 0, 0, 0, _
	    0, 4, 0, 0, 0, 0, 0, _
	    0, 4, 0, 0, 0, 0, 0, _
	    0, 4, 0, 0, 0, 0, 0, _
	    0, 3, 0, 0, 0, 0, 0, _
	    0, 4, 0, 0, 0, 0, 0, _
	    0, 4, 0, 0, 0, 0, 0, _
	    0, 0, 0, 0, 0, 0, 0, _
	    0, 0, 0, 0, 0, 0, 0, _
	    0, 0, 0, 0, 0, 0, 0 }
DIM partystr(9) = #{ 3, 0, 0, 0, 0, 0, 0, 0, 0 }
DIM partyskill(9) = #{ 3, 0, 0, 0, 0, 0, 0, 0, 0 }
Another optimization is to avoid executing "useless" instructions, in the sense that you initialize a value that you already know is the starting one. For example, by omitting these instructions, you gain an entire KB, and more!

Code: Select all

' lockeddoors$(0,0)=""
lockeddoors$(0,1)="e"
' lockeddoors$(1,2)=""
' lockeddoors$(1,0)=""
' lockeddoors$(1,1)=""
' lockeddoors$(1,2)=""
' lockeddoors$(2,0)=""
' lockeddoors$(2,1)=""
' lockeddoors$(2,2)=""
The next version will feature numerous optimization improvements, so stay tuned!
Wall_Axe
Manic Miner
Posts: 501
Joined: Mon Nov 13, 2017 11:13 pm

Re: ugBASIC

Post by Wall_Axe »

hi i tried compiling with the latest normal version available. It goes into an infinite loop and doesnt stop compiling.
(using the same code as pg.3 of this thread)
spotlessmind1975
Drutt
Posts: 21
Joined: Fri Aug 25, 2023 7:24 am

Re: ugBASIC

Post by spotlessmind1975 »

Wall_Axe wrote: Sun Sep 24, 2023 2:23 pm hi i tried compiling with the latest normal version available
Hi Wall_Axe, a new version is out! :D

Try it, and let me know.
Wall_Axe
Manic Miner
Posts: 501
Joined: Mon Nov 13, 2017 11:13 pm

Re: ugBASIC

Post by Wall_Axe »

Thanks I'll check it out
Post Reply