;******************************************************************
; Listing 1.  CP/M call-5, MS-DOS 5+ in conventional memory
;******************************************************************

        ; PSP offset 5

xxxx:0005 9AF0FE1DF0 call  F01D:FEF0   ; HMA FFFF:D0 or IVT 0000:C0
F01D:FEF0 EAD340xxxx jmp   xxxx:40D3   ; CP/M handler in DOS kernel

        ; -- BDOS call handler --

xxxx:40D3 1E         push  ds          ; ** CP/M jmp entry point
xxxx:40D4 2E8E1EE73D mov   ds,cs:[3DE7]; get DOS DS and
xxxx:40D9 8F06EC05   pop   [05EC]      ; save caller DS (DSA+2CCh)

xxxx:40DD 58         pop   ax          ; discard IP pushed by call 5
xxxx:40DE 58         pop   ax          ; get CS of call-5 caller
xxxx:40DF 8F068405   pop   [0584]      ; and the IP pushed by call 5
xxxx:40E3 9C         pushf             ; push the current flags and
xxxx:40E4 FA         cli               ; keep faking an INT call by
xxxx:40E5 50         push  ax          ; pushing CS and then the IP
xxxx:40E6 FF368405   push  [0584]      ; to iret to (mucks DSA+264h)

xxxx:40EA FF36EC05   push  [05EC]      ; get back caller's DS
xxxx:40EE 1F         pop   ds          ; and reload it
xxxx:40EF 80F924     cmp   cl,24       ; valid BDOS fxn call in CL?
xxxx:40F2 77DC       ja    40D0        ; >DOS 2+ limit, return AL=0
xxxx:40F4 8AE1       mov   ah,cl       ; else mimic INT-21 call and
xxxx:40F6 EB06       jmp   40FE        ; enter dispatch handler+6
                                       ; (why not jmp 411B directly?)
        ; -- INT-21h DOS handler --
        ; See Schulman 1994, p. 286

xxxx:40F8 FA         cli               ; ** INT-21h entry point
xxxx:40F9 80FC6C     cmp   ah,6C       ; ext open/create fxn?
xxxx:40FC 77D2       ja    40D0        ; >DOS 6.2 limit, return AL=0

        ; CP/M compatibility entry point

xxxx:40FE 80FC33     cmp   ah,33       ; 33xx family?
xxxx:4101 7218       jb    411B        ; no: use handler below
xxxx:4103 74A2       je    40A7        ; short jump to jump cs:4052

xxxx:4105 80FC64     cmp   ah,64       ; (undoc) DOS 3.2+ internal?
xxxx:4108 7711       ja    411B        ; no: 65xx family and above
xxxx:410A 74B5       je    40C1        ; else set dev lookahead flag

xxxx:410C 80FC51     cmp   ah,51       ; get PSP address fxn?
xxxx:410F 74A4       je    40B5        ; yes: pass to 51/62h-handler
xxxx:4111 80FC62     cmp   ah,62       ; get PSP address (undoc)?
xxxx:4114 749F       je    40B5        ; yes: go there too
xxxx:4116 80FC50     cmp   ah,50       ; set PSP address fxn?
xxxx:4119 748E       je    40A9        ; yes: pass to 50h-handler

xxxx:411B 06         push  es          ; -- 33h > fxns > 64h handler
xxxx:411C 1E         push  ds          ; except for 50h, 51h, & 62h
xxxx:411D 55         push  bp          ; i.e., 'non-reentrant' fxns
                     ...
