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



Search Forums

(Advanced Search)

Forum Statistics
» Members: 267
» Latest member: Jbizzel
» Forum threads: 955
» Forum posts: 6,007

Full Statistics

Online Users
There are currently 57 online users.
» 0 Member(s) | 55 Guest(s)
Bing, Google

Latest Threads
Testing a variable within...
Forum: Help & Support
Last Post: RandomiserUsr
03-25-2022, 09:59 PM
» Replies: 11
» Views: 1,560
WHILE Loop vs FOR/NEXT Lo...
Forum: Help & Support
Last Post: RandomiserUsr
03-25-2022, 09:55 PM
» Replies: 2
» Views: 427
The Disputed Territories ...
Forum: Gallery
Last Post: Jbizzel
03-21-2022, 05:29 PM
» Replies: 0
» Views: 201
The sound effect thread
Forum: How-To & Tutorials
Last Post: worcestersource
02-23-2022, 02:22 PM
» Replies: 3
» Views: 641
mine sweeper
Forum: Gallery
Last Post: Jbizzel
02-22-2022, 02:17 PM
» Replies: 2
» Views: 593
Kardinal Kid - new game i...
Forum: Gallery
Last Post: Jbizzel
01-30-2022, 10:25 PM
» Replies: 2
» Views: 555
Frogger 50
Forum: Gallery
Last Post: boriel
01-23-2022, 08:21 PM
» Replies: 2
» Views: 614
snake game
Forum: Gallery
Last Post: boriel
01-21-2022, 08:23 PM
» Replies: 1
» Views: 499
Problem with compiling ga...
Forum: Help & Support
Last Post: boriel
12-29-2021, 10:02 PM
» Replies: 1
» Views: 655
ZXBC to target 128K BIOS ...
Forum: Help & Support
Last Post: RandomiserUsr
12-28-2021, 01:42 PM
» Replies: 2
» Views: 700

Bug Game is crashing due to out of memory (48k) (*solved*)
Posted by: RandomiserUsr - 04-25-2021, 01:34 PM - Forum: Bug Reports - Replies (10)


I am writing a text adventure game (simply for my own fun) rather than use the other systems out there e.g. PAW Infocom, DAAD, TADS,  Aventuron etc... I wanted the challenge in writing one for the ZX Spectrum . :-)

The biggest issue I had was the amount of Text that needed storing.
At first I was going to use some sort of compression but couldn't get it work so I created a tokenised dictionary that turned string arrays (Locations, Objects, Examination results etc...)  to numeric arrays thus the memory was reduced quite a bit. So I thought this would suffice but I soon ran out of memory.

I then attempted to look into the text compression again and then worked out how to do this, but due to the size of the dictionary which was needed still it crashed when there was a decompression of the location file.

I also attempted to use +3 Disk but whilst I was able to a) load a picture b) load a text it crashed subsequent attempts. (Memory clash perhaps)?

So I am here looking for some hints/tips on the options I have.
I do have another plan though where I will try to rewrite it but this time start using text compression from the start.... we will see ... but the main thing for me is

Thanks to Boriel bringing the ZXB to use and Einar Saukas for their both their support :-)

Print this item

  Crash when creating UDGs using ASM (possibly not a bug)
Posted by: worcestersource - 04-05-2021, 10:14 AM - Forum: Bug Reports - Replies (3)

Hi there,

I can't for the life of me work out why I've hit this wall. I'm currently designing the graphics for my game, keeping character maps in one file and test harness in another. It crashes out with "J Invalid I/O device, 30:1".

The code in the character file, called, _graphics.bas is as follows:

DEFB 000, 254, 254, 254, 254, 254, 254, 254 ; A - roof A
DEFB 000, 000, 254, 254, 254, 254, 254, 254 ; B - roof B
DEFB 254, 254, 000, 069, 170, 069, 170, 000 ; C - top wall
DEFB 085, 168, 085, 000, 170, 069, 170, 000 ; D - bottom wall
DEFB 000, 000, 000, 000, 000, 126, 126, 126 ; E - wall cap
DEFB 060, 060, 060, 060, 060, 060, 060, 000 ; F - vert wall (shared)
DEFB 124, 124, 124, 124, 124, 124, 124, 000 ; G - vert wall (left)
DEFB 062, 062, 062, 062, 062, 062, 062, 000 ; F - vert wall (right)
DEFB 000, 000, 000, 000, 000, 000, 000, 000 ; G -
DEFB 000, 000, 000, 000, 000, 000, 000, 000 ; H -
DEFB 000, 000, 000, 000, 000, 000, 000, 000 ; I -
DEFB 238, 136, 136, 000, 238, 136, 136, 000 ; J - floor A
DEFB 254, 170, 212, 170, 212, 170, 212, 000 ; K - floor B


And the scratch file to display them is:

#include "_graphics.bas"

POKE UINTEGER 23675, @graphicsroom

let toproof$ = chr(144) + chr(145)
let caproof$ = chr(148)
let topwall$ = chr(146) + chr(146)
let botwall$ = chr(147) + chr(147)
let sharewall$ = chr(149)
let lefwall$ = chr(150)
let rigwall$ = chr(151)
let floorA$ = chr(155) + chr(155)
let floorB$ = chr(156) + chr(156)

border 0 : paper 0 : ink 7 : bright 1 : cls

print "  " + caproof$ + toproof$ + toproof$ + toproof$ + caproof$

bright 1 : print "  " + sharewall$; : bright 0 : print topwall$ + topwall$ + topwall$; : bright 1 : print sharewall$

bright 1 : print "  " + lefwall$; : bright 0 : print botwall$ + botwall$ + botwall$; : bright 1 : print rigwall$

bright 1 : ink 7 : print "  " + sharewall$; : bright 0 : ink 1 : print floorA$ + floorA$; : INK 2 : PRINT floorB$; : bright 1 : ink 7 : print sharewall$

bright 1 : ink 7 : print "  " + lefwall$; : bright 0 : ink 1 : print floorA$ + floorA$; : INK 2: PRINT floorB$; : bright 1 : ink 7 : print rigwall$

I have determined that if the last DEFB line in the graphics file is replaced with...

DEFB 254, 170, 212, 170, 212, 170, 000, 000 ; K - floor B

i.e. substituting the last 212 with 000, there is no crash. If I replace it with 001, all of the graphics corrupt but still run. Other values either work as expected or produce crashes. Adding another line after DEFB, i.e. graphic character L, causes it to crash.

It may be me as I'm still learning zxbc. I'm using the latest downloadable version on Mac. I've tried running this with an older download from earlier this year and it also crashes.



Print this item

  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