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: Clive
» Forum threads: 940
» Forum posts: 5,941

Full Statistics

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

Latest Threads
is possible a variable go...
Forum: Help & Support
Last Post: maeloterkim
9 hours ago
» Replies: 0
» Views: 7
warning: [W180] Unreachab...
Forum: Bug Reports
Last Post: boriel
09-24-2021, 09:27 PM
» Replies: 5
» Views: 226
DEFADD trick with ZX BASI...
Forum: Help & Support
Last Post: boriel
09-23-2021, 07:15 AM
» Replies: 1
» Views: 35
Is there a list somewhere...
Forum: Help & Support
Last Post: maeloterkim
09-16-2021, 09:06 AM
» Replies: 2
» Views: 105
why is there 2 halt on wa...
Forum: Help & Support
Last Post: boriel
09-10-2021, 07:05 AM
» Replies: 1
» Views: 92
print42() to allow CR chr...
Forum: Wishlist
Last Post: RandomiserUsr
09-09-2021, 04:10 PM
» Replies: 2
» Views: 126
It is possible to read th...
Forum: Help & Support
Last Post: maeloterkim
09-08-2021, 10:57 AM
» Replies: 2
» Views: 128
Is posible put a ubyte va...
Forum: Help & Support
Last Post: maeloterkim
09-06-2021, 04:18 PM
» Replies: 2
» Views: 112
#include MACRO
Forum: Help & Support
Last Post: RandomiserUsr
09-04-2021, 09:21 AM
» Replies: 2
» Views: 188
struggle on using/impleme...
Forum: Wishlist
Last Post: britlion
09-02-2021, 12:49 PM
» Replies: 2
» Views: 181

 
  is possible a variable goto or gosub?
Posted by: maeloterkim - 9 hours ago - Forum: Help & Support - No Replies

Hi

in the original  ZX spectrum basic you can do this

goto MyVariable  or gosub MyVariable  where this variable must be a line number

this way we can goto or gosub to diferents routines that are in diferents line numbers

but i tried this example with the compiler and says error: Syntax Error. Unexpected token 'MyRoutines' <ARRAY_ID>

This is the example you can try:


dim MyRoutines(2) as uInteger => {  @MyRoutine1, _    '' address of my routine 1
                                                       @MyRoutine2, _    '' address of my routine 2
                                                      @MyRoutine3 _    '' address of my routine 3
                                                  }
                               
dim myVariable as uByte = 1

gosub MyRoutines(myVariable)     '' you can try goto too


myLoop:
goto myLoop


MyRoutine1:
print "MyRoutine 1"
return                   

MyRoutine2:
print "MyRoutine 2"
return                   

MyRoutine3:
print "MyRoutine 3"
return       


Is possible do something like that without a lot of ifs ?


I think i found a solution

The solution i found is this:


dim MyRoutines(2) as uInteger => { @MyRoutine1, _ '' address of my routine 1
@MyRoutine2, _ '' address of my routine 2
@MyRoutine3 _ '' address of my routine 3
}

dim myVariable as uByte = 0


poke uInteger (@pokeGosub1 + 1), MyRoutines(myVariable)

pokeGosub1:
gosub MyRoutine1


myLoop:
goto myLoop


MyRoutine1:
print "MyRoutine 1"
return

MyRoutine2:
print "MyRoutine 2"
return

MyRoutine3:
print "MyRoutine 3"
return


I do a poke with the routine direction just before the gosub

maybe you can implement this with the compiler

this way the behaviour is more like the original ZX spectrum Smile

Print this item

  DEFADD trick with ZX BASIC compiler?
Posted by: maeloterkim - 09-22-2021, 07:45 PM - Forum: Help & Support - Replies (1)

Hi

In the normal basic of zx spectrum 48k there is a behaviour or trick like this

you can change the address of DEFADD variable

and after this you can copy bytes very fast  Is like an assembler LDIR

I will explain more

you can have 2 variables A$ and B$  for example

every one of this variables can have 1000 bytes

when you do A$ = B$  the 1000 bytes of B$ are copied on A$

Normally DEFADD points to the beginning of the variables definitions

for example  (invented numbers)

DEFADD_POINTER_ADDRESS    ;;'' defadd initial definitions of variables
A$ begins on 30000 and have 1000 bytes of size
B$ begins on 32000 and have 1000 bytes of size
etc ...


The trick is that in BASIC we can change the DEFADD address and put any thing

