home *** CD-ROM | disk | FTP | other *** search
/ Ham Radio 2000 #1 / Ham Radio 2000.iso / ham2000 / packet / p_aa4re / mbb35src / mbbios.asm < prev    next >
Encoding:
Assembly Source File  |  1991-02-16  |  25.5 KB  |  528 lines

  1.         PAGE    60,132
  2.         TITLE   Serial interface
  3. ;--------------------------------------------------------------------------;
  4. ;                                                                          ;
  5. ;  Version 3.5                   <== Also in message at end of this file   ;
  6. ;  Date: February 17th, 1991     <== Ditto!                                ;
  7. ;                                                                          ;
  8. ;  Communications BIOS routines:                                           ;
  9. ;                                                                          ;
  10. ;     1)  These replace the standard BIOS routine for interrupt            ;
  11. ;     handling at high speed.                                              ;
  12. ;                                                                          ;
  13. ;     2)  They extend things from character orientation to line            ;
  14. ;     orientation to faciliate packets                                     ;
  15. ;                                                                          ;
  16. ;     3)  They support chips other than the standard IBM 8250 type.        ;
  17. ;                                                                          ;
  18. ;   Currently supported (but maybe not in the version you are looking at)  ;
  19. ;                                                                          ;
  20. ;     a.  IBM standard ASYNC card using the 8250.  This also maps          ;
  21. ;         the AT standard serial port.                                     ;
  22. ;     b.  The PC-100 Paccomm card containing an Zilog 8530 or equivalent   ;
  23. ;         with an onboard AMD 7910 modem.  Only supported in the HDLC      ;
  24. ;         mode.                                                            ;
  25. ;     c.  QUADRAM's QUADPORT card                                          ;
  26. ;     d.  A card contanting up to 4 ASNYC ports using standard 8250s       ;
  27. ;         with the interrupts multiplexed.                                 ;
  28. ;     e.  16550 chips                                                      ;
  29. ;                                                                          ;
  30. ;   Copyright 1983 by William E. Westfield.  All rights reserved.          ;
  31. ;   Copyright 1986, 1987, 1988, 1989, 1990, 1991 by H. Roy Engehausen.     ;
  32. ;   All rights reserved.                                                   ;
  33. ;                                                                          ;
  34. ;   This software may be freely distributed and used, but it may not       ;
  35. ;   under any circumstances be sold by anyone other than the author.       ;
  36. ;   It may be distributed by a commercial company as long as it is         ;
  37. ;   for no cost.                                                           ;
  38. ;                                                                          ;
  39. ;   Change History                                                         ;
  40. ;     12/24/86 -- Changed vector swapping to use DOS calls                 ;
  41. ;      1/10/87 -- Transmit buffering                                       ;
  42. ;      1/11/87 -- Resident monitor                                         ;
  43. ;      2/01/87 -- QUADRAM card                                             ;
  44. ;      2/15/87 -- 4 async port card support                                ;
  45. ;      9/01/87 -- Added 8530 support                                       ;
  46. ;      5/01/88 -- Increased capability for ports                           ;
  47. ;      7/01/88 -- Turbo V4. New display format.  Options.                  ;
  48. ;      8/01/88 -- AT support                                               ;
  49. ;     10/07/89 -- Correct block write code                                 ;
  50. ;     10/14/90 -- 16550 support                                            ;
  51. ;      2/16/91 -- DV support                                               ;
  52. ;                                                                          ;
  53. ;--------------------------------------------------------------------------;
  54.  
  55. ;==========================================================================;
  56. ; System constants                                                         ;
  57. ;==========================================================================;
  58.  
  59. coms_to_build    EQU 12             ; Number of com blocks (max)
  60.  
  61. ; WARNING WARNING WARNING
  62.  
  63. ; You must have at least three buffers and the minimum size is 512.
  64. ; This is because the initialization code is located in the place where
  65. ; the buffers get built during initialization.  In other words, the
  66. ; init buffer stuff will clobber the code.  If you want to change
  67. ; those minimums you may have to rearrange things in the init area
  68.  
  69. buffers_to_build EQU 30             ; Number of buffers!
  70. buffer_size      EQU 512            ; Bytes in each buffer
  71. buffer_size_para EQU buffer_size/16 ; Paragraphs in each buffer
  72.  
  73. ;==========================================================================;
  74. ; Code generation switches  -- To save storage you can select/deselect     ;
  75. ; the code you need do minimize generating support for hardware            ;
  76. ; you dont have or use...                                                  ;
  77. ;                                                                          ;
  78. ; Prereqs...                                                               ;
  79. ;    8250x requires 8250                                                   ;
  80. ;    qrqp  requires 8250                                                   ;
  81. ;    4apc  requires 8250                                                   ;
  82. ;    fifo  requires 8250                                                   ;
  83. ;==========================================================================;
  84.  
  85. present_8250     EQU 1              ; 8250 code generation desired
  86. present_8250x    EQU 1              ; 8250 extended code generation desired
  87. present_8251     EQU 0              ; 8251 code generation not desired
  88. present_8530     EQU 0              ; 8530 HDLC code generation not desired
  89. present_qrqp     EQU 1              ; Quadram Quadport
  90. present_4apc     EQU 1              ; 4 Async port card
  91. present_fifo     EQU 1              ; 16550 FIFO support
  92. present_dv       EQU 1              ; Desqview support
  93.  
  94. ;==========================================================================;
  95. ; Vector numbers to use                                                    ;
  96. ;==========================================================================;
  97.  
  98. dos_terminate_no    EQU   20H       ; DOS terminate interrupt
  99. dos_vector_no       EQU   21H       ; DOS main service interrupt
  100. dos_tsr_no          EQU   27H       ; DOS terminate but stay resident
  101.  
  102. rs232_vector_no     EQU   14H       ; RS232 service interrupt
  103. timer_vector_no     EQU   1CH       ; Timer tick interrupt
  104.  
  105. ;--------------------------------------------------------------------------;
  106. ; DOS subfunctions                                                         ;
  107. ;--------------------------------------------------------------------------;
  108.  
  109. dos_write_line      EQU   09H       ; Write line to output
  110. dos_set_vector      EQU   25H       ; Set vector
  111. dos_get_vector      EQU   35H       ; Get vector
  112. dos_free_mem        EQU   49H       ; Free memory
  113.  
  114. ;==========================================================================;
  115. ; Set up the works                                                         ;
  116. ;==========================================================================;
  117.  
  118. everything SEGMENT PUBLIC
  119.       ASSUME CS: everything         ; These assumptions are for the
  120.       ASSUME DS: NOTHING            ; assembler's benefit.  The code
  121.       ASSUME ES: NOTHING            ; jerks things around as it pleases
  122.       ASSUME SS: NOTHING            ;
  123.  
  124. ;--------------------------------------------------------------------------;
  125. ; Copy right statements -- You must leave these in!!!!                     ;
  126. ; The symbols marker and marklen are used to search for other copies       ;
  127. ; of this program                                                          ;
  128. ;--------------------------------------------------------------------------;
  129.  
  130.  DB  'Copyright 1983 by William E. Westfield.  All rights reserved'        ;
  131.  DB  'Copyright 1986, 1987, 1988, 1989, 1990, 1991 by H. Roy Engehausen.'  ;
  132.  DB  'All rights reserved.'                                                ;
  133.  
  134. ;--------------------------------------------------------------------------;
  135. ; Initialize the desqview stuff                                            ;
  136. ;--------------------------------------------------------------------------;
  137.  
  138.   IF present_dv
  139.  
  140. dv_cnt      = 0
  141.             .LALL
  142. dv_hook     MACRO NUM
  143. dv_hook&num LABEL BYTE
  144.             ENDM
  145.  
  146.   ENDIF
  147.  
  148. ;--------------------------------------------------------------------------;
  149. ; The DOS PSP -- Loaded by COMMAND.COM just before it gives us control     ;
  150. ;--------------------------------------------------------------------------;
  151.  
  152.                     ORG   2CH
  153. psp_environ_ptr     DW    ?         ; Segment address of environment
  154.  
  155.                     ORG   80H
  156. psp_parm_len        DB    ?         ; Length of input parameter
  157. psp_parm            DB    ?         ; Input parameter from here to 0FFH
  158.                                     ; inclusive
  159.  
  160. ;--------------------------------------------------------------------------;
  161. ; BIOS Vector -- These are not really here but allow us to play games      ;
  162. ; to address low storage                                                   ;
  163. ;--------------------------------------------------------------------------;
  164.  
  165.                     ORG   timer_vector_no*4 ; Timer pop
  166. timer_vector        DW    ?         ;
  167.                     DW    ?         ;
  168.  
  169.                     ORG   rs232_vector_no*4 ; Software interrupt vector
  170. rs232_vector        DW    ?         ; to BIOS
  171.                     DW    ?         ;
  172.  
  173.                     ORG   0400H     ; BIOS COMx addresses
  174. rs232_bios_address  DW    ?         ;
  175.                     DW    ?         ;
  176.                     DW    ?         ;
  177.                     DW    ?         ;
  178. rs232_bios_max      EQU   4         ; Maximum number of com ports for that
  179.                                     ; can have addresses here
  180.  
  181. ;--------------------------------------------------------------------------;
  182. ; Buffer contents -- These are not really here but allow us to play games  ;
  183. ; when addressing the buffers via ES.  These may not be used by all the    ;
  184. ; routines in this program.                                                ;
  185. ;                                                                          ;
  186. ; The free buffer list is chained together using the buffer_next variable  ;
  187. ;                                                                          ;
  188. ; The 8250 IBM ASYNC card uses its buffer in a ring fashion.  Only         ;
  189. ; 1 buffer is used for receive and another for transmit.  Data is          ;
  190. ; placed in the buffer and removed in a ring fashion.  Since there         ;
  191. ; are no chains etc, for the 8250, those service/interrupt routines        ;
  192. ; use the whole buffer area.                                               ;
  193. ;                                                                          ;
  194. ; The 8530 has two chains:  Transmit buffers are serially chained using    ;
  195. ; the current one as the head;  Receive buffers are also serially          ;
  196. ; chained using the current one as the head.  These are in reverse order,  ;
  197. ; however, with the last one in the chain being the oldest.                ;
  198. ;                                                                          ;
  199. ;--------------------------------------------------------------------------;
  200.  
  201.             ORG   0
  202. buffer_dat:                         ; Buffer data starts here
  203.  
  204.             ORG   buffer_size-8     ; Last eight bytes of the buffer
  205. buffer_siz2 EQU   $-buffer_dat      ;
  206. buffer_dl   DW    ?                 ; Number of bytes in this buffer
  207. buffer_st1  DB    ?                 ; Status byte 1 for this buffer
  208. buffer_st1_ddb  EQU  10000000B      ;   Don't discard buffer on xmit
  209. buffer_st1_xmt  EQU  01000000B      ;   Buffer transmitted
  210. buffer_st2  DB    ?                 ; Status byte 2 for this buffer
  211. buffer_ufld DW    ?                 ; User field -- For application's use
  212. buffer_next DW    ?                 ; Pointer to next buffer in the chain
  213.  
  214. ; we should now be at the buffer size
  215.  
  216. ;==========================================================================;
  217. ; Control block layout for each port -- Just labels to provide a structure ;
  218. ;==========================================================================;
  219.  
  220.              ORG    0
  221.  INCLUDE MBBCOM.ASM                 ; Control block layout file
  222.  
  223. ;==========================================================================;
  224. ; Program start                                                            ;
  225. ;==========================================================================;
  226.  
  227.             ORG     100H
  228. dos_start:  JMP     start           ; Entry point
  229.  
  230. ;==========================================================================;
  231. ; Configuration information                                                ;
  232. ;==========================================================================;
  233.  
  234. buffer_count DB  buffers_to_build   ; Number of buffers!
  235.              DB  coms_to_build      ; Number of com ports (max)
  236.              DB  com_size           ; Size of one comport
  237.  
  238. com_start:
  239.  
  240.  INCLUDE MBCNF.ASM;                 ; Configuration file
  241.  
  242.             ORG     com_start+coms_to_build*com_size
  243.             ORG     $+coms_to_build*tie_size
  244.  
  245. ;==========================================================================;
  246. ; IBM PC (or clone) hardware constants                                     ;
  247. ;==========================================================================;
  248.  
  249. pic_cmd_port     EQU       020H     ; 8259 interrupt controller command address
  250. pic_mask_port    EQU       021H     ; 8259 interrupt controller mask address
  251.  
  252. pic_clear        EQU       020H     ; Non-specific interrupt clear
  253.  
  254. irq_offset       EQU       008H     ; Offset from IRQ number to vector
  255.  
  256. ;==========================================================================;
  257. ; IBM AT (or clone) hardware constants                                     ;
  258. ;==========================================================================;
  259.  
  260. pic2_cmd_port    EQU       0A0H     ; 8259 interrupt controller command address
  261. pic2_mask_port   EQU       0A1H     ; 8259 interrupt controller mask address
  262.  
  263. irq2_offset      EQU       070H     ; Offset from IRQ number to vector
  264.  
  265. ;==========================================================================;
  266. ; Chip control constants                                                   ;
  267. ;==========================================================================;
  268.  
  269.  
  270.  IF present_8250
  271.    INCLUDE 8250CON.ASM;             ; 8250 hardware constants
  272.  ENDIF
  273.  
  274.  IF present_8530
  275.    INCLUDE 8530CON.ASM;             ; 8530 hardware constants
  276.  ENDIF
  277.  
  278.  INCLUDE KISS.ASM;                  ; KISS mode constants
  279.  
  280.  IF present_qrqp OR present_4apc
  281.    INCLUDE QRQPCON.ASM;             ; QuadRam Quadport hardware constants
  282.  ENDIF
  283.  
  284. ;==========================================================================;
  285. ; Static variables                                                         ;
  286. ;==========================================================================;
  287.  
  288. old_bios_vector   DW  ?             ; Save previous bios vector
  289.                   DW  ?             ; 2 words for each
  290.  
  291. old_interrupt_vec_off DW  ?  ; Previous hardware interrupt vectors -- offset
  292.                   ORG old_interrupt_vec_off+coms_to_build*com_size ;
  293. old_interrupt_vec_seg DW  ?  ; Previous hardware interrupt vectors -- segment
  294.                   ORG old_interrupt_vec_seg+coms_to_build*com_size ;
  295.  
  296. interrupt_vector LABEL WORD         ; List of interrupt handlers.  As they
  297.         DW      OFFSET serint_1     ; are used, the corresponding com block
  298.         DW      OFFSET serint_2     ; address is substituted
  299.         DW      OFFSET serint_3     ;
  300.         DW      OFFSET serint_4     ;
  301.         DW      OFFSET serint_5     ;
  302.         DW      OFFSET serint_6     ;
  303.  
  304. free_buffer_head DW   ?             ; Buffer segment at head of chain
  305. pool_start       DW   ?             ; Buffer segment for pool start
  306.  
  307. timer_old        DW   0             ; Old timer interrupt
  308.                  DW   0             ;      Need two words
  309.                                     ;      Zero = not valid
  310.  
  311. timer_counter    DB   0             ; Timer counter
  312.  
  313. ;--------------------------------------------------------------------------;
  314. ; Local variables for QUADRAM QUADPORT  or 4 async port card interrupt     ;
  315. ; handler.. The interrupt handler runs disabled so we don't need           ;
  316. ; seperate copies of the variables for each port/card.                     ;
  317. ;--------------------------------------------------------------------------;
  318.  
  319.  IF present_qrqp OR present_4apc
  320.  
  321. serint_4apc_switch  DB   ?          ; Switch to show interrupt handled
  322.  
  323. qrqp_save_mir    DB   ?             ; Master interrupt register save
  324. qrqp_tie_pointer DW   ?             ; Pointer to tie pointer to service next
  325.  
  326. qrqp_int_map     LABEL BYTE         ; Interrupt settings for board
  327.                  DB    0            ; IRQ-0
  328.                  DB    0            ; IRQ-1
  329.                  DB    1            ; IRQ-2
  330.                  DB    1            ; IRQ-3
  331.                  DB    2            ; IRQ-4
  332.                  DB    2            ; IRQ-5
  333.                  DB    0            ; IRQ-6
  334.                  DB    0            ; IRQ-7
  335.                  DB    0            ; IRQ-8
  336.                  DB    0            ; IRQ-9
  337.                  DB    1            ; IRQ-A
  338.                  DB    1            ; IRQ-B
  339.                  DB    2            ; IRQ-C
  340.                  DB    2            ; IRQ-D
  341.                  DB    0            ; IRQ-E
  342.                  DB    0            ; IRQ-F
  343.  
  344.  ENDIF
  345.  
  346. ;--------------------------------------------------------------------------;
  347. ; The symbols marker and marklen are used to search for other copies       ;
  348. ; of this program                                                          ;
  349. ;--------------------------------------------------------------------------;
  350.  
  351. marker:
  352.  
  353.  DB  'MBBIOS load marker'                                                  ;
  354.  
  355. marklen      EQU $-marker
  356.  
  357. ;==========================================================================;
  358. ; Our BIOS handler                                                         ;
  359. ;==========================================================================;
  360.  
  361.  INCLUDE MBBUSVC.ASM;               ; Service handler
  362.  
  363. ;==========================================================================;
  364. ; Timer interrupt handler                                                  ;
  365. ;==========================================================================;
  366.  
  367.  INCLUDE MBBTIMER.ASM;              ; Service handler
  368.  
  369. ;==========================================================================;
  370. ; Interrupt handlers                                                       ;
  371. ;==========================================================================;
  372.  
  373.  INCLUDE MBBINTER.ASM;              ; Interrupt handler
  374.  
  375. ;==========================================================================;
  376. ; Generalized subroutines                                                  ;
  377. ;==========================================================================;
  378.  
  379.  INCLUDE MBBSUBR.ASM;               ; General service subroutines
  380.  
  381. ;==========================================================================;
  382. ; DV code                                                                  ;
  383. ;==========================================================================;
  384.  
  385.  INCLUDE DESQVIEW.ASM;              ; The DV code
  386.  
  387. ;==========================================================================;
  388. ; Buffer round up                                                          ;
  389. ;==========================================================================;
  390.  
  391. huh:
  392.         ORG huh+16
  393. buffer_start:
  394.  
  395. ;==========================================================================;
  396. ; Main line to initialize.  This is located in the first buffer and is,    ;
  397. ; therefore destroyed after things start.                                  ;
  398. ;==========================================================================;
  399.  
  400.         ASSUME DS: everything       ; DS works here
  401.         ASSUME ES: NOTHING          ; Don't use ES
  402.         ASSUME SS: NOTHING          ; Don't use SS
  403.  
  404. ;--------------------------------------------------------------------------;
  405. ; Variables only needed by initialization                                  ;
  406. ;--------------------------------------------------------------------------;
  407.  
  408. parm_flag      DB    0              ; Input parameter
  409. parm_flag_f    EQU   10000000B      ; "F" -- Force load
  410. parm_flag_r    EQU   01000000B      ; "R"
  411. parm_flag_u    EQU   00100000B      ; "U" -- Unload
  412. parm_flag_d    EQU   00010000B      ; "D" -- Desqview
  413.  
  414. psp_count      DB    0              ; Number of PSP's after us...
  415.  
  416. com_init_count DW    0              ; Number of ports done * 2
  417.  
  418. need_tmr       DB    0              ; Need to snatch timer
  419.  
  420. ;--------------------------------------------------------------------------;
  421. ; Start the initialization code                                            ;
  422. ;--------------------------------------------------------------------------;
  423.  
  424. start:
  425.  
  426.         MOV     AX,CS               ; Point DS in the right place
  427.         MOV     DS,AX               ;
  428.  
  429. ;--------------------------------------------------------------------------;
  430. ; Announce our presence                                                    ;
  431. ;--------------------------------------------------------------------------;
  432.  
  433.         MOV     DX,OFFSET msghello  ; Message
  434.         MOV     AH,dos_write_line   ; Send to output
  435.         INT     dos_vector_no       ;
  436.  
  437. ;--------------------------------------------------------------------------;
  438. ; Check loading status, etc                                                ;
  439. ;--------------------------------------------------------------------------;
  440.  
  441.  INCLUDE MBBLOAD.ASM ;
  442.  
  443. ;--------------------------------------------------------------------------;
  444. ; Create an hole in the routines here to prevent buffer clobber during     ;
  445. ; init.  There must be 16 bytes prior to the buffer end clear              ;
  446. ;--------------------------------------------------------------------------;
  447.  
  448.         JMP     init_section2       ;
  449.  
  450.         ORG     buffer_start + buffer_size ;
  451.  
  452. init_section2:
  453.  
  454. ;--------------------------------------------------------------------------;
  455. ; Initialize buffers, etc                                                  ;
  456. ;--------------------------------------------------------------------------;
  457.  
  458.  INCLUDE MBBINIT.ASM ;
  459.  
  460. ;--------------------------------------------------------------------------;
  461. ; This leaves a small hole in the code for the buffer pointer              ;
  462. ;--------------------------------------------------------------------------;
  463.  
  464.         JMP     over_pointer
  465.         ORG     $+100
  466. over_pointer:
  467.  
  468. ;--------------------------------------------------------------------------;
  469. ; Tell everybody we worked!                                                ;
  470. ;--------------------------------------------------------------------------;
  471.  
  472.         MOV     DX,OFFSET msgok     ; Message
  473.         MOV     AH,dos_write_line   ; Send to output
  474.         INT     dos_vector_no       ;
  475.  
  476. ;--------------------------------------------------------------------------;
  477. ; Exit and stay resident                                                   ;
  478. ;--------------------------------------------------------------------------;
  479.  
  480.         MOV     AL,buffer_count     ; Calculate size of buffer space
  481.         CBW                         ;
  482.         MOV     BX,buffer_size      ; Calculate size of buffer space
  483.         MUL     BX                  ; needed.
  484.  
  485.         MOV     DX,OFFSET buffer_start+5 ;note some slack...
  486.         ADD     DX,AX               ; Total length!
  487.  
  488.         INT     dos_tsr_no          ; Terminate but stay resident
  489.  
  490. ;--------------------------------------------------------------------------;
  491. ; Create an hole in the routines here to prevent buffer clobber during     ;
  492. ; init.  There must be 16 bytes prior to the buffer end clear              ;
  493. ;--------------------------------------------------------------------------;
  494.  
  495.         ORG     buffer_start + 3*buffer_size ;
  496.  
  497. ;==========================================================================;
  498. ; Messages                                                                 ;
  499. ;==========================================================================;
  500.  
  501. msghello   DB 'MBBIOS Version 3.5 -- October 7th, 1990',13,10
  502.            DB '(c) 1987, 1988, 1989, 1990  H.R. Engehausen',13,10
  503.            DB 'Freely copyable for non-commercial purposes',13,10,13,10,'$'
  504.  
  505. msgbad     DB 'Invalid input parameter',13,10,'$'
  506.  
  507. msgok      DB 'MBBIOS loaded and ready',13,10,'$'
  508.  
  509. msgdupe    DB 'MBBIOS already loaded -- Load ignored',13,10,'$'
  510.  
  511. msgnodup   DB 'MBBIOS not loaded -- Unload ignored',13,10,'$'
  512.  
  513. msgnotlast DB 'Something in memory after MBBIOS -- Unload ignored',13,10,'$'
  514.  
  515. msgunload  DB 'MBBIOS successfully unloaded',13,10,'$'
  516.  
  517. ;==========================================================================;
  518. ; Buffers                                                                  ;
  519. ;==========================================================================;
  520.  
  521. ; The buffers are here
  522.  
  523. program_end:
  524.  
  525. everything     ENDS
  526.  
  527.         END dos_start
  528.