home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / jsage / znode3 / z3util / jltools.lbr / TESTRSX.AZM / TESTRSX.ASM
Encoding:
Assembly Source File  |  1993-06-07  |  5.6 KB  |  254 lines

  1. title    testrsx.asm    (c) 1988 Bridger Mitchell
  2. ;
  3. name    RSX240        ;"RSX" required
  4.  
  5. .xlist
  6.  
  7. ; This rsx just prints an identifying message when called:
  8. ;
  9. ;    ld    c,240        ;0F0h
  10. ;    call    5
  11. ;
  12.  
  13. OURCODE    equ    240        ;0F0h
  14. ;
  15. ;
  16. ; *---------- Plu*Perfect Systems RSX Extended Header----------------*
  17. ;/                                      \
  18. ;
  19. ; The rsx code goes in the CSEG (code segment).
  20. ;
  21. CSEG
  22. ;
  23. rsx:    jp    rsxstart                    ;  00
  24.     jp    rsxwb                        ; +03
  25.     jp    rsxremove                    ; +06
  26. rsxwba:    dw    $-$                        ; +09
  27. rsxprot:dw    rsx                        ; +0B
  28.     dw    rsxname                        ; +0D
  29. rsxnext:jp    $-$        ; -> next wb or ccp entry    ; +0F    
  30. ;
  31. next:    jp    $-$        ; -> next rsx or bdos        ; +12
  32. nextwb:    dw    $-$                        ; +15
  33. ;\                                     /
  34. ; *-----------------------------------------------------------------*
  35. ;
  36. rsxname:
  37.     db    'TESTRSX',0    ; nul-terminated name of rsx. 
  38. ;
  39. ;
  40. ; The BDOS intercept
  41. ;
  42. rsxstart:
  43.     ld    a,c
  44.     cp    OURCODE        ; if not our function 
  45.     jr    nz,next        ; .. pass on to next rsx or bdos
  46.     ld    de,ourmsg    ; do our thing.    
  47.     ld    c,9
  48.     call    next        ; by calling the bdos via the rsx chain
  49.     ret
  50. ;
  51. custom_remove:
  52.     ret
  53. ;
  54. ; Just to illustrate the use of the data segment,
  55. ; let's put the message string there.  It will be loaded
  56. ; immediately above the code segment.
  57. ;
  58. DSEG
  59. ;
  60. ourmsg:    db    0dh,0ah,'TESTRSX is active.$'
  61. ;
  62. CSEG
  63. ;
  64. ;
  65. ; *----------------  Standard RSX Code  -----------------------------*
  66. ;/                                      \
  67. ;
  68. ; The warm-boot intercept.
  69. ;
  70. rsxwb:                .new
  71.     call    fix0001        ; ensure correct page 0
  72.     ld    hl,(bios+4)    ; does bios wb addr
  73.     ld    de,rsx+3    ; point at us?
  74.     or    a
  75.     sbc    hl,de
  76.     jr    nz,1$        ; no, we're not the bottom rsx
  77.     ld    hl,(rsxprot)    ; we are, set our protect address
  78.     ld    (0006),hl
  79. 1$:    ld    bc,(0004h)    ; get c = logged du for ccp
  80.     jp    rsxnext        ; in case we're top rsx
  81. ;
  82. ;
  83. ; The removal routine.
  84. ;
  85. rsxremove:
  86.     call    custom_remove    ; do extra restoration for this rsx
  87. ;
  88.     ld    hl,(nextwb)    ; get saved original warmboot addr
  89.         ld    (bios+4),hl    ; and restore it to bios jmp vector
  90. ;
  91. ; When the caller terminates to a warmboot,
  92. ; the next module (or bios, if none), will correct 0006.
  93. ;
  94. ; Set CY flag to inform removal tool that this routine
  95. ; has taken action. (Some RSX's are not self-removing).
  96. ;
  97. fix0001:ld    hl,(rsxwba)    ; restore (0001) in case an errant
  98.     ld    (0001h),hl    ; application has tampered with it 
  99.     scf            ; set CY to signal success
  100.     ret
  101. ;
  102. ;
  103. ; Before loading an RSX, JetLDR will first check for protected memory.
  104. ; If it detects memory protected by a non-RSX header (e.g. a debugger)
  105. ; it will cancel the load.  Otherwise, JetLDR will call any
  106. ; code in the _INIT_ named common, after the rsx module has been
  107. ; loaded and relocated.  This code will be located in non-protected
  108. ; memory, and takes no space in the RSX.
  109. ;
  110. ; Return parameter: A = 0 indicates a good installation
  111. ;            A = ABORT = 0FFh = not installed
  112. ;
  113. common    /_INIT_/
  114. ;
  115. ; Install the rsx.  This code is standard for all rsx's,
  116. ; except for:
  117. ;    custom_init
  118. ;    custom_twin
  119. ;
  120. init:    ld    hl,(0006)    ; hl = possible rsx, or bdos
  121.     ld    c,0        ; initialize count of rsx's
  122. ;
  123. initlp:    push    hl        ; stack (possible) rsx base address
  124.     ld    de,09         ; if candidate is an rsx
  125.     add    hl,de        ; ..the wbaddr will be here
  126.     ld    e,(hl)        ; get address
  127.     inc    hl
  128.     ld    d,(hl)
  129.     ld    hl,(0001)    ; and compare
  130.     or    a
  131.     sbc    hl,de
  132.     pop    hl
  133.     jr    nz,inittop    ; warmboot addr not there, stop looking
  134. ;
  135. ; we have an rsx in memory, is it our twin?
  136. ;
  137.     inc    c        ; count an rsx found
  138.     push    hl
  139.     call    ckname
  140.     pop    hl
  141.     jr    z,twin
  142. ;
  143.     ld    de,0Fh+1    ; that rsx was't a twin, check for more
  144.     add    hl,de        ; get addr of next rsx's wboot jmp
  145.     ld    a,(hl)
  146.     inc    hl
  147.     ld    h,(hl)
  148.     ld    l,a
  149.     dec    hl        ; back up to head of that next rsx
  150.     dec    hl
  151.     dec    hl
  152.     jr    initlp        ; now check that rsx
  153. ;
  154. ; we're at the top of the (possibly empty) rsx chain 
  155. ;
  156. inittop:
  157.     inc    c        ; any rsx's found?
  158.     dec    c
  159.     ld    hl,ccp+3    ; prepare to use ccp entry address
  160.     jr    z,setnext    ; ..no
  161. ;
  162.     ld    hl,(0006)    ; yes, use bottom rsx's address
  163. ;
  164. setnext:
  165.     ld    (rsxnext+1),hl    ; save the next addr
  166.                 ; in the rsx chain to bdos/ccp
  167. ;
  168. ; install the rsx into the running system
  169. ;
  170.     ld    hl,(bios+4)    ; save the bios's wb addr
  171.     ld    (nextwb),hl    ; in the header
  172.  
  173.     ld    hl,rsx+3    ; point the bios wb jump
  174.     ld    (bios+4),hl    ; at the rsx wb vector
  175.  
  176.     ld    hl,bios+3    ; store wb addr
  177.     ld    (rsx+09),hl    ; in rsx header word
  178.  
  179.     ld    hl,(0006)    ; get addr of next rsx or bdos
  180.     ld    (next+1),hl    ; and install it
  181.  
  182.     ld    hl,rsx        ; finally, protect the rsx
  183.     ld    (0006),hl
  184. ;
  185.     call    custom_init    ; take care of extras 
  186.     ret
  187. ;
  188. ckname:    ld    de,0dh        ; offset to candidate rsx name pointer
  189.     add    hl,de
  190.     ld    a,(hl)        ; get address
  191.     inc    hl
  192.     ld    h,(hl)
  193.     ld    l,a
  194.     ld    de,rsxname    ; compare to our name
  195. ckname1:ld    a,(de)
  196.     cp    (hl)
  197.     ret    nz
  198.     inc    (hl)        ; candidate must be nul-terminated
  199.     dec    (hl)
  200.     jr    nz,ckname2
  201.     or    a        ; ..at our same byte
  202.     ret
  203. ckname2:inc    hl
  204.     inc    de
  205.     jr    ckname1
  206.     
  207. ;
  208. ; Handle the case of a previously-loaded copy of this RSX.
  209. ;
  210. twin:    call    custom_twin
  211.     ret
  212. ;\                                     /
  213. ; *-----------------------------------------------------------------*
  214. ;
  215. ; Custom initialization code goes here.
  216. ;
  217. ;
  218. ; Do the particular patches for this RSX.
  219. ; Note: this code is in the _INIT_ segment.
  220.  
  221. custom_init:
  222. custom_twin:
  223.     ret
  224.  
  225.  
  226. ; Include identification info in the REL image.
  227. ; JetLDR will display the bytes up to the first NUL byte
  228. ; when the RSX is loaded.
  229. ;
  230. ;
  231. common    /_ID_/
  232. ;
  233.     db    'Very simple test RSX:'
  234.     db    13,10,'Print message on bdos function 240'
  235.     db    0
  236.  
  237. ; Include whatever other named-commons are needed for this RSX.
  238. ; JetLDR will resolve these labels for us.
  239. ;
  240. common    /_BIOS_/
  241. bios    equ    $
  242.     
  243. common    /_CCP_/
  244. ccp    equ    $
  245.  
  246.  
  247.     end    ;testrsx.asm
  248.  
  249.  
  250. sxname    ; compare to our name
  251. ckname1:ld    a,(de)
  252.     cp    (hl)
  253.     ret    nz
  254.     inc    (hl)        ; candidate must be nul-ter