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 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: 17639
Location: In your JS exploiting you and your system
revolution
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: 671
system error
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: 11
filox
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: 9089
Location: ˛                             ⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣Posts: 334455
sleepsleep
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: 1288
Location: Paradise Falls
Picnic
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: 11
filox
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: 1288
Location: Paradise Falls
Picnic
Some minor improvements and bug fixes i noticed.

Hobby Basic Version 0.7.9

Download


Various internal variables and available paths.

Code:

    rem  MISC.BAS
    rem  Hobby Basic Interpreter

    cmdline$ = V0

    rem  Do not write above this line

    dim argv$[8]

    argc = split(cmdline$,' ',argv$[])

    title 'Let''s Hobby'
        
    screen 80,25,300 : cls

    ? 'Current Directory'
    ? 'Hobby Basic Path'
    ? 'File Path'
    ? 'File Name'
    ? 'Windows Path'
    ? 'Interpreter Version'
    ? 'Windows Version'
    ? 'Host Name'
    ? 'Local IP Adrress'
    ? 'Window Title'
    ? 'Screen Resolution'
    ? 'Window Pixels'
    ? 'Window Cells'
    ? 'Cell Pixels'
    ? 'File Bytes'
    ? 'Tick Counter'
    ? 'Local Time'

    for i = 0 to 9
        at 25,i,PATH(i)
    next

    view 1
    at 25,10,(STR(V0)+'x'+STR(V1))

    screen -1,-1
    at 25,11,(STR(V2)+'x'+STR(V3))
    at 25,12,(STR(V0)+'x'+STR(V1))

    info 0,0
    at 25,13,(STR(V3&0xFF)+'x'+STR(V3>>16))

    at 25,14,SIZE(PATH(2))

    for i = 0 to argc - 1
        at 0,i+17,('CmdLine Argv$[' + STR(i) +']')
        at 25,i+17,argv$[i]
    next

    @@#
    at 25,15,STR(TICK(0))
    at 25,16,STR(TICK(1))
    if KEY(27) then cls : end
    wait 1
    goto @b
    

Image


Last edited by Picnic on 06 Sep 2020, 09:22; edited 11 times in total
Post 21 Nov 2016, 15:50
View user's profile Send private message Reply with quote
Picnic



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

Hobby Basic Version 0.8.0

Download


The console has 16 indexed colors from 0 to 15.
In Windows versions above Vista, you can set those to whatever 16 full-RGB colors you like.

Code:

    rem  PALETTE.BAS
    rem  Hobby Basic Interpreter
    rem  rgbc {index,0xBBGGRR}  --> V0

    FULL_BLOCK = 0x2588

    a$ = 'Whatever 16 full-RGB colors you like'

    dim temp[16]

    dim Molokai[16] = 0x121212,0x1080D0,0x98E123,0x43A8D0,0xFA2573,0x8700FF,0xDFD460,\
    0xBBBBBB,0x555555,0x00AFFF,0xB1E05F,0x51CEFF,0xF6669D,0xAF87FF,0xFFF26D,0xFFFFFF

    color 0,0
    cls

    ! store the old RGB values and set new
    for index = 0 to 15
        rgbc index, -1
        temp[index] = V0
        rgbc index, Molokai[index]
    next

    for i = 0 to 7
        pen i
        paint i*3,1,3,2,FULL_BLOCK,1
        pen i + 8
        paint i*3,3,3,2,FULL_BLOCK,1
    next

    locate 0,6

    for i = 0 to 15
        pen i
        ? a$
    next

    inkey

    ! restore the palette
    for index = 0 to 15
        rgbc index, temp[index]
    next

    end  
    

Image


Last edited by Picnic on 06 Sep 2020, 09:22; edited 55 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: 191
Location: Madrid - Spain
avcaballero
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: 1288
Location: Paradise Falls
Picnic
I have uploaded a new version with minor improvements and bug fixes.

Hobby Basic Version 0.9.7

Download


P2P Drawing via UDP sockets. Changes appear in real time between the 2 PC's.

