1. SF is by far the best pic compiler that I have ever used.
2. Refer to point 1
With reference to point 1, I have the PBP compiler, PDS, Basic18, Hi Tech C and a couple of others and Swordfish so far is the only one that is a proper modern modular basic.
The only other compiler that is as much a pleasure to use is Power Basic for windows, and that doesn't support pics.
PDS is fantastic for any pic that isn't an 18F and is my second choice now.
PicForth is really cool if you like an environment that allows native compilation on the target device at run time, which can have its uses, especially when debugging hardware real time. Beats the pants off simulators and ICD thingies.
I digress, there are only a couple of things that annoy me a little and most of these are easily fixed with function/sub wrappers and aliases.
Some curious choices in the lexicon, for example using the word 'length' to return the length of a string, standard basic syntax is len(astring).
Anyway that is pretty minor, it just means that I have to be a little careful testing code in PowerBasic before cutting and pasting it directly into SF.
It is the first time that I have been able to directly cut and paste from PB into a pic compiler and have it work 90% of the time without any changes.
I am truly impressed.
I could go on, but time doesn't permit.
To make sense of the subject of this post, why isn't there a SrtToFloat in the convert.bas module.
FloattoStr lives in there and it seems inconsistent not to have StrtoFloat. I have found a solution of course but it isn't very elegant.
I have to teach my Zenbot to plot vector fonts now, so I had better finish up.
Just another small digression, I had a lot of fun converting the bresenham line drawing algorithm to SF Basic and a couple of hours afterwards it occurred to me that SF and the Pic are so fast that it might have been a complete waste of time. I can simply use y=mx+b with float variables and an 80 line sub will shrink to about 10 lines.
For those that are interested.
Code: Select all
' Lineblock is defined as the following struct
Structure Quad
X1 As Integer
Y1 As Integer
X2 As Integer
Y2 As Integer
End Structure
dim lineblock as quad
Sub Drawline()
Dim Diagyinc,diagxinc,shortdistance,straightxinc,straightyinc,straightcount,diagcount As Integer
Dim ax,bx,Cx,dx,di,si As Integer
With LineBlock
DiagYInc = 0 'clear some variables
DiagXInc = 0
ShortDistance = 0
StraightXinc = 0
StraightYinc = 0
StraightCount = 0
DiagCount = 0
Cx = 1 'initial increments for x-axis
DX = 1 'initial increments for y-axis
DI = Y2 - Y1 'DI holds distance on y-axis
If DI < 0 Then 'go ahead if positive slope
DX = -1 'y-axis increment is -1
DI = abs(DI) 'make DI positive
End If
DiagYInc = DX 'save Diagonal Y Increment
SI = X2 - X1 'SI holds distance on x-axis
If SI < 0 Then 'go ahead if positive slope
Cx = -1 'x-axis increment is -1
SI = abs(SI) 'make SI positive
EndIf
DiagXInc = Cx 'save Diagonal X Increment
'determine if straight segments of line are horizontal or vertical
If SI > DI Then 'is x-distance greater than y-distance
DX = 0 'if not the we have vertical segments
Else
Cx = 0 'no x-axis change during segments
Swap(DI,SI) 'swap SI and DI
EndIf
ShortDistance = DI 'DI contains short distance
StraightXinc = Cx 'save Straight X Increment
StraightYinc = DX 'save Straight Y Increment
AX = DI * 2 'double short distance
StraightCount = AX 'save for straight loop
BX = AX - SI 'save for loop counter
AX = AX - 2 * SI 'AX = 2 * DI - 2 * SI
DiagCount = AX 'save it for loop
Cx = X1 'starting x coordinate
DX = Y1 'starting y coordinate
Inc(SI,1) 'increase long axis by 1 for endpoint
While SI > 0
Dec(SI,1) 'decrement counter for long distance
Destination.Xpos = Cx
Destination.Ypos = DX
DoMove ' or plot(x'y) or whatever takes your fancy
If SI > 0 Then 'are we done with long axis yet
If BX < 0 Then
Inc(Cx,StraightXinc) 'add increments for straight segment
Inc(DX,StraightYinc)
Inc(BX,StraightCount) 'add to adjustment factor
Else
Inc(Cx,DiagXInc) 'add increments for diagonal segments
Inc(DX,DiagYInc)
Inc(BX,DiagCount) 'subtract from adjustment factor
EndIf
EndIf
Wend
End With
End Sub
If you are looking for ways to do stuff in basic with integer math (for speed etc) get hold of a copy of ethan winers PDQ and his various DOS basic products. They come with source code and it is dead easy to convert them to SF.
I have found them to be an invaluable reference for graphic stuff, menus and such for LCD use. Not to mention that it is all tightly coded and well commented.