Fix some incbins near Magikarp length code.

Also clean up the comments a little.
This commit is contained in:
yenatch
2014-12-03 20:06:40 -08:00
parent 97e3d9ac10
commit 2f509ab379
2 changed files with 130 additions and 123 deletions

View File

@@ -1,27 +1,24 @@
CalcMagikarpLength: ; fbbfc CalcMagikarpLength: ; fbbfc
; Return Magikarp's length (in mm) in MagikarpLength (big endian) ; Return Magikarp's length (in mm) at MagikarpLength (big endian).
; ;
; input: ; input:
; de: EnemyMonDVs ; de: EnemyMonDVs
; bc: PlayerID ; bc: PlayerID
; This function is needlessly convoluted, and poorly commented. ; This function is poorly commented.
; Reading is discouraged.
; In short, it generates a value between 190 and 1786 using ; In short, it generates a value between 190 and 1786 using
; a Magikarp's DVs and its trainer ID. This value is further ; a Magikarp's DVs and its trainer ID. This value is further
; scrutinized in GetEnemyMon to make longer Magikarp even rarer. ; filtered in LoadEnemyMon to make longer Magikarp even rarer.
; This is done by calculating the value using operands from ; The value is generated from a lookup table.
; a conversion lookup table. ; The index is determined by the dv xored with the player's trainer id.
; Our index is calculated by xoring DVs with the trainer ID: ; bc = rrc(dv[0]) ++ rrc(dv[1]) ^ rrc(id)
; bc = rrc(rrc(dvs)) xor rrc(id) ; if bc < 10: [MagikarpLength] = c + 190
; if bc >= $ff00: [MagikarpLength] = c + 1370
; if bc < $a: MagikarpLength = c + 190 ; else: [MagikarpLength] = z * 100 + (bc - x) / y
; if bc >= $ff00: MagikarpLength = c + 1370
; else: MagikarpLength = z*100 + (bc-x)/y
; X, Y, and Z depend on the value of b as follows: ; X, Y, and Z depend on the value of b as follows:
@@ -38,12 +35,10 @@ CalcMagikarpLength: ; fbbfc
; if b = 252-253: x = 65210, y = 5, z = 13 ; if b = 252-253: x = 65210, y = 5, z = 13
; if b = 254: x = 65410, y = 2, z = 14 ; if b = 254: x = 65410, y = 2, z = 14
; These values represent arbitrary conversion points.
; bc = rrc(dv[0]) ++ rrc(dv[1]) ^ rrc(id)
; b = rrcrrc(atkdefdv) xor rrc(id[0]) ; id
; id
ld h, b ld h, b
ld l, c ld l, c
ld a, [hli] ld a, [hli]
@@ -52,7 +47,7 @@ CalcMagikarpLength: ; fbbfc
rrc b rrc b
rrc c rrc c
; dvs ; dv
ld a, [de] ld a, [de]
inc de inc de
rrca rrca
@@ -60,114 +55,116 @@ CalcMagikarpLength: ; fbbfc
xor b xor b
ld b, a ld b, a
; c = rrcrrc(spdspcdv) xor rrc(id[1])
ld a, [de] ld a, [de]
rrca rrca
rrca rrca
xor c xor c
ld c, a ld c, a
; if bc < $000a: ; if bc < 10:
; de = bc + 190
; break
ld a, b ld a, b
and a and a
jr nz, .loadtable jr nz, .no
ld a, c ld a, c
cp a, $a cp 10
jr nc, .loadtable jr nc, .no
; de = hl = bc + $be ld hl, 190
ld hl, $be
add hl, bc add hl, bc
ld d, h ld d, h
ld e, l ld e, l
jr .endtable jr .done
.loadtable .no
ld hl, .MagikarpLengthTable
ld a, $02 ld hl, .Lengths
ld a, 2
ld [$d265], a ld [$d265], a
.readtable .read
ld a, [hli] ld a, [hli]
ld e, a ld e, a
ld a, [hli] ld a, [hli]
ld d, a ld d, a
call .BLessThanD call .BCLessThanDE
jr nc, .advancetable jr nc, .next
; c = bc / [hl] ; c = (bc - de) / [hl]
call .BCMinusDE call .BCMinusDE
ld a, b ld a, b
ld [$ffb3], a ld [hDividend + 0], a
ld a, c ld a, c
ld [$ffb4], a ld [hDividend + 1], a
ld a, [hl] ld a, [hl]
ld [$ffb7], a ld [hDivisor], a
ld b, $02 ld b, 2
call Divide call Divide
ld a, [$ffb6] ld a, [hQuotient + 2]
ld c, a ld c, a
; de = c + 100 * (2 + number of rows down the table) ; de = c + 100 * (2 + i)
xor a xor a
ld [$ffb4], a ld [hMultiplicand + 0], a
ld [$ffb5], a ld [hMultiplicand + 1], a
ld a, $64 ld a, 100
ld [$ffb6], a ld [hMultiplicand + 2], a
ld a, [$d265] ld a, [$d265]
ld [$ffb7], a ld [hMultiplier], a
call Multiply call Multiply
ld b, $00 ld b, 0
ld a, [$ffb6] ld a, [hProduct + 3]
add c add c
ld e, a ld e, a
ld a, [$ffb5] ld a, [hProduct + 2]
adc b adc b
ld d, a ld d, a
jr .endtable jr .done
.advancetable .next
inc hl ; align to next triplet inc hl ; align to next triplet
ld a, [$d265] ld a, [$d265]
inc a inc a
ld [$d265], a ld [$d265], a
cp a, $10 cp 16
jr c, .readtable jr c, .read
call .BCMinusDE call .BCMinusDE
ld hl, $0640 ld hl, 1600
add hl, bc add hl, bc
ld d, h ld d, h
ld e, l ld e, l
.endtable .done
; hl = de * 10
ld h, d ld h, d
ld l, e ld l, e
add hl, hl add hl, hl
add hl, hl add hl, hl
add hl, de add hl, de
add hl, hl ; hl = de * 10 add hl, hl
ld de, $ff02 ; hl = hl / 254
ld a, $ff ld de, -254
.loop ld a, -1
.div_254
inc a inc a
add hl, de ; - 254 add hl, de
jr c, .loop jr c, .div_254
ld d, $00 ; d, e = hl / 12, hl % 12
ld d, 0
; mod $0c .mod_12
.modloop cp 12
cp a, $0c jr c, .ok
jr c, .done sub 12
sub a, $0c
inc d inc d
jr .modloop jr .mod_12
.ok
.done
ld e, a ld e, a
ld hl, MagikarpLength ld hl, MagikarpLength
ld [hl], d ld [hl], d
inc hl inc hl
@@ -175,22 +172,19 @@ CalcMagikarpLength: ; fbbfc
ret ret
; fbc9a ; fbc9a
.BLessThanD ; fbc9a .BCLessThanDE: ; fbc9a
; return carry if b < d ; Intention: Return bc < de.
; Reality: Return b < d.
ld a, b ld a, b
cp d cp d
ret c ret c
ret nc ret nc ; whoops
; fbc9e
.CLessThanE ; fbc9e
; unused
ld a, c ld a, c
cp e cp e
ret ret
; fbca1 ; fbca1
.BCMinusDE ; fbca1 .BCMinusDE: ; fbca1
; bc -= de ; bc -= de
ld a, c ld a, c
sub e sub e
@@ -201,20 +195,21 @@ CalcMagikarpLength: ; fbbfc
ret ret
; fbca8 ; fbca8
.MagikarpLengthTable ; fbca8 .Lengths: ; fbca8
; ????, divisor ; ????, divisor
dwb $006e, $01 dwb 110, 1
dwb $0136, $02 dwb 310, 2
dwb $02c6, $04 dwb 710, 4
dwb $0a96, $14 dwb 2710, 20
dwb $1e1e, $32 dwb 7710, 50
dwb $452e, $64 dwb 17710, 100
dwb $7fc6, $96 dwb 32710, 150
dwb $ba5e, $96 dwb 47710, 150
dwb $e16e, $64 dwb 57710, 100
dwb $f4f6, $32 dwb 62710, 50
dwb $fcc6, $14 dwb 64710, 20
dwb $feba, $05 dwb 65210, 5
dwb $ff82, $02 dwb 65410, 2
; fbccf dwb 65510, 1 ; not used
; fbcd2

View File

@@ -97840,7 +97840,11 @@ Functione546d: ; e546d (39:546d)
; e5496 (39:5496) ; e5496 (39:5496)
Unknown_e5496: ; e5496 Unknown_e5496: ; e5496
INCBIN "baserom.gbc",$e5496,$e549e - $e5496 dw Unknown_e799d
dw Unknown_e79dd
dw Unknown_e7a1d
dw Unknown_e79dd
; e549e
Functione549e: ; e549e (39:549e) Functione549e: ; e549e (39:549e)
ld a, $1 ld a, $1
@@ -98072,7 +98076,12 @@ IntroUnownBackGFX: ; e785d
INCBIN "gfx/intro/unown_back.2bpp.lz" INCBIN "gfx/intro/unown_back.2bpp.lz"
; e799d ; e799d
INCBIN "baserom.gbc", $e799d, $e7a5d - $e799d Unknown_e799d: ; e799d
INCBIN "baserom.gbc", $e799d, $e79dd - $e799d
Unknown_e79dd: ; e79dd
INCBIN "baserom.gbc", $e79dd, $e7a1d - $e79dd
Unknown_e7a1d: ; e7a1d
INCBIN "baserom.gbc", $e7a1d, $e7a5d - $e7a1d
GFX_e7a5d: ; e7a5d GFX_e7a5d: ; e7a5d
INCBIN "baserom.gbc", $e7a5d, $e7a6d - $e7a5d INCBIN "baserom.gbc", $e7a5d, $e7a6d - $e7a5d
@@ -98168,25 +98177,26 @@ INCBIN "baserom.gbc", $fb434, $fb449 - $fb434
Functionfb449:: ; fb449 Functionfb449:: ; fb449
ld de, Font ld de, Font
ld hl, VTiles1 ld hl, VTiles1
ld bc, Function3e80 lb bc, BANK(Font), $400 / 8
ld a, [rLCDC] ld a, [rLCDC]
bit 7, a bit 7, a
jp z, Copy1bpp jp z, Copy1bpp
ld de, Font ld de, Font
ld hl, VTiles1 ld hl, VTiles1
ld bc, $3e20 lb bc, BANK(Font), $100 / 8
call Functionddc call Functionddc
ld de, $4300 ld de, Font + $100
ld hl, $8a00 ld hl, VTiles1 + $200
ld bc, $3e20 lb bc, BANK(Font), $100 / 8
call Functionddc call Functionddc
ld de, $4400 ld de, Font + $200
ld hl, $8c00 ld hl, VTiles1 + $400
ld bc, $3e20 lb bc, BANK(Font), $100 / 8
call Functionddc call Functionddc
ld de, $4500 ld de, Font + $300
ld hl, $8e00 ld hl, VTiles1 + $600
ld bc, $3e20 lb bc, BANK(Font), $100 / 8
call Functionddc call Functionddc
ret ret
; fb48a ; fb48a
@@ -99185,26 +99195,28 @@ Functionfbbdb: ; fbbdb
call PrintNum call PrintNum
ld [hl], $6f ld [hl], $6f
inc hl inc hl
ld [hl], $50 ld [hl], "@"
ret ret
; fbbfc ; fbbfc
INCLUDE "battle/magikarp_length.asm" INCLUDE "battle/magikarp_length.asm"
INCBIN "baserom.gbc",$fbccf,$fbcd2 - $fbccf
Functionfbcd2: ; fbcd2 Functionfbcd2: ; fbcd2
ld a, [$dfe8] ld a, [$dfe8]
ld [Buffer1], a ld [Buffer1], a
ld a, [$dfe9] ld a, [$dfe9]
ld [Buffer2], a ld [Buffer2], a
call Functionfbbdb call Functionfbbdb
ld hl, $7ce8 ld hl, UnknownText_0xfbce8
call PrintText call PrintText
ret ret
; fbce8 ; fbce8
INCBIN "baserom.gbc",$fbce8,$fbced - $fbce8 UnknownText_0xfbce8: ; 0xfbce8
; "CURRENT RECORD"
text_jump UnknownText_0x1c123a
db "@"
; 0xfbced
INCLUDE "battle/hidden_power.asm" INCLUDE "battle/hidden_power.asm"