SGDK
A free and open development kit for the Sega Mega Drive
Loading...
Searching...
No Matches
vdp.h File Reference

VDP main. More...

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define VDP_DATA_PORT   0xC00000
 VDP Data port address.
#define VDP_CTRL_PORT   0xC00004
 VDP Control port address.
#define VDP_HVCOUNTER_PORT   0xC00008
 VDP HV counter port address.
#define GFX_DATA_PORT   _Pragma("GCC error \"This definition is deprecated, use VDP_DATA_PORT instead.\"")
#define GFX_CTRL_PORT   _Pragma("GCC error \"This definition is deprecated, use VDP_CTRL_PORT instead.\"")
#define GFX_HVCOUNTER_PORT   _Pragma("GCC error \"This definition is deprecated, use VDP_HVCOUNTER_PORT instead.\"")
#define VDP_FIFOEMPTY_FLAG   (1 << 9)
 VDP FIFO empty flag.
#define VDP_FIFOFULL_FLAG   (1 << 8)
 VDP FIFO full flag.
#define VDP_VINTPENDING_FLAG   (1 << 7)
 VDP Vertical interrupt pending flag.
#define VDP_SPROVERFLOW_FLAG   (1 << 6)
 VDP sprite overflow flag.
#define VDP_SPRCOLLISION_FLAG   (1 << 5)
 VDP sprite collision flag.
#define VDP_ODDFRAME_FLAG   (1 << 4)
 VDP odd frame flag.
#define VDP_VBLANK_FLAG   (1 << 3)
 VDP Vertical blanking flag.
#define VDP_HBLANK_FLAG   (1 << 2)
 VDP Horizontal blanking flag.
#define VDP_DMABUSY_FLAG   (1 << 1)
 VDP DMA busy flag.
#define VDP_PALMODE_FLAG   (1 << 0)
 VDP PAL mode flag.
#define VDP_PLAN_A   _Pragma("GCC error \"This definition is deprecated, use VDP_BG_A instead.\"")
#define VDP_PLAN_B   _Pragma("GCC error \"This definition is deprecated, use VDP_BG_B instead.\"")
#define VDP_PLAN_WINDOW   _Pragma("GCC error \"This definition is deprecated, use VDP_WINDOW instead.\"")
#define VDP_BG_A   bga_addr
 VDP background A tilemap address in VRAM.
#define VDP_BG_B   bgb_addr
 VDP background B tilemap address in VRAM.
#define VDP_WINDOW   window_addr
 VDP window tilemap address in VRAM.
#define VDP_HSCROLL_TABLE   hscrl_addr
 VDP horizontal scroll table address in VRAM.
#define VDP_SPRITE_TABLE   slist_addr
 VDP sprite list table address in VRAM.
#define VDP_MAPS_START   maps_addr
 Address in VRAM where tilemaps start (= address of first tilemap / table in VRAM).
#define HSCROLL_PLANE   0
 Definition to set horizontal scroll to mode plane.
#define HSCROLL_TILE   2
 Definition to set horizontal scroll to mode tile.
#define HSCROLL_LINE   3
 Definition to set horizontal scroll to mode line.
#define VSCROLL_PLANE   0
 Definition to set vertical scroll to mode plane.
#define VSCROLL_COLUMN   1
 Definition to set vertical scroll to mode column (2 tiles width).
#define VSCROLL_2TILE   _Pragma("GCC error \"This definition is deprecated, use VSCROLL_COLUMN instead.\"")
#define INTERLACED_NONE   0
 Interlaced scanning mode disabled.
That is the default mode for the VDP.
#define INTERLACED_MODE1   1
 Interlaced Scanning Mode 1 - 8x8 dots per cell (normal vertical resolution)
In Interlaced Mode 1, the same pattern will be displayed on the adjacent lines of even and odd numbered fields.
#define INTERLACED_MODE2   2
 Interlaced Scanning Mode 2 - 8x16 dots per cell (double vertical resolution)
In Interlaced Mode 2, different patterns can be displayed on the adjacent lines of even and odd numbered fields.
#define FONT_LEN   96
 SGDK font length.
#define TILE_SIZE   32
 Size of a single tile in byte.
#define TILE_INDEX_MASK   (0xFFFF / TILE_SIZE)
#define TILE_SPACE   VDP_MAPS_START
 Space in byte for tile in VRAM (tile space ends where tilemaps starts).
#define TILE_MAX_NUM   (TILE_SPACE / TILE_SIZE)
 Maximum number of tile in VRAM (related to TILE_SPACE).
#define TILE_MAX_INDEX   (TILE_MAXNUM - 1)
 Maximum tile index in VRAM (related to TILE_MAXNUM).
#define TILE_SYSTEM_INDEX   0x0000
 System base tile index in VRAM.
#define TILE_SYSTEM_LENGTH   16
 Number of system tile.
#define TILE_USER_INDEX   (TILE_SYSTEM_INDEX + TILE_SYSTEM_LENGTH)
 User base tile index.
#define TILE_FONT_INDEX   (TILE_MAX_NUM - FONT_LEN)
 Font base tile index.
#define TILE_SPRITE_INDEX   (TILE_FONT_INDEX - spriteVramSize)
 Sprite engine base tile index (equal TILE_FONT_INDEX if Sprite Engine is not initialized).
#define TILE_USER_LENGTH   ((userTileMaxIndex - TILE_USER_INDEX) + 1)
 Number of available user tile.
#define TILE_USER_MAX_INDEX   userTileMaxIndex
 Maximum tile index in VRAM reserved for user (for background and user managed sprites).
#define TILE_MAXNUM   _Pragma("GCC error \"This definition is deprecated, use TILE_MAX_NUM instead.\"")
#define TILE_MAXINDEX   _Pragma("GCC error \"This definition is deprecated, use TILE_MAX_INDEX instead.\"")
#define TILE_SYSTEM_LENGHT   _Pragma("GCC error \"This definition is deprecated, use TILE_SYSTEM_LENGTH instead.\"")
#define TILE_SYSTEMLENGTH   _Pragma("GCC error \"This definition is deprecated, use TILE_SYSTEM_LENGTH instead.\"")
#define TILE_SYSTEMINDEX   _Pragma("GCC error \"This definition is deprecated, use TILE_SYSTEM_INDEX instead.\"")
#define TILE_USERINDEX   _Pragma("GCC error \"This definition is deprecated, use TILE_USER_INDEX instead.\"")
#define TILE_FONTINDEX   _Pragma("GCC error \"This definition is deprecated, use TILE_FONT_INDEX instead.\"")
#define TILE_SPRITEINDEX   _Pragma("GCC error \"This definition is deprecated, use TILE_SPRITE_INDEX instead.\"")
#define TILE_USERLENGTH   _Pragma("GCC error \"This definition is deprecated, use TILE_USER_LENGTH instead.\"")
#define TILE_USERMAXINDEX   _Pragma("GCC error \"This definition is deprecated, use TILE_USER_MAX_INDEX instead.\"")
#define TILE_SYSTEM   (TILE_SYSTEM_INDEX * TILE_SIZE)
 System tile address in VRAM.
#define TILE_USER   (TILE_USER_INDEX * TILE_SIZE)
 User tile address in VRAM.
#define TILE_FONT   (TILE_FONT_INDEX * TILE_SIZE)
 Font tile address in VRAM.
#define PAL0   0
 Palette 0.
#define PAL1   1
 Palette 1.
#define PAL2   2
 Palette 2.
#define PAL3   3
 Palette 3.
#define VDP_READ_VRAM_ADDR(adr)
 Set VDP command to read specified VRAM address.
#define VDP_READ_CRAM_ADDR(adr)
 Set VDP command to read specified CRAM address.
#define VDP_READ_VSRAM_ADDR(adr)
 Set VDP command to read specified VSRAM address.
#define VDP_WRITE_VRAM_ADDR(adr)
 Set VDP command to write at specified VRAM address.
#define VDP_WRITE_CRAM_ADDR(adr)
 Set VDP command to write at specified CRAM address.
#define VDP_WRITE_VSRAM_ADDR(adr)
 Set VDP command to write at specified VSRAM address.
#define VDP_DMA_VRAM_ADDR(adr)
 Set VDP command to issue a DMA transfert to specified VRAM address.
#define VDP_DMA_CRAM_ADDR(adr)
 Set VDP command to issue a DMA transfert to specified CRAM address.
#define VDP_DMA_VSRAM_ADDR(adr)
 Set VDP command to issue a DMA transfert to specified VSRAM address.
#define VDP_DMA_VRAMCOPY_ADDR(adr)
 Set VDP command to issue a DMA VRAM copy to specified VRAM address.
#define VDP_VERT_SCROLL(adr)
 Helper to write in vertical scroll table (same as VDP_WRITE_VSRAM_ADDR).
#define VDP_HORZ_SCROLL(adr)
 Helper to write in horizontal scroll table (same as VDP_WRITE_VRAM_ADDR(VDP_SCROLL_H + adr)).
