shithub: pokecrystal

Download patch

ref: 4161ec98b4ab19863ae35502c9959892effbf6ea
parent: 40125a7f4d6450f4cc903234957c22d734fd0a42
author: Remy Oukaour <remy.oukaour@gmail.com>
date: Wed Jan 17 17:37:04 EST 2018

Partially document SGB data from pokered

--- a/constants.asm
+++ b/constants.asm
@@ -44,7 +44,7 @@
 INCLUDE "constants/sprite_anim_constants.asm"
 INCLUDE "constants/tileset_constants.asm"
 INCLUDE "constants/collision_constants.asm"
-INCLUDE "constants/cgb_constants.asm"
+INCLUDE "constants/scgb_constants.asm"
 INCLUDE "constants/battle_tower_constants.asm"
 INCLUDE "constants/cry_constants.asm"
 INCLUDE "constants/audio_constants.asm"
--- a/constants/cgb_constants.asm
+++ /dev/null
@@ -1,36 +1,0 @@
-; GetSGBLayout arguments (see engine/cgb_layouts.asm and engine/sgb_layouts.asm)
-	const_def
-	const SCGB_BATTLE_GRAYSCALE
-	const SCGB_BATTLE_COLORS
-	const SCGB_POKEGEAR_PALS
-	const SCGB_STATS_SCREEN_HP_PALS
-	const SCGB_POKEDEX
-	const SCGB_SLOT_MACHINE
-	const SCGB_06
-	const SCGB_07
-	const SCGB_DIPLOMA
-	const SCGB_MAPPALS
-	const SCGB_PARTY_MENU
-	const SCGB_EVOLUTION
-	const SCGB_0C
-	const SCGB_0D
-	const SCGB_MOVE_LIST
-	const SCGB_0F
-	const SCGB_POKEDEX_SEARCH_OPTION
-	const SCGB_11
-	const SCGB_POKEPIC
-	const SCGB_13
-	const SCGB_PACKPALS
-	const SCGB_TRAINER_CARD
-	const SCGB_POKEDEX_UNOWN_MODE
-	const SCGB_BILLS_PC
-	const SCGB_UNOWN_PUZZLE
-	const SCGB_GAMEFREAK_LOGO
-	const SCGB_PLAYER_OR_MON_FRONTPIC_PALS
-	const SCGB_TRADE_TUBE
-	const SCGB_TRAINER_OR_MON_FRONTPIC_PALS
-	const SCGB_MYSTERY_GIFT
-	const SCGB_1E
-
-SCGB_PARTY_MENU_HP_PALS  EQU -4
-SCGB_RAM EQU -1
--- /dev/null
+++ b/constants/scgb_constants.asm
@@ -1,0 +1,147 @@
+; GetSGBLayout arguments (see engine/cgb_layouts.asm and engine/sgb_layouts.asm)
+	const_def
+	const SCGB_BATTLE_GRAYSCALE
+	const SCGB_BATTLE_COLORS
+	const SCGB_POKEGEAR_PALS
+	const SCGB_STATS_SCREEN_HP_PALS
+	const SCGB_POKEDEX
+	const SCGB_SLOT_MACHINE
+	const SCGB_06
+	const SCGB_07
+	const SCGB_DIPLOMA
+	const SCGB_MAPPALS
+	const SCGB_PARTY_MENU
+	const SCGB_EVOLUTION
+	const SCGB_0C
+	const SCGB_0D
+	const SCGB_MOVE_LIST
+	const SCGB_0F
+	const SCGB_POKEDEX_SEARCH_OPTION
+	const SCGB_11
+	const SCGB_POKEPIC
+	const SCGB_13
+	const SCGB_PACKPALS
+	const SCGB_TRAINER_CARD
+	const SCGB_POKEDEX_UNOWN_MODE
+	const SCGB_BILLS_PC
+	const SCGB_UNOWN_PUZZLE
+	const SCGB_GAMEFREAK_LOGO
+	const SCGB_PLAYER_OR_MON_FRONTPIC_PALS
+	const SCGB_TRADE_TUBE
+	const SCGB_TRAINER_OR_MON_FRONTPIC_PALS
+	const SCGB_MYSTERY_GIFT
+	const SCGB_1E
+
+SCGB_PARTY_MENU_HP_PALS  EQU -4
+SCGB_RAM EQU -1
+
+; PredefPals indexes (see gfx/sgb/predef.pal)
+	const_def
+	const PREDEFPAL_00
+	const PREDEFPAL_01
+	const PREDEFPAL_02
+	const PREDEFPAL_03
+	const PREDEFPAL_04
+	const PREDEFPAL_05
+	const PREDEFPAL_06
+	const PREDEFPAL_07
+	const PREDEFPAL_08
+	const PREDEFPAL_09
+	const PREDEFPAL_0A
+	const PREDEFPAL_0B
+	const PREDEFPAL_0C
+	const PREDEFPAL_0D
+	const PREDEFPAL_0E
+	const PREDEFPAL_0F
+	const PREDEFPAL_10
+	const PREDEFPAL_11
+	const PREDEFPAL_12
+	const PREDEFPAL_13
+	const PREDEFPAL_14
+	const PREDEFPAL_15
+	const PREDEFPAL_16
+	const PREDEFPAL_17
+	const PREDEFPAL_18
+	const PREDEFPAL_19
+	const PREDEFPAL_1A
+	const PREDEFPAL_1B
+	const PREDEFPAL_1C
+	const PREDEFPAL_1D
+	const PREDEFPAL_1E
+	const PREDEFPAL_1F
+	const PREDEFPAL_20
+	const PREDEFPAL_21
+	const PREDEFPAL_22
+	const PREDEFPAL_23
+	const PREDEFPAL_24
+	const PREDEFPAL_25
+	const PREDEFPAL_26
+	const PREDEFPAL_27
+	const PREDEFPAL_28
+	const PREDEFPAL_29
+	const PREDEFPAL_2A
+	const PREDEFPAL_2B
+	const PREDEFPAL_2C
+	const PREDEFPAL_2D
+	const PREDEFPAL_2E
+	const PREDEFPAL_2F
+	const PREDEFPAL_30
+	const PREDEFPAL_31
+	const PREDEFPAL_32
+	const PREDEFPAL_33
+	const PREDEFPAL_34
+	const PREDEFPAL_35
+	const PREDEFPAL_36
+	const PREDEFPAL_37
+	const PREDEFPAL_38
+	const PREDEFPAL_39
+	const PREDEFPAL_3A
+	const PREDEFPAL_3B
+	const PREDEFPAL_3C
+	const PREDEFPAL_3D
+	const PREDEFPAL_3E
+	const PREDEFPAL_3F
+	const PREDEFPAL_40
+	const PREDEFPAL_41
+	const PREDEFPAL_42
+	const PREDEFPAL_43
+	const PREDEFPAL_44
+	const PREDEFPAL_45
+	const PREDEFPAL_46
+	const PREDEFPAL_47
+	const PREDEFPAL_48
+	const PREDEFPAL_49
+	const PREDEFPAL_4A
+	const PREDEFPAL_4B
+	const PREDEFPAL_4C
+	const PREDEFPAL_4D
+	const PREDEFPAL_4E
+
+; SGB system command codes
+; http://gbdev.gg8.se/wiki/articles/SGB_Functions#SGB_System_Command_Table
+	const_def
+	const SGB_PAL01
+	const SGB_PAL23
+	const SGB_PAL03
+	const SGB_PAL12
+	const SGB_ATTR_BLK
+	const SGB_ATTR_LIN
+	const SGB_ATTR_DIV
+	const SGB_ATTR_CHR
+	const SGB_SOUND
+	const SGB_SOU_TRN
+	const SGB_PAL_SET
+	const SGB_PAL_TRN
+	const SGB_ATRC_EN
+	const SGB_TEST_EN
+	const SGB_ICON_EN
+	const SGB_DATA_SND
+	const SGB_DATA_TRN
+	const SGB_MLT_REG
+	const SGB_JUMP
+	const SGB_CHR_TRN
+	const SGB_PCT_TRN
+	const SGB_ATTR_TRN
+	const SGB_ATTR_SET
+	const SGB_MASK_EN
+	const SGB_OBJ_TRN
--- a/engine/cgb_layouts.asm
+++ b/engine/cgb_layouts.asm
@@ -267,7 +267,7 @@
 
 _CGB_Pokedex: ; 8f70
 	ld de, wBGPals1