for example we can do

CHANGED_DEFADD_POINTER_ADDRESS    ;;'' CHANGED defadd initial definitions of variables
A$ begins on 16384 and have 256 bytes of size
B$ begins on 32000 and have 256 bytes of size
etc ...


This way we can do A$ = B$ and copy 256 very fast to the screen !!!

this is better explained here in spanish
https://blog.jafma.net/2020/03/16/effici...m-iv/#sp_5

and here in english
https://blog.jafma.net/2020/03/16/effici...m-iv/#en_5

and here a video in spanish explaining this trick
https://www.youtube.com/watch?v=VKJ2dePykdA

I tried this trick with compiled zx basic but is not working because seems
that string variables are not doing the same behavior that original ROM

Print this item

  Is there a list somewhere that explains how to optimize?
Posted by: maeloterkim - 09-15-2021, 06:19 AM - Forum: Help & Support - Replies (2)

Hi

Is there a list somewhere that explains how to optimize?

i  explain

Normally in compilers if you put the code in one way it is more efficient than if you put the code in another way

For example you can do

variable ++    or   variable = variable + 1

or maybe if you use local variables it is more efficient than if you use global variables

perhaps the compiler translates with fewer bytes and more efficiently one way or another

Is there somewhere a recomended list of tricks to write a more efficient syntax that translates better to assembler

and uses less memory and fewer bytes?

Print this item

  warning: [W180] Unreachable code problem?
Posted by: maeloterkim - 09-10-2021, 06:17 PM - Forum: Bug Reports - Replies (5)

Hi  if i compile this, says

warning: [W180] Unreachable code

but i don't know why


the version is  zxbasic-1.15.2





Code:
' EXAMPE UNRECHABLE CODE

declare sub mySub()

Dim myNumber As uByte
cls

myBucle:
    for myNumber = 0 to 7          
        mySub()                  
    next myNumber
    goto myBucle

sub mySub()

end sub

Print this item

  why is there 2 halt on waitretrace macro?
Posted by: maeloterkim - 09-09-2021, 06:02 PM - Forum: Help & Support - Replies (1)

why is there 2 halt on waitretrace macro?

i found in the library this waitretrace macro in the  retrace.bas  file

REM simple WaitRetrace macro

#ifndef waitretrace
#define waitretrace 'REM Retrace \
asm \
halt \
halt \
end asm

#endif


Is not better put only one halt for better timer control of the programmer?

if there was only one halt is more easy to control

with one halt we can do

waitretrace  ->  only 1 halt  1/50 seconds

2 halt      -> 2/50seconds
waitretrace   
waitretrace    

N halt    -> N/50seconds
for i = 1 to N
   waitretrace
next i

Print this item

  It is possible to read the state of the flags with basic
Posted by: maeloterkim - 09-07-2021, 03:12 PM - Forum: Help & Support - Replies (2)

Hi  Smile

In assembler there is a register that have the state of the flags zero, carry , etc

It is possible to read the state of the flags ONLY WITH BASIC (NOT ASSEMBLER) or the state of the carry flag, zero flag etc

Print this item

  Is posible put a ubyte variable just after DIM
Posted by: maeloterkim - 09-04-2021, 02:17 PM - Forum: Help & Support - Replies (2)

Hi

Is posible put a ubyte variable just after DIM   WITHOUT ASSEMBLER  maybe with AT @  or something

Example:

Code:
DIM udg(1, 7) AS uByte => {{0,1,3,7,15,31,63,127}, _
                           {1,2,4,7,15,31,63,127}}

DIM myVariable as ubyte 

I WANT THIS VARIABLE VALUE JUST THE NEXT BYTE AT THE END OF LAST UDG DIM BYTE LIKE THIS

ADDRESS       1  2  3  4   5   6   7   8     9  10   11  12   13   14   15   16        17
VALUE         0  1  3  7  15  31  63  127    1   2   4    7   15   31   63   127    myVariable
              --------------------      DIM UDG  -------------------------------

Print this item

  print42() to allow CR chr$(13)
Posted by: RandomiserUsr - 09-03-2021, 11:16 PM - Forum: Wishlist - Replies (2)

Trying to use CHR$(13) in print42() and it is ignored - could this be implemented please?


Thanks

Print this item

  struggle on using/implementing sprite libraries
Posted by: nitrofurano - 08-25-2021, 08:02 PM - Forum: Wishlist - Replies (2)

since a long time i was thinking how simple or possible would be using sprite engines/libraries on zxbasic-compiler (just like those used on z88dk and so on)

so i started to try this (very glitchy and inefficient, as the code shows... Big Grin  )

(wsad or cursors for moving)

Code:
ink 1
border 1:ink 5:bright 1: paper 1: cls

sub putudgsprite(txp1 as uinteger,typ1 as uinteger,tad1 as uinteger)
  poke uinteger $5C7B,tad1+(7-(typ1 mod 8))+(txp1 mod 8)*32
  print at int(typ1/8),int(txp1/8);"\A\C"
  print at 1+int(typ1/8),int(txp1/8);"\B\D"
  end sub

yo=0:xo=0
putudgsprite(xo,yo,@udg01)
x1=128:y1=128

do
  cn1=((255-(in 64510)) band 2)/2 bor ((255-(in 65022)) band 2) bor ((255-(in 65022)) band 1)*4 bor ((255-(in 65022)) band 4)*2 :'- wsad
  cn2=((255-(in 61438)) band 8)/8 bor ((255-(in 61438)) band 16)/8 bor ((255-(in 63486)) band 16)/4 bor ((255-(in 61438)) band 4)*2 :'-7658
  cn0=cn1 bor cn2
  x1=x1-((cn0 band 4)/4)
  x1=x1+((cn0 band 8)/8)
  y1=y1-((cn0 band 1)/1)
  y1=y1+((cn0 band 2)/2)
  over 1 
  putudgsprite(xo,yo,@udg01)
  xo=x1:yo=y1
  putudgsprite(x1,y1,@udg01)
  pause 1
  loop

do:loop

udg01:
asm
defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000

defb %11111111
defb %11111111
defb %11111111
defb %11111111
defb %11111111
defb %11111111
defb %11111111
defb %11111111

defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000

defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000

defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000

defb %01111111
defb %01111111
defb %01111111
defb %01111111
defb %01111111
defb %01111111
defb %01111111
defb %01111111

defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000

defb %10000000
defb %10000000
defb %10000000
defb %10000000
defb %10000000
defb %10000000
defb %10000000
defb %10000000

defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000

defb %00111111
defb %00111111
defb %00111111
defb %00111111
defb %00111111
defb %00111111
defb %00111111
defb %00111111

defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000

defb %11000000
defb %11000000
defb %11000000
defb %11000000
defb %11000000
defb %11000000
defb %11000000
defb %11000000

defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000

defb %00011111
defb %00011111
defb %00011111
defb %00011111
defb %00011111
defb %00011111
defb %00011111
defb %00011111

defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000

defb %11100000
defb %11100000
defb %11100000
defb %11100000
defb %11100000
defb %11100000
defb %11100000
defb %11100000

defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000

defb %00001111
defb %00001111
defb %00001111
defb %00001111
defb %00001111
defb %00001111
defb %00001111
defb %00001111

defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000

defb %11110000
defb %11110000
defb %11110000
defb %11110000
defb %11110000
defb %11110000
defb %11110000
defb %11110000

defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000

defb %00000111
defb %00000111
defb %00000111
defb %00000111
defb %00000111
defb %00000111
defb %00000111
defb %00000111

defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000

defb %11111000
defb %11111000
defb %11111000
defb %11111000
defb %11111000
defb %11111000
defb %11111000
defb %11111000

defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000

defb %00000011
defb %00000011
defb %00000011
defb %00000011
defb %00000011
defb %00000011
defb %00000011
defb %00000011

defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000

defb %11111100
defb %11111100
defb %11111100
defb %11111100
defb %11111100
defb %11111100
defb %11111100
defb %11111100

defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000

defb %00000001
defb %00000001
defb %00000001
defb %00000001
defb %00000001
defb %00000001
defb %00000001
defb %00000001

defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000

defb %11111110
defb %11111110
defb %11111110
defb %11111110
defb %11111110
defb %11111110
defb %11111110
defb %11111110

defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000
defb %00000000

end asm

so, any idea of using "true" sprites instead of that attempt above? Big Grin

Print this item

  #include MACRO
Posted by: RandomiserUsr - 08-21-2021, 11:48 AM - Forum: Help & Support - Replies (2)

I wonder if you could show some examples of how to use #include MACRO introduced in 1.5.1 as I don't see anything in the wiki

thanks

Print this item