flat assembler
Message board for the users of flat assembler.

Index > Programming Language Design > Pebble Programming Language

Author
Thread Post new topic Reply to topic
geekbasic@gmx.com



Joined: 25 Oct 2022
Posts: 71
Location: Arizona
geekbasic@gmx.com 07 Nov 2022, 04:39
Hello, I would like to share with you my project with Fasm. Please let me know if you have any feedback.

Pebble is a programming language, compiler, and IDE for x86 DOS. Development is in its early stages. This is just the beginning.

The compiler is written is QBasic and produces Flat Assembler code. Fasm is included along with a wysiwyg IDE written in QBasic. The IDE produces and executes compilation batch files. The compiler may be ran without the IDE.

When a program is compiled, the result is a .com file. The .com files start at less than 100 bytes. Inline asm is supported to allow support for unimplemented features.

The IDE allows you to compile and run by pressing F4. Files must be loaded or saved to compile and run from the IDE. Several example programs are included with the .peb extension. The included examples come with compilation batch files, so the IDE is not required.

Nested if/endif statements are supported. Echoing text doesn't require defining the text. The language currently only supports integer variables. Expressions with parentheses are supported. Inline asm and include files are supported.

More info and download: http://www.basicgames.xyz/index.php?page=article&id=17

Ball and Paddle example Pong game
supports mouse and keyboard
color and sound
game speed control
Under 2kb .com file when compiled (1,673 bytes)

Image

Code:
;Ball and Paddle example pong game
;by Gemino Smothers
;Geek Basic 2022
;http://www.basicgames.xyz

program examples\ballandp

        use mouse.inc

data

        int mousex[0]
        int mousey[0]
        int mouseb[0]

        int paddlex[0]
        int paddley[22]

        int ballx[2]
        int bally[2]
        int balldx[1]
        int balldy[1]

        int score[0]
        int mode[0]
        int key[0]
        int loops[0]
        int speed[0]

begin

        label intro

                cls
                cls 18,25,0,79,0,24
                cls 79,0,0,79,0,0

                cursor 32,0
                echo "Ball and Paddle"
                cursor 32,2
                echo "Geek Basic 2022"
                cursor 27,3
                echo "http://www.basicgames.xyz"
                cursor 26,5
                echo "Mouse (1) or keyboard (0) ? "
                cursor 54,5
                input [mode]
                cursor 25,7
                echo "Game speed (1-65535) ? "
                cursor 48,7
                input [speed]

                cls
                cls 30,24,0,79,0,24
                cls 26,1,0,79,16,22
                cls 79,0,0,79,0,0

                call mouseshow

        if [speed]=0 then intro

        label gameloop

                cursor [paddlex],[paddley]
                echo "     "

                if [mode]=1 then

                        call readmouse

                endif

                scankey [key]

                if [key]=75&[paddlex]>1 then

                        [paddlex]=[paddlex]-5

                endif

                if [key]=77&[paddlex]<75 then

                        [paddlex]=[paddlex]+5

                endif

                if [mode]=1 then

                        [paddlex]=[mousex]

                        if [paddlex]>75 then

                                [paddlex]=75

                        endif

                endif

                cursor [paddlex],[paddley]
                echo "ÛÛÛÛÛ"

                if [mode]=1 then

                        call hidemouse

                endif

                cursor [ballx],[bally]
                echo " "

                if [balldx]=1 then

                        +1 [ballx]

                        if [ballx]=80 then

                                0 [balldx]

                        endif

                endif

                if [balldx]=0 then

                        -1 [ballx]

                        if [ballx]=0 then

                                [balldx]=1

                        endif

                endif

                if [balldy]=0 then

                        -1 [bally]

                        if [bally]=0 then

                                [balldy]=1

                        endif

                endif

                if [balldy]=1 then

                        +1 [bally]

                        if [bally]=[paddley]-1 then

                                if [ballx]<[paddlex]|[ballx]>[paddlex]+5 then

                                        cls
                                        cls 18,25,0,79,0,24
                                        echo "Game over!"
                                        echo "Score: "
                                        cursor 7,1
                                        echo [score]
                                        crlf
                                        echo "Press any key to return to DOS..."
                                        pause
                                        kill

                                endif

                                if [speed]>1 then

                                        -1 [speed]

                                endif

                                call drawball

                                0 [balldy]
                                +1 [score]
                                bell

                        endif

                endif

                call drawball

                cursor 0,0
                echo "Score:"
                cursor 8,0
                echo [score]

                if [mode]=1 then

                        cursor 76,0
                        echo "[X]"

                endif

                if [key]=1|([mouseb]=1&[mousex]>=76&[mousex]<=79&[mousey]=0) then

                        kill

                endif

                0 [loops]

                label repeat

                        +1 [loops]
                        wait 1

                if [loops]<[speed] then repeat

        goto gameloop

end

sub drawball

        cursor [ballx],[bally]
        chr 2

        call mouseshow

ret

sub mouseshow

        if [mode]=1 then

                call showmouse

        endif

ret
    


Description: I uploaded it here for anyone having trouble with my sites download system.
Download
Filename: pebble.zip
Filesize: 153.85 KB
Downloaded: 256 Time(s)



Last edited by geekbasic@gmx.com on 09 Jan 2023, 00:26; edited 23 times in total
Post 07 Nov 2022, 04:39
View user's profile Send private message Visit poster's website Reply with quote
FlierMate11



Joined: 13 Oct 2022
Posts: 94
FlierMate11 07 Nov 2022, 21:09
Very nice effort!

I try to download but it returns an empty page with address bar pointing to:
http://www.basicgames.xyz/download.php?file=pebble.zip

Nothing has been downloaded.
Post 07 Nov 2022, 21:09
View user's profile Send private message Visit poster's website Reply with quote
geekbasic@gmx.com



Joined: 25 Oct 2022
Posts: 71
Location: Arizona
geekbasic@gmx.com 07 Nov 2022, 23:29
Thank you!

The download uses a php script I wrote to break the download into frames to display a full age ad in one and serve the download in the other while tracking the download information. It tracks the time, ip address, etc. Some browser settings or ad blockers may be blocking my system. It's all experimental stuff.

Try this direct download url instead: http://www.basicgames.xyz/games/pebble.zip
Post 07 Nov 2022, 23:29
View user's profile Send private message Visit poster's website Reply with quote
geekbasic@gmx.com



Joined: 25 Oct 2022
Posts: 71
Location: Arizona
geekbasic@gmx.com 12 Nov 2022, 06:02
I have fixed some mistakes and make some updates.
The new update has been uploaded here and on my site.

Updates...

I got rid of the colon in the if statements. That was annoying. The way it is now is better.

There's now an include command. You may use it pretty much anywhere in the code to include another source file with subs or variable declarations or whatever. It may be used between program/data, data/begin, begin/end, and after end. Mostly, it should be used between data/begin and after end. It inserts the file directly where the command is.

With the insert command, you may now develop larger programs using the IDE. It also makes larger programs easier to manage in general.

There's now a cursor command to move the text output. example: cursor [x],[y]

A new example file called click.peb has been included as well as an include file called mouse.inc. The example demonstrates mouse.inc and the cursor command. Inline asm is also demonstrated in the mouse.inc file.

The mouse.inc file may be used as mouse support for TUI programs. call showmouse and call readmouse
Post 12 Nov 2022, 06:02
View user's profile Send private message Visit poster's website Reply with quote
geekbasic@gmx.com



Joined: 25 Oct 2022
Posts: 71
Location: Arizona
geekbasic@gmx.com 14 Nov 2022, 18:45
I have another update! It's uploaded here and on my site.
The update includes many more fixes and new commands.

Updates...

There's now a use command. Similar to include, but instead of including the code in the same place as the command, it includes it at the bottom where subs go. This is useful to include subs at the top of your code between program and begin and have the result placed at in your subs.

The bell command echoes chr 7 making your PC speaker ring.

The chr command prints any ascii character.

The cls command has been fixed and updated. It now has two functions. Clearing the screen and setting colors. To clear the screen, use cls with no parameters. To set colors, use cls [colorcode],[scroll],[x1],[x2],[y1],[y2].

The chr, cls, and cursor commands may use variables and numbers as parameters.

The scankey command returns the ascii value of keys being pressed.

BIG update: The program flags for each command that uses functions from the io.lib and only includes the ones used in the source during compilation. The result is base programs under 100 bytes. The io.lib is now also unlimited in size for future updates.

The examples have been updated to reflect the changes.

I'm sure I'm missing a few things, but it's in the zip.
Hopefully I won't be long before having more updates.
Post 14 Nov 2022, 18:45
View user's profile Send private message Visit poster's website Reply with quote
geekbasic@gmx.com



Joined: 25 Oct 2022
Posts: 71
Location: Arizona
geekbasic@gmx.com 20 Nov 2022, 07:13
I have another update. A major one! The best one yet! It's uploaded here and on my site.

I have fixed and added many things.

Updates...

Added expression parser for arithmetic and if statements..
Fixed parser to allow any combo of mixed tabs and spaces for whitespacing.
fixed the keyboard flush command by xoring ax.
echo command may now include single quotes for display.
variable definitions now use a temp file to allow for much more data.
the data command is now optional when not using variables (example: hello world).
Examples are organized to show use of project folders.
Post 20 Nov 2022, 07:13
View user's profile Send private message Visit poster's website Reply with quote
geekbasic@gmx.com



Joined: 25 Oct 2022
Posts: 71
Location: Arizona
geekbasic@gmx.com 27 Nov 2022, 00:31
Updates...

Fixed/Changed scankey command to now read port 96
I wrote a routine to filter the port.
Removed flush command.
Singe quotes are now allowed with inline asm.
Basic array support.
New examples including a Pong game and array demonstration!
IDE now has mouse support.

Int arrays may be defined and used with arithmetic, if, echo, and input statements. All other statements must use variables to pass values.
Post 27 Nov 2022, 00:31
View user's profile Send private message Visit poster's website Reply with quote
FlierMate11



Joined: 13 Oct 2022
Posts: 94
FlierMate11 27 Nov 2022, 11:41
I tried your ballandp.com and it is playable with mouse or keyboard (on my computer, speed of 200 is ideal Razz ). It shows that building a compiler is not as hard as one imagine. Perhaps you can port your compiler to generate Windows and Linux assembly output once your programming language is stable. Embarassed
The fact that your compiler uses FASM as backend is a wise decision because it is scalable.
Post 27 Nov 2022, 11:41
View user's profile Send private message Visit poster's website Reply with quote
geekbasic@gmx.com



Joined: 25 Oct 2022
Posts: 71
Location: Arizona
geekbasic@gmx.com 27 Nov 2022, 19:32
Thanks for trying my program! 200 speed? What processor is that on? The way I did the delay in the game uses a delay interrupt and loops at the same time. This way computer that don't support the delay may still have speed control by means of looping. It's there in the code.

I'm glad you were able to get both modes of control to work. I learned a lot implementing all that.

This project will come across as simple to some and complex for others. To me, it's something that I feel has come much to late for how long I have been in programming. To learn expression parsing and assembly language. To combine those things into a functional project. It's been a real challenge. I have tried several times before and never got anywhere remotely this far. Never giving up and continuing to learn new things. That's the best we can do.

It took me years of experimentation for me to settle on FASM. I needed something with the requirements of a beginner that is supported on original x86 hardware. Knowing that wonderful operating systems have been written in FASM as well as Linux software. It's so great. In my opinion, it really is a great backend for x86 compilers. Compared to MASM which I used in school 11 years ago, or good old debug.exe, FASM a dream come true.

I do intend to make Pebble portable. The compiler allows you to change the compilation header with a file called header.dat and any DOS only libraries are not included in the compilation if you don't use the related commands. You could optionally use the inline asm with sub routines to make your own pebble libraries that still may use the pebble arithmetic, logic, and non DOS related commands. This way, you could technically create a bootloader and maybe even a full OS.

I think it would be nice like you say to have Windows or Linux compilation when things are more developed and stable. My plan would be to release different versions of Pebble for each system. I will likely use Emergence Basic instead of QBasic for Windows. Not sure what I will use for Linux. First, I need to learn more about Linux compilation. How do I make code that works on different distros?
Post 27 Nov 2022, 19:32
View user's profile Send private message Visit poster's website Reply with quote
FlierMate11



Joined: 13 Oct 2022
Posts: 94
FlierMate11 28 Nov 2022, 03:36
geekbasic@gmx.com wrote:
200 speed? What processor is that on?


My OS is 64-bit Windows, it cannot run 16-bit DOS programs. So I use DOSBox 0.74 (DOS emulator) to run your Pebble and any other DOS programs.
I tried 100 speed, also OK, but 1 speed resulted in instant game over. Laughing

geekbasic@gmx.com wrote:

To learn expression parsing and assembly language. To combine those things into a functional project. It's been a real challenge.


Yes, parser (and lexer) is very important when building a compiler. It is good you have figured them out, to generate .ASM programmatically from your Pebble programming language.

geekbasic@gmx.com wrote:

First, I need to learn more about Linux compilation. How do I make code that works on different distros?


The installation file for various distros might be different (e.g. .rpm, .deb) but the binary executable file for Linux is the same, that is, ELF (or ELF64 for 64-bit). Correct me if I am wrong but one ELF64 file is working for me on Ubuntu, Debian and Chromium OS.
I don't know much about Linux programming given my limited less than two years experience on it, but I can tell the difference about 32-bit and 64-bit Linux programming:

In 32-bit, uses "int 0x80" to call an OS function, whereas in 64-bit, uses "syscall" to call an OS function.
Post 28 Nov 2022, 03:36
View user's profile Send private message Visit poster's website Reply with quote
geekbasic@gmx.com



Joined: 25 Oct 2022
Posts: 71
Location: Arizona
geekbasic@gmx.com 28 Nov 2022, 20:07
That makes sense. DOSBox probably emulates the wait command and that is why you're able to play at 200 like on my true DOS computer. Where as on Windows XP, I set it between 20000-60000. On XP, it depends purely on the looping. Otherwise, the waits 1 millisecond for the number of loops. It's hard to explain, but it works. Smile

When I have the time, I will have to try your ideas about compiling on Linux. It would be nice to Compile for distros such as Tiny Core or Damn Small Linux.

I would also be very interested in MenuetOS.
Post 28 Nov 2022, 20:07
View user's profile Send private message Visit poster's website Reply with quote
geekbasic@gmx.com



Joined: 25 Oct 2022
Posts: 71
Location: Arizona
geekbasic@gmx.com 11 Dec 2022, 08:10
I have made a major update!

The expression evaluation was flawed with boolean and relational conditions.
I think I have fixed this now.
Also, the extra parenthesis are no longer needed!

There's now full string support. Except string arrays.
I still need to add string examples, but here's a preview of an interactive fiction game I am working on in Pebble that uses strings and has a parser (there's two games being made in Pebble at the moment)


Code:
;Desert of Skulls Adventure

program dskulls\dskulls

data

        int space[0]
        int char[0]
        int chars[0]

        int check[0]
        int shortcheck[0]
        int errorflag[0]

        int areax[2]
        int areay[2]
        int areasx[4]
        int areasy[4]

        int@ flag[5]

        str$ cmdline['']
        str$ command['']
        str$ parameters['']

begin

        call intro

        label loop

                call areadescription
                call parser
                call commands

        goto loop

end

sub intro

        cls
        echo "Desert of Skulls Adventure"
        crlf

ret

sub parser

        input cmdline$
        trim cmdline$
        find [space],cmdline$,' '

        if [space]>=1 then

                [char]=[space]-1
                cut 0,[char],command$,cmdline$
                [char]=[space]
                length [chars],cmdline$
                [chars]=[chars]-[char]
                cut [char],[chars],parameters$,cmdline$

        endif

        if [space]=0 then

                copy command$,cmdline$

        endif

        upper command$
        upper parameters$

ret

sub commands

        [errorflag]=1

        call northcommand
        call eastcommand
        call southcommand
        call westcommand
        call examinecommand
        call takecommand
        call usecommand
        call opencommand
        call talkcommand
        call inventorycommand
        call helpcommand
        call byecommand

        if [errorflag]=1 then

                echo "Invalid command."

        endif

        crlf

ret

sub areadescription

        if [areax]=0&[areay]=0 then

                echo "area 0,0"

        endif

        if [areax]=1&[areay]=0 then

                echo "area 1,0"

        endif

        if [areax]=2&[areay]=0 then

                echo "area 2,0"

        endif

        if [areax]=3&[areay]=0 then

                echo "area 3,0"

        endif

        if [areax]=4&[areay]=0 then

                echo "area 4,0"

        endif

        if [areax]=0&[areay]=1 then

                echo "area 0,1"

        endif

        if [areax]=1&[areay]=1 then

                echo "area 1,1"

        endif

        if [areax]=2&[areay]=1 then

                echo "area 2,1"

        endif

        if [areax]=3&[areay]=1 then

                echo "area 3,1"

        endif

        if [areax]=4&[areay]=1 then

                echo "area 4,1"

        endif

        if [areax]=0&[areay]=2 then

                echo "area 0,2"

        endif

        if [areax]=1&[areay]=2 then

                echo "area 1,2"

        endif

        if [areax]=2&[areay]=2 then

                echo "area 2,2"

        endif

        if [areax]=3&[areay]=2 then

                echo "area 3,2"

        endif

        if [areax]=4&[areay]=2 then

                echo "area 4,2"

        endif

        if [areax]=0&[areay]=3 then

                echo "area 0,3"

        endif

        if [areax]=1&[areay]=3 then

                echo "area 1,3"

        endif

        if [areax]=2&[areay]=3 then

                echo "area 2,3"

        endif

        if [areax]=3&[areay]=3 then

                echo "area 3,3"

        endif

        if [areax]=4&[areay]=3 then

                echo "area 4,3"

        endif

        if [areax]=0&[areay]=4 then

                echo "area 0,4"

        endif

        if [areax]=1&[areay]=4 then

                echo "area 1,4"

        endif

        if [areax]=2&[areay]=4 then

                echo "area 2,4"

        endif

        if [areax]=3&[areay]=4 then

                echo "area 3,4"

        endif

        if [areax]=4&[areay]=4 then

                echo "area 4,4"

        endif

        crlf

