/** ASM12 Mode -- Asm mode for the Motorola 68HC12 microcontroller ** Expected syntax is that of the free "as12" compiler from Motorola. ** This file was "hacked" from the Asm.e file provided in Epsilon 12. ** Author -- Tom Almy, tom@almy.us ** Date -- July 2003 ** Lugaru customers may use freely. **/ /************************************************************************ * "Epsilon" is a registered trademark licensed to Lugaru Software, Ltd. * * "EEL" and "Lugaru" are trademarks of Lugaru Software, Ltd. * * * * Copyright (C) 1996, 1997 Lugaru Software Ltd. All rights reserved. * * * * Limited permission is hereby granted to reproduce and modify this * * copyrighted material provided that the resulting code is used only in * * conjunction with Lugaru products and that this notice is retained in * * any such reproduction or modification. * ************************************************************************/ #include "eel.h" #include "proc.h" #include "colcode.h" char _asm12_mode_name[] = "Asm12"; keytable asm_tab; /* key table for asm mode */ user char compile_asm12_cmd[128] = "as12 %r -L"; // assemble this file color_class asm_keyword; color_class asm_register; color_class asm_identifier; color_class asm_preprocessor; color_asm12_range(from, to) // recolor just this section { // last colored region may go past to int t = -1, talk, s; if (from >= to) return to; save_var point, matchstart, matchend; while (get_tagged_region("color-as-unit", from, &s) != -1) from = s - 1; c_init_color(from, to); point = from; to_begin_line(); talk = (to - from > 2000); // show status during long delays while (point < to) { if (!re_search(1, "[0-9A-Za-z_%$#][0-9A-Za-z_]*|[\"';]")) { t = size(); break; } t = matchstart; switch (character(point - 1)) { // check last char case ';': // found comment nl_forward(); set_character_color(t, point, color_class c_comment); break; case '"': // found a string literal point = t; re_search(1, "\"([^\"\\\n]|\\(.|\n))*[\"\n]"); set_character_color(t, point, color_class c_string); if (get_character_color(point, (int *) 0, &s) == color_class c_string && s > to) // fix up after c_init_color(point, to = s); // quoted "'s break; case '\'': // found a char const point = t+2; set_character_color(t, point, color_class c_charconst); break; default: // found identifier, kywd, or number set_character_color(t, point, asm12_keyword_color(t)); break; } if (talk) note("Coloring ASM program: %d%% complete...", muldiv(point - from, 100, to - from)); } c_init_color(to, t); if (talk) note(""); return point; } asm12_keyword_color(from) // return color for "identifier" from here to point { // (something with alpha or digits) char buf[500]; if (point - from > sizeof(buf) / sizeof(char) - 10) save_var point = from + sizeof(buf)/sizeof(char) - 10; buf[0] = '|'; // get identifier, between | chars grab(from, point, buf + 1); if (index("0123456789-$%", buf[1])) return c_number_color(buf + 1); strcpy(buf + point - from + 1, "|"); if (is_asm12_preproc(buf)) return color_class asm_preprocessor; if (is_asm12_keyword(buf)) return color_class asm_keyword; if (is_asm12_register(buf)) return color_class asm_register; return color_class asm_identifier; } is_asm12_keyword(p) // is text in p (must be surrounded by |'s) a keyword? char *p; { if (strstr("|bgnd|mem|iny|dey|dbeq|dbne|tbeq|tbne|ibeq|ibne|jmp|bsr|" "inx|dex|rtc|rti|bset|bclr|brset|brclr|andcc|ediv|mul|emul|" "orcc|jsr|leay|leax|leas|" "bra|brn|bhi|bls|bcc|bcs|bne|beq|bvs|" "bvc|bpl|bmi|bge|blt|bgt|bne|blo|bls|", p)) return 1; if (strstr("|pulx|puly|pula|pulb|pshx|pshy|psha|pshb|pulc|pshc|" "puld|pshd|rts|wai|swi|" "nega|coma|inca|deca|lsra|rola|rora|asra|lsrd|call|" "negb|comb|incb|decb|lsrb|rolb|rorb|asrb|asld|staa|" "stab|std|sty|stx|sts", p)) return 1; if (strstr("|neg|com|inc|dec|lsr|rol|ror|asr|asl|clr|" "suba|cmpa|sbca|anda|bita|ldaa|clra|tsta|eora|adca|oraa|adda|" "subb|cmpb|sbcb|andb|bitb|ldab|clrb|tstb|eorb|adcb|orab|addb|" "cpd|cpy|cpx|cps|nop|tfr|exg|tst|subd|addd|ldd|ldy|ldx|lds|" , p)) return 1; if (strstr("|movw|aba|daa|movb|tab|tba|idiv|fdiv|emacs|emuls|edivs|idivs|" "sba|cba|maxa|mina|emaxd|emind|maxm|minm|emaxm|eminm|" "trap|wav|rev|revw|tbl|etbl|stop|" "lbra|lbrn|lbhi|lbls|lbcc|lbcs|lbne|lbeq|lbvs|" "lbvc|lbpl|lbmi|lbge|lblt|lbgt|lbne|lblo|lbls|", p)) return 1; if (strstr("|clc|sec|cli|sei|clv|sev|xgdx|xgdy|sex|" "equ|org|ds|db|dw|fcc|", p)) return 1; return 0; } is_asm12_preproc(p) // is text in p (must be surrounded by |'s) a reg name? char *p; { if (strstr("|#include|#define|#ifeq|#ifneq|#ifdef|#ifpart|#else|#endif|",p)) return 1; return 0; } is_asm12_register(p) // is text in p (must be surrounded by |'s) a reg name? char *p; { if (strstr("|a|b|d|x|y|sp|pc|ccr|", p)) return 1; return 0; } command asm12_mode() { mode_default_settings(); mode_keys = asm_tab; /* Use these keys. */ major_mode = _asm12_mode_name; compile_buffer_cmd = compile_asm12_cmd; // can compile this strcpy(comment_start, ";[ \t]*"); strcpy(comment_pattern, ";.*$"); strcpy(comment_begin, "; "); strcpy(comment_end, ""); tab_size = 8; recolor_range = color_asm12_range; // set up coloring rules recolor_from_here = recolor_by_lines; if (want_code_coloring) // maybe turn on coloring when_setting_want_code_coloring(); try_calling("asm-mode-hook"); drop_all_colored_regions(); make_mode(); } suffix_asm() { asm12_mode(); } suffix_inc() { asm12_mode(); }