Commit | Line | Data |
---|---|---|
919757fd PH |
1 | |
2 | #include <stdio.h> | |
3 | #include "structures.h" | |
4 | #include "ops.h" | |
5 | ||
6 | /* | |
7 | * Pack an OS/8 filename into 6 bit code, 2 digits per 12 bit word. | |
8 | * Argument is a zero-terminated string, containing the full name with | |
9 | * the dot, i.E. "XXXXXX.YY",0 is the legal form. | |
10 | */ | |
11 | void os8_file_name_pack(os8_file_name_t * filename, char * data){ | |
12 | ||
13 | /* Read and write positions */ | |
14 | int inpos=0, outpos=0; | |
15 | ||
16 | /* Zero out all data in target */ | |
17 | for (outpos=0; outpos<4; outpos++) filename->data[outpos]=0; | |
18 | ||
19 | for (outpos=0; outpos<8 && data[inpos];){ | |
20 | if (data[inpos]=='.'){ | |
21 | inpos++; | |
22 | if (outpos<6) outpos=6; | |
23 | continue; | |
24 | } | |
25 | filename->data[outpos/2] |= os8_ascii2pdp(data[inpos++]) << ((!(outpos%2))*6); | |
26 | outpos++; | |
27 | } | |
28 | } | |
29 | ||
30 | void os8_file_name_extract(os8_file_name_t * filename, char * data){ | |
31 | ||
32 | /* Read and write positions */ | |
33 | int inpos=0, outpos=0; | |
34 | ||
35 | for (inpos=0; inpos<8; inpos++){ | |
36 | ||
37 | unsigned short int current=filename->data[inpos/2]; /* Get right word */ | |
38 | if (!(inpos%2)) current >>= 6; | |
39 | current &= 077; | |
40 | ||
41 | if ((!current) && ((inpos==0)||(inpos==6))){ /* Empty file name or extension*/ | |
42 | data[outpos]=0; /* Terminate file name in buffer */ | |
43 | break; /* Leave the loop! */ | |
44 | } | |
45 | ||
46 | if (inpos==6){ | |
47 | data[outpos++]='.'; /* Insert dot into new name */ | |
48 | } | |
49 | ||
50 | if (current) { /* Insert character into output */ | |
51 | data[outpos++]=os8_pdp2ascii(current); | |
52 | } | |
53 | } | |
54 | data[outpos]=0; /* Terminate string. */ | |
55 | } | |
56 | ||
57 | /* Pack one character into 6 bit OS/8 reduced ASCII code */ | |
58 | unsigned char os8_ascii2pdp(unsigned char inchar){ | |
59 | unsigned char result=inchar & 077; /* Strip upper bits */ | |
60 | return result; | |
61 | } | |
62 | ||
63 | /* Extract one character from 6 bit OS/8 reduced ASCII code */ | |
64 | unsigned char os8_pdp2ascii(unsigned char inchar){ | |
65 | inchar &=077; | |
66 | if (inchar<040) return inchar|0100; | |
67 | return inchar; | |
68 | } | |
69 | ||
70 | /* Negate a p8word */ | |
71 | p8word p8_neg(p8word in){ | |
72 | return (-in)&07777; | |
73 | } | |
74 | ||
75 | /* Twist the bytes for little endian machines */ | |
76 | p8word p8_twist(p8word in){ | |
77 | return (in&0xff)<<8 | ((in>>8)&0xff); | |
78 | } | |
79 | ||
80 | ||
81 | ||
82 | ||
83 | ||
84 |