ret

sub northcommand

        compare [check],command$,"NORTH"
        compare [shortcheck],command$,"N"

        @flag{0}=0

        if [check]=1|[shortcheck]=1 then

                0 [errorflag]

                if [areay]>=1 then

                        @flag{0}=1
                        -1 [areay]
                        echo "You travel North."

                endif

                if @flag{0}=0 then

                        echo "You are unable to travel North."

                endif

        endif

ret

sub eastcommand

        compare [check],command$,"EAST"
        compare [shortcheck],command$,"E"

        @flag{0}=0

        if [check]=1|[shortcheck]=1 then

                0 [errorflag]

                if [areax]+1<=[areasx] then

                        @flag{0}=1
                        +1 [areax]
                        echo "You travel East."

                endif

                if @flag{0}=0 then

                        echo "You are unable to travel East."

                endif

        endif

ret

sub southcommand

        compare [check],command$,"SOUTH"
        compare [shortcheck],command$,"S"

        @flag{0}=0

        if [check]=1|[shortcheck]=1 then

                0 [errorflag]

                if [areay]+1<=[areasy] then

                        @flag{0}=1
                        +1 [areay]
                        echo "You travel South."

                endif

                if @flag{0}=0 then

                        echo "You are unable to travel South."

                endif

        endif

ret

sub westcommand

        compare [check],command$,"WEST"
        compare [shortcheck],command$,"W"

        @flag{0}=0

        if [check]=1|[shortcheck]=1 then

                0 [errorflag]

                if [areax]>=1 then

                        @flag{0}=1
                        -1 [areax]
                        echo "You travel West."

                endif

                if @flag{0}=0 then

                        echo "You are unable to travel West."

                endif

        endif

ret

sub examinecommand

        compare [check],command$,"EXAMINE"
        compare [shortcheck],command$,"EX"

        if [check]=1|[shortcheck]=1 then

                0 [errorflag]

                echo parameters$
                crlf

        endif

ret

sub takecommand

        compare [check],command$,"TAKE"
        compare [shortcheck],command$,"T"

        if [check]=1|[shortcheck]=1 then

                0 [errorflag]

                echo parameters$
                crlf

        endif

ret

sub usecommand

        compare [check],command$,"USE"
        compare [shortcheck],command$,"U"

        if [check]=1|[shortcheck]=1 then

                0 [errorflag]

        endif

ret

sub opencommand

        compare [check],command$,"OPEN"
        compare [shortcheck],command$,"O"

        if [check]=1|[shortcheck]=1 then

        endif

ret

sub talkcommand

        compare [check],command$,"TALK"
        compare [shortcheck],command$,"TA"

        if [check]=1|[shortcheck]=1 then

                0 [errorflag]

        endif

ret

sub inventorycommand

        compare [check],command$,"INVENTORY"
        compare [shortcheck],command$,"I"

        if [check]=1|[shortcheck]=1 then

                0 [errorflag]

        endif

ret

sub helpcommand

        compare [check],command$,"HELP"
        compare [shortcheck],command$,"H"

        if [shortcheck]=0 then

                compare [shortcheck],command$,"?"

        endif

        if [check]=1|[shortcheck]=1 then

                0 [errorflag]

                cls

                echo "Help:"
                crlf
                echo "(n)orth"
                echo "(e)ast"
                echo "(s)outh"
                echo "(w)est"
                echo "(ex)amine (object)"
                echo "(t)ake (object)"
                echo "(u)se (object)"
                echo "(o)pen (object)"
                echo "(ta)lk"
                echo "(i)nventory"
                echo "(h)elp"
                echo "(q)uit"
                crlf
                echo "Press any key to continue..."
                pause
                cls

        endif

ret

sub byecommand

        compare [check],command$,"BYE"

        if [check]=0 then

                compare [check],command$,"END"

        endif

        if [check]=0 then
        
                compare [check],command$,"QUIT"

        endif

        if [check]=0 then
        
                compare [check],command$,"EXIT"

        endif

        compare [shortcheck],command$,"Q"

        if [check]=1|[shortcheck]=1 then

                kill

        endif

ret
    
Post 11 Dec 2022, 08:10
View user's profile Send private message Visit poster's website Reply with quote
geekbasic@gmx.com



Joined: 25 Oct 2022
Posts: 71
Location: Arizona
geekbasic@gmx.com 16 Dec 2022, 08:41
A new example has been included with the Pebble download.

The NIM game. Compiles to 779 bytes.

Code:
;NIM game example program
;Compile with Pebble

program examples\nim

data

        int tokens[12]
        int take[0]

