; Copyright (C) Reston Publishing Company 1983 ; ; TRUE, FALSE, and CPU definitions ; FALSE equ 0 TRUE equ NOT FALSE Z80CPU equ FALSE ; or TRUE, as the case may be ; ; Program entry macro: find bottom of Bdos and set the stack ; there. Call label Main with HL-->end of storage. Provide ; code to support the ABORT macro and the command tail. ; PROLOG MACRO ORG TransientArea ;; start at T.P.A. LHLD BdosAddress ;; HL --> Bdos base MVI L,255 INX H ;; HL --> page above BDOS DCR H ;; HL --> page below BDOS SPHL ;; SP --> high storage DCR H ;; Allow 256 byte stack DCX H ;; HL --> last usable byte CALL Main ;; call mainline code ; On normal exit, the main routine will return here... EPILOG: JMP WarmStart ;; do a warm start ; ; If a fatal error is detected the ABORT macro will come ; here, with the address of a "message$" string on top of ; the stack and all registers as they were. When debugging ; with DDT, set a breakpoint here to trap an abort. When ; using SID, set a pass-counter at label ERROREXIT. ; ERROREXIT: POP D ;; type the string on MVI C,BdosString ;; ..the console CALL Bdos LXI D,ErrorFCB ;; kill any active MVI C,BdosErase ;; ..submit file CALL Bdos JMP WarmStart ;; and terminate. ; ; Truncated FCB, used to delete $$$.SUB and so stop an ; active submit file when an ABORT is done. ; ErrorFCB db 1,'$$$ ','SUB',0,0,0,0 ; fill out FCB with copyright notice -- remove for your ; own programs... db 'COPYRIGHT(C)RESTON PUBLISHING CO 1983' ENDM ; ; Bdos-service macro: call Bdos for a service, saving all ; registers except A and sometimes HL. Load DE with the ; service parameter if one was specified. ; SERVICE MACRO ?S,?DE PUSH B PUSH D IF (?S NE 12) AND (?S NE 24) AND (?S NE 27) AND (?S NE 29) AND (?S NE 31) PUSH H ENDIF IF NOT NUL ?DE LXI D,?DE ENDIF MVI C,?S CALL Bdos IF (?S NE 12) AND (?S NE 24) AND (?S NE 27) AND (?S NE 29) AND (?S NE 31) POP H ENDIF POP D POP B ENDM ; ; Abort-the-program-with-a-message macro. The operand ; is the address of a message in storage. ; ; The macro puts the address of the message on the ; stack, preserving all registers for use in debugging. It ; branches to the ERROREXIT assembled by PROLOG, where the ; message will be printed. ; ABORT MACRO ?MSG PUSH H LXI H,?MSG XTHL JMP ERROREXIT ENDM ; ; Macro to make it easy to origin the assembler to the next ; page boundary. ; ORGPAGE MACRO ORG ($+255) AND 0FF00H ENDM ; ; Macro to test the console and, if a key has been hit, to ; jump to a named location. No registers are changed, so ; the macro can be inserted anywhere in the code. ; TESTCON MACRO WHERE local skippit local endtest push h push d push b push psw mvi c,BdosTestCon call Bdos ;; test the console lxi h,endtest ;; assume no key hit ora a ;; was one? jz skippit ;; jump if not lxi h,WHERE ;; yes, prepare to exit skippit pop psw ;; restore A, flags, pop b ;; regs BC, pop d ;; ..and DE xthl ;; restore H, stack address ret ;; go to 'endtest' or WHERE endtest equ $ endm ; ; The following macros assemble Z80 relative-jump instructions ; when Z80CPU is true, and ordinary 8080 jumps when not. ; DJNZ MACRO TARGET if Z80CPU db 10h,TARGET-$-1 else dcr b jnz TARGET endif endm JMPR MACRO TARGET if Z80CPU db 18h,TARGET-$-1 else jmp TARGET endif endm JRC MACRO TARGET if Z80CPU db 38h,TARGET-$-1 else jc TARGET endif endm JRNC MACRO TARGET if Z80CPU db 30h,TARGET-$-1 else jnc TARGET endif endm JRZ MACRO TARGET if Z80CPU db 28h,TARGET-$-1 else jz TARGET endif endm JRNZ MACRO TARGET if Z80CPU db 20h,TARGET-$-1 else jnz TARGET endif endm else jz TARGET endif endm JRNZ MACRO TARGET if Z80CPU db 20h,TARGET-$-1 else jnz TARGET endi