User Tools

Site Tools


development:csdk:2.0:headers:draw_direct

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
development:csdk:2.0:headers:draw_direct [2024/11/22 05:15] – [Examples] clydedevelopment:csdk:2.0:headers:draw_direct [2024/11/22 09:07] (current) clyde
Line 2: Line 2:
  
 draw_direct.h provides macros and functions to support setting up draw operations by direct manipulation of blitter registers. The functions and macros are largely convenience functions for setting up the control registers for common operations, like drawing sprites or colored boxes. draw_direct.h provides macros and functions to support setting up draw operations by direct manipulation of blitter registers. The functions and macros are largely convenience functions for setting up the control registers for common operations, like drawing sprites or colored boxes.
 +
 +In general the flow of Direct Drawing is:
 +
 +  - Set up either sprite or box mode with ''direct_prepare_sprite_mode'' or ''direct_prepare_box_mode''
 +  - Set values for the blitter parameters using the ''DIRECT_SET_'' macros for ''SOURCE_X'', ''SOURCE_Y'', ''DEST_X'', ''DEST_Y'', ''WIDTH'' and ''HEIGHT''
 +  - Start the blitter with ''DIRECT_DRAW_START();''
 +  - Before modifying parameters to prepare the next drawing, ensure that the last drawing is finished with ''await_drawing();''
  
 ===== Drawing Semantics ===== ===== Drawing Semantics =====
-These are actually defined in gametank.h but are used for direct drawing 
 <code C> <code C>
-#define vram ((volatile char *0x4000) +#define DIRECT_SET_DEST_X(xvram[VX] = (x); 
- +#define DIRECT_SET_DEST_Y(y) vram[VY] = (y); 
-#define VX 0 +#define DIRECT_SET_SOURCE_X(x) vram[GX] = (x) | direct_sprite_offset_x 
-#define VY 1 +#define DIRECT_SET_SOURCE_Y(y) vram[GY] = (y) | direct_sprite_offset_y 
-#define GX 2 +#define DIRECT_SET_WIDTH(w) vram[WIDTH] = (w); 
-#define GY 3 +#define DIRECT_SET_HEIGHT(h) vram[HEIGHT] = (h); 
-#define WIDTH 4 +#define DIRECT_SET_COLOR(c) vram[COLOR] = ~(c);
-#define HEIGHT +
-#define START 6 +
-#define COLOR 7+
 </code> </code>
 `vram` points to the memory range that is alternately used for the Frame Buffer, the Sprite RAM, and the Blitter Control Registers. If the blitter is enabled (as done by calling one of the direct_prepare_ functions below) the first eight addresses in the VRAM range will map to the Blitter Control Registers. `vram` points to the memory range that is alternately used for the Frame Buffer, the Sprite RAM, and the Blitter Control Registers. If the blitter is enabled (as done by calling one of the direct_prepare_ functions below) the first eight addresses in the VRAM range will map to the Blitter Control Registers.
  
-  *  VX and VY, as in "Video" set the position in the frame buffer pointed to (destination)+  *  VX and VY, as in "Video" set the position in the frame buffer pointed to (destination).
  
-  * GX and GX, as in "Graphics" set the position in the Sprite RAM pointed to (source data)+  * GX and GX, as in "Graphics" set the position in the Sprite RAM pointed to (source data). The setter macro for these also ORs in an offset bit which accounts for Sprite Slots that get allocated to quadrants other than the top-left corner.
  
-  * WIDTH and HEIGHT set the width and height of a drawing operation. Range 0-127 supported, the high bit is used for reversing the direction of blitting (sprite flipping)+  * WIDTH and HEIGHT set the width and height of a drawing operation. Range 0-127 supported, the high bit is used for reversing the direction of blitting (sprite flipping).
  
   * START is a location that will start a blit if you write a 1 to it, but you should use the DIRECT_DRAW_START so that the draw_busy flag will be set.   * START is a location that will start a blit if you write a 1 to it, but you should use the DIRECT_DRAW_START so that the draw_busy flag will be set.
Line 29: Line 32:
   * COLOR sets the color for solid colored box mode, bitwise inverted   * COLOR sets the color for solid colored box mode, bitwise inverted
  
 +Before using these, you'll need to call either ''direct_prepare_sprite_mode'' or ''direct_prepare_box_mode'' to ensure that the blitter control registers are ready to accept these parameters. (See below)
 ===== Functions ===== ===== Functions =====
 ==== direct_prepare_sprite_mode ==== ==== direct_prepare_sprite_mode ====
Line 36: Line 40:
 Setup registers to draw sprites in direct mode Setup registers to draw sprites in direct mode
 Also checks for and awaits queued drawing operations Also checks for and awaits queued drawing operations
 +
 ==== direct_quick_select_sprite ==== ==== direct_quick_select_sprite ====
 <code C> <code C>
