Update spi.s

Use names instead of magic values.
This commit is contained in:
Byron Lathi
2022-03-10 11:29:32 -06:00
parent ee5271d955
commit 236a75eef8

View File

@@ -7,6 +7,10 @@
.code .code
SPI_SCLK = $01
SPI_SSn = $02
SPI_MOSI = $04
; Write a single byte to the SPI device ; Write a single byte to the SPI device
; @in A The byte to write ; @in A The byte to write
@@ -19,16 +23,18 @@ _spi_write_byte:
tax tax
@loop: bit tmp1 ; Check if high bit set @loop: bit tmp1 ; Check if high bit set
beq @1 beq @1
lda #$04 ; Bit not set. lda #SPI_MOSI ; Bit not set.
bra @1 bra @1
@1: lda #$00 ; Bit set @1: lda #$00 ; Bit set
sta BB_SPI_BASE ; Write data sta BB_SPI_BASE ; Write data
adc #$01 adc #SPI_SCLK
sta BB_SPI_BASE ; Write clock sta BB_SPI_BASE ; Write clock
txa txa
lsr ; Select next bit lsr ; Select next bit
tax tax
bne @loop ; Stop when mask is 0 bne @loop ; Stop when mask is 0
lda #SPI_SSn ; Raise Slave Select
sta BB_SPI_BASE
ply ; Restore regs ply ; Restore regs
plx plx
rts ; Return rts ; Return