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 1, 2, 3  Next
Author
Thread Post new topic Reply to topic
Picnic



Joined: 05 May 2007
Posts: 1280
Location: countryside
Picnic
Image

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

Version 0.99.3 - November 2019.

Download


Quick Tour

Load an ANSI encoded text file.

Load the apple.
Code:
    
    ansi "ART\APPLE.ANS"
    inkey
    


Load the apple (use the full path).
Code:
    
    ansi PATH(0)+"\ART\APPLE.ANS"
    inkey
    


Load the apple (use a string variable).
Code:
   
    path$=PATH(0)+"\ART\APPLE.ANS"
    ansi path$
    inkey
    


Load the apple (do error check).
Code:
   
    path$=PATH(0)+"\ART\APPLE.ANS"
    if SIZE(path$)=-1 then alert path$:end
    ansi path$
    inkey
    


Load the apple (on error try to download the file).
Create the ART folder if not exist.
Complete script.
Code:
   
    url$="https://sites.google.com/site/hobbybasicfiles/APPLE.ANS"
    path$=PATH(0)+"\ART\APPLE.ANS"

    if SIZE(path$)=-1
        load url$,1
        if V0=-1 then alert url$:end          
        ! execute batch script     
        exec "if not exist ART\NUL mkdir ART"
        exec "move APPLE.ANS ART\APPLE.ANS >NUL"
    endif

    screen 80,25        ! setup screen
    cursor 0,0          ! hide the cursor
    cls                 ! clear the screen
    title path$         ! set the title-bar text
    ansi path$          ! load the apple        
    inkey               ! wait for keypress
    end                 ! exit
    

Image


Erase screen lines.
Code:

    color 0,15      ! set the background and text colors
    erase 11        ! delete line
    erase 12      
    erase 13     
    at 30,12,"This is a line of text"
    

Image


Paint and Flip the screen.
Code:

    color 4,0
    paint 0,0,40,25,-1,1
    flip 40,0,40,25,0
    

Image


Split screen into blocks.
Code:

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

    ! split screen into 4 memory blocks A B C D
    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

    ! copy memory blocks at screen
    block 0,0,B
    block 40,0,A
    block 0,12,D
    block 40,12,C
    

Image


Create a texture tile.
Code:

    A=1001

    block 0,0,5,5,A

    cls

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

Image


Rearrange the screen randomly.
Code:

    dim id[16]=0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15

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

    loop#

    inkey

    if V0=27 then end      ! VK_ESCAPE=27

    id[]=-1                ! shuffle array

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

    goto loop
    

Image


Save screen as text file (assumes DATA folder exist). Opens the text in notepad.
Code:

    grab 0,0,40,20,a$
    save "DATA\apple.txt",a$
    exec "start notepad.exe DATA\apple.txt"
    

Image


An ANSI Text File Viewer (full source program).
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

    ! execute batch script
    cmd$ = "IF EXIST ART\ DIR /b "+CHR(0x22)+path$+CHR(0x22)

    exec cmd$,dir$               ! execute a shell command and send the output to a string
    screen 80,25,1000            ! resize console and set the screen buffer height
    cursor 0,0                   ! hide the cursor

main#

    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$," (",SIZE(a$)," bytes)"
            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 main
    alert "ansi not found":end
    

Image



2D Moving Car in console

Load an ANSI encoded file into an array.
Code:

    rem  Loading an ANSI encoded file into an array

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

    dim c[32,7]              ! car array
        
    screen 80,25
    cursor 0,0
    color 0,0
    cls

    ansi path$              ! load the car

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

    color 1,1
    cls

    grab 0,0,32,7,c[],1     ! array to screen
    grab 0,8,32,7,c[],2     ! array to screen (skip zero cells)
        
    flip 0,8,32,7,0         ! flip the car

    inkey
    end
    

Image


Remove the frame to make the car look like a sprite.
Code:

    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         ! flip the car
    

Image


Add a background.
Code:

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

    dim c1[32,7]              ! car array (right clip)
    dim c2[32,7]              ! car array (left clip)
    dim m[80,25]              ! screen map array

    x=2                       ! car x
    y=18                      ! car y
        
    screen 80,25              ! setup screen
    cursor 0,0                ! hide the cursor
    color 0,0:cls             ! clear the screen

    ansi car$                 ! load the car

    grab 0,0,32,7,c1[],0      ! car to array
    flip 0,0,32,7,0           ! flip the car
    grab 0,0,32,7,c2[],0      ! car to array

    color 0,0:cls             ! clear the screen

    ansi forest$              ! load the forest

    grab 0,0,80,25,m[],0      ! screen to array
    grab x,y,32,7,c1[],2      ! car to screen (skip zero cells)

    inkey
    

Image


Move the car using the Arrow keys.
Code:

    do

        if (KEY(37) and x>0)          ! VK_LEFT=37
            grab x,y,32,7,m[],x,y     ! part of map array into screen
            x=x-2                     ! update car x
            grab x,y,32,7,c2[],2      ! car to screen (skip zero cells)
        elseif (KEY(39) and x<82)     ! VK_RIGHT=39
            grab x,y,32,7,m[],x,y
            x=x+2
            grab x,y,32,7,c1[],2
        endif

        wait 12000

    until KEY(27)

    end
    


Last edited by Picnic on 19 Nov 2019, 22:01; edited 151 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: 1398
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: 6029
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: 2913
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: 1280
Location: countryside
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: 820
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
Stupid post removed.


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: 2913
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: 1280
Location: countryside
Picnic
TmX wrote:
Mouse handling would be a nice addition, I think Wink


Hobby Basic Version 0.3

I uploaded a new version with minor improvements and bug fixes.

[+] Mouse Support.

Download


Last edited by Picnic on 19 Nov 2019, 21:49; edited 17 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: 1280
Location: countryside
Picnic
I uploaded a new version with minor improvements and bug fixes.

Hobby Basic Version 0.4

Download


Last edited by Picnic on 19 Nov 2019, 21:49; edited 11 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: 2913
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: 1280
Location: countryside
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: 2913
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: 1280
Location: countryside
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: 2913
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: 1280
Location: countryside
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: 2913
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: 1280
Location: countryside
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: 2913
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: 1280
Location: countryside
Picnic
I uploaded a new version with minor improvements and bug fixes.

Hobby Basic Version 0.5

Download


Last edited by Picnic on 19 Nov 2019, 21:49; edited 10 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  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-2019, Tomasz Grysztar.

Powered by rwasa.