Advertisement
Erik557

SNES Mode 3 Activation and GFX Upload

Nov 25th, 2015
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.         PHB
  2.         PHK
  3.         PLB
  4.  
  5.         STZ.w $4200
  6.         STZ.w $420C
  7.         LDA.b #$80
  8.         STA.w $2100
  9.  
  10.         LDA.b #$80
  11.         STA.w $2115
  12.  
  13.         REP #$30
  14.  
  15.         LDY.w #$1C
  16. -       LDA.w ExGFX,y
  17.         LDX.w VRAMAddrs,y
  18.         JSR UploadGFXFile
  19.         DEY #2
  20.         BPL -
  21.  
  22.         LDA.w #!PaletteFile
  23.         LDX.w #$0000
  24.         JSR UploadPalette
  25.  
  26.         SEP #$30
  27.  
  28.         LDA.b #$03
  29.         STA.w $2105
  30.         STA.b $3E
  31.         LDA.b #$7C
  32.         STA.w $2107
  33.         STZ.b $1A
  34.         STZ.b $1B
  35.         LDA.b #$FF
  36.         STA.b $1C
  37.         STZ.b $1D
  38.         LDA.b #$01
  39.         STA.w $212C
  40.         STZ.w $212D
  41.         STZ.w $212E
  42.         STZ.w $212F
  43.  
  44.         LDA.b #$20
  45.         STA.w $2131
  46.         STA.b $40
  47.         PLB
  48.         RTS
  49.  
  50. UploadGFXFile:  PHY         ; back up Y
  51.         PHX         ; back up X
  52.         JSR GetExGFXPtrs    ; get pointer to compressed data
  53.         BCS .Upload     ; if success, then upload
  54.         PLX         ; restore X
  55.         PLY         ; restore Y
  56.         RTS
  57.  
  58. .Upload     LDA.w #!GFXBuffer   ; \ GFX buffer low
  59.         STA.b $00       ; / and high byte
  60.         SEP #%00100000      ; 8-bit A
  61.         LDA.b #!GFXBuffer>>16   ; \ GFX buffer
  62.         STA.b $02       ; / bank byte
  63.         PHK         ; \
  64.         PEA.w .Ret1-1       ;  | local JSL to LZ2 routine
  65.         PEA $84CE       ;  | (afterwards A/XY all 8-bit)
  66.         JML $00B8DC     ; /
  67. .Ret1       REP.b #%00010000    ; 16-bit X/Y
  68.         PLX         ; \ restore X, X is the
  69.         STX.w $2116     ; / VRAM destination
  70.         LDA.b #%00000001    ; \ control
  71.         STA.w $4300     ; / register
  72.         LDA.b #$18      ; \ dma to
  73.         STA.w $4301     ; / [21]18
  74.         LDX.w #!GFXBuffer   ; \
  75.         STX.w $4302     ;  | source
  76.         LDA.b #!GFXBuffer>>16   ;  | of data
  77.         STA.w $4304     ; /
  78.         LDX.b $8D       ; \ size of decompressed
  79.         STX.w $4305     ; / GFX File
  80.         LDA.b #%00000001    ; \ start DMA
  81.         STA.w $420B     ; / transfer
  82.         REP #%00100000      ; 16-bit A
  83.         PLY         ; restore Y
  84.         RTS
  85.  
  86. UploadPalette:  PHY         ; back up Y
  87.         PHX         ; back up X
  88.         JSR GetExGFXPtrs    ; get pointer to compressed data
  89.         BCS .Upload     ; if success, then upload
  90.         PLX         ; restore X
  91.         PLY         ; restore Y
  92.         RTS
  93.  
  94. .Upload     LDA.w #!GFXBuffer   ; \ GFX buffer low
  95.         STA.b $00       ; / and high byte
  96.         SEP #%00100000      ; 8-bit A
  97.         LDA.b #!GFXBuffer>>16   ; \ GFX buffer
  98.         STA.b $02       ; / bank byte
  99.         PHK         ; \
  100.         PEA.w .Ret1-1       ;  | local JSL to LZ2 routine
  101.         PEA $84CE       ;  | (afterwards A/XY all 8-bit)
  102.         JML $00B8DC     ; /
  103. .Ret1       REP.b #%00010000    ; 16-bit X/Y
  104.         PLX         ; \  restore X, X is the
  105.         TXA         ;  | 8-bit starting
  106.         STA.w $2121     ; /  color number
  107.         LDA.b #%00000000    ; \ control
  108.         STA.w $4300     ; / register
  109.         LDA.b #$22      ; \ dma to
  110.         STA.w $4301     ; / [21]22
  111.         LDX.w #!GFXBuffer   ; \
  112.         STX.w $4302     ;  | source
  113.         LDA.b #!GFXBuffer>>16   ;  | of data
  114.         STA.w $4304     ; /
  115.         LDX.b $8D       ; \ size of decompressed
  116.         STX.w $4305     ; / GFX File
  117.         LDA.b #%00000001    ; \ start DMA
  118.         STA.w $420B     ; / transfer
  119.         REP #%00100000      ; 16-bit A
  120.         PLY         ; restore Y
  121.         RTS
  122.  
  123. GetExGFXPtrs:   CMP.w #$0032        ; \ < 32, use code
  124.         BCC .GFX00to31      ; / for GFX 00-31
  125.         CMP.w #$0080        ; \ still < 80,
  126.         BCC .UploadReturn   ; / return
  127.         CMP.w #$0100        ; \ > 100, use code
  128.         BCS .ExGFX100toFFF  ; / for 100-FFF
  129. .GFX80toFF  AND.w #$007F        ; reset most significant bit
  130.         STA.b $8A       ; \
  131.         ASL A           ;  | multiply by 3 using
  132.         CLC         ;  | shift-add method
  133.         ADC.b $8A       ; /
  134.         TAY         ; -> Y
  135.         LDA.l $0FF94F       ; \
  136.         STA.b $06       ;  | $0FF94F-$0FF950 contains the pointer
  137.         LDA.l $0FF950       ;  | for the ExGFX table for 80-FF
  138.         STA.b $07       ; /
  139.         BRA .FinishDecomp   ; branch to next step
  140.  
  141. .UploadReturn   CLC         ; "return true"
  142.         RTS
  143.  
  144. .GFX00to31  TAX         ; ExGFX file -> X
  145.         LDA.l $00B992,x     ; \
  146.         STA $8A         ;  | copy ExGFX
  147.         LDA.l $00B9C4,x     ;  | pointer to
  148.         STA $8B         ;  | $8A-$8C
  149.         LDA.l $00B9F6,x     ;  |
  150.         STA $8C         ; /
  151.         BRA .FinishDecomp2  ; branch to next step
  152.  
  153. .ExGFX100toFFF  ;SEC            ; \ subtract #$100
  154.         SBC.w #$0100        ; / SEC commented out because the BCS that branches here would only branch if the carry flag were already set
  155.         STA.b $8A       ; \
  156.         ASL A           ;  | multiply result
  157.         CLC         ;  | by 3 to get
  158.         ADC.b $8A       ;  | index
  159.         TAY         ; /
  160.         LDA.l $0FF873       ; \
  161.         STA.b $06       ;  | $0FF873-$0FF875 contans the pointer
  162.         LDA.l $0FF874       ;  | for the ExGFX table for 100-FFF
  163.         STA.b $07       ; /
  164. .FinishDecomp   LDA.b [$06],y       ; \ Get low byte.
  165.         STA.b $8A       ; / and high byte
  166.         INC.b $06       ; Increase pointer position by 1.
  167.         BNE .NoCrossBank    ; \
  168.         SEP #%00100000      ;  | allow bank crossing
  169.         INC $08         ;  | (not sure if this is necessary here)
  170.         REP #%00100000      ; /
  171. .NoCrossBank    LDA.b [$06],y       ; \ Get the high byte (again)
  172.         STA.b $8B       ; / and bank byte.
  173. .FinishDecomp2  SEC
  174.         RTS
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement