critical BASIC 7.0

Started by hydrophilic, January 27, 2007, 11:22 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

hydrophilic

BASIC on the C128 has a lot of pros and cons compared to other Commies and other programming langauges.

The biggest con, IMHO, is at 1MHz it is much slower than the same program running on say, a C64.  This is due to the all the bank switching that is neccessary and also because BASIC 7.0 uses a software stack for variables in loops.

On the plus side, the best feature is the very flexible DO...LOOP.  With it you can do things 'more advanced' languages (Visual Basic, C++ to name a few) make very clumsy.  For example, on the C128 you can write something like:

DO WHILE N > 0
...something usefull
LOOP UNTIL Y > 199

Most other langauges allow a condition only at the begining or at the end, but not both.  Leading to ugly code like:

DO
IF NOT (N > 0) THEN EXIT
...something usefull
LOOP UNTIL Y > 199

So it can be done in other languages, but is not as 'friendly'.

What features do you think are particularly good or bad in C128 BASIC ?

airship

I think flow control is one of the least understood topics in BASIC programming. You see FOR...NEXT loops all over the place when another looping structure is often much, much better.

As a refresher, here are the flow control commands in BASIC 7.0:

BEGIN...BEND
Used if you have a block of code that should be executed if a specified condition is met, but skipped if it is not.

DO...LOOP...WHILE...UNTIL...EXIT
A very flexible set of conditions for complex loops, as Hydrophilic so helpfully asserts above.

FOR...TO...STEP...NEXT
One of the two that everyone knows about and abuses terribly. Though you don't often see the very useful STEP.

IF...THEN...ELSE
The number one abused looping structure. Utilitarian, but sometimes like using a screwdriver as a hammer.

ON...GOTO/GOSUB
You see lots of GOSUBs, but not many ON conditionals. ON combines nicely with FOR...NEXT supplying the counter.

READ...DATA...RESTORE[liNE#]
Not a flow control command, but RESTORE, especially to a line#, is a powerful and much-underused command.

TRAP...RESUME
Who does error trapping? Anyone? Anyone? Bueller?

STOP...CONT
Have your program STOP. Look at all the variable values. Change variable values based on your human judgement. CONT. Nice during development. See TRAP above.

SYS...(RTS)
You use this one if you write any ML.

WAIT
Use your hardware! Fantastic with the CIAs.
Serving up content-free posts on the Interwebs since 1983.
History of INFO Magazine

hydrophilic

Nice post Airship.  I think you only missed one:

COLLISION type, line#

This is about as close to interrupt processing as most BASIC programmers would care to deal with.  It works like GOSUB when a certain VIC event occurs.  You can catch sprite-sprite and sprite-foreground collsions.  You can also catch light-pen latching too.  When the routine is called, use BUMP(x) to test which sprite(s) have collided or PEN(n) to read the latched coordinate.  Use a standard RETURN to resume normal program operation.  Each event type can be assigned a different line number.  Very useful in connection with MOVSPR.

I think TRAP...RESUME would be more useful if it could trap disk errors.  These are probably the most common / unpredictable and realy need the TRAP ability.  Maybe you could use it to reduce code size (eliminate a bunch of IF checks)?  Or you could use it like a poor man's TRY-CATCH:


100 TRAP 200 : REM START TRY BLOCK
... horribly complex code ...
190 RETURN : REM END TRY BLOCK
200 REM CATCH
... show an error message ?
270 IF BAIL RESUME 190 : REM GIVE UP
280 RESUME 100 : REM TRY AGAIN
290 REM END CATCH

RobertB

Quote from: hydrophilic on January 27, 2007, 11:22 AM
The biggest con, IMHO, is at 1MHz it is much slower than the same program running on say, a C64.  This is due to the all the bank switching that is neccessary and also because BASIC 7.0 uses a software stack for variables in loops.
Somewhat off-topic, Basic 7.0 can be installed into the Commodore Plus/4, thus using that machine's abilities.

             Truly,
             Robert Bernardo
             Fresno Commodore User Group
             http://videocam.net.au/fcug
             The Other Group of Amigoids
             http://www.calweb.com/~rabel1/

hydrophilic

Wow, that's pretty cool!  I'm assuming you just replace the stupid application ROMs?  I wonder what it does to the memory map since 7.0 has a hord of new internal variables... I'm also guessing SPRITE (etc) are not implemented/emulated.  Anyway, makes me want a Plus/4 again... almost... those non-standard connectors annoy me.

RobertB

Quote from: hydrophilic on September 08, 2008, 11:35 AM
Wow, that's pretty cool!  I'm assuming you just replace the stupid application ROMs?
You can grab the binary file or ROM file from

                   http://www.cbm264.com/misc/basic7.html

                          Truly,
                          Robert Bernardo
                          Fresno Commodore User Group
                          http://videocam.net.au/fcug
                          The Other Group of Amigoids
                          http://www.calweb.com/~rabel1/

airship

I did not know that anyone had translated the BASIC 7's ROMs for the Plus/4. How does it work with the TED chip???
Serving up content-free posts on the Interwebs since 1983.
History of INFO Magazine

hydrophilic

OMG!  It doesn't replace 3-plus-1, it works with it!  And it appears to emulate sprites!  And it adds a bunch of new commands!  This is more like BASIC 7.5 or 8.5.  I just downloaded it and will have to check it out.  Thanks Robert!