sgdk
|
VDP main. More...
Go to the source code of this file.
Defines | |
#define | GFX_DATA_PORT 0xC00000 |
VDP Data port address. | |
#define | GFX_CTRL_PORT 0xC00004 |
VDP Control port address. | |
#define | GFX_HVCOUNTER_PORT 0xC00008 |
VDP HV counter port address. | |
#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 VDP_BG_A |
#define | VDP_PLAN_B VDP_BG_B |
#define | VDP_PLAN_WINDOW VDP_WINDOW |
#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 VSCROLL_COLUMN |
#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_MAXNUM (TILE_SPACE / TILE_SIZE) |
Maximum number of tile in VRAM (related to TILE_SPACE). | |
#define | TILE_MAXINDEX (TILE_MAXNUM - 1) |
Maximum tile index in VRAM (related to TILE_MAXNUM). | |
#define | TILE_SYSTEMINDEX 0x0000 |
System base tile index in VRAM. | |
#define | TILE_SYSTEMLENGTH 16 |
Number of system tile. | |
#define | TILE_SYSTEMLENGHT TILE_SYSTEMLENGTH |
#define | TILE_USERINDEX (TILE_SYSTEMINDEX + TILE_SYSTEMLENGTH) |
User base tile index. | |
#define | TILE_FONTINDEX (TILE_MAXNUM - FONT_LEN) |
Font base tile index. | |
#define | TILE_SPRITEINDEX (TILE_FONTINDEX - spriteVramSize) |
Sprite engine base tile index (equal TILE_FONTINDEX if Sprite Engine is not initialized). | |
#define | TILE_USERLENGTH ((userTileMaxIndex - TILE_USERINDEX) + 1) |
Number of available user tile. | |
#define | TILE_USERLENGHT TILE_USERLENGTH |
#define | TILE_USERMAXINDEX userTileMaxIndex |
Maximum tile index in VRAM reserved for user (for background and user managed sprites) | |
#define | TILE_SYSTEM (TILE_SYSTEMINDEX * TILE_SIZE) |
System tile address in VRAM. | |
#define | TILE_USER (TILE_USERINDEX * TILE_SIZE) |
User tile address in VRAM. | |
#define | TILE_FONT (TILE_FONTINDEX * 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 | GFX_READ_VRAM_ADDR(adr) (((0x0000 + ((adr) & 0x3FFF)) << 16) + (((adr) >> 14) | 0x00)) |
Set VDP command to read specified VRAM address. | |
#define | GFX_READ_CRAM_ADDR(adr) (((0x0000 + ((adr) & 0x7F)) << 16) + 0x20) |
Set VDP command to read specified CRAM address. | |
#define | GFX_READ_VSRAM_ADDR(adr) (((0x0000 + ((adr) & 0x3F)) << 16) + 0x10) |
Set VDP command to read specified VSRAM address. | |
#define | GFX_WRITE_VRAM_ADDR(adr) (((0x4000 + ((adr) & 0x3FFF)) << 16) + (((adr) >> 14) | 0x00)) |
Set VDP command to write at specified VRAM address. | |
#define | GFX_WRITE_CRAM_ADDR(adr) (((0xC000 + ((adr) & 0x7F)) << 16) + 0x00) |
Set VDP command to write at specified CRAM address. | |
#define | GFX_WRITE_VSRAM_ADDR(adr) (((0x4000 + ((adr) & 0x3F)) << 16) + 0x10) |
Set VDP command to write at specified VSRAM address. | |
#define | GFX_DMA_VRAM_ADDR(adr) (((0x4000 + ((adr) & 0x3FFF)) << 16) + (((adr) >> 14) | 0x80)) |
Set VDP command to issue a DMA transfert to specified VRAM address. | |
#define | GFX_DMA_CRAM_ADDR(adr) (((0xC000 + ((adr) & 0x7F)) << 16) + 0x80) |
Set VDP command to issue a DMA transfert to specified CRAM address. | |
#define | GFX_DMA_VSRAM_ADDR(adr) (((0x4000 + ((adr) & 0x3F)) << 16) + 0x90) |
Set VDP command to issue a DMA transfert to specified VSRAM address. | |
#define | GFX_DMA_VRAMCOPY_ADDR(adr) (((0x4000 + ((adr) & 0x3FFF)) << 16) + (((adr) >> 14) | 0xC0)) |
Set VDP command to issue a DMA VRAM copy to specified VRAM address. | |
#define | GFX_VERT_SCROLL(adr) GFX_WRITE_VSRAM_ADDR(adr) |
Helper to write in vertical scroll table (same as GFX_WRITE_VSRAM_ADDR). | |
#define | GFX_HORZ_SCROLL(adr) GFX_WRITE_VRAM_ADDR(VDP_SCROLL_H + (adr)) |
Helper to write in horizontal scroll table (same as GFX_WRITE_VRAM_ADDR(VDP_SCROLL_H + adr)). | |
#define | GET_VDPSTATUS(flag) ((*(vu16*)(GFX_CTRL_PORT)) & (flag)) |
Tests VDP status against specified flag (see VDP_XXX_FLAG). | |
#define | IS_PALSYSTEM GET_VDPSTATUS(VDP_PALMODE_FLAG) |
Tests if current system is a PAL system (50 Hz). | |
#define | GET_HVCOUNTER (*(vu16*)(GFX_HVCOUNTER_PORT)) |
Returns HV counter. | |
#define | GET_HCOUNTER (GET_HVCOUNTER & 0xFF) |
Returns Horizontal counter. | |
#define | GET_VCOUNTER (GET_HVCOUNTER >> 8) |
Returns Vertical counter. | |
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 () |
Initialize the whole VDP sub system. | |
void | VDP_resetScreen () |
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. | |
u8 | VDP_getEnable () |
Returns VDP enable state. | |
void | VDP_setEnable (u8 value) |
Set VDP enable state. | |
u16 | VDP_getScanlineNumber () |
Returns number of total scanline. | |
u16 | VDP_getScreenHeight () |
Returns vertical screen resolution. | |
void | VDP_setScreenHeight224 () |
Set vertical resolution to 224 pixels. | |
void | VDP_setScreenHeight240 () |
Set vertical resolution to 240 pixels. | |
u16 | VDP_getScreenWidth () |
Returns horizontal screen resolution. | |
void | VDP_setScreenWidth256 () |
Set horizontal resolution to 256 pixels. | |
void | VDP_setScreenWidth320 () |
Set horizontal resolution to 320 pixels. | |
u16 | VDP_getPlaneWidth () |
Return background plane width (in tile). | |
u16 | VDP_getPlaneHeight () |
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. | |
void | VDP_setPlanSize (u16 w, u16 h) |
u8 | VDP_getHorizontalScrollingMode () |
Returns plane horizontal scrolling mode. | |
u8 | VDP_getVerticalScrollingMode () |
Returns plane vertical scrolling mode. | |
void | VDP_setScrollingMode (u16 hscroll, u16 vscroll) |
Set plane scrolling mode. | |
u8 | VDP_getBackgroundColor () |
Returns the background color index. | |
void | VDP_setBackgroundColor (u8 value) |
Set the background color index. | |
u8 | VDP_getAutoInc () |
Returns auto increment register value. | |
void | VDP_setAutoInc (u8 value) |
Set auto increment register value. | |
u8 | VDP_getDMAEnabled () |
Returns DMA enabled state. | |
void | VDP_setDMAEnabled (u8 value) |
Set DMA enabled state. | |
u8 | VDP_getHVLatching () |
Returns HV counter latching on INT2 (used for light gun) | |
void | VDP_setHVLatching (u8 value) |
Set HV counter latching on INT2 (used for light gun) | |
void | VDP_setHInterrupt (u8 value) |
Enable or Disable Horizontal interrupt. | |
void | VDP_setExtInterrupt (u8 value) |
Enable or Disable External interrupt. | |
void | VDP_setHilightShadow (u8 value) |
Enable or Disable Hilight / Shadow effect. | |
u8 | VDP_getHIntCounter () |
Get Horizontal interrupt counter value. | |
void | VDP_setHIntCounter (u8 value) |
Set Horizontal interrupt counter value. | |
u16 | VDP_getBGAAddress () |
Get VRAM address (location) of BG A tilemap. | |
u16 | VDP_getBGBAddress () |
Get VRAM address (location) of BG B tilemap. | |
u16 | VDP_getAPlanAddress () |
u16 | VDP_getBPlanAddress () |
u16 | VDP_getWindowAddress () |
Get VRAM address (location) of Window tilemap. | |
u16 | VDP_getWindowPlanAddress () |
u16 | VDP_getSpriteListAddress () |
Get VRAM address (location) of Sprite list. | |
u16 | VDP_getHScrollTableAddress () |
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_setAPlanAddress (u16 value) |
void | VDP_setBPlanAddress (u16 value) |
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_setWindowPlanAddress (u16 value) |
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_waitDMACompletion () |
Wait for DMA operation to complete. | |
void | VDP_waitFIFOEmpty () |
Wait for VDP FIFO to be empty. | |
bool | VDP_waitVInt () |
Wait for next Vertical Interruption. | |
bool | VDP_waitVBlank (bool forceNext) |
Wait for next vertical blank period (same as VDP_waitVSync()) | |
bool | VDP_waitVSync () |
Wait for Vertical Synchro. | |
void | VDP_waitVActive (bool forceNext) |
Wait for next vertical active area (end of vertical blank period) | |
u16 | VDP_getAdjustedVCounter () |
Return an enhanced V Counter representation. | |
void | VDP_showFPS (u16 asFloat) |
Display number of Frame Per Second. | |
void | VDP_showCPULoad () |
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. |
VDP main.
This unit provides general VDP (Video Display Processor) methods:
#define TILE_SYSTEMLENGHT TILE_SYSTEMLENGTH |
#define TILE_USERLENGHT TILE_USERLENGTH |
#define VDP_PLAN_A VDP_BG_A |
#define VDP_PLAN_B VDP_BG_B |
#define VDP_PLAN_WINDOW VDP_WINDOW |
#define VSCROLL_2TILE VSCROLL_COLUMN |
u16 VDP_getAdjustedVCounter | ( | ) |
Return an enhanced V Counter representation.
Using direct V counter from VDP may give troubles as the VDP V-Counter rollback during V-Blank period.
This function aim to make ease the use of V-Counter by adjusting it to a [0-255] range where 0 is the start of VBlank area and 255 the end of active display area.
u16 VDP_getAPlanAddress | ( | ) |
u16 VDP_getBPlanAddress | ( | ) |
u8 VDP_getHorizontalScrollingMode | ( | ) |
Returns plane horizontal scrolling mode.
Possible values are: HSCROLL_PLANE, HSCROLL_TILE, HSCROLL_LINE
Get VDP register value.
reg | Register number we want to retrieve value. |
u16 VDP_getScanlineNumber | ( | ) |
Returns number of total scanline.
312 for PAL system and 262 for NTSC system.
u16 VDP_getScreenHeight | ( | ) |
Returns vertical screen resolution.
Always returns 224 on NTSC system as they only support this mode.
PAL system supports 240 pixels mode.
u16 VDP_getScreenWidth | ( | ) |
Returns horizontal screen resolution.
Returns 320 or 256 depending current horizontal resolution mode.
u8 VDP_getVerticalScrollingMode | ( | ) |
Returns plane vertical scrolling mode.
Possible values are: VSCROLL_PLANE, VSCROLL_2TILE
u16 VDP_getWindowPlanAddress | ( | ) |
void VDP_init | ( | ) |
Initialize the whole VDP sub system.
Reset VDP registers, reset sprites then call VDP_resetScreen() to reset BG and palettes.
void VDP_resetScreen | ( | ) |
Reset background planes and palettes.
Reset VRAM (clear BG planes and reload font), reset scrolls and reset palettes (set to default grey / red / green / blue ramps).
void VDP_setAPlanAddress | ( | u16 | value | ) |
void VDP_setBPlanAddress | ( | u16 | value | ) |
void VDP_setDMAEnabled | ( | u8 | value | ) |
Set DMA enabled state.
Note that by default SGDK always enable DMA (there is no reason to disable it)
void VDP_setEnable | ( | u8 | value | ) |
Set VDP enable state.
You can temporary disable VDP to speed up VDP memory transfert.
void VDP_setExtInterrupt | ( | u8 | value | ) |
Enable or Disable External interrupt.
void VDP_setHIntCounter | ( | u8 | value | ) |
Set Horizontal interrupt counter value.
When Horizontal interrupt is enabled, setting 5 here means that H int will occurs each (5+1) scanline.
Set value 0 to get H int at each scanline.
void VDP_setHInterrupt | ( | u8 | value | ) |
Enable or Disable Horizontal interrupt.
void VDP_setHVLatching | ( | u8 | value | ) |
Set HV counter latching on INT2 (used for light gun)
You can ask the HV Counter to fix its value on INT2 for accurate light gun positionning.
Set background plane size (in tile).
WARNING: take attention to properly setup VRAM so tilemaps has enough space.
w | width in tile. Possible values are 32, 64 or 128. |
h | height in tile. Possible values are 32, 64 or 128. |
setupVram | If set to TRUE then tilemaps and tables will be automatically remapped in VRAM depending the plane size. If you don't know what that means then it's better to keep this value to TRUE :p Be careful to redraw your backgrounds, also the sprite engine may need to re-allocate its VRAM region if location changed. |
Set VDP register value.
reg | Register number we want to set value. |
value | value to set. |
void VDP_setScanMode | ( | u16 | mode | ) |
Sets the scan mode of the display.
mode | Accepted values : INTERLACED_NONE, INTERLACED_MODE1, INTERLACED_MODE2 |
This function changes the scanning mode on the next display blanking period.
In Interlaced Mode 1, the same pattern will be displayed on the adjacent lines of even and odd numbered fields.
In Interlaced Mode 2, different patterns can be displayed on the adjacent lines of even and odd numbered fields.
The number of cells on the screen stays the same regardless of which scanning mode is active.
void VDP_setScreenHeight224 | ( | ) |
Set vertical resolution to 224 pixels.
This is the only accepted mode for NTSC system.
void VDP_setScreenHeight240 | ( | ) |
Set vertical resolution to 240 pixels.
Only work on PAL system.
Set plane scrolling mode.
hscroll | Horizontal scrolling mode : HSCROLL_PLANE = Scroll offset is applied to the whole plane. HSCROLL_TILE = Scroll offset is applied on a tile basis granularity (8 pixels bloc). HSCROLL_LINE = Scroll offset is applied on a line basis granularity (1 pixel). |
vscroll | Vertical scrolling mode : VSCROLL_PLANE = Scroll offset is applied to the whole plane. VSCROLL_2TILE = Scroll offset is applied on 2 tiles basis granularity (16 pixels bloc). |
Sets the window Horizontal position.
right | If set to FALSE the window is displayed from column 0 up to column pos If set to TRUE the window is displayed from column pos up to last column |
pos | The Horizontal position of the window in 2 tiles unit (16 pixels). |
void VDP_setWindowPlanAddress | ( | u16 | value | ) |
Sets the window Vertical position.
down | If set to FALSE the window is displayed from row 0 up to row pos If set to TRUE the window is displayed from row pos up to last row |
pos | The Vertical position of the window in 1 tile unit (8 pixels). |
void VDP_showCPULoad | ( | ) |
Display the estimated CPU load (in %).
This function actually display an estimation of the CPU load (in %) for the last frame.
void VDP_showFPS | ( | u16 | asFloat | ) |
Display number of Frame Per Second.
asFloat | Display in float number format. |
This function actually display the number of time it was called in the last second.
i.e: for benchmarking you should call this method only once per frame update.
void VDP_waitDMACompletion | ( | ) |
Wait for DMA operation to complete.
void VDP_waitVActive | ( | bool | forceNext | ) |
Wait for next vertical active area (end of vertical blank period)
forceNext | Force waiting for next start of V-Active if we are already in V-Active period when calling the method. |
The method wait until we are in Vertical active area/period.
Wait for next vertical blank period (same as VDP_waitVSync())
forceNext | Force waiting for next start of VBlank if we are already in VBlank period when calling the method. |
The method wait until we are in Vertical blanking area/period.
bool VDP_waitVInt | ( | ) |
Wait for next Vertical Interruption.
The method actually wait for the start of Vertical Interruption. It returns immediately if we are already in V-Int handler.
bool VDP_waitVSync | ( | ) |
Wait for Vertical Synchro.
The method actually wait for the *next* start of Vertical blanking.
Current background plane height (in tile)
Possible values are: 32, 64, 128
Current background plane height bit shift.
Possible values are: 5, 6 or 7 (corresponding to plane height 32, 64 and 128)
Current background plane width (in tile)
Possible values are: 32, 64, 128
Current background plane width bit shift.
Possible values are: 5, 6 or 7 (corresponding to plane width 32, 64 and 128)
Current window width (in tile)
Possible values are: 32, 64
Current window width bit shift.
Possible values are: 5 or 6 (corresponding to window width 32 or 64)