Read the instructions into simulated memory instead of separate buffer
This commit is contained in:
		@@ -6,6 +6,8 @@
 | 
				
			|||||||
#include <stdio.h>
 | 
					#include <stdio.h>
 | 
				
			||||||
#include <string.h>
 | 
					#include <string.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#define MEM_SIZE (1 << 16)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
struct basic_string {
 | 
					struct basic_string {
 | 
				
			||||||
  char str[4096];
 | 
					  char str[4096];
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
@@ -22,6 +24,9 @@ int main(int argc, char *argv[]) {
 | 
				
			|||||||
    return 1;
 | 
					    return 1;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  u8 memory[MEM_SIZE];
 | 
				
			||||||
 | 
					  memset((void *)memory, 0, MEM_SIZE);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  const char *filename = argv[1];
 | 
					  const char *filename = argv[1];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  printf("Filename: %s\n", filename);
 | 
					  printf("Filename: %s\n", filename);
 | 
				
			||||||
@@ -37,10 +42,7 @@ int main(int argc, char *argv[]) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
  fseek(fp, 0, SEEK_SET);
 | 
					  fseek(fp, 0, SEEK_SET);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  u8 buffer[size + 1];
 | 
					  fread((void *)memory, sizeof(u8), size, fp);
 | 
				
			||||||
  memset((void *)buffer, 0, size + 1);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
  fread((void *)buffer, sizeof(u8), size, fp);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
  fclose(fp);
 | 
					  fclose(fp);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -55,7 +57,7 @@ int main(int argc, char *argv[]) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
  while (offset < size) {
 | 
					  while (offset < size) {
 | 
				
			||||||
    instruction decoded;
 | 
					    instruction decoded;
 | 
				
			||||||
    Sim86_Decode8086Instruction(size - offset, buffer + offset, &decoded);
 | 
					    Sim86_Decode8086Instruction(size - offset, memory + offset, &decoded);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (decoded.Op) {
 | 
					    if (decoded.Op) {
 | 
				
			||||||
      offset += decoded.Size;
 | 
					      offset += decoded.Size;
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user