home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS - Coast to Coast / simteldosarchivecoasttocoast2.iso / asmutil / dos32v12.zip / EXAMPLE2.ASM < prev    next >
Assembly Source File  |  1993-10-17  |  6KB  |  267 lines

  1. ;         32BIT  DOS  EXTENDER
  2. ;
  3. ; Written by Adam Seychell     Wed 8-25-1993
  4. ;
  5. .386
  6.  
  7.  
  8. CODE32    SEGMENT PARA PUBLIC  USE32
  9. assume    DS:CODE32 , CS:CODE32, ES:CODE32
  10.  
  11. extrn    CODE32_sel    :word        ; Selector Values
  12. extrn    DATA_sel    :word
  13. extrn    VIDEO_sel    :word
  14. extrn    FLAT_CODE32_sel    :word
  15. extrn    FLAT_DATA_sel    :word
  16. extrn    XMS_sel        :word
  17. extrn    BASE_sel    :word
  18. extrn    PSP_sel        :word
  19. extrn    ENVIRONMENT_sel    :word
  20.  
  21.  
  22. xms_usage    dd 1000000h    ; Requested size of XMS block in bytes.
  23. xms_base    dd ?        ; Linear base address of the XMS block.
  24. Base_Segment    dw ?        ; Real mode segment value for base memory.
  25. PSP_segment    dw ?        ; Real mode segment value for PSP segment.
  26.  
  27. align 4
  28. count        dd 0
  29. v86_mesg    db ' Message printed in v86 mode !!!!',10,13,36
  30. file_name    db 'C:\Command.COM',0
  31. parmBlock    db 10h dup (0)
  32. welcom_mesg    db 'Now in V86 mode',10,13,36
  33. exit_mesg    db 'back to borring real mode',10,13,36
  34. cunt        db 0
  35.  
  36. include        stdio.asm
  37. include        macros.386
  38. include        dos32.inc
  39.  
  40. start32:        ; 32 bit code entry point.    DS -> data descripor
  41.  
  42.         mov    ds,cs:[data_sel]       ;Must load these with valid selectors
  43.     mov    es,[xms_sel]
  44.     mov    fs,[FLAT_DATA_sel]
  45.     mov    gs,[video_sel]
  46.         mov    ss,[data_sel]        ; Must setup stack area
  47.     mov    esp,offset pmode_stack
  48.         sti
  49.  
  50.     mov real_ds,CODE32
  51.         mov    ds,cs:data_sel
  52.  
  53.         mov ah,7
  54.         call clrscr
  55.  
  56.         writeln 'Got into protected mode ',1
  57.  
  58.     write <10,13,' A '>
  59.  
  60.     mov    edx,xms_usage
  61.         mov ah,0eh
  62.         call hex_dword
  63.  
  64.  
  65.         write <' byte extended memory block with base address '>
  66.         mov ah,0eh
  67.         mov    edx,xms_Base
  68.         call hex_dword
  69.  
  70.     writeln ' was allocated'
  71.  
  72.     write <10,13,'Start of free base memory '>
  73.         xor    edx,edx
  74.  
  75.  
  76.     mov    dx,Base_Segment
  77.         shl    edx,4
  78.         mov ah,0eh
  79.         call hex_dword
  80.  
  81.         writeln
  82.     write <10,13,'PSP memory address '>
  83.         xor    edx,edx
  84.     mov    dx,PSP_Segment
  85.         shl    edx,4
  86.         mov ah,0eh
  87.         call hex_dword
  88.  
  89.  
  90.     writeln
  91.     writeln
  92.     writeln ' Press any key to continue '
  93.  
  94.         mov ah,0
  95.        dosint 16h
  96.  
  97.  
  98.  
  99.         mov es,xms_sel
  100.         cld
  101.  
  102. mov    cunt,10
  103. tsm3:
  104.  
  105.  
  106.         writeln ' Filling memory ',5fh
  107.  
  108.         mov es,xms_sel
  109.         mov ecx,xms_usage
  110.         and ecx,ecx
  111.         jz NOT_fill_XMS
  112.         shr ecx,2
  113.         mov edi,0
  114.         cld
  115.     rep stosd
  116. NOT_fill_XMS:
  117.         mov es,base_sel
  118.         mov ecx,0A000h
  119.         sub cx,Base_segment
  120.         shl ecx,2
  121.         mov edi,0
  122.         cld
  123. ;    rep stosd
  124.  
  125.         dec cunt
  126.         jnz tsm3
  127.  
  128.         open 1,'example2.exe'
  129.         jnc opok
  130.         writeln ' error openning file '
  131.         jmp exit
  132. opok:
  133.         writeln ' reading file '
  134.         blockread 1,0B800h,00,1300
  135.         close 1
  136.  
  137.     mov    word ptr [real_DS],CODE32
  138. dorr:
  139. skipo:
  140.  
  141.     sti
  142.         mov    ax,psp_segment        ; Resize memory block
  143.     mov    word ptr [real_ES],ax
  144.         mov    bx,base_segment
  145.         sub    bx,ax
  146.         mov    ah,4ah
  147.     dosint    21h
  148.     jc exit
  149.  
  150.         mov dx,offset welcom_mesg
  151.         mov ah,9
  152.     dosint 21h
  153.  
  154.         mov    es,PSP_sel
  155.  
  156.         mov    ax,es:[2Ch]        
  157.         mov    word ptr parmBlock,ax       ; set environment segment
  158.         mov    bx,psp_segment
  159.  
  160.         mov    word ptr parmBlock+2,80h    ; set command line
  161.         mov    word ptr parmBlock+4,bx
  162.  
  163.  
  164.         mov    word ptr parmBlock+6,5Ch    ; Set FCB 1
  165.         mov    word ptr parmBlock+8,bx
  166.         mov    word ptr parmBlock+0Ah,6Ch    ; Set FCB 2
  167.         mov    word ptr parmBlock+0Ch,bx
  168.  
  169.         mov    [real_ES],CODE32
  170.         mov    bx,offset parmBlock    ; ES:BX > parameter block
  171.         mov    ah,4bh
  172.         mov    al,0
  173.        mov    dx,offset file_name
  174.     dosint    21h
  175.  
  176.  
  177.         mov    [real_DS],CODE32
  178.  
  179.         mov    ah,9
  180.     mov    dx,offset envir_mesg
  181.         dosint    21h
  182.         ;---- print environment -----
  183.         mov    gs,ENVIRONMENT_sel
  184.         xor    edi,edi
  185.     mov    ah,2
  186.  
  187.  
  188. print_env:
  189.         mov    dl,gs:[edi]
  190.         inc    edi
  191.         cmp    dl,0
  192.         jnz @er5
  193.     mov dl,10
  194.         dosint    21h
  195.     mov dl,13
  196.         dosint    21h
  197. @er5:
  198.         dosint    21h
  199.         cmp    edi,100h
  200.         jb print_env
  201.  
  202.     mov dl,13
  203.         dosint    21h
  204.     mov dl,10
  205.         dosint    21h
  206.  
  207.  
  208.  
  209.         mov dx,offset exit_mesg
  210.         mov ah,9
  211.  
  212.         dosint 21h
  213. exit:
  214.  
  215.  
  216.     mov ah,4ch        ; Termiate the program
  217.         int 21h
  218. envir_mesg db 10,10,10,10,13,'                     PROGRAM  ENVIRONMENT  ',10,13,10,10,36
  219.  
  220. ; The 16 hardware inetrrupts.
  221. ; If an IRQ accours in V86 mode the segment registers will contain same
  222. ; selector values as they were before the last V86 call. ( i.e dosint xx ).
  223. IRQ0:
  224.     push ds
  225.         mov    ds,cs:[flat_data_sel]
  226.         inc    word ptr ds:[0b8000h]
  227.     dosint 08h                      ;  8253  Timer 0
  228.         pop ds
  229.     iretd
  230. IRQ1:    dosint 09h            ;  8242 Keyboard
  231.     iretd
  232. IRQ2:    dosint 0Ah                      ; LPT 2 or  Vert Retrate (6845)
  233.     iretd
  234. IRQ3:    dosint 0Bh            ; Serial communications ports 2 & 4
  235.     iretd
  236. IRQ4:    dosint 0Ch            ; Serial communications ports 1 & 3
  237.     iretd
  238. IRQ5:    dosint 0Dh            ; Reserved
  239.     iretd
  240. IRQ6:    dosint 0Eh            ; NEC µPD765 Floppy Disk Controler
  241.     iretd
  242. IRQ7:    dosint 0Fh                      ; LPT 1
  243.     iretd
  244. IRQ8:    dosint 70h            ; 6818 CMOS CLOCK
  245.     iretd
  246. IRQ9:    dosint 71h            ; Reserved
  247.     iretd
  248. IRQ10:    dosint 72h            ; Reserved
  249.     iretd
  250. IRQ11:    dosint 73h            ; Reserved
  251.     iretd
  252. IRQ12:    dosint 74h            ; Reserved
  253.     iretd
  254. IRQ13:    dosint 75h            ; 80x87 Math Co-Pro exception.
  255.     iretd
  256. IRQ14:    dosint 76h            ; Hard Drive Cotroller.
  257.     iretd
  258. IRQ15:    dosint 77h            ; Reserved
  259.     iretd
  260. align 4
  261. db 100h dup (?)
  262. pmode_stack:
  263.  
  264.  
  265. CODE32 ENDS
  266.  
  267. END