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

Username
  

Password
  





Search Forums

(Advanced Search)

Forum Statistics
» Members: 259
» Latest member: williemdan21
» Forum threads: 933
» Forum posts: 6,288

Full Statistics

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

Latest Threads
Bikers - ZX Spectrum Next
Forum: Gallery
Last Post: RandomiserUsr
04-10-2021, 05:03 PM
» Replies: 4
» Views: 844
ZX0 decompression example...
Forum: Help & Support
Last Post: RandomiserUsr
04-10-2021, 02:44 PM
» Replies: 1
» Views: 100
UDG definition bug (*solv...
Forum: Bug Reports
Last Post: boriel
04-07-2021, 12:45 PM
» Replies: 10
» Views: 14,547
Crash when creating UDGs ...
Forum: Bug Reports
Last Post: worcestersource
04-06-2021, 07:17 PM
» Replies: 3
» Views: 63
Dim At Issue? (1.15.0-bet...
Forum: Help & Support
Last Post: Ljg701
04-06-2021, 09:24 AM
» Replies: 4
» Views: 297
Undefined GLOBAL label er...
Forum: Bug Reports
Last Post: boriel
03-27-2021, 11:36 PM
» Replies: 2
» Views: 107
Print42 library throws er...
Forum: Help & Support
Last Post: boriel
03-25-2021, 06:54 PM
» Replies: 5
» Views: 281
Potential bug in impl of ...
Forum: Help & Support
Last Post: boriel
03-21-2021, 08:29 PM
» Replies: 8
» Views: 424
ZX Basic syntax highlight...
Forum: ZX Basic Compiler
Last Post: patters
03-19-2021, 08:48 PM
» Replies: 2
» Views: 301
FYI FUNCTIONs and RETURN ...
Forum: Help & Support
Last Post: boriel
03-15-2021, 08:51 PM
» Replies: 4
» Views: 348

 
  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:

Code:
graphicsroom:
ASM
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

END ASM

And the scratch file to display them is:

Code:
#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...

Code:
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.

Thanks,


Steve

Print this item

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

Hi

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

testscreen1:
    asm
        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)

Text1:
asm
incbin "location1.txt.zx00"
end asm
Text2:
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? :-)
thanks

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)

Hi,
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
END SUB

Init(6)



Jonathan

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):

https://1drv.ms/u/s!Atca6hVb5b8Tp5JxCEWC...g?e=qGHdEg

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,
Georgeo.

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?

1) IF WORD$ = "SAVE WORLD" THEN


or
2) IF WORD = 99 and WORD=98 THEN

thanks in advance
Ken

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:

Code:
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:

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

...

printAt42Coords:

...

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?

Code:
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)

stop

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)

Code:
'!ORG=24576
'!OPT=4

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

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

do
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:

Code:
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

stop

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

Code:
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
    func_visitor.start()
  File "c:\opt\zxbasic-1.14.0\zxbasic\src\arch\zx48k\translator.py", line 1401, in start
    self.visit(f)
  File "c:\opt\zxbasic-1.14.0\zxbasic\src\ast\ast.py", line 35, in visit
    stack.append(last.send(last_result))
  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