-
Notifications
You must be signed in to change notification settings - Fork 1
v_blank.asm
This file contains an interrupt routine which is called in every V-blank. The V-blank, or vertical blank, is the period that begins when the PPU is finished drawing the screen from top to bottom and lasts until it is ready to begin drawing at the top again. The PPU uses its Object Attribute Memory (OAM) to place sprites on the screen. The V-blank is the only time that it is possible to write to OAM. The main task of the V-blank interrupt is thus to transfer sprite data into the OAM. It achieves this by using the MMU to copy the entire OAM segment (located in the CPU's RAM as described in main.asm) into OAM. It also updates the PPU's control register.
Another big task of the interrupt routine is to optionally update one background tile, or brick. The tile to update is present in the list bricks_to_update, which contains the index of all bricks that should be updated. This list is indexed by the variable first_to_update, and limited by last_to_update. During a V-blank interrupt, the brick pointed to by first_to_update will be updated unless first_to_update and last_to_update is equal. After the update, first_to_update is incremented and the next brick will be updated in the next V-blank. In order to determine the address of a tile in the PPU address space, both 16 bit multiplication and addition is necessary. This is very time consuming, and in order to save time for the V-blank, the addresses are calculated by the main thread whenever tiles are enqueued. The V-blank routine retrieves this address from the brick_address_to_update arrays.