diff --git a/.gitignore b/.gitignore index 974fee9..9003691 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,8 @@ # cp437 tool cp437/cp437 cp437/cp437.exe -*.cp437 +cp437.tmp +*_cp437 # Watcom C *.err diff --git a/cp437/README.md b/cp437/README.md index 52c912e..f60da94 100644 --- a/cp437/README.md +++ b/cp437/README.md @@ -7,6 +7,7 @@ Usage ``` cp437 infile [infile...] - Converts UTF-8 input file(s) to CP437 output file(s) with .cp437 appended. + The new file names are also printed to stdout. ``` Building @@ -14,4 +15,4 @@ Building This tool is automatically built as needed by the build scripts for other tools. Alternatively: * **Windows:** Run `build.bat` from an OpenWatcom "Build Environment" command prompt. -* **Linux:** Run `./build.sh` with OpenWatcom tools present on `$PATH`. +* **Linux:** Run `./build.sh` with OpenWatcom tools present in `$PATH`. diff --git a/cp437/cp437.c b/cp437/cp437.c index ce9ab7e..aa2954e 100644 --- a/cp437/cp437.c +++ b/cp437/cp437.c @@ -48,8 +48,9 @@ main(int argc, char **argv) char *buf; FILE *fin, *fout; - /* Disable stdout buffering. */ + /* Disable stdout/stderr buffering. */ setbuf(stdout, NULL); + setbuf(stderr, NULL); /* Print usage if no input files were specified. */ if (argc < 2) { @@ -57,6 +58,7 @@ main(int argc, char **argv) printf("\n"); printf("cp437 infile [infile...]\n"); printf("- Converts UTF-8 input file(s) to CP437 output file(s) with .cp437 appended.\n"); + printf(" The new file names are also printed to stdout.\n"); return 1; } @@ -66,23 +68,23 @@ main(int argc, char **argv) /* Open input file. */ fin = fopen(argv[i], "rb"); if (!fin) { - printf("Could not open input file \"%s\"\n", argv[i]); + fprintf(stderr, "Could not open input file \"%s\"\n", argv[i]); continue; } /* Generate output file name. */ buf = malloc(strlen(argv[i]) + 7); - sprintf(buf, "%s.cp437", argv[i]); + sprintf(buf, "%s_cp437", argv[i]); /* Open output file. */ fout = fopen(buf, "wb"); if (!fout) { fclose(fin); - printf("Could not open output file \"%s\"\n", buf); + fprintf(stderr, "Could not open output file \"%s\"\n", buf); continue; } - printf("Processing \"%s\"\n", argv[i]); + printf("%s\n", buf); /* Perform the conversion. */ while (!feof(fin)) { diff --git a/lib/build_watcom_dos.bat b/lib/build_watcom_dos.bat index 7204ed3..0b6e5dd 100644 --- a/lib/build_watcom_dos.bat +++ b/lib/build_watcom_dos.bat @@ -33,8 +33,8 @@ if not exist ..\cp437\cp437.exe ( ) :: Convert source file to CP437. -echo *** Converting %1 to CP437... -..\cp437\cp437.exe %1 +echo *** Converting source to CP437... +..\cp437\cp437.exe %* > cp437.tmp if errorlevel 1 ( echo *** Conversion failed. exit /b 2 @@ -48,7 +48,9 @@ for %%i in (A B C D E F G H I J K L M N O P Q R S T U V W X Y Z) do set "destfil :: Call compiler. echo *** Building... -wcl -bcl=dos -fo="!destfile!" "%1.cp437" +set srcfiles= +for /f "delims=" %%i in (cp437.tmp) do set srcfiles=!srcfiles! %%i +wcl -bcl=dos -i=..\lib -fe="!destfile!" %srcfiles% :: Check for success. if errorlevel 1 ( diff --git a/lib/build_watcom_dos.sh b/lib/build_watcom_dos.sh index 4daa0ab..b2391d4 100644 --- a/lib/build_watcom_dos.sh +++ b/lib/build_watcom_dos.sh @@ -35,9 +35,9 @@ then popd fi -# Convert source file to CP437. -echo '***' Converting $1 to CP437... -if ! ../cp437/cp437 "$1" +# Convert source files to CP437. +echo '***' Converting source to CP437... +if ! ../cp437/cp437 "$@" > cp437.tmp then echo '***' Conversion failed. exit 2 @@ -47,7 +47,7 @@ fi destfile=$(basename "$1" .c | tr [:lower:] [:upper:]).EXE # Call compiler and check for success. -if wcl -bcl=dos -fo="$destfile" "$1".cp437 +if wcl -bcl=dos -fo="$destfile" $(cat cp437.tmp) then echo '***' Build successful. else diff --git a/lib/build_watcom_host.bat b/lib/build_watcom_host.bat index f66fbc3..05f67c7 100644 --- a/lib/build_watcom_host.bat +++ b/lib/build_watcom_host.bat @@ -29,7 +29,7 @@ set destfile=%srcfile:~0,-2%.exe :: Call compiler. echo *** Building... -wcl386 -bcl=nt -fo="%destfile%" "%1" +wcl386 -bcl=nt -fo="%destfile%" %* :: Check for success. if errorlevel 1 ( diff --git a/lib/build_watcom_host.sh b/lib/build_watcom_host.sh index 4933f7f..f47a586 100644 --- a/lib/build_watcom_host.sh +++ b/lib/build_watcom_host.sh @@ -26,7 +26,7 @@ fi destfile=$(basename "$1" .c) # Call compiler and check for success. -if wcl386 -bcl=linux -fo="$destfile" "$1" +if wcl386 -bcl=linux -fo="$destfile" "$@" then echo '***' Build successful. chmod +x "$destfile" diff --git a/lib/wlib.c b/lib/wlib.c new file mode 100644 index 0000000..9b69dbd --- /dev/null +++ b/lib/wlib.c @@ -0,0 +1,33 @@ +/* + * 86Box A hypervisor and IBM PC system emulator that specializes in + * running old operating systems and software designed for IBM + * PC systems and compatibles from 1981 through fairly recent + * system designs based on the PCI bus. + * + * This file is part of the 86Box Probing Tools distribution. + * + * Common functions for Watcom C-based tools. + * + * + * + * Authors: RichardG, + * + * Copyright 2021 RichardG. + * + */ +#include +#include "wlib.h" + + +uint32_t +pci_cf8(uint8_t bus, uint8_t dev, uint8_t func, uint8_t reg) +{ + /* Generate a PCI port CF8h dword. */ + multi_t ret; + ret.u8[3] = 0x80; + ret.u8[2] = bus; + ret.u8[1] = dev << 3; + ret.u8[1] |= func & 7; + ret.u8[0] = reg & 0xfc; + return ret.u32; +} diff --git a/lib/wlib.h b/lib/wlib.h new file mode 100644 index 0000000..df3bd04 --- /dev/null +++ b/lib/wlib.h @@ -0,0 +1,70 @@ +/* + * 86Box A hypervisor and IBM PC system emulator that specializes in + * running old operating systems and software designed for IBM + * PC systems and compatibles from 1981 through fairly recent + * system designs based on the PCI bus. + * + * This file is part of the 86Box Probing Tools distribution. + * + * Definitions for common functions for Watcom C-based tools. + * + * + * + * Authors: RichardG, + * + * Copyright 2021 RichardG. + * + */ +#ifndef WLIB_H +# define WLIB_H +#include + +#pragma pack(push, 0) +/* Convenience type for breaking a dword value down into words and bytes. */ +typedef union { + uint8_t u8[4]; + uint16_t u16[2]; + uint32_t u32; +} multi_t; +#pragma pack(pop) + + +/* Port I/O functions. */ +uint8_t inb(uint16_t port); +#pragma aux inb = "in al, dx" parm [dx] value [al]; +void outb(uint16_t port, uint8_t data); +#pragma aux outb = "out dx, al" parm [dx] [al]; +uint16_t inw(uint16_t port); +#pragma aux inw = "in ax, dx" parm [dx] value [ax]; +void outw(uint16_t port, uint16_t data); +#pragma aux outw = "out dx, ax" parm [dx] [ax]; +#ifdef M_I386 +uint32_t inl(uint16_t port); +# pragma aux inl = "in eax, dx" parm [dx] value [eax]; +void outl(uint16_t port, uint32_t data); +# pragma aux outl = "out dx, eax" parm [dx] [eax]; +#else +/* Some manual prefixing trickery to perform 32-bit I/O and access + the extended part of EAX in real mode. Exchanging is necessary + due to Watcom ignoring the order registers are specified in... */ +uint32_t inl(uint16_t port); +# pragma aux inl = "db 0x66" "in ax, dx" /* in eax, dx */ \ + "mov cx, ax" \ + "db 0x66, 0xc1, 0xe8, 0x10" /* shr eax, 16 */ \ + "xchg ax, cx" \ + parm [dx] \ + value [ax cx]; +void outl(uint16_t port, uint32_t data); +# pragma aux outl = "xchg ax, cx" \ + "db 0x66, 0xc1, 0xe0, 0x10" /* shl eax, 16 */ \ + "mov ax, cx" \ + "db 0x66" "out dx, ax" /* out dx, eax */ \ + parm [dx] [ax cx] \ + modify [ax cx]; +#endif + + +/* PCI functions. */ +extern uint32_t pci_cf8(uint8_t bus, uint8_t dev, uint8_t func, uint8_t reg); + +#endif diff --git a/pcireg/PCIREG.EXE b/pcireg/PCIREG.EXE index 2023766..631b287 100644 Binary files a/pcireg/PCIREG.EXE and b/pcireg/PCIREG.EXE differ diff --git a/pcireg/build.bat b/pcireg/build.bat index 6ca3449..398911f 100644 --- a/pcireg/build.bat +++ b/pcireg/build.bat @@ -1,2 +1,2 @@ @echo off -..\lib\build_watcom_dos.bat pcireg.c +..\lib\build_watcom_dos.bat pcireg.c ..\lib\wlib.c diff --git a/pcireg/build.sh b/pcireg/build.sh index f1fc705..3d42296 100644 --- a/pcireg/build.sh +++ b/pcireg/build.sh @@ -1,2 +1,2 @@ #!/bin/sh -exec ../lib/build_watcom_dos.sh pcireg.c +exec ../lib/build_watcom_dos.sh pcireg.c ../lib/wlib.c diff --git a/pcireg/pcireg.c b/pcireg/pcireg.c index 2f8ab04..7b4e71e 100644 --- a/pcireg/pcireg.c +++ b/pcireg/pcireg.c @@ -27,14 +27,9 @@ #include #include #include +#include "wlib.h" -typedef union { - uint8_t u8[4]; - uint16_t u16[2]; - uint32_t u32; -} multi_t; - struct videoconfig vc; union REGPACK rp; /* things break if this is not a global variable... */ @@ -74,52 +69,6 @@ typedef struct { #pragma pack(pop) -void outb(uint16_t port, uint8_t data); -#pragma aux outb = "out dx, al" parm [dx] [al]; -uint8_t inb(uint16_t port); -#pragma aux inb = "in al, dx" parm [dx] value [al]; - -void outw(uint16_t port, uint16_t data); -#pragma aux outw = "out dx, ax" parm [dx] [ax]; -uint16_t inw(uint16_t port); -#pragma aux inw = "in ax, dx" parm [dx] value [ax]; - -#ifdef M_I386 -void outl(uint16_t port, uint32_t data); -# pragma aux outl = "out dx, eax" parm [dx] [eax]; -uint32_t inl(uint16_t port); -# pragma aux inl = "in eax, dx" parm [dx] value [eax]; -#else -void outl(uint16_t port, uint32_t data); -# pragma aux outl = "xchg ax, cx" \ - "db 0x66, 0xc1, 0xe0, 0x10" /* shl eax, 16 */ \ - "mov ax, cx" \ - "db 0x66" "out dx, ax" /* out dx, eax */ \ - parm [dx] [ax cx] \ - modify [ax cx]; -uint32_t inl(uint16_t port); -# pragma aux inl = "db 0x66" "in ax, dx" /* in eax, dx */ \ - "mov cx, ax" \ - "db 0x66, 0xc1, 0xe8, 0x10" /* shr eax, 16 */ \ - "xchg ax, cx" \ - parm [dx] \ - value [ax cx]; -#endif - - -uint32_t -make_cf8(uint8_t bus, uint8_t dev, uint8_t func, uint8_t reg) -{ - multi_t ret; - ret.u8[3] = 0x80; - ret.u8[2] = bus; - ret.u8[1] = dev << 3; - ret.u8[1] |= func & 7; - ret.u8[0] = reg & 0xfc; - return ret.u32; -} - - char * read_string(FILE *f, uint32_t offset) { @@ -148,7 +97,7 @@ dump_regs(uint8_t bus, uint8_t dev, uint8_t func, uint8_t start_reg, char sz) start_reg &= 0xfc; /* Build the base CF8h dword for this dump. */ - cf8 = make_cf8(bus, dev, func, 0x00); + cf8 = pci_cf8(bus, dev, func, 0x00); /* Generate dump file name. */ sprintf(buf, "PCI%02X%02X%d.BIN", bus, dev, func); @@ -568,7 +517,7 @@ scan_bus(uint8_t bus, int nesting, char dump, FILE *f, char *buf) dev_id.u32 = 0xffffffff; } #else - cf8 = make_cf8(bus, dev, func, 0x00); + cf8 = pci_cf8(bus, dev, func, 0x00); outl(0xcf8, cf8); dev_id.u32 = inl(0xcfc); #endif @@ -595,7 +544,7 @@ scan_bus(uint8_t bus, int nesting, char dump, FILE *f, char *buf) dev_rev_class.u16[0] = rand(); dev_rev_class.u16[1] = rand(); #else - cf8 = make_cf8(bus, dev, func, 0x08); + cf8 = pci_cf8(bus, dev, func, 0x08); outl(0xcf8, cf8); dev_rev_class.u32 = inl(0xcfc); #endif @@ -721,7 +670,7 @@ unknown: #ifdef DEBUG header_type = (bus < (DEBUG - 1)) ? 0x01 : 0x00; #else - cf8 = make_cf8(bus, dev, func, 0x0c); + cf8 = pci_cf8(bus, dev, func, 0x0c); outl(0xcf8, cf8); header_type = inb(0xcfe); #endif @@ -732,7 +681,7 @@ unknown: #ifdef DEBUG new_bus = bus + 1; #else - cf8 = make_cf8(bus, dev, func, 0x18); + cf8 = pci_cf8(bus, dev, func, 0x18); outl(0xcf8, cf8); new_bus = inb(0xcfd); #endif @@ -803,7 +752,7 @@ read_reg(uint8_t bus, uint8_t dev, uint8_t func, uint8_t reg) bus, dev, func, reg | 3, reg & 0xfc); /* Read dword value from register. */ - cf8 = make_cf8(bus, dev, func, reg); + cf8 = pci_cf8(bus, dev, func, reg); #ifdef DEBUG reg_val.u32 = cf8; #else @@ -916,7 +865,7 @@ retry_buf: if (entries > 0) { /* Assume device 00 is the northbridge if it has a host bridge class. */ if (entry->dev > 0x00) { - cf8 = make_cf8(0x00, 0x00, 0, 0x08); + cf8 = pci_cf8(0x00, 0x00, 0, 0x08); outl(0xcf8, cf8); dev_class = inw(0xcfe); if (dev_class == 0x0600) @@ -924,7 +873,7 @@ retry_buf: } /* Assume device 01 is the AGP bridge if it has a PCI bridge class. */ if (entry->dev > 0x01) { - cf8 = make_cf8(0x00, 0x01, 0, 0x08); + cf8 = pci_cf8(0x00, 0x01, 0, 0x08); outl(0xcf8, cf8); dev_class = inw(0xcfe); if (dev_class == 0x0604) @@ -1000,7 +949,7 @@ retry_buf: printf("NORTHBRIDGE,"); } else { /* Read device class. */ - cf8 = make_cf8(0x00, entry->dev, 0, 0x08); + cf8 = pci_cf8(0x00, entry->dev, 0, 0x08); outl(0xcf8, cf8); dev_class = inw(0xcfe); @@ -1081,7 +1030,7 @@ write_reg(uint8_t bus, uint8_t dev, uint8_t func, uint8_t reg, char *val) multi_t reg_val; /* Write a byte, word or dword depending on the input value's length. */ - cf8 = make_cf8(bus, dev, func, reg); + cf8 = pci_cf8(bus, dev, func, reg); data_port = 0xcfc; switch (strlen(val)) { case 1: