Welcome, Guest
You have to register before you can post on our site.



Search Forums

(Advanced Search)

Forum Statistics
» Members: 273
» Latest member: Zilog_Z80A
» Forum threads: 962
» Forum posts: 6,053

Full Statistics

Online Users
There are currently 65 online users.
» 0 Member(s) | 65 Guest(s)

Latest Threads
Forum: Wishlist
Last Post: boriel
Yesterday, 03:28 PM
» Replies: 1
» Views: 12
Print color bug
Forum: Bug Reports
Last Post: Darkstar
10-11-2022, 06:57 PM
» Replies: 18
» Views: 987
SIN and COS functions hav...
Forum: Bug Reports
Last Post: boriel
08-17-2022, 06:49 AM
» Replies: 2
» Views: 511
Binary into asm
Forum: Help & Support
Last Post: Nando
08-11-2022, 12:10 PM
» Replies: 12
» Views: 1,698
Set Number Layout to xx.0...
Forum: Help & Support
Last Post: boriel
08-02-2022, 10:32 PM
» Replies: 1
» Views: 471
Using Beepola with ZX BAS...
Forum: How-To & Tutorials
Last Post: Nando
08-02-2022, 09:25 PM
» Replies: 12
» Views: 21,628
Forum: Help & Support
Last Post: boriel
07-25-2022, 12:06 PM
» Replies: 2
» Views: 548
Features breaking compila...
Forum: Core
Last Post: Ljg701
06-19-2022, 08:44 AM
» Replies: 1
» Views: 617
New Text Adventure game u...
Forum: Gallery
Last Post: RandomiserUsr
06-01-2022, 10:21 PM
» Replies: 0
» Views: 460
Testing a variable within...
Forum: Help & Support
Last Post: RandomiserUsr
03-25-2022, 09:59 PM
» Replies: 11
» Views: 4,127

  ZX0 decompression examples
Posted by: RandomiserUsr - 03-31-2021, 08:29 AM - Forum: Help & Support - Replies (3)


I have been looking into the ZX0 library

Having created a compress file by running this "zx0 testscreen.scr"
And to us this file this is a test file I created t.bas

#include "zx0.bas"

10 dzx0Standard(@testscreen1, 16384)
20 GOTO 20

        incbin "testscreen.scr.zx0"
    end asm

When compiled and run it indeed does display the image on screen.
Some questions:-

Q1.I have been able to convert some artwork (PNG) to .SCR and compress this and then load it on screen BUT (newbie alert) I am running out of memory/program crashes/resets Emulator.
So the question is, can I do this and if so HOW?
(A) load from a M: drive (emulator allowing) and/or
(B) use the 128K Mode and then use the memory banks for images and leave the '48K' for the main game?

Q2. How can I display the SCR file but only print it to the top half of the screen?
1/3 or 2/3rds is okay as well? Is there any code examples (ASM/ZXB)

Q3. Next to the text,
I want to next compress text files that contain a description of a game room.
Looking at an example I tried this (don't laugh!) :-

dzx0Standard(@Text1, 50000)

incbin "location1.txt.zx00"
end asm
incbin "location2.txt.zx00"
end asm

But this does nothing but load it to the address of 50000 but I want the routine to return a STRING containing the decompressed text?

Quote:UPDATE 4th April 2021: I have worked how to do Q3 in a standalone test.bas file but when I do this in my main program it crashes the app soon after starting it up?
I am using these params --tzx --BASIC --autorun  --heap=1000 --optimize 2  --org=25000--debug-memory  --debug-array 

Lots of questions but hopefully some kind person can help? :-)

Print this item

Bug Undefined GLOBAL label error on array
Posted by: short_jonny - 03-27-2021, 03:12 PM - Forum: Bug Reports - Replies (2)

Recently started experimented with the compiler. It's been great so far but I've just started getting unexpected errors using arrays. Compiling the snippet below results in:
test.bas:55: error: Undefined GLOBAL label '._myArray'.  
I can't see why this is failing ?  Am I doing something stupid ?  
I've used 1.14.1 and the latest state of the repo. Is it a bug ?

DIM myArray(1 to 6) as ubyte

SUB Init(byval num as ubyte)
    DIM i as ubyte
    FOR i=1 TO num
        myArray(i) = 0
    NEXT i



Print this item

  Potential bug in impl of LOAD "..." CODE
Posted by: georgeo - 03-15-2021, 09:21 PM - Forum: Help & Support - Replies (8)

Hi everyone (probably for the attention of Boriel),

My search for the source of instability in my game continues, though I no longer think it is to do with memory management, but a possible bug in the compiler, for the implementation of LOAD "..." CODE. I have noticed that part of my program gets corrupted after I use LOAD "..." CODE to load some UDGs at the top of memory. Digging in to the implementation of the function, I found the following code (sorry, I can't copy and paste code out of the emulator I am using):


At the end of the snippet, a call is made to 0xE6E1, which is a wrapper to the ROM loader routine (in this case, to load a tape header). IX points to the place in memory where the header should be loaded, which -- in this case -- is inside my program code. If I understand correctly what is going on, the snippet starts with a call to MEM_FREE (0xDB56, in this case) which returns a pointer to space in the heap (perhaps where the header can be stored?). However, the IX register is loaded with 2*SP and passed to the tape loader, which I think is a mistake.

Is that a possible bug?

If this is indeed a bug, it fits with my experience. As the size of my program grows, I need to raise the origin address to avoid random crashes. For example, if I have a 30kb program with origin address at 29,000, then the stack will reside somewhere near the start of the heap, so 2*SP will be around 58,000 which will be near the end of my program. However, if I up the origin to 31,000, then 2*SP will be more like 62,000, which will be just past the end of my program. As the size of my program increases, it will eventually grow past 2*SP and then will start to get corrupted and crash randomly, when I load from tape, so I again need to raise the origin address.

It all seems to fit, but maybe I've just convinced myself,

Print this item

  Memory used ?
Posted by: RandomiserUsr - 03-13-2021, 02:10 PM - Forum: Help & Support - Replies (6)

I wonder if there is a way to print the available memory your compile ZX Basic program has used whilst running it?

One more question on memory usage, which would be better in terms of reducing memory overhead?


2) IF WORD = 99 and WORD=98 THEN

thanks in advance

Print this item

  Understanding memory layout
Posted by: georgeo - 03-13-2021, 11:11 AM - Forum: Help & Support - Replies (2)

Hi everyone,

I am seeing some strange memory problems when compiling a reasonably large program, which probably means I don't understand how the compiler organises memory.

Specifically, I have a program that is around 28kb in size, including a 1kb heap. Depending on the origin value I use, the program will either work or crash, but not as you might expect.

Initially, I set the origin of the code to 26000 (that is, "--org 26000") and this worked fine for a time. However, when my program reached a certain length (from memory, around 25kb), I started to see odd behaviour (corrupted strings and Out Of Memory errors). I tried increasing the heap size (to 2kb, 3kb, 4kb, 5kb, 6kb), though this didn't help. I then tried changing the origin to 28000 and then everything was fine again.

A little later on, with some more code added, I started to see problems again, so I again tried increasing the origin address--now to 29000 and again all is fine.

I'm confused because:

  1. the program isn't that big, fitting in between address 29000 and 57,353 (right now), so well clear of user-defined graphics and any Sinclair BASIC workspaces
  2. I would have expected that lowering the origin address would be more likely to help, if there was a lack of memory, rather than increasing it.

I checked the memory map (produced with '--mmap') and, indeed, symbols are defined for addresses between 29,000 and 57,247, so that all looks correct.

Can anyone suggest what is going on here? Thanks in advance,

Print this item

  Print42 library throws error with --explicit option
Posted by: georgeo - 03-13-2021, 10:59 AM - Forum: Help & Support - Replies (5)

Hi everyone,

I'd like to use --explicit to force me to define all variables before using them, to reduce the risk of bugs. However, I see an issue because my program uses the Print42 library and it contains a definition that seems to violate the --explicit option.

Specifically, if you try to compile a program that includes Print42 library, using --explicit, you will see an error something like:

C:/opt/zxbasic-1.14.0/zxbasic/src/arch/zx48k/library/print42.bas:16: error: Undeclared variable "printAt42Coords"
C:/opt/zxbasic-1.14.0/zxbasic/src/arch/zx48k/library/print42.bas:17: error: Undeclared variable "printAt42Coords"

I considered updating the library source, so that printAt42Coords is defined. However, printAt42Coords is a code label, not a normal variable. The compiler complains because the label is dereferenced with an @printAt42Coords operation to work out the address at which to store the current coordinates:

SUB printat42 (y as uByte, x as uByte)
    POKE @printAt42Coords,x
    POKE @printAt42Coords+1,y




I don't know what type of variable printAt42Coords is, so can't add a 'dim' statement to define it. I tried defining it as a 'uinteger', but then the compiler complains when it tries to use as a label "error: identifier 'printAt42Coords' is a var, not a function"

