flat assembler
Message board for the users of flat assembler.

Index > Tutorials and Examples > Hobby Basic, a toy language interpreter written in fasm

Goto page 1, 2, 3, 4  Next
Author
Thread Post new topic Reply to topic
Picnic



Joined: 05 May 2007
Posts: 1291
Location: Paradise Falls
Picnic
Image

Hobby Basic is a toy interpreter for the Windows console.
It has a BASIC-like syntax.
Its implemented in fasm.

Download


An example written in Hobby Basic.
Code:

    rem  TV.BAS
    rem  Hobby Basic Interpreter

    a$ = 'N  O   S  I  G  N  A  L'

    dim c[8] = 15,14,11,10,13,12,9,0

    title a$

    screen 80,25,300
    cursor 0,0
    color 0,7
    cls

    for x = 0 to 7
        color c[x],0
        paint x*10,0,10,25,0x20,1
    next x

    erase 17
    erase 18
    erase 19

    pen 15
    at 25,18,a$

    locate 0,24
    inkey

    cls : end
    

Image



How to run the examples.

Open the command-line CMD.EXE in the HB folder.
To run the TV.BAS example, type:
Code:
hb EXAMPLES/TV.BAS    


Image



Note for Windows 10 users.

If Hobby Basic is not displaying or operating correctly in the default Windows 10 console,
enable the legacy option to have the maximum compatibility.

Image


Last edited by Picnic on 19 Jan 2021, 13:16; edited 229 times in total
Post 05 May 2013, 21:16
View user's profile Send private message Reply with quote
AsmGuru62



Joined: 28 Jan 2004
Posts: 1422
Location: Toronto, Canada
AsmGuru62
Great stuff!
Things like that motivate beginners to start programming.
Post 05 May 2013, 22:15
View user's profile Send private message Send e-mail Reply with quote
MHajduk



Joined: 30 Mar 2006
Posts: 6038
Location: Poland
MHajduk
I suppose that the author's sentiment to QuickBasic was the main inspiration for this project. Nice thing. Smile
Post 05 May 2013, 22:28
View user's profile Send private message Visit poster's website Reply with quote
typedef



Joined: 25 Jul 2010
Posts: 2914
Location: 0x77760000
typedef
Nice. This prompts me to make a CLI graphics library. Looks pretty neat.
Post 07 May 2013, 04:31
View user's profile Send private message Reply with quote
Picnic



Joined: 05 May 2007
Posts: 1291
Location: Paradise Falls
Picnic
I am glad you like it, i had some concern whether it can be served as an example or tutorial due to the lack of source code.


Last edited by Picnic on 19 Nov 2019, 20:26; edited 11 times in total
Post 07 May 2013, 10:10
View user's profile Send private message Reply with quote
TmX



Joined: 02 Mar 2006
Posts: 825
Location: Jakarta, Indonesia
TmX
This is very nice.
Reminiscent of DOS apps.

Mouse handling would be a nice addition, I think Wink
Post 07 May 2013, 15:45
View user's profile Send private message Reply with quote
HaHaAnonymous



Joined: 02 Dec 2012
Posts: 1180
Location: Unknown
HaHaAnonymous
[ Post removed by author. ]


Last edited by HaHaAnonymous on 28 Feb 2015, 20:54; edited 1 time in total
Post 07 May 2013, 20:58
View user's profile Send private message Reply with quote
typedef



Joined: 25 Jul 2010
Posts: 2914
Location: 0x77760000
typedef
Picnic wrote:
I am glad you like it, i had some concern whether it can be served as helpful example despite the lack of comments in source.


If it can be understood then no worries.

Besides not all examples are aimed at beginners.
Post 07 May 2013, 23:30
View user's profile Send private message Reply with quote
Picnic



Joined: 05 May 2007
Posts: 1291
Location: Paradise Falls
Picnic
TmX wrote:
Mouse handling would be a nice addition, I think Wink


Hobby Basic Version 0.0.2

I have uploaded a new version with minor improvements and bug fixes. Mouse support is now available.


Random colored characters.
Code:

    rem  RND.BAS
    rem  Hobby Basic Interpreter

    color 0,0 : cls

    do

        x = RND() % 24 + 2
        y = RND() % 14 + 1
        c = RND() % 95 + 32
        pen c
        at x,y,CHR(c)

    until KEY(-1)

    locate 0,15
    end
    