Line 69: Line 74:
 Draws a packed sprite as exported from Aseprite with a given X,Y position and frame number. A SpriteSlot is a handle given by allocate_sprite in sprites.h Draws a packed sprite as exported from Aseprite with a given X,Y position and frame number. A SpriteSlot is a handle given by allocate_sprite in sprites.h
 ===== Macros ===== ===== Macros =====
 +
 +==== DIRECT_SET_DEST_X====
 +<code C>
 +DIRECT_SET_DEST_X(x)
 +</code>
 +Sets the X position of the blitter's cursor into the framebuffer.
 +
 +==== DIRECT_SET_DEST_Y====
 +<code C>
 +DIRECT_SET_DEST_Y(y)
 +</code>
 +Sets the Y position of the blitter's cursor into the framebuffer. Safe to modify during blits.
 +
 +==== DIRECT_SET_SOURCE_X====
 +<code C>
 +DIRECT_SET_SOURCE_X(x)
 +</code>
 +Sets the X position of the blitter's cursor in the selected Sprite RAM page.
 +
 +This macro also factors in the X offset bit, which is set or cleared by ''direct_prepare_sprite_mode'' or ''direct_quick_select_sprite'' based on the location of the selected SpriteSlot in Sprite RAM.
 +
 +==== DIRECT_SET_SOURCE_Y====
 +<code C>
 +DIRECT_SET_SOURCE_Y(y)
 +</code>
 +Sets the Y position of the blitter's cursor in the selected Sprite RAM page. Safe to modify during blits.
 +
 +This macro also factors in the Y offset bit, which is set or cleared by ''direct_prepare_sprite_mode'' or ''direct_quick_select_sprite'' based on the location of the selected SpriteSlot in Sprite RAM.
 +
 +==== DIRECT_SET_WIDTH====
 +<code C>
 +DIRECT_SET_WIDTH(w)
 +</code>
 +Sets the width of the next blitter operation.
 +
 +==== DIRECT_SET_HEIGHT====
 +<code C>
 +DIRECT_SET_HEIGHT(h)
 +</code>
 +Sets the height of the next blitter operation. Safe to modify during blits.
 +
 +==== DIRECT_SET_COLOR====
 +<code C>
 +DIRECT_SET_COLOR(c)
 +</code>
 +Sets the color that will be used if the blitter is in solid color mode, as set by ''direct_prepare_box_mode''.
 +
 ==== DIRECT_DRAW_START ==== ==== DIRECT_DRAW_START ====
 <code C> <code C>
Line 106: Line 158:
  
 SpriteSlot map_tile_gfx; SpriteSlot map_tile_gfx;
- 
-static char offset_gx; 
-static char offset_gy; 
  
 void load_tile_graphics() { void load_tile_graphics() {
     map_tile_gfx = allocate_sprite(&ASSET__gfx__tileset_blue_bmp_load_list);     map_tile_gfx = allocate_sprite(&ASSET__gfx__tileset_blue_bmp_load_list);
  
-    //Depending on other allocations the graphic may be offset to another quadrant 
-    //This is not needed for the queued functions which handle this internally 
-    offset_gx = SPRITE_OFFSET_X(map_tile_gfx); 
-    offset_gy = SPRITE_OFFSET_Y(map_tile_gfx); 
 } }
  
Line 129: Line 174:
     y = 0;     y = 0;
     i = 0;     i = 0;
-    vram[VY] = 0; +    DIRECT_SET_DEST_Y(0)
-    vram[WIDTH] = 16; +    DIRECT_SET_WIDTH(16)
-    vram[HEIGHT] = 16;+    DIRECT_SET_HEIGHT(16);
     while(i < 64) {     while(i < 64) {
         t = ASSET__gfx__test1_bin_ptr[i];         t = ASSET__gfx__test1_bin_ptr[i];
         await_drawing();         await_drawing();
-        vram[VX] = x; +        DIRECT_SET_DEST_X(x)
-        vram[GX] = (t << 4) + offset_gx+        DIRECT_SET_SOURCE_X(t << 4); 
-        vram[GY] = (t & ~15) + offset_gy;+        DIRECT_SET_SOURCE_Y(t & ~15);
         DIRECT_DRAW_START();         DIRECT_DRAW_START();
         ++i;         ++i;
Line 144: Line 189:
             x = 0;             x = 0;
             y += 16;             y += 16;
-            vram[VY] = y; //Incidentally, VY, GY, and Height are safe to set while a blit is still running.+            DIRECT_SET_DEST_Y(y); //Incidentally, VY, GY, and Height are safe to set while a blit is still running.
         }         }
     }     }
development/csdk/2.0/headers/draw_direct.1732252524.txt.gz · Last modified: 2024/11/22 05:15 by clyde