ramseg.c 905 B

1234567891011121314151617181920212223242526272829
  1. #include <stdio.h>
  2. #include "ramseg.h"
  3. int size_array(int *ram_seg, int nrows, int ncols)
  4. {
  5. int size, segs_in_col;
  6. segs_in_col = ((nrows - 1) >> RAMSEGBITS) + 1;
  7. *ram_seg = ((ncols - 1) >> RAMSEGBITS) + 1;
  8. size = ((((nrows - 1) >> RAMSEGBITS) + 1) << RAMSEGBITS) *
  9. ((((ncols - 1) >> RAMSEGBITS) + 1) << RAMSEGBITS);
  10. size -= ((segs_in_col << RAMSEGBITS) - nrows) << RAMSEGBITS;
  11. size -= (*ram_seg << RAMSEGBITS) - ncols;
  12. return (size);
  13. }
  14. /* get r, c from seg_index */
  15. int seg_index_rc(int ramseg, int seg_index, int *r, int *c)
  16. {
  17. int seg_no, seg_remainder;
  18. seg_no = seg_index >> DOUBLEBITS;
  19. seg_remainder = seg_index - (seg_no << DOUBLEBITS);
  20. *r = ((seg_no / ramseg) << RAMSEGBITS) + (seg_remainder >> RAMSEGBITS);
  21. *c = ((seg_no - ((*r) >> RAMSEGBITS) * ramseg) << RAMSEGBITS) +
  22. seg_remainder - (((*r) & SEGLENLESS) << RAMSEGBITS);
  23. return seg_no;
  24. }