home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS - Coast to Coast / simteldosarchivecoasttocoast2.iso / ka9q / nan24hyc.zip / NANSI_I.ASM < prev    next >
Assembly Source File  |  1990-10-30  |  4KB  |  144 lines

  1.     page    66, 132
  2. ;------ nansi_i.asm ----------------------------------------------
  3. ; Contains code only needed at initialization time.
  4. ; (C) 1986 Daniel Kegel
  5. ; May be distributed for educational and personal use only
  6. ; Modifications:
  7. ;  2/12/85: Removed code for BIOS takeover, added processor check
  8. ;  2/13/85: changed processor check to PUSH SP
  9. ;-----------------------------------------------------------------
  10.  
  11.     include nansi_d.asm        ; definitions
  12.  
  13.     ; to nansi.asm
  14.     public    dosfn0
  15.  
  16.     ; from nansi.asm
  17.     extrn    break_handler:near
  18.     extrn    int_29:near
  19.     if    takeBIOS
  20.     extrn    new_vid_bios:near
  21.     extrn    old_vid_bios:dword
  22.     endif
  23.     extrn    req_ptr:dword
  24.     extrn    xlate_tab_ptr:word
  25.     extrn    sr_min_y:byte, sr_max_y:byte
  26.  
  27.     ; from nansi_p.asm
  28.     extrn    param_buffer:word    ; adr of first byte free for params
  29.     extrn    param_end:word        ; adr of last byte used for params
  30.     extrn    redef_end:word        ; adr of last used byte for redefs
  31.  
  32.  
  33. code    segment byte public 'CODE'
  34.     assume    cs:code, ds:code
  35.  
  36. ;-------- dos function # 0 : init driver ---------------------
  37. ; Initializes device driver interrupts and buffers, then
  38. ; passes ending address of the device driver to DOS.
  39. ; Since this code is only used once, the buffer can be set up on top
  40. ; of it to save RAM.
  41. ;
  42. ; If assembled for the 80188-80286, make sure we're using it.
  43. ; (drk 7/8/86: this is futile, because we can't return to DOS, because
  44. ;  the PUSHA done initially didn't save the registers- we would need to set
  45. ;  up an alternative main routine which saved the stack as for the 8086.
  46. ;  We would probably want to automatically sense processor type, and only
  47. ;  change to PUSHA/POPA if they were supported.)
  48.  
  49. dosfn0    proc    near
  50. ;    ife    is_8088
  51. ;        ; Check pusha-popa.
  52. ;        mov    ax, sp
  53. ;        push    sp
  54. ;        cmp    ax, sp
  55. ;        jnz    dos0_pushok
  56. ;            mov    di, -1    ; pusha did nothing-
  57. ;            mov    ax, di    ; tell DOS we are bad device
  58. ;            jmp    short dos0_done
  59. ;dos0_pushok:
  60. ;        pop    ax
  61. ;    endif
  62.  
  63.     ; Install BIOS keyboard break handler.
  64.     xor    ax, ax
  65.     mov    ds, ax
  66.     mov    bx, 6Ch
  67.     mov    word ptr [BX],offset break_handler
  68.     mov    [BX+02], cs
  69.     ; Install INT 29 quick putchar.
  70.     mov    bx, 0a4h
  71.     mov    word ptr [bx], offset int_29
  72.     mov    [bx+2], cs
  73.  
  74.     if    takeBIOS
  75.     ; Install INT 10h video bios replacement.
  76.     mov    bx, 40h
  77.     mov    ax, [bx]
  78.     mov    word ptr cs:old_vid_bios, ax
  79.     mov    ax, [bx+2]
  80.     mov    word ptr cs:old_vid_bios[2], ax
  81.     mov    word ptr [bx], offset new_vid_bios
  82.     mov    word ptr [bx+2], cs
  83.     endif
  84.  
  85.     push    cs
  86.     pop    ds
  87.     push    cs
  88.     pop    es            ; es=cs so we can use stosb
  89.     cld                ; make sure stosb increments di
  90.  
  91.     ; Initialize state variables...
  92.     mov    sr_min_y, 0
  93.     mov    sr_max_y, 24        ; assuming 24 line screen...
  94.  
  95.     ; Calculate addresses of start and end of parameter/redef buffer.
  96.     ; The buffer occupies the same area of memory as this code!
  97.     ; ANSI parameters are accumulated at the lower end, and
  98.     ; keyboard redefinitions are stored at the upper end; the variable
  99.     ; param_end is the last byte used by params (changes as redefs added);
  100.     ; redef_end is the last word used by redefinitions.
  101.     mov    di, offset dosfn0
  102.     mov    param_buffer, di
  103.     add    di, 512
  104.     mov    param_end, di    ; addr of last byte in free area
  105.     inc    di
  106.  
  107.     ; Build the default redefinition table:
  108.     ;    control-printscreen -> control-P
  109.     ; (Must be careful not to write over ourselves here!)
  110.     mov    al, 16        ; control P
  111.     stosb
  112.     mov    ax, 7200h    ; control-printscreen
  113.     stosw
  114.     mov    ax, 1        ; length field
  115.     mov    redef_end, di    ; address of last used word in table
  116.     stosw
  117.  
  118.     ; Build a 1:1 output character translation table.
  119.     ; It is 256 bytes long, starts just after the param/redef buffer,
  120.     ; and is the last thing in the initialized device driver.
  121.     mov    xlate_tab_ptr, di
  122.     xor    ax, ax
  123. init_loop:
  124.     stosb
  125.     inc    al
  126.     jnz    init_loop
  127.  
  128.     mov    ax, cs
  129. dos0_done:
  130.     ; Return ending address of this device driver.
  131.     ; If ax=di=FFFF, DOS will refuse to load us.
  132.     lds    si, req_ptr
  133.     mov    word ptr [si+0Eh], di
  134.     mov    [si+10h], ax
  135.  
  136.     ; Return "not busy" exit status.
  137.     xor    ax, ax
  138.     ret
  139.  
  140. dosfn0    endp
  141.  
  142. code    ends
  143.     end                ; of nansi_i.asm
  144.