Code:

    rem  P2P Drawing via UDP sockets
    rem  Click left mouse button to paint a cell
    rem  Click right mouse button to clear a cell
    rem  Swap the connection ports between the hosts
    rem  Set ipv4$ to remote computer address '192.168.1.xxx'

    getmouse()  fix  mouse:x=V0:y=V1:btn=V2:wait 1

    LOCAL_PORT = 50001
    REMOTE_PORT = 50002
    ipv4$ = 'localhost'

    px = -1
    py = -1

    if OPEN(LOCAL_PORT) = -1 then alert 0x10,'socket error ',STR(V0) : end

    title  'P2P Drawing via UDP sockets running on ',PATH(8)
    cursor 0,0
    color 0,0
    cls

    do

        getmouse()
        if (btn = 1 or btn = 2)
            if btn = 2 then c = 0 else c = 0x2588
            do : getmouse()
                if (x <> px or y <> py)
                    pen 15
                    at x,y,CHR(c)
                    px = x
                    py = y
                    ! send data string
                    a$ = STR((((x<<7)|y)<<15)|c)
                    n = SEND(ipv4$,REMOTE_PORT,a$)
                endif
            until btn = -1
        endif

        ! handle incoming messages
        while LEN(QUEUE(1))
            n = VAL(QUEUE(0))
            x = BITS(n,28,7)
            y = BITS(n,21,7)
            c = BITS(n,14,15)
            pen 9
            at x,y,CHR(c)
        endw

    until KEY(27)

    n = CLOSE() : end
    

Image


Last edited by Picnic on 06 Sep 2020, 09:23; edited 33 times in total
Post 28 May 2018, 13:49
View user's profile Send private message Reply with quote
Robocod



Joined: 05 Mar 2018
Posts: 15
Robocod
Source code?
Post 19 Dec 2018, 21:23
View user's profile Send private message Reply with quote
sts-q



Joined: 29 Nov 2018
Posts: 33
sts-q
Post 20 Dec 2018, 09:33
View user's profile Send private message Visit poster's website Reply with quote
Picnic



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

Hobby Basic Version 1.0.5

Download


A Xonix style game in Hobby Basic.

Code:

    rem  XONIX.BAS
    rem  Hobby Basic Interpreter

sub enemyMove(i)

    color 0,0 : at x[i],y[i],' '
    x[i] = x[i] + dx[i] : if grid[x[i],y[i]] = OK then dx[i] = -dx[i] : x[i] = x[i] + dx[i]
    y[i] = y[i] + dy[i] : if grid[x[i],y[i]] = OK then dy[i] = -dy[i] : y[i] = y[i] + dy[i]
    color 12,12 : at x[i],y[i],' '

ends

sub drop(x,y)

    if grid[x,y] = 0 then grid[x,y] = -1
    if grid[x-1,y] = 0 then drop(x-1,y)
    if grid[x+1,y] = 0 then drop(x+1,y)
    if grid[x,y-1] = 0 then drop(x,y-1)
    if grid[x,y+1] = 0 then drop(x,y+1)

ends

sub status()

    local a$ = 'Score  ' + STR(score) + '    Xn  ' + STR(lives) + '    Full  ' + STR(perc) + '%'
    title a$

ends

    S = 1
    C = 60
    R = 30
    CX = C / 2
    CY = R / 2
    CR = (C - 2) * (R - 2)
    TAIL = 0xAA0020
    delay = 70000
    dim grid[C,R]

    load PATH('DATA\XONIX.TXT'),xonix$
    if V0 = -1 then alert 0x30,PATH(3),'missing file'

    screen C,R
    cursor 0,0

    color 0,2 : cls : ? xonix$
    block 0,0,39,6,700


intro#

    color 0,15 : cls : title 'Xonix!'
    block CX-19,CY-5,700

    at CX-9,CY-8,'H o b b y  B a s i c'
    at CX-13,CY+4,'P r e s s  A  t o  S t a r t'
    pen 10 : i = 0 : k = 0 : lives = 3 : enemyCount = 1 : score = 0

    do
        store CX-19+i,CY-5,2,6
        paint CX-19+i,CY-5,2,6,-1,1
        wait 120000 : restore
        i = (i + 2) % 120
        k = KEY(-1) & 0x5F
        if k = 27 then alert 0x4|0x20,'Xonix','Do you want to exit ?': if V0 = 6 then cls : end
    until k = 'A'

    for i = 0 to CX : move 1,0,CX,R,0,0 : move CX,0,CX,R,CX+1,0 : wait 20000 : next


