+int RegAXUsed (struct CodeSeg* S, unsigned Index)
+/* Check if the value in A or(!) the value in X are used. */
+{
+ return (GetRegInfo (S, Index, REG_AX) & REG_AX) != 0;
+}
+
+
+
+int RegEAXUsed (struct CodeSeg* S, unsigned Index)
+/* Check if any of the four bytes in EAX are used. */
+{
+ return (GetRegInfo (S, Index, REG_EAX) & REG_EAX) != 0;
+}
+
+
+
+unsigned GetKnownReg (unsigned Use, const RegContents* RC)
+/* Return the register or zero page location from the set in Use, thats
+ * contents are known. If Use does not contain any register, or if the
+ * register in question does not have a known value, return REG_NONE.
+ */
+{
+ if ((Use & REG_A) != 0) {
+ return (RC == 0 || RC->RegA >= 0)? REG_A : REG_NONE;
+ } else if ((Use & REG_X) != 0) {
+ return (RC == 0 || RC->RegX >= 0)? REG_X : REG_NONE;
+ } else if ((Use & REG_Y) != 0) {
+ return (RC == 0 || RC->RegY >= 0)? REG_Y : REG_NONE;
+ } else if ((Use & REG_TMP1) != 0) {
+ return (RC == 0 || RC->Tmp1 >= 0)? REG_TMP1 : REG_NONE;
+ } else if ((Use & REG_PTR1_LO) != 0) {
+ return (RC == 0 || RC->Ptr1Lo >= 0)? REG_PTR1_LO : REG_NONE;
+ } else if ((Use & REG_PTR1_HI) != 0) {
+ return (RC == 0 || RC->Ptr1Hi >= 0)? REG_PTR1_HI : REG_NONE;
+ } else if ((Use & REG_SREG_LO) != 0) {
+ return (RC == 0 || RC->SRegLo >= 0)? REG_SREG_LO : REG_NONE;
+ } else if ((Use & REG_SREG_HI) != 0) {
+ return (RC == 0 || RC->SRegHi >= 0)? REG_SREG_HI : REG_NONE;
+ } else {
+ return REG_NONE;
+ }
+}
+
+
+
+static cmp_t FindCmpCond (const char* Code, unsigned CodeLen)
+/* Search for a compare condition by the given code using the given length */
+{
+ unsigned I;
+
+ /* Linear search */
+ for (I = 0; I < sizeof (CmpSuffixTab) / sizeof (CmpSuffixTab [0]); ++I) {
+ if (strncmp (Code, CmpSuffixTab [I], CodeLen) == 0) {
+ /* Found */
+ return I;
+ }
+ }
+
+ /* Not found */
+ return CMP_INV;
+}
+
+
+
+cmp_t FindBoolCmpCond (const char* Name)
+/* Check if the given string is the name of one of the boolean transformer
+ * subroutine, and if so, return the condition that is evaluated by this
+ * routine. Return CMP_INV if the condition is not recognised.
+ */
+{
+ /* Check for the correct subroutine name */
+ if (strncmp (Name, "bool", 4) == 0) {
+ /* Name is ok, search for the code in the table */
+ return FindCmpCond (Name+4, strlen(Name)-4);
+ } else {
+ /* Not found */
+ return CMP_INV;
+ }
+}
+
+
+
+cmp_t FindTosCmpCond (const char* Name)
+/* Check if this is a call to one of the TOS compare functions (tosgtax).
+ * Return the condition code or CMP_INV on failure.
+ */
+{
+ unsigned Len = strlen (Name);
+
+ /* Check for the correct subroutine name */
+ if (strncmp (Name, "tos", 3) == 0 && strcmp (Name+Len-2, "ax") == 0) {
+ /* Name is ok, search for the code in the table */
+ return FindCmpCond (Name+3, Len-3-2);
+ } else {
+ /* Not found */
+ return CMP_INV;
+ }
+}
+