-	ld a, $1d
+	ld a, PREDEFPAL_1D
 	call GetPredefPal
 	call LoadHLPaletteIntoDE ; dex interface palette
 	ld a, [CurPartySpecies]
@@ -309,7 +309,7 @@
 
 _CGB_BillsPC: ; 8fca
 	ld de, wBGPals1
-	ld a, $1d
+	ld a, PREDEFPAL_1D
 	call GetPredefPal
 	call LoadHLPaletteIntoDE
 	ld a, [CurPartySpecies]
@@ -366,7 +366,7 @@
 
 _CGB_PokedexUnownMode: ; 903e
 	ld de, wBGPals1
-	ld a, $1d
+	ld a, PREDEFPAL_1D
 	call GetPredefPal
 	call LoadHLPaletteIntoDE
 	ld a, [CurPartySpecies]
@@ -444,7 +444,7 @@
 	call CopyFourPalettes
 	call WipeAttrMap
 	ld de, wOBPals1
-	ld a, $3c
+	ld a, PREDEFPAL_3C
 	call GetPredefPal
 	call LoadHLPaletteIntoDE
 	hlcoord 0, 6, AttrMap
@@ -508,12 +508,12 @@
 
 .Function9166: ; 9166
 	ld de, wBGPals1
-	ld a, $38
+	ld a, PREDEFPAL_38
 	call GetPredefPal
 	call LoadHLPaletteIntoDE
 
 	ld de, wOBPals1
-	ld a, $39
+	ld a, PREDEFPAL_39
 	call GetPredefPal
 	call LoadHLPaletteIntoDE
 	call WipeAttrMap
@@ -524,7 +524,7 @@
 	ld hl, PalPacket_9c36 + 1
 	call CopyFourPalettes
 	ld de, wOBPals1
-	ld a, $3a
+	ld a, PREDEFPAL_3A
 	call GetPredefPal
 	call LoadHLPaletteIntoDE
 	call WipeAttrMap
@@ -579,7 +579,7 @@
 	ld a, c
 	and a
 	jr z, .pokemon
