home *** CD-ROM | disk | FTP | other *** search
/ Power Programming / powerprogramming1994.iso / progtool / modem / tt_104.arc / TT.ASM < prev    next >
Assembly Source File  |  1988-02-22  |  21KB  |  848 lines

  1. COMMENT * ==================================================================
  2.  
  3.     Copyright (C) 1988, George A. Stanislav.
  4.     All Rights Reserved.
  5.  
  6.     This program is a dumb terminal for FOSSIL communications.
  7.     It works only from the COM1 port and only at 300/1200/2400
  8.     baud, with a built-in ansi-bbs and AVATAR terminal emulation.
  9.     That means that if you call a BBS supporting ANSI graphics,
  10.     it should correctly recognize the movement of your cursor keys,
  11.     as well as the <home> and <end> keys. More importantly, if
  12.     the BBS sends out Opus color codes, the AVATAR emulator will
  13.     convert them to ANSI sequences. You need ANSI.SYS properly
  14.     installed for either emulation to work properly.
  15.  
  16.     The purpose of this program is mostly didactical. Lesson 2
  17.     of FOSSIL programming. (Lesson 1 was the previous version,
  18.     called DUMBTERM.) You can probably add Lesson 3 as of version
  19.     1.02, the lesson is contained in the AVATAR emulator.
  20.  
  21.     New in version 1.03 are 20 user configurable keys. With the
  22.     help of TTSETUP.COM, you can configure the 10 function keys
  23.     when combined with either <ctl> or <alt> for a string up to
  24.     32 characters long. The same program will allow you to choose
  25.     defaults other than those coded here.
  26.  
  27.     While the program is a dumb terminal, it allows you to transfer
  28.     file using the Zmodem protocol. For that, however, you need
  29.     TWO additional programs: Author's PROZ.COM and Chuck Forsberg's
  30.     DSZ.COM or DSZ.EXE. Of the two, PROZ.COM must be in the current
  31.     default directory, while DSZ can be anywhere as long as the
  32.     PATH environmental variable is pointing at it.
  33.  
  34.     You can freely copy it and give it to others. The word FREELY
  35.     is substantial. Any charge imposed in connection with passing
  36.     this program onto someone else is in direct violation with
  37.     my Copyright. That also means that anyone who sells diskettes
  38.     or other media with public domain or shareware programs is
  39.     expressly prohibited from distributing this program. This program
  40.     is NOT in public domain!
  41.  
  42.     Usage:
  43.  
  44.         As it is a very simple terminal indeed, all you need is
  45.         a 300, 1200, or 2400 baud modem attached to COM1 and
  46.         type TT.
  47.  
  48.         Whatever you type thereafter goes directly into the
  49.         modem. To dial a number you will have to type
  50.         ATDT 123-4567 <cr>. To initialize the modem, you
  51.         will have to type ATZ or whatever your modem manual
  52.         suggests.
  53.  
  54.         To exit the program, type ^END. That means you can use
  55.         ^C online.
  56.  
  57.     Obviously, you cannot use this program for file transfers. This
  58.     is just a dumb terminal.
  59.  
  60.     Support form author:
  61.  
  62.         None.
  63.  
  64. * ===========================================================================
  65.  
  66. ;    MACROS to make it look like a high level language
  67.  
  68. fossil    macro        ; call FOSSIL driver
  69.  
  70.     int    14h
  71.  
  72. endm
  73.  
  74. dos    macro        ; call MS DOS
  75.  
  76.     int    21h
  77.  
  78. endm
  79.  
  80. print    macro    text
  81.  
  82.     mov    ah,09h    ; display string
  83.     ifnb    <text>
  84.       mov    dx,offset text    ; point to it
  85.     endif
  86.     dos
  87.  
  88. endm
  89.  
  90. exit    macro    level
  91.  
  92.     mov    ax,4c00h + level    ; ah = 4ch, al = level
  93.     dos
  94.  
  95. endm
  96.  
  97. port    macro        ; choose COM1
  98.  
  99.     mov    dx,cport    ; dx = cport
  100.     fossil        ; call the driver
  101.  
  102. endm
  103.  
  104. setB    macro    rate    ; set baud rate
  105.  
  106.     ifnb    <rate>
  107.       mov    al,baud    ; that's ah = 0, al = 10000011 initially
  108.     endif
  109.     xor    ah,ah
  110.         port        ; COM1
  111.  
  112. endm
  113.  
  114. csend    macro        ; transmit a character from al
  115.  
  116.     mov    ah,1    ; the character must already be in al
  117.     port
  118.  
  119. endm
  120.  
  121. crec    macro        ; receive a character from fossil buffer
  122.  
  123.     mov    ah,2    ; the received character will be in al
  124.     port
  125.  
  126. endm
  127.  
  128. open    macro
  129.     local opened,oldfos,done
  130.  
  131.     mov    ah,4    ; initialize fossil
  132.     port
  133.     cmp    ax,1954h    ; the fossil "magic" number
  134.     je    opened    ; achieved
  135.     print    msg    ; fossil not present
  136.     exit    1    ; abort with errorlevel 1
  137. opened:    cmp    bh,4    ; need at least FOSSIL, rev. 4
  138.     jb    oldfos
  139.     cmp    bl,19h    ; can we write a block?
  140.     jnb    done    ; yes, done
  141. oldfos:    add    oldrev,bh ; fix error message
  142.     print    neednew    ; print error message
  143.     exit    2    ; abort with errorlevel 2
  144. done:    
  145.  
  146. endm
  147.  
  148. close    macro        ; cleanup
  149.  
  150.     mov    ah,5
  151.     port
  152.  
  153. endm
  154.  
  155. dtr    macro    onoroff
  156.  
  157.     mov    ax,600h + onoroff    ; on = 1, off = 0
  158.     port
  159.  
  160. endm
  161.  
  162. finkey    macro        ; fossil "inkey"
  163.  
  164.     mov    ah,0ch
  165.     port
  166.     inc    ax    ; zero flag = 0 if nothing there
  167.  
  168. endm
  169.  
  170. inkey    macro        ; keyboard "inkey"
  171.  
  172.     mov    ah,0dh
  173.     fossil        ; never mind the port
  174.     inc    ax    ; check zero flag
  175.  
  176. endm
  177.  
  178. cget    macro        ; read character from keyboard
  179.  
  180.     mov    ah,0eh
  181.     fossil
  182.  
  183. endm
  184.  
  185. cput    macro        ; display a character
  186.  
  187.     mov    ah,13h    ; character must be in al
  188.     fossil
  189.  
  190. endm
  191.  
  192. sends    macro    string,strlen
  193.  
  194.     ifnb <string>
  195.     mov    di,offset string
  196.     mov    cx,strlen
  197.     endif
  198.     mov    ah,19h
  199.     fossil
  200.  
  201. endm
  202.  
  203. talk    macro
  204.     local talk1,talked ; talk to the other end
  205.  
  206.     inkey        ; check if the keyboard has been hit
  207.     jz    talked    ; no it was not, keep quiet
  208.     cget        ; yes, see what it is
  209.     or    al,al    ; is it a function key?
  210.     jne    talk1    ; no, send it out
  211.     call    funkey    ; process function key
  212.     jmp    short talked
  213. talk1:    csend        ; send char out
  214. talked:
  215.  
  216. endm
  217.  
  218. listen    macro
  219.     local l1,listen1,listened    ; listen to the other end
  220.  
  221.     finkey        ; anything there?
  222.     jz    listened    ; nope
  223.     crec        ; receive character
  224.     cmp    al,26    ; is it a control character?
  225.     ja    listen1    ; no, check further
  226. l1:    call    avatar    ; advanced video attribute transfer
  227.     jmp    short listened
  228. listen1:cmp    avaflag,0    ; are we processing avatar?
  229.     jne    l1    ; yes, call avatar
  230.     cput        ; no, display it
  231. listened:
  232.  
  233. endm
  234.  
  235. chat    macro
  236.     local keep
  237. keep:
  238.     talk
  239.     listen
  240.     jmp    keep
  241.  
  242. endm
  243.  
  244. sendc    macro    char
  245.  
  246.     mov    al,char
  247.     csend
  248.  
  249. endm
  250.  
  251. ; DEFINES
  252.  
  253. ctlA    equ    1
  254. ctlB    equ    2
  255. ctlC    equ    3
  256. ctlD    equ    4
  257. ctlE    equ    5
  258. ctlF    equ    6
  259. ctlG    equ    7
  260. ctlH    equ    8
  261. ctlL    equ    12
  262. ctlV    equ    22
  263. ctlY    equ    25
  264. cr    equ    13
  265. dle    equ    16
  266. lf    equ    10
  267. bell    equ    7
  268. stop    equ    '$'
  269. on    equ    1
  270. off    equ    0
  271. tab    equ    9
  272. bmask    equ    00011111b    ; baud rate mask
  273. b3    equ    01000000b    ; 300 baud mask
  274. b12    equ    10000000b    ; 1200 baud mask
  275. b24    equ    10100000b    ; 2400 baud mask
  276. pmask    equ    11100000b    ; parity etc. mask
  277. p7E1    equ    00011010b    ; mask for 7E1
  278. p8N1    equ    00000011b    ; mask for 8N1
  279. imask    equ    00001000b    ; intensity bit
  280. fgrmask    equ    00000111b    ; foreground color mask
  281. bkgmask    equ    01110000b    ; background color
  282. black    equ    0
  283. blue    equ    1
  284. green    equ    2
  285. cyan    equ    3
  286. red    equ    4
  287. magenta    equ    5
  288. brown    equ    6
  289. white    equ    7
  290. vflag    equ    1        ; ^v received
  291. aflag    equ    2        ; ^v^a received
  292. yflag    equ    3        ; ^y received
  293. yflag2    equ    4        ; ^y received, repeat character known
  294. hflag    equ    5        ; ^v^h received
  295. hflag2    equ    6        ; ^v^h received, row known
  296. noflag    equ    0
  297.  
  298. ; The PROGRAM
  299.  
  300. dumb    segment
  301.  
  302.     assume    ds:dumb,es:dumb,cs:dumb,es:dumb
  303.  
  304.     org    100h
  305.  
  306. main    proc
  307. start:    jmp    begin
  308.  
  309. version    dw    0104h        ; 1.04
  310. cport    dw    0        ; start with COM1
  311. baud    db    10000011b    ; start with 1200 baud 8N1
  312. editor    db    0,' /C ',80 dup(0)    ; space for editor
  313. macword    label    word
  314. mac    db    20 dup (32 dup (?))    ; space for 20 key macros
  315. macount    db    20 dup (0)    ; sizes of 20 key macros
  316. copr    db    cr,lf,'TinyTerm - ANSI & AVATAR Emulating Terminal, version 1.04',cr,lf
  317.     db    'Copyright (C) 1988, George A. Stanislav',cr,lf
  318.     db    'All Rights Reserved.',cr,lf,lf
  319.     db    'This is a very simple terminal. Whatever you type '
  320.     db    '(except ^<end>) is sent',cr,lf
  321.     db    'straight to the modem. Its initial setup is 1200 baud, 8N1, from '
  322.     db    'COM1. The full',cr,lf
  323.     db    'assembly language source code is included so you can write '
  324.     db    'your own programs',cr,lf
  325.     db    'using other configurations. The goal of this program is to '
  326.     db    'show to as many',cr,lf
  327.     db    'as possible how to write FOSSIL communications programs '
  328.     db    'and AVATAR emulation.',cr,lf,lf
  329.     db    'TinyTerm allows you to configure the 10 function keys '
  330.     db    'combined with the',cr,lf
  331.     db    '<alt> or <ctl> keys as "macros". You can either define '
  332.     db    'them in the source',cr,lf
  333.     db    'code or, better yet, by running TTSETUP.COM. This also '
  334.     db    'allows you to choose',cr,lf
  335.     db    'defaults other than COM1, 1200 baud and 8N1.',cr,lf,lf
  336.     db    'Hit <F10> for help, <Ctrl> <End> to exit.',cr,lf,lf,stop
  337. msg    db    'FOSSIL not found. In order to run this program you need to '
  338.     db    'load a FOSSIL',cr,lf
  339.     db    'communications driver before you call TINYTERM.',cr,lf,stop
  340. neednew    db    cr,lf,lf,'You are using revision '
  341. oldrev    db    '0 of FOSSIL. For TinyTerm to run properly you',cr,lf
  342.     db    'need revision 5 or higher.',cr,lf,lf,stop
  343. help    db    cr,lf,lf,tab
  344.     db    '     TinyTerm Help:',cr,lf,lf,tab
  345.     db    '< F1 >   -   ATDT',cr,lf,tab
  346.     db    '< F2 >   -   AT <return>',cr,lf,tab
  347.     db    '< F3 >   -   AT',cr,lf,tab
  348.     db    '< F4 >   -   300  baud',cr,lf,tab
  349.     db    '< F5 >   -   1200 baud',cr,lf,tab
  350.     db    '< F6 >   -   2400 baud',cr,lf,tab
  351.     db    '< F7 >   -   7E1',cr,lf,tab
  352.     db    '< F8 >   -   8N1',cr,lf,tab
  353.     db    '< F9 >   -   A/  ( = redial)',cr,lf,tab
  354.     db    '<ctrl> or <alt> <F1 - F10> - user defined macros',cr,lf,tab
  355.     db    '<alt> <H> - drop DTR [hang up]',cr,lf,tab
  356.     db    '<alt> <R> - raise DRT',cr,lf,tab
  357.     db    '<alt> <D> - drop to DOS temporarily',cr,lf,tab
  358.     db    '<alt> <E> - call the editor',cr,lf,lf,tab
  359.     db    'The following file transfer commands need DSZ:',cr,lf,lf,tab
  360.     db    '<PgDn> or <PgUp> - Zmodem receive/send',cr,lf,tab
  361.     db    '<ctrl> <PgDn> or <ctrl> <PgUp> - Xmodem (CRC) transfer',cr,lf,lf,tab
  362.     db    'Hit <ctrl> <end> or <alt> <X> to exit',cr,lf,lf,stop
  363. drop    db    cr,lf,lf,tab,'DTR dropped',cr,lf,lf,stop
  364. raise    db    cr,lf,lf,tab,'DTR raised',cr,lf,lf,stop
  365. zbad    db    cr,lf,lf,bell,tab,'For file transfer you need a copy of DSZ.COM or DSZ.EXE'
  366.     db    cr,lf,tab,'somewhere on the path.',cr,lf,lf,stop
  367. nocom    db    cr,lf,bell,tab,'COMSPEC not found.',cr,lf,stop
  368. command    db    80 dup(0)
  369. cmdret    db    cr,lf,tab,'Type "EXIT" to return to TinyTerm.',cr,lf,stop
  370. cmdret2    db    cr,lf,tab,'Back in TinyTerm.',cr,lf,stop
  371. cmd    db    cmdlen
  372. cmd1    db    ' /C dsz '
  373. cmdr    db    'r'
  374. cmdz    db    'z '
  375. cmdlen    equ    $-cmd1
  376. cmdf    db    80 dup(0)
  377. cmdmdz    db    cr,lf,tab,'Attempting Zmodem download using DSZ:'
  378.     db    cr,lf,lf,stop
  379. cmdmfr    db    cr,lf,tab,'Attempting Xmodem/CRC download using DSZ.',cr,lf,lf
  380.     db    cr,lf,tab,'Enter the filename to receive (up to 80 characte'
  381.     db    'rs)',cr,lf,'> ',stop
  382. cmdmfs    db    cr,lf,tab,'Attempting '
  383. XorZ    db    'Zmodem upload using DSZ.',cr,lf,lf
  384.     db    cr,lf,tab,'Enter the path\filename to send (up to 80 charac'
  385.     db    'ters)',cr,lf,'> ',stop
  386. edmsg    db    cr,lf,,tab,'Calling editor.',cr,lf,stop
  387. noedit    db    cr,lf,tab,bell,'No editor. Use TTSETUP.COM to define one.'
  388.     db    cr,lf,stop
  389. param    dw    0
  390. param1    dw    offset cmd
  391. parseg    dw    ?
  392.     dd    -1
  393.     dd    -1
  394. sseg    dw    ?
  395. sptr    dw    ?
  396. spec    db    'COMSPEC=',0
  397. atdt    db    'ATDT'
  398. atdtlen    equ    $-atdt
  399. at    db    'AT',cr
  400. atlen    equ    $-at
  401. atshort    equ    atlen - 1
  402. bspeed    db    cr,lf,lf,tab,'Baud rate set to $'
  403. b300    db    '3$'
  404. b1200    db    '12$'
  405. b2400    db    '24'
  406. bspeed2    db    '00 bps.',cr,lf,lf,'$'
  407. epar    db    cr,lf,lf,tab,'Set to 7 bits, EQUAL'
  408. par2    db    ' parity, 1 stop bit.',cr,lf,lf,stop
  409. npar    db    cr,lf,lf,tab,'Set to 8 bits, NO$'
  410. noblink    db    '$'
  411. attrib    db    ''
  412. intense    db    '0;4'
  413. back    db    '0;3'
  414. fore    db    '0m$'
  415. blink    db    '$'
  416. cleol    db    '$'
  417. cls    db    'H$'
  418. up    db    'A$'
  419. down    db    'B$'
  420. left    db    'D$'
  421. right    db    'C$'
  422. bracket    db    '$'
  423. even
  424. avatbl    dw    offset blink
  425.     dw    offset up
  426.     dw    offset down
  427.     dw    offset left
  428.     dw    offset right
  429.     dw    offset cleol
  430. color    db    black,red,green,brown,blue,magenta,cyan,white
  431. avaflag    db    0
  432. rchar    db    ?
  433.  
  434. begin:    mov    bx,(4 * 1024)    ; 16 kiloblocks = 1 segment
  435.     mov    ah,4ah
  436.     dos        ; release unneeded memory
  437.     mov    si,offset spec    ; find comspec
  438.     mov    es,es:[2ch]    ; environment block
  439.     xor    di,di    ; start from the beginning
  440. spec1:    mov    bx,si    ; pointer to variable
  441.     cmp    byte ptr es:[di],0    ; not found?
  442.     je    main1    ; comspec not found, cannot shell
  443. spec2:    mov    al,[bx]    ; read char in variable
  444.     or    al,al    ; is it a final 0?
  445.     je    spec4    ; yes, comspec found
  446.     cmp    al,es:[di]    ; matching character?
  447.     jne    spec3    ; nope, try next variable
  448.     inc    bx    ; yes, try next character
  449.     inc    di    ;    in both strings
  450.     jmp    spec2
  451. spec3:    xor    al,al    ; find closing '\0' of nonmatching string
  452.     mov    cx,0ffffh    ; allow for "infinite" length
  453.     cld        ; check in forward direction
  454.     repnz    scasb    ; until a 0 is matched
  455.     jmp    spec1    ; try next variable
  456. spec4:    mov    si,offset command    ; copy env variable to data segment
  457. spec5:    mov    al,es:[di]    ; get character
  458.     mov    [si],al    ; and copy it
  459.     inc    si    ; next char
  460.     inc    di    ; in both strings
  461.     or    al,al    ; closing 0?
  462.     jne    spec5    ; no, copy more
  463. main1:    mov    ax,ds
  464.     mov    es,ax
  465.     mov    parseg,ax
  466.     print    copr    ; say hi
  467.     open        ; open the channel of communications
  468.     setB    1200    ; 1200 baud, 8N1
  469.     dtr    on    ; turn dtr on
  470.     chat        ; communicate till ^end is hit . . .
  471.     ret        ; unnecessary, but just in case...
  472.  
  473. main    endp
  474.  
  475. funkey    proc
  476.  
  477.     cmp    ah,'^'    ; ^ <F1>
  478.     jb    fkey0    ; not a ^FKEY or ALT-FKEY
  479.     cmp    ah,'q'    ; ALT <F10>
  480.     ja    fkey0    ; not a ^FKEY or ALT-FKEY
  481.     sub    ah,'^'    ; offset in the table
  482.     xchg    ah,al    ; al = ah, ah = 0
  483.     mov    bx,ax    ;turn into pointer
  484.     mov    al,macount[bx]    ; string length
  485.     mov    cl,5    ; 32 = 2 ** 5
  486.     shl    bx,cl    ; multiply by 32
  487.     add    bx,offset macword
  488.     mov    di,bx
  489.     mov    cx,ax    ; ah still = 0
  490.     sends        ; send it out to the modem
  491.     ret        ; return to caller
  492. fkey0:    cmp    ah,'H'    ; <up>
  493.     jne    f00
  494.     mov    al,'A'
  495.     jmp    ansi
  496. f00:    cmp    ah,'P'    ; <down>
  497.     jne    f01
  498.     mov    al,'B'
  499.     jmp    ansi
  500. f01:    cmp    ah,'M'    ; <right>
  501.     jne    f02
  502.     mov    al,'C'
  503.     jmp    ansi
  504. f02:    cmp    ah,'K'    ; <left>
  505.     jne    f03
  506.     mov    al,'D'
  507.     jmp    ansi
  508. f03:    cmp    ah,'G'    ; <home> sweet <home>
  509.     jne    f04
  510.     mov    al,'H'
  511.     jmp    ansi
  512. f04:    cmp    ah,'O'    ; <end>
  513.     jne    f05
  514.     mov    al,'K'
  515.     jmp    ansi
  516. f05:    cmp    ah,'u'    ; ^<end>
  517.     je    f050    ; finish
  518.     cmp    ah,'-'    ; <alt> <X>
  519.     jne    f06
  520. f050:    exit    0    ; end program
  521. f06:    cmp    ah,';'    ; <F1> send ATDT to the modem
  522.     jne    f07
  523.     sends    atdt,atdtlen
  524.     ret
  525. f07:    cmp    ah,'<'    ; <F2> send AT<cr>
  526.     jne    f08
  527.     sends    at,atlen    
  528.     ret
  529. f08:    cmp    ah,'D'    ; <F10> help
  530.     jne    f0a
  531. f09:    print    help
  532.     ret
  533. f0a:    cmp    ah,'4'    ; <F12> of enhanced keyboard - help
  534.     je    f09
  535.     cmp    ah,'='    ; <F3> AT, no <cr>
  536.     jne    f0b
  537.     sends    at,atshort
  538.     ret
  539. f0b:    cmp    ah,'>'    ; <F4>, set 300 baud
  540.     jne    f0c
  541.     mov    al,baud
  542.     and    al,bmask ;remove old baud rate
  543.     or    al,b3    ; set to 300 bps
  544.     mov    baud,al
  545.     setB
  546.     print    bspeed
  547.     print    b300
  548.     print    bspeed2
  549.     ret
  550. f0c:    cmp    ah,'?'    ; <F5> set 1200 baud
  551.     jne    f0d
  552.     mov    al,baud
  553.     and    al,bmask
  554.     or    al,b12
  555.     mov    baud,al
  556.     setB
  557.     print    bspeed
  558.     print    b1200
  559.     print    bspeed2
  560.     ret
  561. f0d:    cmp    ah,'@'    ; <F6>, set 2400 baud
  562.     jne    f0e
  563.     mov    al,baud
  564.     and    al,bmask
  565.     or    al,b24
  566.     mov    baud,al
  567.     setB
  568.     print    bspeed
  569.     print    b2400
  570.     ret
  571. f0e:    cmp    ah,'A'    ; <F7>, set 7E1
  572.     jne    f0f
  573.     mov    al,baud
  574.     and    al,pmask
  575.     or    al,p7E1
  576.     mov    baud,al
  577.     setB
  578.     print    epar
  579.     ret
  580. f0f:    cmp    ah,'B'    ; <F8>, set 8N1
  581.     jne    f10
  582.     mov    al,baud
  583.     and    al,pmask
  584.     or    al,p8N1
  585.     mov    baud,al
  586.     setB
  587.     print    npar
  588.     print    par2
  589.     ret
  590. f10:    cmp    ah,'C'    ; <F9>, A/
  591.     jne    f11
  592.     sendc    'A'
  593.     sendc    '/'
  594.     ret
  595. f11:    cmp    ah,'#'    ; <alt> <H>, drop dtr
  596.     jne    f12
  597.     dtr    off
  598.     print    drop
  599.     ret
  600. f12:    cmp    ah,'Q'    ; <Page Down>, call zmodem download
  601.     jne    f14
  602.     mov    cmdr,'r'    ; receive
  603.     mov    cmd,cmdlen
  604.     mov    cmdz,'z'    ; use Zmodem
  605.     mov    cmdf,0    ; don't prompt for a file name
  606.     mov    param1,offset cmd
  607.     lea    dx,cmdmdz    ; Zmodem download message
  608.     call    exec
  609.     jnc    f13
  610.     print    zbad
  611. f13:    ret
  612. f14:    cmp    ah,''    ; <alt> <R>, raise DTR
  613.     jne    f15
  614.     dtr    on
  615.     print    raise
  616.     ret
  617. f15:    cmp    ah,''    ; <alt> <E>, run editor
  618.     jne    f17
  619.     cmp    editor,0    ; is an editor defined?
  620.     jne    f16    ; yes, try to run it
  621.     print    noedit
  622.     ret
  623. f16:    mov    param1,offset editor
  624.     lea    dx,edmsg
  625.     mov    cmdf,0    ; don't prompt for a file name
  626.     call    exec
  627.     ret
  628. f17:    cmp    ah,'v'    ; <ctl> <Page Down>, Xmodem download via DSZ
  629.     jnz    f18
  630.     mov    cmdf,1    ; prompt for the filename
  631.     mov    param1,offset cmd
  632.     mov    cmdr,'r'    ; receive file
  633.     mov    cmdz,'c'    ; using Xmodem/CRC
  634.     lea    dx,cmdmfr
  635.     call    exec
  636.     ret
  637. f18:    cmp    ah,'I'    ; <Page Up>, Zmodem upload
  638.     jnz    f19
  639.     mov    cmdf,1    ; prompt for the file name
  640.     mov    XorZ,'Z'
  641.     mov    param1,offset cmd
  642.     mov    cmdr,'s'    ; send
  643.     mov    cmdz,'z'    ; Zmodem
  644.     lea    dx,cmdmfs
  645.     call    exec
  646.     ret
  647. f19:    cmp    ah,'ä'    ; <ctl> <Page Up>, Xmodem upload
  648.     jnz    f1a
  649.     mov    cmdf,1    ; prompt for the file name
  650.     mov    param1,offset cmd
  651.     mov    cmdr,'s'    ; send
  652.     mov    cmdz,'x'    ; Xmodem
  653.     mov    XorZ,'X'
  654.     lea    dx,cmdmfs
  655.     call    exec
  656.     ret
  657. f1a:    cmp    ah,' '    ; <alt> <D>, drop to DOS
  658.     jnz    f1b
  659.     mov    cmdf,0    ; don't prompt for file name
  660.     mov    param1,offset    cmd
  661.     mov    cmd,0    ; no parameters passed
  662.     lea    dx,cmdret
  663.     call    exec
  664.     print    cmdret2
  665.     ret
  666. f1b:    ret
  667.  
  668. ansi:    push    ax    ; save code
  669.     sends    blink,2    ; <esc>[
  670.     pop    ax    ; restore code
  671.     csend        ;send it to the modem
  672.     ret        ; return to caller
  673.  
  674. funkey    endp
  675.  
  676. avatar    proc    near
  677.  
  678. ; Enter the procedure with a control character received from the modem
  679. ; in AL. Check if it is an advanced video attribute. If so, translate it
  680. ; to ANSI and send to the screen. Else, print it unchanged to the screen.
  681.  
  682.     cmp    avaflag,0    ;have we started yet?
  683.     jne    ava1
  684.     cmp    al,ctlL    ;clear screen?
  685.     jne    a00    ;no, something else
  686.     print    cls    ;thoroughly clean screen
  687.     ret        ;return to caller
  688. a00:    cmp    al,ctlY    ;repeat character?
  689.     jne    a02    ;no, try other codes
  690.     mov    avaflag,yflag        ;set flag
  691.     ret
  692.  
  693. a02:    cmp    al,ctlV    ;video code?
  694.     je    a03    ;yes, parse it
  695.     cput        ;no, send ctrl code to screen
  696.     ret        ;and return to caller
  697. a03:    mov    avaflag,vflag    ;set flag
  698.     ret
  699.  
  700. ava1:    cmp    avaflag,vflag    ;are we in ^v ?
  701.     jne    ava2    ;nope, check further
  702.     cmp    al,ctlA    ;color attribute?
  703.     jne    ava3    ;no, check further
  704.     mov    avaflag,aflag    ;set flag
  705.     ret
  706. ava2:    cmp    avaflag,yflag    ;repeat character?
  707.     jne    ava4    ;no, check further
  708.     mov    rchar,al    ;save repeat char
  709.     mov    avaflag,yflag2    ;set flag
  710.     ret
  711. ava3:    cmp    al,ctlG    ;something simple?
  712.     ja    ava5    ;no, need further processing
  713.     xor    ah,ah    ;clean high byte
  714.     dec    al
  715.     dec    al    ;start at the bottom of table
  716.     shl    ax,1
  717.     mov    bx,ax    ;convert to pointer
  718.     mov    dx,avatbl[bx]    ;find proper ansi sequence
  719.     print        ;and send it to the screen
  720.     mov    avaflag,noflag    ;reset the flag
  721.     ret        ;return to caller
  722. ava4:    cmp    avaflag,aflag    ;are we to set the attribute?
  723.     jne    ava6    ;nope, check further
  724.     mov    avaflag,noflag    ;reset the flag
  725.     test    al,imask;intensity bit on?
  726.     je    a04    ;no
  727.     push    ax    ;print would destroy it
  728.     print    noblink    ;just in case blink is on, turn it off
  729.     pop    ax    ;restore register
  730.     mov    intense,'1'    ;yes, send <esc>[1m
  731.     jmp    short a05
  732. a04:    mov    intense,'0'    ;send <esc>[0m
  733. a05:    push    ax    ;save for further processing
  734.     and    al,bkgmask    ;find background color
  735.     mov    cl,4
  736.     shr    al,cl    ;convert to a decimal digit
  737.     xor    ah,ah    ;clean up high byte
  738.     mov    bx,ax    ;convert to a pointer
  739.     mov    al,color[bx]    ;find ANSI color
  740.     add    al,'0'    ;convert to ASCII
  741.     mov    back,al    ;send to escape sequence
  742.     pop    ax    ;restore attribute
  743.     and    al,fgrmask    ;get foreground attribute
  744.     xor    ah,ah    ;clean up high byte
  745.     mov    bx,ax    ;change into pointer
  746.     mov    al,color[bx]    ;find the color
  747.     add    al,'0'    ;convert to ASCII
  748.     mov    fore,al    ;set to escape sequence
  749.     print    attrib    ;send it all to the screen
  750.     ret        ;return to caller
  751. ava5:    cmp    al,ctlH    ;cursor control?
  752.     je    ava7    ;yes, process it
  753.     push    ax    ;no, print codes
  754.     mov    al,ctlV    ;first print ^v
  755.     cput
  756.     pop    ax    ;restore second character
  757.     cput        ;and print it
  758.     mov    avaflag,noflag    ;reset the flag
  759.     ret        ;return to caller
  760. ava6:    cmp    avaflag,yflag2    ;is it repeat character?
  761.     jne    ava8    ;no, check further
  762.     xor    ah,ah    ;use just AL
  763.     mov    cx,ax    ;initialize the counter
  764.     mov    al,rchar    ;restore character to print
  765. a01:    cput        ;print it
  766.     loop    a01    ;until cx = 0
  767.     mov    avaflag,noflag    ;reset the flag
  768.     ret        ;return to caller
  769. ava7:    mov    avaflag,hflag    ;set flag
  770.     ret
  771. ava8:    cmp    avaflag,hflag    ;cursor control?
  772.     jne    ava9    ;check further
  773.     mov    avaflag,hflag2
  774.     mov    rchar,al    ;save row
  775.     ret        ;return to caller
  776. ava9:    cmp    avaflag,hflag2    ;column?
  777.     jne    ava10    ;nope
  778.     mov    avaflag,noflag    ;reset counter
  779.     push    ax    ;save column
  780.     print    bracket    ;print ANSI intro
  781.     mov    al,rchar    ;restore row number
  782.     call    printno    ;and print them
  783.     mov    al,';'    ;separator
  784.     cput        ;print it out
  785.     pop    ax    ;restore columns
  786.     call    printno    ;print the number
  787.     mov    al,'f'    ;finish the ansi command
  788.     cput
  789.     ret
  790. ava10:            ;theoretically we should never get here....
  791.     mov    avaflag,noflag    ;reset flag
  792.     ret
  793.  
  794. avatar    endp
  795.  
  796. printno    proc    near
  797.  
  798.     aam        ;convert to decimal
  799.     or    ah,ah    ; > 10 ?
  800.     jz    p00    ;no, do not print tens
  801.     push    ax    ;save units
  802.     mov    al,ah    ;ready to print tens
  803.     add    al,'0'    ;convert to ASCII
  804.     cput        ;send to screen
  805.     pop    ax    ;restore units
  806. p00:    add    al,'0'    ;convert to ASCII
  807.     cput        ;send to screen
  808.     ret        ;return to caller
  809.  
  810. printno    endp
  811.  
  812. exec    proc    near
  813.  
  814.     cmp    command,0
  815.     jne    exec1
  816.     print    nocom
  817.     ret
  818. exec1:
  819.     print
  820.     cmp    cmdf,0    ; do we wait for a file name?
  821.     je    exec2    ; no, skip it
  822.     mov    ah,3fh
  823.     xor    bx,bx    ; stdin
  824.     mov    cx,80    ; maximum string length
  825.     lea    dx,cmdf
  826.     dos
  827.     add    ax,(cmdlen-2)    ; count total command tail length w/o cr/lf
  828.     mov    cmd,al    ; and post it
  829. exec2:    push    ds
  830.     push    es
  831.     mov    sseg,ss
  832.     mov    sptr,sp
  833.     mov    dx,offset command
  834.     mov    bx,offset param
  835.     mov    ax,4b00h
  836.     dos
  837.     mov    ss,sseg
  838.     mov    sp,sptr
  839.     pop    es
  840.     pop    ds
  841.     ret
  842.  
  843. exec    endp
  844.  
  845. dumb    ends
  846.     end    start
  847.  
  848.