uk.co.javagear
Class Vdp

java.lang.Object
  extended by uk.co.javagear.Vdp

public final class Vdp
extends java.lang.Object

SMS and GG VDP Emulation.

Version:
18th January 2003
Author:
Copyright (C) 2002-2003 Chris White
See Also:
"JavaGear Final Project Report"

Field Summary
private  boolean[] bgPriority
          Background priorites.
private  int commandByte
          Command word first byte latch.
private  int counter
          Vertical line interrupt counter.
private  int[] cRam
          Colour RAM.
private  int[] display
          Pointer to current display.
private  int[] display1
          Frame 1.
private  int[] display2
          Frame 2.
private  boolean displayBackgroundLayer
          Generate background layer.
private  boolean displaySpriteLayer
          Generate sprite layer.
private  boolean firstByte
          First or second byte of command word.
private  boolean frameint
          Frame interrupt pending.
private static int[] GG_JAVA1
          GG Colours.
private static int[] GG_JAVA2
           
private  InterruptLine irq
          Connection to Z80 interrupt line.
private  int line
          Current line number.
private  boolean lineint
          Line interrupt pending.
private  int location
          Location in VRAM.
private  boolean ntsc
          NTSC/PAL.
private  int[] oldDisplay
          Pointer to previous frame.
private  int operation
          Store type of operation taking place.
private  int readBuffer
          Buffer VRAM reads.
private  Setup setup
          Pointer to general parameters.
private static int[] SMS_JAVA
          SMS Colours converted into Java RGB for speed purposes.
private  boolean[] spritecol
          Sprite collisions.
private  int status
          Status Register.
private  int[] vdpreg
          VDP Registers.
private  byte[] vRam
          Video RAM.
 
Constructor Summary
Vdp(Setup set, InterruptLine i)
          Vdp Constructor.
 
Method Summary
private  void blankColumn(int lineno)
          Deprecated. now, faster fillRect method used.
 int controlRead()
          Read VDP control port (0xBF).
 void controlWrite(int value)
          Write to VDP control port (0xBF).
 int dataRead()
          Read VDP data port (0xBE).
 void dataWrite(int value)
          Write to VDP data port (0xBE).
private  void drawBg(int lineno)
          Render line of background layer.
private  void drawBGColour(int lineno)
          Draw a line of the current background colour.
 void drawLine(int lineno)
          Render line of SMS/GG display.
private  void drawSprite(int lineno)
          Render line of sprite layer.
 void flagChanges(boolean[] pixelUpdate)
          Compare this frame with the previous frame, and flag what lines have been changed.
 int getCounter()
          Get line interrupt counter.
 int[] getDisplay()
          Returns the value of property display.
 boolean getFrameIntPending()
          Get frame interrupt pending flag.
 boolean getIrqStatus()
          Get interruptLine status.
 boolean getLineIntPending()
          Get line interrupt pending flag.
 int getLineNo()
          Get line number under generation.
 int getReg(int index)
          Get a VDP register.
 boolean getSpriteOverflow()
          Get sprite overflow status.
 int getVCount()
          Read vertical port.
 void interrupts(int lineno)
          Generate VDP interrupts.
private  void plotSpritePixel(int x, int y, int location, int address, int bit)
          Plot single sprite pixel.
 void reset()
          Reset VDP.
 void setBackgroundLayer()
          Toggle background layer generation on/off.
 void setDisplay(int[] display)
          Sets the value of property display.
 void setNTSC(boolean b)
          Set NTSC / PAL VDP Mode.
 void setSpriteLayer()
          Toggle Sprite Layer Generation On/Off.
private  int unsigned(byte b)
          Unsign an integer.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

irq

private InterruptLine irq
Connection to Z80 interrupt line.


setup

private Setup setup
Pointer to general parameters.


vRam

private byte[] vRam
Video RAM.


cRam

private int[] cRam
Colour RAM.


vdpreg

private int[] vdpreg
VDP Registers.


status

private int status
Status Register.


firstByte

private boolean firstByte
First or second byte of command word.


commandByte

private int commandByte
Command word first byte latch.


location

private int location
Location in VRAM.


operation

private int operation
Store type of operation taking place.


readBuffer

private int readBuffer
Buffer VRAM reads.


line

private int line
Current line number.


counter

private int counter
Vertical line interrupt counter.


lineint

private boolean lineint
Line interrupt pending.


frameint

private boolean frameint
Frame interrupt pending.


bgPriority

private boolean[] bgPriority
Background priorites.


spritecol

private boolean[] spritecol
Sprite collisions.


display

private int[] display
Pointer to current display.


oldDisplay

private int[] oldDisplay
Pointer to previous frame.


display1

private int[] display1
Frame 1.


display2

private int[] display2
Frame 2.


displayBackgroundLayer

private boolean displayBackgroundLayer
Generate background layer.


displaySpriteLayer

private boolean displaySpriteLayer
Generate sprite layer.


ntsc

private boolean ntsc
NTSC/PAL.


SMS_JAVA

private static final int[] SMS_JAVA
SMS Colours converted into Java RGB for speed purposes.


GG_JAVA1

private static final int[] GG_JAVA1
GG Colours.


GG_JAVA2

private static final int[] GG_JAVA2
Constructor Detail

Vdp

public Vdp(Setup set,
           InterruptLine i)
Vdp Constructor.

Parameters:
set - pointer to general parameters
i - pointer to Z80 interrupt line
Method Detail

reset

public void reset()
Reset VDP.


setNTSC

public void setNTSC(boolean b)
Set NTSC / PAL VDP Mode.

Parameters:
b - true if NTSC, false if PAL.

getDisplay

public int[] getDisplay()
Returns the value of property display. The pointer to the current display.

Returns:
the value of property display.

setDisplay

public void setDisplay(int[] display)
Sets the value of property display. The pointer to the current display.

Parameters:
display - the new value of property display.

setBackgroundLayer

public void setBackgroundLayer()
Toggle background layer generation on/off.


setSpriteLayer

public void setSpriteLayer()
Toggle Sprite Layer Generation On/Off.


getReg

public int getReg(int index)
Get a VDP register.

Parameters:
index - index of register.
Returns:
register data.

getLineNo

public int getLineNo()
Get line number under generation.

Returns:
line number.

getCounter

public int getCounter()
Get line interrupt counter.

Returns:
line interrupt counter.

getLineIntPending

public boolean getLineIntPending()
Get line interrupt pending flag.

Returns:
true if pending.

getFrameIntPending

public boolean getFrameIntPending()
Get frame interrupt pending flag.

Returns:
true if pending.

getIrqStatus

public boolean getIrqStatus()
Get interruptLine status.

Returns:
true if pending.

getSpriteOverflow

public boolean getSpriteOverflow()
Get sprite overflow status.

Returns:
true if overflow has occurred.

getVCount

public int getVCount()
Read vertical port.

Returns:
VCounter value

controlWrite

public void controlWrite(int value)
Write to VDP control port (0xBF).

Parameters:
value - value to write.

controlRead

public int controlRead()
Read VDP control port (0xBF).

Returns:
copy of status register.

dataWrite

public void dataWrite(int value)
Write to VDP data port (0xBE).

Parameters:
value - value to write

dataRead

public int dataRead()
Read VDP data port (0xBE).

Returns:
buffered read from VRAM

interrupts

public void interrupts(int lineno)
Generate VDP interrupts. Assert the IRQ line as necessary for a particular scanline.

Parameters:
lineno - line to check for interrupts.

drawLine

public void drawLine(int lineno)
Render line of SMS/GG display.

Parameters:
lineno - line number to render.

drawSprite

private void drawSprite(int lineno)
Render line of sprite layer.

Parameters:
lineno - line number to render.

plotSpritePixel

private void plotSpritePixel(int x,
                             int y,
                             int location,
                             int address,
                             int bit)
Plot single sprite pixel.

Parameters:
x - x coordinate of pixel (for location array).
y - y coordinate of pixel.
location - coordinates to plot pixel at x+(y*256).
address - VRAM address of pixel plane.
bit - bit of plane to plot.

drawBg

private void drawBg(int lineno)
Render line of background layer.

Parameters:
lineno - line number to render.

drawBGColour

private void drawBGColour(int lineno)
Draw a line of the current background colour.

Parameters:
lineno - line number to render.

blankColumn

private void blankColumn(int lineno)
Deprecated. now, faster fillRect method used.

Blank leftmost column of a particular line.

Parameters:
lineno - line number to render.

unsigned

private int unsigned(byte b)
Unsign an integer.

Parameters:
b - value to unsign.
Returns:
unsigned value.

flagChanges

public void flagChanges(boolean[] pixelUpdate)
Compare this frame with the previous frame, and flag what lines have been changed.

Parameters:
pixelUpdate - array to flag changes in.


Copyright © 2007 JavaGear. All Rights Reserved.