Monday, February 18, 2008

Is it Basic or is it C? Its SEABASS

Personally, I like to program in C. Luckily, there is pretty good C language support for most modern microprocessors. However, if you don't know C, its a pretty steep learning curve. Sometimes you just want to bang something out quick.

If your processor wants you to use C but you want to use Basic, you might try Seabass. Seabass is a BASIC compiler that outputs C code. So anywhere you can compile a C program (even on Linux or Windows) you can write BASIC programs. Even better, Seabass integrates with existing C libraries and you can even embed C code in your program.

The link shows an entire article about using Seabass to produce some Morse code on an Atmel AVR and a PIC. Here's the first part of the AVR program:

include "avrio.bh"       ` get I/O routines
cinclude "app4delay.h" ` get delay routines (from C)
#link "app4delay.c" ` include C library
` Define a string type
deftype string char *
` Speed of a dot in milliseconds
Const speed=200

The first line includes a basic header file (by convention, these files have a .bh extension). This is a SeaBass file (included on the CDROM) that provides some common I/O routines for the APP-IV (the target board). This line allows us to use things like HIGH and LOW to affect the I/O pins.

The second line includes a C file, not a SeaBass file. This file is one that the APP-IV kit supplies and provides an easy way to write delays. Notice the line just under this tells the compiler where to find the associated C file. If you are manually compiling SeaBass' output, this isn't necessary, but if SeaBass controls the build process, this will allow it to automatically bring in the correct C code that your program needs.

Type names in SeaBass have to be a single word. However, many C types use multiple words (or even symbols). For example, if you want to deal with a string, in C you use a character pointer represented by "char *". The SeaBass DefType statement allows you to make a SeaBass type that represents a complex C type:

` Define a string type
deftype string char *

The final part of the initial part of the program sets a constant using Const. In this case, the speed value is set to 200 (this will be the number of milliseconds to delay for a dot).

Now it is very simple to understand the main code:

` Main program
function main() as int
dim text as string
dim i
text="-.-. --.-" ` message to send
` Set LED to output
OUTPUT(B,0)

The first two lines in the function define variables (notice one of them is a string).

Here's the main loop:

` Main code
top:
for i=0 to strlen(text)-1 ` walk through text
` do the right thing
if text[i]='.' then
dot()
end if
if text[i]='-' then
dash()
end if
if text[i]=' ' then
space()
end if
next

Notice that the program uses the C library call strlen to find the length of the string. Of course, you could write a version of strlen in SeaBass, but since the C compiler already has this function, why not use it?


You can read the whole article or look at an example with an LCD library. You can also play with a demo of Seabass online.

Labels: , ,

Submit to:   book mark Is it Basic or is it C? Its SEABASS in del.icio.usDel.icio.us  |   submit Is it Basic or is it C? Its SEABASS to digg.comDigg  |   submit Is it Basic or is it C? Its SEABASS to slashdot.comSlashdot  |  diigo itDiigo

Thursday, December 20, 2007

Resource Editing for Visual Studio Express

Microsoft provides several "Visual Studio Express" tools for free download. These are slightly limited versions of their popular development tools for C++, C#, and Visual Basic.

I enjoy having these tools for free, and most of the missing features I don't notice. Except for one: resource editing. If you want to add icons or menus to your C++ programs, you'll have to manually munge up an RC file. Or do you?

I went looking for an open source resource editor. Of course, I could just break down and install my real copies of Visual C++ or even break out some other commercial resource editors I have, but I wanted a free solution to go along with the free Visual Studio Express product.

I looked pretty hard and I couldn't find a single tool that did what I wanted. However, I did find two tools that together would do the job.

The first tool is the excellent XN Resource Editor. What doesn't this tool do? It will create menus, icons, dialogs, cursors, and everything else you can think of. Oh yeah, but while it will read RC files, I couldn't find any way to make it save an RC file! It will, however, do a nice job saving to a binary res file.

Of course, you could just leave it at that and let Visual Studio include the .res file. So I guess you can just use one tool. But I wanted an RC file that I could easily manipulate -- at least for strings and IDs.

That's when I downloaded Resource Hacker. This tool is made to load resources from just about anywhere. You can do certain things with those resources (although you can't actually edit them). However, this tool will save a proper RC file.

So the steps are:

1. Use XN Resource Editor to create your resources
2. Save resources as a .RES file
3. Open the .RES file with Resource Hacker
4. Save as a .RC file
5. Add the RC file to your Visual Studio project.

You may have to touch up your RC file a little if you get any errors (for example, include winuser.h).

XN can read an RC file, so you can "round trip" by reading the file from step 4 into XN, making changes, and then repeating steps 2 through 4.

Enjoy!

Labels: ,

Submit to:   book mark Resource Editing for Visual Studio Express in del.icio.usDel.icio.us  |   submit Resource Editing for Visual Studio Express to digg.comDigg  |   submit Resource Editing for Visual Studio Express to slashdot.comSlashdot  |  diigo itDiigo

Tuesday, November 13, 2007

Alternative to Spy++


I used to use the full blown Microsoft developers tools, but lately I've been using the express versions along with some open source development tools. In general, I don't miss much about the Microsoft compiler. But I have to admit that I miss some of the tools.

A few weeks ago, I started getting a mysterious error message on my computer. It was a dialog box complaining about the flash installation. There was no hint of which program was complaining though. I thought about running Spy++ -- the Microsoft utility for looking at on screen Windows -- and realized this computer doesn't have a full load of Visual C++!

What I did find is Winspector. This is like a souped up version of Spy++ and its free. Winspector can show hidden windows or not. It can filter and buffer messages. It can watch messages to a window class from the Window's creation. In short, it does everything Spy++ does plus more.

So, what was the offending program? System47, my Star Trek screen saver. Reinstalling it did the trick. I guess a recent flash upgrade broke it. Should have realized my screen saver wasn't running. If you are a Star Trek fan (or even a science fiction fan) you really ought to download this free screen saver. It is quite the conversation piece.

Labels: , , ,

Submit to:   book mark Alternative to Spy++ in del.icio.usDel.icio.us  |   submit Alternative to Spy++ to digg.comDigg  |   submit Alternative to Spy++ to slashdot.comSlashdot  |  diigo itDiigo

Saturday, February 10, 2007

Web Basic?

If you learned programming on BASIC (I didn't, but I sure slung a lot of TRS-80 BASIC in my day) you might enjoy to see an attempt to have a BASIC resurgence on the Web. Amusing in a way.


Run BASIC

Labels: ,

Submit to:   book mark Web Basic? in del.icio.usDel.icio.us  |   submit Web Basic? to digg.comDigg  |   submit Web Basic? to slashdot.comSlashdot  |  diigo itDiigo