Code: Select all
writefile "test" {
writeval (-1)
writeval (-2)
}
readfile "test" {
print number readval number readval
}
Can you guys please test on the official terp? Do you get the same result?
Moderators: Ice Cream Jonsey, joltcountry
Code: Select all
writefile "test" {
writeval (-1)
writeval (-2)
}
readfile "test" {
print number readval number readval
}
Does writing to file use a different type of encoding so something is lost in translation?VALUE (i.e., INTEGER CONSTANT):
<value> <2>
A value may range from -32768 to 32767; negative numbers follow signed-value
16-bit convention by being x + 65536 where x is a negative number.
For example, the values 10 ($0A), 16384 ($4000), and -2 would be written
as:
$4B 0A 00
$4B 00 40
$4B FE FF ($FFFE = 65534 = -2 + 65536)
Code: Select all
case WRITEVAL_T:
{
Writevalloop:
codeptr++;
i = GetValue();
#if !defined (MATH_16BIT)
if (i < 0)
i += 65536;
#endif
if (ioblock)
{
if ((ioblock==2)
|| fputc(i%256, io)==EOF
|| fputc(i/256, io)==EOF)
{
ioerror = true;
retflag = true;
break;
}
}
if (Peek(codeptr)==COMMA_T)
goto Writevalloop;
if (game_version>=23) codeptr++; /* eol */
break;
}
Code: Select all
case READVAL_T:
{
val = 0;
if (ioblock)
{
int low, high;
if ((ioblock==1)
|| (low = fgetc(io))==EOF
|| (high = fgetc(io))==EOF)
/* fscanf() caused trouble for non-ASCII values
(fscanf(io, "%c%c", &a, &b)==EOF) */
{
ioerror = true;
retflag = true;
}
else
{
i = low + high*256;
#if !defined (MATH_16BIT)
if (i > 32767)
i -= 65536;
#endif
val = i;
}
}
codeptr++;
break;
}