diff options
author | B. Watson <urchlay@slackware.uk> | 2024-05-16 01:43:09 -0400 |
---|---|---|
committer | B. Watson <urchlay@slackware.uk> | 2024-05-16 01:43:09 -0400 |
commit | a4cc3ad3504d634e379369862c9f9fd8eed379f3 (patch) | |
tree | 7b6f55c352a4ca62dddaa1b4a6854799111d2d2f /jindroush/chkbas | |
parent | b33c25d1363110e6e4a714530f460b0ff951f56b (diff) | |
download | bw-atari8-tools-a4cc3ad3504d634e379369862c9f9fd8eed379f3.tar.gz |
Add Jindrich Kubec's tools.
Diffstat (limited to 'jindroush/chkbas')
-rw-r--r-- | jindroush/chkbas/Makefile | 61 | ||||
-rw-r--r-- | jindroush/chkbas/basic.h | 152 | ||||
-rw-r--r-- | jindroush/chkbas/basic_tb.h | 223 | ||||
-rw-r--r-- | jindroush/chkbas/basic_xe.h | 219 | ||||
-rw-r--r-- | jindroush/chkbas/basic_xl.h | 213 | ||||
-rw-r--r-- | jindroush/chkbas/carray.cpp | 158 | ||||
-rw-r--r-- | jindroush/chkbas/carray.h | 49 | ||||
-rw-r--r-- | jindroush/chkbas/chkbas.cpp | 1009 | ||||
l--------- | jindroush/chkbas/listbas | 1 | ||||
-rw-r--r-- | jindroush/chkbas/pub.def | 31 | ||||
-rw-r--r-- | jindroush/chkbas/readme.txt | 87 | ||||
-rw-r--r-- | jindroush/chkbas/strlwr.cpp | 11 | ||||
-rw-r--r-- | jindroush/chkbas/switches.def | 34 |
13 files changed, 2248 insertions, 0 deletions
diff --git a/jindroush/chkbas/Makefile b/jindroush/chkbas/Makefile new file mode 100644 index 0000000..18b1d75 --- /dev/null +++ b/jindroush/chkbas/Makefile @@ -0,0 +1,61 @@ +#===================================================================== +PRGNAME = chkbas + +all: $(PRGNAME) + +release: + @$(MAKE) $(PRGNAME) CFLAGS="-c -O2 -Wall" LDFLAGS="" + @echo RELEASE: Compiled. + +rel_strip: + @strip $(PRGNAME).exe + +rel_inst: + @copy $(PRGNAME).exe $(ATAROOT)\\bin + @echo RELEASE: Installed. + +debug: + @$(MAKE) $(PRGNAME) CFLAGS="-c -g -Wall -D_DEBUG" LDFLAGS="-g" + @echo DEBUG: Compiled. + +clean: + rm -f *.o + rm -f $(PRGNAME) + rm -f $(PRGNAME).exe + rm -f switches.cpp + rm -rf rel + @echo DEBUG: Cleaned. + +#===================================================================== +INCLUDES = makefile \ + basic.h \ + basic_tb.h \ + basic_xl.h \ + basic_xe.h \ + carray.h \ + wintypes.h + + +OBJECTS = chkbas.o \ + carray.o \ + strlwr.o + +#===================================================================== +CC = g++ +LD = g++ +LDLIBS = -lm -L../lib -ljindroush +CPPFLAGS=-I../include $(COPT) +COPT=-O2 + +#===================================================================== + +$(PRGNAME) : $(OBJECTS) + $(LD) $(LDFLAGS) $(OBJECTS) $(LDLIBS) -o $(PRGNAME) + +chkbas.o: chkbas.cpp switches.cpp + +%.o:%.cpp $(INCLUDES) switches.cpp + $(CC) $(CPPFLAGS) $(CFLAGS) $< -o $@ + +switches.cpp : switches.def ../switches.pl + @perl ../switches.pl $< $@ diff --git a/jindroush/chkbas/basic.h b/jindroush/chkbas/basic.h new file mode 100644 index 0000000..6fe96fc --- /dev/null +++ b/jindroush/chkbas/basic.h @@ -0,0 +1,152 @@ +// 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. +// + +char* aCmdsBasic[] = +{ + "REM", //00 + "DATA", //01 + "INPUT", //02 + "COLOR", //03 + "LIST", //04 + "ENTER", //05 + "LET", //06 + "IF", //07 + "FOR", //08 + "NEXT", //09 + "GOTO", //0a + "GO TO", //0b + "GOSUB", //0c + "TRAP", //0d + "BYE", //0e + "CONT", //0f + "COM", //10 + "CLOSE", //11 + "CLR", //12 + "DEG", //13 + "DIM", //14 + "END", //15 + "NEW", //16 + "OPEN", //17 + "LOAD", //18 + "SAVE", //19 + "STATUS", //1a + "NOTE", //1b + "POINT", //1c + "XIO", //1d + "ON", //1e + "POKE", //1f + "PRINT", //20 + "RAD", //21 + "READ", //22 + "RESTORE", //23 + "RETURN", //24 + "RUN", //25 + "STOP", //26 + "POP", //27 + "?", //28 + "GET", //29 + "PUT", //2a + "GRAPHICS", //2b + "PLOT", //2c + "POSITION", //2d + "DOS", //2e + "DRAWTO", //2f + "SETCOLOR", //30 + "LOCATE", //31 + "SOUND", //32 + "LPRINT", //33 + "CSAVE", //34 + "CLOAD", //35 + "", //36 silent let + "ERROR -", //37 last Atari Basic command +}; + +char* aOpsBasic[] = { + "NCONST", //0E + "SCONST", //0F + "NOUSE", //10 + "NOUSE", //11 + ",", //12 + "$", //13 + ":", //14 + ";", //15 + "EOL", //16 + " GOTO ", //17 + " GOSUB ", //18 + " TO ", //19 + " STEP ", //1A + " THEN ", //1B + "#", //1C + "<=", //1D + "<>", //1E + ">=", //1F + "<", //20 + ">", //21 + "=", //22 + "^", //23 + "*", //24 + "+", //25 + "-", //26 + "/", //27 + " NOT ", //28 + " OR ", //29 + " AND ", //2A + "(", //2B + ")", //2C + "=", //2D + "=", //2E + "<=", //2F + "<>", //30 + ">=", //31 + "<", //32 + ">", //33 + "=", //34 + "+", //35 + "-", //36 + "(", //37 + "(", //38 + "(", //39 + "(", //3A + "(", //3B + ",", //3C + "STR$", //3D + "CHR$", //3E + "USR", //3F + "ASC", //40 + "VAL", //41 + "LEN", //42 + "ADR", //43 + "ATN", //44 + "COS", //45 + "PEEK", //46 + "SIN", //47 + "RND", //48 + "FRE", //49 + "EXP", //4A + "LOG", //4B + "CLOG", //4C + "SQR", //4D + "SGN", //4E + "ABS", //4F + "INT", //50 + "PADDLE", //51 + "STICK", //52 + "PTRIG", //53 + "STRIG", //54 last Atari Basic +}; + +#define BASIC_CMD_NUM ( sizeof( aCmdsBasic ) / sizeof( aCmdsBasic[ 0 ] ) ) +#define BASIC_OPS_NUM ( sizeof( aOpsBasic ) / sizeof( aOpsBasic[ 0 ] ) ) + diff --git a/jindroush/chkbas/basic_tb.h b/jindroush/chkbas/basic_tb.h new file mode 100644 index 0000000..8547948 --- /dev/null +++ b/jindroush/chkbas/basic_tb.h @@ -0,0 +1,223 @@ +// 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. +// + +char* aCmdsTBasic[] = +{ + "REM", //00 + "DATA", //01 + "INPUT", //02 + "COLOR", //03 + "LIST", //04 + "ENTER", //05 + "LET", //06 + "IF", //07 + "FOR", //08 + "NEXT", //09 + "GOTO", //0a + "GO TO", //0b + "GOSUB", //0c + "TRAP", //0d + "BYE", //0e + "CONT", //0f + "COM", //10 + "CLOSE", //11 + "CLR", //12 + "DEG", //13 + "DIM", //14 + "END", //15 + "NEW", //16 + "OPEN", //17 + "LOAD", //18 + "SAVE", //19 + "STATUS", //1a + "NOTE", //1b + "POINT", //1c + "XIO", //1d + "ON", //1e + "POKE", //1f + "PRINT", //20 + "RAD", //21 + "READ", //22 + "RESTORE", //23 + "RETURN", //24 + "RUN", //25 + "STOP", //26 + "POP", //27 + "?", //28 + "GET", //29 + "PUT", //2a + "GRAPHICS", //2b + "PLOT", //2c + "POSITION", //2d + "DOS", //2e + "DRAWTO", //2f + "SETCOLOR", //30 + "LOCATE", //31 + "SOUND", //32 + "LPRINT", //33 + "CSAVE", //34 + "CLOAD", //35 + "", //36 silent let + "ERROR -", //37 last Atari Basic command + "DPOKE", //38 + "MOVE", //39 + "-MOVE", //3A + "*F", //3B + "REPEAT", //3C + "UNTIL", //3D + "WHILE", //3E + "WEND", //3F + "ELSE", //40 + "ENDIF", //41 + "BPUT", //42 + "BGET", //43 + "FILLTO", //44 + "DO", //45 + "LOOP", //46 + "EXIT", //47 + "DIR", //48 + "LOCK", //49 + "UNLOCK", //4A + "RENAME", //4B + "DELETE", //4C + "PAUSE", //4D + "TIME$=", //4E + "PROC", //4F + "EXEC", //50 + "ENDPROC", //51 + "FCOLOR", //52 + "*L", //53 + "------------------------------", //54 + "RENUM", //55 + "DEL", //56 + "DUMP", //57 + "TRACE", //58 + "TEXT", //59 + "BLOAD", //5A + "BRUN", //5B + "GO#", //5C + "#", //5D + "*B", //5E + "PAINT", //5F + "CLS", //60 + "DSOUND", //61 + "CIRCLE", //62 + "\%PUT", //63 + "\%GET", //64 +}; + +char* aOpsTBasic[] = { + "NHCONST", //0D + "NCONST", //0E + "SCONST", //0F + "NOUSE", //10 + "NOUSE", //11 + ",", //12 + "$", //13 + ":", //14 + ";", //15 + "EOL", //16 + " GOTO ", //17 + " GOSUB ", //18 + " TO ", //19 + " STEP ", //1A + " THEN ", //1B + "#", //1C + "<=", //1D + "<>", //1E + ">=", //1F + "<", //20 + ">", //21 + "=", //22 + "^", //23 + "*", //24 + "+", //25 + "-", //26 + "/", //27 + " NOT ", //28 + " OR ", //29 + " AND ", //2A + "(", //2B + ")", //2C + "=", //2D + "=", //2E + "<=", //2F + "<>", //30 + ">=", //31 + "<", //32 + ">", //33 + "=", //34 + "+", //35 + "-", //36 + "(", //37 + "(", //38 + "(", //39 + "(", //3A + "(", //3B + ",", //3C + "STR$", //3D + "CHR$", //3E + "USR", //3F + "ASC", //40 + "VAL", //41 + "LEN", //42 + "ADR", //43 + "ATN", //44 + "COS", //45 + "PEEK", //46 + "SIN", //47 + "RND", //48 + "FRE", //49 + "EXP", //4A + "LOG", //4B + "CLOG", //4C + "SQR", //4D + "SGN", //4E + "ABS", //4F + "INT", //50 + "PADDLE", //51 + "STICK", //52 + "PTRIG", //53 + "STRIG", //54 last Atari Basic + "DPEEK", //55 + "&", //56 + "!", //57 + "INSTR", //58 + "INKEY$", //59 + " EXOR ", //5A + "HEX$", //5B + "DEC", //5C + " DIV ", //5D + "FRAC", //5E + "TIME$", //5F + "TIME", //60 + " MOD ", //61 + " EXEC ", //62 + "RND", //63 + "RAND", //64 + "TRUNC", //65 + "%0", //66 + "%1", //67 + "%2", //68 + "%3", //69 + " GO# ", //6A + "UINSTR", //6B + "ERR", //6C + "ERL", //6D +}; + +#define TBASIC_CMD_NUM ( sizeof( aCmdsTBasic ) / sizeof( aCmdsTBasic[ 0 ] ) ) +#define TBASIC_OPS_NUM ( sizeof( aOpsTBasic ) / sizeof( aOpsTBasic[ 0 ] ) ) + diff --git a/jindroush/chkbas/basic_xe.h b/jindroush/chkbas/basic_xe.h new file mode 100644 index 0000000..fc86131 --- /dev/null +++ b/jindroush/chkbas/basic_xe.h @@ -0,0 +1,219 @@ +// 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. +// + +char* aCmdsBasicXe[] = +{ + "REM", //00 + "DATA", //01 + "INPUT", //02 + "COLOR", //03 + "LIST", //04 + "ENTER", //05 + "LET", //06 + "IF", //07 + "FOR", //08 + "NEXT", //09 + "GOTO", //0a + "GO TO", //0b + "GOSUB", //0c + "TRAP", //0d + "BYE", //0e + "CONT", //0f + "COM", //10 + "CLOSE", //11 + "CLR", //12 + "DEG", //13 + "DIM", //14 + "END", //15 + "NEW", //16 + "OPEN", //17 + "LOAD", //18 + "SAVE", //19 + "STATUS", //1a + "NOTE", //1b + "POINT", //1c + "XIO", //1d + "ON", //1e + "POKE", //1f + "PRINT", //20 + "RAD", //21 + "READ", //22 + "RESTORE", //23 + "RETURN", //24 + "RUN", //25 + "STOP", //26 + "POP", //27 + "?", //28 + "GET", //29 + "PUT", //2a + "GRAPHICS", //2b + "PLOT", //2c + "POSITION", //2d + "DOS", //2e + "DRAWTO", //2f + "SETCOLOR", //30 + "LOCATE", //31 + "SOUND", //32 + "LPRINT", //33 + "CSAVE", //34 + "CLOAD", //35 + "", //36 silent let + "ERROR -", //37 last Atari Basic command + + "WHILE", //38 + "ENDWHILE", //39 + "TRACEOFF", //3A + "TRACE", //3B + "ELSE", //3C + "ENDIF", //3D + "DPOKE", //3E + "LOMEM", //3F + "DEL", //40 + "RPUT", //41 + "RGET", //42 + "BPUT", //43 + "BGET", //44 + "TAB", //45 + "CP", //46 + "ERASE", //47 + "PROTECT", //48 + "UNPROTECT", //49 + "DIR", //4A + "RENAME", //4B + "MOVE", //4C + "MISSILE", //4D + "PMCLR", //4E + "PMCOLOR", //4F + "PMGRAPHICS", //50 + "PMMOVE", //51 + "PMWIDTH", //52 + "SET", //53 + "LVAR", //54 + "RENUM", //55 + "FAST", //56 + "LOCAL", //57 + "EXTEND", //58 + "PROCEDURE", //59 + "?5A?", //5A + "CALL", //5B + "SORTUP", //5C + "SORTDOWN", //5D + "EXIT", //5E + "NUM", //5F + "HITCLR", //60 + "INVERSE", //61 + "NORMAL", //62 + "BLOAD", //63 + "BSAVE", //64 +}; + +char* aOpsBasicXe[] = { + "NHCONST", //0D + "NCONST", //0E + "SCONST", //0F + "NOUSE", //10 + "NOUSE", //11 + ",", //12 + "$", //13 + ":", //14 + ";", //15 + "EOL", //16 + " GOTO ", //17 + " GOSUB ", //18 + " TO ", //19 + " STEP ", //1A + " THEN ", //1B + "#", //1C + "<=", //1D + "<>", //1E + ">=", //1F + "<", //20 + ">", //21 + "=", //22 + "^", //23 + "*", //24 + "+", //25 + "-", //26 + "/", //27 + " NOT ", //28 + " OR ", //29 + " AND ", //2A + "(", //2B + ")", //2C + "=", //2D + "=", //2E + "<=", //2F + "<>", //30 + ">=", //31 + "<", //32 + ">", //33 + "=", //34 + "+", //35 + "-", //36 + "(", //37 + "(", //38 + "(", //39 + "(", //3A + "(", //3B + ",", //3C + "STR$", //3D + "CHR$", //3E + "USR", //3F + "ASC", //40 + "VAL", //41 + "LEN", //42 + "ADR", //43 + "ATN", //44 + "COS", //45 + "PEEK", //46 + "SIN", //47 + "RND", //48 + "FRE", //49 + "EXP", //4A + "LOG", //4B + "CLOG", //4C + "SQR", //4D + "SGN", //4E + "ABS", //4F + "INT", //50 + "PADDLE", //51 + "STICK", //52 + "PTRIG", //53 + "STRIG", //54 last Atari Basic + " USING ", //55 + "%", //56 + "!", //57 + "&", //58 + ";", //59 + "BUMP(", //5A + "FIND(", //5B + "HEX$", //5C + "RANDOM(", //5D + "DPEEK", //5E + "SYS", //5F + "VSTICK", //60 + "HSTICK", //61 + "PMADR", //62 + "ERR", //63 + "TAB", //64 + "PEN", //65 + "LEFT$", //66 + "RIGHT$", //67 + "MID$", //68 +}; + +#define BASICXE_CMD_NUM ( sizeof( aCmdsBasicXe ) / sizeof( aCmdsBasicXe[ 0 ] ) ) +#define BASICXE_OPS_NUM ( sizeof( aOpsBasicXe ) / sizeof( aOpsBasicXe[ 0 ] ) ) + diff --git a/jindroush/chkbas/basic_xl.h b/jindroush/chkbas/basic_xl.h new file mode 100644 index 0000000..a97f8a7 --- /dev/null +++ b/jindroush/chkbas/basic_xl.h @@ -0,0 +1,213 @@ +// 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. +// + +#define BXL_EXTEND 0x5A + +char* aCmdsBasicXl[] = +{ + "REM", //00 + "DATA", //01 + "INPUT", //02 + "COLOR", //03 + "LIST", //04 + "ENTER", //05 + "LET", //06 + "IF", //07 + "FOR", //08 + "NEXT", //09 + "GOTO", //0a + "GO TO", //0b + "GOSUB", //0c + "TRAP", //0d + "BYE", //0e + "CONT", //0f + "COM", //10 + "CLOSE", //11 + "CLR", //12 + "DEG", //13 + "DIM", //14 + "END", //15 + "NEW", //16 + "OPEN", //17 + "LOAD", //18 + "SAVE", //19 + "STATUS", //1a + "NOTE", //1b + "POINT", //1c + "XIO", //1d + "ON", //1e + "POKE", //1f + "PRINT", //20 + "RAD", //21 + "READ", //22 + "RESTORE", //23 + "RETURN", //24 + "RUN", //25 + "STOP", //26 + "POP", //27 + "?", //28 + "GET", //29 + "PUT", //2a + "GRAPHICS", //2b + "PLOT", //2c + "POSITION", //2d + "DOS", //2e + "DRAWTO", //2f + "SETCOLOR", //30 + "LOCATE", //31 + "SOUND", //32 + "LPRINT", //33 + "CSAVE", //34 + "CLOAD", //35 + "", //36 silent let + "ERROR -", //37 last Atari Basic command + + "WHILE", //38 + "ENDWHILE", //39 + "TRACEOFF", //3A + "TRACE", //3B + "ELSE", //3C + "ENDIF", //3D + "DPOKE", //3E + "LOMEM", //3F + "DEL", //40 + "RPUT", //41 + "RGET", //42 + "BPUT", //43 + "BGET", //44 + "TAB", //45 + "CP", //46 + "ERASE", //47 + "PROTECT", //48 + "UNPROTECT", //49 + "DIR", //4A + "RENAME", //4B + "MOVE", //4C + "MISSILE", //4D + "PMCLR", //4E + "PMCOLOR", //4F + "PMGRAPHICS", //50 + "PMMOVE", //51 + "PMWIDTH", //52 + "SET", //53 + "LVAR", //54 + "RENUM", //55 + "FAST", //56 + "NUM", //57 + "END", //58 + + "?59?", //59 + "BXL_EXTEND", //5A + +}; + +char* aOpsBasicXl[] = { + "NHCONST", //0D + "NCONST", //0E + "SCONST", //0F + "NOUSE", //10 + "NOUSE", //11 + ",", //12 + "$", //13 + ":", //14 + ";", //15 + "EOL", //16 + " GOTO ", //17 + " GOSUB ", //18 + " TO ", //19 + " STEP ", //1A + " THEN ", //1B + "#", //1C + "<=", //1D + "<>", //1E + ">=", //1F + "<", //20 + ">", //21 + "=", //22 + "^", //23 + "*", //24 + "+", //25 + "-", //26 + "/", //27 + " NOT ", //28 + " OR ", //29 + " AND ", //2A + "(", //2B + ")", //2C + "=", //2D + "=", //2E + "<=", //2F + "<>", //30 + ">=", //31 + "<", //32 + ">", //33 + "=", //34 + "+", //35 + "-", //36 + "(", //37 + "(", //38 + "(", //39 + "(", //3A + "(", //3B + ",", //3C + "STR$", //3D + "CHR$", //3E + "USR", //3F + "ASC", //40 + "VAL", //41 + "LEN", //42 + "ADR", //43 + "ATN", //44 + "COS", //45 + "PEEK", //46 + "SIN", //47 + "RND", //48 + "FRE", //49 + "EXP", //4A + "LOG", //4B + "CLOG", //4C + "SQR", //4D + "SGN", //4E + "ABS", //4F + "INT", //50 + "PADDLE", //51 + "STICK", //52 + "PTRIG", //53 + "STRIG", //54 last Atari Basic + " USING ", //55 + "%", //56 + "!", //57 + "&", //58 + ";", //59 + "BUMP(", //5A + "FIND(", //5B + "HEX$", //5C + "RANDOM(", //5D + "DPEEK", //5E + "SYS", //5F + "VSTICK", //60 + "HSTICK", //61 + "PMADR", //62 + "ERR", //63 + "TAB", //64 + "PEN", //65 + "LEFT$", //66 + "RIGHT$", //67 + "MID$", //68 +}; + +#define BASICXL_CMD_NUM ( sizeof( aCmdsBasicXl ) / sizeof( aCmdsBasicXl[ 0 ] ) ) +#define BASICXL_OPS_NUM ( sizeof( aOpsBasicXl ) / sizeof( aOpsBasicXl[ 0 ] ) ) + diff --git a/jindroush/chkbas/carray.cpp b/jindroush/chkbas/carray.cpp new file mode 100644 index 0000000..212b0f3 --- /dev/null +++ b/jindroush/chkbas/carray.cpp @@ -0,0 +1,158 @@ +// 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 "carray.h" + +//constructs new object - 0 size +CArray::CArray() +{ + m_iAllocatedBlocks = 0; + m_iArrayItems = 0; + m_pFirstBlock = NULL; +} + +//destructor calls destroy +CArray::~CArray() +{ + Destroy(); +} + +//destructs all sub array blocks +void CArray::Destroy() +{ + if ( m_iAllocatedBlocks ) + { + SubArray* pCurr = m_pFirstBlock; + SubArray* pNext; + + while ( pCurr ) + { + pNext = pCurr->pNext; + delete pCurr; + pCurr = pNext; + } + } + + m_iAllocatedBlocks = 0; + m_iArrayItems = 0; + m_pFirstBlock = NULL; +} + +//deletes last item +BOOL CArray::DeleteLast() +{ + m_iArrayItems--; + return TRUE; +} + +//gets value from array +void* CArray::GetAt( int iItem ) +{ + if ( ( iItem + 1 ) > m_iArrayItems ) + return NULL; + + int iBlockNeeded = iItem / CARRAY_SUB_SIZE; + + int iBlockCurr = 0; + + SubArray* pCurr = m_pFirstBlock; + + while( iBlockCurr < iBlockNeeded ) + { + pCurr = pCurr->pNext; + iBlockCurr++; + + if ( !pCurr ) + return NULL; + } + + return pCurr->array[ iItem % CARRAY_SUB_SIZE ]; +} + +//sets array's value - must exist before +BOOL CArray::SetAt( int iItem, void* pPtr ) +{ + if ( ( iItem + 1 ) > m_iArrayItems ) + return FALSE; + + int iBlockNeeded = iItem / CARRAY_SUB_SIZE; + + int iBlockCurr = 0; + + SubArray* pCurr = m_pFirstBlock; + + while( iBlockCurr < iBlockNeeded ) + { + pCurr = pCurr->pNext; + iBlockCurr++; + if ( !pCurr ) + return FALSE; + } + + pCurr->array[ iItem % CARRAY_SUB_SIZE ] = pPtr; + return TRUE; +} + +//adds array's value +BOOL CArray::Add( void* pPtr ) +{ + if ( ((( m_iArrayItems ) / CARRAY_SUB_SIZE ) + 1 ) > m_iAllocatedBlocks ) + { + //if we need new block, we try to add them + if ( !AddNewBlock() ) + return FALSE; + } + + m_iArrayItems++; + + if ( !SetAt( m_iArrayItems - 1, pPtr ) ) + { + m_iArrayItems--; + return FALSE; + } + + return TRUE; + +} + +//adds new sub array block +BOOL CArray::AddNewBlock() +{ + SubArray* pCurr = m_pFirstBlock; + SubArray* pNext = m_pFirstBlock; + + //find end + while ( pNext ) + { + pCurr = pNext; + pNext = pCurr->pNext; + } + + if ( !( pNext = new SubArray ) ) + return FALSE; + + memset( pNext, 0, sizeof( SubArray) ); + + if ( !m_pFirstBlock ) + m_pFirstBlock = pNext; + else + pCurr->pNext = pNext; + + m_iAllocatedBlocks++; + + return TRUE; +} + + diff --git a/jindroush/chkbas/carray.h b/jindroush/chkbas/carray.h new file mode 100644 index 0000000..9779cad --- /dev/null +++ b/jindroush/chkbas/carray.h @@ -0,0 +1,49 @@ +// 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 "jintypes.h" + +#ifndef __CARRAY_H__ +#define __CARRAY_H__ + +#define CARRAY_SUB_SIZE 16 + +typedef struct sa +{ + struct sa* pPrev; + struct sa* pNext; + void* array[ CARRAY_SUB_SIZE ]; + +} SubArray; + +class CArray +{ +public: + CArray(); + ~CArray(); + void* GetAt( int ); + BOOL SetAt( int, void* ); + int GetSize() { return m_iArrayItems; }; + BOOL Add( void* ); + BOOL DeleteLast(); + void Destroy(); +private: + BOOL AddNewBlock(); + int m_iAllocatedBlocks; + int m_iArrayItems; + SubArray * m_pFirstBlock; +}; + +#endif diff --git a/jindroush/chkbas/chkbas.cpp b/jindroush/chkbas/chkbas.cpp new file mode 100644 index 0000000..a1ad505 --- /dev/null +++ b/jindroush/chkbas/chkbas.cpp @@ -0,0 +1,1009 @@ +// 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 "jintypes.h" +#include <unistd.h> +#include <fcntl.h> +#include <math.h> +#include <string.h> +#include "carray.h" +#include "cfile.h" + +#include "pub.def" + +#include "basic.h" +#include "basic_tb.h" +#include "basic_xl.h" +#include "basic_xe.h" + +extern void strlwr(char *); + +typedef enum +{ + BASIC = 0, //standard basic + BASIC_TB = 1, //Turbo Basic + BASIC_XL = 2, //OSS Basic XL + BASIC_XE = 3, //OSS Basic XE + BASIC_XEX = 4 //OSS Basic XE in extended mode +} BASIC_TYPE; + +typedef struct +{ + char** ppCommands; //array of commands + char** ppOperands; //array of operands + + int iCmdNum; //number of commands + int iOpNum; //number of operands + int iOpFirst; //first operand +} LANGDESC; + +LANGDESC langtbl[] = +{ + { aCmdsBasic, aOpsBasic, BASIC_CMD_NUM, BASIC_OPS_NUM, 0x0E }, + { aCmdsTBasic, aOpsTBasic, TBASIC_CMD_NUM, TBASIC_OPS_NUM, 0x0D }, + { aCmdsBasicXl, aOpsBasicXl, BASICXL_CMD_NUM, BASICXL_OPS_NUM, 0x0D }, + { aCmdsBasicXe, aOpsBasicXe, BASICXE_CMD_NUM, BASICXE_OPS_NUM, 0x0D }, + { aCmdsBasicXe, aOpsBasicXe, BASICXE_CMD_NUM, BASICXE_OPS_NUM, 0x0D }, +}; + +#define OP_NHCONST 0x0D +#define OP_NCONST 0x0E +#define OP_SCONST 0x0F +#define OP_EOL 0x16 + +#define VART_SCALAR 0x00 + +#define VART_ARRAYU 0x40 +#define VART_ARRAY 0x41 + +#define VART_STRINGU 0x80 +#define VART_STRING 0x81 + +#define VART_STRINGAU 0x90 +#define VART_STRINGA 0x91 + +#define VART_PROC 0xC1 +#define VART_LABEL 0xC2 + +#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" \ + " Thanks to Russ Gilbert for his SALVAGE programs.\n\n" + +#define USAGE HEADER "Usage: " PRG_NAME " " PRG_USAGE + +BOOL GenCode( CFile* pcf, DWORD dwStart, DWORD dwEnd ); +BOOL GenLineCode( CFile* pcf, DWORD dwEnd ); +BOOL GenCmdCode( CFile* pcf, DWORD dwLineStart, DWORD dwLineEnd ); +BOOL GenOpsCode( CFile* pcf, DWORD dwTokEnd ); +double ReadAtariBCD( CFile* pcf ); + +BOOL Vars_Load( CFile* pcf, WORD wVNT, WORD wVNTL, WORD wVVT, WORD NV ); +void Var_Get( char* szRet, int iNum ); +void Vars_Destroy(); + +FILE* g_fout = NULL; +CArray g_aVariables; //array of variables + +BOOL g_bVerbose = FALSE; //verbose output +BOOL g_bAtariOut = FALSE; //atari output +BOOL g_bExtOut = TRUE; //extended output +BOOL g_bHasErrors = FALSE; //decode error flag +BOOL g_bNoInverse = FALSE; //don't emit inverse +BASIC_TYPE g_Type = BASIC; //basic type. Default is Atari Basic + +char** g_aBasicCmds; //array of commands +char** g_aBasicOps; //array of operands +int g_iCmdNum; //number of commands +int g_iOpsNum; //number of operands +int g_iOpFirst; //first operand + +#include "switches.cpp" + +int main( int argc, char* argv[] ) +{ + setbuf( stdout, NULL ); + setbuf( stderr, NULL ); + + if ( !SWITCHES_Init( &argc, argv ) ) + return 1; + + if(strstr(argv[0], "listbas")) + g_bExtOut = FALSE; + + if ( argc < 2 ) + { + SWFN_HELP( USAGE ); + return 1; + } + + if ( g_bExtOut ) + fprintf( stderr, SHEADER "\n" ); + else + fprintf( stderr, HEADER ); + + char* szInfile = argv[ 1 ]; + char* szOutfile = NULL; + + if ( argc > 2 ) + szOutfile = argv[ 2 ]; + + CFile cf; + + if ( !cf.Open( szInfile ) ) + { + fprintf( stderr, "Can't open input file '%s'\n", szInfile ); + return 1; + } + + if ( szOutfile ) + { + if( g_bAtariOut ) + g_fout = fopen( szOutfile, "wb" ); //opening as binary because of + //atascii + else + g_fout = fopen( szOutfile, "wt" ); + } + + if ( !g_fout ) + g_fout = stdout; + + //Don't emit additional info if you are in Atari mode + if ( g_bAtariOut ) + g_bExtOut = FALSE; + + if ( g_bExtOut ) + { + fprintf( g_fout, HEADER ); + fprintf( g_fout, "Input file: %s\n\n", szInfile ); + } + + //initialize globals depending on language set + g_aBasicCmds = langtbl[ g_Type ].ppCommands; + g_aBasicOps = langtbl[ g_Type ].ppOperands; + g_iCmdNum = langtbl[ g_Type ].iCmdNum; + g_iOpsNum = langtbl[ g_Type ].iOpNum; + g_iOpFirst = langtbl[ g_Type ].iOpFirst; + + DWORD dwFileLen = cf.GetLength(); + + //read head + WORD wLOMEM = cf.readLEw(); + WORD wVNT = cf.readLEw(); + WORD wVNTE = cf.readLEw(); + WORD wVVT = cf.readLEw(); + WORD wSTMTAB = cf.readLEw(); + WORD wSTMCUR = cf.readLEw(); + WORD wSTARP = cf.readLEw(); + + if( ( wLOMEM == 0x00DD ) && ( g_Type == BASIC_XE ) ) + { + //extended mode of Basic XE + wLOMEM = 0; + g_Type = BASIC_XEX; + } + + WORD wCOR = wVNT - wLOMEM - 0x0E; + + wVNT -= wCOR; + wVNTE -= wCOR; + wVVT -= wCOR; + wSTMTAB -= wCOR; + wSTMCUR -= wCOR; + wSTARP -= wCOR; + + WORD wVNTL = wVNTE - wVNT + 1; + WORD wVVTE = wSTMTAB - 1; + WORD wVVTL = wVVTE - wVVT + 1; + WORD NV = wVVTL / 8; + + WORD wCodeLen = wSTMCUR - wSTMTAB; + WORD wCodeLenCur = wSTARP - wSTMCUR; + + long lLenDiff = (long)dwFileLen - (long)wSTARP; + + if ( g_bExtOut ) + { + fprintf( g_fout, "Constants & pointers:\n" ); + fprintf( g_fout, "Start of Name Table (VNT) : %04X\n", wVNT ); + fprintf( g_fout, "End of Name Table (VNTE) : %04X\n", wVNTE ); + fprintf( g_fout, "Lenght of Name Table (VNTL) : %04X\n", wVNTL ); + + fprintf( g_fout, "Start of Variable Table (VVT) : %04X\n", wVVT ); + fprintf( g_fout, "End of Variable Table (VVTE) : %04X\n", wVVTE ); + fprintf( g_fout, "Length of Variable Table (VVTL) : %04X\n", wVVTL ); + + fprintf( g_fout, "Number of Variables (NV) : %04X\n", NV ); + + fprintf( g_fout, "Start of Code (STMTAB): %04X\n", wSTMTAB ); + fprintf( g_fout, "Length of Code : %04X\n", wCodeLen ); + fprintf( g_fout, "Current command (STMCUR): %04X\n", wSTMCUR ); + fprintf( g_fout, "Length of current command : %04X\n", wCodeLenCur ); + fprintf( g_fout, "First byte after program (STARP) : %04X\n", wSTARP ); + + if( g_Type != BASIC_XEX ) + { + fprintf( g_fout, "Length of file : %04lX\n", dwFileLen ); + fprintf( g_fout, "File len difference : %08lX\n", (DWORD)lLenDiff ); + } + fputc( '\n', g_fout ); + } + + //records must be 8 bytes long + if ( NV * 8 != wVVTL ) + { + fprintf( stderr, "Variable Table Length Mismatch!\n" ); + return 1; + } + + if ( lLenDiff <0 ) + { + fprintf( stderr, "File Length Incorrect!\n" ); + return 1; + } + + if ( !Vars_Load( &cf, wVNT, wVNTL, wVVT, NV ) ) + return 1; + + if ( g_bExtOut ) + { + fprintf( g_fout, "Main code starts here:\n" ); + } + + GenCode( &cf, wSTMTAB, wSTMCUR ); + + if ( g_bExtOut ) + { + fputc( '\n', g_fout ); + + fprintf( g_fout, "Immediate code starts here:\n" ); + GenCode( &cf, wSTMCUR, wSTARP ); + fputc( '\n', g_fout ); + } + else + { + cf.Seek( wSTARP, SEEK_SET ); + } + + //if extended mode of Basic XE + if( g_Type == BASIC_XEX ) + { + //code is stored in 4 extended memory banks + for( int iBank = 0; iBank < 4; iBank++ ) + { + //read the end of code in bank + WORD wLen = cf.readLEw(); + + //because bank starts at 0x4000, the value must be GE + if( wLen < 0x4000 ) + { + fprintf( stderr, "Bank end too low! %04X\n", wLen ); + g_bHasErrors = TRUE; + break; + } + + wLen -= 0x4000; + + if ( g_bExtOut ) + { + fprintf( g_fout, "\nBank %d code:\n", iBank ); + } + + if ( wLen ) + { + //if we have anything to process, we do so + long lNow = cf.Tell(); + GenCode( &cf, lNow, lNow + wLen ); + } + else + { + //else we skip one byte (error in BXE?) in empty bank + cf.skip( 1 ); + } + + if ( g_bExtOut ) + { + fputc( '\n', g_fout ); + } + } + } + + cf.Close(); + + if ( g_bHasErrors ) + fprintf( stderr, "File may contain some errors!\n" ); + + if ( g_fout != stdout ) + fclose( g_fout ); + + fprintf( stderr, "Done!\n" ); + + Vars_Destroy(); + + return 0; +} + +BOOL GenCode( CFile* pcf, DWORD dwStart, DWORD dwEnd ) +{ + pcf->Seek( dwStart, SEEK_SET ); + + //going thru the bank + while( pcf->Tell() < (long)dwEnd ) + { + //generating line + if ( !GenLineCode( pcf, dwEnd ) ) + { + g_bHasErrors = TRUE; + return FALSE; + } + + //output the correct line terminator + if ( g_bAtariOut ) + fputc( 0x9B, g_fout ); + else + fputc( '\n', g_fout ); + } + + return TRUE; +} + +BOOL GenLineCode( CFile* pcf, DWORD dwEnd ) +{ + DWORD dwLineStart = pcf->Tell(); + + //some debug info + if ( g_bVerbose ) + fprintf( g_fout, "[O:%08lX]", dwLineStart ); + + //line number + WORD wLineNum = pcf->readLEw(); + + //end of line + BYTE btLEnd = pcf->readb(); + DWORD dwLineEnd = dwLineStart + btLEnd; + + //don't print immediate line in BASIC XE extended (already filtered in + // other versions + + if( g_Type == BASIC_XEX ) + { + if( wLineNum == 0x8000 ) + { + pcf->Seek( dwLineEnd, SEEK_SET ); + return TRUE; + } + } + + fprintf( g_fout, "%d ", wLineNum ); + + if ( g_bVerbose ) + { + fprintf( g_fout, "[S:%04lX E:%04lX]", dwLineStart, dwLineEnd ); + } + + //if the line goes the end of buffer, croak + if ( ( dwLineStart > dwEnd ) || ( dwLineEnd > dwEnd ) ) + { + fprintf( g_fout, "***Line size mismatch. (%04lX-%04lX)\n", dwLineEnd, dwEnd ); + return FALSE; + } + + //and generate the output for commands + while( pcf->Tell() < (long)dwLineEnd ) + { + if ( !GenCmdCode( pcf, dwLineStart, dwLineEnd ) ) + return FALSE; + } + + return TRUE; +} + +BOOL GenCmdCode( CFile* pcf, DWORD dwLineStart, DWORD dwLineEnd ) +{ + //end of token + BYTE btTEnd = pcf->readb(); + + DWORD dwTokStart = pcf->Tell(); + DWORD dwTokEnd = dwLineStart + btTEnd; + + if ( g_bVerbose ) + { + fprintf( g_fout, "[C:%04lX E:%04lX]", dwTokStart, dwTokEnd ); + } + + //could this ever happen? + if ( dwTokStart >= dwTokEnd ) + { + fprintf( g_fout, "***Command size problem!\n" ); + return FALSE; + } + + //if token goes behind the eol + if ( dwTokEnd > dwLineEnd ) + { + fprintf( g_fout, "***Command size mismatch. (%04lX-%04lX)\n", dwTokEnd, dwLineEnd ); + return FALSE; + } + + //which token + BYTE btTok = pcf->readb(); + + //token buffer + char szTok[ 50 ]; + + //if known token + if ( btTok < g_iCmdNum ) + { + //sub table for BXL extended commands + if( ( btTok == BXL_EXTEND ) && ( g_Type == BASIC_XL ) ) + { + BYTE btTok = pcf->readb(); + + switch( btTok ) + { + case 0x10: + strcpy( szTok, "LOCAL" ); + break; + + case 0x11: + strcpy( szTok, "EXIT" ); + break; + + case 0x12: + strcpy( szTok, "PROCEDURE" ); + break; + + case 0x13: + strcpy( szTok, "CALL" ); + break; + + case 0x14: + strcpy( szTok, "SORTUP" ); + break; + + case 0x15: + strcpy( szTok, "SORTDOWN" ); + break; + + default: + sprintf( szTok, "EXTEND?%02X", btTok ); + g_bHasErrors = TRUE; + break; + + } + } + else + strcpy( szTok, g_aBasicCmds[ btTok ] ); + } + else + { + sprintf( szTok, "COM%02X", btTok ); + fprintf( stderr, "Unknown command %02X!!!\n", btTok ); + g_bHasErrors = TRUE; + } + + if ( *szTok ) + { + //lower case for some dialects + if( ( g_Type == BASIC_XL ) || ( g_Type == BASIC_XE ) || ( g_Type == BASIC_XEX ) ) + { + strlwr( szTok + 1 ); + } + + fprintf( g_fout, "%s ", szTok ); + } + + //special handling for REM & DATA (first two statements) + if ( btTok < 2 ) + { + BYTE c; + + int iSecure = 0x100; + + for( ;; ) + { + c = pcf->readb(); + + if ( c == 0x9B ) + break; + + if ( g_bNoInverse ) + c &= 0x7F; + + fputc( c, g_fout ); + + iSecure--; + + if( !iSecure ) + { + fprintf( stderr, "Runaway in Rem/Data code!\n" ); + return FALSE; + } + } + + return TRUE; + + } + + //generate operands for remain of command + while( pcf->Tell() < (long)dwTokEnd ) + { + if ( !GenOpsCode( pcf, dwTokEnd ) ) + return FALSE; + } + + return TRUE; +} + +BOOL GenOpsCode( CFile* pcf, DWORD dwTokEnd ) +{ + //get operand + BYTE btTok = pcf->readb(); + + if ( btTok == OP_EOL ) + { + //new line + return TRUE; + } + + if ( btTok == OP_NCONST ) + { + //bcd num + + fprintf( g_fout, "%.10g", ReadAtariBCD( pcf ) ); + + return TRUE; + } + + if ( btTok == OP_NHCONST ) + { + if ( g_Type == BASIC_TB ) + { + //hex num TBASIC + fprintf( g_fout, "$%X", (unsigned short)ReadAtariBCD( pcf ) ); + return TRUE; + } + + if( ( g_Type == BASIC_XL ) || ( g_Type == BASIC_XE ) || ( g_Type == BASIC_XEX ) ) + { + //hex num BASIC XL + WORD wNum = (unsigned short)ReadAtariBCD( pcf ); + + if( wNum > 0xFF ) + fprintf( g_fout, "$%04X", wNum ); + else + fprintf( g_fout, "$%02X", wNum ); + + return TRUE; + } + } + + if ( btTok == OP_SCONST ) + { + //string + BYTE c; + + BYTE btLen = pcf->readb(); + + fprintf( g_fout, "\"" ); + while( btLen-- ) + { + c = pcf->readb(); + + if ( c == 0x9B ) + { + break; + } + + //is this for TBASIC only? + if ( c == '\"' ) + { + fprintf( g_fout, "\"\"" ); + } + else + fputc( c, g_fout ); + + } + fprintf( g_fout, "\"" ); + return TRUE; + } + + //and now for variables + if ( btTok & 0x80 ) + { + char szPom[ 255 ]; + + Var_Get( szPom, btTok & 0x7F ); + + if( ( g_Type == BASIC_XL ) || ( g_Type == BASIC_XE ) || ( g_Type == BASIC_XEX ) ) + { + strlwr( szPom + 1 ); + } + + fprintf( g_fout, szPom ); + + return TRUE; + } + + //func or op + if ( ( btTok < g_iOpFirst ) || ( btTok - g_iOpFirst + 1 > (BYTE)g_iOpsNum ) ) + { + fprintf( g_fout, "UNKOP%02X", btTok ); + fprintf( stderr, "Unknown operand %02X!!!\n", btTok ); + g_bHasErrors = TRUE; + } + else + { + char szPom[ 100 ]; + strcpy( szPom, g_aBasicOps[ btTok - g_iOpFirst ] ); + + if( ( g_Type == BASIC_XL ) || ( g_Type == BASIC_XE ) || ( g_Type == BASIC_XEX ) ) + { + strlwr( szPom + 1 ); + } + + fprintf( g_fout, "%s", szPom ); + } + + return TRUE; + +} + +//code for reading Atari BCD format +double ReadAtariBCD( CFile* pcf ) +{ + double dRes = 0; + + //reads exponent + BYTE btExp = pcf->readb(); + + int iExp; + + if ( !btExp ) + { + //if Exp==0, we're skipping it! (silently!) + iExp = 0; + pcf->skip( 5 ); + } + else + { + //compute exponent + iExp = ( btExp - 68 ) * 2; + + int i = 5; + + //read 5 pairs of numbers and combine 'em + while ( i-- ) + { + BYTE btPom = pcf->readb(); + + BYTE btNum = ( btPom >> 4 ) * 10 + ( btPom &0xf ); + + dRes *= 100; + dRes += btNum; + } + + } + + dRes *= pow( 10, iExp ); + + return dRes; +} + +BOOL Vars_Load( CFile* pcf, WORD wVNT, WORD wVNTL, WORD wVVT, WORD NV ) +{ + char szVarTemp[ 256 ]; + char szVarGen[ 256 ]; + + char* pStr = NULL; + + BOOL bTog = FALSE; + + pcf->Seek( wVNT, SEEK_SET ); + + for( int i = 0; i < wVNTL; i++ ) + { + if ( !pStr ) + pStr = szVarTemp; + + char c = pcf->readb(); + + if ( c & 0x80 ) + { + c &= 0x7F; + bTog = TRUE; + } + + *( pStr++ ) = c; + *pStr = '\0'; + + //this is for correcting the runaway + if ( pStr - szVarTemp > 254 ) + { + *szVarTemp = '\0'; + bTog = TRUE; + } + + if ( bTog ) + { + int iVar = g_aVariables.GetSize(); + + sprintf( szVarGen, "VAR%d", iVar ); + + pStr = szVarTemp; + + int iLength = strlen( szVarTemp ); + + if ( iLength ) + { + for( int i = 0; i < iLength; i++ ) + { + if ( !isprint( *( pStr++ ) ) ) + { + strcpy( szVarTemp, szVarGen ); + break; + } + } + + if ( iVar ) + { + for( int i = 0; i < iVar; i++ ) + { + if( !strcmp( (char*)g_aVariables.GetAt( i ), szVarTemp ) ) + { + fprintf( g_fout, "Dupped varname: %s\n", szVarTemp ); + strcpy( szVarTemp, szVarGen ); + break; + } + } + } + + } + else + { + strcpy( szVarTemp, szVarGen ); + } + + pStr = new char [ strlen( szVarTemp ) + 1 ]; + + if ( pStr ) + { + strcpy( pStr, szVarTemp ); + g_aVariables.Add( pStr ); + } + else + { + printf( "Not enough memory!\n" ); + return FALSE; + } + + bTog = FALSE; + pStr = NULL; + } + } + + if ( g_bExtOut ) + { + fprintf( g_fout, "Variable table:\n" ); + } + + pcf->Seek( wVVT, SEEK_SET ); + + for( int i = 0 ; i < NV; i++ ) + { + BYTE btType = pcf->readb(); + BYTE btNumber = pcf->readb(); + + char* szType; + + char szText[ 50 ]; + + switch( btType ) + { + case VART_SCALAR: + { + szType = "SCALAR "; + sprintf( szText, "%.10g", ReadAtariBCD( pcf ) ); + break; + } + + case VART_ARRAYU: + { + szType = "ARRAYu "; + char* szP = szText; + szP += sprintf( szP, "SPoff: %04X ", pcf->readLEw() ); + szP += sprintf( szP, "Dim1: %d ", pcf->readLEw() ); + szP += sprintf( szP, "Dim2: %d ", pcf->readLEw() ); + break; + } + + case VART_ARRAY: + { + szType = "ARRAY "; + char* szP = szText; + szP += sprintf( szP, "SPoff: %04X ", pcf->readLEw() ); + szP += sprintf( szP, "Dim1: %d ", pcf->readLEw() ); + szP += sprintf( szP, "Dim2: %d ", pcf->readLEw() ); + break; + } + + case VART_STRINGAU: + { + //BASIC_XL / XE + szType = "STRINGAu"; + char* szP = szText; + szP += sprintf( szP, "SPoff: %04X ", pcf->readLEw() ); + szP += sprintf( szP, "Dim1: %d ", pcf->readLEw() ); + szP += sprintf( szP, "Dim2: %d ", pcf->readLEw() ); + break; + } + + case VART_STRINGA: + { + //BASIC_XL / XE + szType = "STRINGA "; + char* szP = szText; + szP += sprintf( szP, "SPoff: %04X ", pcf->readLEw() ); + szP += sprintf( szP, "Dim1: %d ", pcf->readLEw() ); + szP += sprintf( szP, "Dim2: %d ", pcf->readLEw() ); + break; + } + + case VART_STRINGU: + { + szType = "STRINGu "; + char* szP = szText; + szP += sprintf( szP, "SPoff: %04X ", pcf->readLEw() ); + szP += sprintf( szP, "Len: %d ", pcf->readLEw() ); + szP += sprintf( szP, "Dim: %d ", pcf->readLEw() ); + break; + } + + case VART_STRING: + { + szType = "STRING "; + char* szP = szText; + szP += sprintf( szP, "SPoff: %04X ", pcf->readLEw() ); + szP += sprintf( szP, "Len: %d ", pcf->readLEw() ); + szP += sprintf( szP, "Dim: %d ", pcf->readLEw() ); + break; + } + + case VART_PROC: + { + //TBASIC + szType = "PROC "; + char* szP = szText; + for( int i = 0 ; i < 6; i++ ) + { + szP += sprintf( szP, "%02X ", pcf->readb() ); + } + break; + } + + case VART_LABEL: + { + //TBASIC + szType = "LABEL "; + char* szP = szText; + for( int i = 0 ; i < 6; i++ ) + { + szP += sprintf( szP, "%02X ", pcf->readb() ); + } + break; + } + + default: + { + szType = "UNKNOWN "; + char* szP = szText; + for( int i = 0 ; i < 6; i++ ) + { + szP += sprintf( szP, "%02X ", pcf->readb() ); + } + g_bHasErrors = TRUE; + } + } + + char szName[ 255 ]; + Var_Get( szName, btNumber ); + + char cLastChar = szName[ strlen( szName ) - 1 ]; + + switch( btType ) + { + case VART_STRING: + case VART_STRINGU: + { + if ( cLastChar != '$' ) + { + strcat( szName, "$" ); + char* szStr = new char [ strlen( szName ) + 1 ]; + strcpy( szStr, szName ); + char* szOld = (char*) g_aVariables.GetAt( btNumber ); + + if ( szOld ) + delete [] szOld; + + g_aVariables.SetAt( btNumber, szStr ); + + } + + break; + } + + case VART_ARRAY: + case VART_ARRAYU: + { + if ( cLastChar == '(' ) + { + szName[ strlen( szName ) - 1 ] = '\0'; + char* szStr = new char [ strlen( szName ) + 1 ]; + strcpy( szStr, szName ); + char* szOld = (char*) g_aVariables.GetAt( btNumber ); + + if ( szOld ) + delete [] szOld; + + g_aVariables.SetAt( btNumber, szStr ); + + } + + break; + } + + } + + if ( g_bExtOut ) + { + fprintf( g_fout, "%04X %s (%02X) %02X: %s %s\n", + i+1, + szType, + btType, + btNumber, + szText, + szName ); + } + + } + + if ( g_bExtOut ) + fputc( '\n', g_fout ); + + return TRUE; +} + +void Var_Get( char* szRet, int iNum ) +{ + char* szVar = (char*) g_aVariables.GetAt( iNum ); + + if ( szVar ) + strcpy( szRet, szVar ); + else + sprintf( szRet, "VAR%d", iNum ); +} + +void Vars_Destroy() +{ + for( int i = 0; i < g_aVariables.GetSize(); i++ ) + { + if ( g_aVariables.GetAt( i ) ) + delete [] ( char* ) g_aVariables.GetAt( i ); + } +} + diff --git a/jindroush/chkbas/listbas b/jindroush/chkbas/listbas new file mode 120000 index 0000000..8b02192 --- /dev/null +++ b/jindroush/chkbas/listbas @@ -0,0 +1 @@ +chkbas
\ No newline at end of file diff --git a/jindroush/chkbas/pub.def b/jindroush/chkbas/pub.def new file mode 100644 index 0000000..790db8c --- /dev/null +++ b/jindroush/chkbas/pub.def @@ -0,0 +1,31 @@ +// 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. +// + +#define PRG_NAME "chkbas" +#define PRG_VERSION "1.10" +#define PRG_COPYRIGHT "1999-2001" +#define PRG_UNDERGPL "1" +#define PRG_AUTHOR "Jindrich Kubec <kubecj@asw.cz>" + +#define PRG_URL "http://www.asw.cz/~kubecj" + +#define PRG_DESC "Atari Basic/Turbo Basic/Basic XL/Basic XE decompiler." +#define PRG_USAGE "[options] sourcefile [lstfile]" + +#define PRG_ARCH "PC" +#define PRG_TOOLS "PERL" + +#define PRG_SRCS "!GENERATED!" +#define PRG_BINS "rel/chkbas.exe" diff --git a/jindroush/chkbas/readme.txt b/jindroush/chkbas/readme.txt new file mode 100644 index 0000000..a9a1b86 --- /dev/null +++ b/jindroush/chkbas/readme.txt @@ -0,0 +1,87 @@ +ChkBas v1.10 (c) 1999-2001 Jindrich Kubec <kubecj@asw.cz> +Latest version can be found at http://www.asw.cz/~kubecj + +This program is provided 'as is', no warranty will be taken +for any damage caused by it or by any use of it. + +The whole package is placed under the GNU Public License, for further +information on redistribution see the included file "GPL.TXT". + + +Description: +------------ +Atari Basic/Turbo Basic/Basic XL/Basic XE decompiler. + + + +Usage: +------ +ChkBas [options] sourcefile [lstfile] + +sourcefile is Atari basic file. + +lstfile is output text file + +-atari - exports source only in Atari format +-short - exports source only in PC format +-verbose - prints verbose information +-tbs - decodes Turbo Basic file +-bxl - decodes Basic XL file +-bxe - decodes Basic XE file + +The export is by default more verbose and in PC format. + + +History: +-------- +Date, Author, Version +4/5/1999, kubecj, 0.90 +First version + +4/20/1999, kubecj, 1.00 +First public version + +4/20/1999, kubecj, 1.01 +BCD error bugfix + +7/7/1999, kubecj, 1.02 +Atari output file bugfix (it did break lines on 0x0A char) + +9/5/1999, kubecj, 1.03 +'Hacked' variable table bugfix (overflow when filled with chars under 0x80) + +10/10/1999, kubecj, 1.04 +Changed switches processing. + +7/5/2001, kubecj, 1.05 +Added Basic XL. + +7/6/2001, kubecj, 1.06 +Added Basic XE. + +7/7/2001, kubecj, 1.10 +Added Basic XE extended mode. Code cleanup. + + +To Do: +------ +Add other basic dialects? + + +Known Bugs: +----------- +None. + + +Compiling Tools: +---------------- +For scripts: Perl. +URL: http://www.perl.com + +For PC executables: DJGPP. +Sources were written/tested on GCC/Intel only. There should be only +minor problems to port it to different architectures/environments. +Makefile should need only minor changes. +URL: http://www.delorie.com + + diff --git a/jindroush/chkbas/strlwr.cpp b/jindroush/chkbas/strlwr.cpp new file mode 100644 index 0000000..10c3f84 --- /dev/null +++ b/jindroush/chkbas/strlwr.cpp @@ -0,0 +1,11 @@ +#include <ctype.h> + +// 20070524 bkw: Linux and POSIX lack the DOS/Windows strlwr() function, +// so here's an implementation. + +void strlwr(char *s) { + while(*s) { + *s = tolower(*s); + s++; + } +} diff --git a/jindroush/chkbas/switches.def b/jindroush/chkbas/switches.def new file mode 100644 index 0000000..bb09a46 --- /dev/null +++ b/jindroush/chkbas/switches.def @@ -0,0 +1,34 @@ +verbose, v +verbose info +=g_bVerbose = TRUE; += + +atari +Atari output file (only lst is created) +=g_bAtariOut = TRUE; += + +short +PC - lst only output (full output otherwise) +=g_bExtOut = FALSE; += + +noinverse +no inverse characters in DATA or REMs +=g_bNoInverse = TRUE; += + +bxl +Basic XL +=g_Type = BASIC_XL; += + +bxe +Basic XE +=g_Type = BASIC_XE; += + +tbs +Turbo Basic +=g_Type = BASIC_TB; += |