home *** CD-ROM | disk | FTP | other *** search
/ Large Pack of OldSkool DOS MOD Trackers / goattracker_2.68.zip / src / asm / pc.c < prev    next >
C/C++ Source or Header  |  2008-04-01  |  2KB  |  103 lines

  1. /*
  2.  * Copyright (c) 2004 Magnus Lind.
  3.  *
  4.  * This software is provided 'as-is', without any express or implied warranty.
  5.  * In no event will the authors be held liable for any damages arising from
  6.  * the use of this software.
  7.  *
  8.  * Permission is granted to anyone to use this software, alter it and re-
  9.  * distribute it freely for any non-commercial, non-profit purpose subject to
  10.  * the following restrictions:
  11.  *
  12.  *   1. The origin of this software must not be misrepresented; you must not
  13.  *   claim that you wrote the original software. If you use this software in a
  14.  *   product, an acknowledgment in the product documentation would be
  15.  *   appreciated but is not required.
  16.  *
  17.  *   2. Altered source versions must be plainly marked as such, and must not
  18.  *   be misrepresented as being the original software.
  19.  *
  20.  *   3. This notice may not be removed or altered from any distribution.
  21.  *
  22.  *   4. The names of this software and/or it's copyright holders may not be
  23.  *   used to endorse or promote products derived from this software without
  24.  *   specific prior written permission.
  25.  *
  26.  */
  27.  
  28. #include "pc.h"
  29. #include "log.h"
  30. #include <stdlib.h>
  31.  
  32.  
  33. static struct expr unset_value[1];
  34. static struct expr *s_pc1;
  35. static int s_pc2;
  36.  
  37. void pc_dump(int level)
  38. {
  39. }
  40.  
  41. void pc_set(int pc)
  42. {
  43.     s_pc1 = NULL;
  44.     s_pc2 = pc;
  45. }
  46.  
  47. void pc_set_expr(struct expr *pc)
  48. {
  49.     s_pc1 = pc;
  50.     s_pc2 = 0;
  51. }
  52.  
  53. struct expr *pc_get()
  54. {
  55.     struct expr *old_pc1;
  56.  
  57.     if(s_pc1 == unset_value)
  58.     {
  59.         LOG(LOG_ERROR, ("PC must be set by a .org(pc) call.\n"));
  60.         exit(-1);
  61.     }
  62.     if(s_pc1 == NULL || s_pc2 != 0)
  63.     {
  64.         old_pc1 = s_pc1;
  65.         s_pc1 = new_expr_number(s_pc2);
  66.         s_pc2 = 0;
  67.         if(old_pc1 != NULL)
  68.         {
  69.             s_pc1 = new_expr_op2(PLUS, s_pc1, old_pc1);
  70.         }
  71.     }
  72.  
  73.     return s_pc1;
  74. }
  75.  
  76. void pc_add(int offset)
  77. {
  78.     if(s_pc1 != unset_value)
  79.     {
  80.         s_pc2 += offset;
  81.     }
  82. }
  83.  
  84. void pc_add_expr(struct expr *pc)
  85. {
  86.     struct expr *old_pc1;
  87.  
  88.     if(s_pc1 != unset_value)
  89.     {
  90.         old_pc1 = s_pc1;
  91.         s_pc1 = pc;
  92.         if(old_pc1 != NULL)
  93.         {
  94.             s_pc1 = new_expr_op2(PLUS, s_pc1, old_pc1);
  95.         }
  96.     }
  97. }
  98.  
  99. void pc_unset()
  100. {
  101.     pc_set_expr(unset_value);
  102. }
  103.