begin

        call intro

        label gameloop

                echo "There are"
                echo [tokens]
                echo " tokens remaining."
                crlf
                echo "How many would you like to take? "
                input [take]

                if [take] > 3 | [take] < 1 then

                        echo "You must take between 1 to 3 tokens."

                endif

                if [tokens] - [take] < 0 then

                        echo "You cannot take that many."

                endif

                if [take] <= 3 & [take] >= 1 & [tokens] - [take] >= 0 then

                        [tokens] = [tokens] - [take]

                        if [tokens] = 0 then

                                bell
                                echo "Congratulations. You got the last token."
                                pause
                                kill

                        endif

                        [take] = 4 - [take]

                        if [tokens] >= 15 then

                                [take] = 3

                        endif

                        if [tokens] <= 3 then

                                [take] = [tokens]

                        endif

                        echo "I will take"
                        echo [take]
                        echo " tokens.
                        [tokens] = [tokens] - [take]

                        if [tokens] = 0 then

                                echo "I got the last token. I win. Better luck next time."
                                pause
                                kill

                        endif

                endif

        goto gameloop

end

sub intro

        cls
        echo "NIM game"
        crlf
        echo "Press any key to play..."

ret
    
Post 16 Dec 2022, 08:41
View user's profile Send private message Visit poster's website Reply with quote
geekbasic@gmx.com



Joined: 25 Oct 2022
Posts: 71
Location: Arizona
geekbasic@gmx.com 30 Dec 2022, 04:27
I have just made an update that allows you to omit the newline with echo statements by placing a \ at the end.

I also just released a full game written in Pebble called Desert of Skulls Adventure.
It's an interactive fiction adventure game with a command parser.

The game demonstrates string parsing with Pebble. It got quite large and filled up the available space in a com file. The game is fully playable and complete.

Get the game here:
http://basicgames.xyz/index.php?page=article&id=20

here's the source code for you to preview:

Code:
;Desert of Skulls Adventure

program dskulls\dskulls

data

        int space[0]
        int char[0]
        int chars[0]

        int check[0]
        int shortcheck[0]
        int errorflag[0]

        int areax[4]
        int areay[5]
        int lastareax[4]
        int lastareay[4]
        int areasx[8]
        int areasy[8]
        int moved[0]

        int temp[0]
        int boulder[0]
        int hydration[15]
        int gourdfull[0]
        int locked[1]
        int outlaw[1]

        int key[0]
        int rope[0]
        int gourd[0]
        int bullets[0]
        int derringer[0]

        str$ cmdline['']
        str$ command['']
        str$ parameters['']

begin

        call intro

        label loop

                call parser
                call commands

        if [hydration]>=1 then loop

        echo "You are too thirsty and unable to continue... Game over!"
        bell
        pause
        kill

end

sub intro

        cls
        echo "Desert of Skulls Adventure   _____"
        echo "by Gemino Smothers 2022     /     \"
        echo "http://www.basicgames.xyz  | () () |"
        echo "                            \  ^  /"
        echo "Type help at any time.       |||||"
        echo "                             ||||| "
        echo "Press any key to begin..."
        pause
        cls
        echo "You suddenly awaken to the sound of coyotes yapping."
        echo "How did you get here? Last you remember, you were in a small town."
        echo "You were travelling in search for a new home and decided to rest there."
        echo "Unfortunately, the town was full of outlaws and you were knocked out."
        echo "Now you must find your way and continue your adventure..."
        call areadescription

ret

sub parser

        echo "What would you like to do? "\
        call getinput
        crlf

        find [space],cmdline$,' '

        if [space]>=1 then

                [char]=[space]-1
                cut 0,[char],command$,cmdline$
                [char]=[space]
                length [chars],cmdline$
                [chars]=[chars]-[char]
                cut [char],[chars],parameters$,cmdline$

        endif

        if [space]=0 then

                copy command$,cmdline$

        endif

ret

sub commands

        [lastareax]=[areax]
        [lastareay]=[areay]

        [errorflag]=1

        call lookcommand
        call northcommand
        call eastcommand
        call southcommand
        call westcommand
        call examinecommand
        call takecommand
        call usecommand
        call talkcommand
        call inventorycommand
        call helpcommand
        call byecommand

        if [errorflag]=1 then

                echo "Invalid command."
                crlf

        endif

ret

sub areadescription

        crlf
        echo "(hydration: "\
        echo [hydration]
        echo ")"

        [boulder]=1

        if [areax]=4&[areay]=1 then

                call sands

        endif

        if [areax]=5&[areay]=1 then

                call sands

        endif

        if [areax]=6&[areay]=1 then

                call skeleton

        endif

        if [areax]=2&[areay]=2 then

                call barn

        endif

        if [areax]=3&[areay]=2 then

                call house

        endif

        if [areax]=4&[areay]=2 then

                call roads

        endif

        if [areax]=5&[areay]=2 then

                call sands

        endif

        if [areax]=6&[areay]=2 then

                call sands

        endif

        if [areax]=8&[areay]=2 then

                call sands

        endif

        if [areax]=2&[areay]=3 then

                call crops

        endif

        if [areax]=3&[areay]=3 then

                call crops

        endif

        if [areax]=4&[areay]=3 then

                call roads

        endif

        if [areax]=5&[areay]=3 then

                call sands

        endif

        if [areax]=6&[areay]=3 then

                call sands

        endif

        if [areax]=8&[areay]=3 then

                call sands

        endif

        if [areax]=2&[areay]=4 then

                call crops

        endif

        if [areax]=3&[areay]=4 then

                call crops

        endif

        if [areax]=4&[areay]=4 then

                call roads

        endif

        if [areax]=5&[areay]=4 then

                call roads

        endif

        if [areax]=6&[areay]=4 then

                call sands

        endif

        if [areax]=8&[areay]=4 then

                call sands

        endif

        if [areax]=2&[areay]=5 then

                call roads

        endif

        if [areax]=3&[areay]=5 then

                call roads

        endif

        if [areax]=4&[areay]=5 then

                call crossroad

        endif

        if [areax]=5&[areay]=5 then

                call sands

        endif

        if [areax]=6&[areay]=5 then

                call sands

        endif

        if [areax]=8&[areay]=5 then

                call sands

        endif

        if [areax]=4&[areay]=6 then

                call roads

        endif

        if [areax]=5&[areay]=6 then

                call sands

        endif

        if [areax]=6&[areay]=6 then

                call pileofskulls

        endif

        if [areax]=7&[areay]=6 then

                if [outlaw]=0 then

                        call sands

                endif

                if [outlaw]=1 then

                        call robbery

                endif                   

        endif

        if [areax]=8&[areay]=6 then

                call sands

        endif

        if [areax]=1&[areay]=7 then

                call spring

        endif

        if [areax]=2&[areay]=7 then

                call cliff

        endif

        if [areax]=3&[areay]=7 then

                call sands

        endif

        if [areax]=4&[areay]=7 then

                call roads

        endif

        if [areax]=5&[areay]=7 then

                call sands

        endif

        if [areax]=6&[areay]=7 then

                call sands

        endif

        if [areax]=8&[areay]=7 then

                call sands

        endif

        if [areax]=4&[areay]=8 then

                call traveller

        endif

        if [areax]=5&[areay]=8 then

                call sands

        endif

        if [areax]=6&[areay]=8 then

                call sands

        endif

        if [areax]=8&[areay]=8 then

                call greatlake

        endif

        if [boulder]=1 then

                call boulders

        endif

        crlf

