-
Notifications
You must be signed in to change notification settings - Fork 1
/
storchar.c
48 lines (45 loc) · 1.28 KB
/
storchar.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/* storchar.c (acdc) - copyright Mike Arnautov 1990-2018.
* Licensed under GPL, version 3 or later (see the supplied LICENCE file).
*
* 03 Mar 16 MLA Removed non-ANSI C support.
* 31 Jul 09 MLA BUG: text file screwed up in plain mode!
* 09 Mar 03 MLA Store as binary or ASCII data depending on
* value of memory.
* 03 Mar 03 MLA Store as ASCII data.
* 24 Jul 99 MLA Fixed complier warnings.
* 15 Sep 90 MLA Initial coding.
*
*/
#include "text.h"
#include "game.h"
void storchar (int ch)
{
/* ch &= 255; */
if (plain_text)
{
if (memory == 3)
fprintf (text_file,"%s%d",
(next_addr + 1) % 16 == 0 ? ",\n" : ",", ch);
else
fputc(ch, text_file);
}
else
{
int mask;
if (*(++gameid_ptr) == '\0')
gameid_ptr = gameid;
mask = (next_addr >> 4) & 127;
if (mask == 0)
mask = next_addr & 127;
if (mask == 0)
mask = 'X';
mask = (17 * mask + 13) & 127;
if (memory == 3)
fprintf (text_file, "%s%d",
(next_addr + 1) % 16 == 0 ? ",\n" : ",", ch ^ *gameid_ptr ^ mask);
else
fputc(ch ^ *gameid_ptr ^ mask, text_file);
}
next_addr++;
return;
}