flat assembler
Message board for the users of flat assembler.

Index > Examples and Tutorials > 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: 16841
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: 8466
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: 1277
Location: countryside
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: 1277
Location: countryside
Picnic
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: 1277
Location: countryside
Picnic
A new version upload with some minor improvements and bug fixes.
A new command is GRAB, which can be used for transferring from screen to 2d array and vice versa.

A few examples.
Code:

    rem  GRAB Methods

    path$=PATH(0)+"\ART\CAR.ANS"
    if SIZE(path$)=-1 then alert path$:end

    dim a[32,7]

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

    ansi path$

    grab 0,0,32,7,a[],0     ! screen to array

    color 1,1
    cls

    grab 0,0,32,7,a[],1     ! array to screen
    grab 0,8,32,7,a[],2     ! array to screen (skip zero cells)

    flip 0,8,32,7,0

    inkey
    end
    

Image



A 2D moving car.
Code:

    rem  2D Moving Car

    a$=PATH(0)+"\ART\FOREST.ANS"
    if SIZE(a$)=-1 then alert a$:end
    b$=PATH(0)+"\ART\CAR.ANS"
    if SIZE(b$)=-1 then alert b$:end

    VK_LEFT=37
    VK_RIGHT=39

    dim c1[32,7]
    dim c2[32,7]
    dim a[80,25]
    x=2
    y=18

    title "Use the Arrow keys to move"
    color 0,0
    screen 80,25:cls
    cursor 0,0
    ansi b$
    grab 0,0,32,7,c1[],0
    flip 0,0,32,7,0
    grab 0,0,32,7,c2[],0
    color 0,0:cls
    ansi a$
    grab 0,0,80,25,a[],0
    grab x,y,32,7,c1[],2

    do

        if (KEY(VK_LEFT) and x>0)
            grab x,y,32,7,a[],x,y
            x=x-2
            grab x,y,32,7,c2[],2
        elseif (KEY(VK_RIGHT) and x<82)
            grab x,y,32,7,a[],x,y
            x=x+2
            grab x,y,32,7,c1[],2
        endif

        wait 12000

    until KEY(27)
    end
    

Image



2D Scrolling Background.
Code:


    rem  2D Scrolling Background

    VK_LEFT=37
    VK_RIGHT=39
    VK_SPACE=32

    dim player[6,4]
    dim map[160,22]

    title "Use the Arrow keys to move, Space to jump, L to reload"
    screen 80,25
    cursor 0,0

    color 13,13
    paint 0,0,6,4,0x20,1
    color 0,0
    paint 1,1,4,2,0x20,1
    grab 0,0,6,4,player[],0
    cls

start#

    color 0,0:cls
    color 1,8
    paint 0,22,80,3,0x2591,1

    pen 11
    at 2,23,"2D Scrolling Background"

    for i=1 to 4
        x=RND(74)
        y=RND(14)+4
        color x&7,0
        paint x,y,5,3,0x20,1
    next

    grab 0,0,160,22,map[],0

    for x=0 to 79
        for y=0 to 21
            map[x+80,y]=map[x,y]
        next
    next

    x=35
    y=18
    jump=0
    d=0

    grab x,0,80,22,map[],0,0
    grab x,y,6,4,player[],2

    do

        if (KEY(VK_SPACE) and ~jump)
            jump=1
            v=-1
        elseif KEY(VK_LEFT)
            d=-2
        elseif KEY(VK_RIGHT)
            d=2
        elseif KEY("L")
            goto start
        else
            d=0
        endif

        if jump
            y=y+v
            if y=2
                v=1
            elseif y=19
                y=18
                jump=0
            endif
        endif

        x=x+d
        if x<0 then x=80
        if x>80 then x=0

        if (d<>0 or jump)
            grab x,0,80,22,map[],0,0
            grab 35,y,6,4,player[],2
        endif

        wait 12000

    until KEY(27)
    end
    

Image


Last edited by Picnic on 10 Nov 2019, 15:30; edited 37 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: 181
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: 1277
Location: countryside
Picnic
Hobby Basic includes an embedded ANSI file loader that recognizes standard ANSI.SYS escape codes for colors and cursor movement.

Loading an ANSI image is easy.
The command syntax is: ansi {path$,[s]}
s controls the drawing speed (optional)
s=0 unlimited (default)
s=1 slow...50 fast