Anyone know how to work around this?

Thanks in advance,

Print this item

  Understanding scope of variables
Posted by: georgeo - 03-11-2021, 01:51 PM - Forum: Help & Support - Replies (5)

Hi everyone,

In ZXBASIC, is this a valid program?

function myFunction( name$ as string ) as uinteger
    dim length, n as ubyte
    dim total as uinteger = 0

    length = len(name$)

    if length=0 then
    return total
    end if

    for n = 0 to length-1
    total = total + code(name$(n))
    next n
    return total
end function

REM Main program
dim n as ubyte
dim ans as uinteger

n = 14
ans = myFunction("Hello")

print "Answer = " + str$(ans)
print "n = " + str$(n)


I have a variable labelled 'n' in both the top-level program and a function. I believe, in the function, 'n' is a different, locally defined variable, which is deleted when the function ends.

Would the same work, if I replaced the function with a subroutine (accepting I couldn't return an answer in the same way)?

I ask as I am seeing unexpected behaviour in my program (not the one above, a much longer program) and one possibility is that I'm using the same variable names for different entities in both the top-level program and subroutines.

Thanks in advance for any help

Print this item

  Dim At Issue? (1.15.0-beta4)
Posted by: Ljg701 - 03-09-2021, 08:07 PM - Forum: Help & Support - Replies (4)

Hello Boriel,

The following array initiation code I don't think is initiating the array data at the correct address. In the example below, the peek returns a value of 255 rather than 1, also @test doesn't return a value of $c000  (Version  1.15.0-beta4 + NextBuild)


dim test(0 to 3) as ubyte => {1,2,3,4} at $C000

'this should return 1
print at 0,0;peek($c000)

loop until inkey$<>""

Print this item

  Using --debug-array with arrays passed to functions
Posted by: georgeo - 03-09-2021, 01:11 PM - Forum: Help & Support - Replies (4)

Hi everyone,

I would like to use the --debug-array option to check I have not used out-of-range array indices in my program. However, it appears that I need to give the compiler more information, to use the option in a program that passes arrays as function arguments.

For example, the following simple program appears to compile/ run correctly:

function pickString$( choice as ubyte,  listOfStrings() as string ) as string
    return listOfStrings(choice)
end function

dim myString$(3) as string
myString$(0) = "Zero"
myString$(1) = "One"
myString$(2) = "Two"
myString$(3) = "Three"

dim n as ubyte

for n=0 to 3
    print pickString$(n, myString$)
next n


--but the compiler generates an error if I try to compile with the --debug-array option:

zxbc -t -a -B --debug-array array_bounds_ex.bas
Traceback (most recent call last):
  File "c:\opt\zxbasic-1.14.0\zxbasic\zxbc.py", line 10, in <module>
    sys.exit(libzxbc.main())  # Exit
  File "c:\opt\zxbasic-1.14.0\zxbasic\src\libzxbc\zxbc.py", line 246, in main
  File "c:\opt\zxbasic-1.14.0\zxbasic\src\arch\zx48k\translator.py", line 1401, in start
  File "c:\opt\zxbasic-1.14.0\zxbasic\src\ast\ast.py", line 35, in visit
  File "c:\opt\zxbasic-1.14.0\zxbasic\src\arch\zx48k\translator.py", line 196, in visit_ARGLIST
    upper = node.parent.entry.bounds[i].upper
  File "c:\opt\zxbasic-1.14.0\zxbasic\src\symbols\boundlist.py", line 29, in __getitem__
    return self.children[key]
  File "c:\opt\zxbasic-1.14.0\zxbasic\src\ast\tree.py", line 40, in __getitem__
    return self._children[key]
IndexError: list index out of range

I imaging the problem is that the compiler can't work out the array bounds within the function, unless I tell it. Anyone know if I can modify the source, so array-bound checking will still work?

Thanks in advance,

Print this item

  SAVE and LOAD commands - help!
Posted by: RandomiserUsr - 03-08-2021, 09:04 PM - Forum: Help & Support - Replies (3)


I have been trying to use the SAVE command to save the data whilst the program is running, i.e. SAVE "GAME" DATA
which I though would save all of the variables in the program?  *Save to Virtual Cassette tape*

And then I thought "All I need to do next is " LOAD "GAME" DATA 
and it would restore the entire game's data but it just crashes after it says "Bytes: GAME" 

I am sure there is something else that needs doing but can't recall this (80's memory is not as good as it should :-)  )

thanks in advance

Print this item