/ shared / cpp_shared_library_test.cpp
cpp_shared_library_test.cpp
 1  /* ========================================================================
 2  
 3     (C) Copyright 2023 by Molly Rocket, Inc., All Rights Reserved.
 4     
 5     This software is provided 'as-is', without any express or implied
 6     warranty. In no event will the authors be held liable for any damages
 7     arising from the use of this software.
 8     
 9     Please see https://computerenhance.com for more information
10     
11     ======================================================================== */
12  
13  #include <stdio.h>
14  
15  #include "sim86_shared.h"
16  #pragma comment (lib, "./sim86_shared_debug.lib")
17  
18  unsigned char ExampleDisassembly[247] =
19  {
20      0x03, 0x18, 0x03, 0x5E, 0x00, 0x83, 0xC6, 0x02, 0x83, 0xC5, 0x02, 0x83, 0xC1, 0x08, 0x03, 0x5E,
21      0x00, 0x03, 0x4F, 0x02, 0x02, 0x7A, 0x04, 0x03, 0x7B, 0x06, 0x01, 0x18, 0x01, 0x5E, 0x00, 0x01,
22      0x5E, 0x00, 0x01, 0x4F, 0x02, 0x00, 0x7A, 0x04, 0x01, 0x7B, 0x06, 0x80, 0x07, 0x22, 0x83, 0x82,
23      0xE8, 0x03, 0x1D, 0x03, 0x46, 0x00, 0x02, 0x00, 0x01, 0xD8, 0x00, 0xE0, 0x05, 0xE8, 0x03, 0x04,
24      0xE2, 0x04, 0x09, 0x2B, 0x18, 0x2B, 0x5E, 0x00, 0x83, 0xEE, 0x02, 0x83, 0xED, 0x02, 0x83, 0xE9,
25      0x08, 0x2B, 0x5E, 0x00, 0x2B, 0x4F, 0x02, 0x2A, 0x7A, 0x04, 0x2B, 0x7B, 0x06, 0x29, 0x18, 0x29,
26      0x5E, 0x00, 0x29, 0x5E, 0x00, 0x29, 0x4F, 0x02, 0x28, 0x7A, 0x04, 0x29, 0x7B, 0x06, 0x80, 0x2F,
27      0x22, 0x83, 0x29, 0x1D, 0x2B, 0x46, 0x00, 0x2A, 0x00, 0x29, 0xD8, 0x28, 0xE0, 0x2D, 0xE8, 0x03,
28      0x2C, 0xE2, 0x2C, 0x09, 0x3B, 0x18, 0x3B, 0x5E, 0x00, 0x83, 0xFE, 0x02, 0x83, 0xFD, 0x02, 0x83,
29      0xF9, 0x08, 0x3B, 0x5E, 0x00, 0x3B, 0x4F, 0x02, 0x3A, 0x7A, 0x04, 0x3B, 0x7B, 0x06, 0x39, 0x18,
30      0x39, 0x5E, 0x00, 0x39, 0x5E, 0x00, 0x39, 0x4F, 0x02, 0x38, 0x7A, 0x04, 0x39, 0x7B, 0x06, 0x80,
31      0x3F, 0x22, 0x83, 0x3E, 0xE2, 0x12, 0x1D, 0x3B, 0x46, 0x00, 0x3A, 0x00, 0x39, 0xD8, 0x38, 0xE0,
32      0x3D, 0xE8, 0x03, 0x3C, 0xE2, 0x3C, 0x09, 0x75, 0x02, 0x75, 0xFC, 0x75, 0xFA, 0x75, 0xFC, 0x74,
33      0xFE, 0x7C, 0xFC, 0x7E, 0xFA, 0x72, 0xF8, 0x76, 0xF6, 0x7A, 0xF4, 0x70, 0xF2, 0x78, 0xF0, 0x75,
34      0xEE, 0x7D, 0xEC, 0x7F, 0xEA, 0x73, 0xE8, 0x77, 0xE6, 0x7B, 0xE4, 0x71, 0xE2, 0x79, 0xE0, 0xE2,
35      0xDE, 0xE1, 0xDC, 0xE0, 0xDA, 0xE3, 0xD8
36  };
37  
38  int main(void)
39  {
40      u32 Version = Sim86_GetVersion();
41      printf("Sim86 Version: %u (expected %u)\n", Version, SIM86_VERSION);
42      if(Version != SIM86_VERSION)
43      {
44          printf("ERROR: Header file version doesn't match DLL.\n");
45          return -1;
46      }
47      
48      instruction_table Table;
49      Sim86_Get8086InstructionTable(&Table);
50      printf("8086 Instruction Instruction Encoding Count: %u\n", Table.EncodingCount);
51      
52      u32 Offset = 0;
53      while(Offset < sizeof(ExampleDisassembly))
54      {
55          instruction Decoded;
56          Sim86_Decode8086Instruction(sizeof(ExampleDisassembly) - Offset, ExampleDisassembly + Offset, &Decoded);
57          if(Decoded.Op)
58          {
59              Offset += Decoded.Size;
60              printf("Size:%u Op:%s Flags:0x%x\n", Decoded.Size, Sim86_MnemonicFromOperationType(Decoded.Op), Decoded.Flags);
61          }
62          else
63          {
64              printf("Unrecognized instruction\n");
65              break;
66          }
67      }
68      
69      return 0;
70  }