spinning triangle
This commit is contained in:
parent
76dc15b1c0
commit
3459842128
22
bits.h
22
bits.h
@ -178,7 +178,7 @@
|
|||||||
#define VTX_XY__y_coordinate(v) (((v) & 0xffff) << 16)
|
#define VTX_XY__y_coordinate(v) (((v) & 0xffff) << 16)
|
||||||
#define VTX_XY__x_coordinate(v) (((v) & 0xffff) << 0)
|
#define VTX_XY__x_coordinate(v) (((v) & 0xffff) << 0)
|
||||||
#define VTX_XZ__z_coordinate(v) (((v) & 0xffff) << 16)
|
#define VTX_XZ__z_coordinate(v) (((v) & 0xffff) << 16)
|
||||||
#define VTX_XZ__z_coordinate(v) (((v) & 0xffff) << 0)
|
#define VTX_XZ__x_coordinate(v) (((v) & 0xffff) << 0)
|
||||||
#define VTX_YZ__z_coordinate(v) (((v) & 0xffff) << 16)
|
#define VTX_YZ__z_coordinate(v) (((v) & 0xffff) << 16)
|
||||||
#define VTX_YZ__y_coordinate(v) (((v) & 0xffff) << 0)
|
#define VTX_YZ__y_coordinate(v) (((v) & 0xffff) << 0)
|
||||||
#define VTX_DIFF__z_coordinate(v) (((v) & 0x3ff) << 20)
|
#define VTX_DIFF__z_coordinate(v) (((v) & 0x3ff) << 20)
|
||||||
@ -307,17 +307,17 @@
|
|||||||
#define GXSTAT__command_fifo_interrupt_condition__disable (0x0 << 30)
|
#define GXSTAT__command_fifo_interrupt_condition__disable (0x0 << 30)
|
||||||
#define GXSTAT__command_fifo_interrupt_condition__half_full (0x1 << 30)
|
#define GXSTAT__command_fifo_interrupt_condition__half_full (0x1 << 30)
|
||||||
#define GXSTAT__command_fifo_interrupt_condition__empty (0x2 << 30)
|
#define GXSTAT__command_fifo_interrupt_condition__empty (0x2 << 30)
|
||||||
#define GXSTAT__geometry_engine_busy(v) (((v) >> 27) & 0x1)
|
#define GXSTAT__geometry_engine_busy (0x1 << 27)
|
||||||
#define GXSTAT__fifo_status__empty(v) (((v) >> 26) & 0x1)
|
#define GXSTAT__fifo_status__empty (0x1 << 26)
|
||||||
#define GXSTAT__fifo_status__less_than_half_full(v) (((v) >> 25) & 0x1)
|
#define GXSTAT__fifo_status__less_than_half_full (0x1 << 25)
|
||||||
#define GXSTAT__fifo_status__full(v) (((v) >> 24) & 0x1)
|
#define GXSTAT__fifo_status__full (0x1 << 24)
|
||||||
#define GXSTAT__command_fifo_count(v) (((v) >> 16) & 0xff)
|
#define GXSTAT__command_fifo_count(v) (((v) >> 16) & 0xff)
|
||||||
#define GXSTAT__matrix_stack_status__stack_overflow_or_underflow(v) (((v) >> 15) & 0x1)
|
#define GXSTAT__matrix_stack_status__overflow_or_underflow (0x1 << 15)
|
||||||
#define GXSTAT__matrix_stack_status__stack_busy(v) (((v) >> 14) & 0x1)
|
#define GXSTAT__matrix_stack_status__busy (0x1 << 14)
|
||||||
#define GXSTAT__matrix_stack_status__projection_matrix_stack_level(v) (((v) >> 13) & 0x1)
|
#define GXSTAT__matrix_stack_status__projection_stack_level(v) (((v) >> 13) & 0x1)
|
||||||
#define GXSTAT__matrix_stack_status__position_and_vector_matrix_stack_level(v) (((v) >> 8) & 0x1f)
|
#define GXSTAT__matrix_stack_status__position_and_vector_stack_level(v) (((v) >> 8) & 0x1f)
|
||||||
#define GXSTAT__test_status(v) (((v) >> 1) & 0x1)
|
#define GXSTAT__test_status (0x1 << 1)
|
||||||
#define GXSTAT__test_busy(v) (((v) >> 0) & 0x1)
|
#define GXSTAT__test_busy (0x1 << 0)
|
||||||
#define LISTRAM_COUNT__counter(v) (((v) >> 0) & 0xfff)
|
#define LISTRAM_COUNT__counter(v) (((v) >> 0) & 0xfff)
|
||||||
#define VTXRAM_COUNT__counter(v) (((v) >> 0) & 0x1fff)
|
#define VTXRAM_COUNT__counter(v) (((v) >> 0) & 0x1fff)
|
||||||
#define OBJ_ATTRIBUTE_0__obj_shape__square (0x0 << 14)
|
#define OBJ_ATTRIBUTE_0__obj_shape__square (0x0 << 14)
|
||||||
|
127
main.c
127
main.c
@ -398,12 +398,21 @@ void main()
|
|||||||
// 2d graphics engine B OBJ
|
// 2d graphics engine B OBJ
|
||||||
io_registers.a.VRAM_HI_CNT = (1 << 15) | (0b10 << 8);
|
io_registers.a.VRAM_HI_CNT = (1 << 15) | (0b10 << 8);
|
||||||
|
|
||||||
|
io_registers.a.POWCNT = 0
|
||||||
|
| POWCNT__lcd_output_destination__a_to_upper__b_to_lower
|
||||||
|
| POWCNT__2d_graphics_engine_b__enable
|
||||||
|
| POWCNT__geometry_engine__enable
|
||||||
|
| POWCNT__rendering_engine__enable
|
||||||
|
| POWCNT__2d_graphics_engine_a__enable
|
||||||
|
| POWCNT__lcd__enable;
|
||||||
|
|
||||||
io_registers.a.DISPCNT = 0
|
io_registers.a.DISPCNT = 0
|
||||||
| DISPCNT__bg_screen_base_offset(0)
|
| DISPCNT__bg_screen_base_offset(0)
|
||||||
| DISPCNT__bg_character_base_offset(0)
|
| DISPCNT__bg_character_base_offset(0)
|
||||||
| DISPCNT__display_mode__graphics_display
|
| DISPCNT__display_mode__graphics_display
|
||||||
| DISPCNT__bg0__enable
|
| DISPCNT__bg0__enable
|
||||||
| DISPCNT__display_selection_for_bg0__2d_graphics
|
//| DISPCNT__display_selection_for_bg0__2d_graphics
|
||||||
|
| DISPCNT__display_selection_for_bg0__3d_graphics
|
||||||
| DISPCNT__bg_mode__text0_text1_text2_text3
|
| DISPCNT__bg_mode__text0_text1_text2_text3
|
||||||
;
|
;
|
||||||
|
|
||||||
@ -533,6 +542,70 @@ void main()
|
|||||||
(1/β)cosθ
|
(1/β)cosθ
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/* do 3d */
|
||||||
|
while (io_registers.a.GXSTAT & GXSTAT__geometry_engine_busy);
|
||||||
|
|
||||||
|
// clear matrix stack status
|
||||||
|
io_registers.a.GXSTAT |= GXSTAT__matrix_stack_status__overflow_or_underflow;
|
||||||
|
|
||||||
|
// clear projection matrix stack
|
||||||
|
int projection_stack_level = GXSTAT__matrix_stack_status__projection_stack_level(io_registers.a.GXSTAT);
|
||||||
|
if (projection_stack_level) {
|
||||||
|
io_registers.a.MTX_MODE = MTX_MODE__matrix_mode__projection;
|
||||||
|
io_registers.a.MTX_POP = MTX_POP__number_of_pops(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// clear position_and_vector matrix stack
|
||||||
|
int position_and_vector_stack_level = GXSTAT__matrix_stack_status__position_and_vector_stack_level(io_registers.a.GXSTAT);
|
||||||
|
if (position_and_vector_stack_level) {
|
||||||
|
io_registers.a.MTX_MODE = MTX_MODE__matrix_mode__position_and_vector;
|
||||||
|
io_registers.a.MTX_POP = MTX_POP__number_of_pops(position_and_vector_stack_level);
|
||||||
|
}
|
||||||
|
|
||||||
|
// load identity matrices
|
||||||
|
io_registers.a.MTX_MODE = MTX_MODE__matrix_mode__projection;
|
||||||
|
io_registers.a.MTX_IDENTITY = 0;
|
||||||
|
io_registers.a.MTX_SCALE = (1 << 12);
|
||||||
|
io_registers.a.MTX_SCALE = (1 << 12);
|
||||||
|
io_registers.a.MTX_SCALE = (1 << 12);
|
||||||
|
|
||||||
|
io_registers.a.MTX_MODE = MTX_MODE__matrix_mode__position;
|
||||||
|
io_registers.a.MTX_IDENTITY = 0;
|
||||||
|
|
||||||
|
io_registers.a.MTX_MODE = MTX_MODE__matrix_mode__position_and_vector;
|
||||||
|
io_registers.a.MTX_IDENTITY = 0;
|
||||||
|
|
||||||
|
io_registers.a.SWAP_BUFFERS = 0
|
||||||
|
| SWAP_BUFFERS__depth_buffering__z_value
|
||||||
|
| SWAP_BUFFERS__translucent_polygon_y_sorting__auto_sort;
|
||||||
|
|
||||||
|
io_registers.a.DISP3DCNT = 0
|
||||||
|
| DISP3DCNT__clear_image__disable
|
||||||
|
| DISP3DCNT__fog_master__disable
|
||||||
|
| DISP3DCNT__edge_marking__disable
|
||||||
|
| DISP3DCNT__anti_aliasing__disable
|
||||||
|
| DISP3DCNT__alpha_blending__disable
|
||||||
|
| DISP3DCNT__alpha_test__disable
|
||||||
|
| DISP3DCNT__texture_mapping__disable;
|
||||||
|
|
||||||
|
io_registers.a.CLEAR_COLOR = 0
|
||||||
|
| CLEAR_COLOR__clear_polygon_id(31)
|
||||||
|
| CLEAR_COLOR__alpha_value(31)
|
||||||
|
| CLEAR_COLOR__red(10);
|
||||||
|
|
||||||
|
io_registers.a.CLEAR_DEPTH = CLEAR_DEPTH__value(0x7fff);
|
||||||
|
|
||||||
|
io_registers.a.POLYGON_ATTR = 0
|
||||||
|
| POLYGON_ATTR__alpha_value(31)
|
||||||
|
| POLYGON_ATTR__render_front_surface__enable
|
||||||
|
| POLYGON_ATTR__render_back_surface__enable;
|
||||||
|
|
||||||
|
io_registers.a.VIEWPORT = 0
|
||||||
|
| VIEWPORT__y2(191)
|
||||||
|
| VIEWPORT__x2(255)
|
||||||
|
| VIEWPORT__y1(0)
|
||||||
|
| VIEWPORT__x1(0);
|
||||||
|
|
||||||
int theta = 0;
|
int theta = 0;
|
||||||
while (1) {
|
while (1) {
|
||||||
struct sign_v cos = cos_table[theta];
|
struct sign_v cos = cos_table[theta];
|
||||||
@ -540,6 +613,58 @@ void main()
|
|||||||
if (sin_theta >= 360) sin_theta -= 360;
|
if (sin_theta >= 360) sin_theta -= 360;
|
||||||
struct sign_v sin = cos_table[sin_theta];
|
struct sign_v sin = cos_table[sin_theta];
|
||||||
|
|
||||||
|
int _cos = cos.sign ? -cos.v : cos.v;
|
||||||
|
int _sin = sin.sign ? -sin.v : sin.v;
|
||||||
|
|
||||||
|
{
|
||||||
|
int x = -222;
|
||||||
|
int y = -128;
|
||||||
|
int x1 = x * _cos + y * _sin;
|
||||||
|
int y1 = -x * _sin + y * _cos;
|
||||||
|
|
||||||
|
io_registers.a.BEGIN_VTXS = BEGIN_VTXS__type__triangle;
|
||||||
|
io_registers.a.COLOR = (31 << 10); // blue
|
||||||
|
io_registers.a.VTX_10 = 0
|
||||||
|
| VTX_10__z_coordinate(1 << 6)
|
||||||
|
| VTX_10__y_coordinate(y1 >> (3 + 8))
|
||||||
|
| VTX_10__x_coordinate(x1 >> (3 + 8))
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
int x = 222;
|
||||||
|
int y = -128;
|
||||||
|
int x1 = x * _cos + y * _sin;
|
||||||
|
int y1 = -x * _sin + y * _cos;
|
||||||
|
|
||||||
|
io_registers.a.COLOR = (31 << 5); // green
|
||||||
|
io_registers.a.VTX_10 = 0
|
||||||
|
| VTX_10__z_coordinate(1 << 6)
|
||||||
|
| VTX_10__y_coordinate(y1 >> (3 + 8))
|
||||||
|
| VTX_10__x_coordinate(x1 >> (3 + 8))
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
int x = 0 << 8;
|
||||||
|
int y = 1 << 8;
|
||||||
|
int x1 = x * _cos + y * _sin;
|
||||||
|
int y1 = -x * _sin + y * _cos;
|
||||||
|
|
||||||
|
io_registers.a.COLOR = (31 << 0); // blue
|
||||||
|
io_registers.a.VTX_10 = 0
|
||||||
|
| VTX_10__z_coordinate(1 << 6)
|
||||||
|
| VTX_10__y_coordinate(y1 >> (3 + 8))
|
||||||
|
| VTX_10__x_coordinate(x1 >> (3 + 8))
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
|
io_registers.a.END_VTXS = 0;
|
||||||
|
|
||||||
|
io_registers.a.SWAP_BUFFERS = 0
|
||||||
|
| SWAP_BUFFERS__depth_buffering__z_value
|
||||||
|
| SWAP_BUFFERS__translucent_polygon_y_sorting__auto_sort;
|
||||||
|
|
||||||
// dx
|
// dx
|
||||||
oam.b.param[0].pa = cos.sign ? cos.v : -cos.v;
|
oam.b.param[0].pa = cos.sign ? cos.v : -cos.v;
|
||||||
|
|
||||||
|
@ -202,7 +202,7 @@
|
|||||||
"VTX_XY",,"15-0","x_coordinate",,"0xffff",
|
"VTX_XY",,"15-0","x_coordinate",,"0xffff",
|
||||||
,,,,,,
|
,,,,,,
|
||||||
"VTX_XZ",,"31-16","z_coordinate",,"0xffff",
|
"VTX_XZ",,"31-16","z_coordinate",,"0xffff",
|
||||||
"VTX_XZ",,"15-0","z_coordinate",,"0xffff",
|
"VTX_XZ",,"15-0","x_coordinate",,"0xffff",
|
||||||
,,,,,,
|
,,,,,,
|
||||||
"VTX_YZ",,"31-16","z_coordinate",,"0xffff",
|
"VTX_YZ",,"31-16","z_coordinate",,"0xffff",
|
||||||
"VTX_YZ",,"15-0","y_coordinate",,"0xffff",
|
"VTX_YZ",,"15-0","y_coordinate",,"0xffff",
|
||||||
@ -348,17 +348,17 @@
|
|||||||
"GXSTAT","command_fifo_interrupt_condition","31-30","disable","0b00",,
|
"GXSTAT","command_fifo_interrupt_condition","31-30","disable","0b00",,
|
||||||
"GXSTAT","command_fifo_interrupt_condition","31-30","half_full","0b01",,
|
"GXSTAT","command_fifo_interrupt_condition","31-30","half_full","0b01",,
|
||||||
"GXSTAT","command_fifo_interrupt_condition","31-30","empty","0b10",,
|
"GXSTAT","command_fifo_interrupt_condition","31-30","empty","0b10",,
|
||||||
"GXSTAT",,27,"geometry_engine_busy",,,
|
"GXSTAT",,27,"geometry_engine_busy",1,,
|
||||||
"GXSTAT","fifo_status",26,"empty",,,
|
"GXSTAT","fifo_status",26,"empty",1,,
|
||||||
"GXSTAT","fifo_status",25,"less_than_half_full",,,
|
"GXSTAT","fifo_status",25,"less_than_half_full",1,,
|
||||||
"GXSTAT","fifo_status",24,"full",,,
|
"GXSTAT","fifo_status",24,"full",1,,
|
||||||
"GXSTAT",,"23-16","command_fifo_count",,,
|
"GXSTAT",,"23-16","command_fifo_count",,,
|
||||||
"GXSTAT","matrix_stack_status",15,"stack_overflow_or_underflow",,,
|
"GXSTAT","matrix_stack_status",15,"overflow_or_underflow",1,,
|
||||||
"GXSTAT","matrix_stack_status",14,"stack_busy",,,
|
"GXSTAT","matrix_stack_status",14,"busy",1,,
|
||||||
"GXSTAT","matrix_stack_status",13,"projection_matrix_stack_level",,,
|
"GXSTAT","matrix_stack_status",13,"projection_stack_level",,,
|
||||||
"GXSTAT","matrix_stack_status","12-8","position_and_vector_matrix_stack_level",,,
|
"GXSTAT","matrix_stack_status","12-8","position_and_vector_stack_level",,,
|
||||||
"GXSTAT",,1,"test_status",,,
|
"GXSTAT",,1,"test_status",1,,
|
||||||
"GXSTAT",,0,"test_busy",,,
|
"GXSTAT",,0,"test_busy",1,,
|
||||||
,,,,,,
|
,,,,,,
|
||||||
"LISTRAM_COUNT",,"11-0","counter",,,
|
"LISTRAM_COUNT",,"11-0","counter",,,
|
||||||
,,,,,,
|
,,,,,,
|
||||||
|
|
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user