Image


Last edited by Picnic on 19 Jan 2021, 13:17; edited 35 times in total
Post 18 Aug 2013, 22:52
View user's profile Send private message Reply with quote
Picnic



Joined: 05 May 2007
Posts: 1291
Location: Paradise Falls
Picnic
I have uploaded a new version with minor improvements and bug fixes.

Hobby Basic Version 0.0.3


Reading mouse input in the console.
Code:

    rem  MOUSE.BAS
    rem  Hobby Basic Interpreter
    rem
    rem  mouse {}  --> V0,V1,V2,V3
    rem  Returns:
    rem  V0 = cell x
    rem  V1 = cell y
    rem  V2 = 1 left btn, 2 right btn, 4 double click, 254 lost focus, 255 got focus
    rem  V3 = coordinates in pixels (high/low order word)

    screen -1,-1
    if V0 < 80 then screen 80,25

    cls : print 'click mouse inside window'

    x = -1
    y = -1

    do

        mouse

        if (V0 <> x or V1 <> y)
            x = V0
            y = V1
            a$ = STR(x) + ',' + STR(y)
            title a$
        endif

        if V2 = 1
            ? a$ , ' left button'
        elseif V2 = 2
            ? a$ , ' right button'
        elseif V2 = 4
            ? a$ , ' double click'
        endif

    until KEY(27)
    end
    

Image


Last edited by Picnic on 08 Jan 2021, 14:26; edited 28 times in total
Post 15 Dec 2013, 01:37
View user's profile Send private message Reply with quote
typedef



Joined: 25 Jul 2010
Posts: 2914
Location: 0x77760000
typedef
I get this when I run MOUSE

Image
Post 15 Dec 2013, 05:58
View user's profile Send private message Reply with quote
Picnic



Joined: 05 May 2007
Posts: 1291
Location: Paradise Falls
Picnic
Thanks for the feedback typedef. Can you please tell me your Windows version and if you tried the rest of the samples?
Post 15 Dec 2013, 10:10
View user's profile Send private message Reply with quote
typedef



Joined: 25 Jul 2010
Posts: 2914
Location: 0x77760000
typedef
Windows 7 64 bit. Actually all the programs except the binary and the the color ones. And why it says print I don't know
Post 15 Dec 2013, 14:27
View user's profile Send private message Reply with quote
Picnic



Joined: 05 May 2007
Posts: 1291
Location: Paradise Falls
Picnic
I will look into the problem as soon as i can. I starting to feel a bit outdated with my windows xp 32-bit.


Last edited by Picnic on 15 Dec 2013, 17:35; edited 1 time in total
Post 15 Dec 2013, 17:28
View user's profile Send private message Reply with quote
typedef



Joined: 25 Jul 2010
Posts: 2914
Location: 0x77760000
typedef
I see. It's a version difference thing.
Post 15 Dec 2013, 17:34
View user's profile Send private message Reply with quote
Picnic



Joined: 05 May 2007
Posts: 1291
Location: Paradise Falls
Picnic
I think i found what was causing the trouble. Give it a try if you like typedef.
Post 18 Dec 2013, 21:33
View user's profile Send private message Reply with quote
typedef



Joined: 25 Jul 2010
Posts: 2914
Location: 0x77760000
typedef
They work now Very Happy. Care to share what was causing it to say that?
Post 18 Dec 2013, 22:53
View user's profile Send private message Reply with quote
Picnic



Joined: 05 May 2007
Posts: 1291
Location: Paradise Falls
Picnic
Nice to hear!
Sure, it seems that an improper call to SetConsoleOutputCP function crush the program. By the way, i installed Windows 7.
Post 19 Dec 2013, 21:09
View user's profile Send private message Reply with quote
typedef



Joined: 25 Jul 2010
Posts: 2914
Location: 0x77760000
typedef
Picnic wrote:
Nice to hear!
Sure, it seems that an improper call to SetConsoleOutputCP function crush the program. By the way, i installed Windows 7.


Hmm. Nice, what Win7 version?
Post 20 Dec 2013, 01:13
View user's profile Send private message Reply with quote
Picnic



