home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
CBM Funet Archive
/
cbm-funet-archive-2003.iso
/
cbm
/
programming
/
msdos
/
xa214f.lzh
/
xa214f
/
misc
/
file65.c
next >
Wrap
C/C++ Source or Header
|
1997-04-16
|
5KB
|
175 lines
/*
XA65 - 6502 CROSS ASSEMBLER AND UTILITY SUITE
FILE65 - PRINTS INFORMATION ON 'O65' FILES
cOPYRIGHT (c) 1997 aNDR{$e9} fACHAT (A.FACHAT@PHYSIK.TU-CHEMNITZ.DE)
tHIS PROGRAM IS FREE SOFTWARE; YOU CAN REDISTRIBUTE IT AND/OR MODIFY
IT UNDER THE TERMS OF THE gnu gENERAL pUBLIC lICENSE AS PUBLISHED BY
THE fREE sOFTWARE fOUNDATION; EITHER VERSION 2 OF THE lICENSE, OR
(AT YOUR OPTION) ANY LATER VERSION.
tHIS PROGRAM IS DISTRIBUTED IN THE HOPE THAT IT WILL BE USEFUL,
BUT without any warranty; WITHOUT EVEN THE IMPLIED WARRANTY OF
merchantability OR fitness for a particular purpose. sEE THE
gnu gENERAL pUBLIC lICENSE FOR MORE DETAILS.
yOU SHOULD HAVE RECEIVED A COPY OF THE gnu gENERAL pUBLIC lICENSE
ALONG WITH THIS PROGRAM; IF NOT, WRITE TO THE fREE sOFTWARE
fOUNDATION, iNC., 675 mASS aVE, cAMBRIDGE, ma 02139, usa.
*/
#INCLUDE <STDIO.H>
#INCLUDE <STDLIB.H>
#INCLUDE <SYS/STAT.H>
#INCLUDE <UNISTD.H>
#INCLUDE <ERRNO.H>
#INCLUDE <STRING.H>
#DEFINEbuf(9*4+8)
INT READ_OPTIONS(file *FP);
UNSIGNED CHAR HDR[buf];
UNSIGNED CHAR CMP[] = {$7b} 1, 0, 'O', '6', '5' {$7d};
INT XAPAR = 0;
INT ROMPAR = 0;
INT ROMOFF = 0;
VOID USAGE(VOID) {$7b}
PRINTF("FILE65: PRINTS FILE INFORMATION ON 'O65' FILES\N"
" FILE65 [OPTIONS] [FILENAMES...]\N"
"OPTIONS:\N"
" -V = PRINT VERSION NUMBER\N"
" -H, -? = PRINT THIS HELP\N"
" -p = PRINT THE SEGMENT END ADDRESSES ACCORDING TO XA COMMAND LINE\N"
" PARAMETERS '-B?'\N"
" -A OFFSET = PRINT XA 'ROMABLE' PARAMETER FOR ANOTHER FILE BEHIND THIS ONE\N"
" IN THE SAME rom. aDD OFFSET TO START ADDRESS.\N"
" -a OFFSET = SAME AS '-A', BUT ONLY PRINT THE START ADDRESS OF THE NEXT\N"
" FILE IN THE rom.\N"
);
EXIT(0);
{$7d}
INT MAIN(INT ARGC, CHAR *ARGV[]) {$7b}
INT I = 1, N, MODE, HLEN;
file *FP;
CHAR *ALIGNTXT[4]= {$7b}"[ALIGN 1]","[ALIGN 2]","[ALIGN 4]","[ALIGN 256]"{$7d};
IF(ARGC<=1) USAGE();
WHILE(I<ARGC) {$7b}
IF(ARGV[I][0]=='-') {$7b}
/* PROCESS OPTIONS */
SWITCH(ARGV[I][1]) {$7b}
CASE 'V':
PRINTF("FILE65: vERSION 0.2\N");
BREAK;
CASE 'A':
CASE 'a':
ROMPAR = 1;
IF(ARGV[I][1]=='a') ROMPAR++;
IF(ARGV[I][2]) ROMOFF = ATOI(ARGV[I]+2);
ELSE ROMOFF = ATOI(ARGV[++I]);
BREAK;
CASE 'p':
XAPAR = 1;
BREAK;
CASE 'H':
CASE '?':
USAGE();
DEFAULT:
FPRINTF(STDERR,"FILE65: %S UNKNOWN OPTION\N",ARGV[I]);
BREAK;
{$7d}
{$7d} ELSE {$7b}
FP = FOPEN(ARGV[I],"RB");
IF(FP) {$7b}
N = FREAD(HDR, 1, 8, FP);
IF((N>=8) && (!MEMCMP(HDR, CMP, 5))) {$7b}
MODE=HDR[7]*256+HDR[6];
IF(!XAPAR && !ROMPAR) {$7b}
PRINTF("%S: O65 VERSION %D %S FILE\N", ARGV[I], HDR[5],
HDR[7]&0X10 ? "OBJECT" : "EXECUTABLE");
PRINTF(" MODE: %04X =",MODE );
PRINTF("%S%S%S%S%S\N",
(MODE & 0X1000)?"[OBJECT]":"[EXECUTABLE]",
(MODE & 0X2000)?"[32BIT]":"[16BIT]",
(MODE & 0X4000)?"[PAGE RELOCATION]":"[BYTE RELOCATION]",
(MODE & 0X8000)?"[cpu 65816]":"[cpu 6502]",
ALIGNTXT[MODE & 3]);
{$7d}
IF(MODE & 0X2000) {$7b}
FPRINTF(STDERR,"FILE65: %S: 32 BIT SIZE NOT SUPPORTED\N", ARGV[I]);
{$7d} ELSE {$7b}
N=FREAD(HDR+8, 1, 18, FP);
IF(N<18) {$7b}
FPRINTF(STDERR,"FILE65: %S: TRUNCATED FILE\N", ARGV[I]);
{$7d} ELSE {$7b}
HLEN = 8+18+READ_OPTIONS(FP);
IF(!XAPAR && !ROMPAR) {$7b}
PRINTF(" TEXT SEGMENT @ $%04X - $%04X [$%04X BYTES]\N", HDR[9]*256+HDR[8], HDR[9]*256+HDR[8]+HDR[11]*256+HDR[10], HDR[11]*256+HDR[10]);
PRINTF(" DATA SEGMENT @ $%04X - $%04X [$%04X BYTES]\N", HDR[13]*256+HDR[12], HDR[13]*256+HDR[12]+HDR[15]*256+HDR[14], HDR[15]*256+HDR[14]);
PRINTF(" BSS SEGMENT @ $%04X - $%04X [$%04X BYTES]\N", HDR[17]*256+HDR[16], HDR[17]*256+HDR[16]+HDR[19]*256+HDR[18], HDR[19]*256+HDR[18]);
PRINTF(" ZERO SEGMENT @ $%04X - $%04X [$%04X BYTES]\N", HDR[21]*256+HDR[20], HDR[21]*256+HDR[20]+HDR[23]*256+HDR[22], HDR[23]*256+HDR[22]);
PRINTF(" STACK SIZE $%04X BYTES %S\N", HDR[25]*256+HDR[24],
(HDR[25]*256+HDR[24])==0?"(I.E. UNKNOWN)":"");
{$7d} ELSE {$7b}
STRUCT STAT FBUF;
STAT(ARGV[I],&FBUF);
IF(XAPAR) {$7b}
IF(!ROMPAR) PRINTF("-BT %D ",
(HDR[9]*256+HDR[8]) + (HDR[11]*256+HDR[10])
);
PRINTF("-BD %D -BB %D -BZ %D ",
(HDR[13]*256+HDR[12]) + (HDR[15]*256+HDR[14]),
(HDR[17]*256+HDR[16]) + (HDR[19]*256+HDR[18]),
(HDR[21]*256+HDR[20]) + (HDR[23]*256+HDR[22])
);
{$7d}
IF(ROMPAR==1) {$7b}
PRINTF("-a %LD ", (HDR[9]*256+HDR[8])
-HLEN +ROMOFF +FBUF.ST_SIZE);
{$7d} ELSE
IF(ROMPAR==2) {$7b}
PRINTF("%LD ", (HDR[9]*256+HDR[8])
-HLEN +ROMOFF +FBUF.ST_SIZE);
{$7d}
PRINTF("\N");
{$7d}
{$7d}
{$7d}
{$7d} ELSE {$7b}
FPRINTF(STDERR,"FILE65: %S: NOT AN O65 FILE!\N", ARGV[I]);
IF(HDR[0]==1 && HDR[1]==8 && HDR[3]==8) {$7b}
PRINTF("%S: c64 basic EXECUTABLE (START ADDRESS $0801)?\N", ARGV[I]);
{$7d} ELSE
IF(HDR[0]==1 && HDR[1]==4 && HDR[3]==4) {$7b}
PRINTF("%S: cbm pet basic EXECUTABLE (START ADDRESS $0401)?\N", ARGV[I]);
{$7d}
{$7d}
{$7d} ELSE {$7b}
FPRINTF(STDERR,"FILE65: %S: %S\N", ARGV[I], STRERROR(ERRNO));
{$7d}
{$7d}
I++;
{$7d}
RETURN 0;
{$7d}
INT READ_OPTIONS(file *FP) {$7b}
INT C, L=0;
CHAR TB[256];
C=FGETC(FP); L++;
WHILE(C && C!=eof) {$7b}
C&=255;
FREAD(TB, 1, C-1, FP);
L+=C;
C=FGETC(FP);
{$7d}
RETURN L;
{$7d}