v9938-msx-2-line-command

The Technical Data Book explanation for the LINE command wasn't very easy to wrap my head around. It's definitely more complex than the BASIC LINE command! Finally got it to work, so here's a quick write-up for my future self. And hopefully will benefit someone else one day.

Going to presume it's clear how to use the VDP commands in general, this is a quick explanation of the LINE command and just focusing on those registers.

I'm thinking that a practical example with pseudo code will probably work better than formulating a wordy explanation.

Let's say we need a line from one point ( StartX, StartY ) to another point ( EndX, EndY )

R#36 ( and R#37 if needed ) = StartX /*DX registers*/
R#38 ( and R#39 if needed ) = StartY /*DY registers*/

var_flags = 00000000b /*set default flag values*/

/*determine line drawing directions. Currently set to right and down in var_flags*/
if( EndX < StartX ) var_flags bit 2 = 1 /*means line is going left*/
if( StartY < EndY ) var_flags bit 3 = 1 /*means line is going up*/

/*calculate the x and y distance*/
var_x_offset = math.abs( StartX - EndX ) /*calculate total x distance*/
var_y_offset = math.abs( StartY - EndY ) /*calculate total y distance*/

/*check if long and short side need to be swapped around. Longest side should always go in Maj/NX*/
if( var_x_offset < var_y_offset )
{
     swap var_x_offset and var_y_offset
     var_flags bit 0 = 1 /*let the VDP know x and y are swapped*/
}

R#40 ( and R#41 if needed ) = var_x_offset /*Maj/NX*/
R#42 ( and R#43 if needed ) = var_y_offset /*Min/NY*/

R#44 = var_flags /*Assing flag settings to register*/

Now load R#46 to taste and execute the command!