Joined: 05 May 2007
Posts: 1291
Location: Paradise Falls
Picnic
I have uploaded a new version with minor improvements and bug fixes.

Hobby Basic Version 0.0.4


Tetris game in console. This is the first Hobby Basic game ever.
Code:

    rem  TETRIS.BAS
    rem  Hobby Basic Interpreter

    dim piecex[4]
    dim piecey[4]
    dim nextpiecex[4]
    dim nextpiecey[4]
    dim kbd[5]=27,37,38,39,40
    dim tbl[4]=40,100,300,1200

    path$ = PATH('DATA\TETRIS.TXT')
    if SIZE(path$) = -1 then save path$,'100'

    load path$,best$
    best$ = TRIM(best$)

    title 'Tetris in Hobby Basic'

    screen -1,-1
    if V1 < 30 then screen 80,30,300

    cursor 0,0
    color 0,0
    cls

Restart#
    gosub Initialize
    gosub PlayGame
    gosub GameOver
    goto Restart

PlayGame#
    do : gosub GetKeys
        if TICK() - now > time
            gosub DeletePiece
            gosub Move40
            gosub PrintPiece
            now = TICK()
        endif
        wait 1
    until k = 27
    return

GetKeys#
    for a = 0 to 4
        if KEY(kbd[a])
            k = kbd[a]
            if k = 27 then break
            gosub DeletePiece
            gosub Move//k
            gosub PrintPiece
            break
        endif
    next
    wait 40000
    return

Move38#
    for i = 0 to 3
        if CELL(x+2-piecex[i], y+piecey[i]) <> ' ' then return
    next
    for i = 0 to 3
        temp = piecex[i]
        piecex[i] = 2-piecey[i]
        piecey[i] = temp
    next
    wait 50000
    return

Move37#
    for i = 0 to 3
        if CELL(x-1+piecex[i], y+piecey[i]) <> ' ' then return
    next
    x = x - 1
    return

Move39#
    for i = 0 to 3
        if CELL(x+1+piecex[i], y+piecey[i]) <> ' ' then return
    next
    x = x + 1
    return

Move40#
    for r = 0 to 3
        if CELL(x+piecex[r], y+1+piecey[r]) <> ' '
            gosub PrintPiece
            x = startx
            y = starty
            gosub GetPiece
            if k = 27 then break
            gosub CheckLines
            return
        endif
    next
    y = y + 1
    return

CheckLines#
    ln = 0
    for j = toplefty to maxy
        gosub CheckLine
    next
    if ln > 0
        time = time - 2
        score = score + tbl[ln-1]
        gosub PrintScore
    endif
    return

CheckLine#
    for i = topleftx to maxx
        if CELL(i,j) <> 35 then return
    next
    for i = topleftx to maxx
        at i,j,' '
    next
    for l = 0 to j-toplefty-1
        for n = topleftx to maxx
            info n,j-l-1
            i = V0
            pen V2
            at n,j-l,CHR(i)
        next
    next
    ln = ln + 1
    return

PrintScore#
    at 10,8,score
    return

GetPiece#
    for i=0 to 3
        piecex[i] = nextpiecex[i]
        piecey[i] = nextpiecey[i]
    next
    gosub DeleteNextPiece
    gosub GetNextPiece
    gosub PrintNextPiece
    for i=0 to 3
        if CELL(x+piecex[i], y+piecey[i]) <> ' '
        k = 27
        break
    endif
    next
    return

GetNextPiece#
    i = RND()%5 : nextcolor = i + 9
    if i = 0
        nextpiecex[0] = 0
        nextpiecey[0] = 1
        nextpiecex[1] = 1
        nextpiecey[1] = 1
        nextpiecex[2] = 0
        nextpiecey[2] = 2
        nextpiecex[3] = 1
        nextpiecey[3] = 2
    elseif i = 1
        nextpiecex[0] = 0
        nextpiecey[0] = 1
        nextpiecex[1] = 1
        nextpiecey[1] = 1
        nextpiecex[2] = 2
        nextpiecey[2] = 1
        nextpiecex[3] = 0
        nextpiecey[3] = 2
    elseif i = 2
        nextpiecex[0] = 0
        nextpiecey[0] = 1
        nextpiecex[1] = 1
        nextpiecey[1] = 1
        nextpiecex[2] = 2
        nextpiecey[2] = 1
        nextpiecex[3] = 1
        nextpiecey[3] = 2
    elseif i = 3
        nextpiecex[0] = 0
        nextpiecey[0] = 1
        nextpiecex[1] = 1
        nextpiecey[1] = 1
        nextpiecex[2] = 2
        nextpiecey[2] = 1
        nextpiecex[3] = 2
        nextpiecey[3] = 2
    elseif i = 4
        nextpiecex[0] = 0
        nextpiecey[0] = 1
        nextpiecex[1] = 1
        nextpiecey[1] = 1
        nextpiecex[2] = 2
        nextpiecey[2] = 1
        nextpiecex[3] = 3
        nextpiecey[3] = 1
    endif
    return