Code:

    path$="ART\APPLE.ANS"
    ansi path$,0
    inkey
    

Image


Code:

    path$="ART\APPLE.ANS"
    ansi path$,0
    color 8,0
    paint 0,0,40,25,-1,1
    flip 40,0,40,25,0
    inkey
    

Image




Rearranging the screen by using Block.
Code:

    ansi "ART\APPLE.ANS"

    A=1001
    B=1002
    C=1003
    D=1004

    block 0,0,40,12,A
    block 40,0,40,12,B
    block 0,12,40,12,C
    block 40,12,40,12,D

    cls
    block 0,0,B
    block 40,0,A
    block 0,12,D
    block 40,12,C
    inkey
    

Image




Creating a tile texture to fill the screen on the fly.
Code:

    ansi "ART\APPLE.ANS"

    block 0,0,5,5,700
    cls

    for i=0 to 79
        block (i%16)*5,(i/16)*5,700
    next

    inkey
    

Image



Shuffle Screen.
Press Space (or any key) to shuffle the screen.
Press L to change picture.
Code:


    rem  Shuffle Screen
    rem  Press Space (or any key) to shuffle the screen
    rem  Press L to change picture

    dim a$[3]="APPLE.ANS","AUDIO.ANS","KM-DUEL.ANS"
    dim ID[16]=0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15
    n=0

    title "Press Space to shuffle the screen. Press L to change picture"
    cursor 0,0

start#

    path$=PATH(0)+"\ART\"+a$[n]
    if SIZE(path$)=-1 then alert path$:end

    cls
    ansi path$

    for i=0 to 15
        block (i%4)*20,(i/4)*6,20,6,i
    next

main#

    inkey:k=V0

    if k=27 then end

    if k='l' or k='L'
        n=(n+1)%3
        goto start
    endif

    ID[]=-1   ! shuffle array

    for i=0 to 15
        block (i%4)*20,(i/4)*6,ID[i]
    next

    goto main
    

Image




This program is an ANSI text file viewer.
Code:

    rem  ANSI Text File Viewer

    a = 1                        ! auto play slide-show 0/1
    s = 20                       ! drawing text speed
    m = 250                      ! max files in folder
    d = 2000000                  ! delay between images
    path$ = PATH(0)+"\ART\"         ! path to ART folder

    cmd$ = "IF EXIST ART\ DIR /b "+CHR(0x22)+path$+CHR(0x22)
    exec cmd$,dir$

    screen 80,25,1000
    cursor 0,0

start#

    v=0
    for n=1 to m
        a$=READLN(n,dir$)
        if V0=-1 then break
        a$=UCASE(path$+a$)
        if COMP(RIGHT(a$,4),".ANS")
            title a$
            ansi a$,s
            if KEY(27) then end
            if a then wait d else inkey
            v=v+1
        endif
    next

    if v>0 then goto start
    alert "ansi not found":end
    

Image



The command line switch -BIND NAME_OF_EXE binds a program and the interpreter together into a standalone console application which can freely distributed.
Note that this is a new feature currently in experimental stage.


To create the standalone foo.exe from foo.bas you will type in the command-line:
Code:

    hb foo.bas -bind foo.exe
    


To compile one of the examples (e.g., RALLY.BAS) as a standalone application from the command-line:
Code:

    hb EXAMPLES/RALLY.BAS -bind RALLY.EXE
    



This program creates stand-alone applications from the programs in the EXAMPLE folder.
Code:

    rem  Create standalone applications from the programs in the EXAMPLE folder

    cmd$="DIR /b "+CHR(0x22)+PATH(0)+"\EXAMPLES\"+CHR(0x22)
    exec cmd$,dir$

    for n=1 to 20
        a$=READLN(n,dir$)
        if V0=-1 then break
        a$=UCASE(a$)
        if COMP(RIGHT(a$,4),".BAS")
            b$=LEFT(a$,LEN(a$)-4)+".EXE"
            print "Creating standalone ",PATH(0)+"\"+b$
            cmd$="HB EXAMPLES\"+a$+" -BIND "+b$
            exec cmd$
        endif
    next

    pause
    end
    


Last edited by Picnic on 10 Nov 2019, 12:54; edited 26 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: 26
sts-q
Post 20 Dec 2018, 09:33
View user's profile Send private message Visit poster's website 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-2019, Tomasz Grysztar.

Powered by rwasa.