#include "screen.h"
#include "mem.h"
#include "vcpu.h"
#include "speaker.h"

#include <stdio.h>

#define SCREEN_WIDTH 1000
#define SCREEN_HEIGHT 500

int main(int argc, char *argv[])
{
  // Parse argument
  if(argc != 2){
    printf("Usage: %s [rom]\n",argv[0]);
    return 1;
  } else if(!FileExists(argv[1])){
    printf("ROM not found: %s\n",argv[1]);
    return 1;
  }

  // Initialize
  VCPUInit(SCREEN_WIDTH, SCREEN_HEIGHT);
  MemLoadROM(argv[1]); // Load ROM into main memory

  // Set game to run at very high FPS (prevent raylib to interfer with emulator CPU frequency)
  SetTargetFPS(VCPU_FREQ*100);

  // Emulator main loop
  while (!WindowShouldClose()){
    VCPUTick();
  }

  // Finish
  VCPUFinish();

  return 0;
}
