development:csdk:2.0:headers:draw_direct
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
development:csdk:2.0:headers:draw_direct [2024/11/08 03:42] – clyde | development: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 '' | ||
+ | - Set values for the blitter parameters using the '' | ||
+ | - Start the blitter with '' | ||
+ | - Before modifying parameters to prepare the next drawing, ensure that the last drawing is finished with '' | ||
===== Drawing Semantics ===== | ===== Drawing Semantics ===== | ||
- | These are actually defined in gametank.h but are used for direct drawing | ||
<code C> | <code C> | ||
- | # | + | # |
- | + | # | |
- | #define VX 0 | + | # |
- | #define VY 1 | + | # |
- | #define GX 2 | + | # |
- | #define GY 3 | + | # |
- | #define WIDTH 4 | + | # |
- | #define HEIGHT | + | |
- | #define START 6 | + | |
- | #define COLOR 7 | + | |
</ | </ | ||
`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 " | + | |
- | * GX and GX, as in " | + | |
- | * 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. | + | |
- | * COLOR sets the color for solid colored box mode, bitwise inverted | + | |
+ | Before using these, you'll need to call either '' | ||
===== Functions ===== | ===== Functions ===== | ||
- | ==== name ==== | + | ==== direct_prepare_sprite_mode |
<code C> | <code C> | ||
void direct_prepare_sprite_mode(SpriteSlot sprite); | void direct_prepare_sprite_mode(SpriteSlot sprite); | ||
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 | ||
- | ==== name ==== | + | |
+ | ==== direct_quick_select_sprite | ||
<code C> | <code C> | ||
void direct_quick_select_sprite(SpriteSlot sprite); | void direct_quick_select_sprite(SpriteSlot sprite); | ||
Line 42: | Line 47: | ||
Both this and direct_prepare_sprite_mode select the sprite slot to use | Both this and direct_prepare_sprite_mode select the sprite slot to use | ||
but this skips other register settings and ONLY selects the sprite slot | but this skips other register settings and ONLY selects the sprite slot | ||
- | ==== name ==== | + | ==== direct_prepare_box_mode |
<code C> | <code C> | ||
void direct_prepare_box_mode(); | void direct_prepare_box_mode(); | ||
Line 48: | Line 53: | ||
Setup registers to draw colored boxes in direct mode | Setup registers to draw colored boxes in direct mode | ||
Also checks for and awaits queued drawing operations | Also checks for and awaits queued drawing operations | ||
- | ==== name ==== | + | ==== direct_tiled_mode |
<code C> | <code C> | ||
void direct_tiled_mode(bool enabled); | void direct_tiled_mode(bool enabled); | ||
</ | </ | ||
If enabled, sprite draws will repeat the same 16x16 grid from the source data | If enabled, sprite draws will repeat the same 16x16 grid from the source data | ||
- | ==== name ==== | + | ==== direct_transparent_mode |
<code C> | <code C> | ||
void direct_transparent_mode(bool enabled); | void direct_transparent_mode(bool enabled); | ||
</ | </ | ||
If enabled, sprite draws will treat color 0 as transparent instead of black | If enabled, sprite draws will treat color 0 as transparent instead of black | ||
- | ==== name ==== | + | ==== direct_clip_mode==== |
<code C> | <code C> | ||
void direct_clip_mode(clip_mode_t mode); | void direct_clip_mode(clip_mode_t mode); | ||
</ | </ | ||
Set whether drawings will be clipped at screen edges or wrap around | Set whether drawings will be clipped at screen edges or wrap around | ||
- | ==== name ==== | + | ==== direct_draw_sprite_frame |
<code C> | <code C> | ||
void direct_draw_sprite_frame(SpriteSlot sprite, char x, char y, char frame, char flip); | void direct_draw_sprite_frame(SpriteSlot sprite, char x, char y, char frame, char flip); | ||
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 ===== | ||
- | ==== name ==== | + | |
+ | ==== DIRECT_SET_DEST_X==== | ||
+ | <code C> | ||
+ | DIRECT_SET_DEST_X(x) | ||
+ | </ | ||
+ | Sets the X position of the blitter' | ||
+ | |||
+ | ==== DIRECT_SET_DEST_Y==== | ||
+ | <code C> | ||
+ | DIRECT_SET_DEST_Y(y) | ||
+ | </ | ||
+ | Sets the Y position of the blitter' | ||
+ | |||
+ | ==== DIRECT_SET_SOURCE_X==== | ||
+ | <code C> | ||
+ | DIRECT_SET_SOURCE_X(x) | ||
+ | </ | ||
+ | Sets the X position of the blitter' | ||
+ | |||
+ | This macro also factors in the X offset bit, which is set or cleared by '' | ||
+ | |||
+ | ==== DIRECT_SET_SOURCE_Y==== | ||
+ | <code C> | ||
+ | DIRECT_SET_SOURCE_Y(y) | ||
+ | </ | ||
+ | Sets the Y position of the blitter' | ||
+ | |||
+ | This macro also factors in the Y offset bit, which is set or cleared by '' | ||
+ | |||
+ | ==== DIRECT_SET_WIDTH==== | ||
+ | <code C> | ||
+ | DIRECT_SET_WIDTH(w) | ||
+ | </ | ||
+ | Sets the width of the next blitter operation. | ||
+ | |||
+ | ==== DIRECT_SET_HEIGHT==== | ||
+ | <code C> | ||
+ | DIRECT_SET_HEIGHT(h) | ||
+ | </ | ||
+ | Sets the height of the next blitter operation. Safe to modify during blits. | ||
+ | |||
+ | ==== DIRECT_SET_COLOR==== | ||
+ | <code C> | ||
+ | DIRECT_SET_COLOR(c) | ||
+ | </ | ||
+ | Sets the color that will be used if the blitter is in solid color mode, as set by '' | ||
+ | |||
+ | ==== DIRECT_DRAW_START | ||
<code C> | <code C> | ||
DIRECT_DRAW_START() | DIRECT_DRAW_START() | ||
</ | </ | ||
Use DIRECT_DRAW_START() to start a draw operation after setting the blit registers. This macro includes setting the draw_busy flag so that await_drawing() from gfx_sys.h works properly. | Use DIRECT_DRAW_START() to start a draw operation after setting the blit registers. This macro includes setting the draw_busy flag so that await_drawing() from gfx_sys.h works properly. | ||
- | ==== name ==== | + | ==== DIRECT_DRAW_CLEAR_IRQ |
<code C> | <code C> | ||
DIRECT_DRAW_CLEAR_IRQ() | DIRECT_DRAW_CLEAR_IRQ() | ||
</ | </ | ||
Clears the IRQ flag that is set by the blitter when it completes a draw operation. | Clears the IRQ flag that is set by the blitter when it completes a draw operation. | ||
- | ==== name ==== | + | ==== DIRECT_DRAW_SPRITE |
<code C> | <code C> | ||
DIRECT_DRAW_SPRITE(dst_x, | DIRECT_DRAW_SPRITE(dst_x, | ||
</ | </ | ||
Convenience macro for drawing a sprite, assuming that the sprite mode has already been set with direct_prepare_sprite_mode | Convenience macro for drawing a sprite, assuming that the sprite mode has already been set with direct_prepare_sprite_mode | ||
- | ==== name ==== | + | ==== DIRECT_DRAW_SPRITE |
<code C> | <code C> | ||
DIRECT_DRAW_SPRITE(dst_x, | DIRECT_DRAW_SPRITE(dst_x, | ||
</ | </ | ||
Convenience macro for drawing a colored box, assuming that the box mode has already been set with direct_prepare_box_mode | Convenience macro for drawing a colored box, assuming that the box mode has already been set with direct_prepare_box_mode | ||
+ | |||
+ | ===== Examples ===== | ||
+ | |||
+ | A basic tilemap drawing routine using Direct Draws | ||
+ | <code C> | ||
+ | #include " | ||
+ | #include " | ||
+ | #include " | ||
+ | #include " | ||
+ | #include " | ||
+ | |||
+ | /* Here is a tilemap rendering file that serves as an example of the Direct Drawing API | ||
+ | After calling direct_prepare_sprite_mode or direct_prepare_box_mode the blitter registers | ||
+ | are written to using vram[{registerName}]. When the parametrs are ready, use DIRECT_DRAW_START() | ||
+ | to start the blit which will also set the draw_busy flag so that await_drawing() functions correctly. */ | ||
+ | |||
+ | SpriteSlot map_tile_gfx; | ||
+ | |||
+ | void load_tile_graphics() { | ||
+ | map_tile_gfx = allocate_sprite(& | ||
+ | |||
+ | } | ||
+ | |||
+ | void draw_tile_map() { | ||
+ | static char x, y, i, t; | ||
+ | direct_prepare_sprite_mode(map_tile_gfx); | ||
+ | direct_transparent_mode(false); | ||
+ | push_rom_bank(); | ||
+ | change_rom_bank(ASSET__gfx__test1_bin_bank); | ||
+ | |||
+ | x = 0; | ||
+ | y = 0; | ||
+ | i = 0; | ||
+ | DIRECT_SET_DEST_Y(0); | ||
+ | DIRECT_SET_WIDTH(16); | ||
+ | DIRECT_SET_HEIGHT(16); | ||
+ | while(i < 64) { | ||
+ | t = ASSET__gfx__test1_bin_ptr[i]; | ||
+ | await_drawing(); | ||
+ | DIRECT_SET_DEST_X(x); | ||
+ | DIRECT_SET_SOURCE_X(t << 4); | ||
+ | DIRECT_SET_SOURCE_Y(t & ~15); | ||
+ | DIRECT_DRAW_START(); | ||
+ | ++i; | ||
+ | x += 16; | ||
+ | if(x == 128) { | ||
+ | x = 0; | ||
+ | y += 16; | ||
+ | DIRECT_SET_DEST_Y(y); | ||
+ | } | ||
+ | } | ||
+ | await_drawing(); | ||
+ | |||
+ | pop_rom_bank(); | ||
+ | } | ||
+ | </ | ||
+ |
development/csdk/2.0/headers/draw_direct.1731037340.txt.gz · Last modified: 2024/11/08 03:42 by clyde