-	ld a, $1a
+	ld a, PREDEFPAL_1A
 	call GetPredefPal
 	call LoadHLPaletteIntoDE
 	jr .got_palette
@@ -640,7 +640,7 @@
 	ld hl, PalPacket_9bc6 + 1
 	call CopyFourPalettes
 	ld de, wOBPals1
-	ld a, $4c
+	ld a, PREDEFPAL_4C
 	call GetPredefPal
 	call LoadHLPaletteIntoDE
 	ld a, [rSVBK]
@@ -685,7 +685,7 @@
 	ld a, PRYCE
 	call GetTrainerPalettePointer
 	call LoadPalette_White_Col1_Col2_Black
-	ld a, $24
+	ld a, PREDEFPAL_24
 	call GetPredefPal
 	call LoadHLPaletteIntoDE
 
@@ -767,7 +767,7 @@
 
 _CGB_MoveList: ; 9373
 	ld de, wBGPals1
-	ld a, $10
+	ld a, PREDEFPAL_10
 	call GetPredefPal
 	call LoadHLPaletteIntoDE
 	ld a, [PlayerHPPal]
@@ -803,7 +803,7 @@
 
 _CGB_PokedexSearchOption: ; 93ba
 	ld de, wBGPals1
-	ld a, $1d
+	ld a, PREDEFPAL_1D
 	call GetPredefPal
 	call LoadHLPaletteIntoDE
 	call WipeAttrMap
@@ -927,7 +927,7 @@
 
 _CGB_GamefreakLogo: ; 94fa
 	ld de, wBGPals1
-	ld a, $4e
+	ld a, PREDEFPAL_4E
 	call GetPredefPal
 	call LoadHLPaletteIntoDE
 	ld hl, .Palette
@@ -977,7 +977,7 @@
 	ld a, BANK(wOBPals1)
 	call FarCopyWRAM
 	ld de, wOBPals1 palette 7
-	ld a, $1c
+	ld a, PREDEFPAL_1C
 	call GetPredefPal
 	call LoadHLPaletteIntoDE
 	call WipeAttrMap
--- a/engine/color.asm
+++ b/engine/color.asm
@@ -187,7 +187,7 @@
 
 .cgb
 	ld de, wOBPals1
-	ld a, $3b
+	ld a, PREDEFPAL_3B
 	call GetPredefPal
 	jp LoadHLPaletteIntoDE
 
@@ -202,7 +202,7 @@
 
 .cgb
 	ld de, wOBPals1
-	ld a, $3c
+	ld a, PREDEFPAL_3C
 	call GetPredefPal
 	jp LoadHLPaletteIntoDE
 
@@ -765,10 +765,10 @@
 	ret z
 	ld a, $90
 	ld [rOBPI], a
-	ld a, $1c
+	ld a, PREDEFPAL_1C
 	call GetPredefPal
 	call .PushPalette
-	ld a, $21
+	ld a, PREDEFPAL_21
 	call GetPredefPal
 	call .PushPalette
 	ret
@@ -878,7 +878,7 @@
 	call PushSGBBorder
 	call SGBDelayCycles
 	call SGB_ClearVRAM
-	ld hl, PalPacket_9d66
+	ld hl, MaskEnCancelPacket
 	call PushSGBPals
 
 .skip
@@ -943,7 +943,7 @@
 	ret
 
 _InitSGBBorderPals:
-	ld hl, .PalPacketPointerTable
+	ld hl, .PacketPointerTable
 	ld c, 9
 .loop
 	push bc
@@ -959,27 +959,27 @@
 	jr nz, .loop
 	ret
 
-.PalPacketPointerTable:
-	dw PalPacket_9d56
-	dw PalPacket_9d76
-	dw PalPacket_9d86
-	dw PalPacket_9d96
-	dw PalPacket_9da6
-	dw PalPacket_9db6
-	dw PalPacket_9dc6
-	dw PalPacket_9dd6
-	dw PalPacket_9de6
+.PacketPointerTable:
+	dw MaskEnFreezePacket
+	dw DataSndPacket1
+	dw DataSndPacket2
+	dw DataSndPacket3
+	dw DataSndPacket4
+	dw DataSndPacket5
+	dw DataSndPacket6
+	dw DataSndPacket7
+	dw DataSndPacket8
 
 Unreferenced_Function9911:
 	di
 	xor a
 	ld [rJOYP], a
-	ld hl, PalPacket_9d56
+	ld hl, MaskEnFreezePacket
 	call PushSGBPals
 	call PushSGBBorder
 	call SGBDelayCycles
 	call SGB_ClearVRAM
-	ld hl, PalPacket_9d66
+	ld hl, MaskEnCancelPacket
 	call PushSGBPals
 	ei
 	ret
@@ -1005,7 +1005,7 @@
 	ret
 
 PushSGBBorderPalsAndWait:
-	ld hl, PalPacket_9d26
+	ld hl, MltReq2Packet
 	call PushSGBPals
 	call SGBDelayCycles
 	ld a, [rJOYP]
@@ -1050,7 +1050,7 @@
 	ret
 
 .FinalPush:
-	ld hl, PalPacket_9d16
+	ld hl, MltReq1Packet
 	call PushSGBPals
 	jp SGBDelayCycles
 
@@ -1065,7 +1065,7 @@
 	call DrawDefaultTiles
 	ld a, LCDC_DEFAULT
 	ld [rLCDC], a
