Free Web Hosting Provider - Web Hosting - E-commerce - High Speed Internet - Free Web Page
Search the Web

VMU SCRIPT CONCEPTS


Topic

Things discussed

Creating and using arrays

How to create arrays / Using arrays / Using pointers

Using 8 bit pointers with variables or arrays

Further explanation: Using pointers with variables and arrays

Using 16 bit pointers with byte maps

THIS IS THE MOST COMMONLY USED METHOD AND ONE OF THE MOST EFFECTIVE METHODS FOR PRE-MADE GRAPHICS!!!

Retrieving data from within the VMS file / 16 bit pointers

Using 8 bit pointers with byte maps

Retrieving data from within the VMS file / Using two 8 bit pointers instead of a single 16 bit pointer

Writing to / Reading from the VMU screen

Calculating row addresses / Organization of the VMU screen / Writing to the VMU screen / Reading from the VMU screen

Manipulating the VMU screen pixel by pixel

How to use "shift" with the VMU screen

Using "shift" with the VMU screen

Further explanation: How to use "shift" with the VMU screen






Creating and using arrays:

To create an array, use the "var" function followed by the number of bytes in the array.

EXAMPLE: "my_array = var: 5" allocates a 5 byte array named 'my_array'. NOTE: when you allocate an array, the bytes are numbered sequentially starting with zero. With a 5 byte array, the bytes would be numbered 0-4.

To return a value from an array, use the "getvar" function followed by the array name/pointer and the byte number.

EXAMPLE #1: "x = getvar: #my_array, #1" sets the variable "x" to the value of byte number 1 in the array "my_array" NOTE: If you are referencing an array without a pointer, the '#' symbol is required!!!!

EXAMPLE #2: "x = getvar: my_array_pointer, #3" returns the value of byte number 3 from the array referenced by the pointer 'my_array_pointer'.

To set a value in an array, use the "setvar" statement followed by the array name/pointer, the byte number, and the data that you want it set to.

EXAMPLE #1: "setvar: my_array_pointer, #2, data" sets the value of byte number 2 in the array referenced by the pointer 'my_array_pointer' to 'data'

EXAMPLE #2: "setvar: #my_array, #2, data" sets the value of byte number 2 in the array "my_array" to 'data'





How to use 8bit pointers with variables or arrays

A pointer is simply a variable that contains the memory address of another variable. If you were going to read the value of 'y' but wanted to use a pointer you would first assign a pointer to 'y'.

EXAMPLE: "pointer_to_y = #y" sets the pointer 'pointer_to_y' to the memory address of 'y'

Then you would use the "getvar" function to return the value of the variable pointed to by 'pointer_to_y'

EXAMPLE: "x = getvar: pointer_to_y, #0" sets 'x' to the value of the variable pointed to by 'pointer_to_y'

Or you would use the "setvar" statement to set the value of the variable pointed to by 'pointer_to_y'

EXAMPLE: "setvar: pointer_to_y, #0, x" sets the value of the variable pointed to by 'pointer_to_y' to 'x'






How to use 16bit pointers with byte maps

The pointer to a byte map is declared by the byte map itself. When you say, "byte map: my_pointer", it creates the pointer 'my_pointer' and sets it to reference all data below it.

EXAMPLE: byte map: my_pointer

"DATA"

end map

will save the data "DATA" in a byte map and set a pointer 'my_pointer' to reference it

To read data from a byte map using a pointer, just use the "get" function followed by the pointer and the byte offset.

EXAMPLE: "x = get: my_pointer, #0" sets x to the first byte from the byte map referenced by the pointer 'my_pointer'

NOTE: This is the only case in which you would NEVER use the '#' symbol before the pointer when referencing a byte map.






How to use 8bit pointers with byte maps

Since byte maps use 16bit pointers, you have to use two 8bit pointers to form a 16bit pointer. To do this use the "get8" function followed by the high 8bit pointer, the low 8bit pointer, and the offset.

EXAMPLE #1: "x = get8: #my_high_pointer, #my_low_pointer, #0" sets x to the first byte from the byte map referenced by combining the two 8bit pointers to form a single 16bit pointer.

EXAMPLE #2: "x = get8: #>my_pointer, #<my_pointer, #0" sets x to the first byte from the byte map referenced by combining the two 8bit pointers to form a single 16bit pointer.

ADVANTAGES: This allows you to pass byte map pointers to subroutines. Normally, this wouldn't be possible since all arguments for subroutines are 8 bit BUT since these pointers are 8 bits each, you can compromise by using two arguments instead of one. One for the high pointer, and one for the low pointer.






How to write to the VMU screen

The VMU screen has 48 pixels in each row. 8 pixels are in each byte (one bit per pixel) for a total of six bytes in each row. The six bytes (columns) are in sequence, the rows, however, are not.

Since the rows of the VMU screen are organized out of sequence, you have to calculate the base address of each row. To do this, use the "calc_row" function followed by the row number (0-15). It will return an 8bit pointer to the VMU screen row.

EXAMPLE: "x = calc_row: row" sets 'x' to the row number 'row'

The VMU screen is an SFR or Special Function Register. To write to the screen (or any SFR), you have to use the "setsfr" statement followed by the pointer to the SFR (in this case, the pointer to the row), the offset, and the data you want to place in the SFR.

EXAMPLE: "setsfr: x, #0, data" sets the SFR pointed to by 'x' and the offset #0 to data.

To read data from the VMU screen, you would use the "getsfr" function followed by the pointer to the SFR and the offset.

EXAMPLE: "data = getsfr: x, #0" sets 'data' to the data in the SFR pointed to by 'x' and the offset.

NOTE: For the VMU screen, the offset will be the column number (0-5)

ALSO NOTE: You may have noticed that the only row numbers are 0-15 and there are 32 rows total. How does this work? The thing is that the VMU screen is split into two parts: the upper half and the lower half. Each half is selected with "xbnk". Saying "xbnk = #0" selects the upper half and saying "xbnk = #1" selects the lower half. Each half has 6 columns (0-5) and 16 rows (0-15). Simple once you think about it, but still VERY confusing.





Manipulating the VMU screen by pixel instead of by column

Since each column on the VMU screen is one byte, each bit being a pixel, you can shift the bits one to the right or one to the left and then place the data on the screen. EXAMPLE: "left_bits = shift: right: left_bits, right_bits" shifts the bits in "left_bits" one to the right and stores the overflow bits in "right_bits" and the other ones in "left_bits". If "left_bits" was equal to #%10010011 then the "shift" statement would change "left_bits" to #%01001001 and "right_bits" would become #%10000000. This is very useful for use with the VMU screen.






Using "shift" to move data to a specific pixel

Since each column on the VMU screen is one byte, each bit being a pixel, the number of bits that you shift (to the right) is the remainder of X / 8. In other words, to get the shift amount, you get the modulus of X and 8. To do this, use the "mod" function followed by the X coordinate and #8.

EXAMPLE: "shift_amount = mod: X, #8" sets "shift_amount" to the modulus of X and 8.

Then, all you need to do is use a "loop" statement to shift the data to the right "shift_amount" bits

EXAMPLE: loop

left_data = shift: right: left_data, right_data

exit loop if zero: shift_amount

Finally, just put the "left_data" in the column in which X is located and "right_data" in the column to the right of X. The column in which X is located is equal to X/8. So you just say something like this: "col = X / #8" which simply divides X by 8. Then, you need to get the column to the right of "col". How to do this should be obvious: "right_col = col + #1"