# 8051 assembler mode

colorize ASM51 {
    SyntaxParser = 'SIMPLE';
    
    color {
        { 'Normal',        'Editor_Default' },
        { 'Keyword',       'Editor_Keywords' },
        { 'Number',        'Lang_DecimalNumber' },
        { 'HexNumber',     'Lang_HexNumber' },
        { 'Punctuation',   'Lang_Punctuation' },
        { 'String',        'Lang_String' },
        { 'Comment',       'Lang_Comment' },
        { 'Function',      'Lang_Function' },
        { 'Label',         'Lang_Label' },
    };

    keyword 'Editor_Keywords' {
        'mov', 'push', 'pop', 'movc', 'movx',
        'anl', 'da', 'orl', 'xrl', 'nop',
        'add', 'addc', 'subb', 'mul', 'div',
        'clr', 'setb', 'cpl', 'xch', 'xchd',
        'inc', 'dec', 'rl', 'rlc', 'rrc',
    };

    keyword 'Editor_Keywords3' {
        'a', 'acc', 'b', 'dpl', 'dph', 'dptr',
        'R0', 'R1', 'R2', 'R3',
        'R4', 'R5', 'R6', 'R7',
        'IE', 'IP', 'P0', 'P1',
        'P2', 'P3', 'PCON', 'PSW',
        'PSW', 'SBUF', 'SCON', 'SP', 'TCON', 'TH0',
        'TH1', 'TL0', 'TL1', 'TMOD',
        'T2CON', 'TH2', 'TL2', 'RCAP2H', 'RCAP2L',
    };

     keyword 'Editor_Keywords4' {
       'SM0', 'SM1', 'SM2', 'REN', 'TB8',
       'RB8', 'TI', 'RI', 'E0', 'E1', 'E2',
       'E3', 'E4', 'E5', 'E6', 'E7', 'F0',
       'F1', 'F2', 'F3', 'F4', 'F5', 'F6',
       'F7', 'EA', 'ES', 'ET1', 'EX1', 'ET0',
       'EX0', 'T2', 'T2EX', 'TF1', 'TR1',
       'TF0', 'TR0', 'IE1', 'IT1', 'IE0',
       'IT0', 'TF2', 'EXF2', 'RCLK', 'TCLK',
       'EXEN2', 'TR2', 'C/T2', 'CP/RL2',
       'P0.0', 'P0.1', 'P0.2', 'P0.3',
       'P0.4', 'P0.5', 'P0.6', 'P0.7',
       'P1.0', 'P1.1', 'P1.2', 'P1.3',
       'P1.4', 'P1.5', 'P1.6', 'P1.7',
       'P2.0', 'P2.1', 'P2.2', 'P2.3',
       'P2.4', 'P2.5', 'P2.6', 'P2.7',
       'P3.0', 'P3.1', 'P3.2', 'P3.3',
       'P3.4', 'P3.5', 'P3.6', 'P3.7',
     };

#    keyword '1C' {
    keyword 'Editor_Keywords2' {
        'acall', 'lcall', 'ret', 'reti',
        'jmp',
        'jb', 'jnb',
        'jc', 'jnc', 'jbc', 'ajmp',
        'ljmp', 'sjmp', 'jz', 'jnz',
        'cjne', 'djnz',
    };

    keyword 'Editor_Keywords5' {
        'cseg', 'dseg',
        'dw', 'db',
        'AND', 'OR', 'LE', 'GT', 'EQ',
        'if', 'ifdef', 'ifndef', 'endif', 'else',
        'public', 'extrn',
        'macro', 'endm',
        'end', 'org',
        'proc', 'endp', 'equ', 'define',
        '$TT', '$DA', '$EJ', '$PW',
        'db', 'dw',
        'model', 'ideal', 'codeseg', 'dataseg', 'stack', 'include', 'locals',
    };
    
#    keyword '1A' {
#        'AND', 'OR', 'LE', 'GT', 'EQ',
#        'if', 'ifdef', 'ifndef', 'endif', 'else',
#        'public', 'extrn',
#        'macro', 'endm',
#        'end', 'org',
#        'proc', 'endp', 'equ', 'define',
#        '$TT', '$DA', '$EJ', '$PW',
#        'db', 'dw',
#        'model', 'ideal', 'codeseg', 'dataseg', 'stack', 'include', 'locals',
#    };

    h_state 0 { 'Normal' }
    h_trans { 5, '-s', 'a-zA-Z_$@', 'Normal' }
    h_trans { 1, '<', ';', 'Comment' }
    h_trans { 2, '<', '\'', 'String' }
    h_trans { 3, '<', '"', 'String' }
    h_trans { 4, '-s', '0-9', 'Number' }
    h_trans { 0, 'S', 'a-zA-Z0-9_$@', 'Punctuation' }

    h_state 1 { 'Comment' }
    h_trans { 0, '$', '', 'Comment' }

    h_state 2 { 'String' }
    h_trans { 0, '$', '', 'Normal' }
    h_trans { 0, '', '\'', 'String' }

    h_state 3 { 'String' }
    h_trans { 0, '$', '', 'Normal' }
    h_trans { 0, '', '"', 'String' }

    h_state 4 { 'Number' }
    h_trans { 0, '$', '', 'Normal' }
    h_trans { 0, 's', 'Hh', 'Number' }
    h_trans { 0, '-S', '0-9A-Fa-f', 'Number' }

    h_state 5 { 'Normal' }
    h_trans { 0, '$', '', 'Normal' }
    h_wtype { 0, 0, 0, 'i', 'a-zA-Z0-9_$@' }

}

mode ASM51: PLAIN {      # C/C++ Mode
    FileNameRx          = /\.\c{a51}}$/;
    HilitOn             = 1;
    Colorizer           = 'ASM51';
    AutoIndent          = 1;
    IndentMode          = 'C';
    TabSize             = 8; # think twice before changing this, historically
                             # it's been known to cause a mess in sources ;-)
    SpaceTabs           = 0;
    MatchCase           = 1;
    Trim                = 1;
    MultiLineHilit      = 1;
    AutoHilitParen      = 1;
    
#    RoutineRegexp       = /^\w[\w_:*&~]+[\w\\s_:*&~]@\(.*\){\s*\{}?\s*$/;
    RoutineRegexp       = /^\w[\w_:*&~]+[\w\s_:*&~]@\([^;]*$/;
#	RoutineRx      ^\w[\w_:*&]+[\w\s_:*&]@\(
#	RoutineRx      ^{[a-zA-Z0-9_:*&]#\s*}+\(
    
    SaveFolds           = 2;      # save fold info at end of line
    CommentStart        = ' ;';
    CommentEnd          = '';
}
