summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.travis.yml24
-rw-r--r--INSTALL.md2
-rw-r--r--engine/add_mon.asm78
-rw-r--r--engine/bcd.asm146
-rw-r--r--home.asm2
-rw-r--r--hram.asm1
-rwxr-xr-xscripts/oakslab.asm38
7 files changed, 157 insertions, 134 deletions
diff --git a/.travis.yml b/.travis.yml
new file mode 100644
index 00000000..bd38f51b
--- /dev/null
+++ b/.travis.yml
@@ -0,0 +1,24 @@
+language: c
+install:
+ - |-
+ path="$(pwd)"; cd;
+ wget https://github.com/rednex/rgbds/archive/v0.2.5.tar.gz -O rgbds.tar.gz &&
+ tar xf rgbds.tar.gz &&
+ cd rgbds-0.2.5 &&
+ sudo make install &&
+ cd - &&
+ rm -rf rgbds &&
+ cd "$path"
+before_script:
+ - |-
+ function check_status() {
+ if ! git diff-index --quiet --ignore-submodules=all HEAD --; then
+ echo 'Uncommitted changes detected:';
+ git diff-index HEAD --;
+ return 1;
+ fi;
+ }
+script:
+ - make
+ - make compare
+ - check_status
diff --git a/INSTALL.md b/INSTALL.md
index 9bc30d6c..adcde642 100644
--- a/INSTALL.md
+++ b/INSTALL.md
@@ -44,7 +44,7 @@ To build on Windows, use [**Cygwin**](http://cygwin.com/install.html). Use the d
In the installer, select the following packages: `make` `git` `python` `gettext`
Then get the most recent version of [**rgbds**](https://github.com/bentley/rgbds/releases/).
-Extract the archive and put `rgbasm.exe`, `rgblink.exe` and `rgbfix.exe` in `C:\cygwin\usr\local\bin`.
+Extract the archive and put `rgbasm.exe`, `rgblink.exe` and `rgbfix.exe` in `C:\cygwin\usr\local\bin`. If your Cygwin installation directory differs, ensure the `bin` directory is present in the PATH variable.
In the **Cygwin terminal**:
diff --git a/engine/add_mon.asm b/engine/add_mon.asm
index 19d03942..b2feeb12 100644
--- a/engine/add_mon.asm
+++ b/engine/add_mon.asm
@@ -340,13 +340,14 @@ _AddEnemyMonToPlayerParty:
_MoveMon:
ld a, [wMoveMonType]
- and a
+ and a ; BOX_TO_PARTY
jr z, .checkPartyMonSlots
cp DAYCARE_TO_PARTY
jr z, .checkPartyMonSlots
cp PARTY_TO_DAYCARE
ld hl, wDayCareMon
- jr z, .asm_f575
+ jr z, .findMonDataSrc
+ ; else it's PARTY_TO_BOX
ld hl, wNumInBox
ld a, [hl]
cp MONS_PER_BOX
@@ -369,24 +370,26 @@ _MoveMon:
ld a, [wMoveMonType]
cp DAYCARE_TO_PARTY
ld a, [wDayCareMon]
- jr z, .asm_f556
+ jr z, .copySpecies
ld a, [wcf91]
-.asm_f556
+.copySpecies
ld [hli], a ; write new mon ID
ld [hl], $ff ; write new sentinel
+.findMonDataDest
ld a, [wMoveMonType]
dec a
ld hl, wPartyMons
ld bc, wPartyMon2 - wPartyMon1 ; $2c
ld a, [wPartyCount]
- jr nz, .skipToNewMonEntry
+ jr nz, .addMonOffset
+ ; if it's PARTY_TO_BOX
ld hl, wBoxMons
ld bc, wBoxMon2 - wBoxMon1 ; $21
ld a, [wNumInBox]
-.skipToNewMonEntry
+.addMonOffset
dec a
call AddNTimes
-.asm_f575
+.findMonDataSrc
push hl
ld e, l
ld d, h
@@ -394,16 +397,16 @@ _MoveMon:
and a
ld hl, wBoxMons
ld bc, wBoxMon2 - wBoxMon1 ; $21
- jr z, .asm_f591
+ jr z, .addMonOffset2
cp DAYCARE_TO_PARTY
ld hl, wDayCareMon
- jr z, .asm_f597
+ jr z, .copyMonData
ld hl, wPartyMons
ld bc, wPartyMon2 - wPartyMon1 ; $2c
-.asm_f591
+.addMonOffset2
ld a, [wWhichPokemon]
call AddNTimes
-.asm_f597
+.copyMonData
push hl
push de
ld bc, wBoxMon2 - wBoxMon1
@@ -411,84 +414,85 @@ _MoveMon:
pop de
pop hl
ld a, [wMoveMonType]
- and a
- jr z, .asm_f5b4
+ and a ; BOX_TO_PARTY
+ jr z, .findOTdest
cp DAYCARE_TO_PARTY
- jr z, .asm_f5b4
+ jr z, .findOTdest
ld bc, wBoxMon2 - wBoxMon1
add hl, bc
- ld a, [hl]
+ ld a, [hl] ; hl = Level
inc de
inc de
inc de
- ld [de], a
-.asm_f5b4
+ ld [de], a ; de = BoxLevel
+.findOTdest
ld a, [wMoveMonType]
cp PARTY_TO_DAYCARE
ld de, wDayCareMonOT
- jr z, .asm_f5d3
- dec a
+ jr z, .findOTsrc
+ dec a
ld hl, wPartyMonOT
ld a, [wPartyCount]
- jr nz, .asm_f5cd
+ jr nz, .addOToffset
ld hl, wBoxMonOT
ld a, [wNumInBox]
-.asm_f5cd
+.addOToffset
dec a
call SkipFixedLengthTextEntries
ld d, h
ld e, l
-.asm_f5d3
+.findOTsrc
ld hl, wBoxMonOT
ld a, [wMoveMonType]
and a
- jr z, .asm_f5e6
+ jr z, .addOToffset2
ld hl, wDayCareMonOT
cp DAYCARE_TO_PARTY
- jr z, .asm_f5ec
+ jr z, .copyOT
ld hl, wPartyMonOT
-.asm_f5e6
+.addOToffset2
ld a, [wWhichPokemon]
call SkipFixedLengthTextEntries
-.asm_f5ec
+.copyOT
ld bc, NAME_LENGTH
call CopyData
ld a, [wMoveMonType]
+.findNickDest
cp PARTY_TO_DAYCARE
ld de, wDayCareMonName
- jr z, .asm_f611
+ jr z, .findNickSrc
dec a
ld hl, wPartyMonNicks
ld a, [wPartyCount]
- jr nz, .asm_f60b
+ jr nz, .addNickOffset
ld hl, wBoxMonNicks
ld a, [wNumInBox]
-.asm_f60b
+.addNickOffset
dec a
call SkipFixedLengthTextEntries
ld d, h
ld e, l
-.asm_f611
+.findNickSrc
ld hl, wBoxMonNicks
ld a, [wMoveMonType]
and a
- jr z, .asm_f624
+ jr z, .addNickOffset2
ld hl, wDayCareMonName
cp DAYCARE_TO_PARTY
- jr z, .asm_f62a
+ jr z, .copyNick
ld hl, wPartyMonNicks
-.asm_f624
+.addNickOffset2
ld a, [wWhichPokemon]
call SkipFixedLengthTextEntries
-.asm_f62a
+.copyNick
ld bc, NAME_LENGTH
call CopyData
pop hl
ld a, [wMoveMonType]
cp PARTY_TO_BOX
- jr z, .asm_f664
+ jr z, .done
cp PARTY_TO_DAYCARE
- jr z, .asm_f664
+ jr z, .done
push hl
srl a
add $2
@@ -507,6 +511,6 @@ _MoveMon:
add hl, bc
ld b, $1
call CalcStats
-.asm_f664
+.done
and a
ret
diff --git a/engine/bcd.asm b/engine/bcd.asm
index 3e693e1f..2d0b43df 100644
--- a/engine/bcd.asm
+++ b/engine/bcd.asm
@@ -6,155 +6,157 @@ DivideBCDPredef4::
DivideBCD::
xor a
- ld [$ffa5], a
- ld [$ffa6], a
- ld [$ffa7], a
+ ld [hDivideBCDBuffer], a
+ ld [hDivideBCDBuffer+1], a
+ ld [hDivideBCDBuffer+2], a
ld d, $1
-.asm_f72a
- ld a, [$ffa2]
+.mulBy10Loop
+; multiply the divisor by 10 until the leading digit is nonzero
+; to set up the standard long division algorithm
+ ld a, [hDivideBCDDivisor]
and $f0
- jr nz, .asm_f75b
+ jr nz, .next
inc d
- ld a, [$ffa2]
+ ld a, [hDivideBCDDivisor]
swap a
and $f0
ld b, a
- ld a, [$ffa3]
+ ld a, [hDivideBCDDivisor+1]
swap a
- ld [$ffa3], a
+ ld [hDivideBCDDivisor+1], a
and $f
or b
- ld [$ffa2], a
- ld a, [$ffa3]
+ ld [hDivideBCDDivisor], a
+ ld a, [hDivideBCDDivisor+1]
and $f0
ld b, a
- ld a, [$ffa4]
+ ld a, [hDivideBCDDivisor+2]
swap a
- ld [$ffa4], a
+ ld [hDivideBCDDivisor+2], a
and $f
or b
- ld [$ffa3], a
- ld a, [$ffa4]
+ ld [hDivideBCDDivisor+1], a
+ ld a, [hDivideBCDDivisor+2]
and $f0
- ld [$ffa4], a
- jr .asm_f72a
-.asm_f75b
+ ld [hDivideBCDDivisor+2], a
+ jr .mulBy10Loop
+.next
push de
push de
- call DivideBCD_f800
+ call DivideBCD_getNextDigit
pop de
ld a, b
swap a
and $f0
- ld [$ffa5], a
+ ld [hDivideBCDBuffer], a
dec d
- jr z, .asm_f7bc
+ jr z, .next2
push de
- call DivideBCD_f7d7
- call DivideBCD_f800
+ call DivideBCD_divDivisorBy10
+ call DivideBCD_getNextDigit
pop de
- ld a, [$ffa5]
+ ld a, [hDivideBCDBuffer]
or b
- ld [$ffa5], a
+ ld [hDivideBCDBuffer], a
dec d
- jr z, .asm_f7bc
+ jr z, .next2
push de
- call DivideBCD_f7d7
- call DivideBCD_f800
+ call DivideBCD_divDivisorBy10
+ call DivideBCD_getNextDigit
pop de
ld a, b
swap a
and $f0
- ld [$ffa6], a
+ ld [hDivideBCDBuffer+1], a
dec d
- jr z, .asm_f7bc
+ jr z, .next2
push de
- call DivideBCD_f7d7
- call DivideBCD_f800
+ call DivideBCD_divDivisorBy10
+ call DivideBCD_getNextDigit
pop de
- ld a, [$ffa6]
+ ld a, [hDivideBCDBuffer+1]
or b
- ld [$ffa6], a
+ ld [hDivideBCDBuffer+1], a
dec d
- jr z, .asm_f7bc
+ jr z, .next2
push de
- call DivideBCD_f7d7
- call DivideBCD_f800
+ call DivideBCD_divDivisorBy10
+ call DivideBCD_getNextDigit
pop de
ld a, b
swap a
and $f0
- ld [$ffa7], a
+ ld [hDivideBCDBuffer+2], a
dec d
- jr z, .asm_f7bc
+ jr z, .next2
push de
- call DivideBCD_f7d7
- call DivideBCD_f800
+ call DivideBCD_divDivisorBy10
+ call DivideBCD_getNextDigit
pop de
- ld a, [$ffa7]
+ ld a, [hDivideBCDBuffer+2]
or b
- ld [$ffa7], a
-.asm_f7bc
- ld a, [$ffa5]
- ld [$ffa2], a
- ld a, [$ffa6]
- ld [$ffa3], a
- ld a, [$ffa7]
- ld [$ffa4], a
+ ld [hDivideBCDBuffer+2], a
+.next2
+ ld a, [hDivideBCDBuffer]
+ ld [hDivideBCDQuotient], a ; the same memory location as hDivideBCDDivisor
+ ld a, [hDivideBCDBuffer+1]
+ ld [hDivideBCDQuotient+1], a
+ ld a, [hDivideBCDBuffer+2]
+ ld [hDivideBCDQuotient+2], a
pop de
- ld a, $6
+ ld a, $6
sub d
and a
ret z
-.asm_f7ce
+.divResultBy10loop
push af
- call DivideBCD_f7d7
+ call DivideBCD_divDivisorBy10
pop af
dec a
- jr nz, .asm_f7ce
+ jr nz, .divResultBy10loop
ret
-DivideBCD_f7d7:
- ld a, [$ffa4]
+DivideBCD_divDivisorBy10:
+ ld a, [hDivideBCDDivisor+2]
swap a
and $f
ld b, a
- ld a, [$ffa3]
+ ld a, [hDivideBCDDivisor+1]
swap a
- ld [$ffa3], a
+ ld [hDivideBCDDivisor+1], a
and $f0
or b
- ld [$ffa4], a
- ld a, [$ffa3]
+ ld [hDivideBCDDivisor+2], a
+ ld a, [hDivideBCDDivisor+1]
and $f
ld b, a
- ld a, [$ffa2]
+ ld a, [hDivideBCDDivisor]
swap a
- ld [$ffa2], a
+ ld [hDivideBCDDivisor], a
and $f0
or b
- ld [$ffa3], a
- ld a, [$ffa2]
+ ld [hDivideBCDDivisor+1], a
+ ld a, [hDivideBCDDivisor]
and $f
- ld [$ffa2], a
+ ld [hDivideBCDDivisor], a
ret
-DivideBCD_f800:
+DivideBCD_getNextDigit:
ld bc, $3
-.asm_f803
- ld de, $ff9f
- ld hl, $ffa2
+.loop
+ ld de, hMoney ; the dividend
+ ld hl, hDivideBCDDivisor
push bc
call StringCmp
pop bc
ret c
inc b
- ld de, $ffa1
- ld hl, $ffa4
+ ld de, hMoney+2 ; since SubBCD works starting from the least significant digit
+ ld hl, hDivideBCDDivisor+2
push bc
call SubBCD
pop bc
- jr .asm_f803
+ jr .loop
AddBCDPredef::
diff --git a/home.asm b/home.asm
index 8cd85019..0a2d829d 100644
--- a/home.asm
+++ b/home.asm
@@ -2528,7 +2528,7 @@ EngageMapTrainer::
ld a, [hli] ; load trainer class
ld [wEngagedTrainerClass], a
ld a, [hl] ; load trainer mon set
- ld [wEnemyMonAttackMod], a
+ ld [wEngagedTrainerSet], a
jp PlayTrainerMusic
PrintEndBattleText::
diff --git a/hram.asm b/hram.asm
index f5817fa4..9c13e5a1 100644
--- a/hram.asm
+++ b/hram.asm
@@ -155,6 +155,7 @@ hCoins EQU $FFA0 ; 2-byte BCD number
hDivideBCDDivisor EQU $FFA2 ; 3-byte BCD number
hDivideBCDQuotient EQU $FFA2 ; 3-byte BCD number
+hDivideBCDBuffer EQU $FFA5 ; 3-byte BCD number
hSerialReceivedNewData EQU $FFA9
diff --git a/scripts/oakslab.asm b/scripts/oakslab.asm
index b91abd43..e73d7cf8 100755
--- a/scripts/oakslab.asm
+++ b/scripts/oakslab.asm
@@ -712,7 +712,7 @@ OaksLabScript_1d02b:
ret
OaksLabScript_1d076:
- ld hl, OaksLabTextPointers + $36 ; starts at OaksLabText28
+ ld hl, OaksLabTextPointers2
ld a, l
ld [wMapTextPtr], a
ld a, h
@@ -747,19 +747,20 @@ OaksLabTextPointers:
dw OaksLabText25
dw OaksLabText26
dw OaksLabText27
- dw OaksLabText28
- dw OaksLabText29
- dw OaksLabText30
- dw OaksLabText31
- dw OaksLabText32
- dw OaksLabText33
- dw OaksLabText34
- dw OaksLabText35
- dw OaksLabText36
- dw OaksLabText37
- dw OaksLabText38
-
-OaksLabText28:
+
+OaksLabTextPointers2:
+ dw OaksLabText1
+ dw OaksLabText2
+ dw OaksLabText3
+ dw OaksLabText4
+ dw OaksLabText5
+ dw OaksLabText6
+ dw OaksLabText7
+ dw OaksLabText8
+ dw OaksLabText9
+ dw OaksLabText10
+ dw OaksLabText11
+
OaksLabText1:
TX_ASM
CheckEvent EVENT_FOLLOWED_OAK_INTO_LAB_2
@@ -791,7 +792,6 @@ OaksLabText41:
TX_FAR _OaksLabText41
db "@"
-OaksLabText29:
OaksLabText2:
TX_ASM
ld a, STARTER2
@@ -802,7 +802,6 @@ OaksLabText2:
ld b, $2
jr OaksLabScript_1d133
-OaksLabText30:
OaksLabText3:
TX_ASM
ld a, STARTER3
@@ -813,7 +812,6 @@ OaksLabText3:
ld b, $3
jr OaksLabScript_1d133
-OaksLabText31:
OaksLabText4:
TX_ASM
ld a, STARTER1
@@ -1070,8 +1068,6 @@ OaksLabText_1d31d:
TX_FAR _OaksLabText_1d31d
db "@"
-OaksLabText34:
-OaksLabText33:
OaksLabText7:
OaksLabText6:
TX_ASM
@@ -1083,12 +1079,10 @@ OaksLabText_1d32c:
TX_FAR _OaksLabText_1d32c
db "@"
-OaksLabText35:
OaksLabText8:
TX_FAR _OaksLabText8
db "@"
-OaksLabText36:
OaksLabText9:
TX_ASM
ld hl, OaksLabText_1d340
@@ -1227,8 +1221,6 @@ OaksLabText27:
TX_FAR _OaksLabText27
db "@"
-OaksLabText38:
-OaksLabText37:
OaksLabText11:
OaksLabText10:
TX_ASM