Welcome, Guest |
You have to register before you can post on our site.
|
Online Users |
There are currently 240 online users. » 0 Member(s) | 237 Guest(s) Bing, Google, Yandex
|
Latest Threads |
Красивые букетики
Forum: News
Last Post: AnthonyGaxia
3 hours ago
» Replies: 0
» Views: 4
|
Printing with FZX
Forum: Help & Support
Last Post: boriel
07-17-2025, 09:08 PM
» Replies: 1
» Views: 358
|
Strange Happenings
Forum: Bug Reports
Last Post: boriel
05-23-2025, 09:15 AM
» Replies: 4
» Views: 2,530
|
.tap file code not execut...
Forum: Help & Support
Last Post: Zoran
04-28-2025, 10:59 AM
» Replies: 4
» Views: 2,711
|
Exit from more than one l...
Forum: Wishlist
Last Post: Duefectu
04-23-2025, 10:06 PM
» Replies: 3
» Views: 2,263
|
put small ASM programs li...
Forum: How-To & Tutorials
Last Post: Zoran
04-18-2025, 02:02 PM
» Replies: 6
» Views: 5,266
|
Creating +3 Menus - Loadi...
Forum: Help & Support
Last Post: merlinkv
04-16-2025, 02:08 PM
» Replies: 6
» Views: 3,696
|
Randomize not very random...
Forum: Help & Support
Last Post: Zoran
04-08-2025, 10:40 AM
» Replies: 4
» Views: 3,434
|
Scope rules
Forum: Bug Reports
Last Post: Zoran
04-04-2025, 09:46 AM
» Replies: 2
» Views: 1,951
|
Using constants not allow...
Forum: Bug Reports
Last Post: baltasarq
03-19-2025, 10:00 PM
» Replies: 8
» Views: 4,737
|
|
|
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
|
|
|
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$<>""
|
|
|
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,
|
|
|
SAVE and LOAD commands - help! |
Posted by: RandomiserUsr - 03-08-2021, 09:04 PM - Forum: Help & Support
- Replies (3)
|
 |
Hi
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
|
|
|
Dealing with "Out of Memory" errors |
Posted by: georgeo - 03-08-2021, 01:09 PM - Forum: Help & Support
- Replies (6)
|
 |
Hi everyone,
I am relatively new to ZXBASIC, though think I have mostly got the hang of things and am using it to write a new game.
I am seeing intermittent Out of Memory issues (when compiling with --debug-memory), which I believe means I am running out of heap space. However, I've tried increasing the heap quite significantly (e.g., up to 8 kb) with little effect. I've also tried reducing the dependence on string arrays/ variables, in case this was the problem.
If I see an intermittent Out of Memory error mid-way through a program, long after most variables should have been defined, will it be heap-related or could it be something else?
Any suggestions for debugging my code, or properly sizing the heap, would be much appreciated.
Thanks in advance,
Georgeo.
|
|
|
String Arrays and memory |
Posted by: RandomiserUsr - 02-27-2021, 10:51 PM - Forum: Help & Support
- Replies (4)
|
 |
Hi,
I wonder if someone could help me?
I have started writing a game but it uses a lot of String arrays.
The problem is I am compiling okay but on the screen things are missing where text should be.
I have compiled it using :-
Code: zxbc MainEngine.bas --tzx --BASIC --autorun --heap=6000 --optimize 2 --org=25000 --mmap=memory_map.txt
I am not sure where the issue but let me know if you need more information
Thanks
Ken
|
|
|
String Arrays problems "nonsense in Basic" - fixed |
Posted by: RandomiserUsr - 02-27-2021, 04:12 PM - Forum: Help & Support
- No Replies
|
 |
Hi, I am looking at how to store a string of descriptions into an array.
Sounds straight forward enough, so should be something like
Code: DIM A$(100,200)
LET A$(1,1)= "This description 1 : The quick brown fox jumps over the lazy dog."
LET A$(2,1)= "This description 2 : The quick brown fox jumps over the lazy dog."
LET A$(3,1)= "This description 3 : The quick brown fox jumps over the lazy dog."
LET A$(4,1)= "This description 4 : The quick brown fox jumps over the lazy dog."
[size=small][font=Tahoma, Verdana, Arial, sans-serif]PRINT A$(1,1)[/font][/size]
So it should print.
This description 1 : The quick brown fox jumps over the lazy dog.
It is being compiled with
Code: zxbc aTest.bas --tzx --BASIC --autorun --debug-array
But all I get when I run it in the ZX Spectrum emulator is
C Nonsense in BASIC, 30:1
Any ideas why?
I think this is down to memory?
thanks
Ken
UPDATE:
It seems that all I needed to do is declare A$(100,200) as A$(100) and access it via print A$(1) and that is it - nice to fix things along the new road :-)
|
|
|
FUNCTIONS again |
Posted by: RandomiserUsr - 02-27-2021, 12:15 PM - Forum: Help & Support
- Replies (2)
|
 |
If you compile the following code
FUNCTION A(text as STRING)
Print B("Test")
RETURN 0
END FUNCTION
FUNCTION C(text as STRING)
Print B("Test")
RETURN 0
END FUNCTION
FUNCTION B(text as STRING)
Print ("Test")
RETURN 0
END FUNCTION
you will get
inputmud.bas:137: error: 'B' is neither an array nor a function.
inputmud.bas:135: warning: [W150] Parameter 'text' is never used
inputmud.bas:144: warning: [W100] Using default implicit type 'float' for 'C'
inputmud.bas:144: error: 'B' is neither an array nor a function.
inputmud.bas:143: warning: [W150] Parameter 'text' is never used
inputmud.bas:149: warning: [W100] Using default implicit type 'float' for 'B'
inputmud.bas:148: warning: [W150] Parameter 'text' is never used
but moving function B above like below compiles okay
So I guess it's a TOP Down design where the functions in the same .BAS should be ordered
FUNCTION B(text as STRING)
Print ("Test")
RETURN 0
END FUNCTION
FUNCTION A(text as STRING)
Print B("Test")
RETURN 0
END FUNCTION
FUNCTION C(text as STRING)
Print B("Test")
RETURN 0
END FUNCTION
Great tool
Thanks
Ken
|
|
|
FYI FUNCTIONs and RETURN value |
Posted by: RandomiserUsr - 02-27-2021, 12:07 PM - Forum: Help & Support
- Replies (4)
|
 |
I have seen a problem where if you call a function without a RETURN 0 with no return value in FUNCTION declaration e.g.
FUNCTION UFNprintText(printText$ AS STRING )
Sometimes the function will just crash the ZX Spectrum emulator
Adding a RETURN 0 makes it work.
Just thought you might know this?
|
|
|
DIM a$(100,10) possible bug? |
Posted by: RandomiserUsr - 02-26-2021, 08:03 PM - Forum: Help & Support
- Replies (2)
|
 |
Hi,
I have been developing a game and one of thing things I wanted to is build up a string and print it out but the issue I have is that I can't do the following code in zxbc :-
Code: DIM a$(100,10)
LET a$(1) = "Line 1"
PRINT a$(1)
But I can do the above in a ZX Spectrum emulator.
I know the solution is to use a$(1,1) (Ignore the zero array start)
PS Brilliant compiler!!
Thanks,
Ken
|
|
|
|