home *** CD-ROM | disk | FTP | other *** search
/ Oakland CPM Archive / oakcpm.iso / sigm / vol135 / test2.mqc / TEST2.MAC
Encoding:
Text File  |  1985-02-10  |  2.4 KB  |  115 lines

  1.     .z80
  2. cr    equ    13
  3. lf    equ    10
  4. display macro    addr
  5.     ld    de,addr
  6.     call    disp$
  7.     endm
  8.  
  9.     dseg
  10. $memry::
  11.     defs    2
  12. where?::
  13.     jp    ntry
  14. csp::    defw    0
  15.     cseg
  16. hexode::
  17.     push    de
  18.     ld    a,d
  19.     call    hexprn
  20.     pop    de
  21.     ld    a,e
  22. ;    call    hexprn
  23. ;    ret
  24.  
  25. ;------------------------------------------------------------------------------
  26. ;
  27. ;                H E X P R N
  28. ;                ===========
  29. ;
  30. ;    Sends contents of A register to the console as 2 hex bytes.
  31. ;
  32. ;------------------------------------------------------------------------------
  33.  
  34. hexprn::
  35.     push    af
  36.     rept    4
  37.     rrc    a
  38.     endm
  39.     call    outchr
  40.     pop    af
  41. outchr:    and    0fh        ;;Mask 4 bits
  42.     add    a,90h        ;;Add offset
  43.     daa            ;;Decimal adjust
  44.     adc    a,40h        ;;Add offset
  45.     daa            ;;Decimal adjust
  46.     ld    e,a        ;;To E for output
  47.     ld    c,2        ;;Conout
  48.     jp    5        ;;Call BDOS (he'll RETurn for us)
  49.  
  50. disp$:    ld    c,9
  51.     jp    5
  52.  
  53.     dseg
  54. intro:
  55.     defb    cr,lf,lf
  56.     defb    "This program looks at its own starting address"
  57.     defb    " to see if it has been relocated.",cr,lf,lf
  58. ttpa:    defb    "The TPA ends at $"
  59. tlong:    defb    "h long",cr,lf
  60.     defb    "This program starts at $"
  61. rmsg:    defb    "h and is $"
  62. rnot:    defb    "not $"
  63. rrest:    defb    "self-relocating",cr,lf,lf,"$"
  64. cmsg:    defb    "It appears to have been called from $"
  65. cmtail:    defb    "h with SP=$"
  66. sptail: defb    "h",cr,lf,"$"
  67. wbexit: defb    lf,lf,"Ending with warm boot$"
  68. retexit:defb    lf,lf,"Returning to CCP",cr,lf,"$"
  69.     cseg
  70. ntry:
  71.     ld    (csp),sp    ;Save caller's stack pointer
  72.  
  73.     display    intro        ;Signon message
  74.     ld    hl,(6)        ;Get BDOS entry point
  75.     ex    de,hl        ;Put into DE for hex display
  76.     push    de        ;Save a copy for length
  77.     call    hexode
  78.     display    rmsg        ;Display " and is "
  79.     pop    de        ;Recover BDOS address
  80.     dec    d        ;Calculate length
  81.     call    hexode        ;Display TPA length
  82.     display    tlong        ;More message
  83.     ld    de,where?    ;Program start address
  84.     push    de        ;Save a copy
  85.     call    hexode        ;Display it
  86.     display    rmsg
  87.     pop    de        ;Recover program start address
  88.     ld    hl,180h        ;Where programs normally start + a bit
  89.     or    a        ;Clear carry
  90.     sbc    hl,de        ;Check if we are above 100h
  91.     jr    c,above
  92.     display    rnot
  93. above:
  94.     display rrest
  95.     display    cmsg
  96.     ld    ix,(csp)
  97.     ld    e,(ix+0)
  98.     ld    d,(ix+1)
  99.     call    hexode
  100.     display    cmtail
  101.     ld    de,(csp)
  102.     call    hexode
  103.     display    sptail
  104.     ld    a,(6)        ;Check to see if BDOS jump has been modified
  105.     cp    6        ;Unmodified BDOS entry point is XXX6h
  106.     jr    z,retccp
  107.     display wbexit
  108.     jp    0
  109. retccp:
  110.     display retexit
  111.     ld    sp,(csp)    ;Just in case I couldn't count!
  112.     ret
  113.  
  114.     end    ntry
  115.