[Coco] Newbie help: Barden Bubble w/ Portal-9
Robert Gault
robert.gault at worldnet.att.net
Mon Jan 26 07:13:16 EST 2004
jimcox at miba51.com wrote:
> Hi all:
>
> I entered the code below into a new file in Portal-9, set the file to be
> assembled as a single file, and the type of system to CoCo2 and MESS
> came up, but nothing runs. Any pointers?
>
> 00100 * BUBBLE SORT
> 00110 BUBSRT CLR PASSNO SET PASS # TO 0
> 00120 BUB010 LDX #$400 POINT TO SCREEN
> 00130 LDY #0 SET CHANGEFLAG TO 0
> 00140 BUB020 LDA ,X+ GET FIRST ENTRY
> 00150 CMPA ,X TEST NEXT
> 00160 BLS BUB030 GO IF A<=B
> 00170 LDB ,X GET SECOND ENTRY
> 00180 STB -1,X SWAP B TO A
> 00190 STA ,X SWAP A TO B
> 00200 LDY #1 SET "CHANGE"
> 00210 BUB030 CMPX #$400+511 TEST FOR SCREEN END
> 00220 BNE BUB020 GO IF NOT ONE PASS
> 00230 INC PASSNO INCREMENT PASS #
> 00240 CMPY #0 TEST CHANGE FLAG
> 00250 BNE BUB010 GO IF CHANGE OCCURRED
> 00260 LOOP JMP LOOP LOOP HERE
> 00270 PASSNO FCB 0 PASS #
> 00280 END
>
> I think it's something really stupid on my part.
>
> Jim
>
Jim, this is something that I mentioned when this example was first
posted. You need to know what a Coco will do when it sees an ml program
and is told to execute it.
Basic programs load to a default address in memory from which they can
safely be run. ML programs do not have a default load address and they
can't be safely run anywhere in memory.
Basic has a command that reserves memory for ml programs, CLEAR. The
syntax is CLEAR n,h where n is the string workspace size and h is the
start of memory reserved for machine language programs up to $7FFF.
Once you learn more about the Coco's memory usage, you will see that
CLEAR is just a starting point. There are several areas of memory that
are usually safe for ml program use without explicitly reserving them.
Back to your sort program. Since the source code contains no ORG
(origin) address, the program will load at $0000. This will crash Basic
every time. You MUST either do an offset load to a safe (ie. free )
block of memory or include an ORG statement in the source.
Since the source code does not contain an explicit starting address,
even if you did an offset load Basic would execute address $0000 and
crash. Either the source code or the loading procedure must indicate
where execution should start.
You can use the EDTASM+ (and I think CCASM) syntax by adding as the
first statement
ORG $7000
which is typically a good spot for a program. Then change the END
statement to read
END BUBSRT
which will tell EDTASM+ to attach a header and trailer to the program
that tells Basic to load the program at $7000 and execute starting at
$7000. Then the program will run with
LOADM"SORT":EXEC
If you don't want to change the program or your editor/compiler does not
attach the header/trailer, the syntax for running such a program must be
LOADM "SORT",&H7000:EXEC&H7000; pick your own address.
Once the program has been compiled, it is possible to add the headers if
you know the length of the program. The syntax would be
LOADM "SORT",&H7000:SAVEM "SORT",&H7000,&Hnnmm,&H7000
where nnmm is known to be the end of the program.
All of this information and more is contained within the "Color Computer
Disk System Owners Manual & Programming Guide" by Tandy.
More information about the Coco
mailing list