home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / archives / trs80model2.zip / trsmain.mac < prev    next >
Text File  |  1997-03-26  |  13KB  |  321 lines

  1.         subttl  kmain/mac main parser and initialization routin
  2.         cseg
  3.         extrn   oldstk,scrtch,high,cmdlin,stack,stjump,lab
  4.         extrn   rftab,rdtab,rtype,abort,parity,port,fcb,baud
  5.         extrn   wdlen,baudtb,parsetb,byte,initcm,init,state
  6.         public  mjump,rdjump,rfjump,sets,setr,setf,setb,setp,setc
  7.         public  setw,seter,setl
  8.         extrn   lrecl,filnam,paraml,work
  9.         ;
  10.         ;       macros
  11.         ;
  12.         ;       prmes   to display a message stored by mssg
  13.         ;       call    prmes   lab
  14.         ;
  15.         prmes   macro   lab
  16.         .xlist
  17.         extrn   m_&lab,l_&lab
  18.         push    hl
  19.         push    bc
  20.         ld      hl,m_&lab
  21.         ld      bc,(l_&lab)
  22.         ld      c,13
  23.         ld      a,9
  24.         rst     8
  25.         pop     bc
  26.         pop     hl
  27.         .list
  28.         endm
  29.         ;
  30.         ;       jumptb  jump according to a jump table
  31.         ;       call    jumptb  table,code
  32.         ;       where   table is the address of the table
  33.         ;               and code is a one-byte code
  34.         ;
  35.         jumptb  macro   table,code
  36.         .xlist
  37.         local   $1
  38.         ld      hl,table
  39.         ld      bc,(code)
  40.         ld      b,c
  41.         ld      a,28            ;lookup call
  42.         rst     8               ;dos
  43.         jr      z,$1            ;no error
  44.         ld      hl,table+1      ;get abort address (first entry)
  45.         $1:
  46.         jp      (hl)
  47.         .list
  48.         endm
  49.         ;
  50.         ;       main entry save usefull registers
  51.         ;
  52.         start:
  53.                 ld      (oldstk),sp     ;save stack
  54.                 ld      (scrtch),bc     ;first byte after pgm
  55.                 ld      (high),de       ;high memory
  56.                 ld      (cmdlin),hl     ;command line
  57.                 ld      sp,stack        ;new stack
  58.         ;
  59.         ;       main parsing routine
  60.         ;               will respond to the following syntax :
  61.         ;               KERMIT {S,F=file,B=baud,P=par,W=word,C=channel}
  62.         ;                       update {L=lrecl} 85.09.19
  63.         ;
  64.         iparse:
  65.                 ld      e,0             ;init for first call nxtfld
  66.                 ld      hl,(cmdlin)     ;get command line
  67.                 ld      c,(hl)          ;maximum length to parse
  68.                 inc     hl              ;points to first byte
  69.         i0:
  70.                 ld      a,(hl)          ;get first byte
  71.                 cp      ' '             ;white space ?
  72.                 jr      z,i1            ;yes, now find {
  73.                 dec     c               ;decrement length to parse
  74.                 inc     hl              ;update pointer
  75.                 ld      a,c             ;length in a
  76.                 cp      0               ;is it null ?
  77.                 jr      nz,i0           ;no, go on
  78.                 jp      go              ;yes, no parse to be done
  79.         i1:
  80.                 dec     c               ;decrement length to parse
  81.                 inc     hl              ;update pointer
  82.                 ld      a,c             ;get length in a
  83.                 cp      0               ;is it null ?
  84.                 jp      z,go            ;nothing to parse
  85.                 ld      a,(hl)          ;get byte in a
  86.                 cp      ' '             ;is it another null ?
  87.                 jp      z,i1            ;yes, get one more
  88.                 cp      '{'             ;is it valid start ?
  89.                 jp      nz,seter        ;no good
  90.                 dec     c               ;decrement length
  91.                 inc     hl              ;update pointer
  92.                 ld      a,c             ;get length in a
  93.                 cp      0               ;is it null ?
  94.                 jp      z,seter         ;no good
  95.         parse:
  96.                 call    nxtfld          ;get next field
  97.                 jp      nz,go           ;go !
  98.                 ld      a,b             ;length of field
  99.                 cp      0               ;is it null ?
  100.                 jp      z,seter         ;disaster ...
  101.                 call    handler         ;work with this parameter
  102.                 ld      a,c             ;length left to parse
  103.                 or      a               ;is it null ?
  104.                 jp      nz,parse        ;no, do it again
  105.                 ld      a,0FFH          ;terminator ?
  106.                 cp      d               ;in register D
  107.                 jp      z,seter         ;yes and parse is incomplete
  108.                 jp      go              ;go !
  109.         handler:
  110.                 ld      a,(hl)          ;get first caracter of field
  111.                 ld      (byte),a        ;in byte
  112.                 push    hl              ;save
  113.                 push    bc
  114.                 jumptb  parsetb,byte    ;jump accordingly
  115.         sets:
  116.                 pop     bc
  117.                 pop     hl
  118.                 ld      a,11            ;open pseudo-state
  119.                 ld      (state),a       ;set send state
  120.                 ld      a,'R'           ;read only
  121.                 ld      (paraml+6),a    ;put fcb in read state
  122.                 ld      a,0             ;do not create
  123.                 ld      (paraml+9),a    ;and do not create
  124.                 ret
  125.         setr:
  126.                 pop     bc
  127.                 pop     hl
  128.                 ld      a,3
  129.                 ld      (state),a       ;set receive state
  130.                 ret
  131.         setf:
  132.                 pop     bc
  133.                 pop     hl
  134.                 call    nxtfld          ;get next field
  135.                 push    hl              ;save
  136.                 push    de
  137.                 push    bc
  138.                 push    hl              ;i will need it twice
  139.                 ld      a,b             ;get length in a
  140.                 cp      0               ;is it null ?
  141.                 jp      z,f0            ;yes error
  142.                 cp      30              ;greater than 30
  143.                 jp      nc,f0           ;yes, error
  144.                 ld      de,fcb          ;where filaname should be
  145.                 ld      c,b             ;with length in BC
  146.                 ld      b,0
  147.                 ldir                    ;move from hl to de
  148.                 ex      de,hl           ;end of filnam in hl
  149.                 ld      (hl),13         ;put in a CR
  150.                 ld      (filnam),a      ;get filename length in place
  151.                 ld      de,filnam       ;to filenam
  152.                 inc     de              ;plus one (first byte is len)
  153.                 pop     hl              ;from here
  154.                 ld      c,a             ;length in bc
  155.                 ld      b,0
  156.                 ldir                    ;move from param list to filnam
  157.                 ex      de,hl           ;hl points to end
  158.                 ld      (hl),13         ;put in a CR
  159.                 pop     bc              ;restore
  160.                 pop     de
  161.                 pop     hl
  162.                 ret
  163.         f0:
  164.                 prmes   e4              ;not valid filename
  165.                 jp      abort           ;end in disaster
  166.         setp:
  167.                 pop     bc
  168.                 pop     hl
  169.                 call    nxtfld          ;get next field
  170.                 ld      a,(hl)          ;get first byte in a
  171.                 cp      'O'             ;is it odd
  172.                 jr      nz,p0           ;no ...
  173.                 ld      (parity),a      ;set in comm buffer
  174.                 ld      (init),a        ;init flag
  175.                 ret
  176.         p0:
  177.                 cp      'E'             ;is it even ?
  178.                 jr      nz,p1           ;no ...
  179.                 ld      (parity),a      ;set in comm buffer
  180.                 ld      (init),a        ;init flag
  181.                 ret
  182.         p1:
  183.                 cp      'N'             ;is it none ?
  184.                 jr      nz,p2           ;no, error
  185.                 ld      (parity),a      ;set in comm buffer
  186.                 ld      (init),a        ;init flag
  187.                 ret
  188.         p2:
  189.                 prmes   e5              ;invalid parity
  190.                 jp      abort           ;end in disaster
  191.         setb:
  192.                 pop     bc
  193.                 pop     hl
  194.                 call    nxtfld          ;get next field
  195.                 push    hl              ;save
  196.                 push    de
  197.                 push    bc
  198.                 ex      de,hl           ;de=compare string
  199.                 ld      hl,baudtb       ;baud rate table
  200.                 ld      a,49            ;svc scan
  201.                 rst     8               ;dos
  202.                 jr      nz,b0           ;not found
  203.                 inc     hl              ;increment to code
  204.                 inc     hl
  205.                 inc     hl
  206.                 inc     hl
  207.                 ld      a,(hl)          ;get code in a
  208.                 ld      (baud),a        ;in comm buffer
  209.                 ld      (init),a        ;init flag
  210.                 pop     bc              ;restore
  211.                 pop     de
  212.                 pop     hl
  213.                 ret
  214.         b0:
  215.                 prmes   e6              ;unsupported baud rate
  216.                 jp      abort           ;in disaster
  217.         setw:
  218.                 pop     bc
  219.                 pop     hl
  220.                 call    nxtfld          ;get next field
  221.                 ld      a,(hl)          ;first byte in a
  222.                 cp      '7'             ;is it 7
  223.                 jr      nz,w0           ;no, try 8
  224.                 sub     '0'             ;convert to binary
  225.                 ld      (wdlen),a       ;in comm buffer
  226.                 ld      (init),a        ;set init flag
  227.                 ret
  228.         w0:
  229.                 cp      '8'             ;is it 8
  230.                 jr      nz,w1           ;no, error
  231.                 ld      (wdlen),a       ;in comm buffer
  232.                 ld      (init),a        ;init flag
  233.                 ret
  234.         w1:
  235.                 prmes   e7              ;bad word length
  236.                 jp      abort           ;disaster
  237.         setc:
  238.                 pop     bc
  239.                 pop     hl
  240.                 call    nxtfld          ;get next field
  241.                 ld      a,(hl)          ;first byte in a
  242.                 cp      'A'             ;is it cnannel A ?
  243.                 jr      nz,c0           ;no, try B
  244.                 ld      (port),a        ;in comm buffer
  245.                 ld      (init),a        ;init flag
  246.                 ret
  247.         c0:
  248.                 cp      'B'             ;is it B
  249.                 jr      nz,c1           ;no, error
  250.                 ld      (port),a        ;in comm buffer
  251.                 ld      (init),a        ;init flag
  252.                 ret
  253.         c1:
  254.                 prmes   e8              ;invalid channel
  255.                 jp      abort           ;disaster
  256.         seter:
  257.                 pop     bc
  258.                 pop     hl
  259.                 prmes   e9              ;invalid parameter
  260.                 prmes   u0              ;usage is...
  261.                 jp      abort           ;disaster
  262.         setl:
  263.                 pop     bc              ;restore
  264.                 pop     hl
  265.                 call    nxtfld          ;get record length
  266.                 push    hl              ;save
  267.                 push    bc
  268.                 push    de
  269.                 ld      de,work         ;to store value and padd
  270.                 ld      a,b             ;get length
  271.                 cp      6               ;maximum lebgth + 1
  272.                 jp      nc,seter        ;no good ... bye
  273.         l0:
  274.                 cp      5               ;maximum length
  275.                 jr      z,l1            ;finished moving
  276.                 inc     a               ;increase length
  277.                 inc     de              ;and pointer
  278.                 jr      l0
  279.         l1:
  280.                 ld      c,b             ;get length in bc
  281.                 ld      b,0
  282.                 ldir                    ;move to work+(5-bc)
  283.                 ld      hl,work         ;get hl to point correctly
  284.                 ld      b,1             ;code to convert to bin
  285.                 ld      a,21            ;BINDEC svc
  286.                 rst     8               ;dos
  287.                 ld      a,e             ;get binary value
  288.                 ld      (lrecl),a       ;save in fcb
  289.                 pop     de              ;restore
  290.                 pop     bc
  291.                 pop     hl
  292.                 ret
  293.         nxtfld:
  294.                 ld      d,0             ;initialize de to e
  295.                 add     hl,de           ;add to hl - where to start
  296.                 ld      de,lab          ;list address block
  297.                 ld      a,46            ;parse svc
  298.                 rst     8               ;dos
  299.                 ret
  300.         go:
  301.                 call    initcm          ;initialize comm channel
  302.                 prmes   00              ;now say hello
  303.         ;       here is the main jump, every routine ends here
  304.         ;
  305.         mjump:
  306.                 jumptb  stjump,state
  307.          ;
  308.         ;
  309.         ;
  310.         ;       and this is the main receive file jump
  311.         ;
  312.         rfjump:
  313.                 jumptb  rftab,rtype
  314.         ;
  315.         ;       and the main receive data jump
  316.         ;
  317.         rdjump:
  318.                 jumptb  rdtab,rtype
  319.         ;
  320.                 end     start
  321.