Free Science Fiction Stories

Free stories from the depths of my imagination

Wee Basic Manual

Welcome to

Wee Basic

A. Operation

NOTE: There is no ‘run’ command.  Press the A or START key to run your program.  Press ‘X’ to load a program (text) file and press ‘Y’ to save a program (text) file.  You can also use the dashboard on the bottom screen which contains icons to save, load and run a program (just tap the relevant icon with finger or stylus).

BREAK: hold ‘A’ and ‘Start’ at the same time to break a running program (eg if you get stuck in an infinite loop)

B. Commands/statements etc

1. Statements

rem

Description: leave a comment or remark in a program.

Usage: rem [any symbol or letter as a comment] *

Everything between “rem” and “*” is ignored by the interpreter.

Examples:

rem This is a program *
rem Hello.  The interpreter will ignore this so I can say whatever I want *

dim

Description: sets aside memory in the variable table for an array. In Wee Basic, each array must be initialised with dim or using the array will result in an error. There is a maximum of 100 numerical and 100 string variables. Each string array is limited to 30 members and each numerical array is limited to 100 members.

Usage: dim <variable name>(<number of elements>)

Examples:

dim astring$(5)
dim num(10)
for i=1 to 10
let num(i)=i+1
next

while/wend

Description: loops until a condition is satisfied.

Usage:

while <condition>
[block]
wend

<condition> is a boolean expression
Nested while statements are supported in Wee Basic

Examples:

let x=0
while x=0
let x=key()
wend

if/elseif/else/endif

Description: isn’t it obvious?

Usage:

if <condition> {and/or <condition> {and/or <condition>}… etc}
[block]
[elseif <condition>]
[block]
[elseif <condition>]
[block]
Etc..
[else] [block]
endif

<condition> is a boolean expression, eg >, <, = and <>
Nested ‘if’ statements are supported in Wee Basic

Examples:

input age

if age>12 and age<20 print 1 “you are a teenager”
endif

for/next

Description: isn’t it obvious?

Usage:

for <variable> = <number/variable> to <number/variable [<number/variable]
[block]
next

The syntax at the end, ie “[<number/variable]” is optional and provides a step function.

Nested ‘for’ statements are supported in Wee Basic

Examples:

for i=1 to 10
print 1 i
next

for j=1 to 20 [10]
next

(In this example, j will go from 1 to 11 to 21)

let

Description: Wee Basic requires ‘let’ for all assignments

Usage:

let <string variable> = <string expression>
or
let <number variable> = <number expression>

Examples:

let anumber=5
let astring=”Hello”
if a=5 let b=10
endif

goto

Description: move program execution to specified label

Usage: goto <label name>:

Examples:

lab start:
goto start:

gosub/return

Description: execute subroutine

Usage: gosub <sub name>:

Examples:

gosub start:
end

sub start:
print “This is the start.”
return

print/print at

Description: prints text on specified DS screen

Usage: print s [at x,y] <string or variable>, s is screen

at x,y is optional

Examples:

print 1 “Hello World”
print 0 at 5,5 “This is a program”
print 0 astring$

cls

Description: clears specified DS screen of text and graphics

Usage: cls s, s is screen

Examples:

cls 0
cls 1

end

Description: ends the basic program. Omitting ‘end’ will result in an error and so will placing anything after end (except for subroutines – see ’sub’)

Usage: end

input

Description: allows the user to input text until <return> is pressed

Usage: input <variable>

Examples: input a$

Note: buggy, better to use key()

lab

Syntax: lab <label name>:
see goto

sub

Syntax: sub <sub name>: [block] return

see gosub

plot

Description: Places a pixel on screen s at x,y

Usage: plot <s> <x>,<y>,<colour>

Note: colour is a number/variable 0-16  (0 is used to erase)

(See line statement for colours)

line

Description: Draws a line on screen s from x1,y1 to x2,y2

Usage: line <s> <x1>,<y1>,<x2>,<y2>,<colour>

Note: colour is a number/variable 0-16 (0 is used to erase)

Colour are:

black 1
blue 2
green 3
cyan 4
red 5
magenta 6
brown 7
white 8
gray 9
light blue 10
light green 11
light cyan 12
light red 13
light magenta 14
yellow 15
bright white 16

keyshow

Description: show the soft keyboard on the bottom screen if hidden

Usage: keyshow

keyhide

Description: hides the soft keyboard on the bottom screen if visible

Usage: keyhide

Note: keyhide MUST be used before displaying anything on the botton screen. Otherwise Wee Basic throws an error (reason is the user will not be able to see anything displayed if the keyboard is present).

createspr

Description: Creates a sprite specified by the file name on the screen specified at the specified coordinates.

Usage: createspr <number>,<screen>,<x>,<y>,<width>,<height>,<file name>

<file name> is a string or string variable. The file must be a gif file for a 256 colour sprite (greater colour depth will cause a crash). The file must be in the root directory of your card.  The others are numbers or number variables

movspr

Description: Moves an existing sprite specified by the number to new coordinates x and Y on the screen.

Usage: movspr <number>, <screen>, <x>,<y>

All input are numbers or number variables

delspr

Description: Deletes the specified sprite.

Usage: delspr <number>, <screen>

All input are numbers or number variables

vflip and hflip

Description: flips sprites vertically and horizontally.

Usage:

hflip <sprite no>,<screen>
vflip <sprite no>,<screen>

backgr

Description: Creates a background on the specified screen with the gif file specified by the file name.  The file must be 256 colours and in the root directory of your card.

Usage: backgr <screen>, <file name>

Note: <file name> is a string or string variable. The file must be a gif file. Screen is 0 or 1.

2. Sounds

- playmp3 [string] {string is file name}

or playmp3 [string],<filename> <volume>,<pan>,<bitrate>  (each is an integer or number variable)

File must be in the root directory of your card.

plays an mp3 file

- pausemp3

pauses the playing of an mp3 file

- contmp3

continues a paused mp3 file

3. Microphone

- micrec

records from the microphone
will automatically stop recording when buffer is full so no need to manually stop recording

- micpla

plays whatever has been previously recorded from the microphone

4. Expressions

Syntax: let <variable>=<expression>

int(<number expression>)
rnd(<number expression>)
sin(<number expression>)
cos(<number expression>)
tan(<number expression>)
log(<number expression>)
sqrt(<number expression>)
key() – gets key input

returns an integer value for keys pressed as follows:

X: 200
Y: 201
A: 202
B: 203
Left: 204
Right: 205
Up: 206
Down: 207
L: 208
R: 209
Start: 210
Select: 211

keyboard: ascii value

stx() – stylus x coordinate
sty() – stylus y coordinate
stt() – 1 if stylus touches screen, 0 if not

motx – motion x coordinate

moty – motion y coordinate

3. Math symbols

+, -, *, /, ^

4. Motion

- motion (initialises motion – throws an error if motion card is not detected

(see also expressions)

5. Examples

(a) Fun with colours

dim letter$(5)
let letter$(1)=”h”
let letter$(2)=”e”
let letter$(3)=”l”
let letter$(4)=”l”
let letter$(5)=”o”
rem hide the keyboard to use the bottom screen *
keyhide
print 0 at 0,14 “Wee Basic: Fun with colours”
print 0 at 0,15 “Keep pressing a button”
print 0 at 0,16 “to continue”
let j=4
rem test all new 16 colours *
for i=1 to 16
rem draw a line with each colour on each screen *
line 1 j,1,j,30,i
line 0 j,1,j,30,16-i
print 0 at 0,20 “J: “+j+ “i: “+i
let j=j+10
gosub getkey:
next
rem let’s test ‘;’ with print *
for e=1 to 5
print 1 letter$(e);
next
end

rem wait for a key to be pressed *
sub getkey:
let k=0
while k=0
let k=key()
wend
return

(b) Creating and flipping a sprite

createspr 1,1,50,50,32,64,”soldier.gif”
gosub getkey:
hflip 1,1
gosub getkey:
vflip 1,1
gosub getkey:
end

sub getkey:
let k=0
while k=0
let k=key()
wend
return

(Make sure you have a 32×64 sprite named “soldier.gif” in the root directory or this program will raise an error)

(c) Sound

print 1 “A – Pause mp3″
print 1 “B – Continue mp3″
print 1 “right – replay”
print 1 “higher volume/rate”
print 1 “left – exit”
print 1 ” “
let keya=202
let keyb=203
let right=205
let left=204
let vol=10
let pan=0
let rate=500
lab start:
let k=0
print 1 at 0,20 “Volume:”+vol
print 1 at 0,21 “pan: “+pan
print 1 at 0,22 “rate: “+rate
playmp3 “test.mp3″,
vol,pan,rate
while k<>right and k<>left
if k=keya pausemp3
endif
if k=keyb contmp3
endif
let k=key()
wend
stopmp3
let vol=vol+10
let rate=rate+50
if pan=0 let pan=64
elseif pan=64
let pan=127
elseif pan=127
let pan=0
endif
if vol>=127
let vol=10
endif
if k=right
goto start:
endif
end

(Make sure you have a file named test.mp3 in the root directory or this program will raise an error)

(d) Microphone

let keya=202
let keyb=203
let right=205
let k=0 let rec=0
while k<>keya
if k=right and rec=0
let rec=1
print 1 “Recording….”
micrec
endif
if k=keyb and rec=1
let rec=0
print 1 “Playing….”
micpla
endif
let k=key()
wend
end

(e) rem test

rem hello this should all be ignored*
print 1 “Helllo world”
end

(f) sprite demo

let soldier=1
let bottom=0
let top=1
let keya=202
let keyb=203
let right=205
let left=204
let soldx=5
let soldy=95

cls 1
keyhide
cls 0

gosub topback:
gosub botback:
gosub soldspr:

lab start:

let k=0
let k=key()

if k=keyb
gosub jump:
endif

if k=keya
goto finish:
endif
if k=right or k=left
gosub movsold:
endif

goto start:

lab finish:
end

sub key:
let k=0
while k=0
let k=key()
wend
return

sub topback:
backgr top,”island.gif”
return

sub botback:
backgr bottom,”lake.gif”
return

sub soldspr:
createspr soldier,bottom,
soldx,soldy,32,64,
“soldier.gif”
return

sub movsold:
if k=right
let soldx=soldx+20
movspr soldier,bottom,
soldx,soldy
endif
if k=left
let soldx=soldx-20
movspr soldier,bottom,
soldx,soldy
endif
return

sub jump:
for i=1 to 4
let soldy=soldy-20
movspr soldier,bottom,
soldx,soldy
gosub delay:
next
for i=1 to 4
let soldy=soldy+20
movspr soldier,bottom,
soldx,soldy
gosub delay:
next
return

sub delay:
for j=1 to 10
next
return

(You need all of the gif files in the root directory for this to work)

84 Comments »

  1. I need to unjoy weebasic the extended playmp3 fonction: loke that playmp3, canal 1 to …12, volume 1 to 16 polyphonic mp3 sample player !
    do you understand wath i wanna do with my DS !
    the micrec fonction to ex micrec A$”name”,canal 1 to…12 !
    and i’ll be happy with my ds for ever

    Comment by zomboula | February 22, 2009 | Reply

  2. i wrote an error excuse me for playmp3
    it’s look like that : playmp3[string],canal 1 TO 12,volume

    and the micrec looks like : micrec[string] and micplay[string],canal 1 TO 12,volume

    Comment by zomboula | February 22, 2009 | Reply

  3. I really hope that you could make it it will be a big joy for me. thank you mrs

    Comment by zomboula | February 22, 2009 | Reply

  4. yeesssss ! so good ! yes

    the playmp3 fonction need chanel to use polyphonia sond !

    look than this : playmp3 “nameofmp3″,A$(chanel),v$(volume)

    and the wee basic can make a mp3sequencer !

    Comment by teocomputer | February 24, 2009 | Reply

  5. the microphone fonction look like that in my configuration

    micrec “name of sound”

    micplay “name of sound”,a$(chanel),v$(volume)

    and it make my ds so nice to do voice machine !

    i am so impatient to programming !!!!!

    Comment by teocomputer | February 24, 2009 | Reply

  6. very very very immpoorrttantt !!!

    i forget to tell u a new fonction to playmp3 !!! the rate of playing sample or mp3

    The fonction: playmp3 “nameof mp3″,R$,b$,v$

    r$ is the rate of the sample or mp3 value 0 to 1024
    b$ is the chanel to play on polyphonia with chanel 0 to 12
    v$ is the volume 0 to 255

    and my ds could be a sequencer like QBASE !!!!

    Comment by zomboula | February 24, 2009 | Reply

  7. zomboula, teocomputer: I’ll look into this.

    Comment by freescifistories | February 25, 2009 | Reply

  8. OOOOOH thank you very very much ! have a good and nice programming mister !

    Comment by zomboula | February 25, 2009 | Reply

  9. i’m very interested to that project to !

    welcome wee basic

    Comment by sweetroms | February 25, 2009 | Reply

  10. yep yep !

    Comment by teocomputer | February 25, 2009 | Reply

  11. zomboula i’m agree with your fonction is better

    Comment by teocomputer | February 25, 2009 | Reply

  12. how are mr freescifistories ?

    Comment by teocomputer | February 25, 2009 | Reply

  13. i don’t now but it’s the master

    Comment by zomboula | February 25, 2009 | Reply

  14. how to save and load a basic programme on wee basic mr freescifistories ??

    Comment by teocomputer | March 9, 2009 | Reply

  15. the wee basic 0.5 have a bug

    Comment by teocomputer | March 9, 2009 | Reply

  16. To load:

    - press X
    - type the filename eg demo.txt
    - tap enter key on soft keyboard

    To save:

    - press Y
    - type the filename
    - tap enter key

    Have you DLDI patched the rom?

    Please describe the bug

    Comment by freescifistories | March 9, 2009 | Reply

  17. The manual looks good. I’d like to show wee basic to my son who has the DS. So I tried wee06 on no$gba emu, and I can type in a program. I haven’t touched much BASIC since the late 1980s, and the “run” cmd just didn’t work. Finally figured out that I needed to press start. You might want to add that to the user manual. Thanks for creating this. Good luck with it.

    Comment by s54boc | March 25, 2009 | Reply

  18. Thanks s54boc. I’ve added a note at the beginning of the manual.

    Comment by freescifistories | March 25, 2009 | Reply

  19. Been using it more. (version 0.6) Having some issues with the editor when the listing is longer than the screen will hold. But also getting a lot of syntax errors that are not errors. Strange little changes fix it. For example, Problem with labels. If I just change the name of a label from done1: to done11: the problem goes away. Also nested if not following logic correctly – seems to miss the inside endif statement.
    Do you see these things too?
    But happy to see that filenames can include path, so files don’t have to be in the root directory.
    It’s great to be able to program right on the DS. Thanks again. Do you want me to send samples of code that fail?

    Comment by s54boc | March 27, 2009 | Reply

  20. s54boc: yes please provide the code that fails – it’s great to have your feedback so that I fix any bugs

    Comment by freescifistories | March 27, 2009 | Reply

  21. Hi

    Only just started to use it, but so far I really love weebasic, but after getting into a loop, is there a key combination that can be used to ‘break’ out of the running of a program?

    That would help me so much. Many thanks.

    Comment by Simon Ferré | March 28, 2009 | Reply

  22. Great to hear Simon. There is no break command. I’ll put it on the to do list. In the meantime, use a workaround such as using a loop with a variable that can be changed to true if you want to break out of the loop eg

    let i=1
    while(i=1)
    //code
    if [condition] let i=1 //want to break out of the loop
    endif
    wend
    end

    or

    for i=1 to 10
    //code
    if [condition] let i=10 //want to break out of the loop
    endif
    next
    end

    Comment by freescifistories | March 29, 2009 | Reply

  23. Does weebasic support comments (a la C++, as shown in last post)?

    Comment by s54boc | April 1, 2009 | Reply

  24. s54boc: unfortunately not yet but it’s pretty trivial to implement so I’ll try and get them done in the next version.

    Comment by freescifistories | April 1, 2009 | Reply

  25. [...] [...]

    Pingback by wee basic ds Flashcards & Homebrew | July 14, 2009 | Reply

  26. Cool! I’ve been messing around in WeeBASIC and made a little application that plays kind of like capture the flag, so far its done besides ai, but it doesn’t seem to detect when the keys are held, any ideas?

    Comment by chao1212 | August 2, 2009 | Reply

  27. AI is done BTW, just have to make it detect the flag, make it vulnerable when it’s got the flag, and improve button detection (You have to keep pressing it, while the AI just blows throw it.

    Comment by chao1212 | August 2, 2009 | Reply

  28. sounds great chao1212. At the moment, wee basic only detects key presses rather than keys “held” which is why you have to keep pressing. I can include keys “held” in a later version if you like.

    Comment by freescifistories | August 2, 2009 | Reply

  29. i try run weebasic 0.81 on supercard dsone
    it runs… :-) wow
    trying PRINT command

    this code runs
    —-
    keyhide
    print 0 at 0,12 ” Ciao mondo”
    —-

    this code runs with bugs
    —————-
    keyhide
    print 0 at 0,12 ” Ciao mondo”
    print 0 at 12,12 ” Sono anche qui”
    print 0 at 21,12 ” e anche qui”
    —————–
    i get all three string on middle of touchscreen in sequence

    if i run again this code weebasic crush!

    Comment by BASIC FaN | September 12, 2009 | Reply

    • BASIC FaN, did you put ‘end’ at the end of your program?

      eg print 1 “Hello”
      end

      Comment by freescifistories | September 12, 2009 | Reply

      • If this doesn’t help then post the exact code and I will test it.

        Comment by freescifistories | September 12, 2009

    • thank’s for fast answer!
      i haven’t put statement END at the end of program

      output on touchscreen was like this:

      Ciao mondoSono anchequi e anche qui

      how you can see, all three string in sequence!
      in my basic experience this is wrong…
      if i PRINT at X,Y first$
      and then i PRINT at X,Y second$ again
      i must get that second$ overwrite first$ screen_output
      for its lenght! Not this!
      Only in Qbasic PRINT statement I remember the option ‘;’ that force this result.

      Now I try ending code with END statement…
      ok, it runs well
      thank you…
      Now I cancel END statement and I run code again
      it runs well also without END statement…

      where is the bug?

      Now testing this following code all run right! :-)
      Also without END statement!

      ———————
      keyhide
      print 0 at 1,12 “Ciao”
      gosub aspetta:
      print 0 at 1,12 “coccodrillo”
      gosub aspetta:
      print 0 at 1,12 “gioca”

      sub aspetta:
      let a=0
      while a=0
      let a=key()
      wend
      return
      ———————–

      Sorry for my many questions

      1. How to open codefile save? using open icon or X key
      I get only .SAV e .NDS files …in SD root no folder… oops i wrongly put in a folder weebasic files (wee81samp.txt weebasic.nds)! Now I’ll move them in root. What extension i must search? .SAV?!?

      2. how start a new code project?

      thank you for spending your time !

      Comment by BASIC FaN | September 12, 2009 | Reply

      • BASIC FaN,

        Maybe there’s a bug with the new code I put in for ‘;’. I’ll check it out.

        In relation to your other questions:

        1. yes – wee basic searches for files in the root directory only. Also wee basic files should just have a .txt extension NOT .sav

        2. at the moment there is no start new project option. Just create a blank file called start.txt and load it each time you want to start a new project. I’ll fix this in a later version.

        Comment by freescifistories | September 13, 2009

      • I have tested weebasic also on R4 and all run ok also without END statement, but i got error message coming back in program… :-)
        all right I’ll search .TXT file for saved and I’ll create new.TXT for new blank TXT file
        Bye and thank’s

        Comment by BASIC FaN | September 13, 2009

  30. BASIC FaN, I’ve tested your code.

    First:

    keyhide
    print 0 at 0,12 ” Ciao mondo”
    print 0 at 12,12 ” Sono anche qui”
    print 0 at 21,12 ” e anche qui”

    This prints all three strings in a row because you have the same y value for each “print at” and the x values are in sequence (ie you don’t have the same x value – there is no overwriting). There is no bug. Also, without an ‘end’ statement I get a “statement expected” error at the end of the program which is exactly what should happen.

    Second:

    keyhide
    print 0 at 1,12 “Ciao”
    gosub aspetta:
    print 0 at 1,12 “coccodrillo”
    gosub aspetta:
    print 0 at 1,12 “gioca”

    sub aspetta:
    let a=0
    while a=0
    let a=key()
    wend
    return

    Here you have the same x and y values which is why each string gets overwritten. Again, no bug. Also I get “statement expected” error without an ‘end” statement which is how it should work.

    Let me know if you have any other questions.

    Comment by freescifistories | September 14, 2009 | Reply

    • Hello freesifistories
      that you said is right … in a second time I’m counting characters in strings of first code… lenght of string is very like to X value used in PRINT 0 AT statement… so i get an effect like “;” option!
      in the second code example I get what you have got! the code runs and come back with a warning “absence of END statement”!
      Ok thank’s…
      I put weebasic file in root of SD of DSone
      now say me please how to save codefile and then load it!
      1) name like “.\name.txt” gets message error… “Save file, Please enter the exact name of the file to save, Cannot open file, press A to continue”
      ok this is a bad name file

      2)name like “111″ or “qqq.txt” no gets message error… but opening a file with X button or Open icon I get a short filelist with only .SAV and .NDS files in root!
      first question: How to see .TXT file?
      second question: how many files can list in this function weebasic?

      3) name like “000.sav” or “qqq.nds” no gets message error… but opening a file with X button or Open icon I get a short filelist .SAV and .NDS but I don’t see 000.sav or qqq.nds! How can i solve this?
      thank’s for your time

      Comment by BASIC FaN | September 16, 2009 | Reply

      • BASIC FaN, wee basic doesn’t allow directory characters such as “./”. You just need to enter the name of the file eg “file.txt”.

        When you use “X” to load, make sure you scroll down the screen using the d pad – up and down. That way you’ll see more files.

        Comment by freescifistories | September 17, 2009

  31. yes friend but that OPEN_FILE filelist is too short…
    :-) just on a SD with 30-40 files and folders at root it runs ok, but on a most crowed (populated) root it fails!
    But with a dedicate SD on DSone it runs ok (few files and folders in root)… no problem ;-)

    some questions:
    1.variable type:
    variable are strings (ie stringa$ o let stringa= ” ” or dim stringaArray$(100) if I’ve understood)
    or integer number… in future it will be real number?
    2. INPUT statement: help on this page says “buggy” I must forget INPUT statement?

    thank you very much for spending your time!

    Comment by BASIC FaN | September 17, 2009 | Reply

    • Okay, I understand. Yes, there’s a 50 file limit in terms of what can be displayed. If you have more than 50 files then the rest won’t display. If there’s enough memory I’ll change this in a later version.

      Strings:

      - have to end in ‘$’ and can have up to 7 characters in their name (there can be 80 characters in the string itself). Eg let a$=”hello” or let string$=”me”
      - you only need to dim arrays. Eg dim a$(10) Let a$(1)=”test”

      Input:
      - you can use input. Eg input a or input string$
      - bugs have been removed to some extent but input always displays in the same place on the screen
      - you can also use key(), which is like inkey$ in old basic

      Comment by freescifistories | September 18, 2009 | Reply

  32. Hello Freescifistories
    can i make any questions?

    1. How can i use stx() sty() stt() ??? Are they global or enviroment variable? are function like key()?

    2. while i’m typing code in weebasic on NDS, when code goes ahead on the next line, the red_text_cursor jumps on first location in row and text after this! So typing i get a mistake! what about this?

    3. running this code i have met this result! Is it a bug o a non explained function of PRINT statement?
    code:
    ———————————
    print 1 at 0,5 “ciao”
    gosub aspetta:
    print 1 at 0,6 “Oggi calcoliamo

    il numero del nome”
    gosub aspetta:
    cls 1
    end

    sub aspetta:
    print 1 at 0,20 “premere un tasto per continuare”
    while key()=0
    wend
    return
    ———————–
    on the screen :

    ciao
    Oggi calcoliamo

    il numero del nome

    premere un tasto per continuare
    —————-
    two empty line on the screen as a result of writing two ENTER on software keyboard … fine ;-)

    4. how store data for application? ie qbasic OPEN FILE FOR READ/WRITE or DATA statement?
    Good Job and thank’s for your time

    Comment by BASIC FaN | September 23, 2009 | Reply

    • BASIC FaN:

      1. stt(), stx(), sty() work like key(). See example in comment 16 here: http://freescifistories.wordpress.com/2009/03/18/wee-basic-06-released/#comments

      2+3: I’ll look into these and get back to you.

      4. Not implemented yet

      Comment by freescifistories | September 23, 2009 | Reply

      • hi i’ve tested stt() stx() sty(), fine!
        here a utility sample code to see stilo X Y on touchscreen
        and it should be useful to get position and to measure about object created on the touchscreen

        cls 1
        keyhide
        let a=0
        let b=0
        let c=0
        let d=0

        print 1 at 0,3 “tocca il touchscreen”
        print 1 at 0,20 “premi B per terminare”

        while a203

        let a=key()
        let b=stx()
        let c=sty()
        let d=stt()

        print 1 at 0,7 “x= “+ b + “y= ” + c + ” d= ” + d + ” ”

        wend
        end

        Comment by BASIC FaN | September 30, 2009

      • Very helpful code. Thanks.

        Comment by freescifistories | September 30, 2009

  33. hi
    here is a little fun example utility:
    ASCII.txt to show ascii code in soft keyboard and NDS buttons

    ——————–
    cls 1
    print 1 at 0,1 “Ciao premi i tasti per vedere il codice ASCII qui sotto”
    print 1 at 0,20 “Premere A per terminare”

    let a=0
    while a202
    let a=key()
    if a0 print 1 at 5,5 a + ” ”
    endif
    wend
    end
    ——————
    Bye Bye :-)

    Comment by BASIC FaN | September 23, 2009 | Reply

    • good one

      Comment by freescifistories | September 23, 2009 | Reply

  34. Hi, I see you’ve been busy. Summer has just ended here, so back to the keyboard for me. The last version of weebasic didn’t work on my M3. Seemed to just hang early after start up. Can’t remember the details. I’ll try 0.81.

    Comment by s54boc | September 27, 2009 | Reply

    • Good to hear from you again s54boc. It’s odd that you couldn’t get the previous version to run. Let me know if you have any problems with this one.

      Comment by freescifistories | September 28, 2009 | Reply

      • I got this one to run. My BASIC programs are under /TXT or /DATA, so I couldn’t load them with the new interface. I used to save my programs like /TXT/prog1.txt. So have not yet exercised the new version. Maybe I can move them using my txtwriter.nds instead of using the PC. Working on an unrelated little DS project of my own right now. Will share when ready.

        Comment by s54boc | September 28, 2009

      • Sounds exciting. Can’t wait to hear.

        Comment by freescifistories | September 28, 2009

  35. hi freescifistories
    I’m enjoing with wee basic …
    what about statement MOTION and MOTX MOTY?

    have you a section for free example code to submit?

    have you thinked about an option to run sample code like QBASIC /RUN using file batch (.bat) linecommand?

    or any option to do this?

    thank’s for your time…

    PS webpage doesn’t post “” caracters

    Comment by BASIC FaN | September 30, 2009 | Reply

    • At this stage, it’s great if you just post example code in the comments here. I can include them in the manual on the next update. On the batch file, do you mean on a windows machine or on the ds? I am working on something for windows.

      Comment by freescifistories | September 30, 2009 | Reply

      • hi
        I’m thinking about NDS, so a good code can be used as an application simply loading it like it happens for .NDS files …so somebody can use it without disrupt code file in some ways…

        ok weewindows is great and at beginning… I’ll wait improvements..

        sorry what is statement MOTION and MOTX MOTY ? How can i use it?

        PS your webposting doesn’t accept disequal (not equal) charaters ie this ”

        Comment by BASIC FaN | September 30, 2009

      • I understand – a runtime for the NDS so you don’t have to open the editor so the basic file runs automatically. I’m working on it.

        For Motion, you need a motion card (r5?). Then you could do something like this:

        rem enable motion*
        motion
        lab start:
        print 1 “motion x=”+motx
        print 1 “motion y=”+moty
        goto start:
        end

        As you move the ds from side to side, motx and moty should change in value.

        About ‘”‘ – this is a wordpress limitation.

        Comment by freescifistories | October 1, 2009

  36. Hi freescifistories
    look at this WEEBASIC code
    an example showing text columns and text row on screen 1
    (high screen) and screen 0 (touchscreen):

    _____________________________
    rem conta le righe e le colonne dello schermo
    *

    keyhide
    cls 1
    cls 0
    let a = 0
    let b = 0
    for a = 0 to 31
    print 1 at a,0 “0″
    print 0 at a,0 “0″
    next

    gosub pausa:

    for b = 0 to 23
    print 1 at 0,b b
    print 0 at 0,b b
    next

    gosub pausa:

    let a=0
    let b=0

    for b=0 to 23
    let a=a+1
    print 1 at a,b b
    print 0 at a,b b

    next

    gosub pausa:
    end

    sub pausa:
    print 1 at 15,5 “premere un tasto”
    print 0 at 15,5 “premere un tasto”

    while key()=0
    wend
    return
    _________________

    just a question
    while i cancel by backspace virtual keyboard I get sometimes that weebasic hangs… only two black screen

    oops just another question
    is customible heypad in touchscreen?
    for example is it possible to show only digit or characters?

    Bye and thank for your time

    PS about “” (not equal) characters in code at them position I’ll put NOT EQUAL words in capelock!

    Comment by BASIC FaN | October 8, 2009 | Reply

    • Good stuff! Not sure why wee basic hangs with backspace – will have to look into it. Unfortunately you can’t customize the keyboard.

      Comment by freescifistories | October 8, 2009 | Reply

  37. hello Freescifistories
    waiting your debugging of backspace hanging here is a fine raw code to paint by pencil on touchscreen
    ——————–
    cls 1

    keyhide

    let a=0
    let b=0
    let c=0
    let d=0

    print 1 at 0,3 “tocca il touchscreen e trascina la stilo”

    print 1 at 0,20 “premi B per terminare”

    print 1 at 0,17 “cambia colore con i tasti SU GIU del pad”

    let d=2

    while a203

    let a=key()

    let b=stx()
    let c=sty()
    if a=206
    let d=d+1
    elseif a=207
    let d=d-1
    endif

    if d>16
    let d=16
    elseif d<1
    let d=1
    endif

    print 1 at 0,7 "x=" + b + " y=" + c + " d=" + d +" "

    plot 0 b,c,d
    wend

    end
    —————————-
    :-)

    PS are there statements like QBASIC ASCII(car$) CHR$(num%) LEN(string$) line x,y,x1,y1,color,B/BF (make square/square full) PLAY(music_string$) CIRCLE x,y,color

    Comment by BASIC FaN | October 9, 2009 | Reply

  38. hello Freescifistories
    sorry here another code example about graphic screen fulling
    ————
    cls 1
    print 1 at 0,4 “altezza screen 192 pixel”
    print 1 at 0,8 “larghezza screen 255 pixel”

    gosub aspetta:

    let a = 0
    let b = 0
    for a = 0 to 191
    for b = 0 to 255
    plot 1 b,a,4
    next
    next
    print 1 at 0,12 ” coloro schermo intero”

    end

    sub aspetta:
    let z =0

    while z203
    z = key()
    wend
    return
    ——————
    thank’s for your time

    Comment by BASIC FaN | October 9, 2009 | Reply

    • Wow Basic Fan – keep going. I’m impressed!!

      Comment by freescifistories | October 9, 2009 | Reply

  39. hello frescifistories
    I’m often stopped by warning error in weebasic that bring me far to real code error…ie in IF ENDIF embeded statement there is no control couple IF…ENDIF and weebasic report error line far from real bug code…

    otherwise writeing code by stilo on touchscreen isn’t so fun and comfortable… there is no copy_cut_paste routine for code text… so much work for you, to improve your creature.

    bye and thank’s for spending your time

    Comment by BASIC FaN | October 17, 2009 | Reply

  40. hi freescifistories
    see output of this code please:

    ————————————————–

    rem prova statement grafici in weebasic 0.81 *

    keyhide
    let a = 0
    for a = 0 to 256
    line 0 a,0,a,198,4
    line 1 a,0,a,198,4
    next

    rem this second linecode put out a strange behaviour of
    LINE statement (LINE screen x1,y2,x2,y2,color) on screen 1
    changing color value I get a various character output over graphic output for color value 4 is $ (oh oh the shift keyboard code of 4! :-) )
    please try using 3 or 6 as color on screen 1*

    while key()=0
    wend
    cls 0
    rem this line code over doesn’t anything on graphics output… *

    while key() =0
    wend
    cls 1
    rem this line code clear only character on screen 1*

    let b=0
    for b= 0 to 198
    line 0 0,b,256,b,5
    line 1 0,b,256,b,3
    next

    rem in this code there is no problem for output on screen 1*
    end
    ———————————
    thank for spending your time

    Comment by BASIC FaN | October 18, 2009 | Reply

    • Basic Fan, the cls function only clears text characters, not lines/points. If you want to clear lines or points use the colour ‘0′. Eg:

      rem this clears both screens*
      for a = 0 to 256
      line 0 a,0,a,198,0
      line 1 a,0,a,198,0

      Comment by freescifistories | October 19, 2009 | Reply

      • ok I understand
        1) cls is clear text screen… for graphics i must draw black (or my preferred color) on screen

        2) have you got the same strange behaviour of this code?
        ___________
        let a = 0
        for a = 0 to 256
        line 1 a,0,a,198,4
        next
        _________
        ie characters on graphic output?

        bye and thank’s

        Comment by BASIC FaN | October 20, 2009

      • I don’t get any text characters using no$gba.

        Comment by freescifistories | October 20, 2009

  41. Hi freescifistories

    running weebasic interpreter on SD on DSone and on SD R4 I get text over graphics on screen 1 (the other than touchscreen;) that text disappears with cls 1.

    So I don’t get any text characters using no$gba!

    bye and thank’s

    Comment by BASIC FaN | October 22, 2009 | Reply

  42. Hi freescifistories
    do you like text scrolling ? here an example code…
    ________________

    let b$ = “WEEBASIC”
    print 1 at 0,0 “premere un tasto per iniziare”
    while key() =0
    wend

    print 1 at 0,22 “premere un tasto per terminare”
    while key()=0
    let a = 0
    for a = 0 to (31 – 7)
    print 1 at a-1,12 ” “+b$
    let c=0
    for c = 0 to 2000
    next
    next
    let a = 25
    while a > 0
    let a = a-1
    print 1 at a-1,12 b$ + ” ”
    let c=0
    for c = 0 to 2000
    next
    wend
    wend
    end
    ___________________________

    just a question at this time is possible print text with different color than white?
    If yes How?
    thank’s for spending your time

    Comment by BASIC FaN | October 23, 2009 | Reply

    • Good one Basic Fan. Only white at the moment.

      Comment by freescifistories | October 24, 2009 | Reply

  43. Hello freescifistories
    here I can post example code:
    vertical scrolling
    _____________________________
    let b$ = “WEEBASIC”
    let giu = 200
    let su = 100
    let a = 0
    let b = 0

    print 1 at 0,0 “premere un tasto per iniziare”
    while key() =0
    wend
    cls 1
    print 1 at 12,22 “premere un tasto per terminare”
    while key()=0
    if b = giu
    if a >23
    let b = su
    end if
    let a = a +1
    elseif b = su
    if a <0
    let b = giu
    end if
    let a = a-1
    endif

    print 1 at 0,a b$

    let c = 0
    for c = 0 to 2000
    next

    wend
    end
    _________________

    bye bye

    Comment by BASIC FaN | October 26, 2009 | Reply

  44. Sorry for many post:
    can I print extended ascii dos characters? (ie box characters)
    If yes How?

    thank’s for spending your time

    Comment by BASIC FaN | October 29, 2009 | Reply

    • No problem Basic Fan – I like your posts. You can only print what’s on the keyboard.

      Comment by freescifistories | October 29, 2009 | Reply

  45. hi Freescifistories
    I’m moving towards graphic statements…
    sorry it seem a little tutorial on WEE graphic…

    before run following code you must create 4 .GIF files…
    I have used PAINT on windows Vista … but you can use your preferred graphic software saving in .GIF
    How do you ? easy, run PAINT of windows (TM) or some other software and…
    1) two times you take fullfillpaint tool and choosing your preferred colour fill the white paper on PC screen…
    then save this as .GIF on max 256 colours…
    IE 1.GIF 2.GIF (two different colors)
    at this time don’t care about pixel dimensions…
    2)then for the third image.GIF open a fine file image… ie .BMP or JPG or TIF or other format and SAVE AS .GIF
    IE 3.GIF
    3) now you must reduce image dimensions to 256 X 200 pixels
    (in PAINT you must use resize tool setting it on 50%) and save this as your little .gif
    IE 4.GIF
    now after putting these four files on SD root you can run this example code by WEEBASIC 0.81…
    _________________

    rem prova background*
    keyhide
    print 1 at 0,10 “prova sfondo!”
    gosub attesa:
    backgr 1, “1.gif”
    print 1 at 0,12 “testo su sfondo”
    gosub attesa:
    backgr 1, “2.gif”
    gosub attesa:
    cls 1
    gosub attesa:
    backgr 1, “3.gif”
    gosub attesa:
    backgr 1, “4.gif”
    gosub attesa:
    end

    sub attesa:
    BACKGR 0, “1.gif”
    print 0 at 0,12 “premere B per continuare”
    while key()203
    wend
    while key()0
    wend
    return
    _____________________
    you’ll get this…output on screen 1, while touchscreen is help screen
    1) only text on screen 1
    2)the new background don’t overwrite (cancel) text on screen 1
    3) new text overwrite background…but deleting text with CLS statement on screen don’t change background…
    4)using image like photo o some other picture if it is larger 256X200 pixels (X Y screen dimensions) you’ll get only the area filling screen from up left corner…to down and right… the last area is out
    5) using .GIF with 256 colors max and dimensions 256X200
    you’ll get the whole imagine…filling screen

    bye bye

    just a question about createspr…
    in this code above

    gosub attesa:
    backgr 1, “3.gif”

    if I use createspr statement ie

    gosub attesa:
    createspr 1,1, 20,20,77,58,”3.gif”

    I got this error code:
    Error:sprite width/height not available in char position… XXX near [ZZZZZ]

    STATEMENT is
    CREATESPR number, screen, x,y, width, height, filename

    at first time I’ve red on WEEBASIC manual that .gif must have exactly used GIF dimensions … but if I do so… why this error…? ie if 3.gif is 77×58 pixels?
    thank’s for your time

    Comment by BASIC FaN | October 30, 2009 | Reply

    • also your code taken from weebasic manual make this error
      ______createspr 1,1,50,50,32,64,”soldier.gif”
      gosub getkey:
      hflip 1,1
      gosub getkey:
      vflip 1,1
      gosub getkey:
      end

      sub getkey:
      let k=0
      while k=0
      let k=key()
      wend
      return
      _________
      what about this?

      Comment by BASIC FaN | October 30, 2009 | Reply

      • Mixing text and backgrounds can be difficult and is not recommended. You can always create a background with text on it (just use the paint program to create the text).

        Sprite width and height has to be 32×32, 16×16, 8×8, 16×8, 32×8, 32×16, 32×64, 8×16, 8×32, 64×32

        What error did you get with the example code?

        Comment by freescifistories | October 31, 2009

  46. hello freescifistories

    1)
    thank’s for additional info about sprite dimensions… now

    this problem is ok
    ___________________________
    if I use createspr statement ie

    gosub attesa:
    createspr 1,1, 20,20,77,58,”3.gif”

    I got this error code:
    Error:sprite width/height not available in char position… XXX near [ZZZZZ]
    __________________

    2)
    BUT running on no$gba the example code at this webpage
    (b) Creating and flipping a sprite…
    I got this error
    ________
    error: statement expect in char position 31 near [,50,32,64,"soldier.g]
    _________
    PS image soldier.gif is loaded in fcsr!

    WHILE trying on SD R4 it’s all OK!…
    I think it is a problem about no$gba compatibility
    with weebasic.nds because also “char on graphic line” don’t happens on no$gba BUT there is while running on SD R4 e DS DSone on NDS light…

    3) mixing text and backgrounds like in my example code
    gives me more possibilities to code using indipendent graphics and text…
    4) yes it’s fine to use image charactes made by paint or other graphics software..

    thank’s for spending your time…

    only two more question about future development of WEEBASIC
    1) possibility to run in batch WEEBASIC SCRITP…
    2) possibility to manage file, at least text file like .txt
    3) possibility to use more primitive graphics to draw CIRCLE, SQUARE, CLS GRAPHICS
    Bye bye

    Comment by BASIC FaN | November 2, 2009 | Reply

    • Hi – I’m still working on the runtime (like a script) for loading txt files like bat files. With primitive graphics you can use maths to make these with ‘plot’ (eg using pi). CLS graphics is not really required as colour ‘0′ is the same as erase.

      I think there’s a problem with no$gba and FCSR in loading large files. There ends up being some hidden characters at the end of the file which causes the “statement expected” error.

      Keep having fun :)

      Comment by freescifistories | November 3, 2009 | Reply

      • OK i’m waiting for news!
        (in order SCRIPT and then Managing Files)
        If i’ll found more time I post some graphics primitive SUBROUTINE made mixing maths and plot or line…
        but just after some little time…

        Thank’s and bye

        PS: I’m sorry because sometimes my english is very bad (caused by little time and more tired) :-( in spite our communication go on :-)

        Comment by BASIC FaN | November 10, 2009

      • Thanks – I understand you fine.

        Comment by freescifistories | November 11, 2009

  47. In emulator No$gba, after inserting cartridge “WeeBasic.nds”, what have I to do to be able to load and save programs?
    I get “cannot open file” message.

    Comment by Philsan | November 7, 2009 | Reply

    • Philsan, you get that message because no$gba cannot load files without a disk image being attached to the weebasic.nds file. You can use a program called fcsr to do this or you might try desmume emulator instead. I am working on a program that will do this automatically if you can wait a little longer.

      Comment by freescifistories | November 7, 2009 | Reply

      • I am now using Desmume. What have I to do?

        Comment by Philsan | November 7, 2009

      • I think if you put the text file in the same directory as desmume then Wee will be able to load it. Try this and let me know how you go.

        Comment by freescifistories | November 8, 2009

  48. Selecting ‘compact flash’ in the GBA slot and selecting the folder with the .txt file I am able to load and save.
    But when I reset the emulator I lose what I have saved.

    Comment by Philsan | November 8, 2009 | Reply

    • Probably best to wait for my program to be ready.

      Comment by freescifistories | November 11, 2009 | Reply

  49. Hi freescifistories

    waiting news I’m developing a nice software and I fall in “;” trouble….
    using this code afterdown I get “Ok” at 13 rows and “hello” at the first rows… why ???
    if “;” must attach characters in following sequence starting from the last text position why this trouble?

    here weebasic code
    ————————
    dim letter$(5)
    let letter$(1)=”h”
    let letter$(2)=”e”
    let letter$(3)=”l”
    let letter$(4)=”l”
    let letter$(5)=”o”

    rem let’s test ‘;’ with print *
    let e = 0
    print 1 at 0,13 “ok”;
    gosub getkey:

    for e=1 to 5
    print 1 letter$(e);
    next
    gosub getkey:
    end

    rem wait for a key to be pressed *
    sub getkey:
    let k=0
    while k=0
    let k=key()
    wend
    return
    ——————
    Just another question…
    How many characters can I put in a weebasic_string?
    … using DIM striga$(N) N max is 30?
    … and then in Weebasic charset isn’t printable characters with accent…. Must I convert in 2 characters? (ie à become a’)

    bye bye
    and thank’s for spending your time

    Comment by BASIC FaN | November 16, 2009 | Reply

    • Sorry basic fan but ‘;’ doesn’t work with print at, only with print. Dim for string is limited to 30 strings. Each string has 79 characters max.

      Comment by freescifistories | November 16, 2009 | Reply


Leave a comment