/* String-Tabelle und Konsolen-Ein/Ausgabe für Linux */
// Zeichenketten-Liste, durch Null-Bytes voneinander getrennt
// erspart dem Compiler das Generieren eines Arrays
// mit der mindestens ebenso langen Relokationsinformation
static const char stGer[]=
/*0*/ "Detektiere PEPS ... " "\0"
/*1*/ "Verzögerung: %d µs, Einheiten: %d, RAM-Größe: %d KByte" "\0"
/*2*/ "nicht ansprechbar! (Port-Index = %u)" "\0"
/*3*/ "nicht ansprechbar an Portadresse 0x%X!" "\0"
/*4*/ "Amiga Object Module – nicht unterstützt!" "\0"
/*5*/ "Lade Intel-Hex-Datei..." "\0"
/*6*/ "Formatfehler in Datei %s Zeile %d!" "\0"
/*7*/ "Prüfsummen-Fehler in Datei %s Zeile %d: %02X!=%02X!" "\0"
/*8*/ "Hinweis: Eingabedaten ergeben %d Bereiche, Lücken sind mit 0x%02X aufgefüllt!" "\0"
/*9*/ "Warnung: Eingabedaten wurden auf %d KByte abgeschnitten." "\0"
/*10*/ "Lade Motorola-S-Datei..." "\0"
/*11*/ "" "\0"
/*12*/ "" "\0"
/*13*/ "Lade Binärdatei..." "\0"
/*14*/ "Binärdatei %s ist blockiert!" "\0"
/*15*/ "Datei %s nicht lesbar!" "\0"
/*16*/ "^C, <CR>, <ESC> => Ausgang zum Betriebssystem (<CR> mit Start)\n"
"R => Permanent-RESET des Zielsystems\n"
"I < > => RESET-Impulse; langsamer, schneller\n"
"<sonstige Taste> => kurzer RESET-Impuls, Start des Zielsystems\n" "\0"
/*17*/ "Daten passen nicht in %d KByte PEPS-Speicher\n" "\0"
/*18*/ "Zielsystem => RESET-Impulse %u µs" "\0"
/*19*/ "Zielsystem => RESET" "\0"
/*20*/ "Zielsystem => gestartet" "\0"
/*21*/ "Unerlaubter Modus (Zahl) für Option -%c!" "\0"
/*22*/ "\e[1mKommunikation mit Conitec RAM/EPROM-Simulator PEPS-III\e[0m [Version 4.14]\n"
"./peps <Optionen> <Datei> Datei mit EPROM-Daten\n"
"-e n Verschiebe Daten um Offset n (hex, sonst 0)\n"
"-l n Länge der zu übertragenden Daten (hex, sonst 80000)\n"
"-w<Name> PEPS auslesen in Datei <Name>\n"
" -e, -l, ohne -w = RAM füllen mit <Bytes> statt <Datei>\n"
"-b n Busbreite: 1 bis 4 Byte (und PEPSe) — oder Bitmaske\n"
"-u n Nummer 1-4 des anzusprechenden Einzel-PEPS\n"
"-f n Dateiformat: 0=automatisch, 1=binär, 2=Intel-HEX, 3=Motorola-HEX\n"
"-c n Check-Modus: 0 kein Check, 1 HardwareTest (Default) 2 Datencheck\n"
"-o n Debug-Modus: 0 kein Debug, 1 Debug nach dem Laden aktiv\n"
"-inn .. lade Bytes an die mit -e spezifizierte Adresse\n"
"-t n PEPS-Typ, 1=PEPS, 2=PEPS-II, 3=PEPS-III (Vorgabe)\n"
"-d n E/A-Gerät: 0=ioperm, 1=/dev/parportX, 2=/dev/usb/lpX, 3=USB2LPT\n"
"-p n Nummer der Parallel-Schnittstelle: 0 (Vorgabe) = /dev/parport0 usw.\n"
"(-x n) Portadresse der Parallel-Schnittstelle hexadezimal\n"
"-z[n] Delaymodus mit Wert n erzwingen. Ohne n automatische Bestimmung\n\n" "\0"
/*23*/ "\0"
/*24*/ "LPT%d: nicht vorhanden!" "\0"
/*25*/ "unbekannte Option: %s!" "\0"
/*26*/ "Datei %s nicht anlegbar!" "\0"
/*27*/ "\0"
/*28*/ "Datei %s nicht vorhanden!" "\0"
/*29*/ "0x%X Bytes übertragen in %u Sekunden (%u %s)" "\0"
/*30*/ "Kein Parallelport an Adresse 0x%X!" "\0"
/*31*/ "ungültige Option (-w ohne Dateinamen) ignoriert\n" "\0"
/*32*/ "Vergleichsfehler bei Adresse 0x%X: %02X!=%02X!" "\0"
/*33*/ "Lese PEPS (ab Adresse 0x%X Länge 0x%X) aus ... ""\0"
/*34*/ "\0"
/* 27.01.1998 AM */
/*35*/ "Ungültige Portadresse: 0x%X\n" "\0"
/*36*/ "Parameter -p und -x nicht zusammen verwenden\n" "\0"
/*37*/
" Target-Sockel\n"
" ┌──────────────┐\n"
"Einsetzen des ┌─────┬──────────────┐\n"
"PEPS-III in kleinere │ │ │\n"
"Zielsystemsockel │1 │ 1 │\n"
" └─────┴──────────────┘\n"
" └────────────────────┘\n"
" PEPS-III-Sockel\n" "\0"
/*38*/ "Typ Größe 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 (X: Ein)\n" "\0"
/*39*/ "Eine Taste drücken oder <q> für Abbruch." "\0"
/*40*/ "Überprüfung ... " "\0"
/*41*/ "Binärdateilänge: %d (0x%X)\n" "\0"
/*42*/ "Target-Größe: %d (0x%X)\n" "\0"
/*43*/ "" "\0"
/*44*/ "Keine %u Bytes Freispeicher!" "\0"
/*45*/ " Benutzerabbruch (Kode %d)" "\0"
/*46*/ "Kann UID nicht auf 0 (root) setzen! Kein SUID-Bit?" "\0"
/*47*/ "Kann E/A-Berechtigung für 0x%X nicht setzen!" "\0"
/*48*/ "Kann ursprüngliche UID (%d) nicht setzen!\n" "\0"
/*49*/ "Kann Parallelport %s nicht öffnen, Fehlerkode %d!" "\0"
/*50*/ "E/A-Fehler %d! USB-Gerät könnte versagt haben." "\0"
/*51*/ "Kann USB→Paralleldrucker-Konverter %s nicht öffnen, Fehlerkode %d!" "\0"
/*52*/ "Zurzeit keine Unterstützung für USB2LPT." "\0"
/*53*/ "Sende Daten an Adresse 0x%X Länge 0x%X ... " "\0"
/*54*/ "Fertig." "\0"
;
static const char stUSA[]=
/*0*/ "Detecting PEPS ... " "\0"
/*1*/ "PortDelay: %d µs, Units: %d, RAM size (each): %d KByte" "\0"
/*2*/ "not online (at port index %u)!" "\0"
/*3*/ "not online at port address 0x%X!" "\0"
/*4*/ "Amiga Object Module not supported!" "\0"
/*5*/ "Loading Intel-Hex file..." "\0"
/*6*/ "Wrong content in file %s line %d!" "\0"
/*7*/ "Wrong checksum in file %s line %d: %02X!=%02X!" "\0"
/*8*/ "" "\0"
/*9*/ "" "\0"
/*10*/ "Loading Motorola-S file..." "\0"
/*11*/ "" "\0"
/*12*/ "" "\0"
/*13*/ "Loading Binary file..." "\0"
/*14*/ "Binary file %s is locked!" "\0"
/*15*/ "File %s unreadable\n" "\0"
/*16*/ "^C, <CR>, <ESC> => exit to system (start target on <CR>)\n"
"R => permanent RESET target\n"
"I < > => clocked RESET; slower, faster\n"
"<any other key> => single-shot RESET, start target\n" "\0"
/*17*/ "Data won't fit in %dK PEPS space, clipped.\n" "\0"
/*18*/ "Target => clocked RESET %u µs" "\0"
/*19*/ "Target => RESET" "\0"
/*20*/ "Target => started" "\0"
/*21*/ "Illegal mode (number) for option -%c!" "\0"
/*22*/ "\e[1mCommunication with Conitec RAM/EPROM simulator PEPS-III\e[0m [Version 4.14]\n"
"USAGE: ./peps <options> <infile> file containing EPROM data\n"
"-e n offset incoming data by n (hex, default 0)\n"
"-l n length of data (hex) for PEPS load or PEPS read (default 80000)\n"
"-w<name> write data to binary file <name>\n"
" -e, -l, but no -w given: Fill RAM with <bytes> instead of <infile>\n"
"-b n Bus width: 1 (default) upto 4 byte (i.e. multiple PEPS') — or bit mask\n"
"-u n number 1-4 selects one of multiple PEPS units\n"
"-f n Fileformat: 0 Binary, 1 INTEL-HEX, 2 MOTOROLA\n"
"-c n Check-Mode: 0 no Check, 1 Hardware-check (Default) 2 Datacheck\n"
"-o n Debug-Mode: 0 no Debug, 1 enter Debug after Loading\n"
"-inn .. load Bytes to address, specified by -ennnnn\n"
"-d n I/O device: 0=ioperm, 1=/dev/parportX, 2=/dev/usb/lpX, 3=USB2LPT\n"
"-p n select parallel port: 0 = /dev/parport0 etc.\n"
"(-x n) address of parallel port hex.\n"
"-z [n] force delay transfer mode with value n. No n -> n = 1.\n\n" "\0"
/*23*/ "PEPS not online (at port index %u)!" "\0"
/*24*/ "/dev/parport%d: not available" "\0"
/*25*/ "unknown option: %s" "\0"
/*26*/ "file %s open error!" "\0"
/*27*/ "PEPS not online at port address 0x%X!" "\0"
/*28*/ "File %s not found!" "\0"
/*29*/ "0x%X Bytes transferred in %u seconds (%u %s)" "\0"
/*30*/ "No parallel port at address 0x%X!" "\0"
/*31*/ "illegal option (-w without filename) ignored\n" "\0"
/*32*/ "Verify error at address 0x%X: %02X!=%02X!" "\0"
/*33*/ "Reading PEPS (from address 0x%X length 0x%X) ... " "\0"
/*34*/ "" "\0"
/* 27.01.1998 AM */
/*35*/ "Invalid port address: 0x%X" "\0"
/*36*/ "Do not use -p und -x at the same time" "\0"
/*37*/ " Target socket\n"
" ┌──────────────┐\n"
"How to insert ┌─────┬──────────────┐\n"
"PEPS-III into smaller │ │ │\n"
"target sockets. │1 │ 1 │\n"
" └─────┴──────────────┘\n"
" └────────────────────┘\n"
" PEPS-III socket\n" "\0"
/*38*/ "Type Size 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 (X: On)\n" "\0"
/*39*/ "Press any key or <q> to abort." "\0"
/*40*/ "Verify ... " "\0"
/*41*/ "BinSize %ld (%06lx)\n" "\0"
/*42*/ "TargetSize %ld (%06lx)\n" "\0"
/*43*/ "" "\0"
/*44*/ "No %u bytes free memory!" "\0"
/*45*/ " User abort (code %d)" "\0"
/*46*/ "Cannot set UID to 0! Missing SUID bit?" "\0"
/*47*/ "Cannot get IO permissions for 2 bytes starting at 0x%X!""\0"
/*48*/ "Cannot restore original UID (%d)!\n" "\0"
/*49*/ "Cannot access parallel port device %s, errno %d!" "\0"
/*50*/ "I/O error %d (USB device failure?)" "\0"
/*51*/ "Cannot access USB→ParallelPrinter converter %s, errno %d!" "\0"
/*52*/ "Currently no support for USB2LPT." "\0"
/*53*/ "Send data o address 0x%X length 0x%X ... " "\0"
/*54*/ "Completed." "\0"
;
#include "peps.h"
#include <stdio.h>
#include <locale.h>
#include <termios.h>
#include <signal.h>
#include <sys/time.h>
/* Einen Stringanfang aus der Kette nullterminierter Strings liefern */
static const char* getstring(const char *p, int id) {
for(;id;id--) p+=strlen(p)+1;
return p;
}
// Beim Programmstart wird hier die Tabelle und damit Sprache festgelegt
static const char* MsgTable = stUSA;
// Ressource-vprintf
extern void vrprintf(int id,va_list va) {
vprintf(getstring(MsgTable,id),va);
}
// Ressource-printf
extern void rprintf(int id,...) {
va_list va;
va_start(va,id);
vrprintf(id,va);
va_end(va);
}
// liefert -1 wenn kein Zeichen verfügbar (und <noblock> == true)
// ohne vorheriges Flush der Zeichen-Eingabe-Queue
extern int mygetch(bool noblock) {
int c;
struct termios neu,alt;
tcgetattr(0,&alt);
neu=alt;
neu.c_lflag &= ~(ICANON|ECHO|ISIG);
if (noblock) {
neu.c_cc[VMIN]=0;
neu.c_cc[VTIME]=0;
}
tcsetattr(0,TCSANOW,&neu);
c=getchar();
// Liefert 27 (ESC, "\e") bei erweiterten Tasten (bspw. Kursortasten)!
// Die ESC-Taste liefert 27 _ohne_ (sofortig) nachfolgenden Buchstaben.
// CUL="\e[D", CUR="\e[C", CUU"\e[A", CUD="\e[B", F2="\eOQ", F3="\eOR", F4="\eOS",
// F5="\e[15~", F6="\e17~", F7="\e18~", F8="\e[19~", F9="\e[20~",
// INS="\e[2~", DEL="\e3~", HOME="\eOH", END="\eOF", PgUp="\e[5~", PgDn="\e[6~",
// Alt+BkSp="\e\x7F", Shift+F1="\eO1;2P", Shift+F5="\e[15;2~", Shift+CUR="\e[1;2C",
// Alt+CUL="\e[1;3D", ^CUR="\e[1;5C", Alt+Shift+CUR="\e[1;4C", usw.
// Wo steht das eigentlich dokumentiert? "man getchar()" liefert nix.
if (c==27) {
int ch;
neu.c_cc[VMIN]=0;
neu.c_cc[VTIME]=1; // 1/10 Sekunde warten (falls serielle Leitung lahm)
tcsetattr(0,TCSANOW,&neu);
for(;(ch=getchar())!=-1;) { // bei Timeout ESC-Taste annehmen
if ((isalpha(ch) && !(ch=='O')) || ch=='~') {// Ende der Escape-Sequenz
c|=ch<<8; // als High-Byte liefern
break; // (reicht für Kursortasten und F1..F4)
}
}
}
tcsetattr(0,TCSAFLUSH,&alt);
return c;
}
// Bildet Windows-Funktion nach, nur präziser
extern DWORD GetTickCount() {
struct timeval tv;
gettimeofday(&tv,NULL);
return (DWORD)tv.tv_sec*1000 + (DWORD)tv.tv_usec/1000;
}
static void sigint_handler(int sig) {
DoExit(45,sig);
}
extern void InitRes() {
// printf("%s\n",getenv("LANG"));
if (!strncmp(getenv("LANG"),"de",2)) MsgTable = stGer;
/* Zurück kommt bspw. "de_DE.UTF-8",
da ließe sich noch die Ausgabekodeseite anpassen,
falls diese nicht UTF-8 ist (keine Installation bekannt) */
signal(SIGINT, sigint_handler);
setvbuf(stdout,NULL,_IONBF,0); // Pufferung von stdout abschalten
}
// TODO: Leider kann man "/proc/ioports" nicht entnehmen, was SPP und ECP ist.
extern WORD GetParportAddr(int n) {
WORD ret=0;
FILE *f = fopen("/proc/ioports","r");
if (f) {
char line[100];
line[sizeof(line)-1]=0;
while (fgets(line,sizeof(line)-1,f)) {
int a,e,i;
if (sscanf(line,"%x-%x : parport%d",&a,&e,&i)==3 // Ressourcen-Zeile
&& !(a&3) // durch 4 teilbare Basisadresse
&& i==n) {
ret = (WORD)a;
break;
}
}
fclose(f);
}
return ret;
}
Detected encoding: UTF-8 | 0
|