Browse Source

* improved formatting and added comments to the win16 startup code

git-svn-id: trunk@31528 -
nickysn 10 years ago
parent
commit
8bca76e645
1 changed files with 70 additions and 27 deletions
  1. 70 27
      rtl/win16/prt0comn.asm

+ 70 - 27
rtl/win16/prt0comn.asm

@@ -22,45 +22,88 @@
         %fatal "Memory model not defined."
 %endif
 
-        cpu 8086
-        segment _TEXT use16 class=CODE align=1
+                cpu 8086
+                segment _TEXT use16 class=CODE align=1
 
-        extern PASCALMAIN
+                extern PASCALMAIN
 
-        extern InitTask
-        extern WaitEvent
-        extern InitApp
+                extern InitTask
+                extern WaitEvent
+                extern InitApp
 
-..start:
-        call far InitTask
-        test ax, ax
-        jz error
+..start:        ; Win16 applications start with the following
+                ; values in registers:
+                ;
+                ; AX = zero
+                ; BX = the size, in bytes, of the stack
+                ; CX = the size, in bytes, of the heap
+                ; DI = handle, identifying the new application instance
+                ; SI = handle, identifying the previous application instance
+                ; BP = zero
+                ; ES = segment of the Program Segment Prefix (PSP)
+                ; DS = segment of the automatic data segment for the application
+                ; SS = DS
+                ; SP = offset of the first byte of the application stack
 
-        mov [hInst], di
+                ; call InitTask to initialize the task. Windows expects this to
+                ; be the first function, called by the application code. On entry,
+                ; it expects all the startup parameters in registers described above.
+                call far InitTask
+                ; InitTask result:
+                ; AX = 1-success; 0-error
+                test ax, ax
+                jz error
+                ; InitTask result:
+                ; CX = stack limit, in bytes
+                ; DI = instance handle for the new task
+                ; DX = the nCmdShow parameter
+                ; ES = segment of the Program Segment Prefix (PSP) for the new task
+                ; ES:BX = the command line
+                ; SI = instance handle for the previous application instance (if any)
 
-        xor ax, ax
-        push ax
-        call far WaitEvent
-        push word [hInst]
-        call far InitApp
-        test ax, ax
-        jz error
+                mov [hInst], di
+
+                ; call WaitEvent(0) to clear the event that started this task
+                ; Windows expects this call immediately after InitTask
+                xor ax, ax
+                push ax
+                call far WaitEvent
+
+                ; call InitApp(hInst) to initialize the queue and support routines
+                ; for the app. Windows expects this to be the third call in the
+                ; Win16 startup sequence.
+                push word [hInst]
+                call far InitApp
+                test ax, ax
+                jz error
 
 %ifdef __FAR_CODE__
-        jmp far PASCALMAIN
+                jmp far PASCALMAIN
 %else
-        jmp PASCALMAIN
+                jmp PASCALMAIN
 %endif
 
 error:
-        mov ax, 4cffh
-        int 21h
+                mov ax, 4cffh
+                int 21h
+
+
+                segment _DATA use16 class=DATA align=2
+                ; the first 16 bytes of the automatic data segment are reserved.
+                ; they are filled by the InitTask function with these values
+                dw 0
+oOldSP:         dw 0
+hOldSS:         dw 5
+pLocalHeap:     dw 0
+pAtomTable:     dw 0
+pStackTop:      dw 0
+pStackMin:      dw 0
+pStackBot:      dw 0
+                ; end of reserved area, filled by InitTask
 
 
-        segment _DATA use16 class=DATA align=2
-        dw 0,0,5,0,0,0,0,0
-hInst:  dw 0
+hInst:          dw 0
 
-        segment _STACK stack class=STACK align=16
+                segment _STACK stack class=STACK align=16
 
-        group DGROUP _DATA _STACK
+                group DGROUP _DATA _STACK