Saturday 4 October 2014

Converting from MC-10 to Coco and Dragon

=====>

Part of the difficulty I have in porting programs from the MC-10 to Coco and Dragon is that Coco and Dragon Basic needs spaces in certain places that the slightly later rendition of Microsoft Basic used on the MC-10 does not require. Specifically:
ONNGOTO100 must become ONN__GOTO100
FORA=BTOCSTEPD must become FORC=A__TOB__STEPC
IFA=BTHEN must become IFA=B__THEN
IFA=BANDC=D must become IFA=B__ANDC=D
IFA=BORC=D must become IFA=B__ORC=D
PRINTATAB(10)B must become PRINTA__TAB(10)

An important programming technique for getting speed in my games for the MC-10 is to remove ALL spaces and to stick to single letter variables.This is fine on the MC-10.It requires absolutely no spaces anywhere. Every space just wastes tiny increments of time. I have some macros in MSWord now that help me with some of these replacements, but not all.I also have macros for changing the directly entered graphic strings to CHR$ equivalents, but there is always cleanup and unforeseen complications...

In terms of the key polling routine I have to change this for the MC-10:
20 ONK(PEEK(2)ANDPEEK(17023))GOSUB2,3,4,7

to this for the COCO:
14 ONK(PEEK(135))GOSUB2,3,4,7:RETURN
20 POKE345,255:POKE344,255:POKE343,255:POKE342,255:POKE341,255:POKE340,255:IF(PEEK(345)ANDPEEK(344)ANDPEEK(343)ANDPEEK(342)ANDPEEK(341)ANDPEEK(340))<>255THENGOSUB14

and this for the DRAGON:
14 ONK(PEEK(135))GOSUB2,3,4,7:RETURN
20 IF(PEEK(345)ANDPEEK(344)ANDPEEK(343)ANDPEEK(342)ANDPEEK(341)ANDPEEK(340))<>255THENGOSUB14

The multiple pokes in the Coco routine are for the benefit of CocoBs, which have a slightly different way of handling the rollover table that does not reset it. The Coco1 and Coco3 don't need such pokes, but it is too difficult to be bothered having multiple versions and they're not bothered by the pokes. The Dragon, however, is bothered, so I have to take all the pokes out for it. I also have to change the values of the K array to those of the arrow keys on the COCO/DRAGON rather than the codes for ASWZ.

MC-10 "Arrow" DiamondCoco Arrow Keys ASCII ValuesCoco Rollover Table peek
A=65
 LeftArrow=8
 343
W=87
 Up Arrow=94
 341
S=83
 Right Arrow=9
 344
Z=90
 Down Arrow=10
 342
SPACE=32
 Space=32
 345

Any special peeks or pokes must also be converted. Such as those which provide the current cursor location of the MC-10 17024 and 17025 (136 and 137 for the Coco), which I use quite a bit.

POKE49151,64 (MC-10) must be switched for SCREEN0,1 (Coco). The MC-10 uses a special CLOAD*A,"FILENAME" command to store numeric arrays to tape (in this case array A). This has to be replaced with the following code for a Coco with a disk drive:
6800 GOSUB10003:PRINT"SAVING":OPEN "O", #1,"DATA/DAT":FORC1=0TO150:WRITE #1,A(C1):NEXT:CLOSE#1:GOSUB10001
6840 GOSUB10003:PRINT"LOADING":OPEN "I", #1, "DATA/DAT":FORC1=0TO150:INPUT#1,A(C1):NEXT:CLOSE#1:GOSUB10001

or this code for a DRAGON using tape:
6800 GOSUB10003:PRINT"SAVING":OPEN "O", #-1,"DATA":FORC1=0TO150:PRINT #-1,A(C1):NEXT:CLOSE#-1:GOSUB10001
6840 GOSUB10003:PRINT"LOADING":OPEN "I", #-1, "DATA":FORC1=0TO150:INPUT #-1,A(C1):NEXT:CLOSE#-1:GOSUB10001

Finally, I usually include Zephr's nifty speedkey and speedup poke sensing subroutine for the Dragon and Coco
10000 IF PEEK(65535)=27 THEN DS$="Y":GOTO10001 ELSE CLS:INPUT"CAN YOUR COMPUTER HANDLE DOUBLE SPEED (Y/N)";DS$:IFLEFT$(DS$,1)<>"N"ANDLEFT$(DS$,1)<>"Y"THEN10000
10001 IF LEFT$(DS$,1)="Y" THEN IFPEEK(65535)=27 THEN POKE65497,0 ELSE POKE65495,0 
10002 RETURN
10003 IF PEEK(65535)=27 THEN POKE65496,0 ELSE POKE65494,0
10004 RETURN
10005 ' ENABLE DRAGON SPEEDKEY
10006 IF PEEK(65535)<>180 THEN 10008
10007 IF PEEK(269)+PEEK(270)<>1 THEN POKE65283,52:POKE256,116:POKE257,1:POKE258,81:POKE259,126:POKE260,PEEK(269):POKE 261,PEEK(270):POKE269,1:POKE270,0:POKE65283,53
10008 RETURN
10009 ' DISABLE DRAGON SPEEDKEY
10010 IF PEEK(65535)<>180 THEN 10012
10011 IF PEEK(269)+PEEK(270)=1 THEN POKE65283,52:POKE269,PEEK(260):POKE270,PEEK(261):POKE65283,53
10012 RETURN

I also change the typical Coco RANDOMIZE function:
R=RND(-TIMER)
to the following on the MC-10
R=RND(-(PEEK(9)*256+PEEK(10)))

Anyway, I am currently working on porting a dozen or so of my latest MC-10 programs to Coco and Dragon, but it is a lot of fiddly tiring work (not as fun as the original programming challenges), so my progress is slow. I've done BIGRED, SWELFOOP, and DICEWARS for the Coco. I'm currently working on Temple of Apshai. Here's what I plan to do:

JGGAMES10.DSK:
BIGRED
SWELFOOP
DICEWARS
SEAWAR
FLAPPY
DIGGER
CRAZY8S
SHUFFLE
GOFISH
HEXAGON
DOTS

JGGAMES11.DSK:
APSHAI

JGGAMES12.DSK:
PIRATE1
CASTADV1
JOURNEY
MORLOCKS
SORCERY
ORIENT
ADVENT1
DRWHO1
PTREAS
ORAN
CHATEAU1
NINJA
PIRATE1
MANTICOR