ret

sub lookcommand

        compare [check],command$,"LOOK"
        compare [shortcheck],command$,"L"
        
        if [check]=1|[shortcheck]=1 then

                0 [errorflag]

                [temp]=[hydration]
                call areadescription
                [hydration]=[temp]

        endif

ret

sub northcommand

        compare [check],command$,"NORTH"
        compare [shortcheck],command$,"N"

        0 [moved]

        if [check]=1|[shortcheck]=1 then

                0 [errorflag]

                if [areay]>1 then

                        [moved]=1
                        -1 [areay]
                        echo "You travel North."

                endif

                if [moved]=0 then

                        echo "You are unable to travel North."

                endif

                call areadescription

        endif


ret

sub eastcommand

        compare [check],command$,"EAST"
        compare [shortcheck],command$,"E"

        0 [moved]

        if [check]=1|[shortcheck]=1 then

                0 [errorflag]

                if [areax]+1<=[areasx] then

                        [moved]=1
                        +1 [areax]
                        echo "You travel East."

                endif

                if [moved]=0 then

                        echo "You are unable to travel East."

                endif

                call areadescription

        endif

ret

sub southcommand

        compare [check],command$,"SOUTH"
        compare [shortcheck],command$,"S"

        0 [moved]

        if [check]=1|[shortcheck]=1 then

                0 [errorflag]

                if [areay]+1<=[areasy] then

                        [moved]=1
                        +1 [areay]
                        echo "You travel South."

                endif

                if [moved]=0 then

                        echo "You are unable to travel South."

                endif

                call areadescription

        endif

ret

sub westcommand

        compare [check],command$,"WEST"
        compare [shortcheck],command$,"W"

        0 [moved]

        if [check]=1|[shortcheck]=1 then

                0 [errorflag]

                if [areax]>1 then

                        [moved]=1
                        -1 [areax]
                        echo "You travel West."

                endif

                if [moved]=0 then

                        echo "You are unable to travel West."

                endif

                call areadescription

        endif

ret

sub examinecommand

        compare [check],command$,"EXAMINE"
        compare [shortcheck],command$,"EX"

        if [check]=1|[shortcheck]=1 then

                0 [errorflag]

                if [areax]=2&[areay]=2 then

                        call examinebaleofhay

                endif

                if [areax]=3&[areay]=2&[locked]=0 then

                        call examinerange
                        call examinebed
                        call examineshelf

                endif

                if [areax]=2&[areay]=3 then

                        call examinecrops

                endif

                if [areax]=3&[areay]=3 then

                        call examinecrops

                endif

                if [areax]=2&[areay]=4 then

                        call examinecrops

                endif

                if [areax]=3&[areay]=4 then

                        call examinecrops

                endif

                if [areax]=6&[areay]=1 then

                        call examineskeleton

                endif

                if [areax]=6&[areay]=6 then

                        call examinepileofskulls

                endif

                crlf

        endif

ret

sub examinebaleofhay

        compare [check],parameters$,"BALE OF HAY"

        if [check]=0 then

                compare [check],parameters$,"BALE"

        endif

        if [check]=0 then

                compare [check],parameters$,"HAY"

        endif

        if [check]=1 then

                if [key]=1 then

                        echo "There's nothing of interest."

                endif

                if [key]=0 then

                        echo "There's a rusty old key in the hay."

                endif

        endif

ret

sub examinerange

        compare [check],parameters$,"RANGE"

        if [check]=1 then

                echo "The range hasn't been used recently."

        endif

ret

sub examinebed

        compare [check],parameters$,"BED"

        if [check]=1 then

                echo "The bed is old, yet looks cozy."

        endif

ret

sub examineshelf

        compare [check],parameters$,"SHELF"

        if [check]=1 then

                echo "The shelf contains the following items..."

                if [rope]=0 then

                        echo "rope"

                endif

                if [gourd]=0 then

                        echo "gourd"

                endif

        endif

ret

sub examinecrops

        compare [check],parameters$,"CROP"

        if [check]=1 then

                echo "There's doesn't appear to be anything useful here."

        endif

ret

sub examineskeleton

        compare [check],parameters$,"SKELETON"

        if [check]=1 then

                if [derringer]=1 then

                        echo "There's only bones and tatters."

                endif

                if [derringer]=0 then

                        echo "A dirty, rusty, old derringer is in the skeleton's hand."

                endif

        endif

ret

