Advertisement
luckytyphlosion

mew asm

Jan 8th, 2016
1,447
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ; MewUnderTruck: da81
  2. ; RetPointer: dc0e
  3. ; MewBattleTextPointers: dc0f
  4. ; MewBattleText: dc11
  5. ; AfterMewBattle: dc38
  6. ; TruckOAM: dc61
  7. ; MewBlankTile: dc81
  8. ; CopyTruckTilesToVRAM: dc91
  9. ; CopyTruckTileToVRAM: dc98
  10. ; VermillionCityScriptHijack: d8ca
  11.  
  12. _MewUnderTruck:
  13.     ld a, [wd728]
  14.     bit 0, a ; used strength?
  15.     ret z
  16.     predef GetTileAndCoordsInFrontOfPlayer
  17.     ld a, [wYCoord]
  18.     and a
  19.     ret nz ; return if not at ycoord $00
  20.     ld a, e
  21.     cp $15 ; are we at the right of the truck?
  22.     lb de, PLAYER_DIR_LEFT, $3c ; facing and tile
  23.     jr z, .correctCoords
  24.     cp $14 ; are we at the left of the truck?
  25.     ret nz
  26.     lb de, PLAYER_DIR_RIGHT, $58
  27. .correctCoords
  28.     ld a, e
  29.     cp c ; wTileInFrontOfPlayer
  30.     ret nz ; return if we're not actually facing the truck
  31.     ld a, [wPlayerMovingDirection]
  32.     and a
  33.     ret z ; return if we haven't moved
  34.     cp d
  35.     ret nz ; return if we're not facing the correct direction
  36.     push af ; save direction for later
  37. ; truck tiles are:
  38. ; $48 $49 $4a $4b
  39. ; $58 $59 $3c $4c
  40.  
  41. ; upper row
  42.     ld hl, vTileset + $480
  43.     ld de, vNPCSprites + $780 ; use unused slot
  44.     ld c, $4
  45.     push hl
  46.     call CopyTruckTilesToVRAM
  47. ; bottom left
  48.     pop hl
  49.     set 0, h ; get vTileset + $580
  50.     ld c, $2
  51.     call CopyTruckTilesToVRAM
  52. ; bottom right
  53.     ld hl, vTileset + $3c0
  54.     call CopyTruckTileToVRAM
  55.     ld hl, vTileset + $4c0
  56.     call CopyTruckTileToVRAM
  57.  
  58. ; write sprite stuff
  59.     ld a, [wPlayerMovingDirection]
  60.     cp PLAYER_DIR_RIGHT
  61.     ld a, $d
  62.     jr z, .rightAnimation
  63.     ld a, $9
  64. .rightAnimation
  65.     ld [wSpriteStateData1 + $2], a ; walking frame
  66.     call DelayFrame
  67.     ld a, $ff
  68.     ld [wUpdateSpritesEnabled], a
  69.    
  70.     ld hl, TruckOAM
  71.     ld de, wOAMBuffer + 4 * 4
  72.     ld bc, TruckOAMEnd - TruckOAM
  73.    
  74.     push hl
  75.     push bc
  76.    
  77.     call CopyData
  78.    
  79.     pop bc
  80.     pop hl
  81.    
  82.     call CopyData ; copy tiles again so that white isn't seethrough
  83.    
  84.     ld hl, MewBlankTile
  85.     ld de, vNPCSprites2 + $400
  86.     ld c, $1
  87.    
  88.     call CopyTruckTileToVRAM
  89.    
  90.    
  91.     ld hl, wOAMBuffer + 12 * 4 + 2 ; id, 8th entry
  92.     ld de, $3
  93.     lb bc, $0, 8
  94.     ld a, $c0
  95. .writeBlankTileLoop
  96.     ld [hli], a
  97.     ld [hl], b
  98.     add hl, de
  99.     dec c
  100.     jr nz, .writeBlankTileLoop
  101.    
  102.     pop af
  103.     cp PLAYER_DIR_LEFT
  104.     jr z, .coordsAlreadyCorrect
  105. ; fix the coordinates so that they're relative to the player if facing right
  106.     ld hl, wOAMBuffer + 4 * 4 + 1 ; x
  107.     ld de, $4
  108.     lb bc, $30, 16
  109. .shiftOffsetLoop
  110.     ld a, b
  111.     add [hl]
  112.     ld [hl], a
  113.     add hl, de
  114.     dec c
  115.     jr nz, .shiftOffsetLoop
  116. .coordsAlreadyCorrect
  117.     ld a, [rOBP1]
  118.     push af
  119.     ld a, %11100100
  120.     ld [rOBP1], a
  121.    
  122.     callab ReplaceTreeTileBlock ; get address of tile in front of player
  123.     ld [hl], $c ; replace block
  124.    
  125.     push hl ; save address for later
  126.     callab RedrawMapView
  127.    
  128.    
  129.    
  130.     ld a, SFX_PUSH_BOULDER
  131.     call PlaySound
  132.     call DelayFrame
  133.     ld a, [wPlayerMovingDirection]
  134.     cp PLAYER_DIR_RIGHT
  135.     ld b, $1
  136.     jr z, .continue
  137.     ld b, -$1
  138. .continue
  139.     ld c, 16 ; 16 sprites
  140.     ld hl, wOAMBuffer + 4 * 4 + 1
  141.     ld de, $4
  142.     ld a, $20
  143. .moveTruckLoop
  144.     push af
  145.     push hl
  146.     push bc
  147. .shiftTruck
  148.     ld a, b
  149.     add [hl]
  150.     ld [hl], a
  151.     add hl, de
  152.     dec c
  153.     jr nz, .shiftTruck
  154.     pop bc
  155.     pop hl
  156.     call DelayFrame
  157.     call DelayFrame
  158.     pop af
  159.     dec a
  160.     jr nz, .moveTruckLoop
  161.     pop hl ; restore address of truck
  162.     ld a, [wPlayerMovingDirection]
  163.     cp PLAYER_DIR_RIGHT
  164.     ld [wSavedSpriteMapX+3], a ; unused wram
  165.     inc hl
  166.     jr z, .moveTruckToRight
  167.     dec hl
  168.     dec hl
  169. .moveTruckToRight
  170.     ld [hl], $3 ; truck blocks
  171.     ld a, l
  172.     ld [wSavedSpriteMapX+1], a ; unused wram
  173.     ld a, h
  174.     ld [wSavedSpriteMapX+2], a
  175.     callab RedrawMapView
  176.     ld a, $1
  177.     ld [wUpdateSpritesEnabled], a
  178.     ld [wNumSprites], a
  179.     ld hl, wOAMBuffer + 4 * 4
  180.     lb bc, $a0, 16
  181.     ld de, $4
  182. .hideSpritesLoop
  183.     ld [hl], b
  184.     add hl, de
  185.     dec c
  186.     jr nz, .hideSpritesLoop
  187.    
  188. .waitForLYLoop
  189.     ld a, [rLY]
  190.     cp 72
  191.     jr c, .waitForLYLoop
  192.    
  193. ; copy generic mon sprite to 4-tile portion
  194.     ld hl, vNPCSprites + $400
  195.     ld de, vNPCSprites + $780
  196.     ld c, $4
  197.     call CopyTruckTilesToVRAM
  198.  
  199. ; sprite pic   
  200.     ld a, $3d ; four tile sprite
  201.     ld [wSpriteStateData1 + $10], a
  202.     ld hl, wSpriteStateData2 + $14
  203. ; coords
  204.     ld a, $4
  205.     ld [hli], a
  206.     ld a, $19
  207.     ld [hli], a
  208. ; movement byte
  209.     ld [hl], $ff ; no moving
  210. ; sprite slot
  211.     ld a, $b
  212.     ld [wSpriteStateData2 + $1e], a
  213.    
  214.     pop af
  215.     ld [rOBP1], a
  216.    
  217.     call DelayFrame
  218.    
  219.     ld a, [wUpdateSpritesEnabled]
  220.     push af
  221.     ld a, $ff
  222.     ld [wUpdateSpritesEnabled], a
  223.    
  224.     ld a, [wSpriteStateData1 + $6] ; absolute x
  225.     push af
  226.     add $10
  227.     ld b, a
  228.     ld a, [wPlayerMovingDirection]
  229.     cp PLAYER_DIR_RIGHT
  230.     ld a, b
  231.     jr z, .adjustedOffset
  232.     sub $10 + $10
  233. .adjustedOffset
  234.     ld [wSpriteStateData1 + $6], a
  235.     callab AnimateBoulderDust
  236.     pop af
  237.     ld [wSpriteStateData1 + $6], a
  238.     pop af
  239.     ld [wUpdateSpritesEnabled], a
  240.    
  241.     ; change map text pointer
  242.     ld hl, wMapTextPtr
  243.    
  244.     ld a, MewBattleTextPointers & $ff
  245.     ld [hli], a
  246.     ld a, MewBattleTextPointers / $100
  247.     ld [hli], a
  248.    
  249. ; change map script pointer
  250.     ld a, RetPointer & $ff
  251.     ld [hli], a
  252.     ld [hl], RetPointer / $100
  253. RetPointer:
  254.     ret
  255. MewBattleTextPointers:
  256.     dw MewBattleText
  257.    
  258. MewBattleText:
  259.     text "Mew!@"
  260.     TX_ASM
  261.     ld a, MEW
  262.     ld [wCurOpponent], a
  263.     call PlayCry
  264.     call WaitForSoundToFinish
  265.     ld a, $5
  266.     ld [wCurEnemyLVL], a
  267.    
  268.     ld hl, wMapScriptPtr
  269.     ld a, AfterMewBattle & $ff
  270.     ld [hli], a
  271.     ld [hl], AfterMewBattle / $100
  272.     ld hl, wCurMapTileset
  273.     set 7, [hl] ; don't reload map script
  274.     jp TextScriptEnd
  275.    
  276. AfterMewBattle:
  277.     xor a
  278.     ld [wSpriteStateData1 + $10], a ; clear mew sprite
  279.     ld hl, wSavedSpriteMapX + 3 ; saved walking direction
  280.     ld a, [hld]
  281.     ld b, a
  282.     ld a, [hld]
  283.     ld l, [hl]
  284.     ld h, a
  285.     ld [hl], $3 ; rewrite truck block
  286.     ld a, b
  287.     cp PLAYER_DIR_RIGHT
  288.     dec hl
  289.     jr z, .facingRight
  290.     inc hl
  291.     inc hl
  292. .facingRight
  293.     ld [hl], $c
  294.     callab RedrawMapView
  295.     ld hl, wMapScriptPtr
  296.     ld a, VermilionDockScript & $ff
  297.     ld [hli], a
  298.     ld [hl], VermilionDockScript / $100
  299.     ret
  300.    
  301. TruckOAM:
  302. ; y, x, id, flags
  303.     db $50,$28,$78,%10000 ; OBP1
  304.     db $50,$30,$79,%10000
  305.     db $50,$38,$7a,%10000
  306.     db $50,$40,$7b,%10000
  307.    
  308.     db $58,$28,$7c,%10000 ; OBP1
  309.     db $58,$30,$7d,%10000
  310.     db $58,$38,$7e,%10000
  311.     db $58,$40,$7f,%10000
  312. TruckOAMEnd:
  313.  
  314. MewBlankTile:
  315.     rept 8
  316.     db %11111111
  317.     db %00000000
  318.     endr
  319.  
  320.  
  321. CopyTruckTilesToVRAM:
  322. .copyTruckTilesloop
  323.     call CopyTruckTileToVRAM
  324.     dec c
  325.     jr nz, .copyTruckTilesloop
  326.     ret
  327.  
  328. CopyTruckTileToVRAM:
  329.     push bc
  330.     lb bc, %11, $8
  331. .waitForNonHBlank
  332.     ld a, [rSTAT]
  333.     and b
  334.     jr z, .waitForNonHBlank
  335. .waitForHBlank
  336.     ld a, [rSTAT]
  337.     and b
  338.     jr nz, .waitForHBlank
  339.     ld a, [hli]
  340.     ld [de], a
  341.     inc de
  342.     ld a, [hli]
  343.     ld [de], a
  344.     inc de
  345.     dec c
  346.     jr nz, .waitForNonHBlank
  347.     pop bc
  348.     ret
  349. _MewUnderTruckEnd:
  350.  
  351. VermillionCityScriptHijack:
  352.     ld a, [wWalkBikeSurfState]
  353.     cp $2
  354.     jr nz, .keepMapHeightAndTilesetType
  355.     ld a, $80
  356.     ld [wCurMapTileset], a ; allow hijacking boat mapscriptptr
  357.     ld a, $10
  358.     ld [wCurMapHeight], a ; fix warps after
  359. .keepMapHeightAndTilesetType
  360.     ld a, [wCurMap]
  361.     cp VERMILION_DOCK
  362.     jp nz, VermilionCityScript
  363.     ld a, $ff
  364.     ld [wJoyIgnore], a
  365.     ld [rBGP], a
  366.     ld [rOBP0], a
  367.     ld [rOBP1], a
  368.     pop hl ; return address for RunMapScript
  369.     pop hl ; return address for JoypadOverworld
  370.     call LoadMapData
  371.     ld a, wBoxSpecies & $ff
  372.     ld [wMapScriptPtr], a
  373.     ld a, wBoxSpecies / $100
  374.     ld [wMapScriptPtr + 1], a
  375.     jp $3ae ; EnterMap + $8
  376. VermillionCityScriptHijackEnd:
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement