[Coco] running BASIC in RAM (was "Coco Questions")

William Astle lost at l-w.ca
Sun Oct 29 10:59:58 EST 2006

Aaron Banerjee wrote:
> I'm not sure how useful this would be, but just in case there were silent
> lurkers hoping someone would post a short quip to put your coco in all ram
> mode (with BASIC running...).  I've added comments showing what (I hope)
> is the assembly version of the driver.
>                         - Aaron
> 5  DATA 26,80:REM                 ORCC   $50     MASK INTERRUPTS
> 10 DATA 142,128,0:REM             LDX    $8000   START OF BASIC
> 15 DATA 166,132:REM       LINE15  LDA    ,X
> 20 DATA 183,255,233:REM           STA    $FFDF   MAP TYPE 1
> 25 DATA 167,128:REM               STA    ,X+
> 30 DATA 183,255,222:REM           STA    $FFDE   GO BACK TO REGULAR MEM
> 35 DATA 140,255,0:REM             CMPX   $FF00   END OF RAM
> 40 DATA 38,241:REM                BNE    LINE15
> 45 DATA 183,255,223:REM           STA    $FFDF   STAY IN ALL RAM MODE
> 50 DATA 28,175:REM                ANDCC  $AF     UNMASK INTERRUPTS
> 55 DATA 57:REM                           RTS     RETURN
> 65 FOR X=3584 TO 3609
> 70 READ D
> 75 POKE X,D
> 80 NEXT X
> 85 EXEC 3584

The assembly code is not quite right. You've left off the "immediate 
mode" indicators. The code should be:

	ORCC #$50
	LDX #$8000
	STA ,X+
	CMPX #$FF00

There is a siginficant difference between $8000 and #$8000. The former 
refers to the *contents* at $8000 and the latter refers to the literal 
constant $8000. Also, the original code would not have assembled since 
ORCC and ANDCC operate only in immediate mode.

As has been noted, this should not be run on a Coco3. But, since the 
Coco3 is already in all RAM mode, it's also not necessary. There's a 
simple test to see if you're already in RAM mode:

10 A=PEEK(&H8000)
20 POKE&H8000,A+1
30 IF A=PEEK(&H8000) THEN GOSUB 1000 ELSE POKE &H8000,A
40 REM program here

990 END
1000 REM go to all ram mode here

For the above, the reasoning is that because the first two bytes of ECB 
are just a signature that's used at basic startup time, changing one of 
them cannot cause a crash. By reading the original value, adding one to 
it, and storing it back, we can test if the we have ROM. If it is ROM, 
we get back the original value otherwise we get back the new value.

The above test will also prevent the ROM/RAM copy on a Coco3 because it 
is already in RAM mode.

Observation: the basic code to test for ram mode can be added to the 
start of the assembly code as follows:

	LDA $8000
	INC $8000
	CMPA $8000
	STA $8000

Both versions of the test restore the original value at $8000 if RAM 
mode is discovered.

William Astle
finger lost at l-w.ca for further information

Geek Code V3.12: GCS/M/S d- s+:+ !a C++ UL++++$ P++ L+++ !E W++ !N w---
!D !M PS PE V-- Y+ PGP t+@ 5++ X !R tv+@ b+++@ !DI D? G e++ h+ y?

More information about the Coco mailing list