DFLI Library for C and Assembler

Sources are available on github. This library provides a C function (setpa) that allows us to set a pixel on the C+4 DFLI screen (2 free colors in each 4x2 matrix, and additional 2 free colors for each raster line). For example, the next C-code (file test.c and VSIZE=280) generates the out1.prg file that will generate the following image on the C+4.

This C function can help to draw the static image that can be used as the background.

The assembly library can help to create some dynamics. It provides several functions (tobasic, delay, setp, seta, setpbyte, getpbyte, getabyte) and features (vertical scrolling and the timer). Just include your code after the main label in the svn.asm file.

The tobasic function returns to Basic, after calling to this function you can call other functions, for example to print characters or check the keyboard status. The actual return to Basic happens when the RTS instruction is executed, e.g. the next code illustrates the trick.

The delay function simply delays for the specified number of frame ticks. The number must be set in the A register. The actual accuracy is about half a frame tick.

The setp function sets one pixel. The X register must contain the X coordinate, the Y register must contain the low byte of the Y coordinate, the high byte must be at $d8. However if the screen height is less than or equal to 256 then the high byte is ignored. The screen size is set by the VSIZE variable in the svn.asm source file. The A register must contain the color source. There are 4 color sources available:

The seta function sets an attribute for pixels. The A register must contain the color source. This value must be set immediately before the function call because the function uses the Z flag. The X register must contain the X coordinate, the Y register must contain the low byte of the Y coordinate, the high byte must be in $d8. If the screen height is less than or equal to 256 then the high byte is ignored. If A=1 or A=2 the lowest bit of Y and the two lowest bits of X are ignored. The $d9 memory location must contain the color code, for example, $05 for the dark green. The color codes may be taken from this page. If the multicolor is set then the X coordinate is completely ignored because the C+4 hardware only allows us to use 2 multicolors per line. If the background or foreground color is set then the change applies to the entire 4x2 matrix. So, for instance pixels with coordinates in the range (0,0)-(3,1) will have one background and one foreground color.

The setpbyte function sets 4 pixels at once. The X register must contain the X coordinate (the 2 lowest bits are ignored), the Y register must contain the low byte of the Y coordinate, the high byte must be at $d8. If the screen height is less than or equal to 256 then the high byte is ignored. The A register must contain a byte that is a sequence of 4 color sources.

The getpbyte function returns 4 sequential pixel color sources in A. The X register must contain the X coordinate (the 2 lowest bits are ignored), the Y register must contain the low byte of the Y coordinate, the high byte must be at $d8. If the screen height is less than or equal to 256 then the high byte is ignored.

The getabyte function returns attribute information for pixels. The A register must contain the color source. This value must be set immediately before the function call because the function uses the Z flag. The X register must contain the X coordinate, it is ignored if A==0 or A==3, also if A==1 or A==2 then the 2 lowest bits are ignored. The Y register must contain the low byte of the Y coordinate, the high byte must be at $d8. If the screen height is less than or equal to 256 then the high byte is ignored. Also, if A==1 or A==2 then the lowest bit of Y is ignored. The function returns the attribute information via two addresses. The value at the ($d0),Y address contains multicolor #1 if A==0, multicolor #2 if A==3, the luminance byte if A==1 or A==2. The color byte is at the ($d2),Y address if A==1 or A==2. This function may also be used to set or copy attributes. The color byte upper nible is the foreground color (color source 2), and the lower nible is the background (color source 1). The luminance byte upper nible is the background luminance, and the lower nible is the foreground.

The 50/60 Hz timer is available at memory locations $a4-$a5, where $a5 is the low byte. The frequency is set by the PAL or NTSC hardware.

Memory location $d4 contains the vertical scroll value. A positive number scrolls down, a negative number scrolls up. If a value is set there, the screen will scroll once. When the scrolling action is completed this value is set to 0. So set this value only if it is equal to 0. Beware of using too large values, this may cause the displayed image to break!

The library routines use memory locations in the range $d0-$d7, don't use these addresses.