/* tcpclient.c Copyright 2019, Paul Gardner-Stephen Copyright 2012, Isaakidis Marios, Daniel Aguado 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include #include #include #include #include #include #include #include #include #include #include //file found = 1 //file not found = 0 //write and overwrite =1 //apend =0 //tcpclient IP port //argc1, argv0: tcpclient.exe //argc2, argv1: IP address TCP Server //argv3, argv2: TCP Server port int set_nonblock(int fd) { int retVal=0; do { if (fd==-1) break; int flags; if ((flags = fcntl(fd, F_GETFL, NULL)) == -1) { perror("fcntl"); // LOG_ERROR("set_nonblock: fcntl(%d,F_GETFL,NULL)",fd); retVal=-1; break; } if (fcntl(fd, F_SETFL, flags | O_NONBLOCK | O_NDELAY) == -1) { perror("fcntl"); // LOG_ERROR("set_nonblock: fcntl(%d,F_SETFL,n|O_NONBLOCK)",fd); return -1; } } while (0); return retVal; } #define MAX_KEYS 1024 int key_times[MAX_KEYS]; char key_sequences[MAX_KEYS][1024]; int key_count=0; int main (int argc, char *argv[]) { int collect_cycles=5000000; // KERNAL part is actually just under 7KB int rom_bottom=0xe4b7; int rom_top=0xffff; char *filename=NULL; int opt; while ((opt = getopt(argc, argv, "f:b:t:c:k:v:")) != -1) { switch (opt) { case 'b': rom_bottom=strtoll(optarg,NULL,16); break; case 't': rom_top=strtoll(optarg,NULL,16); break; case 'f': filename=optarg; break; case 'c': collect_cycles=atoi(optarg); break; case 'v': system(optarg); sleep(3); break; case 'k': // Scheduled key events if (key_count>=MAX_KEYS) { fprintf(stderr,"Too many -k arguments. Increase MAX_KEYS?\n"); exit(-1); } if (sscanf(optarg,"%d:%[^~]",&key_times[key_count],key_sequences[key_count])<2) { fprintf(stderr,"Malformed argument to -k. Must be :\n" " RETURN should be written \\x0d\n" "\n"); exit(-1); } key_count++; break; default: /* '?' */ fprintf(stderr, "Usage: %s [-v ] [-b ] [-t ] [-f ] [-c ] [[-k