home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 2 / FFMCD02.bin / new / os20 / util / ssl / sslexamp / keycomp.asm < prev    next >
Encoding:
Assembly Source File  |  1993-12-21  |  15.3 KB  |  934 lines

  1. ; Keymap Compiler
  2. ; (c) 1993 MJSoft System Software
  3. ; Martin Mares
  4.  
  5. ;    opt    x+
  6.  
  7.     include    "ssmac.h"
  8.  
  9.     tbase    a4
  10.     clistart
  11.  
  12.     writeln    <Keymap Compiler 1.0, (c) 1993 MJSoft System Software>
  13.  
  14.     get.l    from,a0            ; Load source file
  15.     geta    fromname,a1
  16.     dtl    <kms>,a2
  17.     moveq    #80,d0
  18.     call    ss,AddExtension
  19.     geta    fromname,a0
  20.     call    LoadFile
  21.     move.l    d0,a3            ; A3 points to source file
  22.  
  23.     get.l    to,d0            ; Create destination file
  24.     bne.s    opento
  25.     geta    fromname,a0
  26.     move.l    a0,d1
  27.     call    dos,FilePart
  28.     move.l    d0,a1
  29.     geta    work,a2
  30.     move.l    a2,a0
  31. copyfn1    move.b    (a1)+,(a2)+
  32.     bne.s    copyfn1
  33.     push    a0
  34.     call    ss,RemExtension
  35.     pop    d0
  36. opento    move.l    d0,a0
  37.     move.l    #1006,d0
  38.     push    a0
  39.     call    ss,TrackOpen
  40.     move.l    d0,d7            ; D7=destfh
  41.  
  42.     vpea    fromname
  43.     dtl.l    <Compiling %s to %s.>,a0
  44.     move.l    sp,a1
  45.     call    Printf
  46.     addq.l    #8,sp
  47.  
  48. ; Build hash table
  49.  
  50.     move.l    #128,d0
  51.     moveq    #0,d1
  52.     call    ss,InitHashTree
  53.     put.l    d0,htr
  54.     dv.l    htr
  55.  
  56.     lea    keytab(pc),a2
  57.     moveq    #0,d2
  58. bhat_loop    tst.b    (a2)
  59.     beq.s    bhat_end
  60.     get.l    htr,a0
  61.     move.l    a2,a1
  62.     moveq    #2,d0
  63.     call    AddHashItem
  64.     move.l    d0,a0
  65.     move.w    d2,(a0)+
  66.     addq.w    #1,d2
  67. bhat_next    tst.b    (a2)+
  68.     bne.s    bhat_next
  69.     bra.s    bhat_loop
  70.  
  71. ; Create header of destination file
  72.  
  73. bhat_end    move.l    d7,d1
  74.     geta    hh_id,a0
  75.     move.l    a0,d2
  76.     move.l    #hdrend-hh_id,d3
  77.     moveq    #1,d4
  78.     bsr    chfwrite
  79.  
  80. ; Initialize some fields in the header
  81.  
  82.     lea    inittab(pc),a0
  83. 1$    move.w    (a0)+,d0
  84.     beq.s    2$
  85.     move.w    (a0)+,d1
  86.     geta    hh_id,a1
  87.     add.w    d0,a1
  88.     move.w    d1,(a1)
  89.     bra.s    1$
  90. 2$    dv.l    lino            ; Line number
  91.     put.w    #1,lino+2
  92.     dv.l    chlen            ; Code hunk length
  93.     put.w    #hdrend-km_node,chlen+2
  94.  
  95. ; Initialize data structures
  96.  
  97.     geta    keytypes,a0
  98.     moveq    #103,d0
  99.     moveq    #-128,d1
  100. init_1    move.b    d1,(a0)+
  101.     dbra    d0,init_1
  102.  
  103. ; Start parsing of source
  104.  
  105. srcloop    bsr    getobj        ; Read key header
  106. srcentry    tst.b    d1
  107.     beq.s    srcloop
  108.     bmi    saveit
  109.     subq.b    #3,d1
  110.     bne.s    exkey
  111.     moveq    #$20,d5
  112.     cmp.b    #$6c,d0
  113.     beq.s    keyex1
  114.     moveq    #$40,d5
  115.     cmp.b    #$6d,d0
  116.     beq.s    keyex1
  117.     moveq    #0,d5
  118.     cmp.b    #$71,d0
  119.     beq.s    keyex2
  120. exkey    moveq    #6,d0
  121.     bra    error
  122.  
  123. keyex1    bsr    getobj
  124.     subq.b    #3,d1
  125.     bne.s    exkey
  126.     cmp.b    #$71,d0
  127.     bne.s    exkey        ; D5 now holds correct key type
  128. keyex2    bsr    getobj        ; Read key name
  129.     subq.b    #3,d1
  130.     bne.s    exkey1
  131.     cmp.b    #104,d0
  132.     bcs.s    keyex3
  133. exkey1    moveq    #7,d0
  134.     bra    error
  135.  
  136. keyex3    move.l    d0,d6        ; D6=key code
  137.     moveq    #0,d4        ; D4.0 = nonrepeatable, .1=capsable
  138. keyflg    bsr    getobj        ; Parse key flags
  139.     tst.b    d1
  140.     beq.s    keybody
  141.     bmi.s    keyincl
  142.     subq.b    #3,d1
  143.     bne.s    exkey
  144.     moveq    #0,d1
  145.     cmp.b    #$68,d0    ; SHIFT
  146.     beq.s    keyfl1
  147.     moveq    #1,d1
  148.     cmp.b    #$69,d0    ; ALT
  149.     beq.s    keyfl1
  150.     moveq    #2,d1
  151.     cmp.b    #$70,d0    ; CTRL
  152.     beq.s    keyfl1
  153.     moveq    #0,d1
  154.     cmp.b    #$6a,d0    ; CAPS
  155.     beq.s    keyfl2
  156.     moveq    #1,d1
  157.     cmp.b    #$6b,d0    ; NOREP
  158.     beq.s    keyfl2
  159. keyincl    moveq    #8,d0
  160. keyincle    bra    error
  161.  
  162. keyfl1    bset    d1,d5
  163. keyfl    beq.s    keyflg
  164.     moveq    #9,d0
  165.     bra.s    keyincle
  166. keyfl2    bset    d1,d4
  167.     bra.s    keyfl
  168.  
  169. keytwice    moveq    #12,d0
  170.     bra    error
  171.  
  172. keybody    geta    keytypes,a0    ; Key header done, store the flags
  173.     add.l    d6,a0
  174.     cmp.b    #$80,(a0)
  175.     bne.s    keytwice
  176.     move.b    d5,(a0)
  177.     move.l    d6,d0
  178.     lsr.w    #3,d0
  179.     geta    capsable,a0
  180.     btst    #1,d4    ; NoRep
  181.     bne.s    1$
  182.     bset    d6,(repeatable-capsable)(a0,d0.w)
  183. 1$    btst    #0,d4    ; Caps
  184.     beq.s    2$
  185.     bset    d6,0(a0,d0.w)
  186. 2$    add.l    d6,d6
  187.     add.l    d6,d6
  188.     geta    keydata,a2
  189.     add.l    d6,a2
  190.     dv.b    usedmean
  191.     clrv.b    usedmean
  192.     dv.l    alloccount
  193.     moveq    #0,d0
  194.     moveq    #0,d2
  195.     not.b    d5
  196. 3$    move.b    d0,d1
  197.     and.b    d5,d1
  198.     bne.s    31$
  199.     addq.l    #2,d2
  200. 31$    addq.b    #1,d0
  201.     cmp.b    #8,d0
  202.     bcs.s    3$
  203.     not.b    d5
  204.     put.l    d2,alloccount
  205.  
  206.     btst    #5,d5
  207.     bne.s    bodydead
  208.     btst    #6,d5
  209.     bne.s    bodystrg
  210.  
  211. bodynorm    moveq    #0,d6        ; Body of normal key
  212.     moveq    #0,d2
  213. normloop    moveq    #4,d3
  214.     move.b    d5,d0
  215.     addq.b    #1,d0
  216.     and.b    #7,d0
  217.     beq.s    1$
  218.     moveq    #0,d3
  219. 1$    bsr    getflags
  220.     cmp.b    #1,d1
  221.     bne.s    normend
  222.     lsl.l    #3,d4
  223.     lsl.l    d4,d0
  224.     or.l    d0,d6
  225.     bsr    checkeol
  226.     bra.s    normloop
  227.  
  228. normend    move.l    d6,(a2)
  229.     bra    srcentry
  230.  
  231. bodystrg    bsr    clrwork
  232. strgloop    moveq    #0,d3
  233.     bsr    getflags
  234.     cmp.b    #2,d1
  235.     bne.s    strgend
  236.     add.l    d4,d4
  237.     move.l    d0,d2
  238.     move.l    d0,a0
  239.     bsr    strlen
  240.     geta    work,a0
  241.     move.b    d0,0(a0,d4.l)
  242.     bsr    allocate
  243.     move.b    d0,1(a0,d4.l)
  244.     move.l    d2,a0
  245.     geta    work,a1
  246.     add.l    d0,a1
  247. 1$    move.b    (a0)+,(a1)+
  248.     bne.s    1$
  249.     bsr    checkeol
  250.     bra.s    strgloop
  251. strgend    bsr    shipout
  252.     bra    srcentry
  253.  
  254. bodydead    bsr    clrwork
  255.     push    a2
  256. deadloop    moveq    #0,d3
  257.     bsr    getflags
  258.     add.l    d4,d4
  259.     geta    work,a2
  260.     add.l    d4,a2
  261.     cmp.b    #1,d1
  262.     beq.s    deadnorm
  263.     cmp.b    #3,d1
  264.     bne.s    deadend
  265.     cmp.w    #$6f,d0    ; MOD
  266.     beq.s    deadmod
  267.     cmp.w    #$6e,d0    ; PREFIX
  268.     bne.s    deadend
  269.     move.b    #$08,(a2)+
  270.     bsr    getobj
  271.     subq.b    #1,d1
  272.     bne.s    pxexp
  273.     move.b    d0,(a2)
  274.     cmp.b    #16,d0
  275.     bcc.s    pxexp5
  276.     bsr    getobj
  277.     tst.b    d1
  278.     beq.s    deadloop
  279.     bmi.s    deadloop
  280.     subq.b    #5,d1
  281.     bne.s    pxexp2
  282.     bsr    getobj
  283.     subq.b    #1,d1
  284.     bne.s    pxexp4
  285.     cmp.b    #16,d0
  286.     bcc.s    pxexp5
  287.     lsl.b    #4,d0
  288.     or.b    d0,(a2)
  289.     bsr    checkeol
  290.     bra.s    deadloop
  291.  
  292. pxexp    moveq    #17,d0
  293. pxexp3    bra    error
  294. pxexp2    moveq    #20,d0
  295.     bra.s    pxexp3
  296. pxexp4    moveq    #21,d0
  297.     bra.s    pxexp3
  298. pxexp5    moveq    #22,d0
  299.     bra.s    pxexp3
  300.  
  301. deadend    pop    a2
  302.     bsr.s    shipout
  303.     bra    srcentry
  304.  
  305. deadnorm    sf    (a2)+
  306.     move.b    d0,(a2)+
  307.     bsr    checkeol
  308.     bra    deadloop
  309.  
  310. deadmod    moveq    #0,d0
  311.     bsr.s    allocate
  312.     move.b    #1,(a2)+
  313.     move.b    d0,(a2)+
  314.     geta    work,a2
  315.     add.l    d0,a2
  316. modloop    bsr    getobj
  317.     subq.b    #1,d1
  318.     bne.s    deadmoder
  319.     addqv.l    #1,alloccount
  320.     move.b    d0,(a2)+
  321.     bsr    getobj
  322.     tst.b    d1
  323.     beq    deadloop
  324.     bmi    deadloop
  325.     subq.b    #5,d1
  326.     beq.s    modloop
  327. comexer    moveq    #19,d0
  328.     bra.s    deadmoder2
  329. deadmoder    moveq    #18,d0
  330. deadmoder2    bra    error
  331.  
  332. ; String operations
  333.  
  334. strlen    move.l    a0,d0
  335. 1$    tst.b    (a1)+
  336.     bne.s    1$
  337.     sub.l    a1,d0
  338.     neg.l    d0
  339.     subq.l    #1,d0
  340.     rts
  341.  
  342. ; Allocation of dynamic key data
  343.  
  344. allocate    get.l    alloccount,d1
  345.     cmp.w    #256,d1
  346.     bcc.s    allocerr
  347.     exg.l    d0,d1
  348.     add.l    d0,d1
  349.     put.l    d1,alloccount
  350.     rts
  351.  
  352. allocerr    moveq    #16,d0
  353.     bra    error
  354.  
  355. shipout    mpush    d0-d4
  356.     get.l    chlen,(a2)
  357.     move.l    d7,d1
  358.     geta    work,a0
  359.     move.l    a0,d2
  360.     get.l    alloccount,d3
  361.     moveq    #1,d4
  362.     bsr    chfwrite
  363.     mpop    d0-d4
  364.     rts
  365.  
  366. clrwork    geta    work,a0
  367.     moveq    #31,d0
  368. 1$    clr.l    (a0)+
  369.     dbra    d0,1$
  370.     rts
  371.  
  372. ; Check EOL condition
  373.  
  374. checkeol    bsr    getobj
  375.     tst.b    d1
  376.     bmi.s    1$
  377.     bne.s    2$
  378. 1$    rts
  379. 2$    moveq    #15,d0
  380.     bra    error
  381.  
  382. ; Get meaning flags (D3=disabled flags)
  383.  
  384. getflags    moveq    #0,d4        ; D4 holds the flags
  385.     move.b    d5,d0
  386.     not.b    d0
  387.     and.b    #$07,d0
  388.     or.b    d0,d3
  389. flagloop    bsr    getobj
  390.     tst.b    d1
  391.     beq.s    flageol
  392.     bmi.s    flageof
  393.     cmp.b    #3,d1
  394.     bne.s    flagend
  395.     moveq    #0,d2
  396.     cmp.b    #$68,d0
  397.     beq.s    flagflag
  398.     moveq    #1,d2
  399.     cmp.b    #$69,d0
  400.     beq.s    flagflag
  401.     moveq    #2,d2
  402.     cmp.b    #$70,d0
  403.     bne.s    flagend
  404. flagflag    btst    d2,d3
  405.     bne.s    flagbad
  406.     bset    d2,d4
  407.     beq.s    flagloop
  408.     moveq    #14,d0
  409.     bra.s    flagfler
  410.  
  411. flagbad    moveq    #10,d0
  412. flagfler    bra    error
  413.  
  414. flageol    tst.b    d4
  415.     beq.s    flagloop
  416. flagerr    moveq    #11,d0
  417.     bra.s    flagfler
  418.  
  419. flagend    cmp.b    #3,d1
  420.     bne.s    flagend1
  421.     cmp.w    #$6c,d0
  422.     beq.s    flageof
  423.     cmp.w    #$6d,d0
  424.     beq.s    flageof
  425.     cmp.w    #$71,d0
  426.     beq.s    flageof
  427. flagend1    bsetv    d4,usedmean
  428.     bne.s    flagtwic
  429.     moveq    #1,d2        ; Normalize flags
  430.     moveq    #0,d3
  431.     not.b    d5
  432.     push    d0
  433. 1$    move.b    d2,d0
  434.     and.b    d5,d0
  435.     bne.s    2$
  436.     addq.b    #1,d3
  437.     cmp.b    d2,d4
  438.     bne.s    2$
  439.     move.b    d3,d4
  440.     bra.s    3$
  441. 2$    addq.b    #1,d2
  442.     cmp.b    #8,d2
  443.     bcs.s    1$
  444. 3$    pop    d0
  445.     not.b    d5
  446. flageof    rts
  447.  
  448. flagtwic    moveq    #13,d0
  449.     bra.s    flagfler
  450.  
  451. ; Save the rest of keymap
  452.  
  453. saveit    vmovev.l    chlen,km_name
  454.     geta    fromname,a0
  455.     move.l    a0,d1
  456.     call    dos,FilePart
  457.     move.l    d0,a0
  458.     move.l    d0,d2
  459.     call    ss,RemExtension
  460.     move.l    d2,a0
  461.     move.l    d2,a1
  462. 1$    tst.b    (a1)+
  463.     bne.s    1$
  464.     sub.l    a0,a1
  465.     move.l    a1,d3
  466.     moveq    #1,d4
  467.     move.l    d7,d1
  468.     bsr    chfwrite
  469.  
  470.     move.l    d7,d1            ; Pad to longword boundary
  471.     lea    huend+4(pc),a0
  472.     move.l    a0,d2
  473.     get.l    chlen,d3
  474.     neg.l    d3
  475.     moveq    #3,d0
  476.     and.l    d0,d3
  477.     beq.s    save1
  478.     sub.l    d3,d2
  479.     moveq    #1,d4
  480.     bsr    chfwrite
  481.  
  482. save1    get.l    chlen,d0        ; Adjust hunk length
  483.     addq.l    #3,d0
  484.     lsr.l    #2,d0
  485.     put.l    d0,hh_size
  486.     put.l    d0,hc_size
  487.  
  488.     move.l    #$3ec,d0        ; Put HUNK_RELOC
  489.     bsr    putl
  490.     moveq    #9,d0            ; Count relocations
  491.     geta    keytypes,a0
  492.     moveq    #103,d1
  493. countrel    move.b    (a0)+,d2
  494.     and.b    #$60,d2
  495.     beq.s    1$
  496.     addq.l    #1,d0
  497. 1$    dbra    d1,countrel
  498.     bsr    putl
  499.     moveq    #0,d0
  500.     bsr    putl
  501.     lea    reloxs(pc),a0        ; Write basic relocations
  502.     move.l    d7,d1
  503.     move.l    a0,d2
  504.     moveq    #36,d3
  505.     moveq    #1,d4
  506.     bsr    chfwrite
  507.     geta    keytypes,a2        ; Relocs for string & dead keys
  508.     move.l    #keydata-km_node,d2
  509. 2$    move.b    (a2)+,d0
  510.     and.b    #$60,d0
  511.     beq.s    3$
  512.     move.l    d2,d0
  513.     bsr.s    putl
  514. 3$    addq.l    #4,d2
  515.     cmp.l    #keydata-km_node+104*4,d2
  516.     bcs.s    2$
  517.  
  518.     moveq    #0,d0            ; End of relocs
  519.     bsr.s    putl
  520.  
  521.     move.l    #$3f2,d0        ; Write HUNK_END
  522.     bsr.s    putl
  523.     move.l    d7,d1            ; ... and rewrite the header
  524.     call    Flush
  525.     move.l    d7,d1
  526.     moveq    #0,d2
  527.     moveq    #-1,d3
  528.     call    Seek
  529.     move.l    d7,d1
  530.     geta    hh_id,a0
  531.     move.l    a0,d2
  532.     move.l    #hdrend-hh_id,d3
  533.     bsr.s    chwrite
  534.  
  535.     writeln    <Done.>
  536.  
  537.     rts
  538.  
  539. ; Relocation table
  540.  
  541. reloxs    dc.l    km_name-km_node
  542.     dc.l    lo_types-km_node
  543.     dc.l    lo_data-km_node
  544.     dc.l    lo_caps-km_node
  545.     dc.l    lo_rept-km_node
  546.     dc.l    hi_types-km_node
  547.     dc.l    hi_data-km_node
  548.     dc.l    hi_caps-km_node
  549.     dc.l    hi_rept-km_node
  550.  
  551. ; Output routines
  552.  
  553. putl    mpush    d0-d4            ; Put one longword
  554.     move.l    d7,d1
  555.     move.l    sp,d2
  556.     moveq    #4,d3
  557.     moveq    #1,d4
  558.     bsr.s    chfwrite
  559.     mpop    d0-d4
  560.     rts
  561.  
  562. chwrite    call    dos,Write
  563.     cmp.l    d0,d3
  564.     bra.s    chfwr1
  565.  
  566. chfwrite    call    dos,FWrite
  567.     addv.l    d3,chlen
  568.     moveq    #1,d1
  569.     cmp.l    d0,d1
  570. chfwr1    bne.s    writerr
  571.     rts
  572. writerr    err    <Error writing destination file!>
  573.  
  574. ; Data for generating of hunk longword pad
  575.  
  576. huend    dc.l    0
  577.  
  578. ; Get object from source file
  579. ; A3=SrcPtr => D1=ObjType,D0=ObjValue
  580.  
  581. ot_eof    equ    -1    ; End of file
  582. ot_eol    equ    0    ; End of line
  583. ot_number    equ    1    ; Number
  584. ot_string    equ    2    ; Quoted string, Value=&string contents
  585. ot_keyword    equ    3    ; Keyword, Value=Keyword#
  586. ot_unknown    equ    4    ; Unknown non-quoted string, Value=&string
  587. ot_comma    equ    5    ; A comma
  588.  
  589. getobj    move.b    (a3)+,d0        ; Main loop
  590.     beq.s    gob_eof
  591.     cmp.b    #' ',d0
  592.     beq.s    getobj
  593.     cmp.b    #9,d0
  594.     beq.s    getobj
  595.     cmp.b    #10,d0
  596.     beq    gob_eol
  597.     cmp.b    #'0',d0
  598.     bcs.s    gob_1
  599.     cmp.b    #'9'+1,d0
  600.     bcs    gob_num
  601. gob_1    cmp.b    #'"',d0
  602.     beq    gob_str
  603.     cmp.b    #',',d0
  604.     beq.s    gob_comma
  605.     cmp.b    #';',d0
  606.     beq.s    gob_semic
  607.     cmp.b    #'\',d0
  608.     beq.s    gob_baksl
  609.     cmp.b    #'''',d0
  610.     beq.s    gob_char
  611.     cmp.b    #'_',d0
  612.     beq    gob_unq
  613.     cmp.b    #'?',d0
  614.     beq    gob_unq
  615.     cmp.b    #'A',d0
  616.     bcs.s    gob_bad
  617.     cmp.b    #'Z'+1,d0
  618.     bcs    gob_unq
  619.     cmp.b    #'a',d0
  620.     bcs.s    gob_bad
  621.     cmp.b    #'z'+1,d0
  622.     bcs    gob_unq
  623. gob_bad    moveq    #0,d0
  624.     bra    error
  625.  
  626. gob_eof    subq.l    #1,a3            ; End of file
  627.     moveq    #-1,d1
  628.     rts
  629.  
  630. gob_baksl    cmp.b    #10,(a3)+        ; Ignored end of line
  631.     bne.s    gob_bad
  632.     addq.l    #1,a3
  633.     addqv.l    #1,lino
  634.     bra    getobj
  635.  
  636. gob_semic    move.b    (a3)+,d0        ; Comment
  637.     beq.s    gob_eof
  638.     cmp.b    #10,d0
  639.     bne.s    gob_semic
  640. gob_eol    addqv.l    #1,lino            ; End of line
  641.     moveq    #0,d1
  642.     rts
  643.  
  644. gob_comma    moveq    #5,d1            ; Comma
  645.     rts
  646.  
  647. gob_char    moveq    #0,d0            ; Quoted character
  648.     move.b    (a3)+,d0
  649.     beq.s    1$
  650.     cmp.b    #10,d0
  651.     beq.s    1$
  652.     cmp.b    #'''',d0
  653.     bne.s    2$
  654.     cmp.b    (a3)+,d0
  655.     bne.s    1$
  656. 2$    cmp.b    #'''',(a3)+
  657.     bne.s    1$
  658.     bra.s    num_end
  659.  
  660. 1$    moveq    #1,d0
  661.     bra    error
  662.  
  663. gob_num    subq.l    #1,a3            ; Decimal number
  664.     moveq    #0,d0
  665.     moveq    #0,d1
  666. 1$    move.b    (a3)+,d1
  667.     sub.b    #'0',d1
  668.     bcs.s    2$
  669.     cmp.b    #10,d1
  670.     bcc.s    2$
  671.     mulu    #10,d0
  672.     add.l    d1,d0
  673.     cmp.w    #256,d0
  674.     bcs.s    1$
  675.     moveq    #2,d0
  676.     bra    error
  677. 2$    subq.l    #1,a3
  678. num_end    moveq    #1,d1
  679.     rts
  680.  
  681. gob_str    move.l    a3,a0            ; Quoted string
  682.     subq.l    #1,a0
  683.     move.l    a0,a1
  684. 1$    move.b    (a3)+,d0
  685.     beq.s    str_bad
  686.     cmp.b    #10,d0
  687.     beq.s    str_bad
  688.     cmp.b    #'"',d0
  689.     beq.s    2$
  690.     cmp.b    #'\',d0
  691.     beq.s    3$
  692. 10$    move.b    d0,(a0)+
  693.     bra.s    1$
  694.  
  695. 3$    move.b    (a3)+,d0
  696.     cmp.b    #'\',d0
  697.     beq.s    10$
  698.     cmp.b    #'"',d0
  699.     beq.s    10$
  700.     bsr.s    getnib
  701.     move.b    d0,d1
  702.     lsl.b    #4,d1
  703.     move.b    (a3)+,d0
  704.     bsr.s    getnib
  705.     or.b    d1,d0
  706.     bra.s    10$
  707.  
  708. 2$    cmp.b    (a3)+,d0
  709.     beq.s    10$
  710.     subq.l    #1,a3
  711.     sf    (a0)+
  712.     move.l    a1,d0
  713.     moveq    #2,d1
  714.     rts
  715.  
  716. str_bad    moveq    #3,d0
  717.     bra    error
  718.  
  719. getnib    sub.b    #'0',d0
  720.     bcs.s    1$
  721.     cmp.b    #10,d0
  722.     bcs.s    2$
  723.     and.b    #$DF,d0
  724.     cmp.b    #17,d0
  725.     bcs.s    1$
  726.     subq.b    #7,d0
  727.     cmp.b    #16,d0
  728.     bcc.s    1$
  729. 2$    rts
  730.  
  731. 1$    moveq    #4,d0
  732.     bra.s    error
  733.  
  734. gob_unq    subq.l    #1,a3            ; Unquoted string
  735.     geta    strbuf,a0
  736.     move.l    a0,a1
  737.     moveq    #63,d1
  738. 1$    move.b    (a3)+,d0
  739.     cmp.b    #'_',d0
  740.     beq.s    3$
  741.     cmp.b    #'?',d0
  742.     beq.s    3$
  743.     cmp.b    #'0',d0
  744.     bcs.s    2$
  745.     cmp.b    #'9'+1,d0
  746.     bcs.s    3$
  747.     and.b    #$DF,d0
  748.     cmp.b    #'A',d0
  749.     bcs.s    2$
  750.     cmp.b    #'Z'+1,d0
  751.     bcc.s    2$
  752. 3$    move.b    d0,(a0)+
  753.     dbra    d1,1$
  754.     bra.s    snerr
  755.  
  756. 2$    subq.l    #1,a3
  757.     sf    (a0)
  758.     push    a1
  759.     get.l    htr,a0
  760.     call    ss,FindHashItem
  761.     tst.l    d0
  762.     beq.s    4$
  763.     move.l    d0,a0
  764.     addq.l    #4,sp
  765.     moveq    #0,d0
  766.     move.w    (a0),d0
  767.     moveq    #3,d1
  768.     rts
  769.  
  770. 4$    pop    d0
  771.     moveq    #4,d1
  772.     rts
  773.  
  774. snerr    moveq    #5,d0
  775.  
  776. ; Errors
  777.  
  778. error    dtl.l    <Error in line %ld in file %s: %s !>,a0
  779.     add.w    d0,d0
  780.     move.w    errptrs(pc,d0.w),d0
  781.     pea    errptrs(pc,d0.w)
  782.     vpea    fromname
  783.     vpush    lino
  784.     move.l    sp,a1
  785.     call    ss,Printf
  786.     put.w    #10,sv_rc+2
  787.     jump    ExitCleanup
  788.  
  789. ert    macro
  790.     dc.w    err\1-errptrs
  791.     endm
  792.  
  793. errptrs    ert    0
  794.     ert    1
  795.     ert    2
  796.     ert    3
  797.     ert    4
  798.     ert    5
  799.     ert    6
  800.     ert    7
  801.     ert    8
  802.     ert    9
  803.     ert    10
  804.     ert    11
  805.     ert    12
  806.     ert    13
  807.     ert    14
  808.     ert    15
  809.     ert    16
  810.     ert    17
  811.     ert    18
  812.     ert    19
  813.     ert    20
  814.     ert    21
  815.     ert    22
  816.  
  817. err0    dc.b    'Illegal character',0
  818. err1    dc.b    'Malformed character constant',0
  819. err2    dc.b    'Number out of range',0
  820. err3    dc.b    'String constant exceeds line',0
  821. err4    dc.b    'Bad character code',0
  822. err5    dc.b    'Syntax error',0
  823. err6    dc.b    'Incorrect key definition',0
  824. err7    dc.b    'Key name expected',0
  825. err8    dc.b    'Unexpected end of file',0
  826. err9    dc.b    'Key attribute already set',0
  827. err10    dc.b    'Unexpected attribute',0
  828. err11    dc.b    'Key meaning expected',0
  829. err12    dc.b    'Key defined twice',0
  830. err13    dc.b    'Key meaning defined twice',0
  831. err14    dc.b    'Attribute defined twice',0
  832. err15    dc.b    'End of line expected',0
  833. err16    dc.b    'Dynamic part of key data too long',0
  834. err17    dc.b    'Prefix number expected',0
  835. err18    dc.b    'Character/number expected',0
  836. err19    dc.b    'Comma expected',0
  837. err20    dc.b    'Comma or end of line expected',0
  838. err21    dc.b    'Secondary prefix number expected',0
  839. err22    dc.b    'Prefix number out of range (must be 0-15)',0
  840.  
  841.     even
  842.  
  843. ; Init table
  844.  
  845. iten    macro
  846.     dc.w    \1-hh_id+2,\2
  847.     endm
  848.  
  849. itoff    macro
  850.     iten    \1,\2-km_node
  851.     endm
  852.  
  853. inittab    iten    hh_id,$03f3
  854.     iten    hh_num,1
  855.     iten    hc_id,$03e9
  856.     itoff    lo_types,keytypes
  857.     itoff    lo_data,keydata
  858.     itoff    lo_caps,capsable
  859.     itoff    lo_rept,repeatable
  860.     itoff    hi_types,keytypes+64
  861.     itoff    hi_data,keydata+256
  862.     itoff    hi_caps,capsable+8
  863.     itoff    hi_rept,repeatable+8
  864.     dc.w    0
  865.  
  866. ; Data
  867.  
  868.     dbuf    keyflags,$68    ; Standard key flags (see keymap.i)
  869.     dbuf    auxflags,$68    ; b0=NOREP,b1=CAPS
  870.     dbuf    keys,$68    ; Key data
  871.     dbuf    relocs,104*4    ; Relocation offsets of keys
  872.  
  873.     dbuf    fromname,80    ; Source name
  874.  
  875. ; Output file:
  876.  
  877.     dv.l    hh_id        ; HUNK_HEADER
  878.     dv.l    hh_null
  879.     dv.l    hh_num        ; Number of hunks = 1
  880.     dv.l    hh_first
  881.     dv.l    hh_last
  882.     dv.l    hh_size        ; Size of code hunk
  883.     dv.l    hc_id        ; HUNK_CODE
  884.     dv.l    hc_size        ; Size of code hunk
  885.  
  886.     dbuf    km_node,10    ; Keymap node
  887.     dv.l    km_name        ; R32#0 Pointer to name
  888.     dv.l    lo_types    ; R32#1
  889.     dv.l    lo_data        ; R32#2
  890.     dv.l    lo_caps        ; R32#3
  891.     dv.l    lo_rept        ; R32#4
  892.     dv.l    hi_types    ; R32#5
  893.     dv.l    hi_data        ; R32#6
  894.     dv.l    hi_caps        ; R32#7
  895.     dv.l    hi_rept        ; R32#8
  896.  
  897.     dbuf    keytypes,104    ; KeyType array
  898.     dbuf    keydata,104*4    ; KeyData array
  899.     dbuf    capsable,14    ; Key capsability
  900.     dbuf    repeatable,14    ; Key repeatability
  901.     dbuf    hdrend,0    ; End of file header
  902.  
  903.     dbuf    work,512    ; Used when building key blocks
  904.     dbuf    strbuf,64    ; Buffer for non-quoted strings
  905.  
  906. ; Key names and keywords
  907.  
  908. keytab    dc.b    'TILDE',0,'ONE',0,'TWO',0,'THREE',0,'FOUR',0,'FIVE',0,'SIX',0,'SEVEN',0,'EIGHT',0    ;0
  909.     dc.b    'NINE',0,'ZERO',0,'MINUS',0,'EQUAL',0,'BACKSLASH',0,'???1',0,'K0',0        ;9
  910.     dc.b    'Q',0,'W',0,'E',0,'R',0,'T',0,'Y',0,'U',0,'I',0        ;10
  911.     dc.b    'O',0,'P',0,'LBRACK',0,'RBRACK',0,'???2',0,'K1',0,'K2',0,'K3',0    ;18
  912.     dc.b    'A',0,'S',0,'D',0,'F',0,'G',0,'H',0,'J',0,'K',0        ;20
  913.     dc.b    'L',0,'SEMICOLON',0,'APOSTROPHE',0,'HASH',0,'???3',0,'K4',0,'K5',0,'K6',0 ; 28
  914.     dc.b    'LESS',0,'Z',0,'X',0,'C',0,'V',0,'B',0,'N',0,'M',0    ;30
  915.     dc.b    'COMMA',0,'DOT',0,'SLASH',0,'???4',0,'KDOT',0,'K7',0,'K8',0,'K9',0    ;38
  916.     dc.b    'SPACE',0,'BACKSPACE',0,'TAB',0,'KENTER',0,'ENTER',0,'ESC',0,'DEL',0,'???5',0    ;40
  917.     dc.b    '???6',0,'???7',0,'KMINUS',0,'???8',0,'UP',0,'DOWN',0,'RIGHT',0,'LEFT',0        ;48
  918.     dc.b    'F1',0,'F2',0,'F3',0,'F4',0,'F5',0,'F6',0,'F7',0,'F8',0                ;50
  919.     dc.b    'F9',0,'F10',0,'KLBRACK',0,'KRBRACK',0,'KSLASH',0,'KASTERISK',0,'KPLUS',0,'HELP',0        ;58
  920.     dc.b    'LSHIFT',0,'RSHIFT',0,'CAPSLOCK',0,'CONTROL',0,'LALT',0,'RALT',0,'LAMIGA',0,'RAMIGA',0 ;60
  921.     dc.b    'SHIFT',0,'ALT',0,'CAPS',0,'NOREP',0,'DEAD',0,'STRING',0,'PREFIX',0,'MOD',0 ; Keywords: 68
  922.     dc.b    'CTRL',0,'KEY',0    ; 70
  923.     dc.b    0
  924.  
  925.     tags
  926.  
  927.     template    <FROM/A,TO>
  928.     dv.l    from
  929.     dv.l    to
  930.  
  931.     finish
  932.  
  933.     end
  934.