Re: [cc65] How to prototype an assembler function?

From: Marc 'BlackJack Rintsch <marc1rintsch.de>
Date: 2010-04-25 12:09:44
On Sunday 25 April 2010, Payton Byrd wrote:
> Success!!!  Thank you so much for your help.  I was able to get it
> working with the following assembler code

I think pushing the accu to the C stack is not necessary just like most 
``ldx #0``\s.  That's automatically generated code from a not so smart 
compiler.  You could use the X register to save the accu instead of the 
C stack.  Untested:

.proc _writeVdcRegister
	tax
	ldy #0
	lda (sp),y
	sta $d600
	stx $d601
	jmp incsp1

and for reading the C stack does not to be hit at all:

.proc _readVdcRegister
	sta $d600
loop:	bit $d600
	bpl loop
	lda $d601
	ldx #0
	rts

The return value of the read function is a 16 bit value in A/X (lo/hi).  
The C standard says all interediate calculations have to be at least in 
the value range of the `int` type, so that's possibly why the compiler 
adds all the ``ldx #0``\s because `int`\s are held in A/X in the 
compiler generated code.

Writing code can be one byte shorter if you reverse the arguments, 
because the accu can be written to $d600 right away and does not have 
to be saved in the X register.

Ciao,
	Marc 'BlackJack' Rintsch
-- 
“A mind once stretched by a new idea never regains
 its original dimension.”
        --Oliver Wendell Holmes

----------------------------------------------------------------------
To unsubscribe from the list send mail to majordomo@musoftware.de with
the string "unsubscribe cc65" in the body(!) of the mail.
Received on Sun Apr 25 12:06:56 2010

This archive was generated by hypermail 2.1.8 : 2010-04-25 12:06:58 CEST