home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 23 / IOPROG_23.ISO / SOFT / ASM / GRDBDL17.ZIP / OPTIONS.ASM < prev    next >
Encoding:
Assembly Source File  |  1998-10-26  |  10.6 KB  |  505 lines

  1. ;
  2. ; GRDP
  3. ;
  4. ; Copyright(c) LADsoft
  5. ;
  6. ; David Lindauer, camille@bluegrass.net
  7. ;           
  8. ;
  9. ; OPTIONS.ASM.ASM
  10. ;
  11. ; Function: Option input and display
  12. ;
  13.     ;MASM MODE
  14.     .MODEL SMALL
  15.     .386p
  16.  
  17. NUMOPTS = 11
  18. include  iversion.inc
  19. include  eprints.inc 
  20. include  einput.inc 
  21. include  emtrap.inc 
  22. include  ebreaks.inc 
  23. include  eints.inc
  24. include  elogging.inc
  25.  
  26. ; define the symbol RAWA20 to run flat real mode with XMS
  27. ;
  28.     PUBLIC doopt,optdword, optdwordcommand,optpure,opthist, optflat0, optsignedimm
  29.     PUBLIC Disassemble32Bit, optdiv0, winshellchk
  30.     PUBLIC initflatreal, rundownflatreal, optdosio
  31.         PUBLIC ReadOptions, WriteOptions
  32.  
  33.     .data
  34. ;
  35. ; gdt for flat real mode
  36. ;
  37. gdt    db    8 DUP (0)            ;null entry  SEL 0
  38.     db    0ffh,0ffh,0,0,0,92h,0cfh,0    ;32-bit dseg SEL 8h
  39.     db    0ffh,0ffh,0,0,0,92h,0,0        ;16-bit dseg SEL 10h
  40. gdtp    dw    3 DUP (17h)            ;sice of gdt and its pointer
  41. oldgdt  db    6 DUP (?)            ;their GDT
  42.  
  43. ;
  44. ; optlist, optvals, and optvect MUST be kept in sync
  45. ;
  46. optlst    db    "wrfr32zrbknvfif0sohimd"
  47. oldflat0 db    0    ; echoes flat0 option so we can leave segs alone
  48.             ; on successive ?o if they change them
  49. ;
  50. writeopts db    0    ;true if options have changed
  51. ;
  52. optmark    dw    verid    ; MUST preced optvals
  53. optvals    label    BYTE
  54. optdword db    1    ;flag if user selected 32-bit registers (WR)
  55. optdwordcommand db 0    ;flag if user wants flat real mode (FR)
  56. Disassemble32Bit db    1    ;32-bit instructions enabled
  57.     TRUE    equ    1
  58.     FALSE    equ    0
  59. optdiv0    db    1    ; these two options DEPEND on VECTLIST
  60. optbrk  db    1    ; having the upper bits of the ints set right
  61.             ; on a no-param file start
  62. optpure db    1    ;native video
  63. optflatinit db    1    ;causes init for flat real mode
  64. optflat0 db    0    ; flat real mode - default segs to zero
  65. optsignedimm db    0    ; set if want to see signed immediates on u command
  66. opthist db    1    ;flag if user enabled history
  67. optdosio db    0    ; flag if using dos for command I/O
  68. ;
  69. optvect    dw    vsetopt,vsetopt,vsetopt
  70.     dw    voptdiv0,voptbrk1b,vsetopt,vsetopt,vsetopt,vsetopt,vsetopt
  71.     dw    vsetopt
  72. optname    db    "grdb.opt",0
  73.     .CODE
  74. ;
  75. ; for display of states
  76. ;
  77. optmsgs    label    BYTE
  78.     db    13,10,"WR - wide registers     ",0
  79.     db    13,10,"FR - flat real commands ",0
  80.     db    13,10,"32 - 32 bit disassembly ",0
  81.     db    13,10,"ZR - divide by zero trap",0
  82.     db    13,10,"BK - ctrl-break trap    ",0
  83.     db    13,10,"NV - native video       ",0
  84.     db    13,10,"FI - flat real autoinit ",0
  85.     db    13,10,"F0 - flat real 0 default",0
  86.     db    13,10,"SO - signed immediates  ",0
  87.     db    13,10,"HI - command history    ",0
  88.     db    13,10,"MD - msdos I/O          ",0
  89. ;
  90. ; check for windows shell
  91. ;
  92. winshellchk PROC
  93.     push si
  94.     mov    ax,1600h    ; check for windows func
  95.     int    2fh        ; multiplex int
  96.     pop    si
  97.     cmp    al,00h        ; windows not installed if = 0
  98.     je    nowin
  99.     cmp    al,80h        ; xms (but no windows) if = 80 h
  100.     je    nowin
  101.     pop    ax        ; anything else is windowsxx, drop ret addr
  102.     PRINT_MESSAGE    <10,13,"Feature inactive in windows shells">
  103.     clc
  104. nowin:
  105.     ret
  106.     
  107. winshellchk    ENDP
  108.  
  109. ifdef RAWA20
  110. ;
  111. ; Routine to wait till KB controller not busy
  112. ;
  113. kb_busy proc
  114.     xor cx,cx           ; Loop 65536 times
  115. kb_bs2:
  116.     in al,64h           ; Get status
  117.     jmp $+2
  118.     jmp $+2
  119.     test al,2           ; See if busy
  120.     jz kb_busy_done     ; Not busy any more
  121.     loop kb_bs2
  122.     stc
  123.     ret
  124. kb_busy_done:
  125.     clc
  126.     ret
  127. kb_busy endp
  128. ;
  129. ; Routine to wait till KB data buffer empty
  130. ;
  131. kb_writewait proc
  132.     xor cx,cx           ; Loop 65536 times
  133. kb_rd2:
  134.     in al,64h           ; Get port status
  135.     test al,2           ;
  136.     jz short kb_writewait_done  ; Quit if buffer empty
  137.     loop kb_rd2         ; Wait a while
  138.     stc                 ; Error
  139.     ret
  140. kb_writewait_done:
  141.     clc
  142.     ret
  143. kb_writewait endp
  144. ;
  145. ; Routine to wait till KB data buffer fll
  146. ;
  147. kb_readwait proc
  148.     xor cx,cx           ; Loop 65536 times
  149. kb_rdrd2:
  150.     in al,64h           ; Get port status
  151.     test al,1           ;
  152.     jnz short kb_readwait_done  ; Quit if buffer empty
  153.     loop kb_rdrd2               ; Wait a while
  154.     stc                 ; Error
  155.     ret
  156. kb_readwait_done:
  157.     mov cx,32           ; Wait for controller to set data
  158. delay:
  159.     jmp $+2
  160.     jmp $+2
  161.     loop delay          ;
  162.     clc
  163.     ret
  164. kb_readwait endp
  165. ;
  166. ; Routine to turn on A20 line
  167. ;
  168. seta20  proc
  169.     cli                 ; Don't want a keypress now!
  170.     call kb_busy        ; Wait while busy
  171.     jc short error              ;
  172.     mov al,0d0h         ; Command to get port status
  173.     out 64h,al          ;
  174.     call kb_busy        ; Wait while busy
  175.     jc short error    
  176.     call kb_readwait    ; Wait for it to put the char there
  177.     jc short error
  178.     in al,60h           ; Get the data
  179.     or al,2             ; Set the A20 bit
  180.     xchg al,ah          ; Data to ah
  181.     call kb_busy        ; Wait while busy
  182.     jc short error
  183.     mov al,0d1h         ; Command to put port status
  184.     out 64h,al          ;
  185.     call kb_busy        ; Wait while busy
  186.     jc short error
  187.     call kb_writewait   ; Wait for buffer to empty
  188.     jc short error
  189.     mov al,ah           ; Write the data
  190.     out 60h,al          ;
  191.     clc                 ; No erros
  192. error:
  193.     sti                 ; Keys allowed now
  194.     ret
  195. seta20  endp
  196. endif ; RAWA20
  197. ;
  198. ;
  199. ; init flat real mode
  200. ;
  201. initflatreal PROC
  202.     test    [optdwordcommand],1    ;check if can init
  203.     jz    ifrx
  204.     test    [optflatinit],1
  205.     jz    ifrx
  206.         smsw    ax              ; test if in a shell
  207.         test    ax,1
  208.         jnz     ifr_err         ; err if so
  209. ifdef RAWA20
  210.         call    seta20          ; same as XMS global alloc
  211. else
  212.         mov     ax,4300h        ; now see if XMS loaded
  213.         int     2fh
  214.         cmp     al,80h
  215.         jnz     ifr_err         ; err if not
  216.         push    es
  217.         mov     ax,4310h        ; get xms driver address
  218.         int     2fh
  219.         push    es              ; put on stack
  220.         push    bx
  221.         mov     ax,300h         ; now global enable HMA
  222.         call    dword ptr [esp] ;
  223.         pop     eax             ; clear stack
  224.         pop     es
  225.                                 ; at this point we don't check XMS
  226.                                 ; return stat as it always works :)
  227. endif
  228.         sub     eax,eax
  229.     mov    ax,ds
  230.     shl    eax,4
  231.     mov    bx,offset gdt
  232.     movzx    ebx,bx
  233.     add    eax,ebx
  234.     mov    dword ptr [gdtp+2],eax    ;save old gdt
  235.     push    ds
  236.     push    es
  237.     sgdt    fword ptr [oldgdt]    ;get our gdt
  238.     lgdt    fword ptr [gdtp]    ;flat real mode in FS
  239.     mov    eax,CR0
  240.     inc    eax
  241.     mov    CR0,EAX
  242.     mov    bx,8            
  243.     mov    ds,bx
  244.     mov    es,bx
  245.     mov    fs,bx
  246.     dec    eax        ; back to real mode
  247.     mov    CR0,eax
  248.     lgdt    fword ptr [oldgdt]    ;reload their GDT
  249.     pop    es
  250.     pop    ds
  251.     test    [optflat0],1
  252.     jz    ifrx2
  253.     test    [oldflat0],1
  254.     jnz    ifrx2
  255.     mov    [RegdumpDS],0
  256.     mov    [RegdumpES],0
  257.     mov    [RegdumpFS],0
  258.     mov    [RegdumpGS],0
  259.     ; leaves SS and CS alone so we can run programs :).
  260. ifrx2:
  261.     mov    al,[optflat0]
  262.     mov    [oldflat0],al
  263. ifrx:
  264.     ret
  265. ifr_err:
  266.         PRINT_MESSAGE    <13,10,"Error: in DOS shell or XMS not available">
  267.         mov     [optflatinit],0
  268.         ret
  269. initflatreal ENDP
  270. ;
  271. ; reset descriptors for real mode
  272. ;
  273. rundownflatreal PROC
  274.     test    [optdwordcommand],1    ;check if can init
  275.     jz    rfrx
  276.     test    [optflatinit],1
  277.     jz    rfrx
  278. ;
  279. ; we don't have to do lots of checking as the flatinit flag would have
  280. ; been cleared if we couldn't make the first transition...
  281. ;
  282.     push    ds
  283.     push    es
  284.     sgdt    fword ptr [oldgdt]    ;get our gdt
  285.     lgdt    fword ptr [gdtp]    ;flat real mode in FS
  286.     mov    eax,CR0
  287.     inc    eax
  288.     mov    CR0,EAX
  289.     mov    bx,16
  290.     mov    ds,bx
  291.     mov    es,bx
  292.     mov    fs,bx
  293.     dec    eax        ; back to real mode
  294.     mov    CR0,eax
  295.     lgdt    fword ptr [oldgdt]    ;reload their GDT
  296.     pop    es
  297.     pop    ds
  298.  
  299. rfrx:
  300.     ret
  301. rundownflatreal ENDP
  302. ;
  303. ; option command
  304. ;
  305. doopt    PROC    
  306.     Call    WadeSpace    ; Wade till address
  307.     jnz    optlp
  308.     mov    si,offset _text : optmsgs    ; no args, print all options
  309.     mov    di,offset optvals
  310.     mov    cx,NUMOPTS
  311. polp:
  312.     call    PrintOption
  313.     loop    polp
  314.     call    LoggingStat
  315.     call    initflatreal
  316. optxit:
  317.     clc
  318.     ret
  319. ;
  320. ; subroutine to print an option and its enabled/disabled value
  321. ;
  322. PrintOption:
  323.     mov    bx,si
  324.     call    olMessage
  325.     test    byte ptr [di],-1
  326.     jnz    dotype
  327.     PRINT_MESSAGE    <9,"disabled">
  328.     jmp    dojoin
  329. dotype:
  330.     PRINT_MESSAGE    <9,"enabled">
  331. dojoin:
  332.     inc    di
  333. frs_lp:
  334.     lods    byte ptr cs:[si]
  335.     or    al,al
  336.     jnz    frs_lp
  337.     ret
  338. ;
  339. ; comes here to set/reset an option
  340. ;
  341. optlp:
  342.     cmp    al,13
  343.     je    doopt        ; go back and show vals after the set
  344.     cmp    al,'-'        ; check for off command
  345.     pushf
  346.     jz    incpos
  347.     cmp    al,'+'
  348.     jne    noinc
  349. incpos:
  350.     inc    si
  351. noinc:
  352.     call    WadeSpace    ; now get the option letters
  353.     jz    opterr
  354.     lodsw
  355.     cmp    ah,13
  356.     je    opterr
  357.     mov    cx,NUMOPTS    ; search for them
  358.     mov    di,offset optlst
  359. cmplp:
  360.     scasw
  361.     jz    dovect
  362.     loop    cmplp
  363. opterr:
  364.     add    sp,2        ; bad opt, exit with no display
  365.     clc
  366.     ret
  367. dovect:
  368.     mov    [writeopts],1    ; changing, need disk update
  369.     neg    cx
  370.     add    cx,NUMOPTS
  371.     movzx    ebx,cx
  372.     popf
  373.     lahf
  374.     and    ah,40h
  375.     xor    ah,40h
  376.     shr    ah,6            ; ah = opt new val
  377.     call    [optvect + ebx*2] ; call handler
  378.     call    WadeSpace
  379.     jmp    optlp        ; get another
  380. doopt    ENDP
  381. ;
  382. ; option routines
  383. ; this one is for basic bools
  384. ;
  385. vsetopt PROC
  386.     mov    [bx + optvals],ah
  387.     ret
  388. vsetopt    ENDP
  389. ;
  390. ; following this we have interrupt enables/disables.
  391. ; they run through VECLIST and set the high bit to match the
  392. ; bool value
  393. ;         
  394. voptbrk1b    PROC
  395.     mov    al,1bh
  396.     jmp    vopttraps
  397. voptbrk1b    ENDP
  398. voptdiv0    PROC
  399.     mov    al,0
  400. voptdiv0    ENDP
  401. vopttraps    PROC
  402.     mov    [bx + optvals],ah
  403.     mov    bl,ah
  404. vopttraps    ENDP
  405. voptrefresh    PROC
  406.     push    si
  407.     mov    si,offset veclist
  408.     call    SetVectAttrib
  409.     pop    si
  410.     ret
  411. voptrefresh    ENDP
  412.  
  413. ;
  414. ; write options to disk file
  415. ;
  416. WriteOptions    PROC
  417. IFDEF OPTION_EN
  418.     mov    [optmark],verid
  419.     test    [writeopts],0ffh
  420.     jz    wo_x
  421.     call    optcreat
  422.     jc    wo_x
  423.     mov    dx,offset optmark
  424.     mov    cx,NUMOPTS+2
  425.     mov    ah,40h
  426.     int    21h
  427.     jc    wo_x2
  428.     mov    [writeopts],0
  429. wo_x2:
  430.     call    optclose
  431. wo_x:
  432. ENDIF
  433.     ret
  434. WriteOptions    ENDP
  435. ;
  436. ; read options from disk file
  437. ;
  438. ReadOptions    PROC
  439. IFDEF OPTION_EN
  440.     mov    [writeopts],1
  441.     mov    [optmark],-1
  442.     call    optopen
  443.     jc    ro_x
  444.     mov    dx,offset optmark
  445.     mov    cx,2
  446.     mov    ah,3fh
  447.     int    21h
  448.     jc    ro_x2
  449.     cmp    [optmark],verid
  450.     jne    ro_x2
  451.     mov    dx,offset optmark+2
  452.     mov    cx,NUMOPTS
  453.     mov    ah,3fh
  454.     int    21h
  455.     jc    ro_x2
  456.     cmp    ax,NUMOPTS
  457.     jne    ro_x2
  458.     push    bx
  459.     mov    [writeopts],0   ; the option file is read
  460.     mov    bl,[optdiv0]    ; now set the attrib bits in veclist
  461.     mov    al,0
  462.     call    voptRefresh
  463.     mov    bl,[optbrk]
  464.     mov    al,1bh
  465.     call    voptRefresh
  466.     call    initflatreal
  467.     pop    bx
  468. nd1bfix:
  469. ro_x2:
  470.     call    optclose
  471. ro_x:
  472. ENDIF
  473.     ret
  474. ReadOptions    ENDP
  475.  
  476.  
  477. IFDEF OPTION_EN
  478. ;
  479. ; generi disk file stuff.  Should probably merge with loader and logger
  480. ; routines...
  481. ;
  482. OptOpen    PROC
  483.     mov    ax,3d02h
  484.     mov    dx,offset optname
  485.     int    21h
  486.     mov    bx,ax
  487.     ret
  488. OptOpen    ENDP
  489. OptCreat    PROC
  490.     mov    ax,3c00h
  491.     mov    cx,0
  492.     mov    dx,offset optname
  493.     int    21h
  494.     mov    bx,ax
  495.     ret
  496. OptCreat    ENDP
  497. OptClose    PROC
  498.     mov    ah,3eh
  499.     int    21h
  500.     ret
  501. OptClose    ENDP
  502. ENDIF
  503.  
  504. end