
;*========================================================================
;*
;* AESFAST Public Domain GEM bindings.
;*	Maintenance:
;*	 02/11/89 v1.1: This source file is new with this version.
;*
;*	 04/07/89 v1.2:
;*			  The calculation of the location of the prompt on the
;*			  screen has been changed.	It was placed one boxchar height
;*			  down on the screen, putting it right below the menu bar.
;*			  This didn't look too good on a big-monitor system, so now
;*			  it is calculated by centering the box, then subtracting a
;*			  fixed offset from the centered Y to make it appear right
;*			  above the fsel'er box.  The offset is 9 character heights,
;*			  (plus 2 extra char heights for the prompt itself), less
;*			  2 pixels (just to line everything up real neat).
;*
;*	 07/22/89 v1.3:
;*			  Bugfix...A 'bra.s' instruction was missing just before the
;*			  'strcpy' routine, causing 4 bombs on a pre-1.4 machine.
;*
;*	 03/13/93 v1.9:
;*			  As a part of the conversion to JAS asm code, this module
;*			  was split out as a separate item.  It is called from
;*			  AESFSEL2.S and AESFSEL3.S.
;*========================================================================

;*************************************************************************
;* Fsel Simulation stuff...
;*	The following is the object tree that displays the prompt on
;*	pre-TOS 1.4 systems, and the code to display that box.
;*************************************************************************

;-------------------------------------------------------------------------
; Define the offsets within the AES block storage area.
;-------------------------------------------------------------------------

aespb	  = 		0					; 'aespb' MUST be first!...
pcontrl   = 		0					;	Pointer to control array
pglobal   = 		4					;	Pointer to global array
pintin	  = 		8					;	Pointer to intin array
pintout   = 	   12					;	Pointer to intout array
padrin	  = 	   16					;	Pointer to adrin array
padrout   = 	   20					;	Pointer to adrout array

control   = 	   24					; Control array is next...
function  = 	   24					;	Function code
sintin	  = 	   26					;	size of intin
sintout   = 	   28					;	size of intout
sadrin	  = 	   30					;	size of adrin
sadrout   = 	   32					;	size of adrout

global	  = 	   34					; Global array, needs no further def.

;-------------------------------------------------------------------------
; Define the TEDINFO and OBJECT structures for the prompt text.
;-------------------------------------------------------------------------

		  data

YSZ_PROMPT	=		2
YSZ_FSEL	=		9
Y_OFFSET	=		YSZ_PROMPT+YSZ_FSEL

prmptext:			;Teddef   0,0,0,3,0,TE_CNTR,$1180,0,1,31,0
		  dc.l		0,0,0
		  dc.w		3,0,2,$1180,0,1,31,0

prmptree:			;Objdef   ,-1,-1,-1,G_BOXTEXT,LASTOB,NORMAL,0,0,0,40,YSZ_PROMPT
		  dc.w		-1,-1,-1			; ob_head,next,tail
		  dc.w		22					; ob_type  = G_BOXTEXT
		  dc.w		$20 				; ob_flags = LASTOB
		  dc.w		0					; ob_state = NORMAL
		  dc.l		prmptext			; ob_spec  = &prmptext
		  dc.w		0,0,40,YSZ_PROMPT	; ob_xywh

;-------------------------------------------------------------------------
; Define variables.
;-------------------------------------------------------------------------

treeptr:  dc.l		prmptree   ; Ptr to tree: addrin for objc_draw() et. al.

dialstuf: dc.w		3		   ; Here things get a little ugly: The storage
azero:	  dc.w		0,0 	   ; from 'dialstuff' down is the intin array
prmpstob: dc.w		0		   ; for form_dial(FMD_FINISH).  From prmpstob
prmpdpth: dc.w		8		   ; down, it is also the intin array for
prmpclip: dc.w		0,0,0,0    ; objc_draw().

prmpflag: dc.w		0		   ; Flag: Has one-time object fixup been done?

		  text

;-------------------------------------------------------------------------
; This routine lets us call AES more quickly than going through the
; routines in AESCOMN (and is better tailored to our needs here).
;-------------------------------------------------------------------------

aes_icall:

		  movep.l	d0,control+1(a4)		 ; fill in the control array (!),
		  move.l	a0,padrin(a4)			 ; store the adrin ptr into aespb
		  move.l	a1,pintin(a4)			 ; store the intin ptr into aespb
		  move.l	a2,pintout(a4)			 ; store it into aespb
		  move.l	a4,d1					 ; move the aespb pointer to the
		  move.w	#$C8,d0 				 ; interface register, also the AES
		  trap		#2						 ; function code, call AES, return
		  rts								 ; to the calling binding routine.

;-------------------------------------------------------------------------
; FselSimu - Simulate an exinput call on pre-TOS 1.4 systems.
;
;  On entry to this routine, a6 has been set up for accessing the
;  parameters of the call to fsel_exinput, and also for addressing
;  4 bytes of stack for temp vars as negative offsets from a6.	On
;  exit, intout[] at -4(a6) holds the return values from the fsel_input.
;-------------------------------------------------------------------------

		  globl 	FselSimu

FselSimu:

		  movem.l	d2/a2-a5,-(sp)			 ; Save registers.

		  lea		aesblock,a4 			 ; Load aesblock base register.
		  lea		treeptr,a5				 ; we use this a lot.
		  move.l	(a5),a3 				 ; load pointer to tree.

		  tas		prmpflag				 ; Has first-time object tree fixup
		  bne.b 	do_simulation			 ; been done?  If so, continue below.

;-------------------------------------------------------------------------
; Do the one-time object tree fixup:
;
;  - Plug in a couple of static integer values.
;  - Call rsrc_obfix  for resolution-specific x/y/w/h fixup.
;  - Call form_center to center box in the x coord & calc the clip area.
;  - Call graf_handle to get the height of a boxchar, and use this height
;	 to calc the ob_y of the prompt box (and the clip area).
;-------------------------------------------------------------------------

		  subq.l	#2,sp					 ; allocate intout[1]
		  move.l	sp,a2					 ; a2 -> intout
		  lea		azero,a1				 ; a1 -> intin
		  move.l	a5,a0					 ; a0 -> adrin
		  move.l	#$72010101,d0			 ; rsrc_obfix() ; AControl 114,1,1,1
		  bsr		aes_icall				 ; do it.
		  addq.l	#2,sp					 ; we don't care about intout[0].

		  sub.w 	#10,sp					 ; Allocate intout[5]
		  move.l	sp,a2					 ; a2 -> intout
		  move.l	a5,a0					 ; a0 -> addrin (prmptree)
		  move.l	#$36000501,d0			 ; form_center() ; AControl  54,0,5,1
		  bsr		aes_icall				 ; do it.
		  addq.l	#2,sp					 ; We don't care about intout[0],
		  move.l	(sp)+,prmpclip			 ; the rest of intout is the
		  move.l	(sp)+,prmpclip+4		 ; clip rectangle, save it.

		  sub.w 	#10,sp					 ; Allocate intout[5], make a2 point
		  move.l	sp,a2					 ; to it.  Do graf_handle(&stack).
		  move.l	#$4D000500,d0			 ; graf_handle()  ; AControl  77,0,5,0
		  bsr		aes_icall				 ; We want the height of a char
		  addq.l	#4,sp					 ; which is in intout[2], put that
		  move.w	(sp)+,d0				 ; in d0, throw everything else away.
		  addq.l	#4,sp					 ; Calc the placement of the prompt
		  mulu		#Y_OFFSET,d0			 ; box as Y_OFFSET characters up from
		  subq.w	#2,d0					 ; the current (centered) location,
		  sub.w 	d0,18(a3)				 ; set the ob_y value in the tree
		  sub.w 	d0,prmpclip+2			 ; and clip rectange to this value.

;-------------------------------------------------------------------------
; Once the one-time stuff is done (and on all subsequent calls...) do
; the actual simulation of the TOS 1.4 exinput:
;
;  - Plug the prompt string pointer into the TEDINFO.
;  - The prompt string is placed in a box above the fsel dialog box on the
;	 screen (but below the menu bar) before the system fsel'er is called.
;	 The prompt is displayed inside a box, (it's a BOXTEXT object, which
;	 is the entire tree).  The prompt is displayed with an objc_draw, and
;	 removed by sending a redraw message (via form_dial).
;  - Call fsel_input() (the old one).
;  - Call form_dial() to send a redraw message to clear the prompt box.
;  - Return to caller.
;-------------------------------------------------------------------------

do_simulation:

;		  .cargs	#8,pinpath.l,pinsel.l,pbutton.l,plabel.l

pinpath   = 		8
pinsel	  = 		12
pbutton   = 		16
plabel	  = 		20

		  move.l	plabel(a6),prmptext 	 ; Set prompt text pointer.

		  subq.l	#2,sp					 ; allocate intout[1]
		  move.l	sp,a2					 ; a2 -> intout
		  lea		prmpstob,a1 			 ; a1 -> intin
		  move.l	a5,a0					 ; a0 -> addrin
		  move.l	#$2A060101,d0			 ; objc_draw(prmptree,...) ; AControl  42,6,1,1
		  bsr		aes_icall				 ; do it.
		  addq.l	#2,sp					 ; throw away intout[0].

		  lea		-4(a6),a2				 ; a2 -> intout
		  lea		pinpath(a6),a0			 ; a0 -> addrin
		  move.l	#$5A000202,d0			 ; fsel_input() ; AControl	90,0,2,2
		  bsr		aes_icall				 ; do it.

		  subq.l	#2,sp					 ; allocate intout[1] for form_dial
		  move.l	sp,a2					 ; a2 -> intout
		  lea		dialstuf,a1 			 ; a1 -> intin
		  move.l	#$33090100,d0			 ; form_dial(FMD_FINISH,...); AControl	51,9,1,0
		  bsr		aes_icall				 ; this sends a redraw message to
		  addq.l	#2,sp					 ; clean up our prompt text box.

		  movem.l	(sp)+,d2/a2-a5			 ; Restore working regs.
		  rts

;		  end of code

