?login_element?

Subversion Repositories NedoOS

Rev

Blame | Last modification | View Log | Download

  1. #ifndef INTERPRETER_C
  2. #define INTERPRETER_C
  3.  
  4. #include <evo.h>
  5. #include "bytecode.h"
  6. #include "int_fragments.c"
  7.  
  8. struct vm_cmd {
  9.     u8 id;
  10.     u8 count;
  11.     u8 length;
  12.     u8 p0;
  13.     i16 p1;
  14.     i16 p2;
  15.     i16 p3;
  16.     i16 p4;
  17.     i16 p5;
  18.     i16 p6;
  19.     i16 p7;
  20. };
  21.  
  22. typedef struct vm_cmd VMCmd;
  23.  
  24. u8 *code;
  25.  
  26. u16 pc = 0 ;
  27. u8 exec_cnt = 0;
  28. u8 executing = 0;
  29.  
  30. static void init_vm(u8 *level)
  31. {
  32.     pc = 0;
  33.     exec_cnt = 0;
  34.     code = level;
  35.     executing = 1;
  36. }
  37.  
  38. static void vm_step()
  39. {
  40.     VMCmd* curCmd;
  41.  
  42.     if (!executing)
  43.         return;
  44.    
  45.     curCmd = (void*) (code + pc);
  46.    
  47.     if (exec_cnt >= curCmd->count) {
  48.         exec_cnt = 0;
  49.         pc += curCmd->length;
  50.         curCmd = (void*) (code + pc);
  51.     }
  52.  
  53.     switch (curCmd->id)
  54.     {
  55.         case NOP_CMD:
  56.             break;
  57.         case JUST_STAR_CMD:
  58.             push_star(curCmd->p1, curCmd->p2);
  59.             break;
  60.         case ENEMIES_PAIR_CMD:
  61.             int_enemies_pair(curCmd->p0, curCmd->p1, curCmd->p2);
  62.             break;
  63.         case MAKE_CARAVAN_CMD:
  64.             int_make_caravan(curCmd->p0, curCmd->p1, curCmd->p2, curCmd->p3, curCmd->p4);
  65.             break;
  66.         case MAKE_LEFT_FLYERS_CMD:
  67.             int_make_left_flyers(curCmd->p0, curCmd->p1, curCmd->p2, curCmd->p3, curCmd->p4);
  68.             break;
  69.         case MAKE_RIGHT_FLYERS_CMD:
  70.             int_make_right_flyers(curCmd->p0, curCmd->p1, curCmd->p2, curCmd->p3, curCmd->p4);
  71.             break;
  72.         case MAKE_BOOM_FAIRY_CMD:
  73.             int_make_boom_fairy(curCmd->p1, curCmd->p0, curCmd->p2);
  74.             break;
  75.         case ENEMY_WAVE_CMD:
  76.             int_enemy_wave(curCmd->p1, curCmd->p0, curCmd->p2);
  77.             break;
  78.         case MID_BOSS1_CMD:
  79.             int_mid_boss1(curCmd->p1, curCmd->p2);
  80.             break;
  81.         case DOUBLE_CARAVAN_CMD:
  82.             int_double_caravan(curCmd->p1, curCmd->p0, curCmd->p2, curCmd->p3);
  83.             break;
  84.         case MAKE_SHOOTING_STAR_CMD:
  85.             int_make_shooting_star(curCmd->p0, curCmd->p1, curCmd->p2, curCmd->p3, curCmd->p4);
  86.             break;
  87.         case PUSH_NPC_CMD:
  88.             int_push_npc(curCmd->p0, curCmd->p1, curCmd->p2, curCmd->p3, curCmd->p4, curCmd->p5, curCmd->p6, curCmd->p7);
  89.             break;
  90.         case TRIANGLE_CMD:
  91.             int_triangle(curCmd->p0, curCmd->p1, curCmd->p2);
  92.             break;
  93.         case MAKE_CORRIDOR_CMD:
  94.             int_make_corridor(curCmd->p0, curCmd->p1, curCmd->p2, curCmd->p3);
  95.             break;
  96.         case TRIANGLE_HALF_CMD:
  97.             int_make_triangle_half(curCmd->p0, curCmd->p1, curCmd->p2, curCmd->p3);
  98.             break;
  99.         case DROPPED_ENEMY_CMD:
  100.             int_dropped_enemy(curCmd->p0, curCmd->p1, curCmd->p2);
  101.             break;
  102.         case FIRING_TRAP_CMD:
  103.             int_firing_trap(curCmd->p1);
  104.             break;
  105.         case MID_BOSS2_CMD:
  106.             int_mid_boss2(curCmd->p1, curCmd->p2);
  107.             break;
  108.         case AIMED_SIDE_ENEMIES_CMD:
  109.             int_aimed_side_enemies(curCmd->p0, curCmd->p1);
  110.             break;
  111.         case AIMED_CIRCLE_CMD:
  112.             int_aimed_circle(curCmd->p0, curCmd->p1);
  113.             break;
  114.         case MARISA_HELP_CMD:
  115.             int_marisa_help();
  116.             break;
  117.         case SET_SPEED_CMD:
  118.             int_set_speed(curCmd->p0, curCmd->p1, curCmd->p2);
  119.             break;
  120.         case AIMED_SHOT_CMD:
  121.             int_aimed_shoot(curCmd->p0);
  122.             break;
  123.         case END_CMD:
  124.             executing = 0;
  125.             break;
  126.        
  127.         default:
  128.                 __asm
  129.                     di
  130.                     halt
  131.                 __endasm;
  132.             break;
  133.     }
  134.  
  135.     exec_cnt ++ ;
  136. }
  137.  
  138. #endif