-	ld hl, PalPacket_9d06
+	ld hl, PalTrnPacket
 	call PushSGBPals
 	xor a
 	ld [rBGP], a
@@ -1099,7 +1099,7 @@
 	call DrawDefaultTiles
 	ld a, LCDC_DEFAULT
 	ld [rLCDC], a
-	ld hl, PalPacket_9d46
+	ld hl, PctTrnPacket
 	call PushSGBPals
 	xor a
 	ld [rBGP], a
@@ -1123,7 +1123,7 @@
 	call DrawDefaultTiles
 	ld a, LCDC_DEFAULT
 	ld [rLCDC], a
-	ld hl, PalPacket_9d36
+	ld hl, ChrTrnPacket
 	call PushSGBPals
 	xor a
 	ld [rBGP], a
@@ -1188,8 +1188,8 @@
 	ret
 
 INCLUDE "gfx/sgb/blk_packets.asm"
-
 INCLUDE "gfx/sgb/pal_packets.asm"
+INCLUDE "gfx/sgb/data_snd_packets.asm"
 
 PredefPals:
 INCLUDE "gfx/sgb/predef.pal"
--- a/engine/sgb_layouts.asm
+++ b/engine/sgb_layouts.asm
@@ -113,22 +113,22 @@
 	call GetBattlemonBackpicPalettePointer
 
 	ld a, [hli]
-	ld [wSGBPals + $13], a
+	ld [wSGBPals + 19], a
 	ld a, [hli]
-	ld [wSGBPals + $14], a
+	ld [wSGBPals + 20], a
 	ld a, [hli]
-	ld [wSGBPals + $15], a
+	ld [wSGBPals + 21], a
 	ld a, [hl]
-	ld [wSGBPals + $16], a
+	ld [wSGBPals + 22], a
 	call GetEnemyFrontpicPalettePointer
 	ld a, [hli]
-	ld [wSGBPals + $19], a
+	ld [wSGBPals + 25], a
 	ld a, [hli]
-	ld [wSGBPals + $1a], a
+	ld [wSGBPals + 26], a
 	ld a, [hli]
-	ld [wSGBPals + $1b], a
+	ld [wSGBPals + 27], a
 	ld a, [hl]
-	ld [wSGBPals + $1c], a
+	ld [wSGBPals + 28], a
 
 	ld hl, wSGBPals
 	ld de, wSGBPals + $10
@@ -210,13 +210,13 @@
 	ld bc, $10
 	call CopyBytes
 	ld hl, wSGBPals + 3
-	ld [hl], $9f
+	ld [hl], LOW(palred 31 + palgreen 20 + palblue 10)
 	inc hl
-	ld [hl], $2a
+	ld [hl], HIGH(palred 31 + palgreen 20 + palblue 10)
 	inc hl
-	ld [hl], $5a
+	ld [hl], LOW(palred 26 + palgreen 10 + palblue 6)
 	inc hl
-	ld [hl], $19
+	ld [hl], HIGH(palred 26 + palgreen 10 + palblue 6)
 	ld a, [CurPartySpecies]
 	call GetMonPalettePointer_
 	ld a, [hli]
@@ -238,13 +238,13 @@
 	ld bc, $10
 	call CopyBytes
 	ld hl, wSGBPals + 3
-	ld [hl], $9f
+	ld [hl], LOW(palred 31 + palgreen 20 + palblue 10)
 	inc hl
-	ld [hl], $2a
+	ld [hl], HIGH(palred 31 + palgreen 20 + palblue 10)
 	inc hl
-	ld [hl], $5a
+	ld [hl], LOW(palred 26 + palgreen 10 + palblue 6)
 	inc hl
-	ld [hl], $19
+	ld [hl], HIGH(palred 26 + palgreen 10 + palblue 6)
 	ld a, [CurPartySpecies]
 	ld bc, TempMonDVs
 	call GetPlayerOrMonPalettePointer
@@ -273,13 +273,13 @@
 	ld bc, $10
 	call CopyBytes
 	ld hl, wSGBPals + 3
-	ld [hl], $9f
+	ld [hl], LOW(palred 31 + palgreen 20 + palblue 10)
 	inc hl
-	ld [hl], $2a
+	ld [hl], HIGH(palred 31 + palgreen 20 + palblue 10)
 	inc hl
-	ld [hl], $5a
+	ld [hl], LOW(palred 26 + palgreen 10 + palblue 6)
 	inc hl
-	ld [hl], $19
+	ld [hl], HIGH(palred 26 + palgreen 10 + palblue 6)
 	ld hl, wSGBPals
 	ld de, BlkPacket_9a86
 	ret
@@ -579,19 +579,19 @@
 	ret
 
 .route
-	ld a, $00
+	ld a, PREDEFPAL_00
 	ret
 
 .cave
-	ld a, $18
+	ld a, PREDEFPAL_18
 	ret
 
 .perm5
-	ld a, $06
+	ld a, PREDEFPAL_06
 	ret
 
 .gate
-	ld a, $03
+	ld a, PREDEFPAL_03
 	ret
 ; 8a45
 
