/branches/initialv3/asxxxx/as6804/m04adr.c

# · C · 113 lines · 81 code · 12 blank · 20 comment · 22 complexity · 4f31e7bb804ec6555e2cf84ed94b234a MD5 · raw file

  1. /* m04adr.c */
  2. /*
  3. * (C) Copyright 1989-2000
  4. * All Rights Reserved
  5. *
  6. * Alan R. Baldwin
  7. * 721 Berkeley St.
  8. * Kent, Ohio 44240
  9. */
  10. #include <stdio.h>
  11. #include <setjmp.h>
  12. #include "asxxxx.h"
  13. #include "m6804.h"
  14. int
  15. addr(esp)
  16. register struct expr *esp;
  17. {
  18. register int c;
  19. if ((c = getnb()) == '#') {
  20. expr(esp, 0);
  21. esp->e_mode = S_IMMED;
  22. } else if (c == ',') {
  23. if ((esp->e_mode = admode(xy)) == 0)
  24. aerr();
  25. } else {
  26. unget(c);
  27. expr(esp, 0);
  28. esp->e_mode = S_DIR;
  29. }
  30. if (esp->e_addr & ~0xFF)
  31. aerr();
  32. return (esp->e_mode);
  33. }
  34. /*
  35. * Enter admode() to search a specific addressing mode table
  36. * for a match. Return the addressing value on a match or
  37. * zero for no match.
  38. */
  39. int
  40. admode(sp)
  41. register struct adsym *sp;
  42. {
  43. register char *ptr;
  44. register int i;
  45. register char *ips;
  46. ips = ip;
  47. unget(getnb());
  48. i = 0;
  49. while ( *(ptr = &sp[i].a_str[0]) ) {
  50. if (srch(ptr)) {
  51. return(sp[i].a_val);
  52. }
  53. i++;
  54. }
  55. ip = ips;
  56. return(0);
  57. }
  58. /*
  59. * srch --- does string match ?
  60. */
  61. int
  62. srch(str)
  63. register char *str;
  64. {
  65. register char *ptr;
  66. ptr = ip;
  67. while (*ptr && *str) {
  68. if(ccase[*ptr & 0x007F] != ccase[*str & 0x007F])
  69. break;
  70. ptr++;
  71. str++;
  72. }
  73. if (ccase[*ptr & 0x007F] == ccase[*str & 0x007F]) {
  74. ip = ptr;
  75. return(1);
  76. }
  77. if (!*str)
  78. if (any(*ptr," \t\n,];")) {
  79. ip = ptr;
  80. return(1);
  81. }
  82. return(0);
  83. }
  84. /*
  85. * any --- does str contain c?
  86. */
  87. int
  88. any(c,str)
  89. int c;
  90. char *str;
  91. {
  92. while (*str)
  93. if(*str++ == c)
  94. return(1);
  95. return(0);
  96. }
  97. struct adsym xy[] = { /* x or y registers */
  98. { "x", S_IX },
  99. { "y", S_IY },
  100. { "", 0x00 }
  101. };