151a3a83a44823a68649c84019b0ddadc712e8ea
[picodrive.git] / Pico / cd / cell_map.c
1 // Convert "cell arrange" address to normal address.
2 // (c) Copyright 2007, Grazvydas "notaz" Ignotas
3
4 // 64 x32 x16 x8 x4 x4
5 static unsigned int cell_map(int celln)
6 {
7   int col, row;
8
9   switch ((celln >> 12) & 7) { // 0-0x8000
10     case 0: // x32 cells
11     case 1:
12     case 2:
13     case 3:
14       col = celln >> 8;
15       row = celln & 0xff;
16       break;
17     case 4: // x16
18     case 5:
19       col  = celln >> 7;
20       row  = celln & 0x7f;
21       row |= 0x10000 >> 8;
22       break;
23     case 6: // x8
24       col  = celln >> 6;
25       row  = celln & 0x3f;
26       row |= 0x18000 >> 8;
27       break;
28     case 7: // x4
29       col  = celln >> 5;
30       row  = celln & 0x1f;
31       row |= (celln & 0x7800) >> 6;
32       break;
33     default: // never happens, only here to make compiler happy
34       col = row = 0;
35       break;
36   }
37
38   return (col & 0x3f) + row*64;
39 }
40