#define GFX_READ_VRAM_ADDR(adr)
#define GFX_READ_CRAM_ADDR(adr)
#define GFX_READ_VSRAM_ADDR(adr)
#define GFX_WRITE_VRAM_ADDR(adr)
#define GFX_WRITE_CRAM_ADDR(adr)
#define GFX_WRITE_VSRAM_ADDR(adr)
#define GFX_DMA_VRAM_ADDR(adr)
#define GFX_DMA_CRAM_ADDR(adr)
#define GFX_DMA_VSRAM_ADDR(adr)
#define GFX_DMA_VRAMCOPY_ADDR(adr)
#define GFX_VERT_SCROLL(adr)
#define GFX_HORZ_SCROLL(adr)
#define GET_VDP_STATUS(flag)
 Tests VDP status against specified flag (see VDP_XXX_FLAG).
#define IS_PAL_SYSTEM   GET_VDP_STATUS(VDP_PALMODE_FLAG)
 Tests if current system is a PAL system (50 Hz).
#define GET_HVCOUNTER   (*(vu16*)(VDP_HVCOUNTER_PORT))
 Returns HV counter.
#define GET_HCOUNTER   (GET_HVCOUNTER & 0xFF)
 Returns Horizontal counter.
#define GET_VCOUNTER   (GET_HVCOUNTER >> 8)
 Returns Vertical counter.
#define VDP_setPlanSize(w, h)
#define VDP_getAPlanAddress()
#define VDP_getBPlanAddress()
#define VDP_getWindowPlanAddress()
#define VDP_setAPlanAddress(value)
#define VDP_setBPlanAddress(value)
#define VDP_setWindowPlanAddress(value)

Enumerations

enum  VDPPlane { BG_A = 0 , BG_B = 1 , WINDOW = 2 }
 Type used to define on which plane to work (used by some methods).

Functions

void VDP_init (void)
 Initialize the whole VDP sub system.
void VDP_resetScreen (void)
 Reset background planes and palettes.
u8 VDP_getReg (u16 reg)
 Get VDP register value.
void VDP_setReg (u16 reg, u8 value)
 Set VDP register value.
bool VDP_getEnable (void)
 Returns VDP enable state.
bool VDP_isEnable (void)
 Returns VDP enable state.
void VDP_setEnable (bool value)
 Set VDP enable state.
u16 VDP_getScanlineNumber (void)
 Returns number of total scanline.
u16 VDP_getScreenHeight (void)
 Returns vertical screen resolution.
void VDP_setScreenHeight224 (void)
 Set vertical resolution to 224 pixels.
void VDP_setScreenHeight240 (void)
 Set vertical resolution to 240 pixels.
u16 VDP_getScreenWidth (void)
 Returns horizontal screen resolution.
void VDP_setScreenWidth256 (void)
 Set horizontal resolution to 256 pixels.
void VDP_setScreenWidth320 (void)
 Set horizontal resolution to 320 pixels.
u16 VDP_getPlaneWidth (void)
 Return background plane width (in tile).
u16 VDP_getPlaneHeight (void)
 Return background plane height (in tile).
void VDP_setPlaneSize (u16 w, u16 h, bool setupVram)
 Set background plane size (in tile).
WARNING: take attention to properly setup VRAM so tilemaps has enough space.
u8 VDP_getHorizontalScrollingMode (void)
 Returns plane horizontal scrolling mode.
u8 VDP_getVerticalScrollingMode (void)
 Returns plane vertical scrolling mode.
void VDP_setScrollingMode (u16 hscroll, u16 vscroll)
 Set plane scrolling mode.
u8 VDP_getBackgroundColor (void)
 Returns the background color index.
void VDP_setBackgroundColor (u8 value)
 Set the background color index.
u8 VDP_getAutoInc (void)
 Returns auto increment register value.
void VDP_setAutoInc (u8 value)
 Set auto increment register value.
u8 VDP_getDMAEnabled (void)
 Returns DMA enabled state.
void VDP_setDMAEnabled (bool value)
 Set DMA enabled state.
u8 VDP_getHVLatching (void)
 Returns HV counter latching on INT2 (used for light gun).
void VDP_setHVLatching (bool value)
 Set HV counter latching on INT2 (used for light gun).
