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 / CPM / ZCPR33 / S-Z / TYPE3HDR.Z80 < prev    next >
Text File  |  2000-06-30  |  1KB  |  42 lines

  1. ; This is header code that can be used at the beginning of a type-3-environment
  2. ; program so that it will abort with an error message when not loaded to the
  3. ; correct address (such as when a user tries to run it under CP/M or Z30).
  4.  
  5. entry:
  6.     jr    start0        ; Must use relative jump
  7.     defb    0        ; Filler
  8.     db    'Z3ENV',3    ; Type-3 environment
  9. z3env:    dw    0        ; Filled in by Z33
  10.     dw    entry        ; Intended load address
  11.  
  12. start0:
  13.     ld    hl,0        ; Point to warmboot entry
  14.     ld    a,(hl)        ; Save the byte there
  15.     ld    (hl),0c9h    ; Replace it with a return opcode
  16.     rst    0        ; Call address 0, pushing RETADDR onto stack
  17. retaddr:
  18.     ld    (hl),a        ; Restore byte at 0
  19.     dec    sp        ; Fake a push (leaving stack as it was)
  20.     dec    sp
  21.     pop    hl        ; HL now has actual address of RETADDR
  22.     ld    de,retaddr    ; This is where we should be
  23.     xor    a        ; Clear carry flag
  24.     push    hl        ; Save address again
  25.     sbc    hl,de        ; Subtract -- we should have 0 now
  26.     pop    hl        ; Restore value of RETADDR
  27.     jr    z,start        ; If addresses matched, begin real code
  28.  
  29.     ld    de,notz33msg-retaddr ; Offset to message
  30.     add    hl,de
  31.     ex    de,hl        ; Switch pointer to message into DE
  32.     ld    c,9
  33.     jp    0005h        ; Return via BDOS print string function
  34.  
  35. notz33msg:
  36.     defb    'Not Z33+$'    ; Abort message if not Z33-compatible
  37.  
  38. start:
  39.     ret            ; Replace with real code
  40.  
  41.     end
  42.