SHARE
TWEET

hello.z80

a guest Jan 13th, 2020 71 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #define     WRTPSG   $0093
  2. #define     RDPSG   $0096
  3.  
  4. .org        $c000
  5.  
  6. TYPE        .db     $fe
  7. ADDRSTART   .dw     $c000
  8. ADDREND     .dw     (END)
  9. ADDREXE     .dw     $c009
  10.  
  11. LO          .db     $00
  12. HI      .db     $00
  13.  
  14. .org        $c009
  15.  
  16.     call    READJOYPORTLO
  17.     and $3F
  18.     ld  c,a     ; c=0,0,C,B,L,R,D,U
  19.  
  20.     call    READJOYPORTHI
  21.     and $3C     ; crop S,A,I,I
  22.     add a,a
  23.     add a,a
  24.     ld  b,a     ; b=S,A,I,I,0,0,0,0
  25.  
  26.     call    READJOYPORTLO
  27.     call    READJOYPORTHI
  28.     call    READJOYPORTLO
  29.     call    READJOYPORTHI
  30.     and 00001111b   ; 2nd ID = 0?
  31.     jr  nz,joy3btn  ; If this joypad isn't the 6-button model, skip
  32.  
  33.     ld  a,b     ; a=S,A,0,0,0,0,0,0
  34.     or  c       ; a=S,A,C,B,R,L,D,U
  35.     ld  c,a     ; c=S,A,C,B,R,L,D,U
  36.     call    READJOYPORTLO   ;   ?,?,C,B,M,X,Y,Z
  37.     and $0F     ; Crop      M,X,Y,Z
  38.     ld  b,a     ; b=0,0,0,0,M,X,Y,Z
  39.     ld  (LO),a
  40.     ld  a,c     ; a=S,A,C,B,R,L,D,U
  41.     ld  (HI),a
  42.     ret
  43. joy3btn:    ; This is a 3-button joypad
  44.     ; Now place the bits in the standard two-byte format used for all Sega
  45.     ; controllers & multi-tap
  46.     ld  a,b     ; a=ST,A,00,0000
  47.     or  c       ; a=ST,A,C,B,Rt,Lt,Dn,Up
  48.     ld  b,$1F   ; b=JOYID:001,11111 (L=MODE=X=Y=Z=1)
  49.     ret
  50.  
  51. READJOYPORTHI:
  52.     ld  e,$9F
  53.     ld  a,15
  54.     jp  WRTPSG
  55.     jp  READJOYPORT
  56. READJOYPORTLO:
  57.     ld  e,$8F
  58.     ld  a,15
  59.     jp  WRTPSG
  60.     jp  READJOYPORT
  61. READJOYPORT:
  62.     ld  a,14
  63.     di
  64.     call    RDPSG
  65.     ei
  66.     ret
  67.    
  68. END:
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top