📄 jbimain.c
字号:
IF_CHECK_STACK(2)
{
long_index = stack[--stack_ptr];
long_count = stack[--stack_ptr];
reverse = 0;
if (version > 0)
{
/* stack 0 = array right index */
/* stack 1 = array left index */
/* stack 2 = count */
long_temp = long_count;
long_count = stack[--stack_ptr];
if (long_index > long_temp)
{
reverse = 1;
long_index = long_temp;
}
}
#if PORT==DOS
if (((long_index & 0xFFFF0000) == 0) &&
((long_count & 0xFFFF0000) == 0))
{
variable_id = (unsigned int) args[0];
if ((attributes[variable_id] & 0x1e) == 0x0e)
{
/* initialized compressed Boolean array */
jbi_uncompress_page(variable_id,
(int) (long_index >> 16), version);
long_index &= 0x0000ffff;
charptr_temp = jbi_aca_out_buffer;
}
else
{
charptr_temp = (unsigned char *) variables[variable_id];
}
if (reverse)
{
/* allocate a buffer and reverse the data order */
charptr_temp2 = charptr_temp;
charptr_temp = jbi_malloc((unsigned int)
((long_count >> 3L) + 1L));
if (charptr_temp == NULL)
{
status = JBIC_OUT_OF_MEMORY;
break;
}
else
{
long_temp = long_index + long_count - 1;
long_index2 = 0;
while (long_index2 < long_count)
{
if (charptr_temp2[long_temp >> 3] &
(1 << (long_temp & 7)))
{
charptr_temp[long_index2 >> 3] |=
(1 << (long_index2 & 7));
}
else
{
charptr_temp[long_index2 >> 3] &=
~(1 << (long_index2 & 7));
}
--long_temp;
++long_index2;
}
}
}
if (opcode == 0x51) /* DS */
{
status = jbi_do_drscan((unsigned int) long_count,
charptr_temp, (unsigned long) long_index);
}
else /* IS */
{
status = jbi_do_irscan((unsigned int) long_count,
charptr_temp, (unsigned int) long_index);
}
if (reverse) jbi_free(charptr_temp);
}
else if ((opcode == 0x51) && !reverse)
{
status = jbi_do_drscan_multi_page(
(unsigned int) args[0],
(unsigned long) long_count,
(unsigned long) long_index, version);
}
else
{
/* reverse multi-page scans are not supported */
/* multi-page IR scans are not supported */
status = JBIC_BOUNDS_ERROR;
}
#else
charptr_temp = (unsigned char *) variables[args[0]];
if (reverse)
{
/* allocate a buffer and reverse the data order */
charptr_temp2 = charptr_temp;
charptr_temp = jbi_malloc((long_count >> 3) + 1);
if (charptr_temp == NULL)
{
status = JBIC_OUT_OF_MEMORY;
break;
}
else
{
long_temp = long_index + long_count - 1;
long_index2 = 0;
while (long_index2 < long_count)
{
if (charptr_temp2[long_temp >> 3] &
(1 << (long_temp & 7)))
{
charptr_temp[long_index2 >> 3] |=
(1 << (long_index2 & 7));
}
else
{
charptr_temp[long_index2 >> 3] &=
~(1 << (long_index2 & 7));
}
--long_temp;
++long_index2;
}
}
}
// printf("DS %ld, array[%ld..%ld]\n", long_count,
// long_count + long_index - 1, long_index);
if (opcode == 0x51) /* DS */
{
status = jbi_do_drscan((unsigned int) long_count,
charptr_temp, (unsigned long) long_index);
}
else /* IS */
{
status = jbi_do_irscan((unsigned int) long_count,
charptr_temp, (unsigned int) long_index);
}
#endif
if (reverse && (charptr_temp != NULL))
{
jbi_free(charptr_temp);
}
}
break;
case 0x53: /* DPRA */
/*
* DRPRE with array data
* ...argument 0 is variable ID
* ...stack 0 is array index
* ...stack 1 is count
*/
IF_CHECK_STACK(2)
{
index = (unsigned int) stack[--stack_ptr];
count = (unsigned int) stack[--stack_ptr];
if (version > 0)
{
/* stack 0 = array right index */
/* stack 1 = array left index */
count = 1 + count - index;
}
charptr_temp = (unsigned char *) variables[args[0]];
status = jbi_set_dr_preamble(count, index, charptr_temp);
}
break;
case 0x54: /* DPOA */
/*
* DRPOST with array data
* ...argument 0 is variable ID
* ...stack 0 is array index
* ...stack 1 is count
*/
IF_CHECK_STACK(2)
{
index = (unsigned int) stack[--stack_ptr];
count = (unsigned int) stack[--stack_ptr];
if (version > 0)
{
/* stack 0 = array right index */
/* stack 1 = array left index */
count = 1 + count - index;
}
charptr_temp = (unsigned char *) variables[args[0]];
status = jbi_set_dr_postamble(count, index, charptr_temp);
}
break;
case 0x55: /* IPRA */
/*
* IRPRE with array data
* ...argument 0 is variable ID
* ...stack 0 is array index
* ...stack 1 is count
*/
IF_CHECK_STACK(2)
{
index = (unsigned int) stack[--stack_ptr];
count = (unsigned int) stack[--stack_ptr];
if (version > 0)
{
/* stack 0 = array right index */
/* stack 1 = array left index */
count = 1 + count - index;
}
charptr_temp = (unsigned char *) variables[args[0]];
status = jbi_set_ir_preamble(count, index, charptr_temp);
}
break;
case 0x56: /* IPOA */
/*
* IRPOST with array data
* ...argument 0 is variable ID
* ...stack 0 is array index
* ...stack 1 is count
*/
IF_CHECK_STACK(2)
{
index = (unsigned int) stack[--stack_ptr];
count = (unsigned int) stack[--stack_ptr];
if (version > 0)
{
/* stack 0 = array right index */
/* stack 1 = array left index */
count = 1 + count - index;
}
charptr_temp = (unsigned char *) variables[args[0]];
status = jbi_set_ir_postamble(count, index, charptr_temp);
}
break;
case 0x57: /* EXPT */
/*
* EXPORT
* ...argument 0 is string ID
* ...stack 0 is integer expression
*/
IF_CHECK_STACK(1)
{
#if PORT==DOS
name_id = args[0];
for (j = 0; j < 32; ++j)
{
name[j] = GET_BYTE(string_table + name_id + j);
}
name[32] = '\0';
#else
name = (char *) &program[string_table + args[0]];
#endif
long_temp = stack[--stack_ptr];
jbi_export_integer(name, long_temp);
}
break;
case 0x58: /* PSHE */
/*
* Push integer array element
* ...argument 0 is variable ID
* ...stack 0 is array index
*/
IF_CHECK_STACK(1)
{
variable_id = (unsigned int) args[0];
index = (unsigned int) stack[stack_ptr - 1];
/* check variable type */
if ((attributes[variable_id] & 0x1f) == 0x19)
{
/* writable integer array */
longptr_temp = (long *) variables[variable_id];
stack[stack_ptr - 1] = longptr_temp[index];
}
else if ((attributes[variable_id] & 0x1f) == 0x1c)
{
/* read-only integer array */
long_temp = variables[variable_id] + (4L * index);
stack[stack_ptr - 1] = GET_DWORD(long_temp);
}
else
{
status = JBIC_BOUNDS_ERROR;
}
}
break;
case 0x59: /* PSHA */
/*
* Push Boolean array
* ...argument 0 is variable ID
* ...stack 0 is count
* ...stack 1 is array index
*/
IF_CHECK_STACK(2)
{
variable_id = (unsigned int) args[0];
/* check that variable is a Boolean array */
if ((attributes[variable_id] & 0x18) != 0x08)
{
status = JBIC_BOUNDS_ERROR;
}
else
{
charptr_temp = (unsigned char *) variables[variable_id];
/* pop the count (number of bits to copy) */
count = (unsigned int) stack[--stack_ptr];
/* pop the array index */
index = (unsigned int) stack[stack_ptr - 1];
if (version > 0)
{
/* stack 0 = array right index */
/* stack 1 = array left index */
count = 1 + count - index;
}
if ((count < 1) || (count > 32))
{
status = JBIC_BOUNDS_ERROR;
}
else
{
#if PORT==DOS
if ((attributes[variable_id] & 0x1e) == 0x0e)
{
/* initialized compressed Boolean array */
jbi_uncompress_page(variable_id,
(int) (stack[stack_ptr - 1] >> 16), version);
charptr_temp = jbi_aca_out_buffer;
}
#endif
long_temp = 0L;
for (i = 0; i < count; ++i)
{
if (charptr_temp[(i + index) >> 3] &
(1 << ((i + index) & 7)))
{
long_temp |= (1L << i);
}
}
stack[stack_ptr - 1] = long_temp;
}
}
}
break;
case 0x5A: /* DYNA */
/*
* Dynamically change size of array
* ...argument 0 is variable ID
* ...stack 0 is new size
*/
IF_CHECK_STACK(1)
{
variable_id = (unsigned int) args[0];
long_temp = stack[--stack_ptr];
if (long_temp > variable_size[variable_id])
{
variable_size[variable_id] = long_temp;
if (attributes[variable_id] & 0x10)
{
/* allocate integer array */
long_temp *= 4;
}
else
{
/* allocate Boolean array */
long_temp = (long_temp + 7) >> 3;
}
/*
* If the buffer was previously allocated, free it
*/
if ((attributes[variable_id] & 0x80) &&
(variables[variable_id] != NULL))
{
jbi_free((void *) variables[variable_id]);
variables[variable_id] = NULL;
}
/*
* Allocate a new buffer of the requested size
*/
variables[variable_id] = (long)
jbi_malloc((unsigned int) long_temp);
if (variables[variable_id] == NULL)
{
status = JBIC_OUT_OF_MEMORY;
}
else
{
/*
* Set the attribute bit to indicate that this buffer
* was dynamically allocated and should be freed later
*/
attributes[variable_id] |= 0x80;
/* zero out memory */
count = (unsigned int)
((variable_size[variable_id] + 7L) / 8L);
charptr_temp = (unsigned char *)
(variables[variable_id]);
for (index = 0; index < count; ++index)
{
charptr_temp[index] = 0;
}
}
}
}
break;
case 0x5B: /* EXPR */
bad_opcode = 1;
break;
case 0x5C: /* EXPV */
/*
* Export Boolean array
* ...argument 0 is string ID
* ...stack 0 is variable ID
* ...stack 1 is array right index
* ...stack 2 is array left index
*/
IF_CHECK_STACK(3)
{
if (version == 0)
{
/* EXPV is not supported in JBC 1.0 */
bad_opcode = 1;
break;
}
#if PORT==DOS
name_id = args[0];
for (j = 0; j < 32; ++j)
{
name[j] = GET_BYTE(string_table + name_id + j);
}
name[32] = '\0';
#else
name = (char *) &program[string_table + args[0]];
#endif
variable_id = (unsigned int) stack[--stack_ptr];
long_index = stack[--stack_ptr]; /* right index */
long_index2 = stack[--stack_ptr]; /* left index */
if (long_index > long_index2)
{
/* reverse indices not supported */
status = JBIC_BOUNDS_ERROR;
break;
}
long_count = 1 + long_index2 - long_index;
charptr_temp = (unsigned char *) variables[variable_id];
charptr_temp2 = NULL;
#if PORT==DOS
if ((attributes[variable_id] & 0x1e) == 0x0e)
{
/* initialized compressed Boolean array */
jbi_uncompress_page(variable_id,
(int) (long_index >> 16), version);
charptr_temp = jbi_aca_out_buffer;
long_index &= 0x0000FFFF;
}
#endif
if ((long_index & 7L) != 0)
{
charptr_temp2 = jbi_malloc((unsigned int)
((long_count + 7L) / 8L));
if (charptr_temp2 == NULL)
{
status = JBIC_OUT_OF_MEMORY;
break;
}
else
{
long k = long_index;
for (i = 0; i < (unsigned int) long_count; ++i)
{
if (charptr_temp[k >> 3] & (1 << (k & 7)))
{
charptr_temp2[i >> 3] |= (1 << (i & 7));
}
else
{
charptr_temp2[i >> 3] &= ~(1 << (i & 7));
}
++k;
}
charptr_temp = charptr_temp2;
}
}
else if (long_index != 0)
{
charptr_temp = &charptr_temp[long_index >> 3];
}
jbi_export_boolean_array(name, charptr_temp, long_count);
/* free allocated buffer */
if (((long_index & 7L) != 0) && (charptr_temp2 != NULL))
{
jbi_free(charptr_temp2);
}
}
break;
case 0x80: /* COPY */
/*
* Array copy
* ...argument 0 is dest ID
* ...argument 1 is source ID
* ...stack 0 is count
* ...stack 1 is dest index
* ...stack 2 is source index
*/
IF_CHECK_STACK(3)
{
long copy_count = stack[--stack_ptr];
long copy_index = stack[--stack_ptr];
long copy_index2 = stack[--stack_ptr];
long destleft;
long src_count;
long dest_count;
int src_reverse = 0;
int dest_reverse = 0;
reverse = 0;
if (version > 0)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -