Mercurial > hg > dmlib
comparison tools/objlink.c @ 2560:ac2e60f4bfc3
Improve block description output.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Sun, 27 Feb 2022 17:58:20 +0200 |
parents | 32c2375fda16 |
children | 56510bd4c66b |
comparison
equal
deleted
inserted
replaced
2559:32c2375fda16 | 2560:ac2e60f4bfc3 |
---|---|
741 } | 741 } |
742 | 742 |
743 | 743 |
744 /* Print out an ASCII presentation of memory map | 744 /* Print out an ASCII presentation of memory map |
745 */ | 745 */ |
746 void memPrintLine(FILE *f) | 746 #define BOX_WIDTH 60 |
747 { | 747 #define TO_STR1(x) #x |
748 fprintf(f, | 748 #define TO_STR(x) TO_STR1(x) |
749 " +----------------------------------------------------+\n"); | 749 |
750 } | 750 void memPrintLine(FILE *fh) |
751 | 751 { |
752 void memPrintEmpty(FILE *f, int n) | 752 fputs(" +", fh); |
753 for (int i = 0; i < BOX_WIDTH + 2; i++) | |
754 fputc('-', fh); | |
755 fputs("+\n", fh); | |
756 } | |
757 | |
758 void memPrintEmpty(FILE *fh, const int n) | |
753 { | 759 { |
754 for (int i = 0; i < n; i++) | 760 for (int i = 0; i < n; i++) |
755 fprintf(f, | 761 { |
756 " | |\n"); | 762 fputs(" | ", fh); |
757 } | 763 for (int i = 0; i < BOX_WIDTH; i++) |
758 | 764 fputc(' ', fh); |
759 void dmDescribeMemory(FILE *f) | 765 fputs(" |\n", fh); |
760 { | 766 } |
761 DMMemBlock *prev = NULL; | 767 } |
762 | 768 |
763 memPrintLine(f); | 769 void memPrintBox(FILE *fh, const int bsize, const int bstart, const int bend, const char *bdesc) |
770 { | |
771 int bksize = bsize / (1024 * 2); | |
772 if (bksize > 1) memPrintEmpty(fh, bksize); | |
773 fprintf(fh, "$%.4x - $%.4x | %-" TO_STR(BOX_WIDTH) "s |\n", bstart, bend, bdesc); | |
774 if (bksize > 1) memPrintEmpty(fh, bksize); | |
775 memPrintLine(fh); | |
776 } | |
777 | |
778 void dmDescribeMemory(FILE *fh) | |
779 { | |
780 DMMemBlock *bprev = NULL; | |
781 | |
782 memPrintLine(fh); | |
764 | 783 |
765 for (int i = 0; i < nmemBlocks; i++) | 784 for (int i = 0; i < nmemBlocks; i++) |
766 { | 785 { |
767 DMMemBlock *curr = &memBlocks[i]; | 786 DMMemBlock *bcurr = &memBlocks[i]; |
768 char desc[512], *s; | 787 char bdesc[128]; |
769 int siz, kz; | 788 const char *btype; |
789 int bsize; | |
770 | 790 |
771 // Check for empty, unreserved areas | 791 // Check for empty, unreserved areas |
772 if (prev != NULL) | 792 if (bprev != NULL && (bsize = (bcurr->start - 1) - (bprev->end + 1) + 1) > 1) |
773 siz = (curr->start - 1) - (prev->end + 1) + 1; | 793 { |
774 else | 794 snprintf(bdesc, sizeof(bdesc), "EMPTY (%d)", bsize); |
775 siz = 0; | 795 memPrintBox(fh, bsize, bprev->end + 1, bcurr->start - 1, bdesc); |
776 | 796 } |
777 if (prev != NULL && siz > 1) | 797 bprev = bcurr; |
778 { | |
779 kz = siz / (1024 * 2); | |
780 | |
781 if (kz > 1) memPrintEmpty(f, kz); | |
782 | |
783 snprintf(desc, sizeof(desc), "EMPTY (%d)", siz); | |
784 fprintf(f, "$%.4x - $%.4x | %-50s |\n", prev->end + 1, curr->start - 1, desc); | |
785 | |
786 if (kz > 1) memPrintEmpty(f, kz); | |
787 memPrintLine(f); | |
788 } | |
789 prev = curr; | |
790 | 798 |
791 // Print current block | 799 // Print current block |
792 switch (curr->type) | 800 switch (bcurr->type) |
793 { | 801 { |
794 case MTYPE_NONE: s = "N/A (NC)"; break; | 802 case MTYPE_NONE: btype = "N/A (NC)"; break; |
795 case MTYPE_ROM: s = "ROM"; break; | 803 case MTYPE_ROM: btype = "ROM"; break; |
796 case MTYPE_WT: s = "WT"; break; | 804 case MTYPE_WT: btype = "WT"; break; |
797 case MTYPE_IO: s = "I/O"; break; | 805 case MTYPE_IO: btype = "I/O"; break; |
798 case MTYPE_RES: s = "RSVD"; break; | 806 case MTYPE_RES: btype = "RSVD"; break; |
799 default: s = "????"; break; | 807 default: btype = "????"; break; |
800 } | 808 } |
801 | 809 |
802 siz = curr->end - curr->start + 1; | 810 bsize = bcurr->end - bcurr->start + 1; |
803 kz = siz / (1024 * 2); | 811 snprintf(bdesc, sizeof(bdesc), "%.40s (%s, %d)", bcurr->name, btype, bsize); |
804 | 812 memPrintBox(fh, bsize, bcurr->start, bcurr->end, bdesc); |
805 if (kz > 1) memPrintEmpty(f, kz); | |
806 snprintf(desc, sizeof(desc), "%.40s (%s, %d)", curr->name, s, siz); | |
807 fprintf(f, "$%.4x - $%.4x | %-50s |\n", curr->start, curr->end, desc); | |
808 if (kz > 1) memPrintEmpty(f, kz); | |
809 memPrintLine(f); | |
810 | |
811 } | 813 } |
812 } | 814 } |
813 | 815 |
814 | 816 |
815 /* | 817 /* |