using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using Gear.EmulationCore;
using Gear.PluginSupport;
class VGAMonitor : PluginBase
{
private Propeller Chip;
private Bitmap Screen;
private double Minimum;
private Color Output;
private Color[] Palette;
public bool VSync;
public bool HSync;
private double LastTime;
public int ScanLine;
public int Pixel;
public override string Title
{
get { return "VGA Monitor"; }
}
public VGAMonitor()
{
Screen = new Bitmap(1300, 800);
ScanLine = 0;
Pixel = 0;
Minimum = 1;
Palette = new Color[0x40];
for( int i = 0; i < 0x40; i++ )
{
uint color = 0xFF000000;
if( (i & 1) != 0 ) color |= 0x000055;
if( (i & 2) != 0 ) color |= 0x0000AA;
if( (i & 4) != 0 ) color |= 0x005500;
if( (i & 8) != 0 ) color |= 0x00AA00;
if( (i & 16) != 0 ) color |= 0x550000;
if( (i & 32) != 0 ) color |= 0xAA0000;
Palette[i] = Color.FromArgb((int)color);
}
Output = Palette[0];
for( int x = 0; x < Screen.Width; x++ )
for( int y = 0; y < Screen.Height; y++ )
Screen.SetPixel(x, y, Output);
}
public override void PresentChip(Propeller host)
{
Chip = host;
Chip.NotifyOnPins(this);
}
public override void OnPinChange(double time, PinState[] pins)
{
double delta = time - LastTime;
LastTime = time;
if (delta < Minimum && delta > 0)
Minimum = delta;
int pixels = (int)(delta / Minimum);
while (pixels-- > 0 && Pixel < Screen.Width && ScanLine < Screen.Height)
{
Screen.SetPixel(Pixel++, ScanLine, Output);
Screen.SetPixel(Pixel++, ScanLine, Output);
}
// Check to see if the scanline pins have changed
if (pins[16] == PinState.OUTPUT_LO && !VSync)
{
if( !VSync )
ScanLine = 0;
}
if (pins[17] == PinState.OUTPUT_LO && !HSync)
{
if (++ScanLine == Screen.Height)
ScanLine = 0;
Pixel = 0;
}
VSync = pins[16] == PinState.OUTPUT_LO;
HSync = pins[17] == PinState.OUTPUT_LO;
// Drive color off propeller demo board pins
int index = 0;
for( int b = 0, p = 18; b < 6; b++, p++ )
if(pins[p] == PinState.OUTPUT_HI)
index |= 1 << b;
Output = Palette[index];
}
public override void Repaint(bool force)
{
CreateGraphics().DrawImage(Screen,0,0);
}
protected override void OnPaint(PaintEventArgs e)
{
e.Graphics.DrawImage(Screen,0,0);
}
}