home *** CD-ROM | disk | FTP | other *** search
/ The Unsorted BBS Collection / thegreatunsorted.tar / thegreatunsorted / programming / misc_programming / example2.asm < prev    next >
Assembly Source File  |  1993-10-03  |  5KB  |  229 lines

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