Created
January 28, 2017 23:03
-
-
Save camthesaxman/22210fab1ab58378dea169bbe2b665c9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/perl | |
# | |
# Converts REG_DISPCNT values to the appropriate flag constants | |
# | |
use strict; | |
use warnings; | |
sub usage { | |
print "Usage: $0 [dispcnt value]\n"; | |
exit; | |
} | |
sub bitrange { | |
my ($num, $lobit, $hibit) = @_; | |
return ($num & ((1 << ($hibit + 1)) - 1)) >> $lobit; | |
} | |
sub bit { | |
return ($_[0] >> $_[1]) & 1; | |
} | |
@ARGV == 1 | |
or usage; | |
(my $dispcntVal) = map +(/^0x/ ? hex : $_), $ARGV[0]; | |
my @flags; | |
my $mode = bitrange $dispcntVal, 0, 2; | |
push @flags, "DISPCNT_MODE_$mode"; | |
if (bit $dispcntVal, 6) { | |
push @flags, 'DISPCNT_OBJ_1D_MAP'; | |
} | |
if (bit $dispcntVal, 7) { | |
push @flags, 'DISPCNT_FORCED_BLANK'; | |
} | |
if (bitrange ($dispcntVal, 8, 11) == 15) { | |
push @flags, 'DISPCNT_BG_ALL_ON'; | |
} | |
else { | |
for my $i (0..3) { | |
if (bit $dispcntVal, (8 + $i)) { | |
push @flags, "DISPCNT_BG${i}_ON"; | |
} | |
} | |
} | |
if (bit $dispcntVal, 12) { | |
push @flags, 'DISPCNT_OBJ_ON'; | |
} | |
if (bit $dispcntVal, 13) { | |
push @flags, 'DISPCNT_WIN0_ON'; | |
} | |
if (bit $dispcntVal, 14) { | |
push @flags, 'DISPCNT_WIN1_ON'; | |
} | |
if (bit $dispcntVal, 15) { | |
push @flags, 'DISPCNT_OBJWIN_ON'; | |
} | |
print join ' | ', @flags; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment