[Software] Joyport SPI Master

hu, cd, scd, acd, supergrafx discussions.
Post Reply
User avatar
MooZ
Site Admin
Posts: 389
Joined: Sun Jun 22, 2008 3:19 pm
Location: Lvl 3
Contact:

[Software] Joyport SPI Master

Post by MooZ » Sun Apr 24, 2016 8:15 pm

I'm putting this here as I don't if I'll ever find time to implement it.
SPI is a rather simple bus. It only uses 4 pins, SCK, MISO, MOSI, CS. Long story short, joyport SEL and CLR can be used for SCK and MISO, any of the D0-D3 lines can be used for MOSI, and CS can be directly wired to GND. The code may look like this:

Code: Select all

  .zp
spi_polarity .ds 1
spi_phase    .ds 1
  .code
;;
;; Function: spi_mode
;; Set SPI phase and polarity.
;;
;; Parameters:
;;   A - mode
;;
spi_mode:
    pha
    and    #$02
    sta    <spi_polarity
    pla
    and    #$01
    sta    <spi_phase
    rts

Code: Select all

;;
;; Function: spi_write
;;
;; Parameters:
;;   _al - byte to send
;;
;; Return:
;;   _ah - byte read
;;
spi_write:
    stz    <_ah
    ldx    #$08
@loop:
    lda    <_al
    and    #$01
    sta    joyport
    
    lda    <spi_phase
    bne    @l0
        lda    joyport
        lsr    A
        rol    <_ah
@l0:
    lda    <spi_polarity
    eor    #$02
    sta    joyport
    
    ; todo : delay
    
    lda    <spi_phase
    beq    @l1
        lda    joyport
        lsr    A
        rol    <_ah
@l1:
    
    lda    <spi_polarity
    sta    joyport
    
    ; todo : delay
    
    dex
    bne    @loop
    
    rts


User avatar
MooZ
Site Admin
Posts: 389
Joined: Sun Jun 22, 2008 3:19 pm
Location: Lvl 3
Contact:

Re: [Software] Joyport SPI Master

Post by MooZ » Mon Apr 25, 2016 12:04 pm

I forgot the CS line is used to synchronize packets/byte between master and slave.
A direct implementation is impossible as there are only 2 output PINs on the joyport.

Crap...

User avatar
MooZ
Site Admin
Posts: 389
Joined: Sun Jun 22, 2008 3:19 pm
Location: Lvl 3
Contact:

Re: [Software] Joyport SPI Master

Post by MooZ » Sun Nov 27, 2016 11:27 pm

That leaves us with the good old rx/tx or i2c...

Post Reply