start#

    dim x[enemyCount]
    dim y[enemyCount]
    dim dx[enemyCount]
    dim dy[enemyCount]

    OK = ((0x11 + (enemyCount  % 8) * 17) << 16) | 0x20
    x = 0 : y = 0 : dx = 0 : dy = 0 : m = 0 : n = 0 : perc = 0 : t = TICK()

    for i = 0 to enemyCount - 1
        x[i] = RND() % CX + 10
        y[i] = RND() % CY + 5
        dx[i] = (RND() % 3 - 1)|1
        dy[i] = (RND() % 3 - 1)|1
    next

    wait 500000 : color 0,0 : cls : status()

    for i = 0 to R - 1
        for j = 0 to C - 1
            if i = 0 or j = 0 or i = R-1 or j = C-1 then grid[j,i] = OK else grid[j,i] = 0
        next
    next

    grab 0,0,C,R,grid[],1

    a$ = 'S t a g e  ' + STR(enemyCount)
    pen 15 : at CX-6,CY,a$
    wait 1500000
    erase CX-6,CY,15,-1,-1

    total = score
    Game = TRUE


main#

    if KEY(27) then Game = FALSE : lives = 1
    if KEY(37) then dx = -1 : dy = 0
    if KEY(39) then dx = 1 : dy = 0
    if KEY(38) then dx = 0 : dy = -1
    if KEY(40) then dx = 0 : dy = 1

    if ~Game
        for i = 1 to R - 2
            for j = 1 to C - 2
                if grid[j,i] = TAIL then grid[j,i] = 0xCC0020
            next
        next
        grab 0,0,C,R,grid[],2
        wait 1000000
        lives = lives - 1
        if lives = 0 then color 0,15 : at CX-7,CY,'G a m e  O v e r' : status() : inkey : goto intro
        goto start
    endif

    if TICK() - t > 50

        x = x + dx
        y = y + dy

        if (x < 0) then x = 0
        if (x > C - 1) then x = C - 1
        if (y < 0) then y = 0
        if (y > R - 1) then y = R - 1

        if grid[x,y] = TAIL
            Game = FALSE
        elseif grid[x,y] = 0
            grid[x,y] = TAIL
            m = 1
        endif

        t = TICK()

    endif

    for i = 0 to enemyCount - 1 : enemyMove(i) : next

    if grid[x,y] = OK and m

        dx = 0 : dy = 0 : m = 0 : n = 0

        for i = 0 to enemyCount - 1 : drop(x[i],y[i]) : next

        for i = 1 to R - 2
            for j = 1 to C - 2
                if grid[j,i] = -1 then grid[j,i] = 0 else grid[j,i] = OK : n = n + 1
            next
        next

        if n > 0 then perc = (n * 100) / CR : score = total + n : status()

    endif

    for i = 0 to enemyCount - 1
        if grid[x[i],y[i]] = TAIL then Game = FALSE : break
    next

    if ~Game then goto main

    grab 0,0,C,R,grid[],2

    color 14,14 : at x,y,' '

    if perc > 85 then enemyCount = enemyCount + 1 : goto start

    wait delay

    goto main
    

Image


Last edited by Picnic on 06 Sep 2020, 09:23; edited 4 times in total
Post 05 Mar 2020, 09:56
View user's profile Send private message Reply with quote
Picnic



Joined: 05 May 2007
Posts: 1288
Location: Paradise Falls
Picnic
I have uploaded a new version with minor improvements and (not so minor) bug fixes.

Hobby Basic Version 1.0.6

Download


In the examples I added a simple text drawing program for the Windows console written in Hobby Basic. If someone could run the program in a Windows 10 environment and confirm that the mouse is working, I would appreciate it. I had some minor issues with Windows 10, I made some corrections and changes, but i haven't tested them since I don't have often access to Windows 10.


Image


How to create the standalone DRAW.EXE

Type at the command-line:
Code:

    hb EXAMPLES/DRAW.BAS -bind DRAW.EXE
    

The standalone application will be created inside the HB folder.

