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: Jeffreybub
» Forum threads: 1,074
» Forum posts: 6,434

Full Statistics

Online Users
There are currently 331 online users.
» 0 Member(s) | 328 Guest(s)
Applebot, Bing, Google

Latest Threads
.tap file code not execut...
Forum: Help & Support
Last Post: Zoran
04-28-2025, 10:59 AM
» Replies: 4
» Views: 135
Exit from more than one l...
Forum: Wishlist
Last Post: Duefectu
04-23-2025, 10:06 PM
» Replies: 3
» Views: 237
put small ASM programs li...
Forum: How-To & Tutorials
Last Post: Zoran
04-18-2025, 02:02 PM
» Replies: 6
» Views: 1,482
Creating +3 Menus - Loadi...
Forum: Help & Support
Last Post: merlinkv
04-16-2025, 02:08 PM
» Replies: 6
» Views: 495
Randomize not very random...
Forum: Help & Support
Last Post: Zoran
04-08-2025, 10:40 AM
» Replies: 4
» Views: 402
Scope rules
Forum: Bug Reports
Last Post: Zoran
04-04-2025, 09:46 AM
» Replies: 2
» Views: 275
Using constants not allow...
Forum: Bug Reports
Last Post: baltasarq
03-19-2025, 10:00 PM
» Replies: 8
» Views: 994
404 page not found
Forum: Documentation
Last Post: boriel
03-08-2025, 07:16 PM
» Replies: 5
» Views: 2,827
Spectrum keywords codes
Forum: Bug Reports
Last Post: boriel
03-08-2025, 11:00 AM
» Replies: 1
» Views: 383
ZXodus][Engine
Forum: ZX Basic Compiler
Last Post: boriel
02-19-2025, 11:43 PM
» Replies: 69
» Views: 213,360

 
  .tap file code not executed
Posted by: manuelzo75 - 04-24-2025, 04:09 PM - Forum: Help & Support - Replies (4)

Hello, I'm a newbie tinkering with the Spectrum.
I tried to get some code to test like the classic 'clock.bas' or 'circle. bas' and then converting a .bas file to .tap.
In some cases, I obtain some errors like:

manuelzompetta@Manuels-MacBook-Pro zxbasic % python zxbc.py clock.bas 
clock.bas:21: warning: [W100] Using default implicit type 'float' for 'a'
clock.bas:22: warning: [W100] Using default implicit type 'float' for 'sx'
clock.bas:22: warning: [W100] Using default implicit type 'float' for 'sy'
clock.bas:25: warning: [W100] Using default implicit type 'ulong' for 't2'
Traceback (most recent call last):
  File "/Users/manuelzompetta/Downloads/zxbasic/zxbc.py", line 12, in <module>
    sys.exit(zxbc.main())  # Exit
             ^^^^^^^^^^^
  File "/Users/manuelzompetta/Downloads/zxbasic/src/zxbc/zxbc.py", line 155, in main
    asm_output = backend.emit(optimize=OPTIONS.optimization_level > 0)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/manuelzompetta/Downloads/zxbasic/src/arch/z80/backend/main.py", line 770, in emit
    self._output_join(output, self._QUAD_TABLE[quad.instr].func(quad), optimize=optimize)
                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/manuelzompetta/Downloads/zxbasic/src/arch/z80/backend/generic.py", line 362, in _cast
    output.extend(to_long(tA))
                  ^^^^^^^^^^^
  File "/Users/manuelzompetta/Downloads/zxbasic/src/arch/z80/backend/common.py", line 401, in to_long
    raise NotImplementedError(f"type conversion from {stype} to long is undefined")
NotImplementedError: type conversion from u32 to long is undefined


In other cases I obtain .tap file but when I execute it in the Spectrum or in an emulator nothing happens, I just obtain the welcome screen.

What I'm doing wrong?

Thanks

Print this item

  Exit from more than one level
Posted by: Zoran - 04-18-2025, 02:50 PM - Forum: Wishlist - Replies (3)

Sometimes we need exit not only from innermost loop, but also from some outer loop (sometimes more than two levels).

As a workaround I use "do" in the outer loop and "while 1" in the inner, just to be able to use "exit do" or "exit while":

Code:
do
   ' some code
   while 1
      ' some code

      if somecondition then
         exit do ' exit from two levels
      end if

      ' some code...
      if someothercondition then
         exit while ' exit inner loop only
      end if

      ' some code...
   end while

    ' some code...
loop

When exit from more than two levels is needed, there is no other way but to put a label and use "goto". It would be much more elegant if we could exit from more levels directly. For example, "exit do do" or "exit do do do" would exit from two or three levels of "do". I'm not sure that "exit for for for" or "exit while while" is needed; supporting "do" loop only is probably quite enough -- "do" loop is the most powerful and you can easily write any loop as a "do" loop.

What do you think?

Print this item

  Creating +3 Menus - Loading external BAS files
Posted by: merlinkv - 04-12-2025, 05:18 AM - Forum: Help & Support - Replies (6)

Hello,

I'm creating Menus for my +3 game compilations but I can't find a way to load external BAS files.

With the LOAD command I can load only CODE & SCREEN$ files. There is a way to LOAD another BAS file included in the disks?

Like on standard +3 BASIC.

ie: LOAD "MYBASPRG" or LOAD "MYBASPRG.BAS"

Thanks in advance.

Example:

[Image: SERVER_000249.jpg]

Print this item

  Randomize not very random?
Posted by: BrianT - 04-06-2025, 12:21 PM - Forum: Help & Support - Replies (4)

I don't know if this should be in the bug section or is just a general question. There was an older question in the bug forum saying it would be fixed.

Making a card game, I use an array (0 to 51) for card numbers, then have a routine to shuffle it up.
With RANDOMIZE at top of program so it only gets used once each time the game is loaded, I consistently start with 2,0,3,48,9.
Moving it into the "new game" loop so it is run at the start of each new game, I'm always seeing 49,0,21,24.
I'm seeing the same sequence whether I use my Linux or Windows pc.
Not sure if it's something to do with FUSE emulator rather than ZX BASIC, and not using the FRAME setting which the help page mentions?
I've added my source as a txt file for reference.



Attached Files
.txt   hilo3.txt (Size: 4.05 KB / Downloads: 42)
Print this item

  Scope rules
Posted by: Zoran - 04-03-2025, 01:54 PM - Forum: Bug Reports - Replies (2)

If we have got a routine and another subroutine nested inside the first, the programme behaves unpredictably.

I wanted to test if the variable declared in outer routine is accessible from the inner routine (I couldn't find it documented anywhere).


Please see these two simple examples which show quite different behaviour.

Both compiled with Zx Basic version 1.17.3, with these options:


Quote:--optimize 2 -f tzx --BASIC --autorun --explicit --strict

The first example:

Code:
#pragma explicit = true
#pragma strict = true

sub outerRoutine
    dim n as ubyte
   
    sub nestedRoutine()
        print "From inner sub, before: "; n
        n = 22
        print "From inner sub, after: "; n
    end sub
   
    n = 11
   
    print "From outer sub, before: "; n
    nestedRoutine()
    print "From outer sub, after: "; n
end sub

cls
outerRoutine()


The output:

Quote:From outer sub, before: 11
From inner sub, before: 11
From inner sub, after: 22
From outer sub, after: 22


So the first example shows that variable n, declared in outer routine is fully accessible from the nested routine.

In the second example, I only added a dummy variable declaration inside the nested routine:

Code:
#pragma explicit = true
#pragma strict = true

sub outerRoutine
    dim n as ubyte
   
    sub nestedRoutine()
        dim k as ubyte ' declare a dummy variable
        if k <> 0 then ' and access it
            print "";  ' do nothing meaningful
        end if
       
        print "From inner sub, before: "; n
        n = 22
        print "From inner sub, after: "; n
    end sub
   
    n = 11
   
    print "From outer sub, before: "; n
    nestedRoutine()
    print "From outer sub, after: "; n
end sub

cls
outerRoutine()

Quote:From outer sub, before: 11
From inner sub, before: 0
From inner sub, after: 22
From outer sub, after: 11

Totally different output!
The main problem is that, referring to variable n, something is accessed and even written to inside the nested subroutine, but it is clearly not the varible n declared above.

With explicit and strict options, if the outer routine scope is not accessible, the compiler has to give an error that variable n is not declared in routine innerRoutine.
The compiler gives no error, though. Then the programme behaviour is unpredictable and rather dangerous actually.

Print this item

  Spectrum keywords codes
Posted by: Zoran - 03-07-2025, 08:01 PM - Forum: Bug Reports - Replies (1)

Hello,

The documentation for CHR function (https://zxbasic.readthedocs.io/en/latest/chr/) says that, although expanded, the function is 100% Sinclair basic compatible.
If it is so, then for the same parameters I'd expect the same output, not only for ascii letters, but also for sinclair basic keywords.

In Sinclair basic, this programme:

Code:
10 CLS
20 FOR i = 230 TO 250
30 PRINT CHR$ i
40 NEXT i

gives some Basic keywords in the output (see the attached image zxkeywords_sinclair.png).

.png   zxkeywords_sinclair.png (Size: 10.26 KB / Downloads: 98)

The equivalent programme in ZX Basic:
Code:
dim i as ubyte

cls
for i = 230 to 250
    print chr(i)
next

outputs some silly characters (see the attached image zxkeywords_boriel.png).

.png   zxkeywords_boriel.png (Size: 11.44 KB / Downloads: 77)

Compiled with:
Quote:..\..\zxbasic\zxbc.exe --optimize 2 --output zxkeywords.tzx --output-format tzx --BASIC --autorun --explicit --strict zxkeywords.bas

I'd say it is a bug.

Print this item

  Using constants not allowed in DATAs
Posted by: baltasarq - 03-03-2025, 09:10 PM - Forum: Bug Reports - Replies (8)

Hi!
Another bug or at least improvement, sorry!
When I create constants, such as:
const DCMD_EOD                            as ubyte = 100
const DCMD_LINE                           as ubyte = 101
const DCMD_CIRCLE                         as ubyte = 102
const DCMD_FILL                           as ubyte = 103
const DCMD_UDG                            as ubyte = 104

And then try to use them like so (initializer expression):
sub draw_presentation()
    dim pic_data(11) as ubyte => { _
        DCMD_Circle, 50, 180, 10,  _
        DCMD_Fill, 50, 180,        _
        DCMD_Circle, 100, 160, 25, _
        DCMD_EOD }
   
    draw_pic( pic_data )
end sub

Or maybe like so (DATAs):
LocPics:
    ' Loc 0 - Limbo
    data DCMD_Line, 0, 180, 250, 100, _
        DCMD_Line, 250, 180, 0, 100, _
        DCMD_EOD

    ' Loc 1 - Landing
    data DCMD_Circle, 50, 180, 10,  _
        DCMD_Fill, 50, 180,        _
        DCMD_Circle, 100, 160, 25,  _
        DCMD_EOD

I receive the following errors:
For the use of constants inside DATAs:
locs.bas:64: warning: [W100] Using default implicit type 'float' for 'DCMD_Line'
locs.bas:69: warning: [W100] Using default implicit type 'float' for 'DCMD_Circle'
locs.bas:70: warning: [W100] Using default implicit type 'float' for 'DCMD_Fill'

This doesn't make any sense, since they are defined as constants of type ubyte.
For the use of these constants inside the constant initializer for an array:
reveni.bas:14: error: Initializer expression is not constant.
reveni.bas:19: warning: [W100] Using default implicit type 'float' for 'pic_data'
reveni.bas:19: error: Invalid argument 'pic_data'

Again, this doesn't make any sense, since they are constants but the initializer expression is erroneously detected as non-constant.
Could this be solved?
Thanks,

Print this item

  Download links broken
Posted by: xthunderheartx@gmail.com - 02-17-2025, 02:03 AM - Forum: Bug Reports - Replies (3)

Hey I just tried to download (from all the links) and got nothing.  Links look good but boriel.com/files appears to be empty.  Is that right?  It's Sunday night so maybe it's maintenance?

Thanks - Dallas

Print this item

  2D Array Errors
Posted by: raymondlesley - 02-13-2025, 03:42 PM - Forum: Bug Reports - Replies (1)

I've been enjoying using ZX BASIC so far. It's great to have something that's easy to use (and in-keeping with the original Sinclair BASIC). I have come up against an issue which I can't find a solution for:

The compiler supports multi-dimensional arrays, but it throws an error if I attempt to get a "slice" of the data.

My code:

Code:
DIM data_array(0 TO 2, 0 TO 3) AS UByte = { _
    {0, 1, 2, 3}, {4, 5, 6, 7}, {8, 9, 10, 11} _
}

DIM element12 AS UByte = data_array(1, 2)

DIM element0(0 TO 3) AS UByte

element0 = data_array(0)  ' throws an error

I get no errors relating to element12
I would expect that element0 should result in {0, 1, 2, 3}. It's the right "shape". Instead I get an error:

Quote:
array_test.bas:9: error: Syntax Error. Unexpected token '(' <LP>

I've tried variants e.g. data_array(0, : ) or data_array(0,0 TO 3). Nothing seems to work.

I'm using ZX BASIC 1.17.2

Print this item

  Breaking loops
Posted by: baltasarq - 02-07-2025, 12:28 PM - Forum: Bug Reports - Replies (9)

Out of simple routine, I created a for loop like this:

Code:
for i = 0 to ubound(m)
    if m( i ) = 0
        break
    end if
next

At first, I did not understand what was happening. break was not working. But there was not any error or even a warning. Then I realized: break is not a part of Basic. It never was.
The strange point is the absence of any error or warning. Either this was included in the grammar by error, or maybe because it is planned for inclusion.
I don't know.

Print this item