sub examinepileofskulls

        compare [check],parameters$,"PILE OF SKULLS"

        if [check]=0 then

                compare [check],parameters$,"SKULLS"

        endif

        if [check]=1 then

                echo "The stench is terrible."
                echo "Ravens circle the area."
                echo "There's nothing of interest."

        endif

ret

sub takecommand

        compare [check],command$,"TAKE"
        compare [shortcheck],command$,"T"

        if [check]=1|[shortcheck]=1 then

                0 [errorflag]

                if [areax]=2&[areay]=2&[key]=0 then

                        call takekey

                endif

                if [areax]=3&[areay]=2&[locked]=0&[rope]=0 then

                        call takerope

                endif

                if [areax]=3&[areay]=2&[locked]=0&[gourd]=0 then

                        call takegourd

                endif

                if [areax]=6&[areay]=1&[derringer]=0 then

                        call takederringer

                endif

        endif

ret

sub takekey

        compare [check],parameters$,"KEY"

        if [check]=1 then

                +1 [key]

                echo "You take the key."
                crlf

        endif

ret

sub takerope

        compare [check],parameters$,"ROPE"

        if [check]=1 then

                +1 [rope]

                echo "You take the rope."
                crlf

        endif

ret

sub takegourd

        compare [check],parameters$,"GOURD"

        if [check]=1 then

                +1 [gourd]

                echo "You take the gourd."
                crlf

        endif

ret

sub takederringer

        compare [check],parameters$,"DERRINGER"

        if [check]=1 then

                +1 [derringer]

                echo "You take the derringer."
                crlf

        endif

ret

sub usecommand

        compare [check],command$,"USE"
        compare [shortcheck],command$,"U"

        if [check]=1|[shortcheck]=1 then

                0 [errorflag]

                if [gourd]=1 then

                        call usegourd

                endif

                if [areax]=3&[areay]=2&[key]=1&[locked]=1 then

                        call usekey

                endif

        endif

ret

sub usegourd

        if [gourdfull]=1 then

                [hydration]=[hydration]+5

                echo "You drink the water from your gourd."
                echo "It's warm, but you still feel refreshed."
                crlf

        endif

        if [gourdfull]=0 then

                echo "The gourd is empty. You have no water!"
                crlf

        endif

        0 [gourdfull]

ret

sub usekey

        0 [locked]

        echo "After a short struggle, you manage to unlock the door."
        crlf

ret

sub talkcommand

        compare [check],command$,"TALK"
        compare [shortcheck],command$,"TA"

        if [check]=1|[shortcheck]=1 then

                0 [errorflag]

                if [areax]=4&[areay]=8&[bullets]=0&[gourd]=1&[gourdfull]=1 then

                        call talktotraveller

                endif

        endif

ret

sub talktotraveller

        echo "Traveller:"
        echo "Hello, may you please share some water with me."
        echo "I am so very thirsty and cannot go on without a drink."
        crlf
        echo "Will you offer the traveller a drink of water?"
        echo "Yes or no? "\

        call getinput

        compare [check],cmdline$,"YES"
        compare [shortcheck],cmdline$,"Y"

        if [check]=1|[shortcheck]=1 then

                0 [gourdfull]
                +1 [bullets]

                echo "You share the water from the gourd with the traveller."
                crlf
                echo "Traveller:"
                echo "Thank you for helping me. I thought my life was over!"
                echo "Here's some bullets. They are of no use to me and are"
                echo "all that I have to repay you."

        endif

        crlf

ret

sub inventorycommand

        compare [check],command$,"INVENTORY"
        compare [shortcheck],command$,"I"

        if [check]=1|[shortcheck]=1 then

                0 [errorflag]

                echo "You are carrying the following items..."

                if [key]=1 then

                        echo "key"

                endif

                if [rope]=1 then

                        echo "rope"

                endif

                if [gourd]=1 then

                        if [gourdfull]=1 then

                                echo "full gourd"

                        endif

                        if [gourdfull]=0 then

                                echo "empty gourd"

                        endif

                endif

                if [bullets]=1 then

                        echo "bullets"

                endif

                if [derringer]=1 then

                        echo "derringer"

                endif

                crlf

        endif

ret

sub helpcommand

        compare [check],command$,"HELP"
        compare [shortcheck],command$,"H"

        if [shortcheck]=0 then

                compare [shortcheck],command$,"?"

        endif

        if [check]=1|[shortcheck]=1 then

                0 [errorflag]

                cls

                echo "Help:"
                crlf
                echo "(l)ook"
                echo "(n)orth"
                echo "(e)ast"
                echo "(s)outh"
                echo "(w)est"
                echo "(ex)amine (object)"
                echo "(t)ake (object)"
                echo "(u)se (object)"
                echo "(ta)lk"
                echo "(i)nventory"
                echo "(h)elp"
                echo "(q)uit"
                crlf
                echo "Press any key to continue..."
                pause
                cls

        endif

ret

sub byecommand

        compare [check],command$,"BYE"

        if [check]=0 then

                compare [check],command$,"END"

        endif

        if [check]=0 then
        
                compare [check],command$,"QUIT"

        endif

        if [check]=0 then
        
                compare [check],command$,"EXIT"

        endif

        compare [shortcheck],command$,"Q"

        if [check]=1|[shortcheck]=1 then

                kill

        endif

ret

sub boulders

        echo "The boulders here are much too steep. You'll have to go another way."

        [areax]=[lastareax]
        [areay]=[lastareay]

ret

sub sands

        0 [boulder]

        echo "There's nothing, but sand here."
        echo "The sand is hot and the air is dry."
        echo "Your thirst intensifies."

        -1 [hydration]

ret

sub roads

        0 [boulder]

        echo "You find yourself wandering an old road."
        echo "There's nothing for miles."
        echo "The long walk is making you thirsty."

        -1 [hydration]

ret

sub crossroad

        0 [boulder]

        echo "You are at a crossroad."
        echo "The signpost is faded and unreadable."

        -1 [hydration]