To open the apple image directly from the command-line, type:
Code:

    DRAW ART\APPLE.ANS
    

Image


Last edited by Picnic on 06 Sep 2020, 09:24; edited 9 times in total
Post 22 May 2020, 13:13
View user's profile Send private message Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 3025
Location: vpcmipstrm
bitRAKE
I think I ran all of them on Windows 10.

About the mouse one: didn't indicate which button was double-clicked, and the middle button displays as the left button. This might be a limitation of the API - I don't know.

I did find an error in the XONIX game. I was able to meet the edge at the same time as the red spot. This causes the area not to be filled until I completed another closing move. This typically is just a "one-off" error.

Also, an error in DRAW.BAS, line 336, changed to "if p > 269 then break", and it seems to work.

Was only missing 1200 baud modem sounds. Very Happy
Well done!

_________________
¯\(°_o)/¯ unlicense.org
Post 22 May 2020, 15:05
View user's profile Send private message Visit poster's website Reply with quote
Picnic



Joined: 05 May 2007
Posts: 1288
Location: Paradise Falls
Picnic
Thanks for taking the time running the examples bitRAKE, i appreciate that.

Quote:
This might be a limitation of the API - I don't know.

I think i have to update my code a bit. The interpreter using the same mouse routine since 2015.

Quote:
Also, an error in DRAW.BAS, line 336, changed to "if p > 269 then break", and it seems to work.

Out of range!, i missed that, it's better this way.
Code:

    if p > SIZE(charset[])-1 then break
    

Quote:
I did find an error in the XONIX game. I was able to meet the edge at the same time as the red spot. This causes the area not to be filled until I completed another closing move. This typically is just a "one-off" error.

Oh come on now, how fast did you notice that. A true game tester Wink
Post 22 May 2020, 20:51
View user's profile Send private message Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 3025
Location: vpcmipstrm
bitRAKE
Another oddity is not being able to select a character from the codepage that characters are displayed with. The saved images display correctly, but limited character selection as seen in the picture. I was even able to crash the console by selecting different fonts. Windows 10 might be to blame here as they try to push everyone to Powershell.

Putting this in a batch file will compile all the examples:
Code:
FOR %%G IN (.\EXAMPLES\*.BAS) DO (HB "%%G" -bind ".\BIN\%%~nG.EXE")    
...assuming the batch file is with HB.EXE and a directory .\BIN\ has been created. Change the double "%%" to a single "%" to run the command directly at the prompt.


Description:
Filesize: 67.03 KB
Viewed: 1714 Time(s)

HB10win.PNG



_________________
¯\(°_o)/¯ unlicense.org
Post 23 May 2020, 05:21
View user's profile Send private message Visit poster's website Reply with quote
Picnic



Joined: 05 May 2007
Posts: 1288
Location: Paradise Falls
Picnic
Here is a different 16 color palette (for those who are going to try it).
Code:
    
    dim Default[16] = 0x000000,0x0000BB,0x00BB00,0x00BBBB,0xBB0000,0xBB00BB,0xBBBB00,\
    0xBBBBBB,0x555555,0x5555FF,0x55FF55,0x55FFFF,0xFF5555,0xFF55FF,0xFFFF55,0xFFFFFF
    


Quote:
Windows 10 might be to blame here as they try to push everyone to Powershell.


I see it with the test programs I write. Some, while running smoothly on previous windows versions, behave differently in windows 10, even in the legacy console mode.


Quote:
Putting this in a batch file will compile all the examples:
Code:
FOR %%G IN (.\EXAMPLES\*.BAS) DO (HB "%%G" -bind ".\BIN\%%~nG.EXE")    
...assuming the batch file is with HB.EXE and a directory .\BIN\ has been created. Change the double "%%" to a single "%" to run the command directly at the prompt.


I like this. I can do it through HB as well. Something like that,

Code:

    alert  (0x4|0x20),"","Do you want to compile all the examples?"
    if V0 = 6
        exec "if not exist BIN\NUL md BIN"
        exec "FOR %G IN (.\EXAMPLES\*.BAS) DO (HB ""%G"" -bind "".\BIN\%~nG.EXE"")"
    endif
    


Thanks again bitRAKE.
Post 23 May 2020, 13:13
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


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

Website powered by rwasa.