PrintPiece#
    pen printcolor
    for i = 0 to 3
        at x+piecex[i],y+piecey[i],'#'
    next
    pen 7
    return

DeletePiece#
    for i = 0 to 3
        at x+piecex[i],y+piecey[i],' '
    next
    return

PrintNextPiece#
    pen nextcolor
    for i = 0 to 3
        at nextx+nextpiecex[i],nexty+nextpiecey[i],'#'
    next
    pen 7
    return

DeleteNextPiece#
    printcolor = nextcolor
    for i = 0 to 3
        at nextx+nextpiecex[i],nexty+nextpiecey[i],' '
    next
    return

GameOver#
    pen 5
    paint 18,2,20,26,-1,1
    pen 7
    at 24,14,'GAME OVER'
    if score > VAL(best$)
        best$ = STR(score)
        save path$,best$
    endif
    inkey
    return

Initialize#
    color 0,8
    at 0,0, '░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░'
    at 0,1, '░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░'
    at 0,2, '░                                    ░░'
    at 0,3, '░     TETRIS                         ░░'
    at 0,4, '░                                    ░░'
    at 0,5, '░░░░░░░░░░░░░░░░░░                    ░░'
    at 0,6, '░░░░░░░░░░░░░░░░░░                    ░░'
    at 0,7, '░                                    ░░'
    at 0,8, '░  Score: 0                          ░░'
    at 0,9, '░                                    ░░'
    at 0,10,'░░░░░░░░░░░░░░░░░░                    ░░'
    at 0,11,'░░░░░░░░░░░░░░░░░░                    ░░'
    at 0,12,'░                                    ░░'
    at 0,13,'░  Best:                             ░░'
    at 0,14,'░                     Press SPACE    ░░'
    at 0,15,'░░░░░░░░░░░░░░░░░░                    ░░'
    at 0,16,'░░░░░░░░░░░░░░░░░░                    ░░'
    at 0,17,'░                                    ░░'
    at 0,18,'░  Next:                             ░░'
    at 0,19,'░                                    ░░'
    at 0,20,'░                                    ░░'
    at 0,21,'░                                    ░░'
    at 0,22,'░░░░░░░░░░░░░░░░░░                    ░░'
    at 0,23,'░░░░░░░░░░░░░░░░░░                    ░░'
    at 0,24,'░░░░░░░░░░░░░░░░░░                    ░░'
    at 0,25,'░░░░░░░░░░░░░░░░░░                    ░░'
    at 0,26,'░░░░░░░░░░░░░░░░░░                    ░░'
    at 0,27,'░░░░░░░░░░░░░░░░░░                    ░░'
    at 0,28,'░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░'
    at 0,29,'░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░'
    at 9,13,best$
    printcolor = 0
    nextcolor = 0
    topleftx = 18
    toplefty = 3
    maxx = 37
    maxy = 27
    startx = 27
    starty = 2
    x = startx
    y = starty
    nextx = 10
    nexty = 18
    time = 250
    score = 0
    i=0:k=0:r=0:j=0:l=0:n=0:ln=0:z=0:now=TICK()
    inkey:if V0=27 then cls:end
    paint 18,2,20,26,-1,-1
    gosub GetNextPiece
    gosub GetPiece
    gosub PrintScore
    gosub PrintNextPiece
    return
    

Image


Last edited by Picnic on 19 Jan 2021, 13:18; edited 23 times in total
Post 20 Dec 2013, 20:37
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page 1, 2, 3, 4  Next

< 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


Copyright © 1999-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.