--- a/gfx/sgb/blk_packets.asm
+++ b/gfx/sgb/blk_packets.asm
@@ -1,40 +1,87 @@
+; macros taken from pokered's data/sgb_packets.asm
+
+attr_blk: MACRO
+	db (SGB_ATTR_BLK << 3) + ((\1 * 6) / 16 + 1)
+	db \1
+ENDM
+
+attr_blk_data: MACRO
+	db \1 ; which regions are affected
+	db \2 + (\3 << 2) + (\4 << 4) ; palette for each region
+	db \5, \6, \7, \8 ; x1, y1, x2, y2
+ENDM
+
 BlkPacket_9a86:
-	db $21, $01, $03, $00, $00, $00, $13, $11, $00, $00, $00, $00, $00, $00, $00, $00
+	attr_blk 1
+	attr_blk_data %011, 0,0,0, 00,00, 19,17
+	ds 8
 
 BlkPacket_9a96:
-	db $21, $01, $07, $05, $00, $0a, $13, $0d, $00, $00, $00, $00, $00, $00, $00, $00
+	attr_blk 1
+	attr_blk_data %111, 1,1,0, 00,10, 19,13
+	ds 8
 
 BlkPacket_9aa6:
-	db $22, $05, $07, $0a, $00, $0c, $13, $11, $03, $05, $01, $00, $0a, $03, $03, $00
-	db $0a, $08, $13, $0a, $03, $0a, $00, $04, $08, $0b, $03, $0f, $0b, $00, $13, $07
+	attr_blk 5
+	attr_blk_data %111, 2,2,0, 00,12, 19,17
+	attr_blk_data %011, 1,1,0, 01,00, 10,03
+	attr_blk_data %011, 0,0,0, 10,08, 19,10
+	attr_blk_data %011, 2,2,0, 00,04, 08,11
+	attr_blk_data %011, 3,3,0, 11,00, 19,07
 
 BlkPacket_9ac6:
-	db $21, $01, $07, $05, $00, $01, $07, $07, $00, $00, $00, $00, $00, $00, $00, $00
+	attr_blk 1
+	attr_blk_data %111, 1,1,0, 00,01, 07,07
+	ds 8
 
 BlkPacket_9ad6:
-	db $21, $01, $07, $05, $0b, $01, $13, $02, $00, $00, $00, $00, $00, $00, $00, $00
+	attr_blk 1
+	attr_blk_data %111, 1,1,0, 11,01, 19,02
+	ds 8
 
 BlkPacket_9ae6:
-	db $21, $01, $07, $05, $01, $01, $08, $08, $00, $00, $00, $00, $00, $00, $00, $00
+	attr_blk 1
+	attr_blk_data %111, 1,1,0, 01,01, 08,08
+	ds 8
 
 BlkPacket_9af6:
-	db $21, $01, $07, $05, $07, $05, $0d, $0b, $00, $00, $00, $00, $00, $00, $00, $00
+	attr_blk 1
+	attr_blk_data %111, 1,1,0, 07,05, 13,11
+	ds 8
 
 BlkPacket_9b06:
-	db $22, $05, $03, $05, $00, $00, $13, $0b, $03, $0a, $00, $04, $13, $09, $02, $0f
-	db $00, $06, $13, $07, $03, $00, $04, $04, $0f, $09, $03, $00, $00, $0c, $13, $11
+	attr_blk 5
+	attr_blk_data %011, 1,1,0, 00,00, 19,11
+	attr_blk_data %011, 2,2,0, 00,04, 19,09
+	attr_blk_data %010, 3,3,0, 00,06, 19,07
+	attr_blk_data %011, 0,0,0, 04,04, 15,09
+	attr_blk_data %011, 0,0,0, 00,12, 19,17
 
 BlkPacket_9b26:
-	db $23, $07, $07, $10, $00, $00, $02, $0c, $02, $00, $0c, $00, $12, $01, $02, $00
-	db $0c, $02, $12, $03, $02, $00, $0c, $04, $12, $05, $02, $00, $0c, $06, $12, $07
-	db $02, $00, $0c, $08, $12, $09, $02, $00, $0c, $0a, $12, $0b, $00, $00, $00, $00
+	attr_blk 7
+	attr_blk_data %111, 0,0,1, 00,00, 02,12
+	attr_blk_data %010, 0,0,0, 12,00, 18,01
+	attr_blk_data %010, 0,0,0, 12,02, 18,03
+	attr_blk_data %010, 0,0,0, 12,04, 18,05
+	attr_blk_data %010, 0,0,0, 12,06, 18,07
+	attr_blk_data %010, 0,0,0, 12,08, 18,09
+	attr_blk_data %010, 0,0,0, 12,10, 18,11
+	ds 4
 
 BlkPacket_9b56:
-	db $22, $03, $07, $20, $00, $00, $13, $04, $03, $0f, $00, $06, $13, $11, $03, $05
-	db $0f, $01, $12, $04, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00
+	attr_blk 3
+	attr_blk_data %111, 0,0,2, 00,00, 19,04
+	attr_blk_data %011, 3,3,0, 00,06, 19,17
+	attr_blk_data %011, 1,1,0, 15,01, 18,04
+	ds 12
 
 BlkPacket_9b76:
-	db $21, $01, $07, $10, $00, $00, $13, $05, $00, $00, $00, $00, $00, $00, $00, $00
+	attr_blk 1
+	attr_blk_data %111, 0,0,1, 00,00, 19,05
+	ds 8
 
 BlkPacket_9b86:
-	db $21, $02, $07, $0a, $00, $04, $13, $0d, $03, $05, $00, $06, $13, $0b, $00, $00
+	attr_blk 2
+	attr_blk_data %111, 2,2,0, 00,04, 19,13
+	attr_blk_data %011, 1,1,0, 00,06, 19,11
+	ds 2
--- /dev/null
+++ b/gfx/sgb/data_snd_packets.asm
@@ -1,0 +1,104 @@
+; macros taken from pokered's data/sgb_packets.asm
+; names taken from pandocs
+; http://gbdev.gg8.se/wiki/articles/SGB_Functions#SGB_Palette_Commands
+
+sgb_mask_en: MACRO
+	db ($17 << 3) + 1
+	db \1
+	ds 14
+ENDM
+
+sgb_data_snd: MACRO
+	db ($0f << 3) + 1
+	dw \1 ; address
+	db \2 ; bank
+	db \3 ; length (1-11)
+ENDM
+
+
+MaskEnFreezePacket: sgb_mask_en 1
+MaskEnCancelPacket: sgb_mask_en 0
+
+; These are packets containing SNES code.
+; This set of packets is found in several Japanese SGB-compatible titles.
+; It appears to be part of NCL's SGB devkit.
+
+DataSndPacket1:
+	sgb_data_snd $085d, $0, 11
+	db  $8c                 ; cpx #$8c (2)
+	db  $d0, $f4            ; bne -$0c
+	db  $60                 ; rts
+	ds  7
+
+DataSndPacket2:
+	sgb_data_snd $0852, $0, 11
+	db  $a9, $e7            ; lda #$e7
+	db  $9f, $01, $c0, $7e  ; sta $7ec001, x
+	db  $e8                 ; inx
+	db  $e8                 ; inx
+	db  $e8                 ; inx
+	db  $e8                 ; inx
+	db  $e0                 ; cpx #$8c (1)
+        
+DataSndPacket3:
+	sgb_data_snd $0847, $0, 11
+	db  $c4                 ; cmp #$c4 (2)
+	db  $d0, $16            ; bne +$16
+	db  $a5                 ; lda dp
+	db  $cb                 ; wai
+	db  $c9, $05            ; cmp #$05
+	db  $d0, $10            ; bne +$10
+	db  $a2, $28            ; ldx #$28
+        
+DataSndPacket4:
+	sgb_data_snd $083c, $0, 11
+	db  $f0, $12            ; beq +$12
+	db  $a5                 ; lda dp
+	db  $c9, $c9            ; cmp #$c9
+	db  $c8                 ; iny
+	db  $d0, $1c            ; bne +$1c
+	db  $a5                 ; lda dp
+	db  $ca                 ; dex
+	db  $c9                 ; cmp #$c4 (1)
+
+DataSndPacket5:
+	sgb_data_snd $0831, $0, 11
+	dbw $0c, $caa5          ; tsb $caa5
+	db  $c9, $7e            ; cmp #$7e
+	db  $d0, $06            ; bne +$06
+	db  $a5                 ; lda dp
+	db  $cb                 ; wai
+	db  $c9, $7e            ; cmp #$7e
+
+DataSndPacket6:
+	sgb_data_snd $0826, $0, 11
+	db  $39                 ; bne +$39 (2)
+	dbw $cd, $0c48          ; cmp $0c48
+	db  $d0, $34            ; bne +$34
+	db  $a5                 ; lda dp
+	db  $c9, $c9            ; cmp #$c9
+	db  $80, $d0            ; bra -$30
+
+DataSndPacket7:
+	sgb_data_snd $081b, $0, 11
+	db  $ea                 ; nop
+	db  $ea                 ; nop
+	db  $ea                 ; nop
+	db  $ea                 ; nop
+	db  $ea                 ; nop
+	                        ; $0820:
+	db  $a9, $01            ; lda #01
+	dbw $cd, $0c4f          ; cmp $c4f
+	db  $d0                 ; bne +$39 (1)
+
+DataSndPacket8:
+	sgb_data_snd $0810, $0, 11
+	dbw $4c, $0820          ; jmp $0820
+	db  $ea                 ; nop
+	db  $ea                 ; nop
+	db  $ea                 ; nop
+	db  $ea                 ; nop
+	db  $ea                 ; nop
+	db  $60                 ; rts
+	db  $ea                 ; nop
+	db  $ea                 ; nop
--- a/gfx/sgb/pal_packets.asm
+++ b/gfx/sgb/pal_packets.asm
@@ -1,115 +1,84 @@
-; indexes correspond to PredefPals palettes (see gfx/sgb/predef.pal)
+; macros taken from pokered's data/sgb_packets.asm
+; names taken from pandocs
+; http://gbdev.gg8.se/wiki/articles/SGB_Functions#SGB_Palette_Commands
 
-PalPacket_9b96:
-	db $51, $48, $00, $49, $00, $4a, $00, $4b, $00, $00, $00, $00, $00, $00, $00, $00
+sgb_pal_set: MACRO
+	db (SGB_PAL_SET << 3) + 1
+	dw PREDEFPAL_\1, PREDEFPAL_\2, PREDEFPAL_\3, PREDEFPAL_\4
+	ds 7
+ENDM
 
