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

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: 14671
Location: Origae-6

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: 471
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: 6404
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: 1185
Location: Athens
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: 1185
Location: Athens

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: 1185
Location: Athens
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: upper,lower,pad,base.

Code:

    rem  Decimal to Base 2-36

    cls
    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$ + UPPER(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

start#
    cls:cursor 0,0: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 11 Apr 2017, 08:33; edited 8 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: 140
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 Reply with quote
Picnic



Joined: 05 May 2007
Posts: 1185
Location: Athens
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.

Hobby Basic examples:

Hex dump of a file.

Code:

    rem  Hex dump of file

    cls
    input "filename: ",path$
    a$=TRIM(path$)
    if LEN(a$)<1 then end
    r=SIZE(a$)
    if r<1 then print r: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 "a.txt",a$,2
    until data>data.end
    exec "start notepad.exe a.txt"
    end



Image



Displaying an About Box.

Code:

    rem  About Box

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

    cursor 0,0
    screen 80,40

    r=12
    c=VAR0/2
    y=VAR1/2-r/2
    x=c/2
    dim row[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  <"

    cls
    title a$[0]
    file "About.bas",a$,1
    for i=1 to LEN(a$step 256:print MID(a$,i,256),:next i
    gosub About
    end

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



Image



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 11 Apr 2017, 08:37; edited 1 time in total
Post 22 Dec 2016, 07:49
View user's profile Send private message Reply with quote
Picnic



Joined: 05 May 2007
Posts: 1185
Location: Athens
Hobby Basic Version 0.86
I have uploaded a new version with bug fixes and various internal tweaking.
More examples were added raising the number to 18.

Hobby Basic can now open both local and Internet text files.
The following examples tested on Windows XP and 7.


Code:

    ! Get Internet file size

    url$ = 'https://sites.google.com/site/hobbybasicfiles/'
    dim demo$[8] = 'Demo' ,'Draw''Tetris''XO''Dump''Radix''Greek''About'
    nbytes = 0
    cls

    for i = 0 to 7

        name$ = demo$[i] + '.bas'
        path$ = url$ + name$

        nbytes = size(path$)

        if nbytes <> -1
            print name$' 'nbytes' bytes'
        else
            print name$' NOT found'
        endif

    next i
    end



Image



This example loads a series of text images from the Internet.

Code:

    ! Load ASCII art from Internet

    screen 80,25
    cursor 0,0
    cls

    url$ = 'https://sites.google.com/site/hobbybasicfiles/'
    dim img$[3] = 'City''Hi''Anime'
    i=0 : r=0 : x=0 : y=0

    for i = 0 to 2
        path$ = url$ + img$[i]
        if size(path$) <> -1
            file path$a$1
            cls:color 15,0
            title img$[i]
            print a$
        else
            title img$[i], ' NOT found'
        endif
        wait 1500
    next i
    end



Image



This example downloads fasmw package directly from website.

Code:

    ! Download fasm package

    version$ = "17160"
    url$ = "http://flatassembler.net/fasmw"
    name$ = version$ + ".zip"
    path$ = url$ + name$

    cls
    print "Downloading fasmw",name$,"...",
    if size(path$) <> -1
        file path$01
        print "done"
    else
        print "failed"
    endif
    end


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.