comment last commit

This commit is contained in:
padz
2012-09-16 21:20:04 -04:00
parent 4c1ef2aef5
commit e8b7789127
2 changed files with 151 additions and 98 deletions

230
main.asm
View File

@@ -128,16 +128,26 @@ EnableLCD: ; 58a
INCBIN "baserom.gbc",$591,$984 - $591 INCBIN "baserom.gbc",$591,$984 - $591
GetJoypadState; 984 GetJoypadState; 984
; stores joypad state in $ffa8
; 0 is off, 1 is on
; bit 0: A
; 1: B
; 2: SELECT
; 3: START
; 4: RIGHT
; 5: LEFT
; 6: UP
; 7: DOWN
push af push af
push hl push hl
push de push de
push bc push bc
ld a,[$c2c7] ld a, [$c2c7]
cp a, $ff cp a, $ff
jr z, .asm_9a7 jr z, .asm_9a7
ld a,[$ff00+$a4] ld a, [$ff00+$a4] ; input mask (usually 00)
ld b, a ld b, a
ld a,[$ff00+$a8] ld a, [$ff00+$a8] ; joypad
ld e, a ld e, a
xor b xor b
ld d, a ld d, a
@@ -149,14 +159,14 @@ GetJoypadState; 984
ld c, a ld c, a
ld a, b ld a, b
ld [$ff00+$a8], a ld [$ff00+$a8], a
.asm_9a2 .quit
pop bc pop bc
pop de pop de
pop hl pop hl
pop af pop af
ret ret
.asm_9a7 .asm_9a7
ld a,[$ff00+$9d] ld a, [$ff00+$9d]
push af push af
ld a, [$c2ca] ld a, [$c2ca]
rst $10 rst $10
@@ -171,7 +181,7 @@ GetJoypadState; 984
ld [$c2cb], a ld [$c2cb], a
pop af pop af
rst $10 rst $10
jr .asm_9a2 jr .quit
.asm_9c2 .asm_9c2
ld a, [hli] ld a, [hli]
cp a, $ff cp a, $ff
@@ -200,7 +210,7 @@ GetJoypadState; 984
ld a, b ld a, b
ld [$ff00+$a7], a ld [$ff00+$a7], a
ld [$ff00+$a8], a ld [$ff00+$a8], a
jr .asm_9a2 jr .quit
ld [$c2ca], a ld [$c2ca], a
ld a, l ld a, l
ld [$c2c8], a ld [$c2c8], a
@@ -218,6 +228,7 @@ GetJoypadState; 984
;a0a ;a0a
Functiona0a: Functiona0a:
; clears $c2c7-$c2cb
xor a xor a
ld [$c2ca], a ld [$c2ca], a
ld [$c2c8], a ld [$c2c8], a
@@ -903,10 +914,26 @@ AddNTimes: ; 0x30fe
INCBIN "baserom.gbc",$3105,$3119-$3105 INCBIN "baserom.gbc",$3105,$3119-$3105
Multiply: ; 0x3119 Multiply: ; 0x3119
; function to do multiplication
; all values are big endian
; INPUT
; ffb4-ffb6 = multiplicand
; ffb7 = multiplier
; OUTPUT
; ffb3-ffb6 = product
INCBIN "baserom.gbc",$3119,$3124 - $3119 INCBIN "baserom.gbc",$3119,$3124 - $3119
; 0x3124 ; 0x3124
Divide: ; 0x3124 Divide: ; 0x3124
; function to do division
; all values are big endian
; INPUT
; ffb3-ffb6 = dividend
; ffb7 = divisor
; b = number of bytes in the dividend (starting from ffb3)
; OUTPUT
; ffb4-ffb6 = quotient
; ffb7 = remainder
INCBIN "baserom.gbc",$3124,$3136 - $3124 INCBIN "baserom.gbc",$3124,$3136 - $3124
; 0x3136 ; 0x3136
@@ -914,8 +941,9 @@ INCBIN "baserom.gbc",$3136,$313d - $3136
PrintLetterDelay: ; 313d PrintLetterDelay: ; 313d
; This function is used to wait a short period after printing a letter to the ; This function is used to wait a short period after printing a letter to the
; screen unless the player presses the A/B button or the delay is turned off ; screen unless the delay is turned off through bit 4 (on) in [$cfcc] or bit
; through the [$cfcc] or [$cfcf] flags. ; 1 (off) in [$cfcf]. If A and B are pressed, bits 0-2 in [$cfcc] and bit 0 in
; [$cfcf] are checked.
ld a, [$cfcc] ld a, [$cfcc]
bit 4, a bit 4, a
ret nz ret nz
@@ -933,31 +961,31 @@ PrintLetterDelay: ; 313d
bit 0, a bit 0, a
jr z, .asm_3160 jr z, .asm_3160
ld a, [$cfcc] ld a, [$cfcc]
and a, $07 and a, $07 ; takes bits 0-2 of $cfcc
jr .asm_3162 jr .asm_3162
.asm_3160 .asm_3160
ld a, $01 ld a, $01
.asm_3162 .asm_3162
ld [$cfb2], a ld [$cfb2], a
.joypad .checkjoypad
call GetJoypadState call GetJoypadState
ld a, [$c2d7] ld a, [$c2d7]
and a and a
jr nz, .asm_317f jr nz, .asm_317f
ld a, [$ff00+$a8] ; joypad ld a, [$ff00+$a8] ; joypad
bit 0, a ; a bit 0, a ; is a pressed?
jr z, .asm_3176 jr z, .anotpressed
jr .asm_317a jr .delay
.asm_3176 .anotpressed
bit 1, a ; b bit 1, a ; is b pressed?
jr z, .asm_317f jr z, .asm_317f
.asm_317a .delay
call DelayFrame call DelayFrame
jr .end jr .end
.asm_317f .asm_317f
ld a, [$cfb2] ld a, [$cfb2]
and a and a
jr nz, .joypad jr nz, .checkjoypad
.end .end
pop af pop af
ld [$ff00+$d8], a ld [$ff00+$d8], a
@@ -10732,7 +10760,7 @@ IsJohtoGymLeader: ; 0x3d128
ld hl, JohtoGymLeaders ld hl, JohtoGymLeaders
IsGymLeaderCommon: IsGymLeaderCommon:
push de push de
ld a, [$d22f] ld a, [OtherTrainerClass]
ld de, $0001 ld de, $0001
call IsInArray call IsInArray
pop de pop de
@@ -10802,7 +10830,7 @@ Function3e8eb: ; 3e8eb
ld a, [hl] ld a, [hl]
jr .asm_3e945 jr .asm_3e945
.asm_3e925 .asm_3e925
ld a, [$d230] ld a, [BattleType]
cp a, $0a cp a, $0a
ld a, [$d241] ld a, [$d241]
jr z, .asm_3e945 jr z, .asm_3e945
@@ -10838,7 +10866,7 @@ Function3e8eb: ; 3e8eb
ld a, [$d22d] ld a, [$d22d]
dec a dec a
jr nz, .asm_3e9a8 jr nz, .asm_3e9a8
ld a, [$d230] ld a, [BattleType]
cp a, $05 cp a, $05
jr nz, .asm_3e996 jr nz, .asm_3e996
call $7a01 call $7a01
@@ -10882,22 +10910,22 @@ Function3e8eb: ; 3e8eb
jr nz, .asm_3ea1a jr nz, .asm_3ea1a
ld a, [EnemyMonSpecies] ld a, [EnemyMonSpecies]
cp a, UNOWN cp a, UNOWN
jr nz, .asm_3e9c8 jr nz, .notunown
ld hl, EnemyMonDVs ld hl, EnemyMonDVs
ld a, $2d ld a, $2d
call $2d83 call $2d83
call CheckUnownLetter call CheckUnownLetter
jr c, .asm_3e9a0 jr c, .asm_3e9a0
.asm_3e9c8 .notunown
ld a, [EnemyMonSpecies] ld a, [EnemyMonSpecies]
cp a, MAGIKARP cp a, MAGIKARP
jr nz, .asm_3ea1a jr nz, .asm_3ea1a
ld de, $d20c ld de, EnemyMonDVs
ld bc, PlayerID ld bc, PlayerID
ld hl, Functionfbbfc ld hl, CalcMagikarpLength
ld a, BANK(Functionfbbfc) ld a, BANK(CalcMagikarpLength)
rst $08 rst $08
ld a, [$d1ea] ld a, [$d1ea] ; Magikarp's length
cp a, $06 cp a, $06
jr nz, .asm_3e9fe jr nz, .asm_3e9fe
call $2f8c call $2f8c
@@ -10957,7 +10985,7 @@ Function3e8eb: ; 3e8eb
ld [hli], a ld [hli], a
ld a, [$d219] ; EnemyMonMaxHP + 1 ld a, [$d219] ; EnemyMonMaxHP + 1
ld [hl], a ld [hl], a
ld a, [$d230] ld a, [BattleType]
cp a, $05 cp a, $05
jr nz, .asm_3ea90 jr nz, .asm_3ea90
call $7a01 call $7a01
@@ -11069,22 +11097,22 @@ Function3e8eb: ; 3e8eb
; 3eb38 ; 3eb38
CheckSleepingWildMon: ; 3eb38 CheckSleepingWildMon: ; 3eb38
ld a, [$d230] ld a, [BattleType]
cp a, $08 ; headbutt encounter? cp a, $08 ; headbutt
jr nz, .asm_3eb5b jr nz, .notsleeping
ld hl, SleepingWildMonMornTable ld hl, SleepingWildMonMornTable
ld a, [TimeOfDay] ld a, [TimeOfDay]
cp a, $01 cp a, $01 ; day
jr c, .asm_3eb51 jr c, .check
ld hl, SleepingWildMonDayTable ld hl, SleepingWildMonDayTable
jr z, .asm_3eb51 jr z, .check
ld hl, SleepingWildMonNiteTable ld hl, SleepingWildMonNiteTable
.asm_3eb51 .check
ld a, [EnemyMonSpecies] ld a, [EnemyMonSpecies]
ld de, $0001 ld de, $0001
call IsInArray call IsInArray
ret c ret c
.asm_3eb5b .notsleeping
and a and a
ret ret
; 3eb5d ; 3eb5d
@@ -11123,11 +11151,12 @@ SleepingWildMonMornTable ; 3eb6f
; 3eb75 ; 3eb75
CheckUnownLetter: ; 3eb75 CheckUnownLetter: ; 3eb75
; returns carry if not a valid letter
ld a, [$def3] ld a, [$def3]
ld c, a ld c, a
ld de, $0000 ld de, $0000
.asm_3eb7c .asm_3eb7c
srl c srl c ; bit 0 off?
jr nc, .asm_3eb96 jr nc, .asm_3eb96
ld hl, UnownLetterPointerTable ld hl, UnownLetterPointerTable
add hl, de add hl, de
@@ -11141,16 +11170,16 @@ CheckUnownLetter: ; 3eb75
call IsInArray call IsInArray
pop bc pop bc
pop de pop de
jr c, .asm_3eb9f jr c, .end
.asm_3eb96 .asm_3eb96
inc e inc e
inc e inc e
ld a, e ld a, e
cp a, $08 cp a, $08 ; has the end of the table been reached?
jr c, .asm_3eb7c jr c, .asm_3eb7c
scf scf
ret ret
.asm_3eb9f .end
and a and a
ret ret
@@ -73649,18 +73678,23 @@ INCBIN "gfx/font_battle_extra.2bpp",$0,$200
INCBIN "baserom.gbc",$F8800,$3bfc-$800 INCBIN "baserom.gbc",$F8800,$3bfc-$800
Functionfbbfc ; fbbfc CalcMagikarpLength: ; fbbfc
;input: ; Stores Magikarp's length at $d1ea-$d1eb in big endian
; d: $d2 ;
; e: $0c ; input:
; b: $d4 ; PlayerID ; de: EnemyMonDVs
; c: $7b ; PlayerID ; bc: PlayerID
; a: BANK(Functionfbbfc) $3e ; output:
; $d1ea-$d1eb: length
;
; does a whole bunch of arbitrary nonsense
; cycles through a table of arbitrary values
; http://web.archive.org/web/20110628181718/http://upokecenter.com/games/gs/guides/magikarp.php
ld h, b ld h, b
ld l, c ld l, c
ld a, [hli] ld a, [hli]
ld b, a ld b, a
ld c, [hl] ; ld bc, [bc] ld c, [hl] ; ld bc, [PlayerID]
rrc b rrc b
rrc c rrc c
ld a, [de] ld a, [de]
@@ -73668,35 +73702,35 @@ Functionfbbfc ; fbbfc
rrca rrca
rrca rrca
xor b xor b
ld b, a ld b, a ; b = rrcrrc(atkdefdv) xor rrc(hipid)
ld a, [de] ld a, [de]
rrca rrca
rrca rrca
xor c xor c
ld c, a ld c, a ; c = rrcrrc(spdspcdv) xor rrc(lopid)
ld a, b ld a, b
and a and a
jr nz, .asm_fbc21 jr nz, .loadtable
ld a, c ld a, c
cp a, $0a cp a, $0a
jr nc, .asm_fbc21 jr nc, .loadtable
ld hl, $00be ld hl, $00be ; if bc < $000a
add hl, bc add hl, bc ; hl = $00be + bc
ld d, h ld d, h ; de = hl
ld e, l ld e, l
jr .asm_fbc78 jr .endtable
.asm_fbc21 .loadtable
ld hl, Tablefbca8 ld hl, MagikarpLengthTable
ld a, $02 ld a, $02
ld [$d265], a ld [$d265], a
.asm_fbc29 .readtable
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 Functionfbc9a call BLessThanD ; checks value against the table
jr nc, .asm_fbc63 jr nc, .advancetable
call Functionfbca1 call BCMinusDE
ld a, b ld a, b
ld [$ff00+$b3], a ld [$ff00+$b3], a
ld a, c ld a, c
@@ -73706,7 +73740,7 @@ Functionfbbfc ; fbbfc
ld b, $02 ld b, $02
call Divide call Divide
ld a, [$ff00+$b6] ld a, [$ff00+$b6]
ld c, a ld c, a ; c = bc / [hl]
xor a xor a
ld [$ff00+$b4], a ld [$ff00+$b4], a
ld [$ff00+$b5], a ld [$ff00+$b5], a
@@ -73714,7 +73748,7 @@ Functionfbbfc ; fbbfc
ld [$ff00+$b6], a ld [$ff00+$b6], a
ld a, [$d265] ld a, [$d265]
ld [$ff00+$b7], a ld [$ff00+$b7], a
call Multiply call Multiply ; $64 * (2 + number of rows down the table)
ld b, $00 ld b, $00
ld a, [$ff00+$b6] ld a, [$ff00+$b6]
add c add c
@@ -73722,40 +73756,40 @@ Functionfbbfc ; fbbfc
ld a, [$ff00+$b5] ld a, [$ff00+$b5]
adc b adc b
ld d, a ld d, a
jr .asm_fbc78 jr .endtable
.asm_fbc63 .advancetable
inc hl inc hl ; aligning to next byte triplet
ld a, [$d265] ld a, [$d265]
inc a inc a
ld [$d265], a ld [$d265], a
cp a, $10 cp a, $10
jr c, .asm_fbc29 jr c, .readtable
call Functionfbca1 call BCMinusDE
ld hl, $0640 ld hl, $0640
add hl, bc add hl, bc
ld d, h ld d, h
ld e, l ld e, l
.asm_fbc78 .endtable
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 add hl, hl ; hl = de * 10
ld de, $ff02 ld de, $ff02
ld a, $ff ld a, $ff
.asm_fbc83 .loop
inc a inc a
add hl, de add hl, de ; - 254
jr c, .asm_fbc83 jr c, .loop
ld d, $00 ld d, $00
.asm_fbc89 ; mod $0c .modloop ; mod $0c
cp a, $0c cp a, $0c
jr c, .asm_fbc92 jr c, .done
sub a, $0c sub a, $0c
inc d inc d
jr .asm_fbc89 jr .modloop
.asm_fbc92 .done
ld e, a ld e, a
ld hl, $d1ea ld hl, $d1ea
ld [hl], d ld [hl], d
@@ -73764,17 +73798,23 @@ Functionfbbfc ; fbbfc
ret ret
; fbc9a ; fbc9a
Functionfbc9a: ; fbc9a BLessThanD: ; fbc9a
; returns carry if b < d
ld a, b ld a, b
cp d cp d
ret c ret c
ret nc ret nc
; fbc9e
CLessThanE: ;fbc9e
; unused
ld a, c ld a, c
cp e cp e
ret ret
; fbca1 ; fbca1
Functionfbca1: ; fbca1 BCMinusDE: ; fbca1
; stores bc - de in bc
ld a, c ld a, c
sub e sub e
ld c, a ld c, a
@@ -73782,18 +73822,28 @@ Functionfbca1: ; fbca1
sbc d sbc d
ld b, a ld b, a
ret ret
; fbcab ; fbca8
Tablefbca8: ; fbca8 MagikarpLengthTable: ; fbca8
db $6e, $00, $01, $36, $01, $02, $c6, $02 ; stored in sets of 3
db $04, $96, $0a, $14, $1e, $1e, $32, $2e ; first two values are little endian
db $45, $64, $c6, $7f, $96, $5e, $ba, $96 ; third value is the divisor
db $6e, $e1, $64, $f6, $f4, $32, $c6, $fc db $6e, $00, $01
db $14, $ba, $fe, $05, $82, $ff db $36, $01, $02
db $02, $e6, $ff db $c6, $02, $04
; fbcd1 db $96, $0a, $14
db $1e, $1e, $32
db $2e, $45, $64
db $c6, $7f, $96
db $5e, $ba, $96
db $6e, $e1, $64
db $f6, $f4, $32
db $c6, $fc, $14
db $ba, $fe, $05
db $82, $ff, $02
; fbccf
INCBIN "baserom.gbc",$FBCD1,$fc000-$fbcd1 INCBIN "baserom.gbc",$FBCCF,$fc000-$fbccf
SECTION "bank3F",DATA,BANK[$3F] SECTION "bank3F",DATA,BANK[$3F]

View File

@@ -130,8 +130,9 @@ OtherTrainerClass: ; 0xd22f
; 0 if opponent is a wild Pokémon, not a trainer ; 0 if opponent is a wild Pokémon, not a trainer
ds 1 ds 1
Wramd230: ; 0xd230 BattleType: ; 0xd230
; XXX what is this for ; 00 trainer
; 08 headbutt
ds 1 ds 1
OtherTrainerID: ; 0xd231 OtherTrainerID: ; 0xd231
@@ -139,7 +140,7 @@ OtherTrainerID: ; 0xd231
; (Joey, Mikey, Albert, etc.) ; (Joey, Mikey, Albert, etc.)
ds 1 ds 1
SECTION "Timeofday",BSS[$d269] SECTION "TimeOfDay",BSS[$d269]
TimeOfDay: ; 0xd269 TimeOfDay: ; 0xd269
; 0 if morn ; 0 if morn
@@ -686,14 +687,14 @@ PlayerName: ; 0xd47d
PlayerSprite: ; 0xd4d8 PlayerSprite: ; 0xd4d8
ds 1 ds 1
SECTION "Misc",BSS[$d857] SECTION "Status",BSS[$d84e]
Money: ; d84e Money: ; d84e
ds 3 ds 3
Badges: ; d857 Badges: ; d857
ds 2 ds 2
SECTION "Items",BSS[$d8bd] SECTION "Items",BSS[$d859]
TMsHMs: ; d859 TMsHMs: ; d859
ds 57 ds 57
@@ -702,9 +703,9 @@ NumItems: ; d892
Items: ; d893 Items: ; d893
ds 69 ds 69
NumKeyItems: ; d88c NumKeyItems: ; d8bc
ds 1 ds 1
KeyItems: ; d88d KeyItems: ; d8bd
ds 13 ds 13
NumBalls: ; d8d7 NumBalls: ; d8d7
@@ -801,12 +802,13 @@ PartySpecies: ; 0xdcd8
ds 1 ; any empty slots including the 7th must be FF ds 1 ; any empty slots including the 7th must be FF
; or the routine will keep going ; or the routine will keep going
PartyMons:
PartyMon1: PartyMon1:
PartyMon1Species: ; 0xdcdf PartyMon1Species: ; 0xdcdf
ds 1 ds 1
PartyMon1Item: ; 0xdce0 PartyMon1Item: ; 0xdce0
ds 1 ds 1
PartyMon1Moves: ; 0xdce1 PartyMon1Moves: ; 0xdce1
PartyMon1Move1: ; 0xdce1 PartyMon1Move1: ; 0xdce1
ds 1 ds 1
@@ -816,6 +818,7 @@ PartyMon1Move3: ; 0xdce3
ds 1 ds 1
PartyMon1Move4: ; 0xdce4 PartyMon1Move4: ; 0xdce4
ds 1 ds 1
PartyMon1ID: ; 0xdce5 PartyMon1ID: ; 0xdce5
ds 2 ds 2
PartyMon1Exp: ; 0xdce7 PartyMon1Exp: ; 0xdce7