pokecrystal/gfx/load_pics.asm

491 lines
6.3 KiB
NASM
Raw Normal View History

2016-01-29 05:57:06 +00:00
GetUnownLetter: ; 51040
; Return Unown letter in UnownLetter based on DVs at hl
; Take the middle 2 bits of each DV and place them in order:
; atk def spd spc
; .ww..xx. .yy..zz.
; atk
ld a, [hl]
and %01100000
sla a
ld b, a
; def
ld a, [hli]
and %00000110
swap a
srl a
or b
ld b, a
; spd
ld a, [hl]
and %01100000
swap a
sla a
or b
ld b, a
; spc
ld a, [hl]
and %00000110
srl a
or b
; Divide by 10 to get 0-25
ld [hDividend + 3], a
xor a
ld [hDividend], a
ld [hDividend + 1], a
ld [hDividend + 2], a
ld a, 10
ld [hDivisor], a
ld b, 4
call Divide
; Increment to get 1-26
ld a, [hQuotient + 2]
inc a
ld [UnownLetter], a
ret
GetFrontpic: ; 51077
ld a, [CurPartySpecies]
ld [CurSpecies], a
call IsAPokemon
ret c
ld a, [rSVBK]
push af
call _GetFrontpic
pop af
ld [rSVBK], a
ret
FrontpicPredef: ; 5108b
ld a, [CurPartySpecies]
ld [CurSpecies], a
call IsAPokemon
ret c
ld a, [rSVBK]
push af
xor a
ld [hBGMapMode], a
call _GetFrontpic
call Function51103
pop af
ld [rSVBK], a
ret
_GetFrontpic: ; 510a5
push de
call GetBaseData
ld a, [BasePicSize]
and $f
ld b, a
push bc
call GetFrontpicPointer
ld a, $6
ld [rSVBK], a
ld a, b
ld de, wDecompressScratch + $800
call FarDecompress
pop bc
ld hl, wDecompressScratch
ld de, wDecompressScratch + $800
call Function512ab
pop hl
push hl
ld de, wDecompressScratch
ld c, 7 * 7
ld a, [hROMBank]
ld b, a
call Get2bpp
pop hl
ret
GetFrontpicPointer: ; 510d7
GLOBAL PicPointers, UnownPicPointers
ld a, [CurPartySpecies]
cp UNOWN
jr z, .unown
ld a, [CurPartySpecies]
ld d, BANK(PicPointers)
jr .ok
.unown
ld a, [UnownLetter]
ld d, BANK(UnownPicPointers)
.ok
ld hl, PicPointers ; UnownPicPointers
dec a
ld bc, 6
call AddNTimes
ld a, d
call GetFarByte
call FixPicBank
push af
inc hl
ld a, d
call GetFarHalfword
pop bc
ret
Function51103: ; 51103
ld a, $1
ld [rVBK], a
push hl
ld de, wDecompressScratch
ld c, 7 * 7
ld a, [hROMBank]
ld b, a
call Get2bpp
pop hl
ld de, 7 * 7 tiles
add hl, de
push hl
ld a, $1
ld hl, BasePicSize
call GetFarWRAMByte
pop hl
and $f
ld de, w6_d800 + 5 * 5 tiles
ld c, 5 * 5
cp 5
jr z, .got_dims
ld de, w6_d800 + 6 * 6 tiles
ld c, 6 * 6
cp 6
jr z, .got_dims
ld de, w6_d800 + 7 * 7 tiles
ld c, 7 * 7
.got_dims
push hl
push bc
call Function5114f
pop bc
pop hl
ld de, wDecompressScratch
ld a, [hROMBank]
ld b, a
call Get2bpp
xor a
ld [rVBK], a
ret
Function5114f: ; 5114f
ld hl, wDecompressScratch
swap c
ld a, c
and $f
ld b, a
ld a, c
and $f0
ld c, a
push bc
call LoadFrontpic
pop bc
.asm_51161
push bc
ld c, $0
call LoadFrontpic
pop bc
dec b
jr nz, .asm_51161
ret
GetBackpic: ; 5116c
ld a, [CurPartySpecies]
call IsAPokemon
ret c
ld a, [CurPartySpecies]
ld b, a
ld a, [UnownLetter]
ld c, a
ld a, [rSVBK]
push af
ld a, $6
ld [rSVBK], a
push de
; These are assumed to be at the same
; address in their respective banks.
GLOBAL PicPointers, UnownPicPointers
ld hl, PicPointers ; UnownPicPointers
ld a, b
ld d, BANK(PicPointers)
cp UNOWN
jr nz, .ok
ld a, c
ld d, BANK(UnownPicPointers)
.ok
dec a
ld bc, 6
call AddNTimes
ld bc, 3
add hl, bc
ld a, d
call GetFarByte
call FixPicBank
push af
inc hl
ld a, d
call GetFarHalfword
ld de, wDecompressScratch
pop af
call FarDecompress
ld hl, wDecompressScratch
ld c, 6 * 6
call FixBackpicAlignment
pop hl
ld de, wDecompressScratch
ld a, [hROMBank]
ld b, a
call Get2bpp
pop af
ld [rSVBK], a
ret
FixPicBank: ; 511c5
; This is a thing for some reason.
push hl
push bc
sub PICS_1 - PICS_FIX
ld c, a
ld b, 0
ld hl, .PicsBanks
add hl, bc
ld a, [hl]
pop bc
pop hl
ret
.PicsBanks: ; 511d4
db PICS_1
db PICS_2
db PICS_3
db PICS_4
db PICS_5
db PICS_6
db PICS_7
db PICS_8
db PICS_9
db PICS_10
db PICS_11
db PICS_12
db PICS_13
db PICS_14
db PICS_15
db PICS_16
db PICS_17
db PICS_18
db PICS_19
db PICS_19 + 1
db PICS_19 + 2
db PICS_19 + 3
db PICS_19 + 4
db PICS_19 + 5
Function511ec: ; 511ec
ld a, c
push de
ld hl, PicPointers
dec a
ld bc, 6
call AddNTimes
ld a, BANK(PicPointers)
call GetFarByte
call FixPicBank
push af
inc hl
ld a, BANK(PicPointers)
call GetFarHalfword
pop af
pop de
call FarDecompress
ret
GetTrainerPic: ; 5120d
ld a, [TrainerClass]
and a
ret z
cp NUM_TRAINER_CLASSES
ret nc
call WaitBGMap
xor a
ld [hBGMapMode], a
ld hl, TrainerPicPointers
ld a, [TrainerClass]
dec a
ld bc, 3
call AddNTimes
ld a, [rSVBK]
push af
ld a, $6
ld [rSVBK], a
push de
ld a, BANK(TrainerPicPointers)
call GetFarByte
call FixPicBank
push af
inc hl
ld a, BANK(TrainerPicPointers)
call GetFarHalfword
pop af
ld de, wDecompressScratch
call FarDecompress
pop hl
ld de, wDecompressScratch
ld c, 7 * 7
ld a, [hROMBank]
ld b, a
call Get2bpp
pop af
ld [rSVBK], a
call WaitBGMap
ld a, $1
ld [hBGMapMode], a
ret
DecompressPredef: ; 5125d
; Decompress lz data from b:hl to scratch space at 6:d000, then copy it to address de.
ld a, [rSVBK]
push af
ld a, 6
ld [rSVBK], a
push de
push bc
ld a, b
ld de, wDecompressScratch
call FarDecompress
pop bc
ld de, wDecompressScratch
pop hl
ld a, [hROMBank]
ld b, a
call Get2bpp
pop af
ld [rSVBK], a
ret
FixBackpicAlignment: ; 5127c
push de
push bc
ld a, [wBoxAlignment]
and a
jr z, .keep_dims
ld a, c
cp 7 * 7
ld de, 7 * 7 tiles
jr z, .got_dims
cp 6 * 6
ld de, 6 * 6 tiles
jr z, .got_dims
ld de, 5 * 5 tiles
.got_dims
ld a, [hl]
ld b, $0
ld c, $8
.loop
rra
rl b
dec c
jr nz, .loop
ld a, b
ld [hli], a
dec de
ld a, e
or d
jr nz, .got_dims
.keep_dims
pop bc
pop de
ret
Function512ab: ; 512ab
ld a, b
cp 6
jr z, .six
cp 5
jr z, .five
.seven_loop
ld c, $70
call LoadFrontpic
dec b
jr nz, .seven_loop
ret
.six
ld c, $70
xor a
call .Fill
.six_loop
ld c, $10
xor a
call .Fill
ld c, $60
call LoadFrontpic
dec b
jr nz, .six_loop
ret
.five
ld c, $70
xor a
call .Fill
.five_loop
ld c, $20
xor a
call .Fill
ld c, $50
call LoadFrontpic
dec b
jr nz, .five_loop
ld c, $70
xor a
call .Fill
ret
.Fill:
2016-01-29 05:57:06 +00:00
ld [hli], a
dec c
jr nz, .Fill
ret
LoadFrontpic: ; 512f2
ld a, [wBoxAlignment]
and a
jr nz, .x_flip
.left_loop
ld a, [de]
inc de
ld [hli], a
dec c
jr nz, .left_loop
ret
.x_flip
push bc
.right_loop
ld a, [de]
inc de
ld b, a
xor a
rept 8
rr b
rla
endr
ld [hli], a
dec c
jr nz, .right_loop
pop bc
ret