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 >
Wrap
Assembly Source File
|
1993-12-21
|
16KB
|
934 lines
; Keymap Compiler
; (c) 1993 MJSoft System Software
; Martin Mares
; opt x+
include "ssmac.h"
tbase a4
clistart
writeln <Keymap Compiler 1.0, (c) 1993 MJSoft System Software>
get.l from,a0 ; Load source file
geta fromname,a1
dtl <kms>,a2
moveq #80,d0
call ss,AddExtension
geta fromname,a0
call LoadFile
move.l d0,a3 ; A3 points to source file
get.l to,d0 ; Create destination file
bne.s opento
geta fromname,a0
move.l a0,d1
call dos,FilePart
move.l d0,a1
geta work,a2
move.l a2,a0
copyfn1 move.b (a1)+,(a2)+
bne.s copyfn1
push a0
call ss,RemExtension
pop d0
opento move.l d0,a0
move.l #1006,d0
push a0
call ss,TrackOpen
move.l d0,d7 ; D7=destfh
vpea fromname
dtl.l <Compiling %s to %s.>,a0
move.l sp,a1
call Printf
addq.l #8,sp
; Build hash table
move.l #128,d0
moveq #0,d1
call ss,InitHashTree
put.l d0,htr
dv.l htr
lea keytab(pc),a2
moveq #0,d2
bhat_loop tst.b (a2)
beq.s bhat_end
get.l htr,a0
move.l a2,a1
moveq #2,d0
call AddHashItem
move.l d0,a0
move.w d2,(a0)+
addq.w #1,d2
bhat_next tst.b (a2)+
bne.s bhat_next
bra.s bhat_loop
; Create header of destination file
bhat_end move.l d7,d1
geta hh_id,a0
move.l a0,d2
move.l #hdrend-hh_id,d3
moveq #1,d4
bsr chfwrite
; Initialize some fields in the header
lea inittab(pc),a0
1$ move.w (a0)+,d0
beq.s 2$
move.w (a0)+,d1
geta hh_id,a1
add.w d0,a1
move.w d1,(a1)
bra.s 1$
2$ dv.l lino ; Line number
put.w #1,lino+2
dv.l chlen ; Code hunk length
put.w #hdrend-km_node,chlen+2
; Initialize data structures
geta keytypes,a0
moveq #103,d0
moveq #-128,d1
init_1 move.b d1,(a0)+
dbra d0,init_1
; Start parsing of source
srcloop bsr getobj ; Read key header
srcentry tst.b d1
beq.s srcloop
bmi saveit
subq.b #3,d1
bne.s exkey
moveq #$20,d5
cmp.b #$6c,d0
beq.s keyex1
moveq #$40,d5
cmp.b #$6d,d0
beq.s keyex1
moveq #0,d5
cmp.b #$71,d0
beq.s keyex2
exkey moveq #6,d0
bra error
keyex1 bsr getobj
subq.b #3,d1
bne.s exkey
cmp.b #$71,d0
bne.s exkey ; D5 now holds correct key type
keyex2 bsr getobj ; Read key name
subq.b #3,d1
bne.s exkey1
cmp.b #104,d0
bcs.s keyex3
exkey1 moveq #7,d0
bra error
keyex3 move.l d0,d6 ; D6=key code
moveq #0,d4 ; D4.0 = nonrepeatable, .1=capsable
keyflg bsr getobj ; Parse key flags
tst.b d1
beq.s keybody
bmi.s keyincl
subq.b #3,d1
bne.s exkey
moveq #0,d1
cmp.b #$68,d0 ; SHIFT
beq.s keyfl1
moveq #1,d1
cmp.b #$69,d0 ; ALT
beq.s keyfl1
moveq #2,d1
cmp.b #$70,d0 ; CTRL
beq.s keyfl1
moveq #0,d1
cmp.b #$6a,d0 ; CAPS
beq.s keyfl2
moveq #1,d1
cmp.b #$6b,d0 ; NOREP
beq.s keyfl2
keyincl moveq #8,d0
keyincle bra error
keyfl1 bset d1,d5
keyfl beq.s keyflg
moveq #9,d0
bra.s keyincle
keyfl2 bset d1,d4
bra.s keyfl
keytwice moveq #12,d0
bra error
keybody geta keytypes,a0 ; Key header done, store the flags
add.l d6,a0
cmp.b #$80,(a0)
bne.s keytwice
move.b d5,(a0)
move.l d6,d0
lsr.w #3,d0
geta capsable,a0
btst #1,d4 ; NoRep
bne.s 1$
bset d6,(repeatable-capsable)(a0,d0.w)
1$ btst #0,d4 ; Caps
beq.s 2$
bset d6,0(a0,d0.w)
2$ add.l d6,d6
add.l d6,d6
geta keydata,a2
add.l d6,a2
dv.b usedmean
clrv.b usedmean
dv.l alloccount
moveq #0,d0
moveq #0,d2
not.b d5
3$ move.b d0,d1
and.b d5,d1
bne.s 31$
addq.l #2,d2
31$ addq.b #1,d0
cmp.b #8,d0
bcs.s 3$
not.b d5
put.l d2,alloccount
btst #5,d5
bne.s bodydead
btst #6,d5
bne.s bodystrg
bodynorm moveq #0,d6 ; Body of normal key
moveq #0,d2
normloop moveq #4,d3
move.b d5,d0
addq.b #1,d0
and.b #7,d0
beq.s 1$
moveq #0,d3
1$ bsr getflags
cmp.b #1,d1
bne.s normend
lsl.l #3,d4
lsl.l d4,d0
or.l d0,d6
bsr checkeol
bra.s normloop
normend move.l d6,(a2)
bra srcentry
bodystrg bsr clrwork
strgloop moveq #0,d3
bsr getflags
cmp.b #2,d1
bne.s strgend
add.l d4,d4
move.l d0,d2
move.l d0,a0
bsr strlen
geta work,a0
move.b d0,0(a0,d4.l)
bsr allocate
move.b d0,1(a0,d4.l)
move.l d2,a0
geta work,a1
add.l d0,a1
1$ move.b (a0)+,(a1)+
bne.s 1$
bsr checkeol
bra.s strgloop
strgend bsr shipout
bra srcentry
bodydead bsr clrwork
push a2
deadloop moveq #0,d3
bsr getflags
add.l d4,d4
geta work,a2
add.l d4,a2
cmp.b #1,d1
beq.s deadnorm
cmp.b #3,d1
bne.s deadend
cmp.w #$6f,d0 ; MOD
beq.s deadmod
cmp.w #$6e,d0 ; PREFIX
bne.s deadend
move.b #$08,(a2)+
bsr getobj
subq.b #1,d1
bne.s pxexp
move.b d0,(a2)
cmp.b #16,d0
bcc.s pxexp5
bsr getobj
tst.b d1
beq.s deadloop
bmi.s deadloop
subq.b #5,d1
bne.s pxexp2
bsr getobj
subq.b #1,d1
bne.s pxexp4
cmp.b #16,d0
bcc.s pxexp5
lsl.b #4,d0
or.b d0,(a2)
bsr checkeol
bra.s deadloop
pxexp moveq #17,d0
pxexp3 bra error
pxexp2 moveq #20,d0
bra.s pxexp3
pxexp4 moveq #21,d0
bra.s pxexp3
pxexp5 moveq #22,d0
bra.s pxexp3
deadend pop a2
bsr.s shipout
bra srcentry
deadnorm sf (a2)+
move.b d0,(a2)+
bsr checkeol
bra deadloop
deadmod moveq #0,d0
bsr.s allocate
move.b #1,(a2)+
move.b d0,(a2)+
geta work,a2
add.l d0,a2
modloop bsr getobj
subq.b #1,d1
bne.s deadmoder
addqv.l #1,alloccount
move.b d0,(a2)+
bsr getobj
tst.b d1
beq deadloop
bmi deadloop
subq.b #5,d1
beq.s modloop
comexer moveq #19,d0
bra.s deadmoder2
deadmoder moveq #18,d0
deadmoder2 bra error
; String operations
strlen move.l a0,d0
1$ tst.b (a1)+
bne.s 1$
sub.l a1,d0
neg.l d0
subq.l #1,d0
rts
; Allocation of dynamic key data
allocate get.l alloccount,d1
cmp.w #256,d1
bcc.s allocerr
exg.l d0,d1
add.l d0,d1
put.l d1,alloccount
rts
allocerr moveq #16,d0
bra error
shipout mpush d0-d4
get.l chlen,(a2)
move.l d7,d1
geta work,a0
move.l a0,d2
get.l alloccount,d3
moveq #1,d4
bsr chfwrite
mpop d0-d4
rts
clrwork geta work,a0
moveq #31,d0
1$ clr.l (a0)+
dbra d0,1$
rts
; Check EOL condition
checkeol bsr getobj
tst.b d1
bmi.s 1$
bne.s 2$
1$ rts
2$ moveq #15,d0
bra error
; Get meaning flags (D3=disabled flags)
getflags moveq #0,d4 ; D4 holds the flags
move.b d5,d0
not.b d0
and.b #$07,d0
or.b d0,d3
flagloop bsr getobj
tst.b d1
beq.s flageol
bmi.s flageof
cmp.b #3,d1
bne.s flagend
moveq #0,d2
cmp.b #$68,d0
beq.s flagflag
moveq #1,d2
cmp.b #$69,d0
beq.s flagflag
moveq #2,d2
cmp.b #$70,d0
bne.s flagend
flagflag btst d2,d3
bne.s flagbad
bset d2,d4
beq.s flagloop
moveq #14,d0
bra.s flagfler
flagbad moveq #10,d0
flagfler bra error
flageol tst.b d4
beq.s flagloop
flagerr moveq #11,d0
bra.s flagfler
flagend cmp.b #3,d1
bne.s flagend1
cmp.w #$6c,d0
beq.s flageof
cmp.w #$6d,d0
beq.s flageof
cmp.w #$71,d0
beq.s flageof
flagend1 bsetv d4,usedmean
bne.s flagtwic
moveq #1,d2 ; Normalize flags
moveq #0,d3
not.b d5
push d0
1$ move.b d2,d0
and.b d5,d0
bne.s 2$
addq.b #1,d3
cmp.b d2,d4
bne.s 2$
move.b d3,d4
bra.s 3$
2$ addq.b #1,d2
cmp.b #8,d2
bcs.s 1$
3$ pop d0
not.b d5
flageof rts
flagtwic moveq #13,d0
bra.s flagfler
; Save the rest of keymap
saveit vmovev.l chlen,km_name
geta fromname,a0
move.l a0,d1
call dos,FilePart
move.l d0,a0
move.l d0,d2
call ss,RemExtension
move.l d2,a0
move.l d2,a1
1$ tst.b (a1)+
bne.s 1$
sub.l a0,a1
move.l a1,d3
moveq #1,d4
move.l d7,d1
bsr chfwrite
move.l d7,d1 ; Pad to longword boundary
lea huend+4(pc),a0
move.l a0,d2
get.l chlen,d3
neg.l d3
moveq #3,d0
and.l d0,d3
beq.s save1
sub.l d3,d2
moveq #1,d4
bsr chfwrite
save1 get.l chlen,d0 ; Adjust hunk length
addq.l #3,d0
lsr.l #2,d0
put.l d0,hh_size
put.l d0,hc_size
move.l #$3ec,d0 ; Put HUNK_RELOC
bsr putl
moveq #9,d0 ; Count relocations
geta keytypes,a0
moveq #103,d1
countrel move.b (a0)+,d2
and.b #$60,d2
beq.s 1$
addq.l #1,d0
1$ dbra d1,countrel
bsr putl
moveq #0,d0
bsr putl
lea reloxs(pc),a0 ; Write basic relocations
move.l d7,d1
move.l a0,d2
moveq #36,d3
moveq #1,d4
bsr chfwrite
geta keytypes,a2 ; Relocs for string & dead keys
move.l #keydata-km_node,d2
2$ move.b (a2)+,d0
and.b #$60,d0
beq.s 3$
move.l d2,d0
bsr.s putl
3$ addq.l #4,d2
cmp.l #keydata-km_node+104*4,d2
bcs.s 2$
moveq #0,d0 ; End of relocs
bsr.s putl
move.l #$3f2,d0 ; Write HUNK_END
bsr.s putl
move.l d7,d1 ; ... and rewrite the header
call Flush
move.l d7,d1
moveq #0,d2
moveq #-1,d3
call Seek
move.l d7,d1
geta hh_id,a0
move.l a0,d2
move.l #hdrend-hh_id,d3
bsr.s chwrite
wr