#include <graphics.h>
#include <conio.h>
#include <stdlib.h>
#include <stdio.h>
#include <dos.h>
#include <math.h>
#include "vga.h"
#include <string.h>
#include "antic.h"
#include "gita.h"
#include "pokey.h"
#include "a6502.h"

extern ANTIC pf;
extern GITA pm;
extern POKEY snd;

int video_flag = 0;
Patype amodes[16];
#define LB 0x1f


Byte far *video_page = (unsigned char far *) MK_FP(0xa000,0);
extern Word dlist;

void init_video(void)
{
   //Video memory area
   gr_open();
   setup_colors();
}


//******************hardware update****************************************
//This routine updates the atari video screen in response to
//variable clock being greater than or equal to 228
//*************************************************************************
void m6502::hardware_update(void)
{

   //End of vblank when vcount = 0
   if (pf.evcount == 8) {pf.wait=0; pf.pc=0;}

   pf.dinstr = ram[pf.dlist + pf.pc];

   //Display list when no jvb
   if (pf.wait==0  && pf.dlist!=0 && pf.evcount>=8) (pf.*amodes[pf.dinstr&0xf])();
   else pf.evcount++;

//   if (ram[DMACTL]&b3) pm.player();
//   if (ram[DMACTL]&b4) pm.missle();
     snd.keyboard();
     snd.timers();

   //We are going to display the next scan line
   //reset vcount if necessary
   if (pf.evcount >= 262)
   {
      pf.evcount = 0;
      if (pf.ram[NMIEN&LB]&b6)
      {
	 ram[NMIST] = b6;
	 nmi_();
      }
   }
   ram[VCOUNT] = Byte((pf.evcount)>>1);

}

