Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <z64ovl/oot/u10.h>
- typedef struct {
- z64_actor_t actor;
- } entity_t;
- typedef union {
- struct { // meta commands
- union {
- struct { // set up data pointer
- volatile u8* ptr;
- u8 pad[6];
- } c00_data;
- struct { // write <= 9 bytes
- u8 bytes[ 9 ];
- u8 count;
- } c01_data;
- struct { // write N zeroes
- u32 number_of_zeroes;
- u8 padding[ 6 ];
- } c02_data;
- struct { // checksum/ack/nak
- // ?????
- } c03_data;
- struct { // jump to given function pointer
- void (*func_pointer)(void);
- u8 padding[ 6 ];
- } c04_data;
- u8 bytes[ 10 ];
- };
- u8 meta_command;
- } meta;
- struct { // DMA
- u32* dest_ram;
- u32* src_vrom;
- u32 size:24;
- } lowlevel;
- u8 bytes[ 12 ]; // last byte is padding
- } pad_data_t;
- // 12 bytes long
- // ????
- void (*const DmaMgr_SendRequest0)( u32* vram_addr, u32* vrom_addr, u32 size ) = (const void*)0x80001AA0;
- static volatile u8* data_pointer;
- static pad_data_t pad;
- static void step( entity_t* entity, z64_global_t* global ) {
- #define padb( pad, byte ) ( ((u8*)&(global->common.input[ pad ].raw))[ byte ] )
- register union {
- struct {
- u8 big_endian_padding;
- u8 ll_command;
- u8 byte2;
- u8 byte1;
- };
- u32 word;
- } leftover;
- // only run if all pads are connected and working
- if( global->common.input[ 1 ].status != 0 || global->common.input[ 2 ].status != 0 || global->common.input[ 3 ].status != 0 )
- return;
- pad.bytes[ 0 ] = padb( 1, 0 );
- pad.bytes[ 1 ] = padb( 1, 2 );
- pad.bytes[ 2 ] = padb( 1, 3 );
- pad.bytes[ 3 ] = padb( 2, 0 );
- pad.bytes[ 4 ] = padb( 2, 2 );
- pad.bytes[ 5 ] = padb( 2, 3 );
- pad.bytes[ 6 ] = padb( 3, 0 );
- pad.bytes[ 7 ] = padb( 3, 2 );
- pad.bytes[ 8 ] = padb( 3, 3 );
- leftover.word = padb( 1, 1 );
- leftover.word <<= 6;
- leftover.word |= padb( 2, 1 );
- leftover.word <<= 6;
- leftover.word |= padb( 3, 1 );
- pad.bytes[ 9 ] = leftover.byte1;
- pad.bytes[ 10 ] = leftover.byte2;
- switch( leftover.ll_command ) {
- case 0: break; // NOP
- case 1: { // load 11 bytes
- u8 i;
- for( i = 0; i < 11; ++i )
- *(data_pointer++) = pad.bytes[ i ];
- } break;
- case 2: { // DMA copy
- DmaMgr_SendRequest0( pad.lowlevel.dest_ram, pad.lowlevel.src_vrom, pad.lowlevel.size );
- } break;
- case 3: {
- // -----------------------------------------------
- switch( pad.meta.meta_command ) {
- case 0: { // load data pointer
- data_pointer = pad.meta.c00_data.ptr;
- } break;
- case 1: { // write <= 9 bytes
- u8 i;
- for( i = 0; i < pad.meta.c01_data.count; ++i )
- *( data_pointer++ ) = pad.meta.c01_data.bytes[ i ];
- } break;
- case 2: { // write N zeroes
- while( pad.meta.c02_data.number_of_zeroes > 0 ) {
- *( data_pointer++ ) = 0;
- --pad.meta.c02_data.number_of_zeroes;
- }
- } break;
- case 3: { // error correction
- // ????
- } break;
- case 4: { // jump to address
- pad.meta.c04_data.func_pointer();
- } break;
- default: break;
- }
- // -----------------------------------------------
- } break;
- default: break; // this should never happen
- }
- }
- const z64_actor_init_t init_vars = {
- .number = 0xDEAD, .padding = 0xBEEF,
- .type = 0x06, // stage prop
- .room = 0x00,
- .flags = 0x00000030,
- .object = 1,
- .instance_size = sizeof(entity_t),
- .init = NULL,
- .dest = NULL,
- .main = step,
- .draw = NULL
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement