420 if (sscanf(def, "%d", &num) != 1) {
421 error("Bad integer value near '%s'", def);
422 return;
423 }
424
425 (void) strcpy(fle.parms.gpr[n].name, parm);
426 fle.parms.gpr[n].num = ngpr;
427 fle.parms.gpr[n].def = num;
428 fle.parms.ngpr = n + 1;
429
430 add_init(ngpr, num, parm);
431
432 add_symbol(parm, SY_PARM, gpr_base + ngpr++);
433 }
434
435 static void
436 compile_mono(char **tokens, int cnt)
437 {
438 char *parm, *def;
439 int n, num;
440 char tmp[128];
441
442 CHECK_COUNT(tokens, cnt, 3, 3);
443
444 parm = tokens[1];
445 def = tokens[2];
446
447 n = fle.parms.ngpr;
448 if (n >= MAX_GPR_PARMS) {
449 error("Too many GPR parameters");
450 return;
451 }
452
453 if (sscanf(def, "%d", &num) != 1) {
454 error("Bad integer value near '%s'", def);
455 return;
456 }
457
458 (void) strcpy(fle.parms.gpr[n].name, parm);
459 fle.parms.gpr[n].num = ngpr;
460 fle.parms.gpr[n].def = num;
588 if (strcmp(tokens[0], ".output") == 0) {
589 compile_output(tokens, cnt);
590 return;
591 }
592
593 if (strcmp(tokens[0], ".rem") == 0) {
594 compile_rem(tokens, cnt);
595 return;
596 }
597 if (strcmp(tokens[0], ".'") == 0) {
598 compile_rem(tokens, cnt);
599 return;
600 }
601
602 error("Unknown directive '%s'", tokens[0]);
603 }
604
605 static void
606 compile_asm(char **tokens, int cnt)
607 {
608 char *parms[4];
609 sym_t *symbols[4];
610 #define EMIT(o, r, a, x, y) \
611 fle.code[pc*2] = ((x) << 10) | (y); \
612 fle.code[pc*2+1] = ((o) << 20) | ((r) << 10) | a; pc++
613 #define EMIT_AUDIGY(o, r, a, x, y) \
614 fle.code[pc*2] = ((x) << 12) | (y); \
615 fle.code[pc*2+1] = ((o) << 24) | ((r) << 12) | a; pc++
616
617 int i, n = 0, nerr = 0;
618 int ninputs = 0;
619
620 CHECK_COUNT(tokens, cnt, 5, 5);
621
622 for (i = 0; i < 4; i++) {
623 if ((symbols[i] = find_symbol(tokens[i+1])) == NULL) {
624 (void) fprintf(stderr, "%s\n", tokens[i+1]);
625 nerr++;
626 error("Undefined symbol '%s'", tokens[i + 1]);
627 continue;
628 }
629
630 if (symbols[i]->type == SY_INPUT)
631 ninputs++;
632
633 if (symbols[i]->type == SY_ACCUM && i != 1)
634 error("Bad usage of 'accum' operand.");
635 }
636
637 if (nerr > 0)
796 add_symbol("0x7fffffff", SY_CONST, 0x04f);
797
798 add_symbol("0xffffffff", SY_CONST, 0x050);
799 add_symbol("-1", SY_CONST, 0x050);
800
801 add_symbol("0xfffffffe", SY_CONST, 0x051);
802 add_symbol("-2", SY_CONST, 0x051);
803
804 add_symbol("accum", SY_ACCUM, 0x056);
805 add_symbol("CCR", SY_CONST, 0x057);
806
807 add_symbol("noise_L", SY_CONST, 0x058);
808 add_symbol("noise_R", SY_CONST, 0x059);
809 add_symbol("IRQREQ", SY_CONST, 0x05a);
810 }
811 }
812
813 static void
814 produce_map(char *name)
815 {
816 char fname[1024];
817 int i;
818 FILE *f;
819
820 if ((f = fopen(name, "w")) == NULL) {
821 perror(name);
822 return;
823 }
824
825 (void) fprintf(f, "%d\n", pc);
826
827 for (i = 0; i < nsyms; i++) {
828 (void) fprintf(f, "%04x %x %s\n",
829 symtab[i].arg, symtab[i].type, symtab[i].name);
830 }
831
832 (void) fclose(f);
833 if (verbose) {
834 (void) fprintf(stderr,
835 "No errors detected - Map written to %s\n", name);
836 }
940 } else {
941 (void) fprintf(f, "\t%u, 0x%x%s,\n",
942 fle.init[i].gpr, fle.init[i].value,
943 fle.init[i].value >= 0x80000000U ? "U" : "");
944 }
945 }
946 (void) fprintf(f, "};\n");
947
948 done:
949 (void) fclose(f);
950 if (verbose) {
951 (void) fprintf(stderr,
952 "No errors detected - Header written to %s\n",
953 fname);
954 }
955 }
956
957 int
958 main(int argc, char *argv[])
959 {
960 char line[4096], *p, *s, *outfile;
961 char *iline;
962 int i;
963 FILE *input;
964 char *tokens[10];
965 int tokcnt;
966 char *mapfile = NULL;
967 char *header = NULL;
968 char *prefix = NULL;
969
970 outfile = NULL;
971 infile = NULL;
972 input = NULL;
973 progname = argv[0];
974
975 while ((i = getopt(argc, argv, "m:h:o:i:P:021v")) != EOF) {
976 switch (i) {
977 case 'o':
978 outfile = optarg;
979 break;
980 case 'i':
981 infile = strdup(optarg);
|
420 if (sscanf(def, "%d", &num) != 1) {
421 error("Bad integer value near '%s'", def);
422 return;
423 }
424
425 (void) strcpy(fle.parms.gpr[n].name, parm);
426 fle.parms.gpr[n].num = ngpr;
427 fle.parms.gpr[n].def = num;
428 fle.parms.ngpr = n + 1;
429
430 add_init(ngpr, num, parm);
431
432 add_symbol(parm, SY_PARM, gpr_base + ngpr++);
433 }
434
435 static void
436 compile_mono(char **tokens, int cnt)
437 {
438 char *parm, *def;
439 int n, num;
440
441 CHECK_COUNT(tokens, cnt, 3, 3);
442
443 parm = tokens[1];
444 def = tokens[2];
445
446 n = fle.parms.ngpr;
447 if (n >= MAX_GPR_PARMS) {
448 error("Too many GPR parameters");
449 return;
450 }
451
452 if (sscanf(def, "%d", &num) != 1) {
453 error("Bad integer value near '%s'", def);
454 return;
455 }
456
457 (void) strcpy(fle.parms.gpr[n].name, parm);
458 fle.parms.gpr[n].num = ngpr;
459 fle.parms.gpr[n].def = num;
587 if (strcmp(tokens[0], ".output") == 0) {
588 compile_output(tokens, cnt);
589 return;
590 }
591
592 if (strcmp(tokens[0], ".rem") == 0) {
593 compile_rem(tokens, cnt);
594 return;
595 }
596 if (strcmp(tokens[0], ".'") == 0) {
597 compile_rem(tokens, cnt);
598 return;
599 }
600
601 error("Unknown directive '%s'", tokens[0]);
602 }
603
604 static void
605 compile_asm(char **tokens, int cnt)
606 {
607 sym_t *symbols[4];
608 #define EMIT(o, r, a, x, y) \
609 fle.code[pc*2] = ((x) << 10) | (y); \
610 fle.code[pc*2+1] = ((o) << 20) | ((r) << 10) | a; pc++
611 #define EMIT_AUDIGY(o, r, a, x, y) \
612 fle.code[pc*2] = ((x) << 12) | (y); \
613 fle.code[pc*2+1] = ((o) << 24) | ((r) << 12) | a; pc++
614
615 int i, nerr = 0;
616 int ninputs = 0;
617
618 CHECK_COUNT(tokens, cnt, 5, 5);
619
620 for (i = 0; i < 4; i++) {
621 if ((symbols[i] = find_symbol(tokens[i+1])) == NULL) {
622 (void) fprintf(stderr, "%s\n", tokens[i+1]);
623 nerr++;
624 error("Undefined symbol '%s'", tokens[i + 1]);
625 continue;
626 }
627
628 if (symbols[i]->type == SY_INPUT)
629 ninputs++;
630
631 if (symbols[i]->type == SY_ACCUM && i != 1)
632 error("Bad usage of 'accum' operand.");
633 }
634
635 if (nerr > 0)
794 add_symbol("0x7fffffff", SY_CONST, 0x04f);
795
796 add_symbol("0xffffffff", SY_CONST, 0x050);
797 add_symbol("-1", SY_CONST, 0x050);
798
799 add_symbol("0xfffffffe", SY_CONST, 0x051);
800 add_symbol("-2", SY_CONST, 0x051);
801
802 add_symbol("accum", SY_ACCUM, 0x056);
803 add_symbol("CCR", SY_CONST, 0x057);
804
805 add_symbol("noise_L", SY_CONST, 0x058);
806 add_symbol("noise_R", SY_CONST, 0x059);
807 add_symbol("IRQREQ", SY_CONST, 0x05a);
808 }
809 }
810
811 static void
812 produce_map(char *name)
813 {
814 int i;
815 FILE *f;
816
817 if ((f = fopen(name, "w")) == NULL) {
818 perror(name);
819 return;
820 }
821
822 (void) fprintf(f, "%d\n", pc);
823
824 for (i = 0; i < nsyms; i++) {
825 (void) fprintf(f, "%04x %x %s\n",
826 symtab[i].arg, symtab[i].type, symtab[i].name);
827 }
828
829 (void) fclose(f);
830 if (verbose) {
831 (void) fprintf(stderr,
832 "No errors detected - Map written to %s\n", name);
833 }
937 } else {
938 (void) fprintf(f, "\t%u, 0x%x%s,\n",
939 fle.init[i].gpr, fle.init[i].value,
940 fle.init[i].value >= 0x80000000U ? "U" : "");
941 }
942 }
943 (void) fprintf(f, "};\n");
944
945 done:
946 (void) fclose(f);
947 if (verbose) {
948 (void) fprintf(stderr,
949 "No errors detected - Header written to %s\n",
950 fname);
951 }
952 }
953
954 int
955 main(int argc, char *argv[])
956 {
957 char *outfile;
958 int i;
959 FILE *input;
960 char *tokens[10];
961 int tokcnt;
962 char *mapfile = NULL;
963 char *header = NULL;
964 char *prefix = NULL;
965
966 outfile = NULL;
967 infile = NULL;
968 input = NULL;
969 progname = argv[0];
970
971 while ((i = getopt(argc, argv, "m:h:o:i:P:021v")) != EOF) {
972 switch (i) {
973 case 'o':
974 outfile = optarg;
975 break;
976 case 'i':
977 infile = strdup(optarg);
|