1 REM Ins{nd av Anders Franz`n <5258>    1988-01-01 13.11.06 (KERMIT)
; KERM3.ASM
; Anders Franz`n <5258>
; Stockholm 1987-09-20


KERMIT   CALL KERMV
KERM1    LD   HL,KERM4
         LD   BC,KERM5-KERM4
         CALL 0:11      Skriv promt
KERM2    CALL 7:66
         LD   HL,BUFF6
         LD   BC,39
         PUSH HL
         CALL GETLINE
         POP  HL
         RST  32
         CP   13
         JRZ  KERM2     Tom rad
         LD   BC,KERM1
         PUSH BC        Returadress
         LD   DE,CMDTAB
         PUSH DE
         CALL STRSCAN
         POP  DE
         RETC           Ambigious
         JRNZ KERM3
         LD   DE,CMDJTB
         JP   1:58      Utnyttja ROM!

KERM3    PUSH DE
         LD   HL,KERM5
         LD   BC,KERM6-KERM5
         CALL 0:11
         POP  HL
         JP   HELP1

KERM4    DM 13,10,"KERMIT"
KERM5    DM 13,10,7,"Command must be"
KERM6

GETLINE  LD   DE,3:78
         LD   (253:251),DE
         PUSH IX
         LD   B,C
GETL2    CALL 3:91
         JRNZ GETL2
GETL3    CALL 3:91
GETL4    CALL 0:2
         CP   9
         CALLZ 3:72
         CP   13
         JPZ  2:229
         CP   24
         JRZ  GETL2
         CP   8
         JRZ  GETL3
         PUSH HL
         PUSH DE
         PUSH BC
         PUSH IX
         PUSH AF
         LD   HL,(ESCAPE)
         CP   L
         JRNZ GETL5
         CALL CONNECT
         JR   GETL6

GETL5    LD   HL,(TEDESC)
         CP   L
         CALLZ TED
GETL6    POP  AF
         POP  IX
         POP  BC
         POP  DE
         POP  HL
         CP   32
         JRC  GETL4
         LD   (DE),A
         CP   96
         JRC  GETL7
         AND  95
GETL7    LD   (HL),A
         INC  HL
         INC  (IX+1)
         LD   A,(2:111)
         CP   (IX+1)
         CALLC 2:52
         DJNZ GETL4
         JP   2:228

CMDTAB   DM 128,"CLOSE"
         DM 129,"CONNECT"
         DM 130,"DELETE"
         DM 131,"DIR"
         DM 132,"DUMP"
         DM 130,"ERASE"
         DM 133,"EXIT"
         DM 134,"HELP"
         DM 130,"KILL"
         DM 135,"LOG"
         DM 136,"QUIT"
         DM 137,"RECEIVE"
         DM 138,"SAVE"
         DM 139,"SEND"
         DM 140,"SET"
         DM 141,"SHOW"
         DM 142,"TED"   Rensa tabell om
         DM 143,"TYPE"
         DM 255         TED saknas

CMDJTB   DW CLOSE       128
         DW CONNECT     129
         DW DELETE      130
         DW DIRH        131
         DW DUMP        132
         DW BASIC       133
         DW HELP        134
         DW LOGG        135
         DW QUIT        136
         DW KERMREC     137
         DW SAVE        138
         DW KERMSEND    139
         DW SET         140
         DW SHOW        141
         DW TED         142
         DW TYPE        143

CONNECT  CALL KERMS
CON1     CALL TERMINAL
         LD   A,(FLAGG)
         BIT  1,A
         JPNZ TED1      TED-escape
         CALL KERMV
         LD   A,(FLAGG)
         BIT  6,A
         JRNZ CON2      TED full
         BIT  7,A
         RETZ           LOG/DUMP-FIL ok
         LD   A,(FELKOD)
         CALL ERROR
         CALL CLOSE
         LD   SP,STACK
         JP   KERM1

CON2     LD   HL,CON3
         LD   BC,CON4-CON3
         CALL 0:11
         LD   SP,STACK
         JP   KERM1

CON3     DB 13,10,7
         DM "TED filled",13,10
CON4

TED      LD   A,(TEDFLG)
         AND  A
         RETZ           TED ej i minnet!
         CALL KERMS
TED1     LD   A,(DMP)
         LD   C,A
         LD   A,(LOG)
         OR   C
         JRZ  TED2      Ingen fil |ppen
         CALL KERMV
         CALL CLOSE     St{ng fil
         LD   SP,STACK
         JP   KERM1     Stanna i KERM

TED2     CALL TED3      Anropa TED
         LD   A,(FLAGG)
         BIT  1,A
         JPNZ CON1      TED-escape
         JP   KERMV

TED3     LD   (KERMSP),SP
         LD   SP,(TEDSP)
         RET            Till TED

TEDFLG   DB 0

KERMSEND CALL DRIVEFIX  Fixa filnamn
         LD   A,21
         JPC  ERROR
         CALL CLOSE
         CALL INIT      Rensa buffertar
         CALL INTON     Sl} p} interrupt
         CALL XON
         CALL SEND
         CALL XOFF
         CALL INTOFF    Sl} av interrupt
         CALL 7:66
         RET

