-
Notifications
You must be signed in to change notification settings - Fork 3
/
ntsc2pal.awk
64 lines (61 loc) · 1.3 KB
/
ntsc2pal.awk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
function ntsc2pal(addr) {
# The addresses in these conditions are PAL addresses
if (addr < 0x9DB3) return addr
addr+=6
if (addr < 0xA3FC) return addr
addr+=6
if (addr < 0xA46F) return addr
addr+=19
if (addr < 0xA577) return addr
addr-=1
if (addr < 0xA5D3) return addr
addr-=1
if (addr < 0xA602) return addr
addr-=1
if (addr < 0xA619) return addr
addr-=1
if (addr < 0xA630) return addr
addr-=1
if (addr <= 0xD6E3) return addr
addr-=26 # back in sync
if (addr <= 0xEBAF) return addr
addr-=44
if (addr <= 0xEC6F) return addr
addr+=2
if (addr <= 0xEC87) return addr
addr+=2
if (addr <= 0xEC9F) return addr
addr+=2
if (addr <= 0xECB7) return addr
addr+=2
if (addr <= 0xF0EF) return addr
addr+=35
if (addr <= 0xF3BB) return addr
addr+=3
if (addr <= 0xF45A) return addr
addr+=9
if (addr <= 0xF53B) return addr
addr+=3
if (addr <= 0xF841) return addr
addr-=4
if (addr < 0xFF00) return addr
addr-=10 # back in sync
return addr
}
/NAME "(MMC1_Control|MMC1_CHR0|MMC1_CHR1|DMC_START)"/ {
print
next
}
/ADDR \$A42B/ {
sub("@ret", "playState_bTypeGoalCheck_ret")
}
{
while (match($0, /\$[0-9A-Fa-f]{4}/)) {
printf("%s", substr($0, 1, RSTART-1))
addr=substr($0, RSTART, RLENGTH)
sub(/\$/, "0x", addr)
printf("$%04X", ntsc2pal(strtonum(addr)))
$0=substr($0, RSTART+RLENGTH)
}
print
}