ret

sub crops

        0 [boulder]

        echo "You are surrounded by the remains of an old crop."
        echo "Nothing has grown here for a long time."

ret

sub barn

        0 [boulder]

        echo "There's an old barn here."
        echo "The place is falling apart."
        echo "A single bale of hay remains inside."

ret

sub house

        0 [boulder]

        if [locked]=1 then

                echo "You are outside of an old house."
                echo "The door is locked and the windows are boarded."

        endif

        if [locked]=0 then

                echo "You are inside of an old house."
                echo "There's a range and a bed."
                echo "Above the range is a shelf."

        endif

ret

sub cliff

        0 [boulder]

        if [rope]=1 then

                echo "You are at the edge of a cliff."
                echo "The rope you found at the old house helps you to climb safely."

        endif

        if [rope]=0 then

                echo "You are at the edge of a cliff."
                echo "Maybe you can find somethig to help climb down safely."

                [areax]=[lastareax]
                [areay]=[lastareay]

        endif

ret

sub spring

        0 [boulder]

        echo "You are in a valley between the cliffs. It's beautiful."
        echo "The bushes are a vibrant green."
        echo "Water from the surrounding areas collect here."
        echo "There's a small spring of fresh water."
        echo "You take a good drink and fill your gourd."
        echo "There's berries growing here as well. Delicious!"

        [hydration]=15
        [gourdfull]=1

ret

sub traveller

        0 [boulder]

        if [bullets]=1 then

                call roads

        endif

        if [bullets]=0 then

                if [gourd]=1&[gourdfull]=1 then

                        echo "You encounter a lone traveller."
                        echo "It looks like he wants to talk with you."

                endif

                if [gourdfull]=0 then

                        call roads

                endif

        endif

ret

sub skeleton

        0 [boulder]

        echo "You have been walking for a very long time."
        echo "There's a skeleton lying here in the sand."
        echo "Your thirst intensifies."

        -1 [hydration]

ret

sub pileofskulls

        0 [boulder]

        echo "There's a pile of skulls in the sand."
        echo "Something terrible happened here."
        echo "Whatever it was, that was long ago."
        echo "Your thirst intensifies."

        -1 [hydration]

ret

sub robbery

        0 [boulder]

        echo "You find a passage between the steep boulders."
        echo "Suddenly, an outlaw appears and confronts you."
        crlf
        echo "Outlaw:"
        echo "Give me your possessions or die!"
        crlf
        echo "Will you defend yourself or run?"
        echo "Defend or Run? "\

        call getinput

        compare [check],cmdline$,"DEFEND"
        compare [shortcheck],cmdline$,"D"

        if [check]=1|[shortcheck]=1 then

                if [derringer]=1&[bullets]=1 then

                        echo "The outlaw attempts to draw his gun and shoot you."
                        echo "You produce your gun and shoot him just in time."
                        echo "The outlaw is dead."

                        0 [outlaw]

                endif

                if [derringer]=0|[bullets]=0 then

                        echo "You attempt to defend yourslef, but are shot in the process."
                        echo "Never bring your fists to a gun fight... Game over."
                        bell
                        pause
                        kill

                endif

        endif

        if [check]=0&[shortcheck]=0 then

                echo "You narrowly manage to escape the outlaw robber."

                [areax]=[lastareax]
                [areay]=[lastareay]

        endif

ret

sub greatlake

        echo "After a long adventure, you have found something spectacular."
        echo "A great lake full of life and beauty. This place is your calling."
        echo "It's time for you to settle down and build your home here."
        echo "You win the game!"
        bell
        pause
        kill

ret

sub getinput

        input cmdline$
        trim cmdline$
        upper cmdline$

ret    


Last edited by geekbasic@gmx.com on 31 Dec 2022, 01:50; edited 1 time in total
Post 30 Dec 2022, 04:27
View user's profile Send private message Visit poster's website Reply with quote
geekbasic@gmx.com



Joined: 25 Oct 2022
Posts: 71
Location: Arizona
geekbasic@gmx.com 30 Dec 2022, 19:49
I have fixed a bug that caused an error with whitespace between the assignment variable of arithmetic statements and the equals, but only when it was an array.

I have also added a bubble sort example to the download. It compiles to 549 bytes.

Here's a preview of the bubble sort code.
Code:
;bubble sort example for x86 DOS
;demonstrates arrays
;compile with Pebble

program examples\bubble

data

        int sorting[0]
        int index[0]
        int size[10]
        int temp1[0]
        int temp2[0]

        int@ list[10]

begin

        call fill
        call sort
        call output

        pause
        kill

end

sub fill

        0 [index]

        label loopfill

                echo "Enter value #" \
                echo [index]
                echo ": " \

                input @list{[index]}

                +1 [index]

        if [index] < [size] then loopfill

ret

sub sort

        label loopsort

                0 [sorting]

                0 [index]

                label process

                        [temp1] = [index] + 1

                        if @list{[index]} > @list{[temp1]} then

                                [temp2] = @list{[index]}

                                @list{[index]} = @list{[temp1]}
                                @list{[temp1]} = [temp2]

                                [sorting] = 1

                        endif

                        +1 [index]

                if [index] < [size] - 1 then process

        if [sorting] = 1 then loopsort

ret

sub output

        0 [index]

        label loopoutput

                echo [index]
                echo " : " \
                echo @list{[index]}
                crlf

                +1 [index]

        if [index] < [size] then loopoutput

ret    
Post 30 Dec 2022, 19:49
View user's profile Send private message Visit poster's website Reply with quote
geekbasic@gmx.com



Joined: 25 Oct 2022
Posts: 71
Location: Arizona
geekbasic@gmx.com 09 Jan 2023, 00:06
I have uploaded a major update to Pebble that fixes an issue with the expression parser. It's available in the download.
Post 09 Jan 2023, 00:06
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:  


< 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-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.