Browse Source

Add VRAM engine for copying tile data

master
Forest Belton 3 years ago
parent
commit
da574b6a10
4 changed files with 59 additions and 0 deletions
  1. +2
    -0
      src/main.c
  2. +3
    -0
      src/title.c
  3. +19
    -0
      src/vram.c
  4. +35
    -0
      src/vram.h

+ 2
- 0
src/main.c View File

@ -4,6 +4,7 @@
#include "game.h" #include "game.h"
#include "sdk/hardware.h" #include "sdk/hardware.h"
#include "sdk/oam.h" #include "sdk/oam.h"
#include "vram.h"
game_state_t game_state; game_state_t game_state;
@ -12,6 +13,7 @@ void main() {
// Setup the OAM for sprite drawing // Setup the OAM for sprite drawing
oam_init(); oam_init();
vram_init();
// Set up background & sprites // Set up background & sprites
rBGP = 0b11100100; rBGP = 0b11100100;

+ 3
- 0
src/title.c View File

@ -6,6 +6,7 @@
#include "sdk/joypad.h" #include "sdk/joypad.h"
#include "sdk/oam.h" #include "sdk/oam.h"
#include "sdk/video.h" #include "sdk/video.h"
#include "vram.h"
ASSET(bg_tiles, "bg/title.2bpp"); ASSET(bg_tiles, "bg/title.2bpp");
ASSET(bg_map, "bg/title.map"); ASSET(bg_map, "bg/title.map");
@ -39,5 +40,7 @@ void title(void) {
// Wait for VBLANK. Clear IF since global interrupts are disabled. // Wait for VBLANK. Clear IF since global interrupts are disabled.
HALT(); HALT();
rIF = 0; rIF = 0;
vram_update();
} }
} }

+ 19
- 0
src/vram.c View File

@ -0,0 +1,19 @@
#include "vram.h"
#include <string.h>
#include "sdk/video.h"
mem_xfer_t mem_xfer_queue[MAX_XFERS];
uint8_t mem_xfer_queue_size;
void vram_init(void) { mem_xfer_queue_size = 0; }
void vram_update(void) {
mem_xfer_t *xfer = &mem_xfer_queue[0];
for (uint8_t i = 0; i < mem_xfer_queue_size; i++) {
vram_memcpy((uint16_t)xfer->dest, (void *)xfer->source, xfer->size);
xfer++;
}
mem_xfer_queue_size = 0;
}

+ 35
- 0
src/vram.h View File

@ -0,0 +1,35 @@
#ifndef IS_VRAM_H_
#define IS_VRAM_H_
#include <stdint.h>
#define MAX_XFERS 5
typedef struct {
uint8_t *dest;
const uint8_t *source;
uint8_t size;
} mem_xfer_t;
extern mem_xfer_t mem_xfer_queue[MAX_XFERS];
extern uint8_t mem_xfer_queue_size;
/**
* @brief Initialize VRAM engine
*/
void vram_init(void);
/**
* @brief Process VRAM memory transfers
*/
void vram_update(void);
#define vram_enqueue_mem_xfer(_dest, _source, _size) \
do { \
mem_xfer_t *node = &mem_xfer_queue[mem_xfer_queue_size++]; \
node->dest = (_dest); \
node->source = (_source); \
node->size = (_size); \
} while (0)
#endif

Loading…
Cancel
Save