From a4cc3ad3504d634e379369862c9f9fd8eed379f3 Mon Sep 17 00:00:00 2001 From: "B. Watson" Date: Thu, 16 May 2024 01:43:09 -0400 Subject: Add Jindrich Kubec's tools. --- jindroush/chkrom/chkrom.cpp | 119 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 119 insertions(+) create mode 100644 jindroush/chkrom/chkrom.cpp (limited to 'jindroush/chkrom/chkrom.cpp') diff --git a/jindroush/chkrom/chkrom.cpp b/jindroush/chkrom/chkrom.cpp new file mode 100644 index 0000000..32c8979 --- /dev/null +++ b/jindroush/chkrom/chkrom.cpp @@ -0,0 +1,119 @@ +// 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 +// 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 +#include "pub.def" +#include "jintypes.h" +#include "at_dis.h" + +BOOL g_bDisassemble = FALSE; + +int hIn = -1; + +char* g_szInfile = NULL; + +#define SHEADER PRG_NAME " v" PRG_VERSION " (c) " PRG_COPYRIGHT " " PRG_AUTHOR "\n" + +#define HEADER SHEADER \ + PRG_DESC "\n" \ + " Latest version can be found at " PRG_URL "\n" \ + " Published under GPL. See GPL.TXT.\n\n" + +#define USAGE HEADER "Usage: " PRG_NAME " " PRG_USAGE + +#include "switches.cpp" + +int main (int argc,char *argv[]) +{ + setbuf( stdout, NULL ); + setbuf( stderr, NULL ); + + if ( !SWITCHES_Init( &argc, argv ) ) + return 1; + + if ( argc < 2 ) + { + SWFN_HELP( USAGE ); + return 1; + } + + fprintf( stderr, SHEADER ); + + g_szInfile = argv[ 1 ]; + + hIn = open( g_szInfile, O_RDONLY | O_BINARY ); + + if ( hIn == -1 ) + { + fprintf(stderr, "Unable to open file\n\n%s", g_szInfile ); + exit( 1 ); + } + + LONG lFileLen = lseek( hIn, 0, SEEK_END ); + + lseek( hIn, 0, SEEK_SET ); + + if ( ( lFileLen != 0x2000 ) && ( lFileLen != 0x4000 ) ) + { + printf( "%s: Unknown ROM size\n", g_szInfile ); + close( hIn ); + exit( 1 ); + } + + printf( "ROM file: %s\n", g_szInfile ); + + BYTE pbtMem[ 0x4000 ]; + + read( hIn, pbtMem, lFileLen ); + + WORD wInit = pbtMem[ lFileLen - 2 ] + ( pbtMem[ lFileLen - 1 ] << 8 ); + WORD wFlags = pbtMem[ lFileLen - 4 ] + ( pbtMem[ lFileLen - 3 ] << 8 ); + WORD wRun = pbtMem[ lFileLen - 6 ] + ( pbtMem[ lFileLen - 5 ] << 8 ); + + WORD wStart = ( lFileLen == 0x2000 ) ? 0xA000 : 0x8000; + + printf( "Init Addr :%04X\n", wInit ); + printf( "Run Addr :%04X\n", wRun ); + printf( "Flags :%04X ( ", wFlags ); + + if ( wFlags & 0x0400 ) + { + printf( "INIT&RUN " ); + } + else + printf( "INIT " ); + + if ( wFlags & 0x0100 ) + printf( "BOOT " ); + + if ( wFlags & 0x8000 ) + printf( "TESTMOD " ); + + printf( ")\n" ); + + if ( g_bDisassemble ) + { + printf( "\n" ); + OutputBlockDiss( pbtMem, wStart, wStart + lFileLen - 1 - 6 ); + printf( "\n" ); + } + + printf( "Ok!\n" ); + + close( hIn ); + + return 0; +} + -- cgit v1.2.3