[go: up one dir, main page]

Menu

[r65]: / psrp / fast_sort / sort.cpp  Maximize  Restore  History

Download this file

80 lines (62 with data), 1.6 kB

 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
// Phantasy Star: List sorter and pointer table creater
#include <stdio.h>
int main( int argc, char **argv )
{
int MAIN = argc > 2 ? 1 : 0;
FILE *in;
int address, offset;
char junk[4096];
int list1[4096], list2[4096], index = 0;
in = fopen( argv[1], "r" );
while( fscanf( in, "%X %X", &address, &offset ) ) {
fgets( junk, sizeof( junk ), in );
if( address == -1 && offset == -1 ) break;
list1[ index ] = address;
list2[ index ] = offset;
index++;
}
fclose( in );
int loop = 0;
int old_lowest = -1;
if( MAIN ) printf( "\t" );
for( int lcv = 0; lcv < index; lcv++ ) {
int lowest = list2[ 0 ];
int offset = list1[ 0 ];
int spot = 0;
for( int lcv2 = 1; lcv2 < index; lcv2++ ) {
if( lowest > list2[ lcv2 ] ) {
// new lower
lowest = list2[ lcv2 ];
spot = lcv2;
offset = list1[ lcv2 ];
} else if( lowest == list2[ lcv2 ] && offset > list1[ lcv2 ] ) {
// swap
int old;
old = list1[ lcv2 ];
list1[ lcv2 ] = list1[ spot ];
list1[ spot ] = old;
old = list2[ lcv2 ];
list2[ lcv2 ] = list2[ spot ];
list2[ spot ] = old;
offset = list1[ spot ];
}
}
if( MAIN ) {
if( old_lowest == list2[ spot ] ) printf( "0x0000, " );
printf( "0x%x, ", list1[ spot ] );
old_lowest = list2[ spot ];
list2[ spot ] = 0xffff;
// formatting
loop++;
if( loop == 5 ) {
printf( "\n\t" );
loop = 0;
}
} else {
printf( "%X %04X\n", list1[ spot ], list2[ spot ] );
list2[ spot ] = 0xffff;
}
}
if( MAIN ) { printf( "0xffff,\n"); }
return 0;
}