Files
super6502/sw/spi.s
Byron Lathi ee5271d955 Fix spi bug
Was reading a value from x, shifting it, but then not writing it back.
This caused an infinite loop as it would never move on from the MSB.
2022-03-10 11:16:35 -06:00

35 lines
845 B
ArmAsm

.include "io.inc65"
.export _spi_write_byte
.importzp sp, sreg, regsave, regbank
.importzp tmp1, tmp2, tmp3, tmp4, ptr1, ptr2, ptr3, ptr4
.code
; Write a single byte to the SPI device
; @in A The byte to write
_spi_write_byte:
phx ; Save regs
phy
sta tmp1 ; Save value into tmp1
lda #$80
tax
@loop: bit tmp1 ; Check if high bit set
beq @1
lda #$04 ; Bit not set.
bra @1
@1: lda #$00 ; Bit set
sta BB_SPI_BASE ; Write data
adc #$01
sta BB_SPI_BASE ; Write clock
txa
lsr ; Select next bit
tax
bne @loop ; Stop when mask is 0
ply ; Restore regs
plx
rts ; Return