Advertisement
pxh

SRAM inject source code

pxh
Aug 10th, 2016
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ; Payload for Pokemon Red/Blue serial transfer buffer overload
  2. ; Listens for data from serial port, then puts that data sequentially
  3. ; in the cartridge's SRAM before resetting the game
  4. ; Assemble using RGBDS, then read from $150-$212
  5.  
  6.     SECTION "Program Start",HOME[$0150]
  7. Boot::
  8.     ld a, [$ffff]
  9.     and $f7
  10.     ld [$ffff], a   ; Disable Serial interrupt
  11.    
  12.     ld a, $81
  13.     ld [$ff02],a    ; Send an echo of last byte
  14.     ld a, $ff
  15.     call $23b1      ; Stop music
  16.     call $190f      ; Clear screen
  17.     ld a, $aa
  18.     ld [$d0b5], a
  19.     ld [$cf91], a
  20.     call $1537      ; Load properties of Porygon
  21.     ld hl, $c3cf
  22.     call $1384      ; Display Porygon's sprite
  23.     ld a, $aa
  24.     call $13d0      ; Play Porygon's cry
  25.     ld c, $02
  26.     ld a, $e5
  27.     call $23a1      ; Play trade music
  28.     ld hl, $c490
  29.     ld bc, $0412
  30.     call $5ab3      ; Display text box border
  31.     xor a
  32.     ld [$d358], a   ; Zero delay text
  33.     ld de, .tex + $c486     ; Adjustment for payload location
  34.     ld hl, $c4b9
  35.     call $1955      ; Print "Transferring data."
  36.  
  37.     ld hl, $c4e2    ; Display an empty progress bar below text
  38.     ld a, $63       ; (uses tiles from HP bar)
  39.     ld d, $10
  40. .loadbar
  41.     ld [hli], a
  42.     dec d
  43.     jr nz, .loadbar
  44.  
  45.     ld a, $a
  46.     ld [$0000], a   ; Enable SRAM
  47.     ld a, $1
  48.     ld [$6000], a   ; SRAM banking mode
  49.     ld de, $0000
  50.    
  51. .loop               ; Main loop, loads 32768 bytes from Serial Transfer into SRAM
  52.     ld hl, $a000
  53.     ld bc, $2000
  54.     ld a, d
  55.     ld [$4000], a   ; SRAM bank
  56. .read
  57.     ld a, $81
  58.     ld [$ff02], a
  59. .waitloop1
  60.     ld a, [$ff02]
  61.     and $80
  62.     jr nz, .waitloop1
  63.     ld a, [$ff01]
  64.     ld [hli], a
  65.     dec e
  66.     jr z, .updatebar    ; Update progress bar every 256 cycles
  67. .return
  68.     dec bc
  69.     ld a, b
  70.     or c
  71.     jr nz, .read
  72.     inc d
  73.     ld a, $4
  74.     cp d
  75.     jr nz, .loop
  76.    
  77.     xor a
  78.     ld [$0000], a   ; Disable SRAM
  79.     ld [$6000], a   ; Disable SRAM banking
  80.     ld a, $81
  81.     ld [$ff02],a    ; Send an echo of last byte
  82.     jp $1F54        ; Reset game
  83.    
  84. .updatebar
  85.     push hl
  86.     ld hl, $c4e2
  87. .loadnext
  88.     ld a, [hl]
  89.     cp $6B
  90.     jr nz, .inctile
  91.     inc hl
  92.     jr .loadnext
  93. .inctile
  94.     inc a
  95.     ld [hl], a
  96.     pop hl
  97.     jr .return
  98.    
  99. .tex
  100.     db $91,$a4,$a2,$a4,$a8,$b5,$a8,$ad  ; Receiving data
  101.     db $a6,$7f,$a3,$a0,$e8,$e8,$e8,$50
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement