3 #include "structures.h"
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.
11 void os8_file_name_pack(os8_file_name_t
* filename
, char * data
){
13 /* Read and write positions */
14 int inpos
=0, outpos
=0;
16 /* Zero out all data in target */
17 for (outpos
=0; outpos
<4; outpos
++) filename
->data
[outpos
]=0;
19 for (outpos
=0; outpos
<8 && data
[inpos
];){
20 if (data
[inpos
]=='.'){
22 if (outpos
<6) outpos
=6;
25 filename
->data
[outpos
/2] |= os8_ascii2pdp(data
[inpos
++]) << ((!(outpos
%2))*6);
30 void os8_file_name_extract(os8_file_name_t
* filename
, char * data
){
32 /* Read and write positions */
33 int inpos
=0, outpos
=0;
35 for (inpos
=0; inpos
<8; inpos
++){
37 unsigned short int current
=filename
->data
[inpos
/2]; /* Get right word */
38 if (!(inpos
%2)) current
>>= 6;
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! */
47 data
[outpos
++]='.'; /* Insert dot into new name */
50 if (current
) { /* Insert character into output */
51 data
[outpos
++]=os8_pdp2ascii(current
);
54 data
[outpos
]=0; /* Terminate string. */
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 */
63 /* Extract one character from 6 bit OS/8 reduced ASCII code */
64 unsigned char os8_pdp2ascii(unsigned char inchar
){
66 if (inchar
<040) return inchar
|0100;
71 p8word
p8_neg(p8word in
){
75 /* Twist the bytes for little endian machines */
76 p8word
p8_twist(p8word in
){
77 return (in
&0xff)<<8 | ((in
>>8)&0xff);