void VDP_setVInterrupt (bool value)
 Enable or Disable Vertical interrupt (it's strongly recommanded to keep it enabled).
void VDP_setHInterrupt (bool value)
 Enable or Disable Horizontal interrupt.
void VDP_setExtInterrupt (bool value)
 Enable or Disable External interrupt.
void VDP_setHilightShadow (bool value)
 Enable or Disable Hilight / Shadow effect.
u8 VDP_getHIntCounter (void)
 Get Horizontal interrupt counter value.
void VDP_setHIntCounter (u8 value)
 Set Horizontal interrupt counter value.
u16 VDP_getBGAAddress (void)
 Get VRAM address (location) of BG A tilemap.
u16 VDP_getBGBAddress (void)
 Get VRAM address (location) of BG B tilemap.
u16 VDP_getWindowAddress (void)
 Get VRAM address (location) of Window tilemap.
u16 VDP_getSpriteListAddress (void)
 Get VRAM address (location) of Sprite list.
u16 VDP_getHScrollTableAddress (void)
 Get VRAM address (location) of H SCroll table.
void VDP_setBGAAddress (u16 value)
 Set VRAM address (location) of BG A tilemap. The address should be at multiple of $2000

Ex:
VDP_setBGAAddress(0xC000)
Will set the BG A to at address 0xC000 in VRAM.
void VDP_setBGBAddress (u16 value)
 Set VRAM address (location) of BG B tilemap.
The address should be at multiple of $2000

Ex:
VDP_setBGBAddress(0xE000)
Will set the BG B tilemap at address 0xE000 in VRAM.
void VDP_setWindowAddress (u16 value)
 Set VRAM address (location) of Window tilemap.
The address should be at multiple of $1000 in H40 and $800 in H32

Ex:
VDP_setWindowAddress(0xA000)
Will set the Window tilemap at address 0xA000 in VRAM.
void VDP_setSpriteListAddress (u16 value)
 Set VRAM address (location) of Sprite list.
The address should be at multiple of $400 in H40 and $200 in H32

Ex:
VDP_setSpriteListAddress(0xD800)
Will set the Sprite list to at address 0xD800 in VRAM.
void VDP_setHScrollTableAddress (u16 value)
 Set VRAM address (location) of H Scroll table.
The address should be at multiple of $400

Ex:
VDP_setHScrollTableAddress(0xD400)
Will set the HScroll table to at address 0xD400 in VRAM.
void VDP_setScanMode (u16 mode)
 Sets the scan mode of the display.
void VDP_setWindowHPos (u16 right, u16 pos)
 Sets the window Horizontal position.
void VDP_setWindowVPos (u16 down, u16 pos)
 Sets the window Vertical position.
void VDP_setWindowOff ()
 Turns off the window.
void VDP_setWindowOnTop (u16 rows)
 Positions the window from the top edge of the screen by the specified number of rows (tiles).
void VDP_setWindowOnBottom (u16 rows)
 Positions the window from the bottom edge of the screen by the specified number of rows (tiles).
void VDP_setWindowOnLeft (u16 cols)
 Positions the window from the left edge of the screen by the specified number of columns, each 2 tiles wide (16 pixels).
void VDP_setWindowOnRight (u16 cols)
 Positions the window from the right edge of the screen by the specified number of columns, each 2 tiles wide (16 pixels).
void VDP_setWindowFullScreen ()
 Positions the window to full screen.
void VDP_waitDMACompletion (void)
 Wait for DMA operation to complete - same as DMA_waitCompletion().
void VDP_waitFIFOEmpty (void)
 Wait for VDP FIFO to be empty.
bool VDP_waitVInt (void)
 Wait for next Vertical Interruption.
bool VDP_waitVBlank (bool forceNext)
 Wait for next vertical blank period (same as VDP_waitVSync()).
bool VDP_waitVSync (void)
 Wait for Vertical Synchro.
void VDP_waitVActive (bool forceNext)
 Wait for next vertical active area (end of vertical blank period).
u16 VDP_getAdjustedVCounter (void)
 Return an enhanced V Counter representation.
void VDP_showFPS (u16 asFloat, u16 x, u16 y)
 Display number of Frame Per Second.
void VDP_showCPULoad (u16 x, u16 y)
 Display the estimated CPU load (in %).

Variables

u16 window_addr
u16 bga_addr
u16 bgb_addr
u16 hscrl_addr
u16 slist_addr
u16 maps_addr
u16 userTileMaxIndex
u16 screenWidth
 Current screen width (horizontale resolution).
u16 screenHeight
 Current screen height (verticale resolution).
u16 planeWidth
 Current background plane width (in tile).
u16 planeHeight
 Current background plane height (in tile).
u16 windowWidth
 Current window width (in tile).
u16 planeWidthSft
 Current background plane width bit shift.
u16 planeHeightSft
 Current background plane height bit shift.
u16 windowWidthSft
 Current window width bit shift.

Detailed Description

VDP main.

Author
Stephane Dallongeville
Date
08/2011