Guest User

Untitled

a guest
Dec 4th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. GetText: ; 13f6
  2. ; pushes pointer for each character to the stack
  3. ; input: hl = text pointer
  4. .read
  5.     ld a, [hli]
  6.     cp a, "@"
  7.     ret z ; terminator
  8.     call GetChar
  9.     jr .read
  10.  
  11. GetChar: ; 13ff
  12. ; pushes pointer for given character to the stack
  13. ; input: a = char id
  14.     push hl
  15.     push bc
  16.     ld c, a
  17.     ld b, $00
  18.     ld hl, Chars ; pointer table
  19.     add hl, bc
  20.     add hl, bc
  21.     ld e, [hl]
  22.     inc hl
  23.     ld d, [hl]
  24.     pop bc
  25.     pop hl
  26.     push de
  27.     ret
  28. ; 1410
  29.  
  30. Chars: ; 1410
  31.     dw $143e
  32.     dw $1449
  33.     dw $1470
  34.     dw $1480
  35.     dw $148b
  36.     dw $149b
  37.     dw $149f
  38.     dw $14ba
  39.     dw $14c9
  40.     dw $14d2
  41.     dw $14ed
  42.     dw $1500
  43.     dw $1543
  44.     dw $1562
  45.     dw $1500
  46.     dw $1500
  47.     dw $1500
  48.     dw $1500
  49.     dw $1500
  50.     dw $1500
  51.     dw $156a
  52.     dw $1582
  53.     dw $1455
  54.  
  55.  
  56.  
  57. GetTileType: ; 185d
  58. ; checks the properties of a tile
  59. ; input: a = tile id
  60.     push de
  61.     push hl
  62.     ld hl, TileTypeTable
  63.     ld e, a
  64.     ld d, $00
  65.     add hl, de
  66.     ld a, [$ff00+$9d] ; current bank
  67.     push af
  68.     ld a, BANK(TileTypeTable)
  69.     rst $10
  70.     ld e, [hl] ; get tile type
  71.     pop af
  72.     rst $10 ; return to current bank
  73.     ld a, e
  74.     and a, $0f ; lo nybble only
  75.     pop hl
  76.     pop de
  77.     ret
  78.  
  79.  
  80.  
  81.  
  82. Function1ad2: ; 1ad2
  83.     ld a, [$d0ed]
  84.     bit 0, a
  85.     ret z
  86.     ld a, BANK(Function55e0)
  87.     ld hl, Function55e0
  88.     rst $08
  89.     ld a, $01 ; BANK(Function5920)
  90.     ld hl, $5920 ; Function5920
  91.     rst $08
  92.     ret
  93.  
  94.  
  95.  
  96.  
  97. Function1c07: ; 1c07
  98.     push af
  99.     ld hl, Function243e8
  100.     ld a, BANK(Function243e8)
  101.     rst $08
  102.     pop af
  103.     ret
  104. ; 1c17
  105.  
  106. Function1c17: ; 1c17
  107.     push af
  108.     call Function1c07
  109.     call $321c
  110.     call Function1ad2
  111.     pop af
  112.     ret
  113. ; 1c23
  114.  
  115. Function1c23: ; 1c23
  116.     call Function1cfd
  117.     call ReverseCopyBytes
  118.     call Function1d19
  119.     call ReverseCopyBytes
  120.     ret
  121. ; 1c30
  122.  
  123. ReverseCopyBytes: ; 1c30
  124. ; copy bc bytes from de (dec) to hl (inc)
  125.     call Function1c53
  126.     inc b
  127.     inc b
  128. .HandleLoop
  129.     push bc
  130.     push hl
  131. .CopyByte
  132.     ld a, [de]
  133.     ld [hli], a
  134.     dec de
  135.     dec c
  136.     jr nz, .CopyByte
  137.     pop hl
  138.     ld bc, $0014
  139.     add hl, bc
  140.     pop bc
  141.     dec b
  142.     jr nz, .HandleLoop
  143.     ret
  144. ; 1c47
  145.  
  146. ReverseCopyBytes2: ; 1c47
  147. ; copy $10 bytes from hld into $cf81-$cf90
  148.     ld b, $10
  149.     ld de, $cf81
  150. .loop
  151.     ld a, [hld]
  152.     ld [de], a
  153.     inc de
  154.     dec b
  155.     jr nz, .loop
  156.     ret
  157. ; 1c53
  158.    
  159. Function1c53: ; 1c53
  160. ; b=[$cf84]-[$cf82]
  161. ; c=[$cf85]-[$cf83]
  162.     ld a, [$cf82]
  163.     ld b, a
  164.     ld a, [$cf84]
  165.     sub b
  166.     ld b, a
  167.     ld a, [$cf83]
  168.     ld c, a
  169.     ld a, [$cf85]
  170.     sub c
  171.     ld c, a
  172.     ret
  173.  
  174.  
  175.  
  176.  
  177.  
  178. Function1c7e: ; 1c7e
  179. ; loads pointer from $cf71
  180. ; loads data from [pointer + 1] into hl
  181.     ld hl, $cf71
  182.     ld a, [hli]
  183.     ld h, [hl]
  184.     ld l, a
  185.     inc hl
  186.     ld a, [hli]
  187.     ld h, [hl]
  188.     ld l, a
  189.     ret
  190.  
  191.  
  192.  
  193.  
  194. Function1cfd: ; 1cfd
  195.     ld a, [$cf83]
  196.     ld c, a
  197.     ld a, [$cf82]
  198.     ld b, a
  199.     xor a
  200.     ld h, a
  201.     ld l, b
  202.     ld a, c
  203.     ld b, h
  204.     ld c, l
  205.     add hl, hl
  206.     add hl, hl
  207.     add hl, bc
  208.     add hl, hl
  209.     add hl, hl
  210.     ld c, a
  211.     xor a
  212.     ld b, a
  213.     add hl, bc
  214.     ld bc, $c4a0
  215.     add hl, bc
  216.     ret
  217.    
  218.  
  219. Function1d19: ; 1d19
  220.     ld a, [$cf83]
  221.     ld c, a
  222.     ld a, [$cf82]
  223.     ld b, a
  224.     xor a
  225.     ld h, a
  226.     ld l, b
  227.     ld a, c
  228.     ld b, h
  229.     ld c, l
  230.     add hl, hl
  231.     add hl, hl
  232.     add hl, bc
  233.     add hl, hl
  234.     add hl, hl ; * 20
  235.     ld c, a
  236.     xor a
  237.     ld b, a
  238.     add hl, bc
  239.     ld bc, $cdd9
  240.     add hl, bc
  241.     ret
  242. ; 1d35
  243.  
  244.  
  245. Function1d35: ; 1d35
  246.     call Function1d3c
  247.     call Function1c00
  248.     ret
  249. ; 1d3c
  250.  
  251. Function1d3c: ; 1d3c
  252.     ld de, $cf81
  253.     ld bc, $0010
  254.     call CopyBytes ; copy $10 bytes from [hl] to $cf81
  255.     ld a, [$ff00+$9d]
  256.     ld [$cf8a], a
  257.     ret ; might have been a ret nz once
  258. ; unused?
  259.     ld [$cf88], a
  260.     ret
  261.  
  262. Function1d4f: ; 1d4f
  263.     push hl
  264.     call Function1d58
  265.     pop hl
  266.     jp $1057
  267.     ret
  268. ; 1d58
  269.    
  270. Function1d58: ; 1d58
  271.     ld hl, Table1d5f
  272.     call Function1d35
  273.     ret
  274. ; 1d5f
  275.  
  276. Table1d5f: ; 1d5f
  277.     db $40, $0c, $00, $11, $13, $00, $80, $00
  278. ; 1d67
  279.  
  280. Function1d67: ; 1d67
  281.     call Function1d4f
  282.     call Function1c17
  283.     ret
  284. ; 1d6e
  285.  
  286.  
  287.  
  288. Function261f: ; 261f
  289.     ld [$d439], a
  290.     ld a, l
  291.     ld [$d43a], a
  292.     ld a, h
  293.     ld [$d43b], a
  294.     ld a, $ff
  295.     ld [$d438]. a
  296.     scf
  297.     ret
  298. ; 2631
  299.  
  300.  
  301.  
  302. CopyName1: ; 30d6
  303.     ld hl, $d086
  304. ; 30d9
  305. CopyName2: ; 30d9
  306. .loop
  307.     ld a, [de]
  308.     inc de
  309.     ld [hli], a
  310.     cp "@"
  311.     jr nz, .loop
  312.     ret
  313. ; 30e1
  314.  
  315.  
  316.  
  317. GetNick: ; 38a2
  318. ; gets the nickname of a partymon
  319. ; stores the nick for use at $d073
  320.     push hl
  321.     push bc
  322.     call SkipNames
  323.     ld de, $d073
  324.     push de
  325.     ld bc, PKMN_NAME_LENGTH
  326.     call CopyBytes
  327.     pop de
  328.     ld hl, Function669f ; errorchecking
  329.     ld a, BANK(Function669f)
  330.     rst $08
  331.     pop bc
  332.     pop hl
  333.     ret
  334. ; 38bb
  335.  
  336.  
  337.  
  338. Function55e0: ; 55e0
  339.     ld a, [$d0ed]
  340.     bit 0, a
  341.     rt z
  342.     ld bc, $d4d6
  343.     xor a
  344. .asm_55ea
  345.     ld [$ff00+$af], a
  346.     call $1af1
  347.     jr z, .asm_55f4
  348.     call $565c
  349. .asm_55f4
  350.     ld hl, $0028
  351.     add hl, bc
  352.     ld b, h
  353.     ld c, l
  354.     ld a, [$ff00+$af]
  355.     inc a
  356.     cp $0d
  357.     jr nz, .asm_55ea
  358.     ret
  359.  
  360.  
  361.  
  362. Function669f: ; 669f
  363. ; error-check monster name before use
  364.     push bc
  365.     push de
  366.     ld b, PKMN_NAME_LENGTH
  367. .asm_66a3
  368.     ld a, [de]
  369.     cp "@"
  370.     jr z, .end
  371.     ld hl, Table66cf
  372.     dec hl
  373. .loop
  374.     inc hl
  375.     ld a, [hl]
  376.     cp a, $ff ; reached end of table?
  377.     jr z, .exit
  378.     ld a, [de]
  379.     cp [hl]
  380.     inc hl
  381.     jr c, .loop
  382.     cp [hl]
  383.     jr nc, .loop
  384.     ld a, "?"
  385.     ld [de], a
  386.     jr .loop
  387. .exit
  388.     inc de
  389.     dec b
  390.     jr nz, .asm_66a3 ; reached end of name?
  391.     pop de
  392.     push de
  393.     ld a, "?"
  394.     ld [de], a
  395.     inc de
  396.     ld a, "@"
  397.     ld [de], a
  398. .end
  399.     pop de
  400.     pop bc
  401.     ret
  402. ;66cf
  403.  
  404. Table66cf: ; 66cf
  405.     db $00, $05, $14, $19, $1d, $26, $35, $3a
  406.     db $3f, $40, $49, $5d, $5e, $7f, $ff
  407.  
  408.  
  409.  
  410. GetPartyNick: ; c706
  411. ; copies nickname of a partymon to $d073,
  412. ; $d086 and $d099 for use in textboxes
  413.     ld hl, PartyMon1Nickname
  414.     ld a, $02
  415.     ld [$cf5f], a
  416.     ld a, [$d109] ; partymon #
  417.     call GetNick
  418.     call CopyName1
  419.     ld de, $d086
  420.     ld hl, $d099
  421.     call CopyName2
  422.     ret
  423. ; c721
  424.  
  425.  
  426.  
  427. Functionc731: ; c731
  428.     call CheckFlag
  429.     ret nc
  430.     ld hl, Tablec73d
  431.     call $1d67
  432.     scf
  433.     ret
  434. ; c73d
  435.  
  436. Tablec73d: ; c73d
  437.     db $16, $a7, $45, $70, $50
  438. ; c742
  439.  
  440. CheckPartyMove: ; c742
  441. ; checks if a pokemon in your party has a move
  442. ; input: d = move id
  443.     ld e, $00 ; mon #
  444.     xor a
  445.     ld [$d109], a
  446. .checkmon
  447. ; check for valid species
  448.     ld c, e
  449.     ld b, $00
  450.     ld hl, PartySpecies
  451.     add hl, bc
  452.     ld a, [hl]
  453.     and a ; no id
  454.     jr z, .quit
  455.     cp a, $ff ; terminator
  456.     jr z, .quit
  457.     cp a, EGG
  458.     jr z, .nextmon
  459. ; navigate to appropriate move table
  460.     ld bc, $0030
  461.     ld hl, PartyMon1Moves
  462.     ld a, e
  463.     call AddNTimes
  464.     ld b, $04 ; number of moves
  465. .checkmove
  466.     ld a, [hli]
  467.     cp d ; move id
  468.     jr z, .end
  469.     dec b ; how many moves left?
  470.     jr nz, .checkmove
  471. .nextmon
  472.     inc e ; mon #
  473.     jr .checkmon
  474. .end
  475.     ld a, e
  476.     ld [d109], a ; which mon has the move
  477.     xor a
  478.     ret
  479. .quit
  480. ; $d109 = 0
  481.     scf
  482.     ret
  483. ;
  484.  
  485.  
  486.  
  487. Scriptc986: ; c986
  488.     2call 00 00 ; o
  489. ;
  490.  
  491.  
  492.  
  493. GetSurfSprite: ; c9b8
  494.     ld a, [$d109] ; contains 0-5
  495.     ld e, a
  496.     ld d, $00
  497.     ld hl, PartySpecies
  498.     add hl, de
  499.     ld a, [hl]
  500.     cp PIKACHU
  501.     ld a, $08 ; use surfing pikachu sprite
  502.     ret z
  503.     ld a, $04 ; use lapras sprite
  504.     ret
  505. ; c9cb
  506.  
  507. GetDirection: ; c9cb
  508. ; sets carry if direction is invalid ????
  509.     ld a, [PlayerDirection]
  510.     and a, %00001100 ; bits 2 and 3 contain direction
  511.     rrca
  512.     rrca
  513.     ld e, a
  514.     ld d, $00
  515.     ld hl, DirectionTable
  516.     add hl, de
  517.     ld a, [$c2fe] ; normally $00
  518.     and [hl]
  519.     jr nz, .quit
  520.     xor a
  521.     ret
  522. .quit
  523.     scf
  524.     ret
  525. ; 49e3
  526.    
  527. DirectionTable: ; c9e3
  528.     db $08 ; down
  529.     db $04 ; up
  530.     db $02 ; left
  531.     db $01 ; right
  532. ; c9e7
  533.  
  534. CheckSurf: ; c9e7
  535. ; checks if you can surf
  536. ; returns carry if conditions are met
  537.     ld a, [PlayerState]
  538.     cp $08 ; ????
  539.     jr z, .quit
  540.     cp $04 ; check if you are already surfing
  541.     jr z, .quit
  542.     ld a, [$d03e] ; tile you are facing
  543.     call GetTileType ; check if you are facing a surf tile
  544.     cp $01 ; surfable
  545.     jr nz, .quit
  546.     call GetDirection ; make sure you can surf in that direction ????
  547.     jr c, .quit
  548.     ld de, $001e ; check for fog badge
  549.     call CheckFlag
  550.     jr c, .quit
  551.     ld d, SURF ; check for surfmon
  552.     call CheckPartyMove
  553.     jr c, .quit
  554.     ld hl, $dbf5 ; isn't this part of box6name?
  555.     bit 1, [hl] ; maybe it uses another wrambank
  556.     jr nz, .quit
  557.     call GetSurfSprite ; returns $04, or $08 if pikachu
  558.     ld [$d1eb], a
  559.     call GetPartyNick
  560.     ld a, BANK(Scriptca2c)
  561.     ld hl, Scriptca2c
  562.     call Function261f ; stores farpointer to Scriptca2c at $d439
  563.     scf
  564.     ret
  565. .quit
  566.     xor a
  567.     ret
  568. ; ca2c
  569.  
  570. Scriptca2c: ; ca2c
  571.     loadfont
  572.     2writetext AskSurfText
  573.     yesorno
  574.     iftrue Scriptc986
  575.     loadmovesprites
  576.     end
  577.  
  578. AskSurfText: ; ca36
  579.     TX_FAR _AskSurfText
  580.     db "@"
  581. ; ca3b
  582.  
  583.  
  584.  
  585. _AskSurfText ; 1c066c
  586.     db $0, "The water is calm.", $4f
  587.     db "Want to SURF?" $57
  588. ; 1c068e
  589.  
  590.  
  591.  
  592.  
  593. Function243e8: ; 243e8
  594. ; switches to wram bank 7
  595. ; does something
  596. ; switches back
  597.     xor a
  598.     ld [$ff00+$d4], a
  599.     ld a, [$ff00+$70] ; wram bank
  600.     push af
  601.     ld a, $07
  602.     ld [$ff00+$70], a ; wram bank
  603.     call Function1c7e
  604.     ld a, l
  605.     or h
  606.     jp z, $445d ; 2445d
  607.     ld a, l
  608.     ld [$cf71], a
  609.     ld a, h
  610.     ld [$cf72], a
  611.     call ReverseCopyBytes2
  612.     ld a, [$cf81]
  613.     bit 0, a
  614.     jr z, .asm_24411
  615.     ld d, h
  616.     ld e, l
  617.     call Function1c23
  618. .asm_24411
  619.     call Function1c7e
  620.     ld a, h
  621.     or l
  622.     jr z, .asm_2441b
  623.     call ReverseCopyBytes2
  624. .asm_2441b
  625.     pop af
  626.     ld [$ff00+$70], a ; wram bank
  627.     ld hl, $cf78
  628.     dec [hl]
  629.     ret
  630.  
  631.  
  632.  
  633.  
  634. TileTypeTable: ; 4ce1f
  635. ; 256 tiletypes
  636. ; 01 = surfable
  637.     db $00, $00, $00, $00, $00, $00, $00, $0f
  638.     db $00, $00, $00, $00, $00, $00, $00, $0f
  639.     db $00, $00, $1f, $00, $00, $1f, $00, $00
  640.     db $00, $00, $1f, $00, $00, $1f, $00, $00
  641.     db $01, $01, $11, $00, $11, $01, $01, $0f
  642.     db $01, $01, $11, $00, $11, $01, $01, $0f
  643.     db $01, $01, $01, $01, $01, $01, $01, $01
  644.     db $01, $01, $01, $01, $01, $01, $01, $01
  645.    
  646.     db $00, $00, $00, $00, $00, $00, $00, $00
  647.     db $00, $00, $00, $00, $00, $00, $00, $00
  648.     db $00, $00, $00, $00, $00, $00, $00, $00
  649.     db $00, $00, $00, $00, $00, $00, $00, $00
  650.     db $00, $00, $00, $00, $00, $00, $00, $00
  651.     db $00, $00, $00, $00, $00, $00, $00, $00
  652.     db $00, $00, $00, $00, $00, $00, $00, $00
  653.     db $00, $00, $00, $00, $00, $00, $00, $00
  654.    
  655.     db $0f, $0f, $0f, $0f, $0f, $00, $00, $00
  656.     db $0f, $0f, $0f, $0f, $0f, $00, $00, $00
  657.     db $0f, $0f, $0f, $0f, $0f, $0f, $0f, $0f
  658.     db $0f, $0f, $0f, $0f, $0f, $0f, $0f, $0f
  659.     db $00, $00, $00, $00, $00, $00, $00, $00
  660.     db $00, $00, $00, $00, $00, $00, $00, $00
  661.     db $00, $00, $00, $00, $00, $00, $00, $00
  662.     db $00, $00, $00, $00, $00, $00, $00, $00
  663.    
  664.     db $01, $01, $01, $01, $01, $01, $01, $01
  665.     db $01, $01, $01, $01, $01, $01, $01, $01
  666.     db $00, $00, $00, $00, $00, $00, $00, $00
  667.     db $00, $00, $00, $00, $00, $00, $00, $00
  668.     db $00, $00, $00, $00, $00, $00, $00, $00
  669.     db $00, $00, $00, $00, $00, $00, $00, $00
  670.     db $00, $00, $00, $00, $00, $00, $00, $00
  671.     db $00, $00, $00, $00, $00, $00, $00, $0f
  672. ; 4cf1f
  673.  
  674.  
  675. Function97c5f: ; 97c5f
  676.     call $2a07
  677.     ld [$d03e], a
  678.     ld c, a
  679.     ld a, $04
  680.     ld hl, $765b
  681.     rst $08 ; call 04:765b
  682.     jr c, .asm_97cb9 ; quit?
  683.     call $1894
  684.     jr nz, .asm_97c7b ; skip?
  685.     ld a, $03
  686.     ld hl, $5186
  687.     rst $08 ; call d186
  688.     jr .asm_97cb9
  689. .asm_97c7b
  690.     ld a, [$d03e]
  691.     call $18b4
  692.     jr nz, .asm_97c8b
  693.     ld a, $03
  694.     ld hl, $4e3e
  695.     rst $08 ; call ce3e
  696.     jr .asm_97cb9
  697. .asm_97c8b
  698.     ld a, [$d03e]
  699.     call $18bd
  700.     jr nz, .asm_97c9b
  701.     ld a, $03
  702.     ld hl, $4b56
  703.     rst $08 ; call cb56
  704.     jr .asm_97cb9 ; quit?
  705. .asm_97c9b
  706.     ld a, [$d03e]
  707.     call $189a
  708.     jr nz, .asm_97cad
  709.     ld a, $03
  710.     ld hl, $4ec9
  711.     rst $08 ; call cec9
  712.     jr c, .asm_97cb9
  713.     jr .asm_97cb7
  714. .asm_97cad
  715.     ld a, BANK(CheckSurf)
  716.     ld hl, CheckSurf
  717.     rst $08
  718. ;
Add Comment
Please, Sign In to add comment