BASIC on the 6502 badge

As if it weren’t nerdy enough, the 6502 40th Anniversary Computer Badge runs Lee Davison’s EhBASIC. There are 1024 whole bytes free for your programs, so it’s not exactly spacious. It’s got useful floating point support, though:

Yup, that’s the second most boring BASIC example program, after the quadratic root finder.

100 REM HERON ROOTS
110 EP=0.0001
120 INPUT "X";X
130 N=1:RN=X/2
140 PRINT"COUNT","ROOT","DELTA":PRINT"======","======","======"
150 DE=ABS(RN*RN-X)
160 PRINT N,RN,DE
170 RN=(RN+X/RN)/2
180 N=N+1
190 IF DE>EP THEN GOTO 150

Update: Josh got my badge working again (it wasn’t, for $reasons …) and I re-ran this code. If you try the code for X=100000 and larger, it won’t converge. You might want to add:

185 IF N>25 THEN PRINT "EPSILON TOO LARGE, EXITING":END

so that the loop will exit after 25 times. Alternatively, make the value of EP depend upon the size of X. Aren’t numerical analysis and floating point foibles fun?

Leave a Reply

Your email address will not be published. Required fields are marked *