Author Topic: MY-BASIC  (Read 85953 times)

Offline Cybermonkey342

  • BASIC Developer
  • Posts: 34
Re: MY-BASIC
« Reply #150 on: February 08, 2016, 11:24:14 am »
@Wang: I used the actual Github sources and ran into a problem ...
The following (part of the) program gives an error:

Code: [Select]
...
do
 cls
 x(i)=mousex
 y(i)=mousey
 gosub draw
 i=i+1
 if i>=1000 then i=i-1000
 sync

until keypressed=true
end

draw:
...
return

The error occurs in the line of the until statement:
Quote
Error: Line 23, Column 5: Wrong function reached in file _core_until
Any idea? Until I compiled it with the new sources it worked fine.

Offline John

  • Forum Support / SB Dev
  • Posts: 3114
    • ScriptBasic Open Source Project
Re: MY-BASIC
« Reply #151 on: February 08, 2016, 11:30:23 am »
Maybe doing a DIF of the two would shed some light.

Offline Cybermonkey342

  • BASIC Developer
  • Posts: 34
Re: MY-BASIC
« Reply #152 on: February 09, 2016, 11:30:14 am »
It also seems that the exit function does'nt work properly anymore. The following code does not draw a mandelbrot with the actual my-basic.c and .h files.
I am using now the older  ones which work fine. I hope you can fix that issues soon.
Code: Text
  1. screen (256,256,"Fractal")
  2.  
  3. bx=0
  4. by=0
  5. bw=256*1
  6. bh=256*1
  7.  
  8. sx=-2.2
  9. sy=-1.7
  10. sw=3.4
  11. sh=3.4
  12.  
  13. cls
  14. time1=tickcount
  15. for x=bx to bx+bw
  16.  for y=by to by+bh
  17.    gx=(x-bx)/bw*sw+sx
  18.    gy=(y-by)/bh*sh+sy
  19.    zx=gx
  20.    zy=gy
  21.    for c=0 to 255
  22.     col = c
  23.     nzx=zx*zx - zy*zy + gx
  24.     zy=2*zx*zy+gy
  25.     zx=nzx
  26.     if zx*zx + zy*zy > 4 then  col = c:  exit
  27.   next
  28.   r = col*256+col*32*0.5
  29.   v = col*256+col*64*0.5
  30.   b = col*256+col*32*0.8      
  31.   ink (r,v,b)
  32.   pset (x,y)
  33.  next
  34.  redraw
  35. next
  36. time2=tickcount
  37. ink (255,255,255)
  38. time=(time2-time1)/1000
  39. drawtext (0,0,"Time needed: "+str (time)+" seconds")
  40. sync
  41. inkey

wangrenxin

  • Guest
Re: MY-BASIC
« Reply #153 on: February 09, 2016, 11:52:19 pm »
Marcus, which revision is the well worked one? I'd check it as soon as possible, but it's not easy to find a debug enviroument during Chinese new year.

EDIT: I finally get a debugger, try the latest revision. I fixed the wrong function error, and the EXIT issue; but there's still an issue with the EXIT statement and multiple line IF statement, I'll check it later seriously.
« Last Edit: February 10, 2016, 05:36:52 am by wangrenxin »

Offline Cybermonkey342

  • BASIC Developer
  • Posts: 34
Re: MY-BASIC
« Reply #154 on: February 10, 2016, 08:48:55 am »
Thanks, and a Happy Chinese New Year. (新年好  ;))

wangrenxin

  • Guest
Re: MY-BASIC
« Reply #155 on: February 11, 2016, 06:14:11 am »
 ;)

I've fixed the EXIT bug with multiple line IF.

Offline John

  • Forum Support / SB Dev
  • Posts: 3114
    • ScriptBasic Open Source Project
Re: MY-BASIC
« Reply #156 on: February 11, 2016, 03:18:59 pm »
Thanks Wang!

I'll give it a try from the embedding standpoint and 64 bit Linux.

Curious. Would you have an interest in contributing to the C BASIC project with your C skills? Maybe converting MyBASIC source to C BASIC could act as a tutorial and make the code easier to read. Even if you have no interest in a make-over, your input would be appreciated if you have time.


wangrenxin

  • Guest
Re: MY-BASIC
« Reply #157 on: February 11, 2016, 10:50:45 pm »
Thank you for inviting me, John. But I'm affraid it's difficult for me to dedicate to more hobby projects now. The CB forums looks interesting, I'll join and take a look around.

Offline John

  • Forum Support / SB Dev
  • Posts: 3114
    • ScriptBasic Open Source Project
Re: MY-BASIC
« Reply #158 on: February 11, 2016, 11:44:58 pm »
C BASIC is a fun project and not really a language. It's a preprocessor helper tool to make C look more like BASIC.


Offline Cybermonkey342

  • BASIC Developer
  • Posts: 34
Re: MY-BASIC
« Reply #159 on: February 13, 2016, 01:16:23 am »
;)

I've fixed the EXIT bug with multiple line IF.

Sorry, but it still doesn't work as expected. I think the problem lies in line 26 of the above fractal example:
Code: [Select]
    if zx*zx + zy*zy > 4 then col = c:  exitThis only works with the older my-basic files. If I change the line into
Code: [Select]
if zx*zx + zy*zy > 4 then
 col = c
exit
endif
it even does not work with that older revision.

Offline John

  • Forum Support / SB Dev
  • Posts: 3114
    • ScriptBasic Open Source Project
Re: MY-BASIC
« Reply #160 on: February 14, 2016, 09:53:52 am »
Is it just EXIT or any compound statement after a THEN?

wangrenxin

  • Guest
Re: MY-BASIC
« Reply #161 on: February 15, 2016, 07:35:44 pm »
Markus, please check the latest revision.

Offline John

  • Forum Support / SB Dev
  • Posts: 3114
    • ScriptBasic Open Source Project
Re: MY-BASIC
« Reply #162 on: February 15, 2016, 08:32:16 pm »
Hi Wang,

Here is my quick test.

Code: [Select]
DECLARE SUB mb_init ALIAS "mbas_init" LIB "mb"
DECLARE SUB mb_dispose ALIAS "mbas_dispose" LIB "mb"
DECLARE SUB mb_open ALIAS "mbas_open" LIB "mb"
DECLARE SUB mb_close ALIAS "mbas_close" LIB "mb"
DECLARE SUB mb_load_str ALIAS "mbas_load_str" LIB "mb"
DECLARE SUB mb_run ALIAS "mbas_run" LIB "mb"

mb_code = """
x = 10 : y = 2 : z = 30

IF x = 1 THEN PRINT "One"; : GOTO Done
IF y = 2 THEN PRINT "Two"; : GOTO Done
IF z = 3 THEN PRINT "Three"; : GOTO Done

Done:

END
"""
mb_init()
mb_open()
mb_load_str(mb_code)
mb_run()
mb_close()
mb_dispose()


jrs@laptop:~/sb/sb22/mybasic$ scriba testmbthen.sb
Two
jrs@laptop:~/sb/sb22/mybasic$


Offline Cybermonkey342

  • BASIC Developer
  • Posts: 34
Re: MY-BASIC
« Reply #163 on: February 22, 2016, 12:25:14 pm »
Markus, please check the latest revision.
Yes, thanks it works now.
Although there's another issue now. If I check if the window was closed MY-BASIC now doesn't end the program anymore.
This does not work:
Code: [Select]
if windowclosed = true then
 end
endif
However, any other function (e.g. exit) is exceuted ...

wangrenxin

  • Guest
Re: MY-BASIC
« Reply #164 on: February 22, 2016, 06:10:28 pm »
If I check if the window was closed MY-BASIC now doesn't end the program anymore.

The TRUE is defined as integer 1 and FALSE as integer 0 in MY-BASIC, that means 1 equals to true, but 2 not equals to true nor equals to false. It won't execute the END statement if windowclosed doesn't equal to 1. Currently, it's able to use following ways to test a condition steady.

1.
Code: Visual Basic
  1. if windowclosed <> false then
  2.  end
  3. endif
  4.  

2.
Code: Visual Basic
  1. if windowclosed then
  2.  end
  3. endif
  4.  

I would dismiss this confusion in later refactoring.