Advertisement
PikalaxALT

Func_f430a

Oct 11th, 2015
285
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Func_f430a:: ; f430a (3d:430a)
  2.     ld a, d
  3.     cp 4
  4.     jr z, .d_is_4_or_6
  5.     cp 6
  6.     jr z, .d_is_4_or_6
  7.     push de
  8.     callab Func_fce18
  9.     pop de
  10.     ret nc
  11.     jr .proceed
  12.  
  13. .d_is_4_or_6
  14.     ; We call a different function if d in [4, 6].
  15.     push de
  16.     callab Func_fcdb8
  17.     pop de
  18.     ret nc
  19.  
  20. .proceed
  21.     push de
  22.     ; Divide [wd470] by 100.  Hold the integer part in e.
  23.     ld e, $0
  24.     ld a, [wd470]
  25.     cp 100
  26.     jr c, .wd470_div_100
  27.     inc e
  28.     cp 200
  29.     jr c, .wd470_div_100
  30.     inc e
  31. .wd470_div_100
  32.     ; Get the (d, e) entry from Pointer_f4385.
  33.     ld c, d
  34.     dec c
  35.     ld b, $0
  36.     ld hl, Pointer_f4385
  37.     add hl, bc
  38.     add hl, bc
  39.     add hl, bc
  40.     ld d, $0
  41.     add hl, de
  42.     ld a, [hl]
  43.     ; If [hl] is positive, take min(0xff, [hl] + [wd470]).
  44.     ; If [hl] is negative, take max(0x00, [hl] + [wd470]).
  45.     ; Inexplicably, we're using 100 as the threshold for comparison.
  46.     cp 100
  47.     ld a, [wd470]
  48.     jr nc, .greater_equal_100
  49.     add [hl]
  50.     jr nc, .okay
  51.     ld a, -1
  52.     jr .okay
  53.  
  54. .greater_equal_100
  55.     add [hl]
  56.     jr c, .okay
  57.     xor a
  58. .okay
  59.     ld [wd470], a
  60.    
  61.     ; Restore d and get the d'th entry in Pointer_f43a6.
  62.     pop de
  63.     dec d
  64.     ld hl, Pointer_f43a6
  65.     ld e, d
  66.     ld d, $0
  67.     add hl, de
  68.     ld a, [hl]
  69.     ld b, a
  70.     ; If that entry is equal to $80, do not modify [wd471].
  71.     cp $80
  72.     jr z, .done
  73.     ; If that entry is less than $80, [wd471] is the lesser of that entry and [wd471].
  74.     ; If [wd49c] is not set, [wd471] is the greater of that entry and [wd471].
  75.     ld a, [wd471]
  76.     jr c, .return_if_less_than_b
  77.     cp b
  78.     jr nc, .done
  79.     ld a, [wd49c]
  80.     and a
  81.     jr nz, .done
  82.     jr .copy_b_into_wd471
  83.  
  84. .return_if_less_than_b
  85.     cp b
  86.     jr c, .done
  87. .copy_b_into_wd471
  88.     ld a, b
  89.     ld [wd471], a
  90. .done
  91.     ret
  92.    
  93. Pointer_f4385:: ; f4385 (3d:4385)
  94.     db   5,   3,   2 ; $05, $03, $02
  95.     db   5,   3,   2 ; $05, $03, $02
  96.     db   1,   1,   0 ; $01, $01, $00
  97.     db   3,   2,   1 ; $03, $02, $01
  98.     db   1,   1,   0 ; $01, $01, $00
  99.     db   2,   1,   1 ; $02, $01, $01
  100.     db  -3,  -3,  -5 ; $fd, $fd, $fb
  101.     db  -1,  -1,  -1 ; $ff, $ff, $ff
  102.     db  -5,  -5, -10 ; $fb, $fb, $f6
  103.     db  -5,  -5, -10 ; $fb, $fb, $f6
  104.     db -10, -10, -20 ; $f6, $f6, $ec
  105.  
  106. Pointer_f43a6:: ; f43a6 (3d:43a6)
  107.     db $8a
  108.     db $83
  109.     db $80
  110.     db $80
  111.     db $94
  112.     db $80
  113.     db $62
  114.     db $6c
  115.     db $62
  116.     db $6c
  117.     db $00
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement