| Welcome, Guest |
You have to register before you can post on our site.
|
| Online Users |
There are currently 237 online users. » 0 Member(s) | 236 Guest(s) Bing
|
| Latest Threads |
New video Couse / Nuevo c...
Forum: News
Last Post: Duefectu
2026-04-29, 11:02 PM
» Replies: 0
» Views: 216
|
location of heap manageme...
Forum: Help & Support
Last Post: boriel
2026-03-07, 12:13 AM
» Replies: 1
» Views: 487
|
non-paged supervisor code...
Forum: Help & Support
Last Post: sdo303
2026-02-20, 06:38 PM
» Replies: 8
» Views: 1,302
|
How to open fuse as an ex...
Forum: How-To & Tutorials
Last Post: Duefectu
2026-02-09, 01:52 PM
» Replies: 3
» Views: 1,392
|
Old zxbasic game errors
Forum: Help & Support
Last Post: boriel
2025-11-09, 11:52 AM
» Replies: 7
» Views: 2,080
|
Error: Undefined GLOBAL l...
Forum: Help & Support
Last Post: ardentcrest
2025-11-04, 05:46 PM
» Replies: 3
» Views: 1,082
|
A Fast(er) Plot Routine f...
Forum: How-To & Tutorials
Last Post: tubz74
2025-10-30, 03:16 PM
» Replies: 2
» Views: 1,181
|
Hall of Fame - Include fo...
Forum: How-To & Tutorials
Last Post: tubz74
2025-10-28, 03:48 PM
» Replies: 0
» Views: 630
|
[SOLVED] Array layout bug...
Forum: Bug Reports
Last Post: Zoran
2025-10-25, 05:48 PM
» Replies: 2
» Views: 1,221
|
3DOS Commands?
Forum: Help & Support
Last Post: boriel
2025-10-06, 02:54 PM
» Replies: 3
» Views: 1,383
|
|
|
| Conditional operator? |
|
Posted by: einar - 2014-09-16, 09:57 PM - Forum: Wishlist
- Replies (8)
|
 |
Whenever I'm programming anything in ZX BASIC that involves non-trivial calculations, I really miss the conditional operator from C. So much that I finally decided to post a request here...
Since ZX BASIC already incorporates many useful operators from C like << (binary shift) and & (binary and), could you please consider incorporating C conditional operator also? What I mean is allowing code like this:
Code: IF (a < 30) THEN
LET a = a + 2
ELSE
LET a = a + 1
END IF
To be written like this:
Code: LET a = a + (a < 30 ? 2 : 1)
Those unfamiliar with C programming may not recognize it at first, but after you get used to it, the latter version is a lot easier to read. It's also easier for a compiler to optimize a single expression using conditional operators, instead of multiple IFs. Also this kind of feature would not introduce any problems or ambiguity in the parser.
For more complex expressions it makes a huge difference. Here's another example:
Code: IF (row > 0) THEN
LET pos = pos | (move & UP)
ELSE
LET pos = pos | TOP
END IF
IF (row < 21) THEN
LET pos = pos | (move & DOWN)
ELSE
LET pos = pos | BOTTOM
END IF
IF (col > 0) THEN
LET pos = pos | (move & LEFT)
ELSE
LET pos = pos | LEFTMOST
END IF
IF (col < 31) THEN
LET pos = pos | (move & RIGHT)
ELSE
LET pos = pos | RIGHTMOST
END IF
Using conditional operators, all this code above would be simplified to this:
Code: LET pos = pos | (row > 0 ? move & UP : TOP) |
(row < 21 ? move & DOWN : BOTTOM) |
(col > 0 ? move & LEFT : LEFTMOST) |
(col < 31 ? move & RIGHT : RIGHTMOST)
Makes sense?
|
|
|
| hex numbers in asm blocks |
|
Posted by: LTee - 2014-07-23, 08:31 PM - Forum: Help & Support
- Replies (4)
|
 |
Sorry to be creating so many posts the last couple of days. 
Should this work?
Code: asm
defb ffh
end asm
I read a post elsewhere which suggested that that was the correct syntax to use for hex numbers in an asm block, but I get this:
Code: test.bas:1: Error: Undefined label 'ffh'
If I switch the 'ffh' for a '255' then all is fine. 1.4.0-s1885, as before. Thanks!
|
|
|
| Should I be able to declare an array of @ addresses? |
|
Posted by: LTee - 2014-07-23, 08:01 PM - Forum: Help & Support
- No Replies
|
 |
Not sure if this is a bug or not, so I thought I'd pose the question first. 
I read this post from last year, which suggests that @ addresses should now be treated as constants:
<!-- l --><a class="postlink-local" href="https://forum.boriel.com/post4283.html?hilit=%20not%20constant%20#p4283">post4283.html?hilit=%20not%20constant%20#p4283</a><!-- l -->
So I figured I should probably be able to make some labels and then do something like this:
Code: dim addressMap(4) as uinteger => {@label1,@label2,@label3,@label4}
... except I can't - the compiler won't accept the @ addresses as being constants if they're being used to initialise an array.
So I though I might cheat and try to do this instead:
Code: const c1 as uinteger = @label1
const c2 as uinteger = @label2
const c3 as uinteger = @label3
const c4 as uinteger = @label4
dim addressMap(4) as uinteger => {c1,c2,c3,c4}
... but that doesn't work either - it doesn't think the constants are constant either. 
Should either of those things work? Or am I going about doing this the wrong way? I'm importing some data in asm defb format and thought I might use the @ addresses of some ZX Basic labels to refer to various points within the data. Using 1.4.0-s1885, by the way. Thanks for any input!
|
|
|
| Function declarations not working (sometimes) (*solved*) |
|
Posted by: LTee - 2014-07-22, 09:21 PM - Forum: Bug Reports
- Replies (4)
|
 |
Okay, I think I figured out what my other problem is. 
In 1.3 I could call a function in the code before it was declared providing I declared the function with a prototype at the top of the class. So this would've worked okay, despite the 'addWibble' function appearing after the call to 'addWibble':
Code: 'function prototypes
declare function addWibble(msg as String) as String
'call addWibble even though it's declared down there vvvv
dim newMsg as String
newMsg = addWibble("Hello")
print newMsg
'return a string suffixed with 'wibble'
function addWibble(msg as String) as String
dim newString as String
newString = msg
newString = newString + "wibble"
return newString
end function
In 1.4 this won't compile, it seemingly ignores the 'declare' prototype of the function and doesn't recognise 'addWibble' when it first encounters it, giving an error like this:
Code: TestFunction.bas:8: 'addWibble' is neither an array nor a function.
If you move the call below function like this then everything is fine:
Code: 'return a string suffixed with 'wibble'
function addWibble(msg as String) as String
dim newString as String
newString = msg
newString = newString + "wibble"
return newString
end function
'call addWibble even though it's declared down there vvvv
dim newMsg as String
newMsg = addWibble("Hello")
print newMsg
HOWEVER.... it's a bit more complicated than that. It seems that I only see this effect if the function returns a String. If I quickly switch the function to return a ubyte instead then everything compiles fine.
Code: 'function prototypes
declare function addWibble(msg as string) as ubyte
'call addWibble even though it's declared down there vvvv
dim newMsg as ubyte
newMsg = addWibble("test")
print newMsg
'return the number 1
function addWibble(msg as string) as ubyte
return 1
end function
Hope that makes sense!
|
|
|
| Declaring arrays with constants (*solved*) |
|
Posted by: LTee - 2014-07-21, 08:19 PM - Forum: Bug Reports
- Replies (6)
|
 |
Hi guys, it's been a little while. 
I finally got around to upgrading to 1.4.0-s1881 and set about recompiling a bunch of old stuff to see how it turned out. One thing I'm having a problem with is that some of my code uses consts in the declaration of arrays, which was fine in 1.3 but doesn't seem to like compiling in 1.4.
e.g.
Code: 'constants
const DGMAXX as ubyte = 10
const DGMAXY as ubyte = 10
'dungeon data
dim dgConnected(DGMAXY, DGMAXX) as ubyte
This fails to compile with an error telling me that I must use a constant (which I thought I did). 
Code: DunGen.bas:6: Array bound must be a constant expression.
DunGen.bas:6: Array bound must be a constant expression.
Traceback (most recent call last):
File "zxb.py", line 348, in <module>
File "zxb.py", line 262, in main
File "ply\yacc.pyc", line 263, in parse
File "ply\yacc.pyc", line 710, in parseopt
File "zxbparser.pyc", line 600, in p_bound_list_bound
File "zxbparser.pyc", line 324, in make_bound_list
File "symbols\boundlist.pyc", line 45, in make_node
File "ast_\tree.pyc", line 147, in appendChild
File "ast_\tree.pyc", line 52, in append
AssertionError
Apologies if this has already been covered in here, I didn't have much luck with the search!
|
|
|
| Function pointers |
|
Posted by: antoniovillena - 2014-07-09, 12:22 AM - Forum: Wishlist
- No Replies
|
 |
Something like this:
<!-- m --><a class="postlink" href="http://virtualink.wikidot.com/fbex20">http://virtualink.wikidot.com/fbex20</a><!-- m -->
|
|
|
| Program refuses to compile |
|
Posted by: Darkstar - 2014-06-29, 04:22 PM - Forum: Bug Reports
- Replies (28)
|
 |
Hello.
I got a program that works fine under 130s1121 but not under 140s1876. When I try to compile it then it bombs with this message:
Traceback (most recent call last):
File "/home/pi/zxbasic/zxb.py", line 348, in <module>
sys.exit(main(sys.argv)) # Exit
File "/home/pi/zxbasic/zxb.py", line 274, in main
translator.visit(zxbparser.ast)
File "/home/pi/zxbasic/ast_/ast.py", line 105, in visit
stack.append(self._visit(stack.pop()))
File "/home/pi/zxbasic/arch/zx48k/translator.py", line 143, in _visit
return NodeVisitor._visit(self, node)
File "/home/pi/zxbasic/ast_/ast.py", line 118, in _visit
return meth(node)
File "/home/pi/zxbasic/ast_/ast.py", line 122, in generic_visit
raise RuntimeError("No {}() method defined".format('visit_' + node.token))
RuntimeError: No visit_SAVE() method defined
Usage: zxbasm.py <input file> [options]
I do not wnat to share the source on a forum, is there any way that I can get the source to you Boriel so that you can have a look at it?
Also, under the old version if you had a wihite paper and a black ink but a yellow border then the SAVE command did change the paper color to yellow afterwards and the tape message got displayed in paper yellow instead of white. Highly fishy. And if I tried to compile this program with -O3 then it bombed so I had to set it back to -O1. Now it totally refuses to compile under the new version. Help would be good here Boriel.
|
|
|
| an additional label in <library-asm/print.asm> |
|
Posted by: programandala.net - 2014-06-08, 08:11 PM - Forum: Library
- Replies (3)
|
 |
Mi wish is easy to satisfy: I need one label after CP 80h in <print.asm>:
Code: ex af, af'
cp 80h ; Is the char an UDG, a block character or a token?
JUMP_IF_GREATER_THAN_80H:
; XXX label needed to hack the printing system
jp c, __SRCADDR ; if not, jump
(That is an extract from my hacked version of <print.asm>, with additional comments of my own; the actual name of the label doesn't matter.)
The reason I need a label there is I have written a module that provides a sub to switch on an off the ZX Spectrum legacy printing mode (that treats ASCII chars, block chars and UDG chars apart). When the legacy mode is off, all chars 32-255 are taken from the same charset. This makes it possible to write source code with a modern 8-bit encoding, e.g. Latin1. This is very useful for programs that print a lot of text in other languages than English.
I tinkered with this idea four years ago, and hacked <print.asm>, but I had to redo the changes after every new version of ZX BASIC. The new approach is simpler and better: The sub modifies the code of <print.asm> in two locations, and the legacy printing mode can be restored at any time by the program. It works great. So far I have tried it with a modified version of <print.asm>. That's why I need that single label.
I will publish the module as soon as it can be used with a new version of ZX BASIC, unless someone requires it sooner.
Thank you.
|
|
|
|