View difference between Paste ID: 1ARTkNq0 and PWbgR64d
SHOW: | | - or go back to the newest paste.
1
; this has been made over the routine that loads an enemy Pokemon
2
; had to find a point to break the routine where
3
; 1: stats had already been loaded into RAM
4
; 2: working with registers bc, de, and hl was not a problem (for convenience) 
5
6
#org 3EB10
7
jp Main ; jumps to the new stuff 
8
9
Main:
10
#org 3FE88
11
ld a,(D22D)
12
cp a, 2 ; are we in a trainer battle?
13
jp z, ApplyStatBoosts ; if so the stat boosts are applied, otherwise fallthrough
14
#org 3FE90
15
Original:
16
; original routine stuff, that is, original 3EB10-3EB37
17
ld hl,D073 
18
ld de,C616
19
ld bc,000B
20
call Label3026
21
ld a,(D204)
22
dec a
23
ld c,a
24
ld b,01
25
ld hl,DEB9
26
ld a,03
27
call Label2D83
28
ld hl,D21A
29
ld de,C6C1
30
ld bc,000A
31
call Label3026 
32
ret ; the original routine finishes at this point
33
34
ApplyStatBoosts:
35
;   [1,32]: no boost
36
;  [33,34]: boost = level/16 = 2
37
;  [35,54]: boost = level/16 + level/32
38
;  [55,73]: boost = level/8
39
;  [74,77]: boost = level/8 + level/16
40
; [78,100]: boost = level/4
41
 
42
ld hl,D21B ; point to the first stat LSB (attack)
43
ld c,5 ; there are five stats
44
ld a,(D143) ; get enemy's level 
45
46
level78to100:
47
cp a,4E
48
jr c,level74to77 ; if not between 78 and 100, skip
49
ld d,2 ; level will be halved twice
50
call boost ; boost the stats 
51
jr Original ; we are done
52
53
level74to77:
54
cp a,4A
55
jr c,level55to73
56
ld d,3
57
call boost ; level/(2^3) = level/8
58
ld hl,D21B 
59
ld c,5
60
ld d,4
61
call boost ; level/(2^4) = level/16 --> level/8 + level/16
62
jr Original ; 
63
64
level55to73:
65
cp a,37
66
jr c,level36to54
67
ld d,3
68
call boost
69
jr Original
70
71
level35to54:
72
cp a,23
73
jr c,level33to34
74
ld d,4
75
call boost
76
ld hl,D21B
77
ld c,5
78
ld d,5
79
call boost
80
jr Original
81
82
level33to34:
83
cp a,21
84
jr c,level0to32
85
ld d,4
86
call boost ; fallthrough
87
88
level0to32:
89
jr Original ; no boost if level<33
90
91
#org 3EB13
92
boost:
93
ld a,(D143) ; get enemy's level (a gets overwritten on every loop)
94
ld b,a
95
ld e,d ; save d for later
96
halve: ; halve level d times
97
slr b
98
dec d
99
jr nz,halve
100
ld a,(hl) ; a = attack LSB before boost has been applied
101
add a,b 
102
ld (hl),a ; load a+b into the stat
103
jr nc,finish ; overflow check
104
dec hl ; if overflow, add 0x100 to the stat
105
inc (hl) ; inc MSB
106
inc hl ; point to LSB again
107
finish:
108
inc hl
109
inc hl ; point to the next stat LSB
110
dec c ; one less stat left
111
ld d,e 
112
jr nz,boost ; loop if not done
113
ret ; otherwise return