-PalPacket_9ba6:
-	db $51, $2b, $00, $24, $00, $20, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00
+sgb_pal01: MACRO
+	db (SGB_PAL01 << 3) + 1
+ENDM
 
-PalPacket_9bb6:
-	db $51, $41, $00, $42, $00, $43, $00, $44, $00, $00, $00, $00, $00, $00, $00, $00
+sgb_pal23: MACRO
+	db (SGB_PAL23 << 3) + 1
+ENDM
 
-PalPacket_9bc6:
-	db $51, $4c, $00, $4c, $00, $4c, $00, $4c, $00, $00, $00, $00, $00, $00, $00, $00
+sgb_pal_trn: MACRO
+	db (SGB_PAL_TRN << 3) + 1
+	ds 15
+ENDM
 
-PalPacket_9bd6:
-	db $51, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00
+sgb_mlt_req: MACRO
+	db (SGB_MLT_REG << 3) + 1
+	db \1 - 1
+	ds 14
+ENDM
 
-PalPacket_9be6:
-	db $51, $36, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00
+sgb_chr_trn: MACRO
+	db (SGB_CHR_TRN << 3) + 1
+	db \1 + (\2 << 1)
+	ds 14
+ENDM
 
-PalPacket_9bf6:
-	db $51, $37, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00
+sgb_pct_trn: MACRO
+	db (SGB_PCT_TRN << 3) + 1
+	ds 15
+ENDM
 
-PalPacket_9c06:
-	db $51, $38, $00, $39, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00
 
-PalPacket_9c16:
-	db $51, $3a, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00
+PalPacket_9b96: sgb_pal_set 48, 49, 4A, 4B
+PalPacket_9ba6: sgb_pal_set 2B, 24, 20, 00
+PalPacket_9bb6: sgb_pal_set 41, 42, 43, 44
+PalPacket_9bc6: sgb_pal_set 4C, 4C, 4C, 4C
+PalPacket_9bd6: sgb_pal_set 00, 00, 00, 00
+PalPacket_9be6: sgb_pal_set 36, 00, 00, 00
+PalPacket_9bf6: sgb_pal_set 37, 00, 00, 00
+PalPacket_9c06: sgb_pal_set 38, 39, 00, 00
+PalPacket_9c16: sgb_pal_set 3A, 00, 00, 00
+PalPacket_9c26: sgb_pal_set 3B, 00, 00, 00
+PalPacket_9c36: sgb_pal_set 3C, 00, 00, 00
+PalPacket_9c46: sgb_pal_set 39, 00, 00, 00
+PalPacket_9c56: sgb_pal_set 2E, 2F, 30, 31
+PalPacket_9c66: sgb_pal_set 1A, 1A, 1A, 1A
+PalPacket_9c76: sgb_pal_set 32, 00, 00, 00
+PalPacket_9c86: sgb_pal_set 3C, 00, 00, 00
+PalPacket_9c96: sgb_pal_set 3D, 3E, 3F, 40
+PalPacket_9ca6: sgb_pal_set 33, 34, 1B, 1F
+PalPacket_9cb6: sgb_pal_set 1B, 00, 00, 00
+PalPacket_9cc6: sgb_pal_set 1C, 00, 00, 00
+PalPacket_9cd6: sgb_pal_set 35, 00, 00, 00
 
-PalPacket_9c26:
-	db $51, $3b, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00
-
-PalPacket_9c36:
-	db $51, $3c, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00
-
-PalPacket_9c46:
-	db $51, $39, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00
-
-PalPacket_9c56:
-	db $51, $2e, $00, $2f, $00, $30, $00, $31, $00, $00, $00, $00, $00, $00, $00, $00
-
-PalPacket_9c66:
-	db $51, $1a, $00, $1a, $00, $1a, $00, $1a, $00, $00, $00, $00, $00, $00, $00, $00
-
-PalPacket_9c76:
-	db $51, $32, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00
-
-PalPacket_9c86:
-	db $51, $3c, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00
-
-PalPacket_9c96:
-	db $51, $3d, $00, $3e, $00, $3f, $00, $40, $00, $00, $00, $00, $00, $00, $00, $00
-
-PalPacket_9ca6:
-	db $51, $33, $00, $34, $00, $1b, $00, $1f, $00, $00, $00, $00, $00, $00, $00, $00
-
-PalPacket_9cb6:
-	db $51, $1b, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00
-
-PalPacket_9cc6:
-	db $51, $1c, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00
-
-PalPacket_9cd6:
-	db $51, $35, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00
-
 PalPacket_9ce6:
-	db $01, $ff, $7f, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00
+	sgb_pal01
+	RGB 31, 31, 31
+rept 6
+	RGB 00, 00, 00
+endr
+	ds 1
 
 PalPacket_9cf6:
-	db $09, $ff, $7f, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00
+	sgb_pal23
+	RGB 31, 31, 31
+rept 6
+	RGB 00, 00, 00
+endr
+	ds 1
 
