;* $Revision Header built automatically *************** (do not edit) ************
;*
;* © Copyright by (none)
;*
;* File             : AskBool.asm
;* Created on       : Monday, 21.02.94 21:23:51
;* Created by       : Arnold Schommer
;* Current revision : V1.1
;*
;*
;* Purpose
;* -------
;*   - Opens an EasyRequest and returns the boolean result via
;*     returncode.
;*
;* Revision V1.1
;* --------------
;* created on Friday, 01.04.94 11:19:05  by  Arnold Schommer.   LogMessage :
;*   - Changed to return not into a variable but by returncode.
;*
;* Revision V1.0
;* --------------
;* created on Monday, 21.02.94 21:23:51  by  Arnold Schommer.   LogMessage :
;*     --- Initial release ---
;*
;*********************************************************************************
REVISION  MACRO
          dc.b "1.1"
          ENDM
REVDATE   MACRO
          dc.b "01.04.94"
          ENDM
REVTIME   MACRO
          dc.b "11:19:05"
          ENDM
AUTHOR    MACRO
          dc.b "Arnold Schommer"
          ENDM
VERNUM    EQU  1
REVNUM    EQU  1
NAME      MACRO
          dc.b "AskBool"
          ENDM
****************************************************************************
TEMPLATE: macro
        dc.b    "TITLE/K,QUESTION/A,YES/K,NO/K",0
        endm
****************************************************************************
        NOLIST
        INCLUDE "exec/LVO.i"
        INCLUDE "exec/libraries.i"
        INCLUDE "dos/LVO.i"
        INCLUDE "dos/dos.i"
        INCLUDE "dos/dosextens.i"
        INCLUDE "dos/rdargs.i"
        INCLUDE "dos/var.i"
        INCLUDE "intuition/LVO.i"
        INCLUDE "intuition/intuition.i"

DOS:    MACRO
        move.l  _DosBase(a4),a6
        CALL    \1
        ENDM
INT:    MACRO
        move.l  _IntuitionBase(a4),a6
        CALL    \1
        ENDM
        LIST
****************************************************************************
;Rahmen-Programm, welches die Libraries öffnet und eine ordnungsgemäße
;Rückkehr gewährleistet:

        CODE
; eigene Variablen auf dem Stack anlegen
; (es sind nur etwa 1K, also durchaus akzeptabel)
        lea     -SIZE_data(sp),sp
        move.l  sp,a4
        move.l  sp,FrameSP(a4)
        moveq   #0,d0
        move.l  d0,_DosBase(a4)
        move.l  d0,_IntuitionBase(a4)
        move.l  d0,RetCode(a4)
        move.l  d0,readargs(a4)
        sub.l   a1,a1           ;a1=0->eigener Task
        CALLEXEC FindTask       ;Wo darf man denn nachschauen ?
        move.l  d0,a3
        tst.l   pr_CLI(a3)      ;von CLI oder WB aus gestartet ?
        bne     fromCLI
;von WB aus: ist nicht vorgesehen (keine Parameterübergabe), also Abbruch
        lea     pr_MsgPort(a3),a0
        CALL    WaitPort        ;auf Start-Message warten
        lea     pr_MsgPort(a3),a0
        CALL    GetMsg
        move.l  d0,-(sp)        ;Startup-Message sichern
;Message zur WB zurück
        CALL    Forbid
        move.l  (sp)+,a1
        CALL    ReplyMsg
        lea     SIZE_data(a4),sp
        moveq   #RETURN_FAIL,d0
        rts
;Libraries öffnen:
fromCLI: OPENLIB DosName(pc)
        move.l  d0,_DosBase(a4)
        bne     1$
;Fehler: KEINE dos.library !?!
        moveq   #RETURN_FAIL,d0
        bra     _exit
1$:     move.l  d0,a0
        cmp.w   #37,LIB_VERSION(a0)
        bge     2$
;Fehler: alte Dos-Library
        move.l  d0,a6
        CALL    Output
        move.l  d0,d1
        lea     error_olddos(pc),a0
        move.l  a0,d2
        moveq   #SIZE_error_olddos,d3
        CALL    Write
        moveq   #RETURN_ERROR,d0
        bra     _exit
2$:     OPENLIB IntName(pc),36
        move.l  d0,_IntuitionBase(a4)
        bne     4$
;Fehler: keine Intuition-Library
        lea     error_noint(pc),a0
        bra     _error
;Das Hauptprogramm aufrufen:
4$:     bsr     main
_exit:  move.l  d0,RetCode(a4)
        move.l  FrameSP(a4),sp
;Freigabe der RDArgs-Struktur
        move.l  readargs(a4),d1
        beq     1$
        DOS     FreeArgs
;die Libraries schließen
1$:     move.l  _IntuitionBase(a4),d0
        beq     CloseDos
        CLOSELIB d0
CloseDos: move.l _DosBase(a4),d0
        beq     ende
        CLOSELIB d0
;und wieder zurück
ende:   move.l  RetCode(a4),d0
        lea     SIZE_data(a4),sp
        rts
****************************************************************************
;Versions-String
        dc.b    "$VER: "
        NAME
        dc.b    " "
        REVISION
        dc.b    " ("
        REVDATE
        dc.b    ")",0
        even
****************************************************************************
;Fehler-Ausstieg:
_error: move.l  a0,-(sp)
        move.l  sp,d2
        lea     error_any(pc),a0
        move.l  a0,d1
        DOS     VPrintf
        moveq   #RETURN_ERROR,d0
        bra     _exit
****************************************************************************
;Argumenten-Array löschen
main:   moveq   #0,d0
        moveq   #NARGS-1,d1
        lea     rargs(a4),a0
1$:     move.l  d0,(a0)+
        dbra    d1,1$
; Presets für "Yes"- und "No"-Gadget:
        lea     txt_yes(pc),a0
        move.l  a0,ARG_YES(a4)
        lea     txt_no(pc),a0
        move.l  a0,ARG_NO(a4)
;Parsen lassen
        lea     Template(pc),a0
        move.l  a0,d1
        move.l  #rargs,d2
        add.l   a4,d2
        moveq   #0,d3
        DOS     ReadArgs
        move.l  d0,readargs(a4)
        bne     2$
;Fehler-Ausstieg, weil ReadArgs fehlschlug
        DOS     IoErr
        move.l  d0,d1
        moveq   #0,d2
        move.l  #String,d3
        add.l   a4,d3
        move.l  #256,d4
        CALL    Fault
        lea     String(a4),a0
        bra     _error
;EasyStruct initialisieren:
2$:     moveq   #es_SIZEOF,d0
        move.l  d0,es_StructSize+easyreq(a4)
        moveq   #0,d0
        move.l  d0,es_Flags+easyreq(a4)
        move.l  ARG_TITLE(a4),es_Title+easyreq(a4)
        move.l  ARG_QUESTION(a4),es_TextFormat+easyreq(a4)
        lea     String(a4),a1
        move.l  a1,es_GadgetFormat+easyreq(a4)
;Gadget-Texte zusammensetzen:
;        lea     String(a4),a1
        move.l  ARG_YES(a4),a0
4$:     move.b  (a0)+,(a1)+
        bne     4$
        move.b  #'|',-1(a1)             ;u.a. 0 überschreiben
        move.l  ARG_NO(a4),a0
5$:     move.b  (a0)+,(a1)+
        bne     5$

;EasyRequest aufrufen:
        sub.l   a0,a0           ;kein Window
        lea     easyreq(a4),a1  ;EasyStruct
        move.l  a0,a2           ;keine IDCMP-Flags
        move.l  a0,a3           ;keine Argumente
        INT     EasyRequestArgs

;Rückgabewert ermitteln
        tst.l   d0
        beq     6$
        moveq   #RETURN_WARN,d0
6$:     rts
****************************************************************************
IntName: INTNAME
DosName: DOSNAME

;verschiedene Fehler-Texte:
error_olddos:
        NAME
        dc.b ": dos.library v37+ required",10
SIZE_error_olddos: equ *-error_olddos
error_any:
        NAME
        dc.b ": %s",10,0
error_noint:    dc.b "intuition.library v36+ required",0

txt_yes: dc.b "Yes",0
txt_no: dc.b "No",0

Template:       TEMPLATE
****************************************************************************
;Definition der eigenen Variablen:

FrameSP:        equ 0
RetCode:        equ FrameSP+4
_IntuitionBase: equ RetCode+4
_DosBase:       equ _IntuitionBase+4
readargs:       equ _DosBase+4
rargs:          equ readargs+4
ARG_TITLE:      equ rargs
ARG_QUESTION:   equ ARG_TITLE+4
ARG_YES:        equ ARG_QUESTION+4
ARG_NO:         equ ARG_YES+4
easyreq:        equ ARG_NO+4
NARGS:          equ (easyreq-rargs)/4
String:         equ easyreq+es_SIZEOF
SIZE_data:      equ String+256

        END
