case on
mcopy /usr/local/ainclude/m16.smartstacks
root start
end
* void PutBits(Word bits, Word cnt, Bool sane)
*
* puts the bits into a buffer.
* Bits will be reversed unless sane is set
*
* cnt MUST be <= 9 or this routine will fail
* (since workByte is 16 bits)
PutBits start
DefineStack
FixStack
BegParms
bits Word
cnt Word
sane Word
EndParms
BeginStack
* swap the bits if insane
* if cnt = 0 | bits == 0 don't worry.
* we swap by shifting bits right,
* then rotating the carry bit left into the accumulator.
*
lda sane
bne normal
ldy cnt
beq exit
lda bits
beq normal
lda #0
reverse anop
lsr 7, flush it.
* could potentially be 16, which means save twice.
cmp #8
bcc exit
save anop
lda workByte
and #$00ff
pha
jsl __PutRawByte
lda workByte
xba
and #$00ff
sta workByte
sec
lda workCnt
sbc #8
sta workCnt
cmp #8
beq save
exit anop
EndStack
rtl
end