Browse Source

Clarified some constants

Exonorid 3 years ago
parent
commit
303ed753df

+ 3 - 3
stage1/High_level_prototypes/stage1_assembler-0.c

@@ -24,7 +24,7 @@ FILE* source_file;
 void line_Comment()
 {
 	int c = fgetc(source_file);
-	while((10 != c) && (13 != c))
+	while(('\n' != c) && ('\r' != c)) //Discard input until we get to a newline
 	{
 		c = fgetc(source_file);
 	}
@@ -43,7 +43,7 @@ int hex(int c)
 	if('0' > c) return -1;
 
 	/* Deal with 0-9 */
-	if('9' >= c) return (c - 48);
+	if('9' >= c) return (c - ('0' - 0x0));
 
 	/* Convert a-f to A-F*/
 	c = c & 0xDF;
@@ -52,7 +52,7 @@ int hex(int c)
 	if('A' > c) return -1;
 
 	/* Deal with A-F */
-	if('F' >= c) return (c - 55);
+	if('F' >= c) return (c - ('A' - 0xA));
 
 	/* Everything else is garbage */
 	return -1;

+ 7 - 7
stage1/High_level_prototypes/stage1_assembler-1.c

@@ -47,7 +47,7 @@ void storePointer()
 void line_Comment()
 {
 	int c = fgetc(source_file);
-	while((10 != c) && (13 != c))
+	while(('\n' != c) && ('\r' != c))
 	{
 		c = fgetc(source_file);
 	}
@@ -69,8 +69,8 @@ int8_t hex(int c)
 		{
 			return (c - 55);
 		}
-		case 35:
-		case 59:
+		case '#':
+		case ';':
 		{
 			line_Comment();
 			return -1;
@@ -86,13 +86,13 @@ void first_pass()
 	for(c = fgetc(source_file); EOF != c; c = fgetc(source_file))
 	{
 		/* Check for and deal with label */
-		if(58 == c)
+		if(':' == c)
 		{
 			storeLabel();
 		}
 
 		/* check for and deal with pointers to labels */
-		if(64 == c)
+		if('@' == c)
 		{
 			c = fgetc(source_file);
 			ip = ip + 2;
@@ -117,11 +117,11 @@ void second_pass()
 	int c;
 	for(c = fgetc(source_file); EOF != c; c = fgetc(source_file))
 	{
-		if(58 == c)
+		if(':' == c)
 		{
 			c = fgetc(source_file);
 		}
-		else if(64 == c)
+		else if('@' == c)
 		{
 			storePointer();
 		}

+ 15 - 15
stage1/High_level_prototypes/stage1_assembler-2.c

@@ -70,7 +70,7 @@ void storeLabel()
 
 void storePointer(char ch)
 {
-	if(38 == ch)
+	if('&' == ch)
 	{
 		ip = ip + 4;
 	}
@@ -98,19 +98,19 @@ void storePointer(char ch)
 
 	int target = GetTarget(temp);
 	uint8_t first, second;
-	if(36 == ch)
+	if('$' == ch)
 	{ /* Deal with $ */
 		first = target/256;
 		second = target%256;
 		printf("%c%c", first, second );
 	}
-	else if(64 == ch)
+	else if('@' == ch)
 	{ /* Deal with @ */
 		first = (target - ip + 4)/256;
 		second = (target - ip + 4)%256;
 		printf("%c%c", first, second );
 	}
-	else if(38 == ch)
+	else if('&' == ch)
 	{
 		uint8_t third, fourth;
 		first = target >> 24;
@@ -124,7 +124,7 @@ void storePointer(char ch)
 void line_Comment()
 {
 	int c = fgetc(source_file);
-	while((10 != c) && (13 != c))
+	while(('\n' != c) && ('\r' != c))
 	{
 		c = fgetc(source_file);
 	}
@@ -136,18 +136,18 @@ int8_t hex(int c)
 	{
 		case '0' ... '9':
 		{
-			return (c - 48);
+			return (c - ('0' - 0x0));
 		}
 		case 'a' ... 'z':
 		{
-			return (c - 87);
+			return (c - ('a' - 0xa));
 		}
 		case 'A' ... 'Z':
 		{
-			return (c - 55);
+			return (c - ('A' - 0xA));
 		}
-		case 35:
-		case 59:
+		case '#':
+		case ';':
 		{
 			line_Comment();
 			return -1;
@@ -163,13 +163,13 @@ void first_pass()
 	for(c = fgetc(source_file); EOF != c; c = fgetc(source_file))
 	{
 		/* Check for and deal with label */
-		if(58 == c)
+		if(':' == c)
 		{
 			storeLabel();
 		}
 
 		/* check for and deal with relative pointers to labels */
-		if((64 == c) || (36 == c))
+		if(('@' == c) || ('$' == c))
 		{ /* deal with @ and $ */
 			while((' ' != c) && ('\t' != c) && ('\n' != c))
 			{
@@ -177,7 +177,7 @@ void first_pass()
 			}
 			ip = ip + 2;
 		}
-		else if(38 == c)
+		else if('&' == c)
 		{ /* deal with & */
 			while((' ' != c) && ('\t' != c) && ('\n' != c))
 			{
@@ -205,14 +205,14 @@ void second_pass()
 	int c;
 	for(c = fgetc(source_file); EOF != c; c = fgetc(source_file))
 	{
-		if(58 == c)
+		if(':' == c)
 		{ /* Deal with : */
 			while((' ' != c) && ('\t' != c) && ('\n' != c))
 			{
 				c = fgetc(source_file);
 			}
 		}
-		else if((64 == c) || (36 == c) || (38 == c))
+		else if(('@' == c) || ('$' == c) || ('&' == c))
 		{ /* Deal with @, $ and & */
 			storePointer(c);
 		}