Advertisement
Guest User

Untitled

a guest
Jul 24th, 2014
331
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 4.01 KB | None | 0 0
  1. --- 8086tiny.c  2014-03-19 15:04:54.000000000 +0100
  2. +++ 8086tiny.c  2014-06-24 07:58:14.000000000 +0200
  3. @@ -8,6 +8,8 @@
  4.  #include <time.h>
  5.  #include <sys/timeb.h>
  6.  #include <memory.h>
  7. +#include <stdio.h>
  8. +#include <stdlib.h>
  9.  
  10.  #ifndef _WIN32
  11.  #include <unistd.h>
  12. @@ -15,7 +17,7 @@
  13.  #endif
  14.  
  15.  #ifndef NO_GRAPHICS
  16. -#include "SDL.h"
  17. +#include <SDL.h>
  18.  #endif
  19.  
  20.  // Emulator system constants
  21. @@ -202,15 +204,19 @@
  22.  // Assemble and return emulated CPU FLAGS register in scratch_uint
  23.  void make_flags()
  24.  {
  25. +   int i;
  26.     scratch_uint = 0xF002; // 8086 has reserved and unused flags set to 1
  27. -   for (int i = 9; i--;)
  28. +   //for (int i = 9; i--;)
  29. +    for (i=8;i>=0;i--)
  30.         scratch_uint += regs8[FLAG_CF + i] << bios_table_lookup[TABLE_FLAGS_BITFIELDS][i];
  31.  }
  32.  
  33.  // Set emulated CPU FLAGS register from regs8[FLAG_xx] values
  34.  void set_flags(int new_flags)
  35.  {
  36. -   for (int i = 9; i--;)
  37. +   int i;
  38. +   //for (i = 9; ;i--)
  39. +   for (i=8;i>=0;i--)
  40.         regs8[FLAG_CF + i] = !!(1 << bios_table_lookup[TABLE_FLAGS_BITFIELDS][i] & new_flags);
  41.  }
  42.  
  43. @@ -248,7 +254,8 @@
  44.  #ifndef NO_GRAPHICS
  45.  void audio_callback(void *data, unsigned char *stream, int len)
  46.  {
  47. -   for (int i = 0; i < len; i++)
  48. +   int i;
  49. +   for (i = 0; i < len; i++)
  50.         stream[i] = (spkr_en == 3) && CAST(unsigned short)mem[0x4AA] ? -((54 * wave_counter++ / CAST(unsigned short)mem[0x4AA]) & 1) : sdl_audio.silence;
  51.  
  52.     spkr_en = io_ports[0x61] & 3;
  53. @@ -257,7 +264,9 @@
  54.  
  55.  // Emulator entry point
  56.  int main(int argc, char **argv)
  57. + //int main(int argc, char* argv[])
  58.  {
  59. +   int i,j;
  60.  #ifndef NO_GRAPHICS
  61.     // Initialise SDL
  62.     SDL_Init(SDL_INIT_AUDIO);
  63. @@ -280,8 +289,18 @@
  64.     regs8[REG_DL] = ((argc > 3) && (*argv[3] == '@')) ? argv[3]++, 0x80 : 0;
  65.  
  66.     // Open BIOS (file id disk[2]), floppy disk image (disk[1]), and hard disk image (disk[0]) if specified
  67. -   for (file_index = 3; file_index;)
  68. -       disk[--file_index] = *++argv ? open(*argv, 32898) : 0;
  69. +   //for (file_index = 3; ;file_index)
  70. +   //  disk[--file_index] = *++argv ? open(*argv, 32898) : 0;
  71. +   //JASON
  72. +   //disk[2]=open("bios",32898);
  73. +   //disk[1]=open("fd.img",32898);
  74. +   //disk[0]=open("hd.img",32898);
  75. +   for(file_index=3;file_index--;file_index>=0)
  76. +   {
  77. +       if(*++argv!=0x0)
  78. +           disk[file_index] = *argv ? open(*argv, 32898) : 0;
  79. +      
  80. +   }
  81.  
  82.     // Set CX:AX equal to the hard disk image size, if present
  83.     CAST(unsigned)regs16[REG_AX] = *disk ? lseek(*disk, 0, 2) >> 9 : 0;
  84. @@ -290,8 +309,8 @@
  85.     read(disk[2], regs8 + (reg_ip = 0x100), 0xFF00);
  86.  
  87.     // Load instruction decoding helper table
  88. -   for (int i = 0; i < 20; i++)
  89. -       for (int j = 0; j < 256; j++)
  90. +   for (i = 0; i < 20; i++)
  91. +       for (j = 0; j < 256; j++)
  92.             bios_table_lookup[i][j] = regs8[regs16[0x81 + i] + j];
  93.  
  94.     // Instruction execution loop. Terminates if CS:IP = 0:0
  95. @@ -711,12 +730,13 @@
  96.                 // If we don't already have an SDL window open, set it up and compute color and video memory translation tables
  97.                 if (!sdl_screen)
  98.                 {
  99. -                   for (int i = 0; i < 16; i++)
  100. +                   int i;
  101. +                   for (i = 0; i < 16; i++)
  102.                         pixel_colors[i] = mem[0x4AC] ? // CGA?
  103.                             cga_colors[(i & 12) >> 2] + (cga_colors[i & 3] << 16) // CGA -> RGB332
  104.                             : 0xFF*(((i & 1) << 24) + ((i & 2) << 15) + ((i & 4) << 6) + ((i & 8) >> 3)); // Hercules -> RGB332
  105.  
  106. -                   for (int i = 0; i < GRAPHICS_X * GRAPHICS_Y / 4; i++)
  107. +                   for (i = 0; i < GRAPHICS_X * GRAPHICS_Y / 4; i++)
  108.                         vid_addr_lookup[i] = i / GRAPHICS_X * (GRAPHICS_X / 8) + (i / 2) % (GRAPHICS_X / 8) + 0x2000*(mem[0x4AC] ? (2 * i / GRAPHICS_X) % 2 : (4 * i / GRAPHICS_X) % 4);
  109.  
  110.                     SDL_Init(SDL_INIT_VIDEO);
  111. @@ -727,7 +747,7 @@
  112.  
  113.                 // Refresh SDL display from emulated graphics card video RAM
  114.                 vid_mem_base = mem + 0xB0000 + 0x8000*(mem[0x4AC] ? 1 : io_ports[0x3B8] >> 7); // B800:0 for CGA/Hercules bank 2, B000:0 for Hercules bank 1
  115. -               for (int i = 0; i < GRAPHICS_X * GRAPHICS_Y / 4; i++)
  116. +               for (i = 0; i < GRAPHICS_X * GRAPHICS_Y / 4; i++)
  117.                     ((unsigned *)sdl_screen->pixels)[i] = pixel_colors[15 & (vid_mem_base[vid_addr_lookup[i]] >> 4*!(i & 1))];
  118.  
  119.                 SDL_Flip(sdl_screen);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement