OpenCBM
petscii.c
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version
5  * 2 of the License, or (at your option) any later version.
6  *
7  * Copyright 1999-2005 Michael Klein <michael(dot)klein(at)puffin(dot)lb(dot)shuttle(dot)de>
8  * Copyright 2001-2005 Spiro Trikaliotis
9  *
10  * Parts are Copyright
11  * Jouko Valta <jopi(at)stekt(dot)oulu(dot)fi>
12  * Andreas Boose <boose(at)linux(dot)rz(dot)fh-hannover(dot)de>
13 */
14 
24 #define DBG_USERMODE
25 
27 #define DBG_PROGNAME "OPENCBM.DLL"
28 
29 #include "debug.h"
30 
31 #include <ctype.h>
32 #include <stdlib.h>
33 
35 #define DLL
36 #include "opencbm.h"
37 
38 /*-------------------------------------------------------------------*/
39 /*--------- ASCII <-> PETSCII CONVERSION FUNCTIONS ------------------*/
40 /*
41  *
42  * These functions are taken from VICE's charset.c,
43  * Copyright
44  * Jouko Valta <jopi(at)stekt(dot)oulu(dot)fi>
45  * Andreas Boose <boose(at)linux(dot)rz(dot)fh-hannover(dot)de>
46  *
47  * You can get VICE from http://www.viceteam.org/
48  */
49 
63 char CBMAPIDECL
64 cbm_petscii2ascii_c(char Character)
65 {
66  switch (Character & 0xff) {
67  case 0x0a:
68  case 0x0d:
69  return '\n';
70  case 0x40:
71  case 0x60:
72  return Character;
73  case 0xa0: /* CBM: Shifted Space */
74  case 0xe0:
75  return ' ';
76  default:
77  switch (Character & 0xe0) {
78  case 0x40: /* 41 - 7E */
79  case 0x60:
80  return (Character ^ 0x20);
81 
82  case 0xc0: /* C0 - DF */
83  return (Character ^ 0x80);
84 
85  }
86  }
87 
88  return ((isprint(Character) ? Character : '.'));
89 }
90 
91 
104 char CBMAPIDECL
105 cbm_ascii2petscii_c(char Character)
106 {
107  if ((Character >= 0x5b) && (Character <= 0x7e))
108  {
109  return Character ^ 0x20;
110  }
111  else if ((Character >= 'A') && (Character <= 'Z')) /* C0 - DF */
112  {
113  return Character | 0x80;
114  }
115  return Character;
116 }
117 
118 
135 char * CBMAPIDECL
137 {
138  char *p;
139  for (p = Str; *p; p++)
140  {
141  *p = cbm_petscii2ascii_c(*p);
142  }
143  return Str;
144 }
145 
159 char * CBMAPIDECL
161 {
162  char *p;
163  for (p = Str; *p; p++)
164  {
165  *p = cbm_ascii2petscii_c(*p);
166  }
167  return Str;
168 }
Define makros for debugging purposes.
#define CBMAPIDECL
Definition: opencbm.h:85
char *CBMAPIDECL cbm_petscii2ascii(char *Str)
Convert an null-termined PETSCII string to ASCII.
Definition: petscii.c:136
char *CBMAPIDECL cbm_ascii2petscii(char *Str)
Convert an null-termined ASCII string to PETSCII.
Definition: petscii.c:160
char CBMAPIDECL cbm_petscii2ascii_c(char Character)
Convert a PETSCII character to ASCII.
Definition: petscii.c:64
DLL interface for accessing the driver.
char CBMAPIDECL cbm_ascii2petscii_c(char Character)
Convert an ASCII character to PETSCII.
Definition: petscii.c:105