[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Thanks...now a New problem...
In article <1me4kcINN9k9@master.cs.rose-hulman.edu> julichjh@NeXTwork.Rose-Hulman.Edu (Joseph H Julicher) writes:
>
> I am trying to read the A/D converter on the DOC....
> is the following code workable??????
I presume the 'c' characters in your asm function are actually '#'
characters? (e.g. sep c0x20 should be sep #0x20) I've corrected
them as such. Pretty weird data corruption, if you ask me!
>
> #include <stdio.h>
> asm int getAD(void)
> {
> sep #0x20 /* Short accumulator */
> loop1:
> lda >0xC03C /* Get sound control (forced long addressing mode) */
> bpl DOCready /* loop until DOC is ready */
> jmp loop1
>
> DOCready:
> and #0xBF /* make sure I am reading DOC data */
> sta >0xC03C /* rewrite sound countrol */
> lda #0xE1 /* as auto increment is on.. second read will be the A/D */
> sta >0xC03E /* store $E1 in sound address pointer */
> /* should allow A/D register to be read on the second pass */
> lda >0xC03D /* read the audio data */
> lda >0xC03D /* reads lag by a read cycle so I read again */
[the above two lines came through as 'lda >0xC3D', so I've corrected them]
> rep #0x20 /* Long accumulator */
> rtl /* Return with sample in A */
> }
The above code will not work as an in-line function, because the ORCA/C
inline assembler doesn't know about 8-bit immediate mode for the
accumulator and index registers. Your 'and #0xBF' instruction will
actually generate a 16-bit operand, which will result in a BRK when the
code is executed.
The sep and rep instructions are handled correctly, but LDA, etc. aren't.
You have to perform all immediate-mode operations in 16 bits, turn
this into an external assembly language function (written with
ORCA/M), or use some other addressing mode to get the 8-bit constants.
For example, you could set up a local (direct page) variable with the
appropriate constants.
Other than that, the function should work fine, except that you will
end up with a random value in the high-order byte of the accumulator.
After doing the final REP #0x20, do an AND #0x00FF, to make sure the
high byte of the accumulator is zero.
--
David Empson
Internet: David.Empson@bbs.actrix.gen.nz EMPSON_D@kosmos.wcc.govt.nz
Snail mail: P.O. Box 27-103, Wellington, New Zealand