| Author |
Message |
|
|
Posted: Sep 22, 2008 - 09:52 PM |
|


Joined: Mar 27, 2002
Posts: 18599
Location: Lund, Sweden
|
|
|
Quote:
I have a problem with the download !
The link is to an index.php file ?!
Thats a known bug in the forum software. The downloaded file is correct, but the suggested name "index.php" is wrong. Just choose to save the file under the correct name and all will be fine. |
|
|
| |
|
|
|
|
|
Posted: Sep 23, 2008 - 04:37 AM |
|

Joined: Sep 22, 2008
Posts: 47
Location: Bothell, WA
|
|
I recompiled for a 'mega128 and have attached that file. The executable expects a 16MHz crystal and talks through USART0 at 38.4K, 8N1. I tested this executable on a BDMicros' Mavric IIB dev board.
I have also attached a short benchmark program so you can get an idea of some of the features of this program. Just do an ASCII text transfer from your comm program; you may need to set a small delay (say, 20 ms) at the end of each line.
Feedback welcome...
klaxon44 |
|
|
| |
|
|
|
|
|
Posted: Sep 23, 2008 - 07:50 PM |
|

Joined: Dec 18, 2001
Posts: 4724
|
|
|
klaxon44 wrote:
I recompiled for a 'mega128 and have attached that file.
Feedback welcome...
klaxon44
have you had time to document the language? Syntax? etc? |
Last edited by stevech on Sep 23, 2008 - 07:54 PM; edited 1 time in total
|
| |
|
|
|
|
|
Posted: Sep 23, 2008 - 07:52 PM |
|

Joined: Oct 07, 2002
Posts: 2027
Location: Denmark
|
|
First thank to Johan about the name problem.
I don't have a mega128, so can I get the numberes at 16MHz, to make some compare of how I would do it
I see that you don't DIM your var. so do you place them like the microsoft basic (just after the program)
or some kind of stack ?
The same for the FOR NEXT do you have a stack ?
And do you semi compile on the fly (so a goto will be a jump, the microsoft basic compare with current line number and then either start here or at the beginning, so a lot of lines gets slow).
And I don't see real strings, they are a real pain to deal with, especially the gabage collection. (on a commodore64, the clean up can take more than 30min if you make a lot of strings 1 char long, then change them to 2char long then 3 long, now we are running out of memory and stall for 30min)(the way to get round is to force it to clean up more often, (for the MS the free() function will do that).
Have fun
Jens |
|
|
| |
|
|
|
|
|
Posted: Sep 23, 2008 - 08:24 PM |
|

Joined: Sep 22, 2008
Posts: 47
Location: Bothell, WA
|
|
stevech and sparrow2,
1. No, I haven't yet had a chance to document the syntax or develop a manual. It's on my list because I know how important it is, but I don't have anything yet.
2. Simple variables do not (yet) need to be DIMed, though I will probably add an EXPLICIT command so you can decide whether you must DIM them before use. Arrays must be DIMed before use. All variables are kept in a separate pool of RAM. Use the FREE command to see how much RAM you have available and where it has been assigned.
3. GOTOs and GOSUBs are compiled to pcode + target line number. I'm not happy with this, because the line number search takes place repeatedly during execution. I will fix this and some other foundational issues as time permits.
4. String variables are not supported, though obviously printed constant strings are supported. Additionally, the INPUT statement accepts a quoted string for use as a prompt.
Do these questions mean that some of you have been able to get the .hex file to run?
klaxon44 |
|
|
| |
|
|
|
|
|
Posted: Sep 24, 2008 - 10:58 PM |
|

Joined: Oct 07, 2002
Posts: 2027
Location: Denmark
|
|
I can't test it because I don't have a 1280.
And that will be a problem for your BASIC, it needs to be able to fit in a mega8 or so.
I don't see it as a problem with only 1K of RAM. I remember the ZX80 with 1K RAM and 4K ROM.
And if no need for speed the code can come from a EEprom(like a BASIC stamp).(that was why I started with the AVR emulator so a tiny AVR could run a big program, the emulater take only about 2K flash(depending of how fast it needs to be))
If you want I can help with a ASM version, but as a C freak I asume that isn't want you want
Jens |
|
|
| |
|
|
|
|
|
Posted: Sep 24, 2008 - 11:09 PM |
|

Joined: Oct 07, 2002
Posts: 2027
Location: Denmark
|
|
If you need something for demo where the PC allways is connected you could make the basic run on the PC, and just have a fast RS232(or USB) to the AVR. The AVR then only need a robot program, evt with a automated timer interrupt etc. for the real time events.
Jens |
|
|
| |
|
|
|
|
|
Posted: Sep 25, 2008 - 07:54 AM |
|

Joined: Aug 24, 2006
Posts: 89
|
|
Great piece of software! I loaded the mega128 hex file on a 16 Mhz ET-AVR stamp board (from Futurlec) and it runs flawlessly (once I had the usual serial port issues resolved).
Downloading text files using Brey's terminal or Hyperterminal doesn't work very well though (buffer overrun probably), unless someone can point out a "delay after each line" option. So I copied the test program using several "paste to host" operations. Works great, here are the results:
Empty loops per second, uptime comparison: 4474
Empty loops per second, timer0: 5130
Time to execute 50,000 empty loops: 1088
Time to execute 50,000 additions: 5603
Time to execute 50,000 multiplies: 5769
Time to execute 50,000 divisions: 7482
Is there any way to edit lines (as opposed to retyping)?
I see that the original Basic11 has keywords like PORTA, PORTB, APOKE etc. Could you summarize the avr/machine level interfaces?
I live in Kirkland WA myself. With sparrow2, klaxon4 and jrseattle all close by, we could start a local AVR freaks chapter Of course zbaird is invited too.
jrseattle
www.oscilloscopeclock.com |
|
|
| |
|
|
|
|
|
Posted: Sep 25, 2008 - 08:50 AM |
|


Joined: Mar 28, 2001
Posts: 20400
Location: Sydney, Australia (Gum trees, Koalas and Kangaroos, No Edelweiss)
|
|
How exciting!! Got it running on one of may boards fitted with the M128.
http://www.members.optusnet.com.au/~amp ... 20diag.gif
I only wish I had some time to play with BASIC, it would bring back lots of memories, at least 4K worth
I have the Basic11 manual and the .arc file for version 1.55. Had to install arc with winzip to extract it, how quaint!!
I should also have the whole source file somewhere as a have a js version of the .s19 file.
Now what do I do with it?  |
_________________ John Samperi
Ampertronics Pty. Ltd.
www.ampertronics.com.au
* Electronic Design * Custom Products * Contract Assembly
|
| |
|
|
|
|
|
Posted: Sep 25, 2008 - 04:25 PM |
|

Joined: Dec 18, 2001
Posts: 4724
|
|
10 X = 1234
20 GOSUB 1400
déjà vu ! ! |
|
|
| |
|
|
|
|
|
Posted: Sep 25, 2008 - 06:02 PM |
|

Joined: Aug 24, 2006
Posts: 89
|
|
Found one potential problem. I used the "autost fl0" command to automatically start a program on reboot, which worked great. Then I turned the unit off overnight and the autostart did not work this morning. The program was still saved in fl0 so I did another "autost fl0" to get it to autostart again.
Unclear why the previous autostart was lost.
jrseattle
www.oscilloscopeclock.com |
|
|
| |
|
|
|
|
|
Posted: Sep 25, 2008 - 10:19 PM |
|

Joined: Oct 07, 2002
Posts: 2027
Location: Denmark
|
|
So a short estimate give about 4000 clk for a empty loop.
semi compiled (where consts is handled as var)
will give something like this
10 x=x+1
could be handled as
stack addr x
stack addr x
stack addr 1
+
=
this should take about 100 clk with subrutine calls.
(the call/ret will be about 50% of the clk's)
20 if x<>1000 then 10 "in MS both then and goto would work"
would take about 50 clk.
so an empty loop would take 150 clk or be about 25 times faster if it's written in ASM. |
|
|
| |
|
|
|
|
|
Posted: Sep 26, 2008 - 04:29 AM |
|

Joined: Dec 18, 2001
Posts: 4724
|
|
I flashed to a mega128 ETT stamp, 16MHz. UART0 is at 38.4Kbaud
Using Bray's Terminal, I could not upload the benchmark test program. I slowed down the upload to like 5 chars per second. I think there are line feeds in the file and the Interpreter does not want them. I could't find a way to prevent line feeds using the editors I have (several). The interpreter should/could ignore them.
Clue: If I change my terminal program so that when I type CR it sends CRLF, I get the same error when typing manually. That error is ERROR #7: Illegal variable
So I typed in part of the benchmark program and it ran fine.
here's another ditty
100 n = uptime/1000
110 if uptime/1000 = n then 110
120 ?uptime
130 goto 100 |
|
|
| |
|
|
|
|
|
Posted: Sep 26, 2008 - 05:26 PM |
|

Joined: Sep 22, 2008
Posts: 47
Location: Bothell, WA
|
|
1. There is no way to edit a line short of retyping. I have given thought to adding an ANSI terminal interface, which would allow cool things like source-level debugging, in-line editing, and suchlike. I don't think the overhead would be very much, either; mabye a few K.
2. Sounds like sending a trailing LF might be an issue; I will double-check to make sure that gets stripped out.
3. sparrow2, I agree that if this compiled down to assembly language, it would run about 10x faster and 10x smaller. I purposely chose to do a pcode interpreter rather than a full compiler. One of my reasons was I didn't want to create yet another machine-specific compiler. I may one day do a true target-based Basic compiler, but for now I'm having fun with the interpreter.
4. For the atmega128, you have direct access to all GPIO ports and registers, all A/D-based registers, and all SPI registers. For example, you can write a byte to the SPI with: 130 spdr = $44
and you can read a byte from the SPI with: 140 mydata = spdr
Note that I used the same names as WinAVR uses in their ioxxx.h files. I do not provide names for accessing bits, though.
5. When I use Hyperterm to send my source text into th e target, I include a 5 or 10 msec delay after each line but no delay between characters; works fine for me.
6. jrseattle, not sure why you would lose the autostart from flash following powercycle. Next time you powercycle, enter: autost
at the prompt and see if it says fl0 was marked for autostart. If it wasn't, something is corrupting your EEPROM on power-down or power-up. Let me know what you find out.
7. js, now that you have it running, you can do anything you want with it!
Actually, I intend to provide support for PWM and servos soon, so robotics is right around the corner.
8. jrseattle, sparrow2, and others,
Yes, it would be fun to have a Puget Sound AVR gathering. If you guys want to hook up for pizza and geek-talk some evening, let me know.
So many features to add, so little time...
klaxon44 |
|
|
| |
|
|
|
|
|
Posted: Sep 26, 2008 - 05:29 PM |
|

Joined: Sep 22, 2008
Posts: 47
Location: Bothell, WA
|
|
1. There is no way to edit a line short of retyping. I have given thought to adding an ANSI terminal interface, which would allow cool things like source-level debugging, in-line editing, and suchlike. I don't think the overhead would be very much, either; mabye a few K.
2. Sounds like sending a trailing LF might be an issue; I will double-check to make sure that gets stripped out.
3. sparrow2, I agree that if this compiled down to assembly language, it would run about 10x faster and 10x smaller. I purposely chose to do a pcode interpreter rather than a full compiler. One of my reasons was I didn't want to create yet another machine-specific compiler. I may one day do a true target-based Basic compiler, but for now I'm having fun with the interpreter.
4. For the atmega128, you have direct access to all GPIO ports and registers, all A/D-based registers, and all SPI registers. For example, you can write a byte to the SPI with: 130 spdr = $44
and you can read a byte from the SPI with: 140 mydata = spdr
Note that I used the same names as WinAVR uses in their ioxxx.h files. I do not provide names for accessing bits, though.
5. When I use Hyperterm to send my source text into th e target, I include a 5 or 10 msec delay after each line but no delay between characters; works fine for me.
6. jrseattle, not sure why you would lose the autostart from flash following powercycle. Next time you powercycle, enter: autost
at the prompt and see if it says fl0 was marked for autostart. If it wasn't, something is corrupting your EEPROM on power-down or power-up. Let me know what you find out.
7. js, now that you have it running, you can do anything you want with it!
Actually, I intend to provide support for PWM and servos soon, so robotics is right around the corner.
8. jrseattle, sparrow2, and others,
Yes, it would be fun to have a Puget Sound AVR gathering. If you guys want to hook up for pizza and geek-talk some evening, let me know.
So many features to add, so little time...
klaxon44 |
|
|
| |
|
|
|
|
|
Posted: Sep 26, 2008 - 05:33 PM |
|

Joined: Sep 22, 2008
Posts: 47
Location: Bothell, WA
|
|
Oops, sorry for the double-post!
sparrow2, I reread your post and realized my reply wasn't actually on-target; sorry about that. I'll try again.
I borrowed Gordon Doughman's original 'hc11 design for the interpreter. His design has some excellent features that I wanted to preserve, one of which is that his interpreter can recover the original source line intact, complete with all embedded spaces. The design you promote is much faster and smaller, but is one-way. I had compelling reasons to go with Gordon's design, but I certainly considered what you were proposing. Thanks for the comment!
klaxon44 |
|
|
| |
|
|
|
|
|
Posted: Sep 26, 2008 - 07:15 PM |
|

Joined: Oct 07, 2002
Posts: 2027
Location: Denmark
|
|
For some reason I had missed that you use a specific BASIC I was thinking that you was making your own.(I will read the manual but I'm at work now).
Now I see why you need more RAM
To speed it up you can do like the spectrum BASIC, store both (1000 is stored as 1000 and $03E8 you just don't see it).
Are there any way I can run this from the simulator?
In the 80's you could buy a 8052 with BASIC in the ROM (I don't think they made it for the CMOS). Maybe some ideas from there could help.
You could make a token for 2 spaces 3...... (or a token that take a byte for the number of spaces.(I asume you want this for indentation).
Jens
Edit: so does this BASIC run a true ASCII text or is it just stored so you can make a 100% correct LIST?
make it a 8052 |
|
|
| |
|
|
|
|
|
Posted: Sep 26, 2008 - 11:13 PM |
|

Joined: Sep 22, 2008
Posts: 47
Location: Bothell, WA
|
|
|
sparrow2 wrote:
For some reason I had missed that you use a specific BASIC I was thinking that you was making your own.(I will read the manual but I'm at work now).
Now I see why you need more RAM
To speed it up you can do like the spectrum BASIC, store both (1000 is stored as 1000 and $03E8 you just don't see it).
Are there any way I can run this from the simulator?
In the 80's you could buy a 8052 with BASIC in the ROM (I don't think they made it for the CMOS). Maybe some ideas from there could help.
You could make a token for 2 spaces 3...... (or a token that take a byte for the number of spaces.(I asume you want this for indentation).
Jens
Edit: so does this BASIC run a true ASCII text or is it just stored so you can make a 100% correct LIST?
make it a 8052
Actually, this is my own Basic. It is based on Gordon Doughman's BASIC11, but it is all my own code. I translated Gordon's 68hc11 assembly language source into ANSI C, then compiled the C for Windows and also for the AVR.
How the interpreter stores each source line of your program internally was already mapped out by Gordon and I haven't changed it (much). Gordon's internal storage scheme makes it easy to convert back and forth between ASCII text and the corresponding pcodes. Keeping the flexibility, however, means that the pcode scheme isn't quite as efficient as it might be. Still, I want the user (typically a newbie) to be able to see the source faithfully reproduced with a LIST command, so I kept Gordon's scheme.
klaxon44 |
|
|
| |
|
|
|
|
|
Posted: Sep 27, 2008 - 12:39 AM |
|

Joined: Dec 18, 2001
Posts: 4724
|
|
here's some of the keywords/command words from the original. Maybe it would be easy to edit this and delete those that are N/A and those that are omitted, etc.
Code:
"LIST"
"RUN"
"NEW"
"CONT"
"CLEAR"
"ESAVE"
"ELOAD"
"LLIST"
"AUTOST"
"NOAUTO"
"FREE"
"DATA" xdata();
"LET" xlet();
"READ" xread();
"RESTORE" xrestore();
"GOSUB" xgosub();
"GOTO" xgoto();
"ON" xon();
"RETURN" xreturn();
"IF" xif();
"INPUT" xinput();
"PRINT" xprint();
"FOR" xfor();
"NEXT" xnext();
"STOP" xstop();
"ENDWH" xendwh();
"END" xend();
"REM" xrem();
*/*"SWAP" xswap();*/
"TRON" xtron();
"TROFF" xtroff();
"WHILE" xwhile();
TOKTBL: EQU *
FCB LETTOK
FDB LET
FCB READTOK
FDB READ
FCB RESTRTOK
FDB RESTORE
FCB GOSUBTOK
FDB GOSUB
FCB GOTOTOK
FDB GOTO
FCB ONTOK
FDB ON
FCB RETNTOK
FDB RETURN
FCB IFTOK
FDB IIF
FCB THENTOK
FDB THENS
FCB ELSETOK
FDB ELSES
FCB INPUTTOK
FDB INPUT
FCB PRINTTOK
FDB PRINT
FCB FORTOK
FDB FOR
FCB NEXTTOK
FDB NEXT
FCB STOPTOK
FDB STOPSS
FCB ENDTOK
FDB ENDS
FCB TRONTOK
FDB TRON
FCB TROFFTOK
FDB TROFF
FCB WHILETOK
FDB WHILE
FCB ENDWHTOK
FDB ENDWH
FCB STEPTOK
FDB STEP
FCB TOTOK
FDB TO
FCB COMMATOK
FDB COMMAC
FCB SEMITOK
FDB SEMIC
FCB MEOLTOK
FDB COLLINC
FCB IMLETTOK
FDB IMLET
FCB POKETOK
FDB POKE
FCB EQUALTOK
FDB EQ
FCB OPARNTOK
FDB OPARN
FCB CPARNTOK
FDB CPARN
FCB ANDTOK
FDB ANDS
FCB ORTOK
FDB ORS
FCB EORTOK
FDB EORS
FCB LTTOK
FDB LT
FCB GTTOK
FDB GT
FCB LTEQTOK
FDB LTEQ
FCB GTEQTOK
FDB GTEQ
FCB EQTOK
FDB EQ
FCB NOTEQTOK
FDB NOTEQ
FCB PLUSTOK
FDB PLUS
FCB MINUSTOK
FDB MINUS
FCB MULTTOK
FDB MULT
FCB DIVTOK
FDB DIV
FCB MODTOK
FDB MODS
FCB NOTTOK
FDB NOTS
FCB RTIMETOK
FDB RTIMES
FCB NEGTOK
FDB NEGS
FCB SSCNTOK
FDB SPACE
FCB DIMTOK
FDB DIM
FCB EEPTOK
FDB EEP
FCB PORTATOK
FDB PORTA
FCB PORTBTOK
FDB PORTB
FCB PORTCTOK
FDB PORTC
FCB PORTDTOK
FDB PORTD
FCB PNUMTOK
FDB POUNDSGN
FCB INBYTTOK
FDB INBYTES
FCB TIMETOK
FDB TIME
FCB ONTIMTOK
FDB ONTIME
FCB ONIRQTOK
FDB ONIRQ
FCB RETITOK
FDB RETI
FCB PACCTOK
FDB PACC
FCB ONPACTOK
FDB ONPACC
FCB SLEEPTOK
FDB SLEEP
LFUNCTBL: EQU *
FCB FDIVTOK
FDB FDIVS
FCB CHRTOK
FDB CHRS
FCB ADCTOK
FDB ADCS
FCB ABSTOK
FDB ABS
FCB RNDTOK
FDB RND
FCB SGNTOK
FDB SGN
FCB TABTOK
FDB TABS
FCB CALLTOK
FDB CALL
FCB PEEKTOK
FDB PEEK
FCB FEEPTOK
FDB EEP
FCB HEXTOK
FDB HEX
FCB FPRTATOK
FDB PORTA
FCB FPRTBTOK
FDB PORTB
FCB FPRTCTOK
FDB PORTC
FCB FPRTDTOK
FDB PORTD
FCB FPRTETOK
FDB PORTE
FCB FTIMETOK
FDB TIME
FCB HEX2TOK
FDB HEX2
FCB FPACCTOK
FDB PACC
|
|
|
| |
|
|
|
|
|
Posted: Sep 27, 2008 - 08:21 PM |
|

Joined: Sep 22, 2008
Posts: 47
Location: Bothell, WA
|
|
From the above list, KLBasic supports the following commands:
LIST
RUN
NEW
CONT
AUTOST (but with changes, see below)
FREE
NOAUTO has been replaced; AUTOST now supports the following variations:
AUTOST show state of autostart
AUTOST OFF autostart disabled
AUTOST EE autostart program in EEPROM
AUTOST FL0 autostart program in flash file 0
AUTOST FL1 autostart program in flash file 1
AUTOST FL2 autostart program in flash file 2
ESAVE and ELOAD replaced by LOAD and SAVE.
SAVE has the following arguments:
SAVE EE save program to EEPROM
SAVE FL0 save program to flash file 0
SAVE FL1 save program to flash file 0
SAVE FL2 save program to flash file 2
LOAD has following arguments:
LOAD EE load program from EEPROM
LOAD FL0 load program from flash file 0
LOAD FL1 load program from flash file 1
LOAD FL2 load program from flash file 2
KLBasic supports the following functions and statements:
DATA
LET (implied)
READ
RESTORE
GOSUB
GOTO
RETURN
IF
INPUT (with optional quoted prompt string)
PRINT (also supports ? as quick-print)
FOR
NEXT
STOP
WHILE
ENDWH
REM (also supports ' as a remark char)
TRON
TROFF
END
: (separates to statements in same line)
AND
OR
NOT
XOR
MOD
+, -, *, /
<, >, =, <>, <=, >=
DIM (declares size of arrays)
RND(N) returns random 32-bit int <N
RND(0) reseeds random number generator
This should get you going...
klaxon44 |
|
|
| |
|
|
|
|
|