class PPU
This class represents the Picture Processing Unit of the GBA Functions in here are mostly inline utilities to make code inside renderers understandable. There’s also the rendering timing idle. (the real rendering is in the functions below)
Memory CPU MainWindow Tile4 Tile8 OAMSprites Palettes
| PPU | This class represents the Picture Processing Unit of the GBA Functions in here are mostly inline utilities to make code inside renderers understandable. |
| Variables | |
| mMemory | A pointer to the memory to read LCD registers, vram, oam and pram. |
| mCpu | A pointer to the cpu for interrupts. |
| palettes | A reinterpretation of pram to make things understandable. |
| sprites | A reinterpretation of oam to make things understandable. |
| mBGOrder | Obsolete. |
| mCurrentPixel | Obsolete. |
| mHCOUNT | Keeps track of Horizontal Count (which x is currently theoretically drawn). |
| Functions | |
| CheckVMatch | Generates an interrupt if VCOUNT is equal to LYC. |
| PPU | Builds a PPU. |
| Variables | |
| buffer_nul | Backdrop buffer. |
| buffer_bg0 | Background 0 buffer. |
| buffer_bg1 | Background 1 buffer. |
| buffer_bg2 | Background 2 buffer. |
| buffer_bg3 | Background 3 buffer. |
| buffer_obj | Sprites layer buffer. |
| buffer_obj_priority | Sprites priorities buffer. |
| Functions | |
| GetObjTilesMemory | Unimplemented. |
| GetMemory | The memory of the GBA associated to the PPU. |
| GetVRam | The VRAM of the GBA associated to the PPU. |
| GetIORam | The IORam of the GBA associated to the PPU. |
| GetPalettes | The Palettes of the GBA associated to the PPU. |
| GetSprites | The Sprites of the GBA associated to the PPU. |
| GetDISPSTAT | The DISPSTAT register contains the LYC (vertical match register) and things like HBLANK flag, VBLANK flag, .... |
| GetDISPCNT | The DISPCNT register contains information about rendering (e.g. |
| GetBLDYEvy | Computes Evy factor for backgrounds effects (from BLDY register). |
| GetSelectedSecondFrame | For Render modes 4-5. |
| GetFirstFrame | The first frame in rendering modes 3-4-5. |
| GetSecondFrame | The second frame in rendering modes 3-4-5. |
| GetBGMode | Contained in DISPCNT. |
| ClearHBlank | Clears HBLANK Flag. |
| ClearVBlank | Clears VBlank Flag. |
| GetVBlank | True if VBlank Flag is set. |
| HBlank | Generates a HBlank interrupt if the environment allows that. |
| VBlank | Generates a VBlank interrupt. |
| DrawIdle | Performs PPU idle operations. |
| pack_rgb | Packs 3 channels into a 16 bit RGBA_5_5_5_1 format integer. |
| render_sprite_rotscale | Renders a sprite (into sprites buffer) that has rotation/scale enabled. |
| render_sprite_fixed | Renders a sprite (into sprites buffer) that has rotation/scale disabled. |
| render_sprite | Renders a sprite (into sprites buffer). |
| render_objsprites | Renders all the sprites of the ppu into its sprites buffer PPU.buffer_obj. |
| render_bg_textmode_tile4 | Renders a background with 16/16 palettes/color mode. |
| render_bg_textmode_tile8 | Renders a background with 256/1 colors/palette mode. |
| render_bg_textmode | Renders a background in text mode. |
| render_mode0 | Renders a background with rendering mode 0. |
| render_mode1 | UNIMPLEMENTED. |
| render_mode2 | UNIMPLEMENTED. |
| render_mode3 | UNIMPLEMENTED. |
| render_mode4 | Renders a background with rendering mode 4. |
| render_mode5 | UNIMPLEMENTED. |
| Variables | |
| PPU_renderers | Pointers to the render functions. |
inline uint16_t GetDISPCNT()
The DISPCNT register contains information about rendering (e.g. which backgrounds are enabled, if mosaic is enabled, if sprites are enabled, if in swap chained modes the back buffer becomes the front, if OAM tiles are 1D or 2D, ...)
The DISPCNT register value.
inline bool GetSelectedSecondFrame()
For Render modes 4-5. These render modes use vram to store two full screen frames. Then something similar to today’s swapchains swaps between frames This flag determines if the first or second frame has to be used (false=first). The information is inside DISPCNT.
True if the second frame is selected, False otherwise.
inline void DrawIdle( int count )
Performs PPU idle operations.
A pixel has a draw time of 4 cycles (238.xx ns (approx)) The screen is 240x160 with a vertical draw period of 197120 cycles and a vblanking of 83776, we have a total of 280896 cycles each frame, with 16.78Mhz it means we have 59.59ns per cycle and thus a wait time of 16.73859264 ms per frame -> 59.7421792 Frames Per Second (60 FPS approx).
| count | Number of cycles since last call. |
inline void render_objsprites( PPU * ppu, void * tilesMem )
Renders all the sprites of the ppu into its sprites buffer PPU.buffer_obj.
| ppu | The ppu used for rendering. |
| tilesMem | Pointer to the tiles memory. |
inline void render_bg_textmode_tile4( PPU * ppu, uint16_t bgcnt, uint16_t bghofs, uint16_t bgvofs, uint16_t * outBuffer )
Renders a background with 16/16 palettes/color mode. Text Mode (no rotation).
| ppu | The ppu used for rendering. |
| bgcnt | Background control register value. |
| bghofs | Background horizontal scroll. |
| bgvofs | Background vertical scroll. |
| outBuffer | Output buffer. |
inline void render_bg_textmode_tile8( PPU * ppu, uint16_t bgcnt, uint16_t bghofs, uint16_t bgvofs, uint16_t * outBuffer )
Renders a background with 256/1 colors/palette mode. Text Mode (no rotation)
| ppu | The ppu used for rendering. |
| bgcnt | Background control register value. |
| bghofs | Background horizontal scroll. |
| bgvofs | Background vertical scroll. |
| outBuffer | Output buffer. |
inline void render_bg_textmode( PPU * ppu, uint16_t bgcnt, uint16_t bghofs, uint16_t bgvofs, uint16_t * outBuffer )
Renders a background in text mode.
| ppu | The ppu used for rendering. |
| bgcnt | Background control register value. |
| bghofs | Background horizontal scroll. |
| bgvofs | Background vertical scroll. |
| outBuffer | Output buffer. |
void render_mode0( PPU * ppu, unsigned char * outBuffer )
Renders a background with rendering mode 0.
Rendering mode 0 supports all backgrounds, 1024 tiles, 16/16 and 256/1 colors mode, Scrolling, Flip, Mosaic, and Alpha blending effects.
It doesn’t support rotation/scaling.
| ppu | The ppu used for rendering. |
| outBuffer | Output buffer. |
void render_mode4( PPU * ppu, unsigned char * outBuffer )
Renders a background with rendering mode 4.
In render mode 4 there’s only a big frame, 32768 colors available, rotation/scaling/mosaic/brightness/darkness effects available. The frame size is fullscreen (240x160).
| ppu | The ppu used for rendering. |
| outBuffer | Output buffer. |
This class represents the Picture Processing Unit of the GBA Functions in here are mostly inline utilities to make code inside renderers understandable.
class PPU
A pointer to the memory to read LCD registers, vram, oam and pram.
Memory* mMemory
A pointer to the cpu for interrupts.
CPU* mCpu
A reinterpretation of pram to make things understandable.
Palettes* palettes
A reinterpretation of oam to make things understandable.
OAMSprites* sprites
Obsolete.
int mBGOrder[4]
Obsolete.
int mCurrentPixel
Keeps track of Horizontal Count (which x is currently theoretically drawn).
int mHCOUNT
Generates an interrupt if VCOUNT is equal to LYC.
inline void CheckVMatch()
Builds a PPU.
PPU( Memory * mem, CPU * cpu, Palettes * pal, OAMSprites * spr )
Backdrop buffer.
uint16_t buffer_nul[38400]
Background 0 buffer.
uint16_t buffer_bg0[38400]
Background 1 buffer.
uint16_t buffer_bg1[38400]
Background 2 buffer.
uint16_t buffer_bg2[38400]
Background 3 buffer.
uint16_t buffer_bg3[38400]
Sprites layer buffer.
uint16_t buffer_obj[38400]
Sprites priorities buffer.
uint8_t buffer_obj_priority[38400]
Unimplemented.
inline void* GetObjTilesMemory()
The memory of the GBA associated to the PPU.
inline Memory* GetMemory()
The VRAM of the GBA associated to the PPU.
inline int8_t* GetVRam()
The IORam of the GBA associated to the PPU.
inline ASICRegisters* GetIORam()
The Palettes of the GBA associated to the PPU.
inline Palettes* GetPalettes()
The Sprites of the GBA associated to the PPU.
inline OAMSprites* GetSprites()
The DISPSTAT register contains the LYC (vertical match register) and things like HBLANK flag, VBLANK flag, ....
inline uint16_t GetDISPSTAT()
The DISPCNT register contains information about rendering (e.g.
inline uint16_t GetDISPCNT()
Computes Evy factor for backgrounds effects (from BLDY register).
inline float GetBLDYEvy()
For Render modes 4-5.
inline bool GetSelectedSecondFrame()
The first frame in rendering modes 3-4-5.
inline unsigned char* GetFirstFrame()
The second frame in rendering modes 3-4-5.
inline unsigned char* GetSecondFrame()
Contained in DISPCNT.
inline int GetBGMode()
Clears HBLANK Flag.
inline void ClearHBlank()
Clears VBlank Flag.
inline void ClearVBlank()
True if VBlank Flag is set.
inline bool GetVBlank()
Generates a HBlank interrupt if the environment allows that.
inline void HBlank()
Generates a VBlank interrupt.
inline void VBlank()
Performs PPU idle operations.
inline void DrawIdle( int count )
Packs 3 channels into a 16 bit RGBA_5_5_5_1 format integer.
inline uint16_t pack_rgb( int r, int g, int b )
Renders a sprite (into sprites buffer) that has rotation/scale enabled.
inline void render_sprite_rotscale( PPU * ppu, OAMSprite * sprite, void * tilesMem )
Renders a sprite (into sprites buffer) that has rotation/scale disabled.
inline void render_sprite_fixed( PPU * ppu, OAMSprite * sprite, void * tilesMem )
Renders a sprite (into sprites buffer).
inline void render_sprite( PPU * ppu, OAMSprite * sprite, void * tilesMem )
Renders all the sprites of the ppu into its sprites buffer PPU.buffer_obj.
inline void render_objsprites( PPU * ppu, void * tilesMem )
Renders a background with 16/16 palettes/color mode.
inline void render_bg_textmode_tile4( PPU * ppu, uint16_t bgcnt, uint16_t bghofs, uint16_t bgvofs, uint16_t * outBuffer )
Renders a background with 256/1 colors/palette mode.
inline void render_bg_textmode_tile8( PPU * ppu, uint16_t bgcnt, uint16_t bghofs, uint16_t bgvofs, uint16_t * outBuffer )
Renders a background in text mode.
inline void render_bg_textmode( PPU * ppu, uint16_t bgcnt, uint16_t bghofs, uint16_t bgvofs, uint16_t * outBuffer )
Renders a background with rendering mode 0.
void render_mode0( PPU * ppu, unsigned char * outBuffer )
UNIMPLEMENTED.
void render_mode1( PPU * ppu, unsigned char * outBuffer )
UNIMPLEMENTED.
void render_mode2( PPU * ppu, unsigned char * outBuffer )
UNIMPLEMENTED.
void render_mode3( PPU * ppu, unsigned char * outBuffer )
Renders a background with rendering mode 4.
void render_mode4( PPU * ppu, unsigned char * outBuffer )
UNIMPLEMENTED.
void render_mode5( PPU * ppu, unsigned char * outBuffer )
Pointers to the render functions.
extern void ( * PPU_renderers[6] )(PPU*,unsigned char*)
Represents the entire address space of the GBA.
struct Memory
This class represents an ARM7TDMI CPU running at 16.78MHZ with 32 bit registers and two execution modes (ARM32bit, THUMB16bit).
class CPU
Represents an openGL window that displays the GBA video output.
class MainWindow
32 bytes Tile, 4 bit depth.
struct Tile4
64 bytes Tile, 8 bit depth.
struct Tile8
Builds and handles all OAMSprites and OAMTransformGroups contained in OAM memory.
class OAMSprites
Represents the full set of palettes.
class Palettes