Merge branch 'master' into remove-extras

This commit is contained in:
Bryan Bishop 2013-08-27 10:51:30 -05:00
commit 3453879756
393 changed files with 73016 additions and 6914 deletions

View File

@ -1,6 +1,6 @@
# Getting Started
Compiling **pokecrystal.gbc** requires a certain **Pokemon Crystal** rom:
Assembling **pokecrystal.gbc** requires a certain **Pokemon Crystal** rom:
```
Pokemon - Crystal Version (UE) (V1.0) [C][!].gbc
@ -9,11 +9,14 @@ md5: 9f2922b235a5eeb78d65594e82ef5dde
Save it as **baserom.gbc** in the repository.
Feel free to ask us on **[nucleus.kafuka.org #skeetendo](https://kiwiirc.com/client/irc.nolimitzone.com/?#skeetendo)** if something goes wrong!
Feel free to ask us on
**[nucleus.kafuka.org #skeetendo](https://kiwiirc.com/client/irc.nolimitzone.com/?#skeetendo)**
if something goes wrong.
# Windows
If you are on Windows and can't install Linux, **Cygwin** is a great alternative.
If you're on Windows and can't install Linux, **Cygwin** is a great alternative.
## Installing Cygwin
@ -24,14 +27,20 @@ Cygwin provides a virtual Linux environment on Windows systems. Just get **setup
During the install:
* Keep the defaults.
* Most mirrors are molasses. Use **http://mirrors.kernel.org**.
* From the package selection, select **wget**.
* From the package selection, pick:
* **wget**
* **make**
* **git**
* **python**
* **python-setuptools**
* **unzip**
## Using Cygwin
Launch the **Cygwin terminal**. Maybe you know your way around the Linux terminal, **bash**. If not, a crash course:
Launch the **Cygwin terminal**.
Maybe you know your way around the Linux terminal ( **bash** ).
If not, a crash course:
```bash
# list files in current directory
ls
@ -45,48 +54,40 @@ cd /away/we/go
## Getting up and running
We need a couple more things to be able to compile.
We need three things to assemble the source into a rom.
If you're feeling lazy, just paste these commands into your terminal.
**apt-cyg** lets you install new packages without running Cygwin setup.
1. **rgbds**
2. a **pokecrystal** repository
3. a **base rom**
We use **rgbds** to spit out a Game Boy rom from source.
```bash
wget http://apt-cyg.googlecode.com/svn/trunk/apt-cyg
chmod +x apt-cyg
mv apt-cyg /usr/local/bin/
cd /usr/local/bin
wget http://iimarck.us/etc/rgbds-20130811.zip
unzip -j rgbds-20130811.zip
rm rgbds-20130811.zip
```
Now we can use apt-cyg to install everything else.
```bash
apt-cyg install make git python python-setuptools unzip
easy_install pip
```
**rgbds** will let you compile Game Boy roms.
```bash
wget http://diyhpl.us/~bryan/irc/pokered/rgbds/rgbds-0.0.1.zip
unzip rgbds-0.0.1.zip
mv rgbds-0.0.1/* /usr/local/bin
rm -r rgbds-0.0.1*
```
Set up the **pokecrystal** repository:
The **pokecrystal** repository contains the source files used to create the rom.
```bash
cd ~
git clone https://github.com/kanzure/pokecrystal
cd pokecrystal
# install python requirements
pip install -r extras/requirements.txt
easy_install pip
pip install -r requirements.txt
```
## Don't forget baserom.gbc!!
Not everything is included in the source yet.
Missing patches are copied from a **base rom** (not included).
Make sure you downloaded a base rom. Name it **baserom.gbc**.
```
Pokemon - Crystal Version (UE) (V1.0) [C][!].gbc
md5: 9f2922b235a5eeb78d65594e82ef5dde
```
Name it **baserom.gbc**.
**pokecrystal** only compiles with the use of a git submodule. To activate the submodule type:
@ -105,29 +106,25 @@ make
This ought to take **between 3 and 15 seconds**, depending on your computer.
If you see `cmp baserom.gbc pokecrystal.gbc` as the last line, the build was successful!
If the last line is `cmp baserom.gbc pokecrystal.gbc`, the build was successful!
Your first compile processes every source file at once. After that, **only modified source files have to be reprocessed**, so compiling again should be a few seconds faster.
Your first build processes every source file at once.
After that, **only modified source files have to be processed again**,
so compiling again should be a few seconds faster.
# Linux
```bash
sudo apt-get install make gcc bison git python python-setuptools
# unittest2 is required if using python2.6
sudo easy_install unittest2
sudo easy_install pip
# download rgbds source code
# install rgbds
git clone git://github.com/bentley/rgbds.git
# compile rgbds
cd rgbds
make
sudo make install
# check if rgbasm is installed now
which rgbasm
cd ..
# download pokecrystal
git clone git://github.com/kanzure/pokecrystal.git
@ -144,22 +141,39 @@ pip install -r extras/requirements.txt
git config diff.hex.textconv hexdump
```
To compile the rom from asm source:
Put your base rom in the pokecrystal repository. Name it **baserom.gbc**.
To compile the rom from source:
```bash
make
```
That will take between 3 and 15 seconds, depending on your computer. If you see `cmp baserom.gbc pokecrystal.gbc` as the last line, the build was successful! Rejoice!
That will take between 3 and 15 seconds, depending on your computer.
If you see `cmp baserom.gbc pokecrystal.gbc` as the last line, the build was successful! Rejoice!
# Now what?
**main.asm** is a good starting point. The structure of the source is laid out here.
**[pokecrystal.asm](https://github.com/kanzure/pokecrystal/blob/master/pokecrystal.asm)** is a good starting point.
The structure of the source is laid out here.
* **Can't find something?** Anyone can add to the source. There's lots to be uncovered.
* **Do your own thing!** The asm source is hack-friendly, and the supplementary scripts in extras/ can be used for other projects.
* Other **make targets** that may come in handy:
* `make clean` deletes any preprocessed source files (.tx), rgbds object files and pokecrystal.gbc.
* `make pngs` decompresses any **lz** files in gfx/ and then exports any graphics files to **png**.
* `make lzs` does the reverse. This is already part of the build process, so **modified pngs will automatically be converted to 2bpp and lz-compressed** without any additional work.
* **Can't find something?**
Anyone can add to the source. There's lots to be uncovered.
* **Do your own thing!**
The asm source is hack-friendly, and the supplementary scripts in extras/ can be used for other projects.
We'll be happy to answer any **questions** on
**[nucleus.kafuka.org #skeetendo](https://kiwiirc.com/client/irc.nolimitzone.com/?#skeetendo)**.
* We'll be happy to answer any **questions** on **[nucleus.kafuka.org #skeetendo](https://kiwiirc.com/client/irc.nolimitzone.com/?#skeetendo)**.
Other **make targets** that may come in handy:

View File

@ -21,7 +21,7 @@ pokecrystal.o: $(TEXTFILES:.asm=.tx) wram.asm constants.asm $(shell find constan
@rm -f $@
pokecrystal.gbc: pokecrystal.o
rgblink -o $@ $<
rgblink -n pokecrystal.sym -m pokecrystal.map -o $@ $<
rgbfix -Cjv -i BYTE -k 01 -l 0x33 -m 0x10 -p 0 -r 3 -t PM_CRYSTAL $@
pngs:

View File

@ -6850,7 +6850,7 @@ Function0x365d7: ; 365d7
ld a, $5
call Function0x3661d
ld hl, $6d45
ld hl, BadgeStatBoosts
call CallBankF
call SwitchTurn
@ -8385,7 +8385,7 @@ BattleCommand98: ; 36f25
; doubleflyingdamage
ld a, BATTLE_VARS_SUBSTATUS3_OPP
call CleanGetBattleVarPair
bit 6, a ; flying
bit SUBSTATUS_FLYING, a
ret z
jr DoubleDamage
; 36f2f
@ -8395,7 +8395,7 @@ BattleCommand99: ; 36f2f
; doubleundergrounddamage
ld a, BATTLE_VARS_SUBSTATUS3_OPP
call CleanGetBattleVarPair
bit 5, a ; underground
bit SUBSTATUS_UNDERGROUND, a
ret z
; fallthrough
@ -10623,11 +10623,7 @@ BattleCommand6d: ; 37be8
ld a, [AttackMissed]
and a
ret nz
ld a, $3e
ld hl, $7ced
rst FarCall
callba GetHiddenPower
ret
; 37bf4

108
battle/hidden_power.asm Normal file
View File

@ -0,0 +1,108 @@
GetHiddenPower: ; fbced
; Override Hidden Power's type and power based on the actor's DVs.
ld hl, BattleMonDVs
ld a, [hBattleTurn]
and a
jr z, .GotDVs
ld hl, EnemyMonDVs
.GotDVs
; Power:
; Take the top bit from...
; Atk
ld a, [hl]
swap a
and 8
ld b, a
; Def
ld a, [hli]
and 8
srl a
or b
ld b, a
; Spd
ld a, [hl]
swap a
and 8
srl a
srl a
or b
ld b, a
; Spc
ld a, [hl]
and 8
srl a
srl a
srl a
or b
ld b, a
; * 5
add a
add a
add b
ld b, a
; + (Spc & 3)
ld a, [hld]
and 3
add b
; / 2
srl a
; + 30
add 30
; + 1
inc a
ld d, a
; Type:
; Def & 3
ld a, [hl]
and 3
ld b, a
; + (Atk & 3) << 2
ld a, [hl]
and 3 << 4
swap a
add a
add a
or b
; Skip Normal
inc a
; Skip type 6 (unused)
cp 6
jr c, .GotType
inc a
; Skip unused types between Steel and Fire
cp STEEL + 1
jr c, .GotType
add FIRE - (STEEL + 1)
.GotType
push af
ld a, BATTLE_VARS_MOVE_TYPE
call GetBattleVarPair
pop af
ld [hl], a
ld a, d
push af
callba BattleCommand06
pop af
ld d, a
ret
; fbd54

File diff suppressed because it is too large Load Diff

View File

@ -36,6 +36,12 @@ dn: MACRO
db \1 << 4 + \2
ENDM
dt: MACRO ; three-byte (big-endian)
db (\1 >> 16) & $ff
db (\1 >> 8) & $ff
db \1 & $ff
ENDM
bigdw: MACRO ; big-endian word
dw ((\1)/$100) + (((\1)&$ff)*$100)
ENDM
@ -221,8 +227,23 @@ PREDEF_FLAG EQU $03
PREDEF_FILLPP EQU $05
PREDEF_ADDPARTYMON EQU $06
PREDEF_FILLSTATS EQU $0C
PREDEF_PRINT_MOVE_DESCRIPTION EQU $11
PREDEF_UPDATE_PLAYER_HUD EQU $12
PREDEF_FILL_BOX EQU $13
PREDEF_UPDATE_ENEMY_HUD EQU $15
PREDEF_FILL_IN_EXP_BAR EQU $17
PREDEF_FILLMOVES EQU $1B
PREDEF_GETUNOWNLETTER EQU $2D
PREDEF_GET_GENDER EQU $24
PREDEF_STATS_SCREEN EQU $25
PREDEF_DRAW_PLAYER_HP EQU $26
PREDEF_DRAW_ENEMY_HP EQU $27
PREDEF_GET_TYPE_NAME EQU $29
PREDEF_PRINT_MOVE_TYPE EQU $2A
PREDEF_PRINT_TYPE EQU $2B
PREDEF_GET_UNOWN_LETTER EQU $2D
PREDEF_LOAD_SGB_LAYOUT EQU $31
PREDEF_CHECK_CONTEST_MON EQU $33
PREDEF_PARTYMON_ITEM_NAME EQU $3B
PREDEF_DECOMPRESS EQU $40
@ -247,6 +268,20 @@ D_UP EQU %01000000
D_DOWN EQU %10000000
; screen
HP_BAR_LENGTH EQU 6
HP_BAR_LENGTH_PX EQU 48
EXP_BAR_LENGTH EQU 8
EXP_BAR_LENGTH_PX EQU 64
SCREEN_WIDTH EQU 20
SCREEN_HEIGHT EQU 18
SCREEN_WIDTH_PX EQU 160
SCREEN_HEIGHT_PX EQU 144
TILE_WIDTH EQU 8
; movement
STEP_SLOW EQU 0
STEP_WALK EQU 1

View File

@ -1583,3 +1583,187 @@ EAST EQU 1
WEST EQU 2
SOUTH EQU 4
NORTH EQU 8
; sprites
SPRITE_CHRIS EQU $01
SPRITE_CHRIS_BIKE EQU $02
SPRITE_GAMEBOY_KID EQU $03
SPRITE_SILVER EQU $04
SPRITE_OAK EQU $05
SPRITE_RED EQU $06
SPRITE_BLUE EQU $07
SPRITE_BILL EQU $08
SPRITE_ELDER EQU $09
SPRITE_JANINE EQU $0a
SPRITE_KURT EQU $0b
SPRITE_MOM EQU $0c
SPRITE_BLAINE EQU $0d
SPRITE_REDS_MOM EQU $0e
SPRITE_DAISY EQU $0f
SPRITE_ELM EQU $10
SPRITE_WILL EQU $11
SPRITE_FALKNER EQU $12
SPRITE_WHITNEY EQU $13
SPRITE_BUGSY EQU $14
SPRITE_MORTY EQU $15
SPRITE_CHUCK EQU $16
SPRITE_JASMINE EQU $17
SPRITE_PRYCE EQU $18
SPRITE_CLAIR EQU $19
SPRITE_BROCK EQU $1a
SPRITE_KAREN EQU $1b
SPRITE_BRUNO EQU $1c
SPRITE_MISTY EQU $1d
SPRITE_LANCE EQU $1e
SPRITE_SURGE EQU $1f
SPRITE_ERIKA EQU $20
SPRITE_KOGA EQU $21
SPRITE_SABRINA EQU $22
SPRITE_COOLTRAINER_M EQU $23
SPRITE_COOLTRAINER_F EQU $24
SPRITE_BUG_CATCHER EQU $25
SPRITE_TWIN EQU $26
SPRITE_YOUNGSTER EQU $27
SPRITE_LASS EQU $28
SPRITE_TEACHER EQU $29
SPRITE_BUENA EQU $2a
SPRITE_SUPER_NERD EQU $2b
SPRITE_ROCKER EQU $2c
SPRITE_POKEFAN_M EQU $2d
SPRITE_POKEFAN_F EQU $2e
SPRITE_GRAMPS EQU $2f
SPRITE_GRANNY EQU $30
SPRITE_SWIMMER_GUY EQU $31
SPRITE_SWIMMER_GIRL EQU $32
SPRITE_BIG_SNORLAX EQU $33
SPRITE_SURFING_PIKACHU EQU $34
SPRITE_ROCKET EQU $35
SPRITE_ROCKET_GIRL EQU $36
SPRITE_NURSE EQU $37
SPRITE_LINK_RECEPTIONIST EQU $38
SPRITE_CLERK EQU $39
SPRITE_FISHER EQU $3a
SPRITE_FISHING_GURU EQU $3b
SPRITE_SCIENTIST EQU $3c
SPRITE_KIMONO_GIRL EQU $3d
SPRITE_SAGE EQU $3e
SPRITE_UNUSED_GUY EQU $3f
SPRITE_GENTLEMAN EQU $40
SPRITE_BLACK_BELT EQU $41
SPRITE_RECEPTIONIST EQU $42
SPRITE_OFFICER EQU $43
SPRITE_CAL EQU $44
SPRITE_SLOWPOKE EQU $45
SPRITE_CAPTAIN EQU $46
SPRITE_BIG_LAPRAS EQU $47
SPRITE_GYM_GUY EQU $48
SPRITE_SAILOR EQU $49
SPRITE_BIKER EQU $4a
SPRITE_PHARMACIST EQU $4b
SPRITE_MONSTER EQU $4c
SPRITE_FAIRY EQU $4d
SPRITE_BIRD EQU $4e
SPRITE_DRAGON EQU $4f
SPRITE_BIG_ONIX EQU $50
SPRITE_N64 EQU $51
SPRITE_SUDOWOODO EQU $52
SPRITE_SURF EQU $53
SPRITE_POKE_BALL EQU $54
SPRITE_POKEDEX EQU $55
SPRITE_PAPER EQU $56
SPRITE_VIRTUAL_BOY EQU $57
SPRITE_OLD_LINK_RECEPTIONIST EQU $58
SPRITE_ROCK EQU $59
SPRITE_BOULDER EQU $5a
SPRITE_SNES EQU $5b
SPRITE_FAMICOM EQU $5c
SPRITE_FRUIT_TREE EQU $5d
SPRITE_GOLD_TROPHY EQU $5e
SPRITE_SILVER_TROPHY EQU $5f
SPRITE_KRIS EQU $60
SPRITE_KRIS_BIKE EQU $61
SPRITE_KURT_OUTSIDE EQU $62
SPRITE_SUICUNE EQU $63
SPRITE_ENTEI EQU $64
SPRITE_RAIKOU EQU $65
SPRITE_STANDING_YOUNGSTER EQU $66
SPRITE_POKEMON EQU $80
SPRITE_UNOWN EQU $80
SPRITE_GEODUDE EQU $81
SPRITE_GROWLITHE EQU $82
SPRITE_WEEDLE EQU $83
SPRITE_SHELLDER EQU $84
SPRITE_ODDISH EQU $85
SPRITE_GENGAR EQU $86
SPRITE_ZUBAT EQU $87
SPRITE_MAGIKARP EQU $88
SPRITE_SQUIRTLE EQU $89
SPRITE_TOGEPI EQU $8a
SPRITE_BUTTERFREE EQU $8b
SPRITE_DIGLETT EQU $8c
SPRITE_POLIWAG EQU $8d
SPRITE_PIKACHU EQU $8e
SPRITE_CLEFAIRY EQU $8f
SPRITE_CHARMANDER EQU $90
SPRITE_JYNX EQU $91
SPRITE_STARMIE EQU $92
SPRITE_BULBASAUR EQU $93
SPRITE_JIGGLYPUFF EQU $94
SPRITE_GRIMER EQU $95
SPRITE_EKANS EQU $96
SPRITE_PARAS EQU $97
SPRITE_TENTACOOL EQU $98
SPRITE_TAUROS EQU $99
SPRITE_MACHOP EQU $9a
SPRITE_VOLTORB EQU $9b
SPRITE_LAPRAS EQU $9c
SPRITE_RHYDON EQU $9d
SPRITE_MOLTRES EQU $9e
SPRITE_SNORLAX EQU $9f
SPRITE_GYARADOS EQU $a0
SPRITE_LUGIA EQU $a1
SPRITE_HO_OH EQU $a2
SPRITE_DAYCARE_MON_1 EQU $e0
SPRITE_DAYCARE_MON_2 EQU $e1
SPRITE_VARS EQU $f0
SPRITE_CONSOLE EQU $f0
SPRITE_DOLL_1 EQU $f1
SPRITE_DOLL_2 EQU $f2
SPRITE_BIG_DOLL EQU $f3
SPRITE_WEIRD_TREE EQU $f4
SPRITE_OLIVINE_RIVAL EQU $f5
SPRITE_AZALEA_ROCKET EQU $f6
SPRITE_FUSCHIA_GYM_1 EQU $f7
SPRITE_FUSCHIA_GYM_2 EQU $f8
SPRITE_FUSCHIA_GYM_3 EQU $f9
SPRITE_FUSCHIA_GYM_4 EQU $fa
SPRITE_COPYCAT EQU $fb
SPRITE_JANINE_IMPERSONATOR EQU $fc
; sprite types
WALKING_SPRITE EQU 1
STANDING_SPRITE EQU 2
STILL_SPRITE EQU 3
; sprite palettes
PAL_OW_RED EQU 0
PAL_OW_BLUE EQU 1
PAL_OW_GREEN EQU 2
PAL_OW_BROWN EQU 3
PAL_OW_PINK EQU 4
PAL_OW_SILVER EQU 5
PAL_OW_TREE EQU 6
PAL_OW_ROCK EQU 7
; permissions
TOWN EQU 1
ROUTE EQU 2
INDOOR EQU 3
CAVE EQU 4
GATE EQU 6
DUNGEON EQU 7

View File

@ -149,7 +149,7 @@ SFX_POKEFLUTE EQU $26
SFX_ELEVATOR_END EQU $27
SFX_THROW_BALL EQU $28
SFX_BALL_POOF EQU $29
SFX_UNKNOWN_3A EQU $2a
SFX_UNKNOWN_2A EQU $2a
SFX_RUN EQU $2b
SFX_SLOT_MACHINE_START EQU $2c
SFX_FANFARE EQU $2d
@ -254,7 +254,7 @@ SFX_MORNING_SUN EQU $8f
SFX_LEVEL_UP EQU $90
SFX_KEY_ITEM EQU $91
SFX_FANFARE_2 EQU $92
SFX_REGISTER_PHONE_# EQU $93
SFX_REGISTER_PHONE_NUMBER EQU $93
SFX_3RD_PLACE EQU $94
SFX_GET_EGG_FROM_DAYCARE_MAN EQU $95
SFX_GET_EGG_FROM_DAYCARE_LADY EQU $96

367
engine/decompress.asm Normal file
View File

@ -0,0 +1,367 @@
FarDecompress: ; b40
; Decompress graphics data at a:hl to de
; put a away for a sec
ld [$c2c4], a
; save bank
ld a, [hROMBank]
push af
; bankswitch
ld a, [$c2c4]
rst Bankswitch
; what we came here for
call Decompress
; restore bank
pop af
rst Bankswitch
ret
; b50
Decompress: ; b50
; Pokemon Crystal uses an lz variant for compression.
; This is mainly used for graphics, but the intro's
; tilemaps also use this compression.
; This function decompresses lz-compressed data at hl to de.
; Basic rundown:
; A typical control command consists of:
; -the command (bits 5-7)
; -the count (bits 0-4)
; -and any additional params
; $ff is used as a terminator.
; Commands:
; 0: literal
; literal data for some number of bytes
; 1: iterate
; one byte repeated for some number of bytes
; 2: alternate
; two bytes alternated for some number of bytes
; 3: zero (whitespace)
; 0x00 repeated for some number of bytes
; Repeater control commands have a signed parameter used to determine the start point.
; Wraparound is simulated:
; Positive values are added to the start address of the decompressed data
; and negative values are subtracted from the current position.
; 4: repeat
; repeat some number of bytes from decompressed data
; 5: flipped
; repeat some number of flipped bytes from decompressed data
; ex: $ad = %10101101 -> %10110101 = $b5
; 6: reverse
; repeat some number of bytes in reverse from decompressed data
; If the value in the count needs to be larger than 5 bits,
; control code 7 can be used to expand the count to 10 bits.
; A new control command is read in bits 2-4.
; The new 10-bit count is split:
; bits 0-1 contain the top 2 bits
; another byte is added containing the latter 8
; So, the structure of the control command becomes:
; 111xxxyy yyyyyyyy
; | | | |
; | | our new count
; | the control command for this count
; 7 (this command)
; For more information, refer to the code below and in extras/gfx.py .
; save starting output address
ld a, e
ld [$c2c2], a
ld a, d
ld [$c2c3], a
.loop
; get next byte
ld a, [hl]
; done?
cp $ff ; end
ret z
; get control code
and %11100000
; 10-bit param?
cp $e0 ; LZ_HI
jr nz, .normal
; 10-bit param:
; get next 3 bits (%00011100)
ld a, [hl]
add a
add a ; << 3
add a
; this is our new control code
and %11100000
push af
; get param hi
ld a, [hli]
and %00000011
ld b, a
; get param lo
ld a, [hli]
ld c, a
; read at least 1 byte
inc bc
jr .readers
.normal
; push control code
push af
; get param
ld a, [hli]
and %00011111
ld c, a
ld b, $0
; read at least 1 byte
inc c
.readers
; let's get started
; inc loop counts since we bail as soon as they hit 0
inc b
inc c
; get control code
pop af
; command type
bit 7, a ; 80, a0, c0
jr nz, .repeatertype
; literals
cp $20 ; LZ_ITER
jr z, .iter
cp $40 ; LZ_ALT
jr z, .alt
cp $60 ; LZ_ZERO
jr z, .zero
; else $00
; 00 ; LZ_LIT
; literal data for bc bytes
.loop1
; done?
dec c
jr nz, .next1
dec b
jp z, .loop
.next1
ld a, [hli]
ld [de], a
inc de
jr .loop1
; 20 ; LZ_ITER
; write byte for bc bytes
.iter
ld a, [hli]
.iterloop
dec c
jr nz, .iternext
dec b
jp z, .loop
.iternext
ld [de], a
inc de
jr .iterloop
; 40 ; LZ_ALT
; alternate two bytes for bc bytes
; next pair
.alt
; done?
dec c
jr nz, .alt0
dec b
jp z, .altclose0
; alternate for bc
.alt0
ld a, [hli]
ld [de], a
inc de
dec c
jr nz, .alt1
; done?
dec b
jp z, .altclose1
.alt1
ld a, [hld]
ld [de], a
inc de
jr .alt
; skip past the bytes we were alternating
.altclose0
inc hl
.altclose1
inc hl
jr .loop
; 60 ; LZ_ZERO
; write 00 for bc bytes
.zero
xor a
.zeroloop
dec c
jr nz, .zeronext
dec b
jp z, .loop
.zeronext
ld [de], a
inc de
jr .zeroloop
; repeats
; 80, a0, c0
; repeat decompressed data from output
.repeatertype
push hl
push af
; get next byte
ld a, [hli]
; absolute?
bit 7, a
jr z, .absolute
; relative
; a = -a
and %01111111 ; forget the bit we just looked at
cpl
; add de (current output address)
add e
ld l, a
ld a, $ff ; -1
adc d
ld h, a
jr .repeaters
.absolute
; get next byte (lo)
ld l, [hl]
; last byte (hi)
ld h, a
; add starting output address
ld a, [$c2c2]
add l
ld l, a
ld a, [$c2c3]
adc h
ld h, a
.repeaters
pop af
cp $80 ; LZ_REPEAT
jr z, .repeat
cp $a0 ; LZ_FLIP
jr z, .flip
cp $c0 ; LZ_REVERSE
jr z, .reverse
; e0 -> 80
; 80 ; LZ_REPEAT
; repeat some decompressed data
.repeat
; done?
dec c
jr nz, .repeatnext
dec b
jr z, .cleanup
.repeatnext
ld a, [hli]
ld [de], a
inc de
jr .repeat
; a0 ; LZ_FLIP
; repeat some decompressed data w/ flipped bit order
.flip
dec c
jr nz, .flipnext
dec b
jp z, .cleanup
.flipnext
ld a, [hli]
push bc
ld bc, $0008
.fliploop
rra
rl b
dec c
jr nz, .fliploop
ld a, b
pop bc
ld [de], a
inc de
jr .flip
; c0 ; LZ_REVERSE
; repeat some decompressed data in reverse
.reverse
dec c
jr nz, .reversenext
dec b
jp z, .cleanup
.reversenext
ld a, [hld]
ld [de], a
inc de
jr .reverse
.cleanup
; get type of repeat we just used
pop hl
; was it relative or absolute?
bit 7, [hl]
jr nz, .next
; skip two bytes for absolute
inc hl
; skip one byte for relative
.next
inc hl
jp .loop
; c2f

225
engine/init.asm Normal file
View File

@ -0,0 +1,225 @@
Reset: ; 150
di
call CleanSoundRestart
xor a
ld [$ffde], a
call ClearPalettes
xor a
ld [rIF], a
ld a, 1 ; VBlank int
ld [rIE], a
ei
ld hl, $cfbe
set 7, [hl]
ld c, 32
call DelayFrames
jr Init
; 16e
_Start: ; 16e
cp $11
jr z, .asm_175
xor a
jr .asm_177
.asm_175
ld a, $1
.asm_177
ld [hCGB], a
ld a, $1
ld [$ffea], a
; 17d
Init: ; 17d
di
xor a
ld [rIF], a
ld [rIE], a
ld [rRP], a
ld [rSCX], a
ld [rSCY], a
ld [rSB], a
ld [rSC], a
ld [rWX], a
ld [rWY], a
ld [rBGP], a
ld [rOBP0], a
ld [rOBP1], a
ld [rTMA], a
ld [rTAC], a
ld [$d000], a
ld a, %100 ; Start timer at 4096Hz
ld [rTAC], a
.wait
ld a, [rLY]
cp 145
jr nz, .wait
xor a
ld [rLCDC], a
; Clear WRAM bank 0
ld hl, $c000
ld bc, $d000 - $c000
.asm_1b1
ld [hl], 0
inc hl
dec bc
ld a, b
or c
jr nz, .asm_1b1
ld sp, Stack - 1
; Clear HRAM
ld a, [hCGB]
push af
ld a, [$ffea]
push af
xor a
ld hl, $ff80
ld bc, $ffff - $ff80
call ByteFill
pop af
ld [$ffea], a
pop af
ld [hCGB], a
call ClearWRAM
ld a, 1
ld [rSVBK], a
call ClearVRAM
call ClearSprites
call Function270
ld a, BANK(LoadPushOAM)
rst Bankswitch
call LoadPushOAM
xor a
ld [$ffde], a
ld [hSCX], a
ld [hSCY], a
ld [rJOYP], a
ld a, $8 ; HBlank int enable
ld [rSTAT], a
ld a, $90
ld [hWY], a
ld [rWY], a
ld a, 7
ld [hWX], a
ld [rWX], a
ld a, %11100011
; LCD on
; Win tilemap 1
; Win on
; BG/Win tiledata 0
; BG Tilemap 0
; OBJ 8x8
; OBJ on
; BG on
ld [rLCDC], a
ld a, $ff
ld [$ffcb], a
callba Function9890
ld a, $9c
ld [$ffd7], a
xor a
ld [hBGMapAddress], a
callba StartClock
xor a
ld [MBC3LatchClock], a
ld [MBC3SRamEnable], a
ld a, [hCGB]
and a
jr z, .asm_22b
call Function2ff7
.asm_22b
xor a
ld [rIF], a
ld a, %1111 ; VBlank, LCDStat, Timer, Serial interrupts
ld [rIE], a
ei
call DelayFrame
ld a, $30
call Predef
call CleanSoundRestart
xor a
ld [CurMusic], a
jp GameInit
; 245
ClearVRAM: ; 245
; Wipe VRAM banks 0 and 1
ld a, 1
ld [rVBK], a
call .clear
xor a
ld [rVBK], a
.clear
ld hl, VTiles0
ld bc, $2000
xor a
call ByteFill
ret
; 25a
ClearWRAM: ; 25a
; Wipe swappable WRAM banks (1-7)
ld a, 1
.asm_25c
push af
ld [rSVBK], a
xor a
ld hl, $d000
ld bc, $1000
call ByteFill
pop af
inc a
cp 8
jr nc, .asm_25c
ret
; 270
Function270: ; 270
ld a, $0
call GetSRAMBank
ld hl, $a000
ld bc, $0020
xor a
call ByteFill
call CloseSRAM
ret
; 283

View File

@ -103,7 +103,7 @@ Joypad: ; 935
; For example, soft reset:
and BUTTON_A | BUTTON_B | SELECT | START
cp BUTTON_A | BUTTON_B | SELECT | START
jp z, $0150 ; reset
jp z, Reset
ret
; 984

829
engine/movement.asm Normal file

File diff suppressed because it is too large Load Diff

View File

@ -485,11 +485,11 @@ Script_verbosegiveitem: ; 0x96f60
; item (ItemLabelByte)
; quantity (DecimalParam)
call $77ca
call Script_giveitem
call CurItemName
ld de, StringBuffer1
ld a, $1
call $76c8
call Function976c8
ld b, BANK(GiveItemScript)
ld de, GiveItemScript
jp ScriptCall
@ -535,7 +535,7 @@ Script_verbosegiveitem2: ; 0x96f8e
.asm_96f98
ld [$d106], a
call GetScriptByte
call $769e
call Unknown_0x9769e
ld a, [de]
ld [$d10c], a
ld hl, $d892
@ -548,7 +548,7 @@ Script_verbosegiveitem2: ; 0x96f8e
call CurItemName
ld de, StringBuffer1
ld a, $1
call $76c8
call Function976c8
ld b, BANK(GiveItemScript)
ld de, GiveItemScript
jp ScriptCall
@ -1021,6 +1021,9 @@ Script_applymovement: ; 0x971f3
call GetScriptByte
call Unknown_0x971e3
ld c, a
; 971fa
Function971fa: ; 971fa
push bc
ld a, c
ld a, $1
@ -1028,7 +1031,7 @@ Script_applymovement: ; 0x971f3
rst $8
pop bc
push bc
call $7221
call Unknown_0x97221
pop bc
call GetScriptByte
ld l, a
@ -1058,7 +1061,7 @@ Script_applymovement2: ; 0x97228
ld a, [$ffe0]
ld c, a
jp $71fa
jp Function971fa
; 0x9722e
Script_faceplayer: ; 0x9722e
@ -1079,7 +1082,7 @@ Script_faceplayer: ; 0x9722e
ld e, a
ld a, [$ffe0]
ld d, a
call $728b
call Unknown_0x9728b
ret
; 0x97248
@ -1114,7 +1117,7 @@ Script_faceperson: ; 0x97248
add a
ld e, a
ld d, c
call $728b
call Unknown_0x9728b
ret
; 0x97274
@ -1135,7 +1138,7 @@ Script_spriteface: ; 0x97274
add a
add a
ld e, a
call $728b
call Unknown_0x9728b
ret
; 0x9728b
@ -1161,7 +1164,7 @@ Unknown_0x9728b: ; 0x9728b
ld hl, $d0ed
bit 6, [hl]
jr nz, .asm_972b5 ; 0x972b0 $3
call $72bc
call Unknown_0x972bc
.asm_972b5
call $1ad2
ret
@ -1173,7 +1176,7 @@ Unknown_0x9728b: ; 0x9728b
Unknown_0x972bc: ; 0x972bc
call $217a
ld hl, $c4a0
ld hl, TileMap
ld bc, $0168
.asm_972c5
res 7, [hl]
@ -1211,7 +1214,7 @@ Script_appear: ; 0x972dd
call $1956
ld a, [$ffaf]
ld b, $0
call $730b
call Unknown_0x9730b
ret
; 0x972ee
@ -1229,7 +1232,7 @@ Script_disappear: ; 0x972ee
call $199f
ld a, [$ffaf]
ld b, $1
call $730b
call Unknown_0x9730b
ld a, $1
ld hl, $5920
rst $8
@ -1543,9 +1546,7 @@ Script_returnafterbattle: ; 0x97459
jr z, .asm_9748e ; 0x97481 $b
ld b, $24
ld de, $4255
ld a, $25
ld hl, $7c4f
rst $8
callba Function97c4f
.asm_9748e
jp Script_reloadmap
; 0x97491
@ -1978,7 +1979,7 @@ Script_random: ; 0x97640
and a
ret z
ld c, a
call $7673
call Unknown_0x97673
and a
jr z, .asm_9765f ; 0x9764d $10
ld b, a
@ -2027,7 +2028,7 @@ Script_checkcode: ; 0x9767d
; variable_id (SingleByteParam)
call GetScriptByte
call $769e
call Unknown_0x9769e
ld a, [de]
ld [$c2dd], a
ret
@ -2039,7 +2040,7 @@ Script_writevarcode: ; 0x97688
; variable_id (SingleByteParam)
call GetScriptByte
call $769e
call Unknown_0x9769e
ld a, [$c2dd]
ld [de], a
ret
@ -2052,7 +2053,7 @@ Script_writecode: ; 0x97693
; value (SingleByteParam)
call GetScriptByte
call $769e
call Unknown_0x9769e
call GetScriptByte
ld [de], a
ret
@ -2096,9 +2097,12 @@ Script_pokenamemem: ; 0x976ae
Unknown_976c0: ; 0x976c0
call GetScriptByte
cp $3
jr c, .asm_976c8 ; 0x976c5 $1
jr c, .asm_976c8
xor a
.asm_976c8
; 976c8
Function976c8: ; 976c8
ld hl, StringBuffer3
ld bc, 19
call AddNTimes
@ -2197,8 +2201,8 @@ Script_readmoney: ; 0x97732
; account (SingleByteParam)
; memory (SingleByteParam)
call $7771
call $7861
call Unknown_0x97771
call Unknown_0x97861
ld hl, StringBuffer1
ld bc, $4306
call $3198
@ -2211,7 +2215,7 @@ Script_readcoins: ; 0x97747
; parameters:
; memory (SingleByteParam)
call $7771
call Unknown_0x97771
ld hl, StringBuffer1
ld de, $d855
ld bc, $4206
@ -2225,7 +2229,7 @@ Script_RAM2MEM: ; 0x9775c
; parameters:
; memory (SingleByteParam)
call $7771
call Unknown_0x97771
ld de, $c2dd
ld hl, StringBuffer1
ld bc, $4103
@ -2372,8 +2376,8 @@ Script_givemoney: ; 0x97829
; account (SingleByteParam)
; money (MoneyByteParam)
call $7861
call $786d
call Unknown_0x97861
call Unknown_0x9786d
ld a, $5
ld hl, $5fd7
rst $8
@ -2386,8 +2390,8 @@ Script_takemoney: ; 0x97836
; account (SingleByteParam)
; money (MoneyByteParam)
call $7861
call $786d
call Unknown_0x97861
call Unknown_0x9786d
ld a, $5
ld hl, $5ffa
rst $8
@ -2400,8 +2404,8 @@ Script_checkmoney: ; 0x97843
; account (SingleByteParam)
; money (MoneyByteParam)
call $7861
call $786d
call Unknown_0x97861
call Unknown_0x9786d
ld a, $5
ld hl, $600b
rst $8
@ -2451,7 +2455,7 @@ Script_givecoins: ; 0x97881
; parameters:
; coins (CoinByteParam)
call $78a0
call Function978a0
ld a, $5
ld hl, $606f
rst $8
@ -2463,7 +2467,7 @@ Script_takecoins: ; 0x9788b
; parameters:
; coins (CoinByteParam)
call $78a0
call Function978a0
ld a, $5
ld hl, $608f
rst $8
@ -2475,11 +2479,14 @@ Script_checkcoins: ; 0x97895
; parameters:
; coins (CoinByteParam)
call $78a0
call Function978a0
ld a, $5
ld hl, $60a1
rst $8
jr Unknown_9784f ; 0x9789e $af
jr Unknown_9784f
; 978a0
Function978a0: ; 978a0
call GetScriptByte
ld [$ffc4], a
call GetScriptByte
@ -2718,7 +2725,7 @@ Script_setbit2: ; 0x979bb
call GetScriptByte
ld d, a
ld b, $1
call $79ee
call Unknown_0x979ee
ret
; 0x979c9
@ -2732,7 +2739,7 @@ Script_clearbit2: ; 0x979c9
call GetScriptByte
ld d, a
ld b, $0
call $79ee
call Unknown_0x979ee
ret
; 0x979d7
@ -2746,7 +2753,7 @@ Script_checkbit2: ; 0x979d7
call GetScriptByte
ld d, a
ld b, $2
call $79ee
call Unknown_0x979ee
ld a, c
and a
jr z, .asm_979ea ; 0x979e6 $2
@ -2897,9 +2904,7 @@ Script_writecmdqueue: ; 0x97a8b
ld d, a
ld a, [ScriptBank]
ld b, a
ld a, $25
ld hl, $7e31
rst $8
callba Function97e31
ret
; 0x97a9e
@ -2912,9 +2917,7 @@ Script_delcmdqueue: ; 0x97a9e
ld [$c2dd], a
call GetScriptByte
ld b, a
ld a, $25
ld hl, $7e5c
rst $8
callba Function97e5c
ret c
ld a, $1
ld [$c2dd], a
@ -2976,16 +2979,12 @@ Script_warpcheck: ; 0x97af6
call $224a
ret nc
ld a, $25
ld hl, $66d0
rst $8
callba Function966d0
ret
; 0x97b01
Unknown_0x97b01: ; 0x97b01
ld a, $25
ld hl, $66d0
rst $8
callba Function966d0
ret
; 0x97b08
@ -3005,7 +3004,7 @@ Script_newloadmap: ; 0x97b08
Script_reloadandreturn: ; 0x97b16
; script command 0x92
call $7b08
call Script_newloadmap
jp Script_end
; 0x97b1c
@ -3203,8 +3202,9 @@ Script_credits: ; 0x97bf3
ld hl, $6455
rst $8
; fallthrough
DisplayCredits:
call $7bc0
call Script_resetfuncs
ld a, $3
call $261b
call StopScript

1229
engine/text.asm Normal file

File diff suppressed because it is too large Load Diff

View File

@ -71,31 +71,31 @@ VBlank0: ; 2b1
; advance rng
ld a, [rDIV]
ld b, a
ld a, [$ffe1]
ld a, [hRandomAdd]
adc b
ld [$ffe1], a
ld [hRandomAdd], a
ld a, [rDIV]
ld b, a
ld a, [$ffe2]
ld a, [hRandomSub]
sbc b
ld [$ffe2], a
ld [hRandomSub], a
; save bank
ld a, [$ff9d] ; current bank
ld a, [hROMBank] ; current bank
ld [$ff8a], a
; scroll x
ld a, [$ffcf]
ld a, [hSCX]
ld [rSCX], a
; scroll y
ld a, [$ffd0]
ld a, [hSCY]
ld [rSCY], a
; window y
ld a, [$ffd2]
ld a, [hWY]
ld [rWY], a
; window x + 7
ld a, [$ffd1]
ld a, [hWX]
ld [rWX], a
; some time management is in order
@ -123,7 +123,7 @@ VBlank0: ; 2b1
.doneframeaction
; oam update off?
ld a, [$ffd8]
ld a, [hOAMUpdate]
and a
jr nz, .vblankoccurred
@ -146,12 +146,12 @@ VBlank0: ; 2b1
xor a
ld [VBlankOccurred], a
; dec $cfb1 until 0
ld a, [$cfb1]
; dec OverworldDelay until 0
ld a, [OverworldDelay]
and a
jr z, .textdelay
dec a
ld [$cfb1], a
ld [OverworldDelay], a
.textdelay
; dec text delay counter until 0
@ -172,7 +172,7 @@ VBlank0: ; 2b1
rst Bankswitch ; restore bank
;
ld a, [$ff98]
ld a, [hSeconds]
ld [$ffe3], a
ret
@ -183,7 +183,7 @@ VBlank2: ; 325
; sound only
; save bank
ld a, [$ff9d]
ld a, [hROMBank]
ld [$ff8a], a
; update sound
@ -211,15 +211,15 @@ VBlank1: ; 337
; sound / lcd stat
; save bank
ld a, [$ff9d]
ld a, [hROMBank]
ld [$ff8a], a
; scroll x
ld a, [$ffcf]
ld a, [hSCX]
ld [rSCX], a
; scroll y
ld a, [$ffd0]
ld a, [hSCY]
ld [rSCY], a
; time-sensitive fns
@ -291,7 +291,7 @@ UpdatePals: ; 37f
; update pals for either dmg or cgb
; check cgb
ld a, [$ffe6]
ld a, [hCGB]
and a
jp nz, UpdateCGBPals
@ -319,18 +319,18 @@ VBlank3: ; 396
; sound / lcd stat
; save bank
ld a, [$ff9d]
ld a, [hROMBank]
ld [$ff8a], a
; scroll x
ld a, [$ffcf]
ld a, [hSCX]
ld [rSCX], a
; scroll y
ld a, [$ffd0]
ld a, [hSCY]
ld [rSCY], a
; any pals to update?
ld a, [$ffe5]
ld a, [hCGBPalUpdate]
and a
call nz, ForceUpdateCGBPals
jr c, .vblankoccurred
@ -404,7 +404,7 @@ VBlank4: ; 3df
; sound
; save bank
ld a, [$ff9d]
ld a, [hROMBank]
ld [$ff8a], a
call UpdateBGMap
@ -451,11 +451,11 @@ VBlank5: ; 400
;
; save bank
ld a, [$ff9d]
ld a, [hROMBank]
ld [$ff8a], a
; scroll x
ld a, [$ffcf]
ld a, [hSCX]
ld [rSCX], a
; if we can update pals, skip this part
@ -509,7 +509,7 @@ VBlank6: ; 436
; sound
; save bank
ld a, [$ff9d]
ld a, [hROMBank]
ld [$ff8a], a
; inc frame counter

BIN
gfx/frames/1.1bpp Normal file

Binary file not shown.

BIN
gfx/frames/2.1bpp Normal file

Binary file not shown.

BIN
gfx/frames/3.1bpp Normal file

Binary file not shown.

BIN
gfx/frames/4.1bpp Normal file

Binary file not shown.

BIN
gfx/frames/5.1bpp Normal file

Binary file not shown.

Some files were not shown because too many files have changed in this diff Show More