home *** CD-ROM | disk | FTP | other *** search
/ ftp.barnyard.co.uk / 2015.02.ftp.barnyard.co.uk.tar / ftp.barnyard.co.uk / cpm / walnut-creek-CDROM / JSAGE / ZSUS / PROGPACK / JLTOOLS.LBR / OKDRIVES.AZM / OKDRIVES.ASM
Assembly Source File  |  2000-06-30  |  8KB  |  316 lines

  1. title    okdrives.asm 6/25/88    (c) 1988 Bridger Mitchell
  2. ;
  3. ;
  4. ; This rsx sets the vector of valid drives allowed by the bios.
  5. ; If called with de == 0, it returns the current valid-drives vector.
  6. ;
  7. ; usage to set valid drives:
  8. ;
  9. ;    ld    c,DRIVEFN
  10. ;    ld    de,<vector>    ; bit 0 = A:, ..., bit 15 = P:
  11. ;    call    5
  12. ;
  13. ; usage to determine currently-valid drives:
  14. ;
  15. ;    ld    c,DRIVEFN
  16. ;    ld    de,0000
  17. ;    call    5
  18. ;
  19. ;
  20. ; We need an extended bdos function number.
  21. ;
  22. DRIVEFN    equ    241    ; 0F1h
  23. ABORT    equ    0ffh
  24. ;
  25. ;
  26. ; Name the REL image with "RSX" plus 0-3 characters of identification.
  27. ; In this case, we've used the rsx's bdos function number (241).
  28.  
  29. name    RSX241        ;"RSX" required
  30.  
  31. ;
  32. ; All of the code within the bracketed regions is the same for any rsx
  33. ; loaded by JetLDR.  It can be copied intact when creating a different rsx.
  34.  
  35. ;
  36. ; *---------- Plu*Perfect Systems RSX Extended Header----------------*
  37. ;/                                      \
  38. ;
  39. ; The rsx code goes in the CSEG (code segment).
  40. ;
  41. CSEG
  42.  
  43. rsx:    jp    rsxstart                    ;  00
  44.     jp    rsxwb                        ; +03
  45.     jp    rsxremove                    ; +06
  46. rsxwba:    dw    $-$                        ; +09
  47. rsxprot:dw    rsx                        ; +0B
  48.     dw    rsxname                        ; +0D
  49. rsxnext:jp    $-$        ; -> next wb or ccp entry    ; +0F    
  50. ;
  51. next:    jp    $-$        ; -> next rsx or bdos        ; +12
  52. nextwb:    dw    $-$                        ; +15
  53. ;\                                     /
  54. ; *-----------------------------------------------------------------*
  55. ;
  56. ;
  57. ; The custom code for this rsx begins here.
  58. ;
  59. ;
  60. rsxname:db    'OKDRIVES',0      ; nul-terminated name of rsx.
  61. ;
  62. vector:    dw    1111111111111111b ;  <-- set bits for valid drives
  63. ;               PONMLKJIHGFEDCBA  ;  <-- must be terminated by 'B' char.
  64. ;
  65. ;
  66. ; This RSX's bdos function.
  67. ;
  68. ; enter: c  =  DRIVEFN
  69. ;     de == 0 to get current ok-drives vector
  70. ;        de != 0 to set the current vector to de
  71. ; return:
  72. ;     hl = vector of ok drives
  73. ;
  74. rsxstart:
  75.     ld    a,c
  76.     cp    DRIVEFN        ; if not our function
  77.     jr    nz,next        ; .. on to the next rsx/bdos
  78.     ld    a,e        ; set vector?
  79.     or    d
  80.     jr    nz,set        ; ..yes
  81. get:    ld    hl,(vector)    ; no, return the drive vector in hl
  82.     ld    a,l        ; return a != 0
  83.     ret
  84. ;
  85. set:    ex    de,hl
  86.     set    0,l        ; ensure drive A: always valid
  87.     ld    (vector),hl    ; save the new drive vector
  88.     ld    a,l        ; and return it in hl
  89.     ret
  90.  
  91. ;
  92. ; The bios seldsk intercept
  93. ;
  94. ; enter: c = requested drive
  95. ; exit:  hl == 0 if drive not allowed
  96. ;     else continue to bios seldsk
  97. ;
  98. rsxseldsk:
  99.     ld    hl,(vector)    ; shift ok-drives vector left
  100.     ld    a,16
  101.     sub    c
  102. rsxs1:    add    hl,hl
  103.     dec    a
  104.     jr    nz,rsxs1
  105.     ld    hl,0000        ; prime error return
  106.     ret    nc        ; NC if bit wasn't set
  107. jseldsk:jp    $-$        ; jmp to bios seldsk routine
  108. ;
  109. ;
  110. ; Restore this rsx's particular patches.
  111. ;
  112. custom_remove:
  113.     ld    hl,(jseldsk+1)    ; restore bseldsk address
  114.     ld    (bios+1ch),hl    ; to bios jmp vector
  115.     ret
  116.  
  117. ;
  118. ; *----------------  Standard RSX Code  -----------------------------*
  119. ;/                                      \
  120. ;
  121. ; The warm-boot intercept.
  122. ;
  123. rsxwb:                .new
  124.     call    fix0001        ; ensure correct page 0
  125.     ld    hl,(bios+4)    ; does bios wb addr
  126.     ld    de,rsx+3    ; point at us?
  127.     or    a
  128.     sbc    hl,de
  129.     jr    nz,rsxwb1    ; no, we're not the bottom rsx
  130.     ld    hl,(rsxprot)    ; we are, set our protect address
  131.     ld    (0006),hl
  132. rsxwb1:    ld    bc,(0004h)    ; get c = logged du for ccp
  133.     jp    rsxnext        ; in case we're top rsx
  134. ;
  135. ;
  136. ; The removal routine.
  137. ;
  138. rsxremove:
  139.     call    custom_remove    ; do extra restoration for this rsx
  140. ;
  141.     ld    hl,(nextwb)    ; get saved original warmboot addr
  142.         ld    (bios+4),hl    ; and restore it to bios jmp vector
  143. ;
  144. ; When the caller terminates to a warmboot,
  145. ; the next module (or bios, if none), will correct 0006.
  146. ;
  147. ; Set CY flag to inform the removal tool that this routine
  148. ; has indeed taken action. (Some RSX's are not self-removing).
  149. ;
  150. fix0001:ld    hl,(rsxwba)    ; restore (0001) in case an errant
  151.     ld    (0001h),hl    ; application has tampered with it 
  152.     scf            ; set CY to signal success
  153.     ret
  154. ;
  155. ;
  156. ; Before loading an RSX, JetLDR will first check for protected memory.
  157. ; If it detects that memory is protected by a non-RSX header (e.g. a debugger)
  158. ; it will cancel the load.  Otherwise, JetLDR will call any
  159. ; code in the _INIT_ named common, after the rsx module has been
  160. ; loaded and relocated.  This code will be located in non-protected
  161. ; memory, and takes no space in the RSX.
  162. ;
  163. ; Return parameter: A = 0 indicates a good installation
  164. ;            A = ABORT = 0FFh = not installed
  165. ;
  166. common    /_INIT_/
  167. ;
  168. ; Install the rsx.  This code is standard for all rsx's,
  169. ; except for:
  170. ;    custom_init
  171. ;    custom_twin
  172. ;
  173. init:    ld    hl,(0006)    ; hl = possible rsx, or bdos
  174.     ld    c,0        ; initialize count of rsx's
  175. ;
  176. initlp:    push    hl        ; stack (possible) rsx base address
  177.     ld    de,09         ; if candidate is an rsx
  178.     add    hl,de        ; ..the wbaddr will be here
  179.     ld    e,(hl)        ; get address
  180.     inc    hl
  181.     ld    d,(hl)
  182.     ld    hl,(0001)    ; and compare
  183.     or    a
  184.     sbc    hl,de
  185.     pop    hl
  186.     jr    nz,inittop    ; warmboot addr not there, stop looking
  187. ;
  188. ; we have an rsx in memory, is it our twin?
  189. ;
  190.     inc    c        ; count an rsx found
  191.     push    hl
  192.     call    ckname
  193.     pop    hl
  194.     jr    z,twin
  195. ;
  196.     ld    de,0Fh+1    ; that rsx was't a twin, check for more
  197.     add    hl,de        ; get addr of next rsx's wboot jmp
  198.     ld    a,(hl)
  199.     inc    hl
  200.     ld    h,(hl)
  201.     ld    l,a
  202.     dec    hl        ; back up to head of that next rsx
  203.     dec    hl
  204.     dec    hl
  205.     jr    initlp        ; now check that rsx
  206. ;
  207. ; we're at the top of the (possibly empty) rsx chain 
  208. ;
  209. inittop:
  210.     inc    c        ; any rsx's found?
  211.     dec    c
  212.     ld    hl,ccp+3    ; prepare to use ccp entry address
  213.     jr    z,setnext    ; ..no
  214. ;
  215.     ld    hl,(0006)    ; yes, use bottom rsx's address
  216. ;
  217. setnext:
  218.     ld    (rsxnext+1),hl    ; save the next addr
  219.                 ; in the rsx chain to bdos/ccp
  220. ;
  221. ; install the rsx into the running system
  222. ;
  223.     ld    hl,(bios+4)    ; save the bios's wb addr
  224.     ld    (nextwb),hl    ; in the header
  225.  
  226.     ld    hl,rsx+3    ; point the bios wb jump
  227.     ld    (bios+4),hl    ; at the rsx wb vector
  228.  
  229.     ld    hl,bios+3    ; store wb addr
  230.     ld    (rsx+09),hl    ; in rsx header word
  231.  
  232.     ld    hl,(0006)    ; get addr of next rsx or bdos
  233.     ld    (next+1),hl    ; and install it
  234.  
  235.     ld    hl,rsx        ; finally, protect the rsx
  236.     ld    (0006),hl
  237. ;
  238.     call    custom_init    ; take care of extras 
  239.     ret
  240. ;
  241. ckname:    ld    de,0dh        ; offset to candidate rsx name pointer
  242.     add    hl,de
  243.     ld    a,(hl)        ; get address
  244.     inc    hl
  245.     ld    h,(hl)
  246.     ld    l,a
  247.     ld    de,rsxname    ; compare to our name
  248. ckname1:ld    a,(de)
  249.     cp    (hl)
  250.     ret    nz
  251.     inc    (hl)        ; candidate must be nul-terminated
  252.     dec    (hl)
  253.     jr    nz,ckname2
  254.     or    a        ; ..at our same byte
  255.     ret
  256. ckname2:inc    hl
  257.     inc    de
  258.     jr    ckname1
  259.     
  260. ;
  261. ; Handle the case of a previously-loaded copy of this RSX.
  262. ;
  263. twin:    call    custom_twin
  264.     ret
  265. ;\                                     /
  266. ; *-----------------------------------------------------------------*
  267. ;
  268. ; Custom initialization code goes here.
  269. ;
  270. ;
  271. ; Do the particular patches for this RSX.
  272. ; Note: this code is in the _INIT_ segment.
  273.  
  274. custom_init:
  275.     ld    hl,(bios+1ch)    ; get bseldsk address
  276.     ld    (jseldsk+1),hl    ; install it in rsx
  277. ;
  278.     ld    hl,rsxseldsk    ; divert bios jump
  279.     ld    (bios+1ch),hl    ; to the rsx
  280.     ret
  281. ;
  282. ; This particular rsx should not be duplicated.
  283. ; A different rsx might wish to query the user here,
  284. ; print a warning, or whatever.
  285. ;
  286. custom_twin:
  287.     ld    a,ABORT
  288.     ret
  289. ;
  290.  
  291. ; Include identification info in the REL image.
  292. ; JetLDR will display the bytes up to the first NUL byte
  293. ; when the RSX is loaded.
  294. ;
  295. ;
  296. common    /_ID_/
  297. ;
  298.     db    'OKDRIVES: RSX prevents bios logins'
  299.     db    13,10
  300.     db    'Use BDOS function 241 (0F1h) to set de = drive vector',0
  301.  
  302. ;
  303. ; Include whatever other named-commons are needed for this RSX.
  304. ; JetLDR will resolve these labels for us.
  305. ;
  306. common    /_BIOS_/
  307. bios    equ    $
  308.     
  309. common    /_CCP_/
  310. ccp    equ    $
  311.  
  312.  
  313.     end    ;okdrives.asm
  314.  
  315.  
  316. rσPTCH1  ASM tσB      SUB vÇ