NEWCLS

Playing around with some ideas…

COLOR BASIC SOURCE

The inner loop of the CLS command

* CLEAR SCREEN
LA928	LDB	#$60	BLANK
	LDX	#VIDRAM	GET ADDR OF START OF SCREEN BUFFER
LA92D	STX	CURPOS	SAVE IT IN CURPOS
LA92F	STB	,X+	FILL SCREEN WITH CONTENTS OF ACCB
	CMPX	#VIDRAM+511	END OF SCREEN?
	BLS	LA92F	NO
	RTS

A NEW CLS

The part of of the CLS code that I was poking at runs from A928 to A936 - the core loop that uses the main cycles to clear the screen.

By my Slightly Suspect™ math, it takes 512 loops of 11 cycles each to clear the low-res text screen using the B register, for a total of around 5632 cycles.

However, if you use the D register, and step X by two, you could cut the looping in half, with only a cycle or two more used in each loop pass… for a total of around 3072 cycles, almost cutting the count in half.

>>> cat newcls.s                                                                                                                                       
CURPOS	EQU	$88		; CURSOR POSITION HELD BY COLOR BASIC
VIDRAM	EQU	$0400		; START OF VIDEO RAM

	ORG	$7F00		; PICK A RAM ADDRESS
NEWCLS	PSHS	D,X,CC		; SAVE MODIFIED REGISTERS ONTO STACK
	LDD	#$6060		; LOAD BLANK CHARACTER IN A AND B
	LDX	#VIDRAM		; START ADDRESS OF VIDEO TEXT RAM
	STX	CURPOS		; SET CURSOR POSITION BACK TO HOME
CLRTWO	STD	,X++		; CLEAR TWO BYTES AT X AND INCREMENT X+2
	CMPX	#VIDRAM+511	; HAVE WE REACHED THE LAST ADDRESSES?
	BLS	CLRTWO		; NOT DONE YET, GO TO NEXT
	PULS	D,X,CC,PC	; CLEAN UP REGISTERS FROM STACK AND RETURN

>>> lwasm -l -o newcls.bin -b -m newcls.s
                              0088             (         newcls.s):00001         CURPOS  EQU     $88             ; CURSOR POSITION HELD BY COLOR BASIC
     0400             (         newcls.s):00002         VIDRAM  EQU     $0400           ; START OF VIDEO RAM
                      (         newcls.s):00003         
                      (         newcls.s):00004                 ORG     $7F00           ; PICK A RAM ADDRESS
7F00 3417             (         newcls.s):00005         NEWCLS  PSHS    D,X,CC          ; SAVE MODIFIED REGISTERS ONTO STACK
7F02 CC6060           (         newcls.s):00006                 LDD     #$6060          ; LOAD BLANK CHARACTER IN A AND B
7F05 8E0400           (         newcls.s):00007                 LDX     #VIDRAM         ; START ADDRESS OF VIDEO TEXT RAM
7F08 9F88             (         newcls.s):00008                 STX     CURPOS          ; SET CURSOR POSITION BACK TO HOME
7F0A ED81             (         newcls.s):00009         CLRTWO  STD     ,X++            ; CLEAR TWO BYTES AT X AND INCREMENT X+2
7F0C 8C05FF           (         newcls.s):00010                 CMPX    #VIDRAM+511     ; HAVE WE REACHED THE LAST ADDRESSES?
7F0F 23F9             (         newcls.s):00011                 BLS     CLRTWO          ; NOT DONE YET, GO TO NEXT
7F11 3597             (         newcls.s):00012                 PULS    D,X,CC,PC       ; CLEAN UP REGISTERS FROM STACK AND RETURN
Symbol: CLRTWO (newcls.bin) = 7F0A
Symbol: CURPOS (newcls.bin) = 0088
Symbol: NEWCLS (newcls.bin) = 7F00
Symbol: VIDRAM (newcls.bin) = 0400
                                 
>>> perl -e 'print chr(255) x (35*18*256)' > newcls.dsk

>>> writecocofile newcls.dsk newcls.bin

Once you load it into a CoCo:

CLEAR 256,32512
LOADM"NEWCLS.BIN"
EXEC32512

ADDITIONAL THOUGHTS

The replacement loop takes ~4 bytes more than the existing loop in Color BASIC.

These bytes could be recovered by scavenging additional bytes from the code taken by the Microsoft CLS Easter egg.

Also, my code does not allow you to jump into the middle due to the change from RTS to PSHS/PULS, which is how the background color change works … it jumps into the CLS code after the LDB #$60 green blank character.

Thinking about that, it should be possible to use one of the few zero page addresses as a BCKCLR location, and have it seeded with $6060 or let you push a different character there… beyond just the full color blocks.

RTS

This website uses cookies. By using the website, you agree with storing cookies on your computer. Also you acknowledge that you have read and understand our Privacy Policy. If you do not agree leave the website.More information about cookies