Re: [stella] An exercise in minimalism...

Subject: Re: [stella] An exercise in minimalism...
From: Mark De Smet <desmet@xxxxxxxxxxxx>
Date: Thu, 2 Sep 1999 00:08:02 -0500 (CDT)
> > > LDY #$FF ;2
> > > LDX #0 ;2
> > >B1      STX 0,Y ;2
> > > DEY ;1
> > > BNE B1 ;2
> >
> > You could change the first two lines of this to LDX #0 and TXY to save one
> > byte.  It'll still work.
> 
> Yes it will, but not with exactly the same result;  the original doesn't
> clear address 0 (it clears 255 bytes of zero page).  Your method will clear
> address 0, clearing all of zero page, which is more correct anyway :)

Well, not really more correct.  Address 0 would be clearing VSYNC.  This
doesn't need to be done during initialization b/c it is done later.  I
wouldn't do it in a normal program, because it could confuse the TV
alittle to get 2 VSYNC's in such a short time.  But as Erik points out,
here it can be used to save a byte, which is the goal.

> I don't have the original email handy, but I hope somewhere there the stack
> pointer was setup!!

No it was not.  There was no point in doing so, as that requires more
code, and the stack is never used in the code.(no jsr's, etc)

> I dug up my earlier posting regarding an efficient startup.
> Here's my best...
>
>
>     ; CLEARS ALL VARIABLES, STACK
>     ; INIT STACK POINTER
>     ; ALSO CLEARS TIA REGISTERS
>     ; DOES THIS BY "WRAPPING" THE STACK - UNUSUAL
>
>     LDX #0
>     TXS         
>     PHA            ; BEST WAY TO GET SP=$FF, X=0

Wow! that's interesting, I never would have thought of that.  And I guess
it doesn't really matter that the stack starts out 'incorrect' because you
just do that first 'push' onto the VSYNC, which doesn't really matter...

>     TXA
> CLEAR PHA
>     DEX
>     BNE CLEAR
>
>     ; 9 BYTES TOTAL FOR CLEARING STACK, MEMORY
>     ; STACK POINTER NOW $FF, A=X==0

Wow, and because PHA is only one byte, it is more efficient than doing the
index addressing STA/STX as I used.  novel use of the push operation...

Here, I don't need the stack, so I should be able to remove that.  Your
code manages to setup the stack as well in the same 9 bytes I used to just
clear the TIA.

How about this, assumeing that you don't need the stack:

	LDY #0		;2
	TYA	 	;1 ;a-la Erik's suggestion,
clear
	PHA		;1 ;a-la Andrew's suggestion,
	DEY		;1
	BNE clear	;2

Oh, boy, that's good.  Down to 7 bytes.  Quite an improvement from my 9.
And I think this should work because, although I have not setup the stack
pointer, it will loop all the way around, and to all 256 bytes, is this
correct?

Mark




--
Archives (includes files) at http://www.biglist.com/lists/stella/archives/
Unsub & more at http://www.biglist.com/lists/stella/

Current Thread