Advertisement
tomoha

SMW Built-in Hex Editor

Aug 6th, 2022 (edited)
2,303
2
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ; how to patch (EN) https://docs.google.com/document/d/1hSZBCYtGbPgmxxF9S0OACDMp3DIVn4ijL3LEqaet3hE/edit?usp=sharing
  2. ; how to patch (JP) https://docs.google.com/document/d/1Vcs2G5Vqk7welBcZPcEPIGTl4KZYw0kyijplHv_ufCA/edit?usp=sharing
  3.  
  4. !HexEditorOpenFlag = $79
  5.  
  6. ; modifies bootstrap to expand Intended RAM
  7. org $00804C
  8.  
  9. jsl $03D6B1
  10. nop #2
  11.  
  12.  
  13. ; expanded Intended RAM
  14. org $03D6AC
  15.  
  16. db $22,$5C,$E0,$03,$6B ; jsl $03E05C, rtl
  17.  
  18. modifyIntendedRAM:
  19.     ldx #$00
  20.     expandIntendedRAM:
  21.         lda $03D6AC,X
  22.         sta $7F8182,X
  23.         inx
  24.         txa
  25.         cmp #$05
  26.         bne expandIntendedRAM
  27.         rtl
  28.  
  29.  
  30. ; code to be run every frame
  31. org $03E05C
  32.  
  33. checkHexEditorOpenFlag:
  34.     lda !HexEditorOpenFlag
  35.     cmp #$01
  36.     beq gotoHexEditor
  37.  
  38. ; Check if R and Select are being held
  39. checkOpenCommand:
  40.     ldx $17
  41.     cpx #$10
  42.     bne returntoIntendedRAM
  43.     ldx $15
  44.     cpx #$20
  45.     beq openHexEditor
  46.  
  47. returntoIntendedRAM:
  48.     rtl
  49.  
  50. openHexEditor:
  51.     ; play SFX sound
  52.     lda #$29
  53.     sta $1DFC
  54.     ; hex editor open flag set
  55.     inc !HexEditorOpenFlag
  56.     rtl
  57.  
  58. gotoHexEditor:
  59.     jsl HexEditor
  60.     rtl
  61.  
  62.  
  63.  
  64. ; hex editor code by SethBling and Mally
  65. ; modefied by tomoha
  66. org $0FEF90
  67.  
  68. HexEditor:
  69.     ; Store $0100 to $F8. This is only used for a couple compare instructions
  70.     LDA #$01
  71.     STA $F9    
  72.     STZ $F8
  73.  
  74.     ; Check if select is being pressed
  75.     LDA $15
  76.     AND #$20
  77.     TAX
  78.  
  79.     ; Move cursor/page/bank with UDLR
  80.     LDA $FB
  81.     LDY $16
  82.  
  83.     ; Check if right is being pressed
  84.     DEY
  85.     BNE noright
  86.     INC A
  87.     INC $DE,X
  88.  
  89. noright:
  90.     ; Check if left is being pressed
  91.     DEY
  92.     BNE noleft
  93.     DEC A
  94.     DEC $DE,X
  95.    
  96. noleft:
  97.     ; Check if down is being pressed
  98.     CPY #$02
  99.     BNE nodown
  100.     ADC #$0F        ; Carry is set, plus $0F
  101.     DEC $DF,X
  102.    
  103. nodown:
  104.     ; Check if up is being pressed
  105.     CPY #$06
  106.     BNE noup
  107.     ADC #$EF        ; Carry is set, minus $0F
  108.     INC $DF,X
  109.    
  110. noup:
  111.     ; Update the cursor if select isn’t being pressed
  112.     STA $FB,X
  113.     TAY
  114.  
  115.     ; Increment/decrement value at cursor
  116.     LDA [$FD],Y
  117.  
  118.     LDX $18
  119.     ; Check if R is being pressed
  120.     CPX #$10
  121.     BEQ incVal
  122.  
  123.     ; Check if L is being pressed
  124.     CPX #$20
  125.     BNE noL
  126.     DEC A
  127.    
  128. noL:
  129.     ; Check of both L and R are being held
  130.     LDX $17
  131.     CPX #$30
  132.     BNE noLR
  133.     INC A
  134.     INC A
  135.     incVal:
  136.     INC A
  137.  
  138. noLR:
  139.     ; Check of both L and Select are being held
  140.     LDX $17
  141.     CPX #$20
  142.     BNE noClose
  143.     LDX $15
  144.     CPX #$20
  145.     BEQ closeHexEditor
  146.  
  147. noClose:
  148.     STA [$FD],Y
  149.  
  150. draw:
  151.     ; Set up stripe image loader
  152.     REP #$30 ; 16-bit accumulator and index registers
  153.  
  154.     STZ $24
  155.  
  156.     ; Write 4-byte stripe image header
  157.     LDA #$A050
  158.     STA $7F837D
  159.     LDA #$0009
  160.     STA $3E
  161.     LDA #$0704
  162.     STA $7F837F
  163.  
  164.     XBA         ; A becomes $0407
  165.     TAX
  166.  
  167.     LDY #$0101
  168.  
  169.     ; Write all tiles to stripe data (400 bytes)
  170.    
  171. loop:
  172.     LDA [$FD],Y
  173.  
  174.     ; Special cases for bank/page numbers
  175.     CPY $F8     ; $F8 is $0100. Could just CPY #$0100 instead.
  176.     BMI skip
  177.     LDA $FE     ; A becomes $FF$FE
  178.     CPY $F8     ; $F8 is $0100. Could just CPY #$0100 instead.
  179.     BNE skip
  180.     XBA         ; A becomes $FE$FF
  181.  
  182.     skip:
  183.         PHA
  184.         JSR.w writeTile
  185.         PLA
  186.         LSR A
  187.         LSR A
  188.         LSR A
  189.         LSR A
  190.         JSR.w writeTile
  191.  
  192.     DEY
  193.     BPL loop
  194.  
  195.     SEP #$30 ; 8-bit accumulator and index registers
  196.  
  197.     TYA
  198.     STA $7F8789
  199.  
  200. returnSubroutine:
  201.     RTL
  202.  
  203. writeTile:
  204.     AND #$000F      ; Draw hex digit
  205.     ORA #$3800      ; Tile properties
  206.     CPY $FB     ; Check if highlighted by cursor
  207.     BNE nocolor
  208.     ORA #$0400      ; Add color
  209.     nocolor:
  210.     DEX
  211.     STA $7F8381,X   ; Write tile ID and properties
  212.     DEX
  213.     RTS
  214.  
  215. closeHexEditor:
  216.     LDA #$29
  217.     STA $1DFC
  218.     ; clear hex editor open flag
  219.     STZ !HexEditorOpenFlag
  220.  
  221. ; thanks T.T for advising me this routine
  222. ClearLayer3Long:
  223.     REP #$30 ; 16-bit accumulator and index registers
  224.  
  225.     ; Write 4-byte stripe image header
  226.     LDA #$A050
  227.     STA $7F837D
  228.     LDA #$0B04
  229.     STA $7F837F
  230.  
  231.     XBA         ; A becomes $040B
  232.     TAX
  233.  
  234.     LDA #$38FC
  235.   - DEX
  236.     STA $7F8381,X   ; Write tile ID and properties
  237.     DEX
  238.     BPL -
  239.  
  240.     SEP #$30 ; 8-bit accumulator and index registers
  241.     TXA
  242.     STA $7F878D
  243.  
  244.     RTL
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement