home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 8 / FreshFishVol8-CD2.bin / bbs / dev / ssl-4.1.lha / SSL / SSLExamp / KeyComp.asm < prev    next >
Assembly Source File  |  1993-12-21  |  16KB  |  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.     wr