 Gyrating cubes in BBC BASIC |
Posted - 6/12/2008 7:29:48 PM | Work has been keeping me busy recently, but I've tried to set aside a small amount of time each evening to reclaim some sanity and do a little work on BBC BASIC. Not much progress has been made, but there has been some at least.

On the left is the program running on an 83+ SE at 15MHz, on the right on the regular 83+ at 6MHz. If you really wanted to do 3D in BBC BASIC you could probably get away with writing some of the more expensive operations — such as transforming/projecting vertices in batches — in assembly, but that would sort of go against the whole point of trying to write a program to test the speed of BASIC. 
Here's the rather naïve code:
10 *REFRESH OFF
20 DIM p%(15)
30 fps%=0
40 lfps%=0
50 fpst%=TIME+100
60 REPEAT
70 rX=TIME/300
80 rY=TIME/400
90 SrX=SIN(rX)
100 CrX=COS(rX)
110 SrY=SIN(rY)
120 CrY=COS(rY)
130 pt%=0
140 FOR x=-1TO1STEP2
150 FOR y=-1TO1STEP2
160 FOR z=-1TO1STEP2
170 tX=y*CrX-x*SrX
180 tY=-x*CrX*SrY-y*SrX*SrY-z*CrY
190 tZ=3-x*CrX*CrY-y*SrX*CrY+z*SrY
200 p%(pt%)=tX*40/tZ+48
210 pt%=pt%+1
220 p%(pt%)=tY*40/tZ+32
230 pt%=pt%+1
240 NEXT
250 NEXT
260 NEXT
270 CLG
280 PRINTTAB(10,0)lfps%" FPS"
290 MOVE p%(0),p%(1)
300 DRAW p%(4),p%(5)
310 DRAW p%(12),p%(13)
320 DRAW p%(8),p%(9)
330 DRAW p%(0),p%(1)
340 DRAW p%(2),p%(3)
350 DRAW p%(6),p%(7)
360 DRAW p%(14),p%(15)
370 DRAW p%(10),p%(11)
380 DRAW p%(2),p%(3)
390 MOVE p%(4),p%(5)
400 DRAW p%(6),p%(7)
410 MOVE p%(12),p%(13)
420 DRAW p%(14),p%(15)
430 MOVE p%(8),p%(9)
440 DRAW p%(10),p%(11)
450 *REFRESH
460 fps%=fps%+1
470 IF TIME>fpst% THEN lfps%=fps%:fps%=0:fpst%=TIME+100
480 UNTIL INKEY(0)<>-1
490 *REFRESH ON
500 END
I have also added support for the COLOUR statement (for changing the text foreground and background colour) and copy key editing.

Copy key editing, as demonstrated in the screenshot on the right, lets you break the text input cursor into two parts - a write cursor (which is left behind on the line you were editing) and a read cursor, which can be positioned anywhere on the screen. Pressing the copy key (in this case, XTθn) reads a character under the read cursor and writes it to the write cursor, then increments both.
One feature that's a bit more fun is the support of device files. This is a way of accessing external devices as if they were files. For example, by opening the file AT.DEV you can read and write bytes using the AT protocol (used by AT and PS/2 keyboards and mice) using BBC BASIC's built-in file manipulation routines.

You could use this to do something useful, or could just use this to flash the LED on a keyboard back and forth.
10 keyb%=OPENOUT"AT.DEV"
20 DATA 2,4,1,4,-1 : REM LED flash pattern (-1 terminated).
30 REPEAT
40 READ l%
50 REPEAT
60 PROC_setled(l%)
70 PROC_pause(30)
80 READ l%
90 UNTIL l%=-1
100 RESTORE
110 UNTIL FALSE
120 END
130 :
140 DEF PROC_flushin
150 REPEAT
160 IF EXT#keyb% d%=BGET#keyb%
170 UNTIL NOT EXT#keyb%
180 ENDPROC
190 :
200 DEF PROC_setled(l%)
210 BPUT#keyb%,&ED
220 PROC_flushin
230 BPUT#keyb%,l%
240 PROC_flushin
250 ENDPROC
260 :
270 DEF PROC_pause(t%)
280 start%=TIME
290 REPEAT UNTIL TIME >= start%+t%
300 ENDPROC
| |
Comments
 |  ManTis
Member since: 8/27/2004 From: Warszawa, Warszawa |
Posted - 6/13/2008 8:13:18 AM | I remember trying to make a cube appear in QBASIC on my AT long long time ago. It's funny to see the code running faster on a calculator. Then again, AT was only 12 mhz, wasn't it?
| |
|
| S | M | T | W | T | F | S | | | | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | | |
OPTIONS
Track this Journal
ARCHIVES
August, 2010
July, 2010
June, 2010
April, 2010
March, 2010
February, 2010
January, 2010
December, 2009
November, 2009
October, 2009
August, 2009
June, 2009
May, 2009
March, 2009
February, 2009
January, 2009
December, 2008
November, 2008
October, 2008
September, 2008
August, 2008
July, 2008
June, 2008
May, 2008
April, 2008
March, 2008
February, 2008
November, 2007
October, 2007
September, 2007
August, 2007
July, 2007
May, 2007
April, 2007
February, 2007
January, 2007
December, 2006
November, 2006
October, 2006
September, 2006
August, 2006
July, 2006
June, 2006
May, 2006
April, 2006
March, 2006
February, 2006
January, 2006
December, 2005
November, 2005
October, 2005
September, 2005
August, 2005
April, 2005
February, 2005
January, 2005
|