Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Test actor
- #define is_debug 0
- #if is_debug == 1
- #include <z64ovl/oot/debug.h>
- #define free_memory 0x80600000 /* 2MB */
- #else
- #include <z64ovl/oot/u10.h>
- #define free_memory 0x80400000 /* 4MB */
- #endif
- #define framebuffer_size 0x25800 /* 320x240 16bpp */
- const u8 digit_gfx[ 112 ];
- // entity structure
- typedef struct entity_t entity_t;
- struct entity_t {
- z64_actor_t actor;
- u16* framebuffer;
- u32 randu_state;
- u8 ll_command;
- u16 command;
- u8 input_bytes[11];
- u32* dma_vram_addr;
- u32* dma_vrom_addr;
- u32 dma_size;
- u32 dma_unknown;
- u8* pointer;
- void (*func_pointer)( entity_t*, z64_global_t* );
- };
- // Actor Information
- #define OBJ_ID 1 // Object to use
- inline u32 randu_get( entity_t* entity );
- inline void print_digit( u16* framebuffer, u8 digit, u16 x, u16 y );
- void print_number32( u16* framebuffer, u32 number, u16 x, u16 y );
- void print_number16( u16* framebuffer, u16 number, u16 x, u16 y );
- void print_number8( u16* framebuffer, u8 number, u16 x, u16 y );
- void print_bytes( u16* framebuffer, u8* bytes, u32 amount, u16 x, u16 y, u16 bytes_per_line );
- void get_pad_input( z64_global_t* global, u8 pad_number, u8* out_bytes ) {
- union {
- z64_controller_t pad;
- u32 word;
- } data;
- pad_number &= 3;
- if( global->common.input[ pad_number ].status != 0 ) {
- *((u32*)out_bytes) = 0xFF3FFFFF;
- return;
- }
- data.pad = global->common.input[ pad_number ].raw;
- data.word &= 0xFF3FFFFF;
- *((u32*)out_bytes) = data.word;
- }
- void get_input( entity_t* entity, z64_global_t* global ) {
- u8 ib[ 16 ], *ob;
- get_pad_input( global, 0, &ib[ 0 ] );
- get_pad_input( global, 1, &ib[ 4 ] );
- get_pad_input( global, 2, &ib[ 8 ] );
- get_pad_input( global, 3, &ib[ 12 ] );
- print_bytes( entity->framebuffer, ib, 16, 24, 240 - 64, 4 );
- ob = entity->input_bytes;
- // ib = bytes from controller input
- // ob = extracted bytes, stored in entity
- // read pad bits sequentially (bit twiddling hell)
- ob[ 0 ] = ib[ 4 ];
- ob[ 1 ] = ib[ 5 ] << 2;
- ob[ 1 ] |= ib[ 6 ] >> 6;
- ob[ 2 ] = ib[ 6 ] << 2;
- ob[ 2 ] |= ib[ 7 ] >> 6;
- ob[ 3 ] = ib[ 7 ] << 2;
- ob[ 3 ] |= ib[ 8 ] >> 6;
- ob[ 4 ] = ib[ 8 ] << 2;
- ob[ 4 ] |= ib[ 9 ] >> 4;
- ob[ 5 ] = ib[ 9 ] << 4;
- ob[ 5 ] |= ib[ 10 ] >> 4;
- ob[ 6 ] = ib[ 10 ] << 4;
- ob[ 6 ] |= ib[ 11 ] >> 4;
- ob[ 7 ] = ib[ 11 ] << 4;
- ob[ 7 ] |= ib[ 12 ] >> 4;
- ob[ 8 ] = ib[ 12 ] << 4;
- ob[ 8 ] |= ib[ 13 ] >> 2;
- ob[ 9 ] = ib[ 13 ] << 6;
- ob[ 9 ] |= ib[ 14 ] >> 2;
- ob[ 10 ] = ib[ 14 ] << 6;
- ob[ 10 ] |= ib[ 15 ] >> 2;
- entity->ll_command = ib[ 15 ] & 3;
- }
- int run_commands( entity_t* entity, z64_global_t* global ) {
- union {
- u8** in_u8p;
- u32** in_u32p;
- void (*in_fp)(entity_t *, z64_global_t *);
- u64* in_u64;
- u32* in_u32;
- u16* in_u16;
- u8* in_u8;
- u32 word;
- } types;
- types.in_u8 = entity->input_bytes;
- switch( entity->ll_command ) {
- case 0: break; // NOP
- case 1: { // load new meta command
- entity->command = *( types.in_u16 );
- } break;
- case 2: { // run meta command
- // ----------------------------------
- switch( entity->command ) {
- case 0: { // set data pointer
- entity->pointer = types.in_u8p[ 0 ];
- } break;
- case 1: { // set function pointer
- entity->func_pointer = *( types.in_fp );
- } break;
- case 2: { // jump to function pointer
- entity->func_pointer( entity, global );
- } break;
- case 3: { // write 11 bytes to pointer
- u8 i;
- for( i = 0; i < 11; ++i )
- *(entity->pointer++) = entity->input_bytes[ i ];
- } break;
- case 4: { // write <= 10 bytes to pointer
- u8 count, i;
- count = entity->input_bytes[ 10 ];
- if( count > 10 ) count = 10;
- for( i = 0; i < count; ++i )
- *(entity->pointer++) = entity->input_bytes[ i ];
- } break;
- case 5: { // Set DMA source and dest
- entity->dma_vram_addr = types.in_u32p[ 0 ];
- entity->dma_vrom_addr = types.in_u32p[ 1 ];
- } break;
- case 6: { // Set DMA other attributes
- entity->dma_size = types.in_u32[ 0 ];
- entity->dma_unknown = types.in_u32[ 1 ];
- } break;
- case 7: { // Execute DMA transfer using previously set attributes
- load_data_from_rom(
- entity->dma_vram_addr,
- entity->dma_vrom_addr,
- entity->dma_size,
- entity->dma_unknown
- );
- } break;
- case 10: { // *test* play sound
- sound_play_actor( &entity->actor, types.in_u16[ 0 ] );
- } break;
- case 11: { // *test* draw a number on-screen
- if( entity->framebuffer != NULL )
- print_number32(
- entity->framebuffer,
- types.in_u32[ 0 ],
- types.in_u16[ 2 ],
- types.in_u16[ 3 ]
- );
- } break;
- default: break;
- }
- // ----------------------------------
- } break;
- case 3: break; // do something
- default: break; // this should never happen
- }
- }
- // ----------------------------------------------------------------------------
- // .text
- static void create( entity_t* entity, z64_global_t* global ) {
- u8 i;
- entity->pointer = (u8*)free_memory;
- entity->randu_state = 1;
- entity->framebuffer = global->common.gfx_ctxt->frame_buffer;
- entity->ll_command = 0;
- entity->command = 0;
- for( i = 0; i < 11; ++i )
- entity->input_bytes[ i ] = 0;
- entity->func_pointer = NULL;
- //*((volatile u32*)0x04400000)
- *((volatile u32*)0x800A2634) = 0; // enable pad 2
- *((volatile u32*)0x800A2640) = 0; // enable pad 4
- }
- static void step( entity_t* entity, z64_global_t* global ) {
- entity->framebuffer = global->common.gfx_ctxt->frame_buffer;
- get_input( entity, global );
- if( entity->framebuffer != NULL ) {
- print_digit( entity->framebuffer, entity->ll_command, 24, 56 );
- print_number16( entity->framebuffer, entity->command, 24, 56 + 8 );
- print_number32( entity->framebuffer, (u32)entity->pointer, 24, 56 + 16 );
- print_number32( entity->framebuffer, *((volatile u32*)0x800A2634), 24, 100 );
- print_number32( entity->framebuffer, *((volatile u32*)0x800A2640), 24, 108 );
- print_number32( entity->framebuffer, (u32)entity->func_pointer, 24, 56 + 24 );
- print_bytes( entity->framebuffer, entity->input_bytes, 11, 24, 56 + 32, 11 );
- }
- run_commands( entity, global );
- }
- static void draw( entity_t* entity, z64_global_t* global ) {
- }
- static void destroy( entity_t* entity, z64_global_t* global ) {
- u32 ent_pos;
- ent_pos = ((u32)(&(entity->framebuffer))) - (u32)entity;
- while( ent_pos < sizeof(entity_t) ) {
- ((u8*)&entity->framebuffer)[ ent_pos ] = 0;
- ++ent_pos;
- }
- }
- // .data
- const z64_actor_init_t init_vars = {
- .number = 0xDEAD, .padding = 0xBEEF, // <-- magic values, do not change
- // .number = 0x82, .padding = 0, // <-- magic values, do not change
- .type = 0x06, // type = stage prop
- .room = 0x00,
- .flags = 0x00000030,
- .object = OBJ_ID,
- .instance_size = sizeof(entity_t),
- .init = create,
- .dest = destroy,
- .main = step,
- .draw = draw
- };
- // ----------------------------------------------------------------------------
- const char test1[] = "TheRealWayToGetTheTriforce";
- // digits
- const u8 digit_gfx[ 112 ] = {
- 0b01110,
- 0b10001,
- 0b10011,
- 0b10101,
- 0b11001,
- 0b11001,
- 0b01110,
- 0b00100,
- 0b01100,
- 0b10100,
- 0b00100,
- 0b00100,
- 0b00100,
- 0b11111,
- 0b01110,
- 0b10001,
- 0b00001,
- 0b00110,
- 0b01100,
- 0b10001,
- 0b11111,
- 0b01110,
- 0b10001,
- 0b00001,
- 0b00110,
- 0b00001,
- 0b10001,
- 0b01110,
- 0b00010,
- 0b00110,
- 0b01010,
- 0b10010,
- 0b11111,
- 0b00010,
- 0b00111,
- 0b11111,
- 0b10000,
- 0b10000,
- 0b11110,
- 0b00001,
- 0b10001,
- 0b01110,
- 0b00110,
- 0b01000,
- 0b10000,
- 0b11110,
- 0b10001,
- 0b10001,
- 0b01110,
- 0b11111,
- 0b10001,
- 0b00010,
- 0b00100,
- 0b01000,
- 0b01000,
- 0b01000,
- 0b01110,
- 0b10001,
- 0b10001,
- 0b01110,
- 0b10001,
- 0b10001,
- 0b01110,
- 0b01110,
- 0b10001,
- 0b10001,
- 0b01111,
- 0b00001,
- 0b00001,
- 0b01110,
- 0b00100,
- 0b01010,
- 0b10001,
- 0b10001,
- 0b11111,
- 0b10001,
- 0b10001,
- 0b11110,
- 0b01001,
- 0b01001,
- 0b01110,
- 0b01001,
- 0b01001,
- 0b11110,
- 0b00110,
- 0b01001,
- 0b10000,
- 0b10000,
- 0b10000,
- 0b01001,
- 0b00110,
- 0b11110,
- 0b01001,
- 0b01001,
- 0b01001,
- 0b01001,
- 0b01001,
- 0b11110,
- 0b11111,
- 0b01001,
- 0b01000,
- 0b01110,
- 0b01000,
- 0b01001,
- 0b11111,
- 0b11111,
- 0b01001,
- 0b01000,
- 0b01110,
- 0b01000,
- 0b01000,
- 0b11100
- };
- u32 randu_get( entity_t* entity ) {
- if( entity == NULL ) return 0;
- return entity->randu_state = ( entity->randu_state * 65539U ) & 0x7FFFFFFF;
- }
- inline void put_pixel( u16* framebuffer, u16 x, u32 y, u16 color );
- void put_pixel( u16* framebuffer, u16 x, u32 y, u16 color ) {
- if( x < 320 && y < 240 ) {
- y *= 320;
- y += x;
- framebuffer[ y ] = color;
- }
- }
- void print_digit( u16* framebuffer, u8 digit, u16 x, u16 y ) {
- u8 i;
- digit &= 15;
- digit *= 7;
- for( i = 0; i < 7; ++i ) {
- u8 line, pixel;
- line = digit_gfx[ digit + i ];
- for( pixel = 0; pixel < 5; ++pixel ) {
- if( line & 0b10000 ) {
- put_pixel( framebuffer, x + pixel + 1, y + i + 1, 0 );
- put_pixel( framebuffer, x + pixel, y + i, 0xFFFF );
- }
- line <<= 1;
- }
- }
- }
- void print_number32( u16* framebuffer, u32 number, u16 x, u16 y ) {
- u8 counter;
- for( counter = 0; counter < 8; ++counter ) {
- print_digit( framebuffer, number >> 28, x, y );
- x += 6;
- number <<= 4;
- }
- }
- void print_number16( u16* framebuffer, u16 number, u16 x, u16 y ) {
- u8 counter;
- for( counter = 0; counter < 4; ++counter ) {
- print_digit( framebuffer, number >> 12, x, y );
- x += 6;
- number <<= 4;
- }
- }
- void print_number8( u16* framebuffer, u8 number, u16 x, u16 y ) {
- print_digit( framebuffer, number >> 4, x, y );
- print_digit( framebuffer, number & 15, x + 6, y );
- }
- void print_bytes( u16* framebuffer, u8* bytes, u32 amount, u16 x, u16 y, u16 bytes_per_line ) {
- u16 dx, dy, i;
- dx = dy = 0;
- for( i = 0; i < amount; ++i ) {
- print_digit( framebuffer, bytes[ i ] >> 4, x + dx, y + dy );
- print_digit( framebuffer, bytes[ i ] & 15, x + dx + 6, y + dy );
- dx += 14;
- if( dx >= ( bytes_per_line * 14 ) ) {
- dx = 0;
- dy += 8;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement