home *** CD-ROM | disk | FTP | other *** search
/ Oakland CPM Archive / oakcpm.iso / cpm / zcpr33 / type3hdr.bug < prev    next >
Encoding:
Text File  |  1987-09-26  |  1.8 KB  |  57 lines

  1. ; TYPE3HDR will eventually fail if your system is interrupt driven.
  2. ; If an interrupt occurs after the RET planted at 0000H is executed
  3. ; and before the two  DEC   SP  operations are executed the address
  4. ; that you find on the stack will be that pushed by the interrupt.
  5. ; It may close but that only counts in horseshoes. And the ZCPR33
  6. ; program running on your ZCPR33 system will mysteriously exit.
  7. ; The fix is to include a DI and an EI as shown below.
  8. ;   9-25-87   C. S. Irvine
  9.  
  10. ; This is header code that can be used at the beginning of a type-3-environment
  11. ; program so that it will abort with an error message when not loaded to the
  12. ; correct address (such as when a user tries to run it under CP/M or Z30).
  13.  
  14. entry:
  15.     jr    start0        ; Must use relative jump
  16.     defb    0        ; Filler
  17.     db    'Z3ENV',3    ; Type-3 environment
  18. z3env:    dw    0        ; Filled in by Z33
  19.     dw    entry        ; Intended load address
  20.  
  21. start0:
  22.     ld    hl,0        ; Point to warmboot entry
  23.     ld    a,(hl)        ; Save the byte there
  24.     ld    (hl),0c9h    ; Replace it with a return opcode
  25.  
  26.     di        ; PROTECT THE RETURN ADDRESS   CSI
  27.  
  28.     rst    0        ; Call address 0, pushing RETADDR onto stack
  29. retaddr:
  30.     ld    (hl),a        ; Restore byte at 0
  31.     dec    sp        ; Fake a push (leaving stack as it was)
  32.     dec    sp
  33.  
  34.     ei        ; NOW THAT WE HAVE RESET THE SP ALLOW INTERRUPTS   CSI
  35.  
  36.     pop    hl        ; HL now has actual address of RETADDR
  37.     ld    de,retaddr    ; This is where we should be
  38.     xor    a        ; Clear carry flag
  39.     push    hl        ; Save address again
  40.     sbc    hl,de        ; Subtract -- we should have 0 now
  41.     pop    hl        ; Restore value of RETADDR
  42.     jr    z,start        ; If addresses matched, begin real code
  43.  
  44.     ld    de,notz33msg-retaddr ; Offset to message
  45.     add    hl,de
  46.     ex    de,hl        ; Switch pointer to message into DE
  47.     ld    c,9
  48.     jp    0005h        ; Return via BDOS print string function
  49.  
  50. notz33msg:
  51.     defb    'Not Z33+$'    ; Abort message if not Z33-compatible
  52.  
  53. start:
  54.     ret            ; Replace with real code
  55.  
  56.     end
  57.