fork of PCE focusing on macplus, supporting DaynaPort SCSI network emulation
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

simppc: Add pceutils-powerpc

+1228
+1
Makefile.inc.in
··· 162 162 include $(srcdir)/src/arch/macplus/pcex/Makefile.inc 163 163 include $(srcdir)/src/arch/rc759/Makefile.inc 164 164 include $(srcdir)/src/arch/sim405/Makefile.inc 165 + include $(srcdir)/src/arch/sim405/pceutils/Makefile.inc 165 166 include $(srcdir)/src/arch/sim6502/Makefile.inc 166 167 include $(srcdir)/src/arch/simarm/Makefile.inc 167 168 include $(srcdir)/src/arch/sims32/Makefile.inc
+1
mkdep
··· 11 11 } > "src/config.h" 12 12 13 13 find src -type f -name "*.c" -print |\ 14 + grep -v "^src/arch/sim405/pceutils/" |\ 14 15 while read file ; do 15 16 echo "${file%.*}.o:" 16 17 makedepend -Y -f- -w0 -Isrc "$file" 2> /dev/null
+49
src/arch/sim405/pceutils/Makefile
··· 1 + # Makefile 2 + 3 + #CROSS = powerpc-linux- 4 + 5 + CC = $(CROSS)gcc 6 + LD = $(CROSS)gcc 7 + 8 + CFLAGS = -Os -Wall 9 + AFLAGS = 10 + 11 + prefix = inst 12 + bindir = $(prefix)/bin 13 + 14 + BIN := pcecp pcemsg pcetime pcever 15 + 16 + all: $(BIN) 17 + 18 + clean: 19 + rm -f pce.o 20 + rm -f pcecp pcemsg pcetime pcever 21 + rm -f pcecp.o pcemsg.o pcetime.o pcever.o 22 + 23 + install: 24 + mkdir -p $(bindir) 25 + cp $(BIN) $(bindir) 26 + 27 + %.o: %.c 28 + $(CC) $(CFLAGS) -c -o $@ $< 29 + 30 + %.o: %.S 31 + $(CC) $(AFLAGS) -c -o $@ $< 32 + 33 + pce.o: pce.S 34 + pcecp.o: pcecp.c pce.h config.h 35 + pcemsg.o: pcemsg.c pce.h config.h 36 + pcetime.o: pcetime.c pce.h config.h 37 + pcever.o: pcever.c pce.h config.h 38 + 39 + pcecp: pcecp.o pce.o 40 + $(LD) $(LDFLAGS) -o $@ pce.o pcecp.o 41 + 42 + pcemsg: pcemsg.o pce.o 43 + $(LD) $(LDFLAGS) -o $@ pce.o pcemsg.o 44 + 45 + pcetime: pcetime.o pce.o 46 + $(LD) $(LDFLAGS) -o $@ pce.o pcetime.o 47 + 48 + pcever: pcever.o pce.o 49 + $(LD) $(LDFLAGS) -o $@ pce.o pcever.o
+12
src/arch/sim405/pceutils/Makefile.inc
··· 1 + # src/arch/sim405/pceutils/Makefile.inc 2 + 3 + rel := src/arch/sim405/pceutils 4 + 5 + DIRS += $(rel) 6 + DIST += $(rel)/Makefile.inc 7 + 8 + # ---------------------------------------------------------------------- 9 + 10 + FILES := Makefile config.h pce.S pce.h pcecp.c pcemsg.c pcetime.c pcever.c 11 + 12 + DIST += $(foreach f,$(FILES),$(rel)/$(f))
+30
src/arch/sim405/pceutils/config.h
··· 1 + /***************************************************************************** 2 + * pce * 3 + *****************************************************************************/ 4 + 5 + /***************************************************************************** 6 + * File name: config.h * 7 + * Created: 2018-12-24 by Hampa Hug <hampa@hampa.ch> * 8 + * Copyright: (C) 2018 Hampa Hug <hampa@hampa.ch> * 9 + *****************************************************************************/ 10 + 11 + /***************************************************************************** 12 + * This program is free software. You can redistribute it and / or modify it * 13 + * under the terms of the GNU General Public License version 2 as published * 14 + * by the Free Software Foundation. * 15 + * * 16 + * This program is distributed in the hope that it will be useful, but * 17 + * WITHOUT ANY WARRANTY, without even the implied warranty of * 18 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General * 19 + * Public License for more details. * 20 + *****************************************************************************/ 21 + 22 + 23 + #ifndef PCEUTILS_CONFIG_H 24 + #define PCEUTILS_CONFIG_H 1 25 + 26 + 27 + #define PCEUTILS_VERSION_STR "0.0.1" 28 + 29 + 30 + #endif
+375
src/arch/sim405/pceutils/pce.S
··· 1 + #----------------------------------------------------------------------------- 2 + # pce 3 + #----------------------------------------------------------------------------- 4 + 5 + #----------------------------------------------------------------------------- 6 + # File name: pce.S 7 + # Created: 2018-12-22 by Hampa Hug <hampa@hampa.ch> 8 + # Copyright: (C) 2018 Hampa Hug <hampa@hampa.ch> 9 + #----------------------------------------------------------------------------- 10 + 11 + #define PCE_HOOK_CHECK 0x0000 12 + #define PCE_HOOK_GET_VERSION 0x0001 13 + #define PCE_HOOK_GET_VERSION_STR 0x0002 14 + #define PCE_HOOK_INIT 0x0100 15 + #define PCE_HOOK_PUTC 0x0101 16 + #define PCE_HOOK_GETC 0x0102 17 + #define PCE_HOOK_STOP 0x0200 18 + #define PCE_HOOK_ABORT 0x0201 19 + #define PCE_HOOK_MSG 0x0300 20 + #define PCE_HOOK_GET_TIME_UNIX 0x0400 21 + #define PCE_HOOK_READ_OPEN 0x0500 22 + #define PCE_HOOK_READ_CLOSE 0x0501 23 + #define PCE_HOOK_READ 0x0502 24 + #define PCE_HOOK_WRITE_OPEN 0x0600 25 + #define PCE_HOOK_WRITE_CLOSE 0x0601 26 + #define PCE_HOOK_WRITE 0x0602 27 + 28 + #define hook .long 0x44ce0002 29 + 30 + .global pce_check 31 + .global pce_get_version 32 + .global pce_get_version_str 33 + .global pce_init 34 + .global pce_putc 35 + .global pce_putc0 36 + .global pce_puts 37 + .global pce_puts0 38 + .global pce_getc 39 + .global pce_gets 40 + .global pce_stop 41 + .global pce_abort 42 + .global pce_set_msg 43 + .global pce_get_time_unix 44 + .global pce_read_open 45 + .global pce_read_close 46 + .global pce_read16 47 + .global pce_write_open 48 + .global pce_write_close 49 + .global pce_write16 50 + 51 + .text 52 + 53 + #----------------------------------------------------------------------------- 54 + # int pce_check (void) 55 + #----------------------------------------------------------------------------- 56 + pce_check: 57 + li %r3, PCE_HOOK_CHECK 58 + hook 59 + 60 + cmpwi %r3, 0xffffffce 61 + beq 1f 62 + 63 + li %r3, -1 64 + blr 65 + 1: 66 + li %r3, 0 67 + blr 68 + 69 + 70 + #----------------------------------------------------------------------------- 71 + # int pce_get_version (unsigned p[3]) 72 + #----------------------------------------------------------------------------- 73 + pce_get_version: 74 + mr %r7, %r3 75 + 76 + li %r3, PCE_HOOK_GET_VERSION 77 + hook 78 + cmpwi %r3, 0 79 + bnelr 80 + 81 + stw %r4, 0(%r7) 82 + stw %r5, 4(%r7) 83 + stw %r6, 8(%r7) 84 + 85 + blr 86 + 87 + 88 + #----------------------------------------------------------------------------- 89 + # int pce_get_str (char *str, unsigned max) 90 + #----------------------------------------------------------------------------- 91 + pce_get_version_str: 92 + mflr %r0 93 + stwu %r1, -8(%r1) 94 + stw %r0, 12(%r1) 95 + 96 + mr %r5, %r3 97 + 98 + li %r3, PCE_HOOK_GET_VERSION_STR 99 + hook 100 + cmpwi %r3, 0 101 + bnelr 102 + 103 + mr %r3, %r5 104 + bl pce_gets 105 + 106 + lwz %r0, 12(%r1) 107 + mtlr %r0 108 + addi %r1, %r1, 8 109 + blr 110 + 111 + 112 + #----------------------------------------------------------------------------- 113 + # int pce_init (void) 114 + #----------------------------------------------------------------------------- 115 + pce_init: 116 + li %r3, PCE_HOOK_INIT 117 + hook 118 + blr 119 + 120 + 121 + #----------------------------------------------------------------------------- 122 + # int pce_putc0 (int c) 123 + #----------------------------------------------------------------------------- 124 + pce_putc0: 125 + mr %r5, %r3 126 + li %r3, PCE_HOOK_INIT 127 + hook 128 + cmpwi %r3, 0 129 + bnelr 130 + mr %r3, %r5 131 + # fall through 132 + 133 + 134 + #----------------------------------------------------------------------------- 135 + # int pce_putc (int c) 136 + #----------------------------------------------------------------------------- 137 + pce_putc: 138 + li %r3, PCE_HOOK_PUTC 139 + hook 140 + blr 141 + 142 + 143 + #----------------------------------------------------------------------------- 144 + # int pce_puts0 (const char *s) 145 + #----------------------------------------------------------------------------- 146 + pce_puts0: 147 + mr %r5, %r3 148 + li %r3, PCE_HOOK_INIT 149 + hook 150 + cmpwi %r3, 0 151 + bnelr 152 + mr %r3, %r5 153 + # fall through 154 + 155 + 156 + #----------------------------------------------------------------------------- 157 + # int pce_puts (const char *s) 158 + #----------------------------------------------------------------------------- 159 + pce_puts: 160 + subi %r5, %r3, 1 161 + 0: 162 + lbzu %r4, 1(%r5) 163 + cmpwi %r4, 0 164 + beq 1f 165 + 166 + li %r3, PCE_HOOK_PUTC 167 + hook 168 + cmpwi %r3, 0 169 + beq 0b 170 + 1: 171 + blr 172 + 173 + 174 + #----------------------------------------------------------------------------- 175 + # int pce_getc (void) 176 + #----------------------------------------------------------------------------- 177 + pce_getc: 178 + li %r3, PCE_HOOK_GETC 179 + hook 180 + blr 181 + 182 + 183 + #----------------------------------------------------------------------------- 184 + # int pce_gets (const char *s, unsigned max) 185 + #----------------------------------------------------------------------------- 186 + pce_gets: 187 + subi %r5, %r3, 1 188 + 189 + mtctr %r4 190 + 0: 191 + li %r3, PCE_HOOK_GETC 192 + hook 193 + cmpwi %r3, 0 194 + blt 1f 195 + 196 + stbu %r3, 1(%r5) 197 + bdnz 0b 198 + 199 + li %r3, -1 200 + blr 201 + 1: 202 + li %r3, 0 203 + stbu %r3, 1(%r5) 204 + blr 205 + 206 + 207 + #----------------------------------------------------------------------------- 208 + # void pce_stop (void) 209 + #----------------------------------------------------------------------------- 210 + pce_stop: 211 + li %r3, PCE_HOOK_STOP 212 + hook 213 + blr 214 + 215 + 216 + #----------------------------------------------------------------------------- 217 + # void pce_abort (void) 218 + #----------------------------------------------------------------------------- 219 + pce_abort: 220 + li %r3, PCE_HOOK_ABORT 221 + hook 222 + blr 223 + 224 + 225 + #----------------------------------------------------------------------------- 226 + # int pce_set_msg (const char *msg, const char *val) 227 + #----------------------------------------------------------------------------- 228 + pce_set_msg: 229 + mflr %r0 230 + stwu %r1, -16(%r1) 231 + stw %r0, 20(%r1) 232 + stw %r31, 12(%r1) 233 + 234 + mr %r31, %r4 235 + 236 + bl pce_puts0 237 + cmpwi %r3, 0 238 + bne 1f 239 + 240 + li %r3, 0 241 + bl pce_putc 242 + cmpwi %r3, 0 243 + bne 1f 244 + 245 + mr %r3, %r31 246 + bl pce_puts 247 + cmpwi %r3, 0 248 + bne 1f 249 + 250 + li %r3, PCE_HOOK_MSG 251 + hook 252 + 1: 253 + lwz %r31, 12(%r1) 254 + lwz %r0, 20(%r1) 255 + mtlr %r0 256 + addi %r1, %r1, 16 257 + blr 258 + 259 + 260 + #----------------------------------------------------------------------------- 261 + # long long pce_get_time_unix (void) 262 + #----------------------------------------------------------------------------- 263 + pce_get_time_unix: 264 + li %r3, PCE_HOOK_GET_TIME_UNIX 265 + hook 266 + 267 + cmpwi %r3, 0 268 + bne 1f 269 + 270 + mr %r3, %r4 271 + mr %r4, %r5 272 + blr 273 + 1: 274 + li %r3, 0 275 + li %r4, 0 276 + blr 277 + 278 + 279 + #----------------------------------------------------------------------------- 280 + # int pce_read_open (const char *str) 281 + #----------------------------------------------------------------------------- 282 + pce_read_open: 283 + mflr %r0 284 + stwu %r1, -8(%r1) 285 + stw %r0, 12(%r1) 286 + 287 + bl pce_puts0 288 + cmpwi %r3, 0 289 + bne 1f 290 + 291 + li %r3, PCE_HOOK_READ_OPEN 292 + hook 293 + 1: 294 + lwz %r0, 12(%r1) 295 + mtlr %r0 296 + addi %r1, %r1, 8 297 + blr 298 + 299 + 300 + #----------------------------------------------------------------------------- 301 + # int pce_read_close (void) 302 + #----------------------------------------------------------------------------- 303 + pce_read_close: 304 + li %r3, PCE_HOOK_READ_CLOSE 305 + hook 306 + blr 307 + 308 + 309 + #----------------------------------------------------------------------------- 310 + # int pce_read16 (void *buf) 311 + #----------------------------------------------------------------------------- 312 + pce_read16: 313 + mr %r8, %r3 # buf 314 + 315 + li %r4, 0 316 + li %r5, 0 317 + li %r6, 0 318 + li %r7, 0 319 + 320 + li %r3, PCE_HOOK_READ 321 + hook 322 + 323 + stw %r4, 0(%r8) 324 + stw %r5, 4(%r8) 325 + stw %r6, 8(%r8) 326 + stw %r7, 12(%r8) 327 + 328 + blr 329 + 330 + 331 + #----------------------------------------------------------------------------- 332 + # int pce_write_open (const char *str) 333 + #----------------------------------------------------------------------------- 334 + pce_write_open: 335 + mflr %r0 336 + stwu %r1, -8(%r1) 337 + stw %r0, 12(%r1) 338 + 339 + bl pce_puts0 340 + cmpwi %r3, 0 341 + bne 1f 342 + 343 + li %r3, PCE_HOOK_WRITE_OPEN 344 + hook 345 + 1: 346 + lwz %r0, 12(%r1) 347 + mtlr %r0 348 + addi %r1, %r1, 8 349 + blr 350 + 351 + 352 + #----------------------------------------------------------------------------- 353 + # int pce_write_close (void) 354 + #----------------------------------------------------------------------------- 355 + pce_write_close: 356 + li %r3, PCE_HOOK_WRITE_CLOSE 357 + hook 358 + blr 359 + 360 + 361 + #----------------------------------------------------------------------------- 362 + # int pce_write16 (void *buf, unsigned cnt) 363 + #----------------------------------------------------------------------------- 364 + pce_write16: 365 + mr %r8, %r4 # cnt 366 + 367 + lwz %r4, 0(%r3) 368 + lwz %r5, 4(%r3) 369 + lwz %r6, 8(%r3) 370 + lwz %r7, 12(%r3) 371 + 372 + li %r3, PCE_HOOK_WRITE 373 + hook 374 + 375 + blr
+54
src/arch/sim405/pceutils/pce.h
··· 1 + /***************************************************************************** 2 + * pce * 3 + *****************************************************************************/ 4 + 5 + /***************************************************************************** 6 + * File name: pce.h * 7 + * Created: 2018-12-22 by Hampa Hug <hampa@hampa.ch> * 8 + * Copyright: (C) 2018 Hampa Hug <hampa@hampa.ch> * 9 + *****************************************************************************/ 10 + 11 + /***************************************************************************** 12 + * This program is free software. You can redistribute it and / or modify it * 13 + * under the terms of the GNU General Public License version 2 as published * 14 + * by the Free Software Foundation. * 15 + * * 16 + * This program is distributed in the hope that it will be useful, but * 17 + * WITHOUT ANY WARRANTY, without even the implied warranty of * 18 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General * 19 + * Public License for more details. * 20 + *****************************************************************************/ 21 + 22 + 23 + #ifndef PCEUTILS_PCE_H 24 + #define PCEUTILS_PCE_H 1 25 + 26 + 27 + int pce_check (void); 28 + int pce_get_version (unsigned *p); 29 + int pce_get_version_str (char *str, unsigned max); 30 + 31 + int pce_init (void); 32 + int pce_putc (int c); 33 + int pce_putc0 (int c); 34 + int pce_puts (const char *s); 35 + int pce_puts0 (const char *s); 36 + int pce_getc (void); 37 + 38 + void pce_stop (void); 39 + void pce_abort (void); 40 + 41 + int pce_set_msg (const char *msg, const char *val); 42 + 43 + long long pce_get_time_unix (void); 44 + 45 + int pce_read_open (const char *s); 46 + int pce_read_close (void); 47 + int pce_read16 (void *buf); 48 + 49 + int pce_write_open (const char *s); 50 + int pce_write_close (void); 51 + int pce_write16 (void *buf, unsigned cnt); 52 + 53 + 54 + #endif
+381
src/arch/sim405/pceutils/pcecp.c
··· 1 + /***************************************************************************** 2 + * pce * 3 + *****************************************************************************/ 4 + 5 + /***************************************************************************** 6 + * File name: pcecp.c * 7 + * Created: 2018-12-22 by Hampa Hug <hampa@hampa.ch> * 8 + * Copyright: (C) 2018 Hampa Hug <hampa@hampa.ch> * 9 + *****************************************************************************/ 10 + 11 + /***************************************************************************** 12 + * This program is free software. You can redistribute it and / or modify it * 13 + * under the terms of the GNU General Public License version 2 as published * 14 + * by the Free Software Foundation. * 15 + * * 16 + * This program is distributed in the hope that it will be useful, but * 17 + * WITHOUT ANY WARRANTY, without even the implied warranty of * 18 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General * 19 + * Public License for more details. * 20 + *****************************************************************************/ 21 + 22 + 23 + #include <stdio.h> 24 + #include <stdlib.h> 25 + #include <time.h> 26 + 27 + #include "config.h" 28 + #include "pce.h" 29 + 30 + 31 + #define BUFMAX 16384 32 + 33 + 34 + const char *arg0 = NULL; 35 + 36 + static char par_verbose = 0; 37 + static char par_write = 0; 38 + static char par_std = 0; 39 + static char par_endarg = 0; 40 + 41 + static char *par_src = NULL; 42 + static char *par_dst = NULL; 43 + 44 + static unsigned char par_buf[BUFMAX]; 45 + 46 + 47 + static 48 + void print_help (void) 49 + { 50 + fputs ( 51 + "pcecp: copy files to/from the host\n" 52 + "\n" 53 + "usage: pcecp [options] [src [dst]]\n" 54 + " -c Use stdin/stdout instead of a guest file [no]\n" 55 + " -h Print help\n" 56 + " -i Copy a file from the host to the guest [default]\n" 57 + " -o Copy a file from the guest to the host\n" 58 + " -v Verbose operation [no]\n" 59 + " -V Print version\n", 60 + stdout 61 + ); 62 + 63 + fflush (stdout); 64 + } 65 + 66 + static 67 + void print_version (void) 68 + { 69 + fputs ("pcecp version " PCEUTILS_VERSION_STR "\n", stdout); 70 + fflush (stdout); 71 + } 72 + 73 + static 74 + int pce_copy_in_fp (const char *inp, FILE *out) 75 + { 76 + int r; 77 + unsigned cnt; 78 + unsigned long total; 79 + time_t t1, t2; 80 + 81 + if (pce_read_open (inp)) { 82 + fprintf (stderr, "%s: error opening host file (%s)\n", 83 + arg0, inp 84 + ); 85 + 86 + return (1); 87 + } 88 + 89 + t1 = time (NULL); 90 + 91 + total = 0; 92 + cnt = 0; 93 + 94 + while (1) { 95 + r = pce_read16 (par_buf + cnt); 96 + 97 + if (r <= 0) { 98 + if (r < 0) { 99 + fprintf (stderr, "%s: read error\n", arg0); 100 + } 101 + 102 + break; 103 + } 104 + 105 + cnt += r; 106 + 107 + if (cnt >= BUFMAX) { 108 + total += cnt; 109 + 110 + if (par_verbose) { 111 + t2 = time (NULL); 112 + 113 + if (t1 != t2) { 114 + fprintf (stderr, "%lu KiB read\r", 115 + total / 1024 116 + ); 117 + 118 + t1 = t2; 119 + } 120 + } 121 + 122 + if (fwrite (par_buf, 1, cnt, out) != cnt) { 123 + fprintf (stderr, "%s: write error\n", arg0); 124 + return (1); 125 + } 126 + 127 + cnt = 0; 128 + } 129 + } 130 + 131 + if (cnt > 0) { 132 + total += cnt; 133 + 134 + if (fwrite (par_buf, 1, cnt, out) != cnt) { 135 + fprintf (stderr, "%s: write error\n", arg0); 136 + return (1); 137 + } 138 + } 139 + 140 + pce_read_close(); 141 + 142 + fflush (out); 143 + 144 + if (par_verbose) { 145 + fprintf (stderr, "%lu bytes read\n", total); 146 + } 147 + 148 + return (0); 149 + } 150 + 151 + static 152 + int pce_copy_in (const char *inp, const char *out, int std) 153 + { 154 + int r; 155 + FILE *fp; 156 + 157 + if (std) { 158 + fp = stdout; 159 + } 160 + else { 161 + fp = fopen (out, "wb"); 162 + } 163 + 164 + if (fp == NULL) { 165 + fprintf (stderr, "%s: error opening local file (%s)\n", 166 + arg0, out 167 + ); 168 + 169 + return (1); 170 + } 171 + 172 + r = pce_copy_in_fp (inp, fp); 173 + 174 + if (fp != stdout) { 175 + fclose (fp); 176 + } 177 + 178 + return (r); 179 + } 180 + 181 + static 182 + int pce_copy_out_fp (FILE *inp, const char *out) 183 + { 184 + int r; 185 + unsigned idx, cnt, n; 186 + unsigned long total; 187 + time_t t1, t2; 188 + 189 + if (pce_write_open (out)) { 190 + fprintf (stderr, "%s: error opening host file (%s)\n", 191 + arg0, out 192 + ); 193 + 194 + return (1); 195 + } 196 + 197 + t1 = time (NULL); 198 + 199 + total = 0; 200 + idx = 0; 201 + cnt = 0; 202 + 203 + while (1) { 204 + if (idx >= cnt) { 205 + if (par_verbose) { 206 + t2 = time (NULL); 207 + 208 + if (t1 != t2) { 209 + fprintf (stderr, "%lu KiB written\r", 210 + total / 1024 211 + ); 212 + 213 + t1 = t2; 214 + } 215 + } 216 + 217 + idx = 0; 218 + cnt = fread (par_buf, 1, BUFMAX, inp); 219 + 220 + if (cnt == 0) { 221 + break; 222 + } 223 + } 224 + 225 + n = cnt - idx; 226 + 227 + if (n > 16) { 228 + n = 16; 229 + } 230 + 231 + r = pce_write16 (par_buf + idx, n); 232 + 233 + if (r <= 0) { 234 + if (r < 0) { 235 + fprintf (stderr, "%s: write error\n", arg0); 236 + } 237 + 238 + break; 239 + } 240 + 241 + idx += r; 242 + total += r; 243 + } 244 + 245 + pce_write_close(); 246 + 247 + if (par_verbose) { 248 + fprintf (stderr, "%lu bytes written\n", total); 249 + } 250 + 251 + return (0); 252 + } 253 + 254 + static 255 + int pce_copy_out (const char *inp, const char *out, int std) 256 + { 257 + int r; 258 + FILE *fp; 259 + 260 + if (std) { 261 + fp = stdin; 262 + } 263 + else { 264 + fp = fopen (inp, "rb"); 265 + } 266 + 267 + if (fp == NULL) { 268 + fprintf (stderr, "%s: error opening local file (%s)\n", 269 + arg0, inp 270 + ); 271 + 272 + return (1); 273 + } 274 + 275 + r = pce_copy_out_fp (fp, out); 276 + 277 + if (fp != stdin) { 278 + fclose (fp); 279 + } 280 + 281 + return (r); 282 + } 283 + 284 + static 285 + int args (int *argi, char **argv) 286 + { 287 + const char *s; 288 + 289 + s = argv[*argi] + 1; 290 + 291 + while (*s != 0) { 292 + if (*s == 'c') { 293 + par_std = 1; 294 + } 295 + else if (*s == 'h') { 296 + print_help(); 297 + exit (0); 298 + } 299 + else if (*s == 'i') { 300 + par_write = 0; 301 + } 302 + else if (*s == 'o') { 303 + par_write = 1; 304 + } 305 + else if (*s == 'v') { 306 + par_verbose = 1; 307 + } 308 + else if (*s == 'V') { 309 + print_version(); 310 + exit (0); 311 + } 312 + else { 313 + fprintf (stderr, "%s: unknown option (%s)\n", arg0, s); 314 + return (1); 315 + } 316 + 317 + s += 1; 318 + } 319 + 320 + return (0); 321 + } 322 + 323 + int main (int argc, char **argv) 324 + { 325 + int i, r; 326 + 327 + arg0 = argv[0]; 328 + 329 + if (pce_check()) { 330 + fprintf (stderr, "%s: not running under pce\n", arg0); 331 + return (1); 332 + } 333 + 334 + i = 1; 335 + 336 + while (i < argc) { 337 + if ((argv[i][0] == '-') && (par_endarg == 0)) { 338 + if ((argv[i][1] == '-') && (argv[i][2] == 0)) { 339 + par_endarg = 1; 340 + } 341 + else if (args (&i, argv)) { 342 + return (1); 343 + } 344 + } 345 + else { 346 + if (par_src == NULL) { 347 + par_src = argv[i]; 348 + } 349 + else if (par_dst == NULL) { 350 + par_dst = argv[i]; 351 + } 352 + else { 353 + return (1); 354 + } 355 + } 356 + 357 + i += 1; 358 + } 359 + 360 + if (par_src == NULL) { 361 + print_help(); 362 + return (0); 363 + } 364 + 365 + if (par_dst == NULL) { 366 + par_dst = par_src; 367 + } 368 + 369 + if (par_write) { 370 + r = pce_copy_out (par_src, par_dst, par_std); 371 + } 372 + else { 373 + r = pce_copy_in (par_src, par_dst, par_std); 374 + } 375 + 376 + if (r) { 377 + return (1); 378 + } 379 + 380 + return (0); 381 + }
+123
src/arch/sim405/pceutils/pcemsg.c
··· 1 + /***************************************************************************** 2 + * pce * 3 + *****************************************************************************/ 4 + 5 + /***************************************************************************** 6 + * File name: pcemsg.c * 7 + * Created: 2018-12-23 by Hampa Hug <hampa@hampa.ch> * 8 + * Copyright: (C) 2018 Hampa Hug <hampa@hampa.ch> * 9 + *****************************************************************************/ 10 + 11 + /***************************************************************************** 12 + * This program is free software. You can redistribute it and / or modify it * 13 + * under the terms of the GNU General Public License version 2 as published * 14 + * by the Free Software Foundation. * 15 + * * 16 + * This program is distributed in the hope that it will be useful, but * 17 + * WITHOUT ANY WARRANTY, without even the implied warranty of * 18 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General * 19 + * Public License for more details. * 20 + *****************************************************************************/ 21 + 22 + 23 + #include <stdio.h> 24 + 25 + #include "config.h" 26 + #include "pce.h" 27 + 28 + 29 + const char *arg0 = NULL; 30 + 31 + 32 + static 33 + void print_help (void) 34 + { 35 + fputs ( 36 + "pcemsg: send messages to the emulator\n" 37 + "\n" 38 + "usage: pcemsg [options] message [arg]\n" 39 + " -h Print help\n" 40 + " -V Print version information\n", 41 + stdout 42 + ); 43 + 44 + fflush (stdout); 45 + } 46 + 47 + static 48 + void print_version (void) 49 + { 50 + fputs ("pcemsg version " PCEUTILS_VERSION_STR "\n", stdout); 51 + fflush (stdout); 52 + } 53 + 54 + int main (int argc, char **argv) 55 + { 56 + int i; 57 + const char *s; 58 + const char *msg, *val; 59 + 60 + arg0 = argv[0]; 61 + 62 + msg = NULL; 63 + val = NULL; 64 + 65 + i = 1; 66 + while (i < argc) { 67 + if (argv[i][0] == '-') { 68 + s = argv[i] + 1; 69 + 70 + while (*s != 0) { 71 + if (*s == 'h') { 72 + print_help(); 73 + return (0); 74 + } 75 + else if (*s == 'V') { 76 + print_version(); 77 + return (0); 78 + } 79 + else { 80 + fprintf (stderr, 81 + "%s: unknown option (%s)\n", 82 + arg0, argv[i] 83 + ); 84 + 85 + return (1); 86 + } 87 + 88 + s += 1; 89 + } 90 + } 91 + else if (msg == NULL) { 92 + msg = argv[i]; 93 + } 94 + else if (val == NULL) { 95 + val = argv[i]; 96 + } 97 + else { 98 + fprintf (stderr, "%s: too many arguments (%s)\n", 99 + arg0, argv[i] 100 + ); 101 + 102 + return (1); 103 + } 104 + 105 + i += 1; 106 + } 107 + 108 + if (msg == NULL) { 109 + print_help(); 110 + return (1); 111 + } 112 + 113 + if (val == NULL) { 114 + val = ""; 115 + } 116 + 117 + if (pce_set_msg (msg, val)) { 118 + fprintf (stderr, "error\n"); 119 + return (1); 120 + } 121 + 122 + return (0); 123 + }
+145
src/arch/sim405/pceutils/pcetime.c
··· 1 + /***************************************************************************** 2 + * pce * 3 + *****************************************************************************/ 4 + 5 + /***************************************************************************** 6 + * File name: pcetime.c * 7 + * Created: 2018-12-23 by Hampa Hug <hampa@hampa.ch> * 8 + * Copyright: (C) 2018 Hampa Hug <hampa@hampa.ch> * 9 + *****************************************************************************/ 10 + 11 + /***************************************************************************** 12 + * This program is free software. You can redistribute it and / or modify it * 13 + * under the terms of the GNU General Public License version 2 as published * 14 + * by the Free Software Foundation. * 15 + * * 16 + * This program is distributed in the hope that it will be useful, but * 17 + * WITHOUT ANY WARRANTY, without even the implied warranty of * 18 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General * 19 + * Public License for more details. * 20 + *****************************************************************************/ 21 + 22 + 23 + #include <stdio.h> 24 + #include <time.h> 25 + #include <sys/time.h> 26 + 27 + #include "config.h" 28 + #include "pce.h" 29 + 30 + 31 + const char *arg0 = NULL; 32 + 33 + static char par_print = 0; 34 + static char par_set = 0; 35 + 36 + 37 + static 38 + void print_help (void) 39 + { 40 + fputs ( 41 + "pcetime: get the time from the host\n" 42 + "\n" 43 + "usage: pcetime [options]\n" 44 + " -h Print help\n" 45 + " -p Print the current host time\n" 46 + " -s Set the system time to the current host time\n" 47 + " -V Print version\n", 48 + stdout 49 + ); 50 + } 51 + 52 + static 53 + void print_version (void) 54 + { 55 + fputs ("pcetime version " PCEUTILS_VERSION_STR "\n", stdout); 56 + fflush (stdout); 57 + } 58 + 59 + int main (int argc, char **argv) 60 + { 61 + int i; 62 + const char *s; 63 + time_t val; 64 + 65 + arg0 = argv[0]; 66 + 67 + if (pce_check()) { 68 + fprintf (stderr, "%s: not running under pce\n", arg0); 69 + return (1); 70 + } 71 + 72 + i = 1; 73 + while (i < argc) { 74 + if (argv[i][0] == '-') { 75 + s = argv[i] + 1; 76 + while (*s != 0) { 77 + if (*s == 'h') { 78 + print_help(); 79 + return (0); 80 + } 81 + else if (*s == 'p') { 82 + par_print = 1; 83 + } 84 + else if (*s == 's') { 85 + par_set = 1; 86 + } 87 + else if (*s == 'V') { 88 + print_version(); 89 + return (0); 90 + } 91 + else { 92 + fprintf (stderr, 93 + "%s: unknown option (%s)\n", 94 + arg0, argv[i] 95 + ); 96 + 97 + return (1); 98 + } 99 + 100 + s += 1; 101 + } 102 + } 103 + else { 104 + fprintf (stderr, "%s: unknown option (%s)\n", 105 + arg0, argv[i] 106 + ); 107 + 108 + return (1); 109 + } 110 + 111 + i += 1; 112 + } 113 + 114 + if ((par_print == 0) && (par_set == 0)) { 115 + print_help(); 116 + return (0); 117 + } 118 + 119 + val = (time_t) pce_get_time_unix(); 120 + 121 + if (par_print) { 122 + struct tm *tm; 123 + 124 + tm = gmtime (&val); 125 + 126 + printf ("%04d-%02d-%02d %02d:%02d:%02d UTC\n", 127 + tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, 128 + tm->tm_hour, tm->tm_min, tm->tm_sec 129 + ); 130 + } 131 + 132 + if (par_set) { 133 + struct timeval tv; 134 + 135 + tv.tv_sec = val; 136 + tv.tv_usec = 0; 137 + 138 + if (settimeofday (&tv, NULL)) { 139 + fprintf (stderr, "%s: error setting time\n", arg0); 140 + return (1); 141 + } 142 + } 143 + 144 + return (0); 145 + }
+57
src/arch/sim405/pceutils/pcever.c
··· 1 + /***************************************************************************** 2 + * pce * 3 + *****************************************************************************/ 4 + 5 + /***************************************************************************** 6 + * File name: pcever.c * 7 + * Created: 2018-12-22 by Hampa Hug <hampa@hampa.ch> * 8 + * Copyright: (C) 2018 Hampa Hug <hampa@hampa.ch> * 9 + *****************************************************************************/ 10 + 11 + /***************************************************************************** 12 + * This program is free software. You can redistribute it and / or modify it * 13 + * under the terms of the GNU General Public License version 2 as published * 14 + * by the Free Software Foundation. * 15 + * * 16 + * This program is distributed in the hope that it will be useful, but * 17 + * WITHOUT ANY WARRANTY, without even the implied warranty of * 18 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General * 19 + * Public License for more details. * 20 + *****************************************************************************/ 21 + 22 + 23 + #include <stdio.h> 24 + 25 + #include "config.h" 26 + #include "pce.h" 27 + 28 + 29 + const char *arg0 = NULL; 30 + 31 + 32 + int main (int argc, char **argv) 33 + { 34 + unsigned ver[3]; 35 + char str[256]; 36 + 37 + arg0 = argv[0]; 38 + 39 + if (pce_check()) { 40 + fprintf (stderr, "%s: not running under pce\n", arg0); 41 + return (1); 42 + } 43 + 44 + if (pce_get_version (ver)) { 45 + fprintf (stderr, "%s: can't get version\n", arg0); 46 + return (1); 47 + } 48 + 49 + if (pce_get_version_str (str, sizeof (str))) { 50 + fprintf (stderr, "%s: can't get version string\n", arg0); 51 + return (1); 52 + } 53 + 54 + printf ("%s\n", str); 55 + 56 + return (0); 57 + }