8-Bit Software Online Conversion

/* fahr.c 17-Dec-88 A.J.Travis */ /* * print Fahrenheit-Celsius table * ------------------------------ * Adapted from the tutorial example in Kernighan and Ritchie * to show how fixed-point arithmetic can be used in Small-C. */ #include <stdio.h> #define SCALE 10 /* fixed-point scale */ main() { int lower, upper, step; int fahr, celsius; int integer, fraction; lower = 0; /* lower limit of temperature table */ upper = 300; /* upper limit */ step = 20; /* step size */ fahr = lower; while (fahr <= upper) { celsius = (SCALE * 5 * (fahr - 32)) / 9; integer = celsius / SCALE; if ((fraction = celsius % SCALE) < 0) fraction = -fraction; printf("%4d %4d.%1d\n", fahr, integer, fraction); fahr = fahr + step; } } /* cmp.c - 19 Apr 88 A.J.Travis */ /* * Simple file comparison */ #include <stdio.h> char buf1[BUFSIZ]; char buf2[BUFSIZ]; char *bp1, *bp2; int c1, c2; int fd1, fd2; int n1, n2; int n; main(argc, argv) int argc; char *argv[]; { if (argc != 3) { fprintf(stderr, "usage: cmp file1 file2\n"); exit(-1); } if ((fd1 = open(argv[1], 0)) == -1) { fprintf(stderr, "cmp: can't open %s\n", argv[1]); exit(-1); } if ((fd2 = open(argv[2], 0)) == -1) { fprintf(stderr, "cmp: can't open %s\n", argv[2]); close(fd1); exit(-1); } n = 0; do { n1 = read(fd1, buf1, BUFSIZ); n2 = read(fd2, buf2, BUFSIZ); bp1 = buf1; bp2 = buf2; while ((bp1 < buf1 + n1) & (bp2 < buf2 + n2)) { if ((c1 = *bp1++ & 0xFF) != (c2 = *bp2++ & 0xFF)) printf("%4X: %02X %02X\n", n, c1, c2); n++; } if (n1 < n2) printf("cmp: end of file on %s\n", argv[1]); if (n1 > n2) printf("cmp: end of file on %s\n", argv[2]); } while (n1 > 0 & n1 == n2); close(fd1); close(fd2); } /* hanoi.c 19-Nov-88 Modified by A.J.Travis */ /* * Towers of Hanoi in Small-C by Jon Welch * --------------------------------------- * The program should be run in mode 2, and * shows the disks in 7 different colours. */ #include <stdio.h> int j, n; int one, two, three; main() { printf("\f\nHeight (0-12): "); scanf("%d", &n); if (n > 12) n = 12; j = n; while (j > 0) { box((j % 7) + 1, 200, (n - j + 1) * 40, j * 16); j = j - 1; } one = n * 40; two = 0; three = 0; hanoi(n, 1, 2, 3); } up(x) int x; { if (x == 1) one = one + 40; else if (x == 2) two = two + 40; else three = three + 40; } down(x) int x; { if (x == 1) one = one - 40; else if (x == 2) two = two - 40; else three = three - 40; } height(x) int x; { if (x == 1) return(one); else if (x == 2) return(two); else return(three); } bytes(x) int x; { vdu(x); vdu(x >> 8); } box(col, x, y, size) int col, x, y, size; { vdu(18); vdu(0); vdu(col + 128); vdu(24); bytes(x - size); bytes(y); bytes(x + size); bytes(y + 20); vdu(16); } move(n, s, e) int n, s, e ; { box(0, s * 400 - 200, height(s), n * 16); down(s); up(e); box((n % 7) + 1, e * 400 - 200, height(e), n * 16); } hanoi(a, b, c, d) int a, b, c, d; { if (a != 0) { hanoi(a - 1, b, d, c); move(a, b, c); hanoi(a - 1, d, c, b); } }