flat assembler
Message board for the users of flat assembler.
 Home   FAQ   Search   Register 
 Profile   Log in to check your private messages   Log in 
flat assembler > Examples and Tutorials > Hobby Basic, a BASIC-like interpreter for Windows

Goto page Previous  1, 2, 3
Author
Thread Post new topic Reply to topic
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 14924
Location: 6EQUJ5

filox wrote:
Sorry but where i can find sources of Hobbybasic?

Have a look at the first post in this thread.
Post 21 Oct 2016, 12:13
View user's profile Send private message Visit poster's website Reply with quote
system error



Joined: 01 Sep 2013
Posts: 521
This is good. Keep it coming, bro!
Post 22 Oct 2016, 13:32
View user's profile Send private message Reply with quote
filox



Joined: 13 Feb 2013
Posts: 10

revolution wrote:

filox wrote:
Sorry but where i can find sources of Hobbybasic?

Have a look at the first post in this thread.



No source, only EXE and Demo.bas
Post 26 Oct 2016, 12:24
View user's profile Send private message Reply with quote
sleepsleep



Joined: 05 Oct 2006
Posts: 6649
Location: ˛                              ⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣ Posts: 6699
hi filox,
you could try pm picnic for source etc
Post 26 Oct 2016, 12:36
View user's profile Send private message Reply with quote
Picnic



Joined: 05 May 2007
Posts: 1201
Location: Athens, Greece
Hi filox, the source is not available, at least not yet. Hobby Basic has still some way to go. I want to extend the command list, find methods to make the intepreter faster, add features like user procedures with parameters and local variables and some other ideas i have. This is done somewhat slowly, the only days i can steal some time to work are the weekends.
Post 26 Oct 2016, 13:37
View user's profile Send private message Reply with quote
filox



Joined: 13 Feb 2013
Posts: 10

Picnic wrote:
Hi filox, the source is not available, at least not yet. Hobby Basic has still some way to go. I want to extend the command list, find methods to make the intepreter faster, add features like user procedures with parameters and local variables and some other ideas i have. This is done somewhat slowly, the only days i can steal some time to work are the weekends.



Hi picnic, if u can share code with us, we can help you possibly to improve it faster and i'm interested in it for educational scope Very Happy
Post 18 Nov 2016, 13:19
View user's profile Send private message Reply with quote
Picnic



Joined: 05 May 2007
Posts: 1201
Location: Athens, Greece

Quote:
...and i'm interested in it for educational scope


Take a look at MINI-BASIC for fasm. It's a piece of code available for modifications.
Post 21 Nov 2016, 15:50
View user's profile Send private message Reply with quote
Picnic



Joined: 05 May 2007
Posts: 1201
Location: Athens, Greece
I have uploaded a new version with bug fixes and various internal tweaking.

From now on, commands and function names are case insensitive.

So a$ and A$ are different strings but now you can print :

Code:

    print len(a$)
    PRINT LEN(a$)
    Print Len(a$)




A print function e.g. hex(x) can also used in strings.

Code:

    print hex(255! prints FF
    x=hex(255)     ! x=255
    a$=hex(255)    ! a$='FF'





New commands: on...gosub and on...goto

Code:

  for x=1 to 3
      on x gosub L1,L2,L3
  next x
  end

  L1print 'Label 1':return
  L2print 'Label 2':return
  L3print 'Label 3':return





New string functions: ucase,lcase,pad,base.

Code:

    rem  Decimal to Base 2-36

    crlf$ = CHR(13) + CHR(10)

    input "Enter a decimal value:",n
    if n > 0

        a$ = "Decimal:  " + STR(n)

        for i = 2 to 36
            a$ = a$ + crlf$
            a$ = a$ + "Base " + PAD(STR(i),'0',2) + ":  "
            a$ = a$ + UCASE(BASE(n,i))
        next i

        alert a$

    endif
    end





Simple Xs and Os game in Hobby Basic.

Code:

    rem  Xs and Os for Hobby Basic

    P1 fix m[x,y]
    P2 fix m[x+i,y+j]
    P3 fix m[x+i*2,y+j*2]
    screen 80,25
        cursor 0,0

start#
    color 0,7:cls:locate 0,15
    n=0:dim m[3,3]=0,0,0,0,0,0,0,0,0
    at 4,1,"Xs and Os"
    at 0,3,"Player X  vs  CPU O"
    paint 1,7,17,1,'_',0
    paint 1,10,17,1,'_',0
    paint 6,5,1,9,'|',0
    paint 12,5,1,9,'|',0
    @@at 0,15,"Play first? [y/n]"
    inkey:p=VAR0:if p=27 then end
    if p='y' or p='Y' then p=1 else p=0
    at 0,15,"Strong CPU? [y/n]"
    inkey:z=VAR0:if z=27 then goto @b
    do
        if p=0 then gosub cpu_move else gosub player_move
        gosub is_winner:p=p^1:n=n+1
    until w<>0 or n=9
    pen 7:erase 0,15,30,' ',0
    if w=0 then at 0,15,"Game was a draw"
    if w=1 then at 0,15,"Player X has won!"
    if w=2 then at 0,15,"CPU O has won!"
    at 0,16,"press a key":inkey:goto start

player_move#
    pen 7:at 0,15,"Player X''s turn       "
    @@mouse:x=(VAR0+1)/7:y=(VAR1+4)/3-3:btn=VAR2:wait 1
    if x<0 or x>2 or y<0 or y>2 or btn=0 then goto @b
    if m[x,y]=0 then m[x,y]=1:pen 10:at x*6+3,y*3+6,'X':return
    goto @b

cpu_move#
    pen 7:at 0,15,"CPU O''s turn          "
    b=0:cx=0:cy=0
    x=0:i=1:j=0:for y=0 to 2:gosub scoring:next y
    y=0:i=0:j=1:for x=0 to 2:gosub scoring:next x
    x=2:y=0:i=-1:j=1:gosub scoring
    x=0:i=1:j=1:gosub scoring
    m[cx,cy]=2:wait RND(1000)+400
    pen 15:at cx*6+3,cy*3+6,'O'
    return

scoring#
    r=0:k=0:s=0
    if P1=0 then r=x:k=y:s=1
    if P2=0 then r=x+i:k=y+j:s=1
    if P3=0 then r=x+i*2:k=y+j*2:s=1
    if P1=1 and P2=0 and P3=0 then r=x+i*2:k=y+j*2:s=2
    if P1=0 and P2=1 and P3=0 then r=x:k=y:s=2
    if P1=0 and P2=0 and P3=1 then r=x:k=y:s=2
    if P1=0 and P2=0 and P3=0 then r=x:k=y:s=4
    if P1=2 and P2=0 and P3=0 then r=x+i*2:k=y+j*2:s=8
    if P1=0 and P2=2 and P3=0 then r=x:k=y:s=8
    if P1=0 and P2=0 and P3=2 then r=x:k=y:s=8
    if P1=1 and P2=1 and P3=0 then r=x+i*2:k=y+j*2:s=16
    if P1=1 and P2=0 and P3=1 then r=x+i:k=y+j:s=16
    if P1=0 and P2=1 and P3=1 then r=x:k=y:s=16
    if P1=2 and P2=2 and P3=0 then r=x+i*2:k=y+j*2:s=32
    if P1=2 and P2=0 and P3=2 then r=x+i:k=y+j:s=32
    if P1=0 and P2=2 and P3=2 then r=x:k=y:s=32
    if m[1,1]=0 and z='y' then r=1:k=1:s=64
    if s>b then b=s:cx=r:cy=k
    return

is_winner#
    w=0:x=0:i=1:j=0:for y=0 to 2:gosub win:next y
    y=0:i=0:j=1:for x=0 to 2:gosub win:next x
    x=2:y=0:i=-1:j=1:gosub win
    x=0:i=1:j=1:gosub win
    return

win#
    if P1=1 and P2=1 and P3=1 then w=1
    if P1=2 and P2=2 and P3=2 then w=2
    return



Image


Last edited by Picnic on 15 Aug 2017, 16:46; edited 11 times in total
Post 21 Dec 2016, 12:34
View user's profile Send private message Reply with quote
avcaballero



Joined: 02 Feb 2004
Posts: 146
Location: Madrid - Spain
Hello, it is very interesting. I was very fond of qbasic. I'd just say that it would be nice to see your page in English, Greek is a bit hard for me Smile
Post 21 Dec 2016, 13:20
View user's profile Send private message Visit poster's website Reply with quote
Picnic



Joined: 05 May 2007
Posts: 1201
Location: Athens, Greece
Hi avcaballero,

I know it resembles qbasic although my purpose is to create some kind of freestyle interpreter. I intend to translate the manual page soon, it is not easy for me since my English are limited.

Some code examples.


This example displays the hex dump of a file in notepad.

Code:

    cls
    input "filename: ",path$
    a$=TRIM(path$)
    if LEN(a$)<1 then end
    r=SIZE(a$):n=0
    if r<1 then print r:pause:end
    dim a[r]
    file a$,a[],1
    data=0:data.end=r/4
    a$='':c$=CHR(13)+CHR(10)
    file "a.txt",0,0
    do
        b$=' '
        a$=PAD(HEX(data*4),'0',8)+':  '
        for i=0 to 3
            for j=0 to 3
                n=(a[data]>>(j*8))&0xff
                a$=a$+PAD(HEX(n),'0',2)+' '
                if n<32 or n>126 then n='.'
                b$=b$+CHR(n)
            next j
            data=data+1
        next i
        a$=a$+b$+c$
        file "dump.txt",a$,2
        title "data chunk ",data/4
    until data>data.end
    exec "start notepad.exe dump.txt"
    end





This example displays an About Box.

Code:

    rem  Display About Box

    GetMouse fix mouse:cx=VAR0:cy=VAR1:btn=VAR2:wait 1

    COLS=90
    ROWS=50
    screen COLS,ROWS
    cursor 0,0
    color 0,7
    cls

    c=40:r=12
    x=(COLS/2)-(c/2)
    y=(ROWS/2)-(r/2)
    dim a[7]=0,2,3,4,6,8,10
    dim a$[7]

    a$[0]="About Box"
    a$[1]="Application Title"
    a$[2]="Copyright (c) 2015-2017"
    a$[3]="By Author, All Rights Reserved"
    a$[4]="This is a freeware program"
    a$[5]="Send comments to <email@address>"
    a$[6]=">  Ok  <"

    file PATH(1),a$,1
    print a$
    gosub About_Box
    pause
    end

About_Box#
    copy x,y,c,r
    color 3,-1
    paint x,y,c,1,' '1
    color 7,-1
    paint x,y+1,c,r-1,' '1
    for i=0 to 6
        if a[i]=0 or a[i]=10 then color 3,15 else color 7,0
        at ((COLS/2)-(LEN(a$[i])/2)),y+a[i],a$[i]
    next i
    do
        GetMouse
    until ((btn>0 and cx>x and cx<x+c and cy>y and cy<y+ror key(27)<>0)
    paste x,y,c,r
    color 0,7
    return






New array features: String arrays.

Code:

    dim a$[12]
    dim b$[12]='Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'

    a$[]=b$[]  ! copy string array

    for i=0 to size(a$[])-1
        print upper(a$[i]),' ',i+1
    next i




Code:

    dim Λίστα$[5]='Άλφα','Βήτα','Γάμα','Δέλτα','Έψιλον'
    dim Λίστα$[10]  ! resize array

    for i=5 to size(Λίστα$[])-1
        input '>',Λίστα$[i]
    next i

    for i=0 to size(Λίστα$[])-1
        if len(Λίστα$[i])>0
            print Λίστα$[i]
        else
            print 'null'
        endif
    next i




Last edited by Picnic on 15 Aug 2017, 16:45; edited 5 times in total
Post 22 Dec 2016, 07:49
View user's profile Send private message Reply with quote
Picnic



Joined: 05 May 2007
Posts: 1201
Location: Athens, Greece
Hobby Basic Version 0.91
I have uploaded a new version with bug fixes and various internal tweaking.
Hobby Basic can now open both local and Internet text files.

The following examples tested on Windows XP/7/8 and 10.


How to get the size of a file.

Code:

    dim a$[3] = "HB.exe" ,"HB.html""TEST.bas"

    for i = 0 to 2
        path$ = PATH(0) + "\" + a$[i]
        n = SIZE(path$)
        if n <> -1
            print a$[i], " "n" bytes"
        else
            print a$[i], " NOT found"
        endif
    next i

    pause





Count the number of lines in a text file.

Code:

    path$ = PATH(0) + "\TEST.bas"
    n = -1 : a$ = ""

    do
        n = n+1
        a$ = READLN(n+1,path$)
    until VAR0 = -1

    print path$,

    if n > 1
        print " contains "n" lines"
    else
        print " NOT found"
    endif

    pause





Load a series of text images from the Internet.

Code:

    cursor 0,0
    cls

    dim img$[4] = "City""Hi""Love""Anime"

    url$ = "https://sites.google.com/site/hobbybasicfiles/"

    for i = 0 to 3
        path$ = url$ + img$[i]
        print "Downloading ",img$[i]
        file path$a$1
        if VAR0 < 0 then print "Can''t open ",img$[i]:pause:end
        file img$[i], 02
        print a$
        wait 1500
    next i

    pause





Download a 10MB test file.

Code:

    url$ = "https://sites.google.com/site/hobbybasicfiles/10MB.zip"

    n = SIZE(url$)

    if n <> -1
        print "Downloading ",n," bytes...",
        t1 = TICK()
        file url$01
        t2 = TICK()-t1
        print "done in ",t2/1000,".",t2%1000," sec"
    else
        print "download failed"
    endif

    pause    


Post 14 Mar 2017, 08:51
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page Previous  1, 2, 3

< Last Thread | Next Thread >

Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001-2005 phpBB Group.

Main index   Download   Documentation   Examples   Message board
Copyright © 2004-2016, Tomasz Grysztar.