Advertisement
Guest User

actor v1337

a guest
Feb 22nd, 2020
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 6.89 KB | None | 0 0
  1. #include <z64ovl/oot/u10.h>
  2. #include <z64ovl/helpers.h>
  3.  
  4. // Actor Information
  5. #define ACT_ID                  1
  6. #define OBJ_ID                  1
  7.  
  8. // framebuffer GFX stuff
  9. #ifndef __ASCII_C
  10. #define __ASCII_C
  11.  
  12. #define game_framebuffer (*((u16**)0x8011F56C))
  13.  
  14. #define _letter_width  6
  15. #define _letter_height 8
  16.  
  17. // each byte is a 6px scanline at 1bpp
  18. const u8 ascii_letters[ 768 ] = {
  19.      0, 0, 0, 0, 0, 0, 0, 0,
  20.      8,28,28, 8, 8, 0, 8, 0,
  21.     20,20,20, 0, 0, 0, 0, 0,
  22.     20,20,62,20,62,20,20, 0,
  23.      8,30,32,28, 2,60,24, 0,
  24.      0,50,36, 8,16,18,38, 0,
  25.      8,20, 8,42,36,36,26, 0,
  26.      8, 8, 4, 0, 0, 0, 0, 0,
  27.      8,16,32,32,32,16, 8, 0,
  28.     16, 8, 4, 4, 4, 8,16, 0,
  29.      0,20, 8,62, 8,20, 0, 0,
  30.      0, 4, 4,31, 4, 4, 0, 0,
  31.      0, 0, 0, 0, 0, 8, 8,16,
  32.      0, 0, 0,30, 0, 0, 0, 0,
  33.      0, 0, 0, 0, 0, 8, 8, 0,
  34.      0, 1, 2, 4, 8,16,32, 0,
  35.     28,34,38,42,50,50,28, 0,
  36.      8,24,40, 8, 8, 8,62, 0,
  37.     28,34, 2,12,24,34,62, 0,
  38.     28,34, 2,12, 2,34,28, 0,
  39.      4,12,20,36,62, 4,14, 0,
  40.     62,32,32,60, 2,34,28, 0,
  41.     12,16,32,60,34,34,28, 0,
  42.     62,34, 4, 8,16,16,16, 0,
  43.     28,34,34,28,34,34,28, 0,
  44.     28,34,34,30, 2, 2,28, 0,
  45.      0, 8, 8, 0, 0, 8, 8, 0,
  46.      0, 8, 8, 0, 0, 8, 8,16,
  47.      4, 8,16,32,16, 8, 4, 0,
  48.      0, 0,62, 0, 0,62, 0, 0,
  49.     16, 8, 4, 2, 4, 8,16, 0,
  50.     28,34, 2, 4, 8, 0, 8, 0,
  51.     28,34,46,42,46,32,28, 0,
  52.      8,20,34,34,62,34,34, 0,
  53.     60,18,18,28,18,18,60, 0,
  54.     12,18,32,32,32,18,12, 0,
  55.     60,18,18,18,18,18,60, 0,
  56.     62,18,16,28,16,18,62, 0,
  57.     62,18,16,28,16,16,56, 0,
  58.     12,18,32,32,38,18,14, 0,
  59.     34,34,34,62,34,34,34, 0,
  60.     28, 8, 8, 8, 8, 8,28, 0,
  61.     14, 4, 4, 4,36,36,24, 0,
  62.     50,20,20,24,20,20,51, 0,
  63.     56,16,16,16,16,18,62, 0,
  64.     34,54,42,42,34,34,34, 0,
  65.     34,50,42,38,34,34,34, 0,
  66.     28,34,34,34,34,34,28, 0,
  67.     60,18,18,28,16,16,56, 0,
  68.     28,34,34,34,34,42,28, 3,
  69.     60,18,18,28,24,20,50, 0,
  70.     28,34,32,28, 2,34,28, 0,
  71.     62,42, 8, 8, 8, 8,28, 0,
  72.     34,34,34,34,34,34,28, 0,
  73.     34,34,34,34,34,20, 8, 0,
  74.     34,34,34,42,42,42,20, 0,
  75.     34,20,20, 8,20,20,34, 0,
  76.     34,34,20, 8, 8, 8,28, 0,
  77.     62,34, 4, 8,16,34,62, 0,
  78.     56,32,32,32,32,32,56, 0,
  79.     32,32,16, 8, 4, 2, 1, 0,
  80.     56, 8, 8, 8, 8, 8,56, 0,
  81.      8,20,34,34, 0, 0, 0, 0,
  82.      0, 0, 0, 0, 0, 0, 0,63,
  83.      8, 8, 4, 0, 0, 0, 0, 0,
  84.      0, 0,28, 2,30,34,31, 0,
  85.     48,16,16,20,26,18,44, 0,
  86.      0, 0,28,34,32,34,28, 0,
  87.      6, 2, 2,26,38,38,27, 0,
  88.      0, 0,28,34,62,32,28, 0,
  89.     12,18,16,56,16,16,56, 0,
  90.      0, 0,26,34,34,30, 2,60,
  91.     48,16,20,26,18,18,50, 0,
  92.      8, 0,24, 8, 8, 8,28, 0,
  93.      2, 0, 6, 2, 2,34,34,28,
  94.     48,16,18,20,24,20,18, 0,
  95.     24, 8, 8, 8, 8, 8,28, 0,
  96.      0, 0,52,42,42,42,42, 0,
  97.      0, 0,44,50,34,34,34, 0,
  98.      0, 0,28,34,34,34,28, 0,
  99.      0, 0,60,18,18,28,16,56,
  100.      0, 0,26,36,36,28, 4,14,
  101.      0, 0,54,26,16,16,56, 0,
  102.      0, 0,30,32,28, 2,60, 0,
  103.     16,16,60,16,16,18,12, 0,
  104.      0, 0,34,34,34,38,26, 0,
  105.      0, 0,34,34,34,20, 8, 0,
  106.      0, 0,34,42,42,42,20, 0,
  107.      0, 0,34,20, 8,20,34, 0,
  108.      0, 0,34,34,34,30, 2,60,
  109.      0, 0,62, 4, 8,16,62, 0,
  110.      6, 8, 8,48, 8, 8, 6, 0,
  111.      8, 8, 8, 0, 8, 8, 8, 0,
  112.     48, 8, 8, 6, 8, 8,48, 0,
  113.     18,44, 0, 0, 0, 0, 0, 0,
  114.      0, 8,20,34,34,34,62, 0
  115. };
  116.  
  117. const u8 hex_to_ascii[] = {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
  118.  
  119. #define color_new( r, g, b ) ( (u16)((((u16)(r))<<11)|(((u16)(g))<<6)|(((u16)(b))<<1)|1) )
  120.  
  121. // screen bounds:
  122. // 4 <= X <= 316
  123. // 1 <= Y <= 237
  124.  
  125. inline void put_pixel( u32 x, u32 y, u16 color );
  126. void put_pixel( u32 x, u32 y, u16 color ) {
  127.     x += 4; // account for overscan
  128.     y += 1;
  129.     if( x > 316 ) return;
  130.     if( y > 237 ) return;
  131.     y *= 320;
  132.     y += x;
  133.     game_framebuffer[ y ] = color;
  134. }
  135.  
  136. // Print letter to the screen, with a shadow
  137. // c is u16 as it gets multiplied by 8
  138. void print_char( u16 c, u16 x, u16 y, u16 color ) {
  139.     u8 i, j, scanline;
  140.     if( c < ' ' || c > 127 ) c = '?';
  141.     c -= ' ';
  142.     c <<= 3;
  143.     for( i = 0; i < 8; ++i ) {
  144.         scanline = ascii_letters[ c + i ];
  145.         for( j = 0; j < 6; ++j ) {
  146.             if( scanline & 32 ) {
  147.                 //put_pixel( x + j + 1, y + i + 1, 0 ); // draw dropshadow
  148.                 put_pixel( x + j, y + i, color );
  149.             }
  150.             scanline <<= 1;
  151.         }
  152.     }
  153. }
  154.  
  155. void print_string( u8* str, u16 x, u16 y ) {
  156.     u16 xstart;
  157.     xstart = x;
  158.     while( *str != '\0' ) {
  159.         if( *str == '\n' ) {
  160.             x = xstart;
  161.             y += _letter_height;
  162.         } else {
  163.             print_char( *str, x, y, 0xFFFF );
  164.             x += _letter_width;
  165.         }
  166.         ++str;
  167.     }
  168. }
  169.  
  170. extern s32 _sprintf( u8* dest, const char* format, ...);
  171. asm( ".equ _sprintf, 0x800CE7B4" );
  172.  
  173. #define _printf( x, y, format, ...) {u8 __temp__[192];_sprintf(__temp__,(format),__VA_ARGS__);print_string(__temp__,(x),(y));}
  174.  
  175. // from openbsd
  176. u8* n_strcat( u8* str, u8* append ) {
  177.     u8* save;
  178.     save = str;
  179.     for(;*str;++str);
  180.     while( ( *str++ = *append++ ) != '\0' );
  181.     return save;
  182. }
  183.  
  184. void bytes_to_str( u8* str, u32 l_str, u8* bytes, u32 l_bytes ) {
  185.     u32 current_byte, current_char;
  186.     current_char = 0;
  187.     for( current_byte = 0; current_byte < l_bytes; ++current_byte ) {
  188.         if( current_char < l_str )
  189.             str[ current_char++ ] = hex_to_ascii[ bytes[ current_byte ] >> 4 ];
  190.         if( current_char < l_str )
  191.             str[ current_char++ ] = hex_to_ascii[ bytes[ current_byte ] & 15 ];
  192.         if( current_char < l_str )
  193.             str[ current_char++ ] = ' ';
  194.     }
  195. }
  196.  
  197. void print_bytes( u16 x, u16 y, u8* bytes, u16 amount, u16 per_line ) {
  198.     u16 xstart, i, j;
  199.     xstart = x;
  200.     j = 0;
  201.     for( i = 0; i < amount; ++i ) {
  202.         u8 c;
  203.         c = bytes[ i ];
  204.         print_char( hex_to_ascii[ c >> 4 ], x, y, 0xFFFF ); x += _letter_width;
  205.         print_char( hex_to_ascii[ c & 15 ], x, y, 0xFFFF ); x += _letter_width; x += 2;
  206.         ++j;
  207.        
  208.         if( j >= per_line ) {
  209.             x = xstart; j = 0;
  210.             y += _letter_height;
  211.         }
  212.     }
  213. }
  214.  
  215. void print_string_and_bytes( u16 x, u16 y, u8* str, u8* bytes, u16 amount, u16 per_line ) {
  216.     print_string( str, x, y );
  217.     y += _letter_height;
  218.     print_bytes( x, y, bytes, amount, per_line );
  219. }
  220.  
  221. void print_color( u16 x, u16 y, u16 color ) {
  222.     u8 c, i;
  223.     for( i = 0; i < 3; ++i ) {
  224.         c = color >> 11;
  225.         print_char( hex_to_ascii[ c >> 1 ], x, y, (c&1)?65535:44395 );
  226.         x += _letter_width;
  227.         color <<= 5;
  228.     }
  229. }
  230.  
  231. #endif
  232.  
  233. // Actor Structure
  234. typedef struct {
  235.     z64_actor_t actor;
  236. } entity_t;
  237.  
  238. extern void seed_rotation( void );
  239. asm( ".equ seed_rotation, 0x801FC000" );
  240.  
  241. static void create( entity_t* entity, z64_global_t* global ) {
  242.     *(u32*)0x801FC000 = 0x0C0475E4; // seed angle
  243. }
  244.  
  245. static void step( entity_t* entity, z64_global_t* global ) {
  246.     _printf( 16, 56, "Distance to AOE:%.3f", (entity->actor.dist_from_link_xz) - 1800.0f );
  247.     _printf( 16, 64, "Seed angle:%08X", *(u32*)0x801FC000 ); // big endian :)
  248.     _printf( 16, 72, "Pad 1:%08X", *(u32*)0x8011D790 );
  249.    
  250.     if( entity->actor.dist_from_link_xz < 1800.0f )
  251.         seed_rotation();
  252. }
  253.  
  254. static void draw( entity_t* entity, z64_global_t* global ) {
  255.    
  256. }
  257.  
  258. static void destroy( entity_t* entity, z64_global_t* global ) {
  259.    
  260. }
  261.  
  262. /* .data */
  263. const z64_actor_init_t init_vars = {
  264.     .number = ACT_ID, .padding = 0x0000,
  265.     .type = 0x06, // type = stage prop
  266.     .room = 0x00,
  267.     .flags = 0x00000011, // enable Z targetting
  268.     .object = OBJ_ID,
  269.     .instance_size = sizeof(entity_t),
  270.     .init = create,
  271.     .dest = destroy,
  272.     .main = step,
  273.     .draw = draw
  274. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement