#ifndef __shared_h_
#define __shared_h_

#define MAXSTRINGRESOURCES 12

#define STRP(row) (&g.indp[g.sortp[row]][2] )
#define BITP(row) (&g.bitp[g.sortp[row]/256][g.sortp[row]&0xff] )

typedef struct {
  Word numEntries;  //Each string resource reports a number of entries.
  char data[0];      //Entries themselves follow, 0 delimited.
} StringResource_t;

typedef struct {
  DWord data[8];
} BitmapData_t;

typedef struct {
  Word gs;
  ULong bsf;
} KanjiData_t;

typedef struct {
  unsigned char record; //record of last 8 guesses.  MSB = most recent guess
} KanjiInfo_t;

typedef struct {
  unsigned long numIndices:16; //maxIndex +1
  unsigned long numKanji:16 ;   //maxKanji +1
  long numGuessed;
  long numRight;

  KanjiInfo_t track[0];  //alocated at whatever the number of indices is
} UserTrack_t;

#define SORT_NONE 0
#define SORT_FREQ  1
#define SORT_SPAHN 2
#define SORT_GRADE 3
#define SORT_SKIP  4
#define SORT_COUNT 5
#define SORT_BUSHU 6
#define SORT_LAST 6

//kp must be a KanjiData_t pointer
#define SORTVAL_BUSHU(index) (kp[index].bsf >> 23)
#define SORTVAL_FREQ(index)  ((kp[index].bsf >> 12) & 0x7ff)
#define SORTVAL_SKIP(index)  (kp[index].bsf & 0xfff)
#define SORTVAL_SPAHN(index) (kp[index].gs & 0x1fff)
#define SORTVAL_GRADE(index) (kp[index].gs >> 13)
#define SORTVAL_COUNT(index) ({unsigned long i = SORTVAL_SPAHN(index); \
        (i /600) + (i % 30);})

#endif
