|
Revision 11, 1.7 kB
(checked in by sven, 4 years ago)
|
|
The Windows backend works right now.
-- Sven @ XP Workstation
|
| Line | |
|---|
| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | #include <stdio.h> |
|---|
| 8 | #include <io.h> |
|---|
| 9 | #include <stdlib.h> |
|---|
| 10 | #include "backend.h" |
|---|
| 11 | |
|---|
| 12 | void puncher_frontend_visualize_byte(unsigned char buf) { |
|---|
| 13 | |
|---|
| 14 | unsigned char against = 0x01; |
|---|
| 15 | unsigned char check; |
|---|
| 16 | int pos; |
|---|
| 17 | |
|---|
| 18 | printf("|"); |
|---|
| 19 | for(pos=0; pos < 8; pos++) { |
|---|
| 20 | if(pos == 3) |
|---|
| 21 | printf("."); |
|---|
| 22 | check = buf; |
|---|
| 23 | check >>= pos; |
|---|
| 24 | |
|---|
| 25 | if((check & against) == 0) |
|---|
| 26 | printf(" "); |
|---|
| 27 | else |
|---|
| 28 | printf("*"); |
|---|
| 29 | } |
|---|
| 30 | printf("|"); |
|---|
| 31 | } |
|---|
| 32 | |
|---|
| 33 | |
|---|
| 34 | int main(int argc, char **argv) { |
|---|
| 35 | PuncherBackend *puncher; |
|---|
| 36 | int ret; |
|---|
| 37 | |
|---|
| 38 | printf("Paper Tape Project -- Windows user mode puncher\n"); |
|---|
| 39 | |
|---|
| 40 | puncher = puncher_backend_new(1); |
|---|
| 41 | |
|---|
| 42 | for(int xy=0;;xy++) { |
|---|
| 43 | unsigned char buf; |
|---|
| 44 | |
|---|
| 45 | ret = read(0, &buf, 1); |
|---|
| 46 | if(ret < 0) { |
|---|
| 47 | printf("HARD READ IN EROR\n"); |
|---|
| 48 | puncher_backend_destroy(puncher); |
|---|
| 49 | return 1; |
|---|
| 50 | } |
|---|
| 51 | |
|---|
| 52 | if(ret == 0) { |
|---|
| 53 | printf("EOF STDIN.\n"); |
|---|
| 54 | break; |
|---|
| 55 | } |
|---|
| 56 | |
|---|
| 57 | |
|---|
| 58 | puncher_frontend_visualize_byte(buf); |
|---|
| 59 | printf(" 0x%02x=%03i ", buf, buf); |
|---|
| 60 | |
|---|
| 61 | |
|---|
| 62 | ret = puncher_backend_write_byte(puncher, buf); |
|---|
| 63 | |
|---|
| 64 | if(ret < 0) { |
|---|
| 65 | printf("BACKEND HARD ERROR: calling write backend\n"); |
|---|
| 66 | puncher_backend_destroy(puncher); |
|---|
| 67 | return 1; |
|---|
| 68 | } else if(ret == 0) { |
|---|
| 69 | printf("=)\n"); |
|---|
| 70 | } else if(ret == 1) { |
|---|
| 71 | printf(":-(\n"); |
|---|
| 72 | } |
|---|
| 73 | } |
|---|
| 74 | |
|---|
| 75 | if(puncher_backend_destroy(puncher)) { |
|---|
| 76 | perror("finishing backend"); |
|---|
| 77 | return 1; |
|---|
| 78 | } else |
|---|
| 79 | return 0; |
|---|
| 80 | } |
|---|