Page 1 of 1
Cbasic
Posted: Wed Jul 22, 2020 5:23 pm
by Milli
I’ve been tinkering with cbasic under cpm. It creates some nice code and it’s relocatable. I believe with a header file I can create a ColecoVision game using cbasic. It won’t be able to use the I/O commands (print, input) or the file commands since these rely on CPM but the rest should be usable and you can access CV ROM routines via the call command.
Re: Cbasic
Posted: Sat Jul 25, 2020 8:31 am
by Milli
I'm actually using CB80 which was an upgraded version of CBasic. I have upload a zip file with the compiler, linker and the manuals to the archive at:
http://adamarchive.org/archive/CPM/CB80.zip
I have yet to determine how to add assembly language routines to it but so far I really like the way it works. Here is a sample of a game I am working on that is in CB80
Code: Select all
randomize
dim board$(21)
ESC$ = chr$(27)
CLS$ = chr$(26)
CLEOL$ = chr$(24)
BKS$ = chr$(8)
GOR$ = chr$(12)
HOME$ = chr$(30)
DMODE$ = chr$(2)
BMODE$ = chr$(1)
SPINNER% = 1
width% = 80
x% = 15
y% = 11
ox% = -1
oy% = -1
def FN.CENTER(a$)
w% = int(width% - len(a$)) / 2
while w%
print GOR$;
w% = w% - 1
wend
print a$;
FN.CENTER = 0
fend
def FN.SPINNER
print BKS$;mid$("\|/-",SPINNER%,1);
SPINNER% = SPINNER% + 1
if SPINNER% = 5 then SPINNER% = 1
FN.SPINNER = 0
fend
gosub ShowTitle
gosub NewBoard
print CLS$;
Loop:
gosub UpdatePlayer
gosub ShowBoard
gosub GetMove
if key$ = "Q" then stop
if key$ = "U" then y% = y% - 1
if key$ = "D" then y% = y% + 1
if key$ = "L" then x% = x% - 1
if key$ = "R" then x% = x% + 1
goto Loop
ShowBoard:
REM Home screen and display board
print HOME$;DMODE$;
null% = FN.CENTER("+-----------------------------+")
print ""
for r%=1 to 21
null% = FN.CENTER("|"+board$(r%)+"|")
print ""
next r%
null% = FN.CENTER("+-----------------------------+")
print ""
return
NewBoard:
REM Create a new board
print CLS$;"Creating board ";
for r%=1 to 21
board$(r%) = ""
for c%=1 to 29
board$(r%) = board$(r%) + chr$(48 + int(rnd * 7) + 2)
next c%
null% = FN.SPINNER
next r%
print ""
return
ShowTitle:
REM Title screen and instructions
print CLS$:print:print:print
null% = FN.CENTER("Greed")
print:print:print
null% = FN.CENTER("Press any key to begin...")
gosub WaitKey
return
MoveCursor:
REM Move cursor to x%,y%
print ESC$;"=";chr$(32 + y%);chr$(32 + x% + (width% / 4));BMODE$;"@";
return
WaitKey:
REM Wait for a key and return it in key$. Also modifies the RND seed
null% = rnd * 4
if constat% = 0 then goto WaitKey
key$ = chr$(inkey)
return
UpdatePlayer:
REM Update player in the board
if ox% <> -1 then \
board$(oy%) = left$(board$(oy%),ox% - 1)+ " " + mid$(board$(oy%),ox% + 1,40)
ox% = x%
oy% = y%
board$(y%) = left$(board$(y%),x% - 1)+ "@" + mid$(board$(y%),x% + 1,40)
return
GetMove:
REM Determine possible moves and get players input returned in key$
pos$ = ""
if y% > 1 and mid$(board$(y% - 1),x%,1) <> " " then pos$ = pos$ + "U,"
if y% < 21 and mid$(board$(y% + 1),x%,1) <> " " then pos$ = pos$ + "D,"
if x% > 1 and mid$(board$(y%),x% - 1,1) <> " " then pos$ = pos$ + "L,"
if x% < 29 and mid$(board$(y%),x% + 1,1) <> " " then pos$ = pos$ + "R,"
pos$ = pos$ + "Q"
print CLEOL$;pos$;" ? ";
GetMoveLoop:
gosub WaitKey
key$ = ucase$(key$)
if match(key$,pos$,1) <> 0 and key$ <> "," then print key$:return
goto GetMoveLoop
Re: Cbasic
Posted: Sun Jul 26, 2020 7:17 am
by joltguy
Very nice code! Really clean and well structured which is not something that can be said about a lot of BASIC programs.
It is pretty cool to have a compiler for BASIC. Thanks for uploading it to the archive... I've downloaded and imported it into CP/M (using wrdisk + ADAM.COM) so I can mess around with it later.
Re: Cbasic
Posted: Tue Jul 28, 2020 9:46 am
by Wmaalouli
Nice. I have never really messed with compiled Basic under CP/M since I had Turbo Pascal at may disposal.
I would be cool to see if you can get it to access the graphic and sound resources of the Adam.
My main beef with the Adam SmartBasic and variants is that it relies heavily on pokes and peeks to do anything interesting, which in my view makes the code difficult to read as well as write.
Re: Cbasic
Posted: Tue Jul 28, 2020 9:21 pm
by Milli
Wmaalouli wrote: ↑Tue Jul 28, 2020 9:46 am
Nice. I have never really messed with compiled Basic under CP/M since I had Turbo Pascal at may disposal.
I would be cool to see if you can get it to access the graphic and sound resources of the Adam.
My main beef with the Adam SmartBasic and variants is that it relies heavily on pokes and peeks to do anything interesting, which in my view makes the code difficult to read as well as write.
You should do it
Re: Cbasic
Posted: Wed Jul 29, 2020 8:32 am
by Wmaalouli
Hah! It might be an interesting challenge, but I have way too much on my plate currently to even consider it. That said, if there is a way to embed machine language in CBASIC, then it should be relatively trivial to add the extensions since the routines already exist with my TP3 extensions.
Can CBASIC use external modules?
Re: Cbasic
Posted: Thu Jul 30, 2020 6:58 am
by Milli
Wmaalouli wrote: ↑Wed Jul 29, 2020 8:32 am
Hah! It might be an interesting challenge, but I have way too much on my plate currently to even consider it. That said, if there is a way to embed machine language in CBASIC, then it should be relatively trivial to add the extensions since the routines already exist with my TP3 extensions.
Can CBASIC use external modules?
Yes it can use REL files. I have yet to figure it out. It doesn't have a CALL or USR function that lets you jump to an ML address. From what I can determine when you compile a module to an REL file it somehow knows labels and then you can use the CALL function to jump to the code. It is confusing.