-PalPacket_9d06:
-	db $59, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00
-
-PalPacket_9d16:
-	db $89, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00
-
-PalPacket_9d26:
-	db $89, $01, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00
-
-PalPacket_9d36:
-	db $99, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00
-
-PalPacket_9d46:
-	db $a1, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00
-
-PalPacket_9d56:
-	db $b9, $01, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00
-
-PalPacket_9d66:
-	db $b9, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00, $00
-
-PalPacket_9d76:
-	db $79, $5d, $08, $00, $0b, $8c, $d0, $f4, $60, $00, $00, $00, $00, $00, $00, $00
-
-PalPacket_9d86:
-	db $79, $52, $08, $00, $0b, $a9, $e7, $9f, $01, $c0, $7e, $e8, $e8, $e8, $e8, $e0
-
-PalPacket_9d96:
-	db $79, $47, $08, $00, $0b, $c4, $d0, $16, $a5, $cb, $c9, $05, $d0, $10, $a2, $28
-
-PalPacket_9da6:
-	db $79, $3c, $08, $00, $0b, $f0, $12, $a5, $c9, $c9, $c8, $d0, $1c, $a5, $ca, $c9
-
-PalPacket_9db6:
-	db $79, $31, $08, $00, $0b, $0c, $a5, $ca, $c9, $7e, $d0, $06, $a5, $cb, $c9, $7e
-
-PalPacket_9dc6:
-	db $79, $26, $08, $00, $0b, $39, $cd, $48, $0c, $d0, $34, $a5, $c9, $c9, $80, $d0
-
-PalPacket_9dd6:
-	db $79, $1b, $08, $00, $0b, $ea, $ea, $ea, $ea, $ea, $a9, $01, $cd, $4f, $0c, $d0
-
-PalPacket_9de6:
-	db $79, $10, $08, $00, $0b, $4c, $20, $08, $ea, $ea, $ea, $ea, $ea, $60, $ea, $ea
+PalTrnPacket:  sgb_pal_trn
+MltReq1Packet: sgb_mlt_req 1
+MltReq2Packet: sgb_mlt_req 2
+ChrTrnPacket:  sgb_chr_trn 0, 0
+PctTrnPacket:  sgb_pct_trn
--- a/gfx/sgb/roof_pal_inds.asm
+++ b/gfx/sgb/roof_pal_inds.asm
@@ -2,31 +2,31 @@
 
 MapGroupRoofSGBPalInds: ; 8a45
 ; entries correspond to map groups
-	db $00 ; group 0 (unused)
-	db $12 ; group 1 (Olivine)
-	db $14 ; group 2 (Mahogany)
-	db $18 ; group 3 (dungeons)
-	db $11 ; group 4 (Ecruteak)
-	db $15 ; group 5 (Blackthorn)
-	db $09 ; group 6 (Cinnabar)
-	db $04 ; group 7 (Cerulean)
-	db $0f ; group 8 (Azalea)
-	db $16 ; group 9 (Lake of Rage)
-	db $0e ; group 10 (Violet)
-	db $10 ; group 11 (Goldenrod)
-	db $06 ; group 12 (Vermilion)
-	db $01 ; group 13 (Pallet)
-	db $03 ; group 14 (Pewter)
-	db $06 ; group 15 (Mount Moon Square)
-	db $0b ; group 16 (Indigo)
-	db $08 ; group 17 (Fuchsia)
-	db $05 ; group 18 (Lavender)
-	db $17 ; group 19 (Silver Cave)
-	db $08 ; group 20 (Cable Club)
-	db $07 ; group 21 (Celadon)
-	db $13 ; group 22 (Cianwood)
-	db $02 ; group 23 (Viridian)
-	db $0c ; group 24 (New Bark)
-	db $0a ; group 25 (Saffron)
-	db $0d ; group 26 (Cherrygrove)
+	db PREDEFPAL_00 ; group 0 (unused)
+	db PREDEFPAL_12 ; group 1 (Olivine)
+	db PREDEFPAL_14 ; group 2 (Mahogany)
+	db PREDEFPAL_18 ; group 3 (dungeons)
+	db PREDEFPAL_11 ; group 4 (Ecruteak)
+	db PREDEFPAL_15 ; group 5 (Blackthorn)
+	db PREDEFPAL_09 ; group 6 (Cinnabar)
+	db PREDEFPAL_04 ; group 7 (Cerulean)
+	db PREDEFPAL_0F ; group 8 (Azalea)
+	db PREDEFPAL_16 ; group 9 (Lake of Rage)
+	db PREDEFPAL_0E ; group 10 (Violet)
+	db PREDEFPAL_10 ; group 11 (Goldenrod)
+	db PREDEFPAL_06 ; group 12 (Vermilion)
+	db PREDEFPAL_01 ; group 13 (Pallet)
+	db PREDEFPAL_03 ; group 14 (Pewter)
+	db PREDEFPAL_06 ; group 15 (Mount Moon Square)
+	db PREDEFPAL_0B ; group 16 (Indigo)
+	db PREDEFPAL_08 ; group 17 (Fuchsia)
+	db PREDEFPAL_05 ; group 18 (Lavender)
+	db PREDEFPAL_17 ; group 19 (Silver Cave)
+	db PREDEFPAL_08 ; group 20 (Cable Club)
+	db PREDEFPAL_07 ; group 21 (Celadon)
+	db PREDEFPAL_13 ; group 22 (Cianwood)
+	db PREDEFPAL_02 ; group 23 (Viridian)
+	db PREDEFPAL_0C ; group 24 (New Bark)
+	db PREDEFPAL_0A ; group 25 (Saffron)
+	db PREDEFPAL_0D ; group 26 (Cherrygrove)
 ; 8a60