aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordannye <33dannye@gmail.com>2023-04-25 19:52:12 -0500
committerdannye <33dannye@gmail.com>2023-04-25 19:52:12 -0500
commit667f1febbe59355b1ffea68619e5e5486fd3c408 (patch)
tree9a3ca97fea7cb54d1db9c23ac8c2a405a13f6f5c
parentFix trainer parties' comments (#104) (diff)
parentUpdate `EndBug` to v9. (diff)
downloadpokeyellow-667f1febbe59355b1ffea68619e5e5486fd3c408.tar.gz
pokeyellow-667f1febbe59355b1ffea68619e5e5486fd3c408.tar.xz
pokeyellow-667f1febbe59355b1ffea68619e5e5486fd3c408.zip
Merge branch 'master' of https://github.com/pret/pokered
-rw-r--r--.github/workflows/main.yml3
-rw-r--r--Makefile17
-rw-r--r--constants/move_constants.asm14
-rw-r--r--data/moves/animations.asm4
-rw-r--r--data/pokemon/dex_entries.asm2
-rw-r--r--data/trainers/name_pointers.asm2
-rw-r--r--data/trainers/names.asm96
-rw-r--r--data/trainers/parties.asm2
-rw-r--r--engine/battle/core.asm4
-rw-r--r--engine/battle/effects.asm22
-rw-r--r--engine/battle/trainer_ai.asm2
-rw-r--r--engine/debug/debug_menu.asm10
-rw-r--r--engine/menus/main_menu.asm1
-rw-r--r--engine/movie/oak_speech/oak_speech.asm10
-rw-r--r--engine/movie/title.asm23
-rw-r--r--home/init.asm2
-rw-r--r--tools/common.h2
-rw-r--r--tools/make_patch.c2
-rw-r--r--tools/pkmncompress.c20
19 files changed, 128 insertions, 110 deletions
diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml
index 9b3efa30..44317b8b 100644
--- a/.github/workflows/main.yml
+++ b/.github/workflows/main.yml
@@ -69,9 +69,8 @@ jobs:
- name: Update symbols
if: ${{ github.event_name == 'push' && github.repository_owner == 'pret' }}
- uses: EndBug/add-and-commit@v7
+ uses: EndBug/add-and-commit@v9
with:
- branch: symbols
cwd: "./symbols"
add: "*.sym"
message: ${{ github.event.commits[0].message }}
diff --git a/Makefile b/Makefile
index 78d44bb6..5eb584b1 100644
--- a/Makefile
+++ b/Makefile
@@ -96,27 +96,28 @@ $(pokeyellow_vc_obj): RGBASMFLAGS += -D _YELLOW_VC
rgbdscheck.o: rgbdscheck.asm
$(RGBASM) -o $@ $<
+# Build tools when building the rom.
+# This has to happen before the rules are processed, since that's when scan_includes is run.
+ifeq (,$(filter clean tidy tools,$(MAKECMDGOALS)))
+
+$(info $(shell $(MAKE) -C tools))
+
# The dep rules have to be explicit or else missing files won't be reported.
# As a side effect, they're evaluated immediately instead of when the rule is invoked.
# It doesn't look like $(shell) can be deferred so there might not be a better way.
+preinclude_deps := includes.asm $(shell tools/scan_includes includes.asm)
define DEP
-$1: $2 $$(shell tools/scan_includes $2) | includes.asm rgbdscheck.o
+$1: $2 $$(shell tools/scan_includes $2) $(preinclude_deps) | rgbdscheck.o
$$(RGBASM) $$(RGBASMFLAGS) -o $$@ $$<
endef
-# Build tools when building the rom.
-# This has to happen before the rules are processed, since that's when scan_includes is run.
-ifeq (,$(filter clean tidy tools,$(MAKECMDGOALS)))
-
-$(info $(shell $(MAKE) -C tools))
-
# Dependencies for objects
$(foreach obj, $(pokeyellow_obj), $(eval $(call DEP,$(obj),$(obj:.o=.asm))))
$(foreach obj, $(pokeyellow_debug_obj), $(eval $(call DEP,$(obj),$(obj:_debug.o=.asm))))
$(foreach obj, $(pokeyellow_vc_obj), $(eval $(call DEP,$(obj),$(obj:_vc.o=.asm))))
# Dependencies for VC files that need to run scan_includes
-%.constants.sym: %.constants.asm $(shell tools/scan_includes %.constants.asm) | includes.asm rgbdscheck.o
+%.constants.sym: %.constants.asm $(shell tools/scan_includes %.constants.asm) $(preinclude_deps) | rgbdscheck.o
$(RGBASM) $(RGBASMFLAGS) $< > $@
endif
diff --git a/constants/move_constants.asm b/constants/move_constants.asm
index 570be95e..3376c1af 100644
--- a/constants/move_constants.asm
+++ b/constants/move_constants.asm
@@ -178,14 +178,14 @@ DEF NUM_ATTACKS EQU const_value - 1
const SHOWPIC_ANIM
const STATUS_AFFECTED_ANIM
const ANIM_A8
- const ANIM_A9
+ const ENEMY_HUD_SHAKE_ANIM
const TRADE_BALL_DROP_ANIM
const TRADE_BALL_SHAKE_ANIM
const TRADE_BALL_TILT_ANIM
const TRADE_BALL_POOF_ANIM
const XSTATITEM_ANIM ; use X Attack/Defense/Speed/Special
- const ANIM_AF
- const ANIM_B0
+ const XSTATITEM_DUPLICATE_ANIM
+ const SHRINKING_SQUARE_ANIM
const ANIM_B1
const ANIM_B2
const ANIM_B3
@@ -197,18 +197,18 @@ DEF NUM_ATTACKS EQU const_value - 1
const ANIM_B9
const BURN_PSN_ANIM ; Plays when a monster is burned or poisoned
const ANIM_BB
- const ANIM_BC
+ const SLP_PLAYER_ANIM
const SLP_ANIM ; sleeping monster
- const ANIM_BE
+ const CONF_PLAYER_ANIM
const CONF_ANIM ; confused monster
- const ANIM_C0
+ const SLIDE_DOWN_ANIM
const TOSS_ANIM ; toss Poké Ball
const SHAKE_ANIM ; shaking Poké Ball when catching monster
const POOF_ANIM ; puff of smoke
const BLOCKBALL_ANIM ; trainer knocks away Poké Ball
const GREATTOSS_ANIM ; toss Great Ball
const ULTRATOSS_ANIM ; toss Ultra Ball or Master Ball
- const ANIM_C7
+ const SHAKE_SCREEN_ANIM
const HIDEPIC_ANIM ; monster disappears
const ROCK_ANIM ; throw rock
const BAIT_ANIM ; throw bait
diff --git a/data/moves/animations.asm b/data/moves/animations.asm
index fd7ad88b..a7e1f0be 100644
--- a/data/moves/animations.asm
+++ b/data/moves/animations.asm
@@ -192,7 +192,7 @@ AttackAnimationPointers:
dw SleepEnemyAnim
dw ConfusedPlayerAnim
dw ConfusedEnemyAnim
- dw FaintAnim
+ dw SlideDownAnim
dw BallTossAnim
dw BallShakeAnim
dw BallPoofAnim
@@ -1258,7 +1258,7 @@ BallBlockAnim:
battle_anim NO_MOVE, SUBANIM_0_BALL_BLOCK, 0, 3
db -1 ; end
-FaintAnim:
+SlideDownAnim:
battle_anim DIG, SE_SLIDE_MON_DOWN
db -1 ; end
diff --git a/data/pokemon/dex_entries.asm b/data/pokemon/dex_entries.asm
index ae243768..0f8b6d96 100644
--- a/data/pokemon/dex_entries.asm
+++ b/data/pokemon/dex_entries.asm
@@ -194,7 +194,7 @@ PokedexEntryPointers:
; string: species name
; height in feet, inches
-; weight in pounds
+; weight in tenths of a pound
; text entry
BulbasaurDexEntry:
diff --git a/data/trainers/name_pointers.asm b/data/trainers/name_pointers.asm
index 6317f54a..914fe9d4 100644
--- a/data/trainers/name_pointers.asm
+++ b/data/trainers/name_pointers.asm
@@ -2,6 +2,7 @@ TrainerNamePointers:
; These are only used for trainers' defeat speeches.
; They were originally shortened variants of the trainer class names
; in the Japanese versions, but are now redundant with TrainerNames.
+ table_width 2, TrainerNamePointers
dw .YoungsterName
dw .BugCatcherName
dw .LassName
@@ -49,6 +50,7 @@ TrainerNamePointers:
dw wTrainerName
dw wTrainerName
dw wTrainerName
+ assert_table_length NUM_TRAINERS
.YoungsterName: db "YOUNGSTER@"
.BugCatcherName: db "BUG CATCHER@"
diff --git a/data/trainers/names.asm b/data/trainers/names.asm
index d8e1f550..dc6ded77 100644
--- a/data/trainers/names.asm
+++ b/data/trainers/names.asm
@@ -1,48 +1,50 @@
TrainerNames::
- db "YOUNGSTER@"
- db "BUG CATCHER@"
- db "LASS@"
- db "SAILOR@"
- db "JR.TRAINER♂@"
- db "JR.TRAINER♀@"
- db "POKéMANIAC@"
- db "SUPER NERD@"
- db "HIKER@"
- db "BIKER@"
- db "BURGLAR@"
- db "ENGINEER@"
- db "JUGGLER@"
- db "FISHERMAN@"
- db "SWIMMER@"
- db "CUE BALL@"
- db "GAMBLER@"
- db "BEAUTY@"
- db "PSYCHIC@"
- db "ROCKER@"
- db "JUGGLER@"
- db "TAMER@"
- db "BIRD KEEPER@"
- db "BLACKBELT@"
- db "RIVAL1@"
- db "PROF.OAK@"
- db "CHIEF@"
- db "SCIENTIST@"
- db "GIOVANNI@"
- db "ROCKET@"
- db "COOLTRAINER♂@"
- db "COOLTRAINER♀@"
- db "BRUNO@"
- db "BROCK@"
- db "MISTY@"
- db "LT.SURGE@"
- db "ERIKA@"
- db "KOGA@"
- db "BLAINE@"
- db "SABRINA@"
- db "GENTLEMAN@"
- db "RIVAL2@"
- db "RIVAL3@"
- db "LORELEI@"
- db "CHANNELER@"
- db "AGATHA@"
- db "LANCE@"
+ list_start TrainerNames
+ li "YOUNGSTER"
+ li "BUG CATCHER"
+ li "LASS"
+ li "SAILOR"
+ li "JR.TRAINER♂"
+ li "JR.TRAINER♀"
+ li "POKéMANIAC"
+ li "SUPER NERD"
+ li "HIKER"
+ li "BIKER"
+ li "BURGLAR"
+ li "ENGINEER"
+ li "JUGGLER"
+ li "FISHERMAN"
+ li "SWIMMER"
+ li "CUE BALL"
+ li "GAMBLER"
+ li "BEAUTY"
+ li "PSYCHIC"
+ li "ROCKER"
+ li "JUGGLER"
+ li "TAMER"
+ li "BIRD KEEPER"
+ li "BLACKBELT"
+ li "RIVAL1"
+ li "PROF.OAK"
+ li "CHIEF"
+ li "SCIENTIST"
+ li "GIOVANNI"
+ li "ROCKET"
+ li "COOLTRAINER♂"
+ li "COOLTRAINER♀"
+ li "BRUNO"
+ li "BROCK"
+ li "MISTY"
+ li "LT.SURGE"
+ li "ERIKA"
+ li "KOGA"
+ li "BLAINE"
+ li "SABRINA"
+ li "GENTLEMAN"
+ li "RIVAL2"
+ li "RIVAL3"
+ li "LORELEI"
+ li "CHANNELER"
+ li "AGATHA"
+ li "LANCE"
+ assert_list_length NUM_TRAINERS
diff --git a/data/trainers/parties.asm b/data/trainers/parties.asm
index b8c795ef..e4ff648a 100644
--- a/data/trainers/parties.asm
+++ b/data/trainers/parties.asm
@@ -1,4 +1,5 @@
TrainerDataPointers:
+ table_width 2, TrainerDataPointers
dw YoungsterData
dw BugCatcherData
dw LassData
@@ -46,6 +47,7 @@ TrainerDataPointers:
dw ChannelerData
dw AgathaData
dw LanceData
+ assert_table_length NUM_TRAINERS
; if first byte != $FF, then
; first byte is level (of all pokemon on this team)
diff --git a/engine/battle/core.asm b/engine/battle/core.asm
index 8618cced..addff324 100644
--- a/engine/battle/core.asm
+++ b/engine/battle/core.asm
@@ -3496,7 +3496,7 @@ CheckPlayerStatusConditions:
; fast asleep
xor a
ld [wAnimationType], a
- ld a, SLP_ANIM - 1
+ ld a, SLP_PLAYER_ANIM
call PlayMoveAnimation
ld hl, FastAsleepText
call PrintText
@@ -3580,7 +3580,7 @@ CheckPlayerStatusConditions:
call PrintText
xor a
ld [wAnimationType], a
- ld a, CONF_ANIM - 1
+ ld a, CONF_PLAYER_ANIM
call PlayMoveAnimation
call BattleRandom
cp 50 percent + 1 ; chance to hurt itself
diff --git a/engine/battle/effects.asm b/engine/battle/effects.asm
index f2e2590c..f13d679c 100644
--- a/engine/battle/effects.asm
+++ b/engine/battle/effects.asm
@@ -133,12 +133,12 @@ PoisonEffect:
dec de
ldh a, [hWhoseTurn]
and a
- ld b, ANIM_C7
+ ld b, SHAKE_SCREEN_ANIM
ld hl, wPlayerBattleStatus3
ld a, [de]
ld de, wPlayerToxicCounter
jr nz, .ok
- ld b, ANIM_A9
+ ld b, ENEMY_HUD_SHAKE_ANIM
ld hl, wEnemyBattleStatus3
ld de, wEnemyToxicCounter
.ok
@@ -252,14 +252,14 @@ FreezeBurnParalyzeEffect:
ld a, 1 << PAR
ld [wEnemyMonStatus], a
call QuarterSpeedDueToParalysis ; quarter speed of affected mon
- ld a, ANIM_A9
+ ld a, ENEMY_HUD_SHAKE_ANIM
call PlayBattleAnimation
jp PrintMayNotAttackText ; print paralysis text
.burn1
ld a, 1 << BRN
ld [wEnemyMonStatus], a
call HalveAttackDueToBurn ; halve attack of affected mon
- ld a, ANIM_A9
+ ld a, ENEMY_HUD_SHAKE_ANIM
call PlayBattleAnimation
ld hl, BurnedText
jp PrintText
@@ -267,7 +267,7 @@ FreezeBurnParalyzeEffect:
call ClearHyperBeam ; resets hyper beam (recharge) condition from target
ld a, 1 << FRZ
ld [wEnemyMonStatus], a
- ld a, ANIM_A9
+ ld a, ENEMY_HUD_SHAKE_ANIM
call PlayBattleAnimation
ld hl, FrozenText
jp PrintText
@@ -315,14 +315,14 @@ FreezeBurnParalyzeEffect:
ld a, 1 << PAR
ld [wBattleMonStatus], a
call QuarterSpeedDueToParalysis
- ld a, ANIM_C7
+ ld a, SHAKE_SCREEN_ANIM
call PlayBattleAnimation2
jp PrintMayNotAttackText
.burn2
ld a, 1 << BRN
ld [wBattleMonStatus], a
call HalveAttackDueToBurn
- ld a, ANIM_C7
+ ld a, SHAKE_SCREEN_ANIM
call PlayBattleAnimation2
ld hl, BurnedText
jp PrintText
@@ -330,7 +330,7 @@ FreezeBurnParalyzeEffect:
; hyper beam bits aren't reseted for opponent's side
ld a, 1 << FRZ
ld [wBattleMonStatus], a
- ld a, ANIM_C7
+ ld a, SHAKE_SCREEN_ANIM
call PlayBattleAnimation2
ld hl, FrozenText
jp PrintText
@@ -838,7 +838,7 @@ ThrashPetalDanceEffect:
inc a
ld [de], a ; set thrash/petal dance counter to 2 or 3 at random
ldh a, [hWhoseTurn]
- add ANIM_B0
+ add SHRINKING_SQUARE_ANIM
jp PlayBattleAnimation2
SwitchAndTeleportEffect:
@@ -1041,7 +1041,7 @@ ChargeEffect:
jr z, .chargeEffect
ld hl, wEnemyBattleStatus1
ld de, wEnemyMoveEffect
- ld b, ANIM_AF
+ ld b, XSTATITEM_DUPLICATE_ANIM
.chargeEffect
set CHARGING_UP, [hl]
ld a, [de]
@@ -1055,7 +1055,7 @@ ChargeEffect:
cp DIG
jr nz, .notDigOrFly
set INVULNERABLE, [hl] ; mon is now invulnerable to typical attacks (fly/dig)
- ld b, ANIM_C0
+ ld b, SLIDE_DOWN_ANIM
.notDigOrFly
push de
push bc
diff --git a/engine/battle/trainer_ai.asm b/engine/battle/trainer_ai.asm
index 4048e808..41325ce7 100644
--- a/engine/battle/trainer_ai.asm
+++ b/engine/battle/trainer_ai.asm
@@ -722,7 +722,7 @@ AIIncreaseStat:
ld a, [hl]
push af
push hl
- ld a, ANIM_AF
+ ld a, XSTATITEM_DUPLICATE_ANIM
ld [hli], a
ld [hl], b
callfar StatModifierUpEffect
diff --git a/engine/debug/debug_menu.asm b/engine/debug/debug_menu.asm
index 83917823..d888743e 100644
--- a/engine/debug/debug_menu.asm
+++ b/engine/debug/debug_menu.asm
@@ -2,12 +2,14 @@ DebugMenu:
IF DEF(_DEBUG)
call ClearScreen
- ld hl, DebugPlayerName
+ ; These debug names are used for TestBattle.
+ ; StartNewGameDebug uses the debug names from PrepareOakSpeech.
+ ld hl, DebugBattlePlayerName
ld de, wPlayerName
ld bc, NAME_LENGTH
call CopyData
- ld hl, DebugRivalName
+ ld hl, DebugBattleRivalName
ld de, wRivalName
ld bc, NAME_LENGTH
call CopyData
@@ -58,10 +60,10 @@ IF DEF(_DEBUG)
ld hl, StartNewGameDebug
ret
-DebugPlayerName:
+DebugBattlePlayerName:
db "Tom@"
-DebugRivalName:
+DebugBattleRivalName:
db "Juerry@"
DebugMenuOptions:
diff --git a/engine/menus/main_menu.asm b/engine/menus/main_menu.asm
index cfcfcb74..ce0b12c5 100644
--- a/engine/menus/main_menu.asm
+++ b/engine/menus/main_menu.asm
@@ -147,6 +147,7 @@ NotEnoughMemoryText:
StartNewGame:
ld hl, wd732
res 1, [hl]
+ ; fallthrough
StartNewGameDebug:
call OakSpeech
ld a, $8
diff --git a/engine/movie/oak_speech/oak_speech.asm b/engine/movie/oak_speech/oak_speech.asm
index 2ed61fda..3c6b8b45 100644
--- a/engine/movie/oak_speech/oak_speech.asm
+++ b/engine/movie/oak_speech/oak_speech.asm
@@ -1,4 +1,4 @@
-SetDefaultNames:
+PrepareOakSpeech:
ld a, [wLetterPrintingDelayFlags]
push af
ld a, [wOptions]
@@ -30,11 +30,13 @@ SetDefaultNames:
ld a, [wOptionsInitialized]
and a
call z, InitOptions
- ld hl, NintenText
+ ; These debug names are used for StartNewGameDebug.
+ ; TestBattle uses the debug names from DebugMenu.
+ ld hl, DebugNewGamePlayerName
ld de, wPlayerName
ld bc, NAME_LENGTH
call CopyData
- ld hl, SonyText
+ ld hl, DebugNewGameRivalName
ld de, wRivalName
ld bc, NAME_LENGTH
call CopyData ; rip optimizations
@@ -48,7 +50,7 @@ OakSpeech:
call PlayMusic
call ClearScreen
call LoadTextBoxTilePatterns
- call SetDefaultNames
+ call PrepareOakSpeech
predef InitPlayerData2
ld hl, wNumBoxItems
ld a, POTION
diff --git a/engine/movie/title.asm b/engine/movie/title.asm
index c84b1f23..3d054138 100644
--- a/engine/movie/title.asm
+++ b/engine/movie/title.asm
@@ -1,10 +1,13 @@
-SetDefaultNamesBeforeTitlescreen::
- ld hl, NintenText
+PrepareTitleScreen::
+ ; These debug names are already copied later in PrepareOakSpeech.
+ ; Removing the unused copies below has no apparent impact.
+ ; CopyDebugName can also be safely deleted afterwards.
+ ld hl, DebugNewGamePlayerName
ld de, wPlayerName
- call CopyFixedLengthText
- ld hl, SonyText
+ call CopyDebugName
+ ld hl, DebugNewGameRivalName
ld de, wRivalName
- call CopyFixedLengthText
+ call CopyDebugName
xor a
ldh [hWY], a
ld [wLetterPrintingDelayFlags], a
@@ -344,13 +347,15 @@ DoTitleScreenFunction:
ld [wTitleScreenScene], a
ret
-; copy text of fixed length NAME_LENGTH (like player name, rival name, mon names, ...)
-CopyFixedLengthText:
+CopyDebugName:
ld bc, NAME_LENGTH
jp CopyData
-NintenText: db "NINTEN@"
-SonyText: db "SONY@"
+DebugNewGamePlayerName:
+ db "NINTEN@"
+
+DebugNewGameRivalName:
+ db "SONY@"
IncrementResetCounter:
ld hl, wTitleScreenScene + 2
diff --git a/home/init.asm b/home/init.asm
index 989a86d5..58264dcf 100644
--- a/home/init.asm
+++ b/home/init.asm
@@ -118,7 +118,7 @@ DEF rLCDC_DEFAULT EQU %11100011
ld a, rLCDC_DEFAULT
ldh [rLCDC], a
- jp SetDefaultNamesBeforeTitlescreen
+ jp PrepareTitleScreen
ClearVram::
ld hl, VRAM_Begin
diff --git a/tools/common.h b/tools/common.h
index f04e917b..2c690423 100644
--- a/tools/common.h
+++ b/tools/common.h
@@ -19,6 +19,8 @@
#error Define USAGE_OPTS before including common.h!
#endif
+#define COUNTOF(...) (sizeof(__VA_ARGS__) / sizeof(*(__VA_ARGS__)))
+
#define error_exit(...) exit((fprintf(stderr, PROGRAM_NAME ": " __VA_ARGS__), 1))
noreturn void usage_exit(int status) {
diff --git a/tools/make_patch.c b/tools/make_patch.c
index 71c6b455..ecfd67b2 100644
--- a/tools/make_patch.c
+++ b/tools/make_patch.c
@@ -165,7 +165,7 @@ int strfind(const char *s, const char *list[], int count) {
return -1;
}
-#define vstrfind(s, ...) strfind(s, (const char *[]){__VA_ARGS__}, sizeof (const char *[]){__VA_ARGS__} / sizeof(const char *))
+#define vstrfind(s, ...) strfind(s, (const char *[]){__VA_ARGS__}, COUNTOF((const char *[]){__VA_ARGS__}))
int parse_arg_value(const char *arg, bool absolute, const struct Symbol *symbols, const char *patch_name) {
// Comparison operators for "ConditionValueB" evaluate to their particular values
diff --git a/tools/pkmncompress.c b/tools/pkmncompress.c
index f8899b1e..0e20df4f 100644
--- a/tools/pkmncompress.c
+++ b/tools/pkmncompress.c
@@ -32,7 +32,7 @@ void write_bit(int bit) {
}
void compress_plane(uint8_t *plane, int width) {
- static int nybble_lookup[2][0x10] = {
+ static int gray_codes[2][0x10] = {
{0x0, 0x1, 0x3, 0x2, 0x6, 0x7, 0x5, 0x4, 0xC, 0xD, 0xF, 0xE, 0xA, 0xB, 0x9, 0x8},
{0x8, 0x9, 0xB, 0xA, 0xE, 0xF, 0xD, 0xC, 0x4, 0x5, 0x7, 0x6, 0x2, 0x3, 0x1, 0x0},
};
@@ -44,10 +44,10 @@ void compress_plane(uint8_t *plane, int width) {
}
int j = i / width + m * width * 8;
int nybble_hi = (plane[j] >> 4) & 0xF;
- int code_1 = nybble_lookup[nybble_lo & 1][nybble_hi];
+ int code_hi = gray_codes[nybble_lo & 1][nybble_hi];
nybble_lo = plane[j] & 0xF;
- int code_2 = nybble_lookup[nybble_hi & 1][nybble_lo];
- plane[j] = (code_1 << 4) | code_2;
+ int code_lo = gray_codes[nybble_hi & 1][nybble_lo];
+ plane[j] = (code_hi << 4) | code_lo;
}
}
@@ -105,7 +105,7 @@ int interpret_compress(uint8_t *plane1, uint8_t *plane2, int mode, int order, in
}
cur_bit = 7;
cur_byte = 0;
- memset(compressed, 0, sizeof(compressed) / sizeof(*compressed));
+ memset(compressed, 0, COUNTOF(compressed));
compressed[0] = (width << 4) | width;
write_bit(order);
uint8_t bit_groups[0x1000] = {0};
@@ -113,7 +113,7 @@ int interpret_compress(uint8_t *plane1, uint8_t *plane2, int mode, int order, in
for (int plane = 0; plane < 2; plane++) {
int type = 0;
int nums = 0;
- memset(bit_groups, 0, sizeof(bit_groups) / sizeof(*bit_groups));
+ memset(bit_groups, 0, COUNTOF(bit_groups));
for (int x = 0; x < width; x++) {
for (int bit = 0; bit < 8; bit += 2) {
for (int y = 0, byte = x * width * 8; y < width * 8; y++, byte++) {
@@ -129,7 +129,7 @@ int interpret_compress(uint8_t *plane1, uint8_t *plane2, int mode, int order, in
write_bit(0);
}
type = 1;
- memset(bit_groups, 0, sizeof(bit_groups) / sizeof(*bit_groups));
+ memset(bit_groups, 0, COUNTOF(bit_groups));
index = 0;
} else {
if (!type) {
@@ -171,7 +171,7 @@ int compress(uint8_t *data, int width) {
plane1[i] = data[i * 2];
plane2[i] = data[i * 2 + 1];
}
- uint8_t current[sizeof(compressed) / sizeof(*compressed)] = {0};
+ uint8_t current[COUNTOF(compressed)] = {0};
int compressed_size = -1;
for (int mode = 1; mode < 4; mode++) {
for (int order = 0; order < 2; order++) {
@@ -181,12 +181,12 @@ int compress(uint8_t *data, int width) {
int new_size = interpret_compress(plane1, plane2, mode, order, width);
if (compressed_size == -1 || new_size < compressed_size) {
compressed_size = new_size;
- memset(current, 0, sizeof(current) / sizeof(*current));
+ memset(current, 0, COUNTOF(current));
memcpy(current, compressed, compressed_size / 8);
}
}
}
- memset(compressed, 0, sizeof(compressed) / sizeof(*compressed));
+ memset(compressed, 0, COUNTOF(compressed));
memcpy(compressed, current, compressed_size / 8);
free(plane1);
free(plane2);