KERMREC  LD   (FILPEK),HL Ev filnamn
         CALL CLOSE
         CALL INIT      Rensa buffertar
         CALL INTON     Sl} p} interrupt
         CALL XON
         CALL RECEIVE
         CALL XOFF
         CALL INTOFF    Sl} av interrupt
         CALL 7:66
         RET

QUIT     PUSH HL        Spara ev pgm
         CALL CLOSE
         CALL KERMS
         LD   HL,254:64 Inga parametrar
         LD   (HL),L    om QUIT KERM
         POP  HL
         CALL BASIC1    Anropa BASIC
KERMV    LD   HL,KERMBILD
         CALL VISABILD
         RET

KERMS    LD   DE,KERMBILD
         CALL SPARBILD
         RET

BASIC    CALL CLOSE
         JP   0:0

BASIC1   LD   (KERMSP),SP
         LD   SP,(254:39)
         LD   A,(13:76)
         CP   231
         JPZ  13:76     RUN i BASIC
         JP   13:74

;Visar vilka kommandon som finns
HELP     LD   HL,CMDTAB
HELP1    LD   B,1
HELP2    DJNZ HELP3
         CALL 7:66
         LD   B,3
         LD   A,(1:216)
         CP   40
         JRZ  HELP3
         LD   B,5
HELP3    LD   A,-10
         LD   DE,SPACE
         CALL SKRIVTAB
         LD   A,(HL)
         INC  A
         JRNZ HELP2
         CALL 7:66
         RET

;Visa parametrar
SHOW     CALL 7:66
         LD   IX,PARMAREA
         LD   HL,SHOWTAB
         PUSH HL
         LD   HL,SETTAB
SHOW1    LD   B,2       Antal/rad
         LD   A,(1:216)
         CP   40
         JRZ  SHOW2
         LD   B,3
SHOW2    LD   A,-7      Rak v{nsterkant
         LD   DE,PUNKTER
         CALL SKRIVTAB
         EX   (SP),HL
         PUSH BC
         LD   E,(HL)
         INC  HL
         LD   D,(HL)
         INC  HL
         LD   C,(HL)
         INC  HL
         LD   B,(HL)
         INC  HL
         PUSH HL
         EX   DE,HL
         LD   A,(IX)
         INC  IX
         OR   128
         CP   254
         JRZ  SHOW3
         CP   255
         JRZ  SHOW3
         CPIR
         JRZ  SHOW4
SHOW3    AND  127
         LD   L,A
         LD   H,0
         LD   A,9
         LD   DE,PUNKTER
         CALL SKRTAL
         JR   SHOW5

SHOW4    DEC  HL
         LD   A,9
         LD   DE,PUNKTER
         CALL SKRIVTAB
SHOW5    POP  HL
         POP  BC
         EX   (SP),HL
         LD   A,(HL)
         INC  A
         JRZ  SHOW6
         PUSH HL
         PUSH BC
         LD   HL,SPACE
         LD   BC,2
         CALL 0:11
         POP  BC
         POP  HL
         DJNZ SHOW2
         CALL 7:66
         JR   SHOW1

SHOW6    POP  HL
         CALL 7:66
         RET

;IN  DE Typ av delare
;     A L{ngd f{lt >0 rak h|gerkant
;                  <0 rak v{nsterkant
SKRIVTAB PUSH BC
         LD   BC,-1
         INC  HL        Skippa highbyte
         PUSH HL
SKRIVT1  BIT  7,(HL)
         INC  HL
         INC  BC        R{kna l{ngd ord
         JRZ  SKRIVT1
         DEC  HL
         EX   (SP),HL   Spara n{sta ord
         PUSH DE        Spara avskiljare
         AND  A
         JPM  SKRIVT2   Rak v{nsterkant
         PUSH HL
         PUSH BC
         EX   DE,HL
         SUB  C
         LD   C,A
         CALLNZ 0:11    Skriv avskiljare
         XOR  A
         POP  BC        L{ngd p} ord
         POP  HL        Pekar p} ord
SKRIVT2  PUSH AF
         PUSH BC
         CALL 0:11      Skriv ord
         POP  BC
         POP  AF
         POP  HL        Avskiljare
         NEG
         SUB  C
         LD   C,A
         CALLP 0:11     Skriv avskiljare
         POP  HL        N{sta ord
         POP  BC
         RET

PUNKTER  DM ".........."

;[ndra parametrar
SET      LD   DE,SETTAB
         PUSH DE
         CALL STRSCAN
         POP  DE
         RETC           Ambigious
         JRNZ SET1
         LD   DE,SETJTB
         JP   1:58      Utnyttja ROM!

SET1     PUSH DE
         LD   HL,SETF1
         LD   BC,SETF2-SETF1
         CALL 0:11      Felmeddelande
         POP  HL
         JP   HELP1

SET2     PUSH DE
         LD   HL,SETF2
         LD   BC,SETF3-SETF2
         CALL 0:11      Felmeddelande
         POP  HL
         JP   HELP1

SETF1    DM 13,10,7,"Parameter must be"
SETF2    DM 13,10,7,"Value must be"
SETF3

SETTAB   DM 128,"ACCESS"
         DM 129,"BAUD"
         DM 130,"CHECK"
         DM 131,"DEBUG"
         DM 132,"DUPLEX"
         DM 133,"EOL"
         DM 134,"ESCAPE"
         DM 135,"FILE"
         DM 136,"FLOW"
         DM 137,"LENGTH"
         DM 138,"MARKER"
         DM 139,"NEWLINE"
         DM 140,"NUMPAD"
         DM 141,"PADCHAR"
         DM 142,"PARITY"
         DM 143,"PAUSE"
         DM 144,"QBIN"
         DM 145,"QCTL"
         DM 146,"REPT"
         DM 147,"RETRY"
         DM 148,"TEDESC"
         DM 149,"TEDMODE"
         DM 150,"TIMEOUT"
         DM 255

SETJTB   DW [ACC        128
         DW [BAUD       129
         DW [CHECK      130
         DW [DEBUG      131
         DW [DUPL       132
         DW [EOL        133
         DW [ESCAPE     134
         DW [FILE       135
         DW [FLOW       136
         DW [LENGTH     137
         DW [MARKER     138
         DW [NEWL       139
         DW [NUMPAD     140
         DW [PADCHAR    141
         DW [PAR        142
         DW [PAUSE      143
         DW [QBIN       144
         DW [QCTL       145
         DW [REPT       146
         DW [RETRY      147
         DW [TEDESC     148
         DW [TED        149
         DW [TIME       150


[BAUD    LD   DE,PBAUD
         LD   BC,BAUD
         CALL [TAB
         JP   FIXBAUD

PBAUD    DM 128,"300/300"
         DM 129,"1200/75"
         DM 130,"75/1200"
         DM 131,"1200/1200"
         DM 132,"2400/2400"
         DM 133,"4800/4800"
         DM 255
PBAUDS

[DUPL    LD   DE,PDUPL
         LD   BC,DUPLEX
         JP   [TAB

PDUPL    DM 128,"HALF"
         DM 129,"FULL"
         DM 255
PDUPLS

[PAR     LD   DE,PPAR
         LD   BC,PARITET
         JP   [TAB

PPAR     DM 128,"NONE"
         DM 129,"SPACE",129,"0"
         DM 130,"MARK",130,"1"
         DM 131,"EVEN"
         DM 132,"ODD"
         DM 255
PPARS

[FLOW    LD   DE,PFLOW
         LD   BC,FLOW
         JP   [TAB

PFLOW    DM 128,"OFF"
         DM 129,"XON/XOFF"
         DM 255
PFLOWS

[TIME    LD   DE,TIME
         JR   [TAL

[RETRY   LD   DE,RETRY
[TAL     PUSH DE
         CALL G\RTAL
         POP  BC
         EX   DE,HL
         LD   DE,PTAL
         JPC  SET2
         LD   A,H
         AND  A
         JPNZ SET2
         LD   A,L
         CP   1
         JPC  SET2
         CP   31
         JPNC SET2
         LD   (BC),A
         CALL 7:66
         AND  A
         RET

PTAL     DM 254,"1-30"
         DM 255
PTALS

[FILE    LD   DE,PFILE
         LD   BC,FILE
         JP   [TAB

PFILE    DM 128,"TEXT"
         DM 129,"BIN"
         DM 130,"AUTO"
         DM 255
PFILES

[LENGTH  CALL G\RTAL
         EX   DE,HL
         LD   DE,PLENGTH
         JPC  SET2
         LD   A,H
         AND  A
         JPNZ SET2
         LD   A,L
         CP   20
         JPC  SET2
         CP   95
         JPNC SET2
         LD   (LENGTH),A
         CALL 7:66
         RET

PLENGTH  DM 254,"20-94"
         DM 255
PLENGTHS

[MARKER  LD   DE,MARKER
         JP   [TKN

[CHECK   LD   DE,PCHECK
         LD   BC,CHECK
[TAB     PUSH DE
         PUSH BC
         CALL STRSCAN
         POP  BC
         POP  DE
         RETC           Ambigious
         JPNZ SET2
         AND  127
         LD   (BC),A
         CALL 7:66
         RET

PCHECK   DM 129,"1"
         DM 130,"2"
         DM 255
PCHECKS

[EOL     LD   DE,EOL
         JR   [TKN

[NUMPAD  LD   DE,NUMPAD
         JR   [TKN

[PADCHAR LD   DE,PADCHAR
         JR   [TKN

[QCTL    LD   DE,QCTL
         JR   [TKN

[QBIN    LD   DE,QBIN
         JR   [TKN

[ESCAPE  LD   DE,ESCAPE
         JR   [TKN

[TEDESC  LD   DE,TEDESC
         JR   [TKN

[REPT    LD   DE,REPT
[TKN     PUSH DE        Spara variabel
         CALL G\RTAL
         POP  BC
         EX   DE,HL
         LD   DE,PTKN
         JPC  SET2
         LD   A,H
         AND  A
         JPNZ SET2
         LD   A,L
         BIT  7,A
         JPNZ SET2
         LD   (BC),A
         CALL 7:66
         AND  A
         RET

PTKN     DM 254,"0-127"
         DM 255
PTKNS

[ACC     LD   DE,PACC
         LD   BC,ACCESS
         JP   [TAB

PACC     DM 128,"PREPARE"
         DM 129,"KILL"
         DM 130,"STOP"
         DM 255
PACCS

[DEBUG   LD   DE,PDEBUG
         LD   BC,DEBUG
         JP   [TAB

PDEBUG   DM 128,"OFF"
         DM 129,"PACKET"
         DM 130,"DUMP"
         DM 255
PDEBUGS

[TED     LD   DE,PTED
         LD   BC,TEDSAVE
         CALL [TAB
         RET

PTED     DM 128,"OFF"
         DM 129,"SAVE"
         DM 130,"SEND"
         DM 255
PTEDS

[NEWL    LD   DE,PNEWL
         LD   BC,NEWLINE
         JP   [TAB

PNEWL    DM 128,"OFF"
         DM 129,"ON"
         DM 255
PNEWLS

[PAUSE   LD   DE,PAUSE
         JP   [TKN

SHOWTAB  DW PACC,PACCS-PACC         128
         DW PBAUD,PBAUDS-PBAUD      129
         DW PCHECK,PCHECKS-PCHECK   130
         DW PDEBUG,PDEBUGS-PDEBUG   131
         DW PDUPL,PDUPLS-PDUPL      132
         DW PTKN,PTKNS-PTKN eol     133
         DW PTKN,PTKNS-PTKN escape  134
         DW PFILE,PFILES-PFILE      135
         DW PFLOW,PFLOWS-PFLOW      136
         DW PLENGTH,PLENGTHS-PLENGTH 137
         DW PTKN,PTKNS-PTKN marker  138
         DW PNEWL,PNEWLS-PNEWL      139
         DW PTKN,PTKNS-PTKN numpad  140
         DW PTKN,PTKNS-PTKN padchar 141
         DW PPAR,PPARS-PPAR         142
         DW PTKN,PTKNS-PTKN pause   143
         DW PTKN,PTKNS-PTKN qbin    144
         DW PTKN,PTKNS-PTKN qctl    145
         DW PTKN,PTKNS-PTKN rept    146
         DW PTAL,PTALS-PTAL retry   147
         DW PTKN,PTKNS-PTKN TEDesc  148
         DW PTED,PTEDS-PTED         149
         DW PTAL,PTALS-PTAL time    150

FIXBAUD  LD   A,(BAUD)
         INC  A
         LD   HL,FIXBAUD2-5
         LD   BC,5
FIXBAUD1 ADD  HL,BC
         DEC  A
         JRNZ FIXBAUD1
         LD   A,(HL)    Kort tid f|r
         INC  HL        tangentrepeet
         LD   (TAN1-1),A
         LD   E,(HL)
         INC  HL
         LD   D,(HL)
         INC  HL
         LD   (BAUDSEND),DE
         LD   E,(HL)
         INC  HL
         LD   D,(HL)
         INC  HL
         LD   (BAUDREC),DE
         RET

FIXBAUD2 DB 3
         DW BAUD300,BAUD300
         DB 5
         DW BAUD75,BAUD1200
         DB 2
         DW BAUD1200,BAUD75
         DB 2
         DW BAUD1200,BAUD1200
         DB 2
         DW BAUD2400,BAUD2400
         DB 2
         DW BAUD4800,BAUD4800

FIXTED   LD   A,(TEDFLG)
         AND  A
         RETZ           TED ej i minnet
         CALL R[KNA     Ant rader i TED
         LD   (TEDANRAD),DE
         INC  DE
         LD   (TEDINRAD),DE
         CALL TILLBUFF
         XOR  A
         LD   (TEDKOL),A
         LD   L,A
         LD   H,A
         LD   (TEDUTRAD),HL
         RET

PARMAREA

ACCESS   DB 0    Kolla om fil finns
BAUD     DB 1    Baud
CHECK    DB 2    Checksummetyp
DEBUG    DB 0    Debug-mode
DUPLEX   DB 1    Duplex
EOL      DB 13   End of packet
ESCAPE   DB 27   Esccape-tkn terminal
FILE     DB 2    Filtyp
FLOW     DB 1    Flow controll
LENGTH   DB 94   Packetl{ngd
MARKER   DB 1    Start of packet
NEWLINE  DB 0    Tolka <RETURN> som CRLF
NUMPAD   DB 0    Antal PAD-tkn
PADCHAR  DB 0    PAD-tecken
PARITET  DB 0    Paritet
PAUSE    DB 0    Paus innan packet s{nds
QBIN     DB "&"
QCTL     DB "#"
REPT     DB "~"
RETRY    DB 5    Antal omf|rs|k
TEDESC   DB 0    Hopp-till-TED-tangent
TEDSAVE  DB 0    Spara/s{nda text i TED
TIME     DB 10   Timeout

PARMLEN  EQU $-PARMAREA

LOG      DB 0    Logga p} disk
DMP      DB 0    S{nd iv{g fil
