Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --- 8086tiny.c 2014-03-19 15:04:54.000000000 +0100
- +++ 8086tiny.c 2014-06-24 07:58:14.000000000 +0200
- @@ -8,6 +8,8 @@
- #include <time.h>
- #include <sys/timeb.h>
- #include <memory.h>
- +#include <stdio.h>
- +#include <stdlib.h>
- #ifndef _WIN32
- #include <unistd.h>
- @@ -15,7 +17,7 @@
- #endif
- #ifndef NO_GRAPHICS
- -#include "SDL.h"
- +#include <SDL.h>
- #endif
- // Emulator system constants
- @@ -202,15 +204,19 @@
- // Assemble and return emulated CPU FLAGS register in scratch_uint
- void make_flags()
- {
- + int i;
- scratch_uint = 0xF002; // 8086 has reserved and unused flags set to 1
- - for (int i = 9; i--;)
- + //for (int i = 9; i--;)
- + for (i=8;i>=0;i--)
- scratch_uint += regs8[FLAG_CF + i] << bios_table_lookup[TABLE_FLAGS_BITFIELDS][i];
- }
- // Set emulated CPU FLAGS register from regs8[FLAG_xx] values
- void set_flags(int new_flags)
- {
- - for (int i = 9; i--;)
- + int i;
- + //for (i = 9; ;i--)
- + for (i=8;i>=0;i--)
- regs8[FLAG_CF + i] = !!(1 << bios_table_lookup[TABLE_FLAGS_BITFIELDS][i] & new_flags);
- }
- @@ -248,7 +254,8 @@
- #ifndef NO_GRAPHICS
- void audio_callback(void *data, unsigned char *stream, int len)
- {
- - for (int i = 0; i < len; i++)
- + int i;
- + for (i = 0; i < len; i++)
- stream[i] = (spkr_en == 3) && CAST(unsigned short)mem[0x4AA] ? -((54 * wave_counter++ / CAST(unsigned short)mem[0x4AA]) & 1) : sdl_audio.silence;
- spkr_en = io_ports[0x61] & 3;
- @@ -257,7 +264,9 @@
- // Emulator entry point
- int main(int argc, char **argv)
- + //int main(int argc, char* argv[])
- {
- + int i,j;
- #ifndef NO_GRAPHICS
- // Initialise SDL
- SDL_Init(SDL_INIT_AUDIO);
- @@ -280,8 +289,18 @@
- regs8[REG_DL] = ((argc > 3) && (*argv[3] == '@')) ? argv[3]++, 0x80 : 0;
- // Open BIOS (file id disk[2]), floppy disk image (disk[1]), and hard disk image (disk[0]) if specified
- - for (file_index = 3; file_index;)
- - disk[--file_index] = *++argv ? open(*argv, 32898) : 0;
- + //for (file_index = 3; ;file_index)
- + // disk[--file_index] = *++argv ? open(*argv, 32898) : 0;
- + //JASON
- + //disk[2]=open("bios",32898);
- + //disk[1]=open("fd.img",32898);
- + //disk[0]=open("hd.img",32898);
- + for(file_index=3;file_index--;file_index>=0)
- + {
- + if(*++argv!=0x0)
- + disk[file_index] = *argv ? open(*argv, 32898) : 0;
- +
- + }
- // Set CX:AX equal to the hard disk image size, if present
- CAST(unsigned)regs16[REG_AX] = *disk ? lseek(*disk, 0, 2) >> 9 : 0;
- @@ -290,8 +309,8 @@
- read(disk[2], regs8 + (reg_ip = 0x100), 0xFF00);
- // Load instruction decoding helper table
- - for (int i = 0; i < 20; i++)
- - for (int j = 0; j < 256; j++)
- + for (i = 0; i < 20; i++)
- + for (j = 0; j < 256; j++)
- bios_table_lookup[i][j] = regs8[regs16[0x81 + i] + j];
- // Instruction execution loop. Terminates if CS:IP = 0:0
- @@ -711,12 +730,13 @@
- // If we don't already have an SDL window open, set it up and compute color and video memory translation tables
- if (!sdl_screen)
- {
- - for (int i = 0; i < 16; i++)
- + int i;
- + for (i = 0; i < 16; i++)
- pixel_colors[i] = mem[0x4AC] ? // CGA?
- cga_colors[(i & 12) >> 2] + (cga_colors[i & 3] << 16) // CGA -> RGB332
- : 0xFF*(((i & 1) << 24) + ((i & 2) << 15) + ((i & 4) << 6) + ((i & 8) >> 3)); // Hercules -> RGB332
- - for (int i = 0; i < GRAPHICS_X * GRAPHICS_Y / 4; i++)
- + for (i = 0; i < GRAPHICS_X * GRAPHICS_Y / 4; i++)
- 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);
- SDL_Init(SDL_INIT_VIDEO);
- @@ -727,7 +747,7 @@
- // Refresh SDL display from emulated graphics card video RAM
- 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
- - for (int i = 0; i < GRAPHICS_X * GRAPHICS_Y / 4; i++)
- + for (i = 0; i < GRAPHICS_X * GRAPHICS_Y / 4; i++)
- ((unsigned *)sdl_screen->pixels)[i] = pixel_colors[15 & (vid_mem_base[vid_addr_lookup[i]] >> 4*!(i & 1))];
- SDL_Flip(sdl_screen);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement