⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jbimain.c

📁 microwindows移植到S3C44B0的源码
💻 C
📖 第 1 页 / 共 5 页
字号:
				name = (char *) &program[string_table + name_id];
#endif

				if (jbi_stricmp(action, name) == 0)
				{
					action_found = 1;
					current_proc = (int) GET_DWORD(action_table + (12 * i) + 8);
				}
			}

			if (!action_found)
			{
				status = JBIC_ACTION_NOT_FOUND;
				done = 1;
			}
		}

		if (status == JBIC_SUCCESS)
		{
			int first_time = 1;
			i = current_proc;
			while ((i != 0) || first_time)
			{
				first_time = 0;
				/* check procedure attribute byte */
				proc_attributes[i] = (unsigned char)
					(GET_BYTE(proc_table + (13 * i) + 8) & 0x03);

				if (proc_attributes[i] != 0)
				{
					/*
					*	BIT0 - OPTIONAL
					*	BIT1 - RECOMMENDED
					*	BIT6 - FORCED OFF
					*	BIT7 - FORCED ON
					*/
					if (init_list != NULL)
					{
						name_id = GET_DWORD(proc_table + (13 * i));
#if PORT==DOS
						for (j = 0; j < 32; ++j)
						{
							name[j] = GET_BYTE(string_table + name_id + j);
						}
						name[32] = '\0';
#else
						name = (char *) &program[string_table + name_id];
#endif
						count = 0;
						while (init_list[count] != NULL)
						{
							equal_ptr = init_list[count];
							length = 0;
							while ((*equal_ptr != '=') && (*equal_ptr != '\0'))
							{
								++equal_ptr;
								++length;
							}
							if (*equal_ptr == '=')
							{
								++equal_ptr;
								jbi_strncpy(message_buffer, init_list[count], length);
								message_buffer[length] = '\0';

								if (jbi_stricmp(message_buffer, name) == 0)
								{
									if (jbi_atol(equal_ptr) == 0)
									{
										proc_attributes[i] |= 0x40;
									}
									else
									{
										proc_attributes[i] |= 0x80;
									}
								}
							}

							++count;
						}
					}
				}

				i = (unsigned int) GET_DWORD(proc_table + (13 * i) + 4);
			}

			/*
			*	Set current_proc to the first procedure to be executed
			*/
			i = current_proc;
			while ((i != 0) &&
				((proc_attributes[i] == 1) ||
				((proc_attributes[i] & 0xc0) == 0x40)))
			{
				i = (unsigned int) GET_DWORD(proc_table + (13 * i) + 4);
			}

			if ((i != 0) || ((i == 0) && (current_proc == 0) &&
				((proc_attributes[0] != 1) &&
				((proc_attributes[0] & 0xc0) != 0x40))))
			{
				current_proc = i;
				pc = code_section + GET_DWORD(proc_table + (13 * i) + 9);
				CHECK_PC;
			}
			else
			{
				/* there are no procedures to execute! */
				done = 1;
			}
		}
	}

	message_buffer[0] = '\0';

	while (!done)
	{
		opcode = (unsigned int) (GET_BYTE(pc) & 0xff);
		opcode_address = pc;
		++pc;
                //printk("%x@%lx\n",opcode,opcode_address);
		arg_count = (opcode >> 6) & 3;
		for (i = 0; i < arg_count; ++i)
		{
			args[i] = GET_DWORD(pc);
			pc += 4;
		}

		switch (opcode)
		{
		case 0x00: /* NOP  */
			/* do nothing */
			break;

		case 0x01: /* DUP  */
			IF_CHECK_STACK(1)
			{
				stack[stack_ptr] = stack[stack_ptr - 1];
				++stack_ptr;
			}
			break;

		case 0x02: /* SWP  */
			IF_CHECK_STACK(2)
			{
				long_temp = stack[stack_ptr - 2];
				stack[stack_ptr - 2] = stack[stack_ptr - 1];
				stack[stack_ptr - 1] = long_temp;
			}
			break;

		case 0x03: /* ADD  */
			IF_CHECK_STACK(2)
			{
				--stack_ptr;
				stack[stack_ptr - 1] += stack[stack_ptr];
			}
			break;

		case 0x04: /* SUB  */
			IF_CHECK_STACK(2)
			{
				--stack_ptr;
				stack[stack_ptr - 1] -= stack[stack_ptr];
			}
			break;

		case 0x05: /* MULT */
			IF_CHECK_STACK(2)
			{
				--stack_ptr;
				stack[stack_ptr - 1] *= stack[stack_ptr];
			}
			break;

		case 0x06: /* DIV  */
			IF_CHECK_STACK(2)
			{
				--stack_ptr;
				stack[stack_ptr - 1] /= stack[stack_ptr];
			}
			break;

		case 0x07: /* MOD  */
			IF_CHECK_STACK(2)
			{
				--stack_ptr;
				stack[stack_ptr - 1] %= stack[stack_ptr];
			}
			break;

		case 0x08: /* SHL  */
			IF_CHECK_STACK(2)
			{
				--stack_ptr;
				stack[stack_ptr - 1] <<= stack[stack_ptr];
			}
			break;

		case 0x09: /* SHR  */
			IF_CHECK_STACK(2)
			{
				--stack_ptr;
				stack[stack_ptr - 1] >>= stack[stack_ptr];
			}
			break;

		case 0x0A: /* NOT  */
			IF_CHECK_STACK(1)
			{
				stack[stack_ptr - 1] ^= (-1L);
			}
			break;

		case 0x0B: /* AND  */
			IF_CHECK_STACK(2)
			{
				--stack_ptr;
				stack[stack_ptr - 1] &= stack[stack_ptr];
			}
			break;

		case 0x0C: /* OR   */
			IF_CHECK_STACK(2)
			{
				--stack_ptr;
				stack[stack_ptr - 1] |= stack[stack_ptr];
			}
			break;

		case 0x0D: /* XOR  */
			IF_CHECK_STACK(2)
			{
				--stack_ptr;
				stack[stack_ptr - 1] ^= stack[stack_ptr];
			}
			break;

		case 0x0E: /* INV */
			IF_CHECK_STACK(1)
			{
				stack[stack_ptr - 1] = stack[stack_ptr - 1] ? 0L : 1L;
			}
			break;

		case 0x0F: /* GT   */
			IF_CHECK_STACK(2)
			{
				--stack_ptr;
				stack[stack_ptr - 1] =
					(stack[stack_ptr - 1] > stack[stack_ptr]) ? 1L : 0L;
			}
			break;

		case 0x10: /* LT   */
			IF_CHECK_STACK(2)
			{
				--stack_ptr;
				stack[stack_ptr - 1] =
					(stack[stack_ptr - 1] < stack[stack_ptr]) ? 1L : 0L;
			}
			break;

		case 0x11: /* RET  */
			if ((version > 0) && (stack_ptr == 0))
			{
				/*
				*	We completed one of the main procedures of an ACTION.
				*	Find the next procedure to be executed and jump to it.
				*	If there are no more procedures, then EXIT.
				*/
				i = (unsigned int) GET_DWORD(proc_table + (13 * current_proc) + 4);
				while ((i != 0) &&
					((proc_attributes[i] == 1) ||
					((proc_attributes[i] & 0xc0) == 0x40)))
				{
					i = (unsigned int) GET_DWORD(proc_table + (13 * i) + 4);
				}

				if (i == 0)
				{
					/* there are no procedures to execute! */
					done = 1;
					*exit_code = 0;	/* success */
				}
				else
				{
					current_proc = i;
					pc = code_section + GET_DWORD(proc_table + (13 * i) + 9);
					CHECK_PC;
				}
			}
			else IF_CHECK_STACK(1)
			{
				pc = stack[--stack_ptr] + code_section;
				CHECK_PC;
				if (pc == code_section)
				{
					status = JBIC_BOUNDS_ERROR;
				}
			}
			break;

		case 0x12: /* CMPS */
			/*
			*	Array short compare
			*	...stack 0 is source 1 value
			*	...stack 1 is source 2 value
			*	...stack 2 is mask value
			*	...stack 3 is count
			*/
			IF_CHECK_STACK(4)
			{
				long a = stack[--stack_ptr];
				long b = stack[--stack_ptr];
				long_temp = stack[--stack_ptr];
				count = (unsigned int) stack[stack_ptr - 1];

				if ((count < 1) || (count > 32))
				{
					status = JBIC_BOUNDS_ERROR;
				}
				else
				{
					long_temp &= ((-1L) >> (32 - count));

					stack[stack_ptr - 1] =
						((a & long_temp) == (b & long_temp)) ? 1L : 0L;
				}
			}
			break;

		case 0x13: /* PINT */
			/*
			*	PRINT add integer
			*	...stack 0 is integer value
			*/
			IF_CHECK_STACK(1)
			{
				jbi_ltoa(&message_buffer[jbi_strlen(message_buffer)],
					stack[--stack_ptr]);
			}
			break;

		case 0x14: /* PRNT */
			/*
			*	PRINT finish
			*/
			jbi_message(message_buffer);
			message_buffer[0] = '\0';
			break;

		case 0x15: /* DSS  */
			/*
			*	DRSCAN short
			*	...stack 0 is scan data
			*	...stack 1 is count
			*/
			IF_CHECK_STACK(2)
			{
				long_temp = stack[--stack_ptr];
				count = (unsigned int) stack[--stack_ptr];
				jbi_make_dword(charbuf, long_temp);
				status = jbi_do_drscan(count, charbuf, 0);
			}
			break;

		case 0x16: /* DSSC */
			/*
			*	DRSCAN short with capture
			*	...stack 0 is scan data
			*	...stack 1 is count
			*/
			IF_CHECK_STACK(2)
			{
				long_temp = stack[--stack_ptr];
				count = (unsigned int) stack[stack_ptr - 1];
				jbi_make_dword(charbuf, long_temp);
				status = jbi_swap_dr(count, charbuf, 0, charbuf, 0);
				stack[stack_ptr - 1] = jbi_get_dword(charbuf);
			}
			break;

		case 0x17: /* ISS  */
			/*
			*	IRSCAN short
			*	...stack 0 is scan data
			*	...stack 1 is count
			*/
			IF_CHECK_STACK(2)
			{
				long_temp = stack[--stack_ptr];
				count = (unsigned int) stack[--stack_ptr];
				jbi_make_dword(charbuf, long_temp);
				status = jbi_do_irscan(count, charbuf, 0);
			}
			break;

		case 0x18: /* ISSC */
			/*
			*	IRSCAN short with capture
			*	...stack 0 is scan data
			*	...stack 1 is count
			*/
			IF_CHECK_STACK(2)
			{
				long_temp = stack[--stack_ptr];
				count = (unsigned int) stack[stack_ptr - 1];
				jbi_make_dword(charbuf, long_temp);
				status = jbi_swap_ir(count, charbuf, 0, charbuf, 0);
				stack[stack_ptr - 1] = jbi_get_dword(charbuf);
			}
			break;

		case 0x19: /* VSS  */
			/*
			*	VECTOR short
			*	...stack 0 is scan data
			*	...stack 1 is count
			*/
			bad_opcode = 1;
			break;

		case 0x1A: /* VSSC */
			/*
			*	VECTOR short with capture
			*	...stack 0 is scan data
			*	...stack 1 is count
			*/
			bad_opcode = 1;
			break;

		case 0x1B: /* VMPF */
			/*
			*	VMAP finish
			*/
			bad_opcode = 1;
			break;

		case 0x1C: /* DPR  */
			IF_CHECK_STACK(1)
			{
				count = (unsigned int) stack[--stack_ptr];
				status = jbi_set_dr_preamble(count, 0, NULL);
			}
			break;

		case 0x1D: /* DPRL */
			/*
			*	DRPRE with literal data
			*	...stack 0 is count
			*	...stack 1 is literal data
			*/
			IF_CHECK_STACK(2)
			{
				long_temp = stack[--stack_ptr];
				count = (unsigned int) stack[--stack_ptr];
				jbi_make_dword(charbuf, long_temp);
				status = jbi_set_dr_preamble(count, 0, charbuf);
			}
			break;

		case 0x1E: /* DPO  */
			/*
			*	DRPOST
			*	...stack 0 is count
			*/
			IF_CHECK_STACK(1)
			{
				count = (unsigned int) stack[--stack_ptr];
				status = jbi_set_dr_postamble(count, 0, NULL);
			}
			break;

		case 0x1F: /* DPOL */
			/*
			*	DRPOST with literal data
			*	...stack 0 is count
			*	...stack 1 is literal data
			*/
			IF_CHECK_STACK(2)
			{
				long_temp = stack[--stack_ptr];
				count = (unsigned int) stack[--stack_ptr];
				jbi_make_dword(charbuf, long_temp);
				status = jbi_set_dr_postamble(count, 0, charbuf);
			}
			break;

		case 0x20: /* IPR  */
			IF_CHECK_STACK(1)
			{
				count = (unsigned int) stack[--stack_ptr];
				status = jbi_set_ir_preamble(count, 0, NULL);
			}
			break;

		case 0x21: /* IPRL */
			/*
			*	IRPRE with literal data
			*	...stack 0 is count
			*	...stack 1 is literal data
			*/
			IF_CHECK_STACK(2)
			{
				long_temp = stack[--stack_ptr];
				count = (unsigned int) stack[--stack_ptr];
				jbi_make_dword(charbuf, long_temp);
				status = jbi_set_ir_preamble(count, 0, charbuf);
			}
			break;

		case 0x22: /* IPO  */
			/*
			*	IRPOST
			*	...stack 0 is count
			*/
			IF_CHECK_STACK(1)
			{
				count = (unsigned int) stack[--stack_ptr];
				status = jbi_set_ir_postamble(count, 0, NULL);
			}
			break;

		case 0x23: /* IPOL */
			/*
			*	IRPOST with literal data
			*	...stack 0 is count
			*	...stack 1 is literal data
			*/
			IF_CHECK_STACK(2)
			{
				long_temp = stack[--stack_ptr];
				count = (unsigned int) stack[--stack_ptr];
				jbi_make_dword(charbuf, long_temp);
				status = jbi_set_ir_postamble(count, 0, charbuf);
			}
			break;

		case 0x24: /* PCHR */
			IF_CHECK_STACK(1)
			{
				unsigned char ch;
				count = jbi_strlen(message_buffer);
				ch = (char) stack[--stack_ptr];
				if ((ch < 1) || (ch > 127))
				{
					/* character code out of range */
					/* instead of flagging an error, force the value to 127 */
					ch = 127;
				}
				message_buffer[count] = ch;
				message_buffer[count + 1] = '\0';
			}
			break;

		case 0x25: /* EXIT */
			IF_CHECK_STACK(1)
			{
				*exit_code = (int) stack[--stack_ptr];
			}
			done = 1;
			break;

		case 0x26: /* EQU  */
			IF_CHECK_STACK(2)
			{
				--stack_ptr;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -