Special Effects (Part 1)

Author:
Alberto Covarrubias

Index
Concepts
HBias World
Using Palettes
Reading the pad

Example
Virtual Pong
This document pretends to define the missing fundamental concepts in Virtual Boy programming. To understand the information provided in this document you need some background in game programming. You must refer to the previous documents to have some background in VB concepts.

Concepts

Palettes: A set of static colors valid for a certain image. A palette is a concept to keep in mind when you work with limited color data because it will let you visualize all the image information it diferent ways according to the stored information.

Hardware Register: A value stored commonly on RAM to represent the current status of a hardware device.

HBias Worlds

In the first document about display we said that Worlds can be represented in many modes, like normal BGMaps, like a set of Objects, and in this case, in a modified BGMap. To modify the mode a BGMap is displayed, the Virtual Boy uses a special value called Param Base. This value is defined in the World structure and is valid only if you define it as HBias/Affin Mode. Remember that the mode is also part of the World structure.

The HBias mode is readed in the same way as Normal mode, but the difference is that HBias lets you modify the X coordinate on every row in the displayed map. In other worlds, the HBias lets you make special effects on images like mapped fog (used in Insane Mouse Mansion) or fire effects.

To modify every row value, you need to use an array that specifies the coordinate of each row. The Param Base value is used for that purpose, as a pointer for this array. Also, the Virtual Boy has a space on memory ready for store this array, and is called Param Table. This table has the following address:

0003 C000 - 0003 D7FF     Param Table

The Param Table has 2 columns and store only HWORD values. Each column in Param Table represent the Left and Right screen coordinate offset values to be modified in the real world. The following image explains better the result of applying an HBias effect on a World that displays a graded bar.

You can see that every offset in coordinate is subtracted from real value, so positive values will move left the row and negative values will move right the row.In Virtual Pong, this effect is used on the presentation screen making a sine effect on the image.

Using Palettes

As explained before, the palettes let us represent the color on an indexed image. Remember that Virtual Boy works with 2 bit per pixel bitmaps, so we need 4-valued palettes for represent the color on this bitmaps.

The process of palette description starts on the VIP Brightness Registers, called BRTA, BRTB and BRTC, registers that represent the bright intensity on every pixel according to the value stored from 0 to 80. This BRT values will be taken by the World and Object palette registers (Worlds use GPLT0-3 and Objects use JPLT0-3) to construct a palette needed to represent the color on this display structures. An special register called BKCOL represents the color where the display will be cleaned each time it needs, so be careful with the value stored on this register. The mentioned registers are stored on VIP with the following addresses:

0005 F824         BRTA
0005 F826         BRTB
0005 F828         BRTC
0005 F860         GPLT0
0005 F862         GPLT1
0005 F864         GPLT2
0005 F866         GPLT3
0005 F868         JPLT0
0005 F86A         JPLT1
0005 F86C         JPLT2
0005 F86E         JPLT3
0005 F870         BKCOL

The BRTA value represents the real color for 1 as value stored on the palette. The BRTB is joined with 2 as value and BRTC with 3. The palette register uses a byte value, where the most significant 2 bits represent the 3 index values on image, the next 2 bits represent the 2 index values on image and so on. The 0 entry on palette is used as transparent bit, so if you need a black color, you must define a 0 value on another palette entry. Finally, the value stored on BRTC is added with BRTA and BRTB to make the real value for this register, so be careful also with this. The following diagram explains how all this stuff is mapped on VB.

As you can suppose, when you manipulate the BRT register, some cool effects can be done, like fades, or screen lightings. Using the BKCOL is also useful to make wonderful effects like Teleroboxer robots shadow. Use you imagination manipulating the palette register to make another cool effects (a fire effect can also make use of palette rotation).

Reading the pad

To complete this first document about Special Effects on Virtual Boy, we need to talk about how you can read the keypad on your demos, and some techniques to improve this work.

We talk in the animation document a little in the way you can work with Hardware registers for enable the timer interrupt, that part of the document was for experimented programmers who need to make 2 or more tasks (one of these can be animation), but one missing thing to work with your demos is how you can read input in VB.

The Virtual Boy uses one control register called SCR and two result registers called SLB-SHB to handle the keypad reading. As you can suppose, the control register plays the most important part in reading input because you can perform pad interrupts, read data, etc. To understand all lets see the flags on the SCR reg and which things can do:

SCR - 0200 0028
7 6 5 4 3 2 1 0
Interrupt
0-Enable
1-Disable
Reserved LatchData
0-Hw Use
1-Sw Use
Clock
0-Hw
1,0-Sw
Reserved Reader
1-StartRead
Status
1-Reading
0-Ready
Suspend
0-Enable
1-Disable

After the VB reads the input, it writes the result splited on SLB-SHB as byte values, each one represented if a key was pressed or not. The values must be joined performing an OR operation with this 2 registers and considering the following obtained information:

SHB - 0200 0014 SLB - 0200 0010
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
RP-D RP-L Select Start LP-U LP-D LP-L LP-R RP-R RP-U L R B A X Power

As a comment, the bit 1 is for testing the reading and is always on. The following code is useful to perform the keypaf reading, note what bit are on in SCR and also the composed hword result is stored on $3.

; Virtual-E (c) 1999
; Coded by Alberto Covarrubias
; Functions:            readpad
; Parameters:           $3 - Readed value (Returned here)
;                       $31 - Call PC value (use jal or .call).
; Dependency Regs:      $0 - Always 0 value
;                       $1,2,3 Reading
; Hardware functions

lb.     readpad
.mov32  SCRPtr, $1
mov     0x84, $2
st.b    $2, 0[$1]
.mov32  SHBPtr, $1
ld.b    0[$1], $2
shl     8, $2
.mov32  SLBPtr, $1
ld.b    0[$1], $3
or      $2, $3
jmp     [$31]

With all this information you are ready to build real videogames on VB. Wait a following reference to explain the final and most used mode on VB, the AFFIN mode, used to perform rotation and scale on maps to make effects like 3D fields or rotational elements. Thanks to David Tucker for providing useful information for this reference.

Any comment? Write us: virtuale98@yahoo.com

The Virtual Boy and Nintendo logos are trademarks of Nintendo Co. Ltd.