Video Mode 9

From Uzebox Wiki
Revision as of 00:07, 6 June 2013 by Uze (talk | contribs) (Documented video mode 9)
Jump to navigation Jump to search
Alt text
Mode 9 Example: Uze Snakes

Introduction

Video mode 9 has the highest resolution on the Uzebox at 4 cycles per pixel yielding 360x224 for 60x28 tiles. This resolution is attained by using "codetiles" where the tile data (or pixels) are actually made of AVR assembly instructions. which embeds both the pixels color and the code to output it. This however comes to the expense of flash usage since 6x8 pixels codetiles consumes 336 bytes of flash vs. 48bytes for regular tiles.

The video mode also supports setting different background colors per tile row.

Specification

  • 260x224 resolution
  • 60x28 tiles VRAM using 8-bit indices
  • 60x28 visible window
  • 6x8 pixel tiles
  • Variable tiles height
  • Background color per tile row
  • Horizontal resolution is fixed at 60 tiles
  • No scrolling or sprites

Configuration

To use Mode 9 , configure your Makefile with this parameter:

 KERNEL_OPTIONS += -DVIDEO_MODE=9

Compile-time Switches

These configuration switches are supported in the Makefile's KERNEL_OPTIONS.

  • TILE_HEIGHT: Specify the height of tiles and sprites. Default=8.
  • VRAM_TILES_V: Vertical size of VRAM.
  • FRAME_LINES: The number of video lines to render. Rendering less video lines leaves the main program with more CPU cycles. Defaults to SCREEN_TILES_V*TILE_HEIGHT.
  • FIRST_RENDER_LINE: When changing FRAME_LINES, the picture will not be centered in the screen. Use this parameter to adjust Y cetering of the picture. Default=20.

Using mode 9

Mode 9 used the regular tile setting functions.

The video support having a different background color per tile row. For example, if the tile source image is the following:

Font6x8.png

Set the "background-color" attribute of the output element of the gconvert file to the color to be "transparent" or replacable at run time. In this case it's black, or color #0 (zero).

<output file="..\data\fonts6x8.inc" type="code" background-color="0">

Then in you program you can access the backgroundColor array and set the required colors.

Typical usage:

 //Set the font and tiles to use.
 SetTileTable(font);

 //Clear the screen (fills the vram with tile zero) 
 ClearVram();

 //define background color for text rows #10
 backgroundColor[10]=7;

 //prints the string with color #7 as the background
 Print(0,10,PSTR("012345678901234567890123456789012345678901234567890123456789"));

Implementation

The Gconvert tool generates the following assembly code for codetiles. If background color was specified in the gconvert config file, pixels in the input picture matching the bg color would result in the "ldi r16,pixeln" replaced by "mov r16,r2".

ldi  r16, pixel1    ; ?1 e? ; 1 cycle
out  0x08, r16      ; 08 b9 ; 1 cycle
ld   r17, Y+        ; 19 91 ; 2 cycles

ldi  r16, pixel2    ; ?1 e? ; 1 cycle
out  0x08, r16      ; 08 b9 ; 1 cycle
mul  r17, r21       ; 15 9f ; 2 cycles

ldi  r16, pixel3    ; ?1 e? ; 1 cycle
out  0x08, r16      ; 08 b9 ; 1 cycle
add  r0, r24        ; 08 0e ; 1 cycle
adc  r1, r25        ; 19 1e ; 1 cycle

ldi  r16, pixel4    ; ?1 e? ; 1 cycle
out  0x08, r16      ; 08 b9 ; 1 cycle
movw r30, r18       ; f9 01 ; 1 cycle
dec  r20            ; 4a 95 ; 1 cycle

ldi  r16, pixel5    ; ?1 e? ; 1 cycle
out  0x08, r16      ; 08 b9 ; 1 cycle
breq .+2            ; 09 f0 ; 1 cycle or 2 if r20 is 0
movw r30, r0        ; f0 01 ; 1 cycle

ldi  r16, pixel6    ; ?1 e? ; 1 cycle
out  0x08, r16      ; 08 b9 ; 1 cycle
ijmp                ; 09 94 ; 2 cycles


Original Forum thread