;************************************************************************
;* ä-soft GEM-lib							*
;* ½1989/90 ä-soft, written by Markus Fritze	       18.01.1990 13:27 *
;************************************************************************
;************************************************************************
;* global vars: 							*
;************************************************************************
_StackSize	EQU 1024	;1k stack for the program

;************************************************************************
;* init of the library (GEMDOS & AES)					*
;************************************************************************
_gem_init:	movea.l 4(SP),A6	;get basepageadr
		movea.w #$0100+_StackSize,A5 ;size of basepage + stacksize
		adda.l	12(A6),A5	;+ size of TEXT-segment
		adda.l	20(A6),A5	;+ size of DATA-segment
		adda.l	28(A6),A5	;+ size of BSS-segment
		move.l	A5,D1		;= size of the program
		and.b	#$FE,D1 	;EVEN
		add.l	A6,D1		;+ basepageadr
		movea.l D1,SP		;top of the stackarea
		move.l	A5,-(SP)	;prgsize
		move.l	A6,-(SP)	;basepageadr
		move.l	A6,basepage	;save it
		move.l	#$4A0000,-(SP)	;
		trap	#1		;Mshrink(0,basepageadr,prgsize)
		lea	12(SP),SP

		move.l	#appl_init,D0
		bsr	_aes
		move.w	D0,ap_id
		moveq	#-1,D7		;-1: appl_init() error
		addq.w	#1,D0
		beq	_pterm		;no ID for the program => exit

		move.l	#graf_handle,D0
		bsr	_aes		;get vdi-handle
		move.w	D0,vdi_handle
		movem.w int_out+2(PC),D1-D4
		movem.w D1-D4,gr_hwchar

		lea	int_in(PC),A0
		movea.l A0,A1
		moveq	#10,D0
_gem_init2:	move.w	#1,(A0)+	;1,1,1,1,1,1,1,1,1,1,2
		dbra	D0,_gem_init2
		addq.w	#1,-(A0)
		move.l	#v_opnvwk,D0
		bsr	_vdi		;open workstation
		moveq	#-39,D7 	;-39: no memory for the VDI-workstation
		move.w	12+control(PC),vdi_handle
		beq	_do_pterm	;=> exit

;************************************************************************
;* the main part starts here						*
;* D0: the exit-code of the program					*
;************************************************************************


;************************************************************************
;* program exit 							*
;************************************************************************
_gem_exit:	move.w	D0,D7		;save exit-status

		moveq	#v_clsvwk,D0
		bsr	_vdi		;close workstation

_do_pterm:	move.l	#appl_exit,D0
		bsr	_aes		;close applikation

_pterm: 	move.w	D7,-(SP)	;exit-status
		move.w	#$4C,-(SP)
		trap	#1		;Pterm(exit-status)

;************************************************************************
;* my own AES-call							*
;* D0=the first 4 entries of the control-array (4 bytes!)		*
;*    bit 24-31 = functioncode						*
;*    bit 16-23 = entries in int_in					*
;*    bit 8-15	= entries in int_out					*
;*    bit 0-7	= entries in addr_in					*
;************************************************************************
_aes:		movem.l D1-A6,-(SP)	;save all regs
		lea	control(PC),A0
		clr.l	(A0)+
		clr.l	(A0)+		;clear control-array
		clr.w	(A0)
		movep.l D0,-7(A0)	;insert the new datas
		cmpi.b	#112,-7(A0)	;rsrc_gaddr()-Call?
		bne.s	_aes1		;no! =>
		move.b	#1,1(A0)	;entries in addr_out=1
_aes1:		lea	_aes_pb(PC),A0
		move.l	A0,D1
		move.w	#200,D0
		trap	#2		;call the AES
		moveq	#0,D0
		move.w	int_out(PC),D0	;int_out[0]
		movem.l (SP)+,D1-A6	;restore all regs
		rts

_aes_pb:	DC.L control	;the AES-parameterblock
		DC.L global
		DC.L int_in
		DC.L int_out
		DC.L addr_in
		DC.L addr_out

;************************************************************************
;* my own VDI-Call							*
;* D0 = the input-parameter						*
;*	Bit 24-31 = functioncode					*
;*	Bit 16-23 = size of the intin-array				*
;*	Bit 8-15  = ID of the sub-opcode				*
;*	Bit 0-7   = size of ptsin					*
;* the workstation is "gr_handle"					*
;************************************************************************
_vdi:		movem.l D1-A6,-(SP)
		lea	control+2(PC),A0
		clr.w	(A0)+		;clear all parameter
		clr.l	(A0)+
		clr.w	(A0)
		move.l	D0,-(SP)
		tst.b	(SP)		;no opcode? => short format
		addq.l	#4,SP
		bne.s	_vdi1
		move.b	D0,1-8(A0)	;opcode in bit 0-7
		bra.s	_vdi2		;thats all =>
_vdi1:		move.b	D0,3-8(A0)	;size of the ptsin-array
		lsr.w	#8,D0
		move.w	D0,10-8(A0)	;the sub-opcode
		swap	D0
		move.b	D0,7-8(A0)	;size of the intin-array
		lsr.w	#8,D0
		move.w	D0,0-8(A0)	;the opcode
_vdi2:		move.w	vdi_handle(PC),12-8(A0) ;VDI-handle
		lea	_vdi_pb(PC),A0
		move.l	A0,D1
		moveq	#$73,D0
		trap	#2
		moveq	#0,D0
		move.w	int_out(PC),D0	;int_out[0]
		movem.l (SP)+,D1-A6
		rts

_vdi_pb:	DC.L control	;the VDI-parameterblock
		DC.L int_in
		DC.L ptsin
		DC.L int_out
		DC.L ptsout

;************************************************************************
;* the BSS-area 							*
;************************************************************************
		BSS
basepage:	DS.L 1		;basepageadr
control:	DS.W 16
global: 	DS.W 15 	;AES-Arrays
addr_in:	DS.L 3
addr_out:	DS.L 1
int_in: 	DS.W 128
int_out:	DS.W 128	;VDI-Arrays
ptsin:		DS.W 128
ptsout: 	DS.W 128
ap_id:		DS.W 1		;applikation-ID
vdi_handle:	DS.W 1		;VDI-handle
gr_hwchar:	DS.W 1		;graf_handle() parameter
gr_hhchar:	DS.W 1
gr_hwbox:	DS.W 1
gr_hhbox:	DS.W 1

		>PART 'AES/VDI-Library-EQUs'
;************************************************************************
;* the AES-"library"							*
;************************************************************************
appl_init	EQU $0A000100
appl_read	EQU $0B020101
appl_write	EQU $0C020101
appl_find	EQU $0D000101
appl_tplay	EQU $0E020101
appl_trecord	EQU $0F010101
appl_bvset	EQU $10020100	;GEM 2.0
appl_yield	EQU $11000100	;GEM 2.0
appl_exit	EQU $13000100

evnt_keybd	EQU $14000100
evnt_button	EQU $15030500
evnt_mouse	EQU $16050500
evnt_mesag	EQU $17000101
evnt_timer	EQU $18020100
evnt_multi	EQU $19100701
evnt_dclick	EQU $1A020100

menu_bar	EQU $1E010101
menu_icheck	EQU $1F020101
menu_ienable	EQU $20020101
menu_tnormal	EQU $21020101
menu_text	EQU $22010102
menu_register	EQU $23010101
menu_unregister EQU $24010100	;GEM 2.0

objc_add	EQU $28020101
objc_delete	EQU $29010101
objc_draw	EQU $2A060101
objc_find	EQU $2B040101
objc_offset	EQU $2C010301
objc_order	EQU $2D020101
objc_edit	EQU $2E040201
objc_change	EQU $2F080101

form_do 	EQU $32010101
form_dial	EQU $33090100
form_alert	EQU $34010101
form_error	EQU $35010100
form_center	EQU $36000501
form_keybd	EQU $37030301
form_button	EQU $38020201

graf_rubberbox	EQU $46040300
graf_rubbox	EQU $46040300
graf_dragbox	EQU $47080300
graf_movebox	EQU $48060100
graf_mbox	EQU $48060100
graf_growbox	EQU $49080100
graf_shrinkbox	EQU $4A080100
graf_watchbox	EQU $4B040101
graf_slidebox	EQU $4C030101
graf_handle	EQU $4D000500
graf_mouse	EQU $4E010101
graf_mkstate	EQU $4F000500

srcp_read	EQU $50000101
srcp_write	EQU $51000101
scrp_clear	EQU $52000100	;GEM 2.0

fsel_input	EQU $5A000202
fsel_exinput	EQU $5B000203	;TOS 1.4

wind_create	EQU $64050100
wind_open	EQU $65050100
wind_close	EQU $66010100
wind_delete	EQU $67010100
wind_get	EQU $68020500
wind_set	EQU $69060100
wind_find	EQU $6A020100
wind_update	EQU $6B010100
wind_calc	EQU $6C060500
wind_new	EQU $6D000000	;TOS 1.4

rsrc_load	EQU $6E000101
rsrc_free	EQU $6F000100
rsrc_gaddr	EQU $70020100
rsrc_saddr	EQU $71020101
rsrc_obfix	EQU $72010101

shel_read	EQU $78000102
shel_write	EQU $79030102
shel_get	EQU $7A010101
shel_put	EQU $7B010101
shel_find	EQU $7C000101
shel_envrn	EQU $7D000102
shel_rdef	EQU $7E000102	;GEM 2.0
shel_wdef	EQU $7F000002	;GEM 2.0

xgrf_stepcalc	EQU $82060600	;GEM 2.0
xgrf_2box	EQU $83090100	;GEM 2.0

; Die Messages des AES
MN_SELECTED	EQU 10		;Meneintrag angew„hlt
WM_REDRAW	EQU 20		;Teil eines Windows muž neu gezeichnet werden
WM_TOPPED	EQU 21		;Window ist nun das aktuelle Fenster
WM_CLOSED	EQU 22		;Window soll geschlossen werden
WM_FULLED	EQU 23		;Window soll auf max.Gr”že gebracht werden
WM_ARROWED	EQU 24		;Scollbalken angeklickt
WM_HSLID	EQU 25		;Der horizontale Slider wurde bewegt
WM_VSLID	EQU 26		;Der vertikale Slider wurde bewegt
WM_SIZED	EQU 27		;Die Gr”že des Windows wurde ge„ndert
WM_MOVED	EQU 28		;Das Window wurde bewegt
WM_NEWTOP	EQU 29		;Das Fenster wurde aktiviert (siehe WM_TOPPED)
WM_UNTOPPED	EQU 30		;Der Fenster wird gleich inaktiv (erst ab GEM 2.0!)
AC_OPEN 	EQU 40		;Ein Acc wurde angeklickt.(30 bzw. 31 ist FALSCH!)
AC_CLOSE	EQU 41		;Prg wurde beendet, ACC soll seinen Speicher freigeben.
CT_UPDATE	EQU 50
CT_MOVE 	EQU 51		;Funktion unbekannt
CT_NEWTOP	EQU 52

; WM_ARROWED angeklickt (nun die genauere Definition)
WA_UPPAGE	EQU 0		;Balken oberhalb des Sliders
WA_DNPAGE	EQU 1		;Balken unterhalb des Sliders
WA_UPLINE	EQU 2		;Pfeil nach oben
WA_DNLINE	EQU 3		;Pfeil nach unten
WA_LFPAGE	EQU 4		;Balken links vom Slider
WA_RTPAGE	EQU 5		;Balken rechts vom Slider
WA_LFLINE	EQU 6		;Pfeil nach links
WA_RTLINE	EQU 7		;und Pfeil nach rechts

; Die Objekttypen des Resource-Baumes
G_BOX		EQU 20
G_TEXT		EQU 21
G_BOXTEXT	EQU 22
G_IMAGE 	EQU 23
G_PROGDEF	EQU 24
G_IBOX		EQU 25		;Bitte in entsprechender Literatur nachschlagen
G_BUTTON	EQU 26
G_BOXCHAR	EQU 27
G_STRING	EQU 28
G_FTEXT 	EQU 29
G_FBOXTEXT	EQU 30
G_ICON		EQU 31
G_TITLE 	EQU 32

; Object-Flags bei einem Objekt
NONE_FLG	EQU $00
SELECTABLE_FLG	EQU $01
DEFAULT_FLG	EQU $02
EXIT_FLG	EQU $04
EDITABLE_FLG	EQU $08
RBUTTON_FLG	EQU $10 	;Bitte ebenfalls in der Literatur nachlesen
LASTOB_FLG	EQU $20
TOUCHEXIT_FLG	EQU $40
HIDETREE_FLG	EQU $80
INDIRECT_FLG	EQU $0100

; Objekt-Status bei einem Objekt
NORMAL		EQU $00
SELECTED	EQU $01
CROSSED 	EQU $02
CHECKED 	EQU $04 	;s.o.
DISABLED	EQU $08
OUTLINED	EQU $10
SHADOWED	EQU $20

; Die einzelnen Bits bei evnt_multi()
MU_KEYBD	EQU $01 	;Tastaturereignis
MU_BUTTON	EQU $02 	;Maustastenereignis
MU_M1		EQU $04 	;1.Mausereignis
MU_M2		EQU $08 	;2.Mausereignis
MU_MESAG	EQU $10 	;Message des AES
MU_TIMER	EQU $20 	;Timer-Ereignis

; form_dial()
FMD_START	EQU $00 	;Bildschirmhintergrund reservieren
FMD_GROW	EQU $01 	;Ausdehnende Box zeichnen
FMD_SHRINK	EQU $02 	;Schrumpfende Box zeichnen
FMD_FINISH	EQU $03 	;Bildschirmbereich wieder freigeben

; graf_mouse()
ARROW		EQU $00
TEXT_CRSR	EQU $01
HOURGLASS	EQU $02
BUSYBEE 	EQU $02
POINT_HAND	EQU $03
FLAT_HAND	EQU $04
THIN_CROSS	EQU $05
THICK_CROSS	EQU $06
OUTL_CROSS	EQU $07
USER_DEF	EQU $FF
M_OFF		EQU $0100
M_ON		EQU $0101

; Parameter bei wind_create()
WI_NAME 	EQU $01
WI_CLOSE	EQU $02
WI_FULL 	EQU $04
WI_MOVE 	EQU $08
WI_INFO 	EQU $10
WI_SIZE 	EQU $20
WI_UPARROW	EQU $40
WI_DNARROW	EQU $80
WI_VSLIDE	EQU $0100
WI_LFARROW	EQU $0200
WI_RARROW	EQU $0400
WI_HSLIDE	EQU $0800

; Parameter bei wind_get() & wind_set()
WF_KIND 	EQU 1
WF_NAME 	EQU 2
WF_INFO 	EQU 3
WF_WORKXYWH	EQU 4
WF_CURRXYWH	EQU 5
WF_PREVXYWH	EQU 6
WF_FULLXYWH	EQU 7
WF_HSLIDE	EQU 8
WF_VSLIDE	EQU 9
WF_TOP		EQU 10
WF_FIRSTXYWH	EQU 11
WF_NEXTXYWH	EQU 12
WF_NEWDESK	EQU 14
WF_HSLSIZE	EQU 15
WF_VSLSIZE	EQU 16

; wind_update()
END_UPDATE	EQU 0
BEG_UPDATE	EQU 1
END_MCTRL	EQU 2
BEG_MCTRL	EQU 3

;************************************************************************
;* Die VDI-"Library"							*
;* Wer n„heres dazu wissen m”chte, sollte sich im Profibuch von Sybex	*
;* die Informationen dazu besorgen.					*
;************************************************************************
;1. Kontrollfunktionen
v_opnwk 	EQU $010B0000	;Open workstation
v_clswk 	EQU $02 	;Close workstation
v_opnvwk	EQU $640B0000	;Open virtual screen workstation
v_clsvwk	EQU $65 	;Close virtual screen workstation
v_clrwk 	EQU $03 	;Clear workstation
v_updwk 	EQU $04 	;Update workstation
vst_load_fonts	EQU $77010000	;Load fonts
unload_fonts	EQU $78010000	;Unload fonts
vs_clip 	EQU $81010002	;Set clipping rectangle
;2. Ausgabefunktionen
v_pline 	EQU $06000000	;Polyline (Byte 0=count(n))
v_pmarker	EQU $07000000	;Polymarker (Byte 0=count(n))
v_gtext 	EQU $08000001	;Text (Byte 2=n)
v_fillarea	EQU $09000000	;Filled area (Byte 0=count(n))
v_cellarray	EQU $0A000002	;Cell array (Byte 2=n)
v_contourfill	EQU $67010001	;Contour fill
vr_recfl	EQU $72000002	;Fill rectangle
v_bar		EQU $0B000102	;Bar
v_arc		EQU $0B020204	;Arc
v_pieslice	EQU $0B020304	;Pie
v_circle	EQU $0B000403	;Circle
v_ellipse	EQU $0B000502	;Ellipse
v_ellarc	EQU $0B020602	;Elliptical arc
v_ellpie	EQU $0B020702	;Elliptical pie
v_rbox		EQU $0B000802	;Rounded rectangle
v_rfbox 	EQU $0B000902	;Filled rounded rectangle
v_justified	EQU $0B020A02	;Justified graphics text (Byte 2=n+2)
;3. Attribut-Funktionen
vswr_mode	EQU $20010000	;Set writing mode
vs_color	EQU $0E040000	;Set color representation
vsl_type	EQU $0F010000	;Set polyline line type
vsl_udsty	EQU $71010000	;Set user-defined line style pattern
vsl_width	EQU $10000001	;Set polyline line width
vsl_color	EQU $11010000	;Set polyline color index
vsl_ends	EQU $6C020000	;Set polyline end styles
vsm_type	EQU $12010000	;Set polymarker type
vsm_height	EQU $13000001	;Set polymarker height
vsm_color	EQU $14010000	;Set polymarker color index
vst_height	EQU $0C000001	;Set character height, absolute mode
vst_point	EQU $6B010000	;Set character height, points mode
vst_rotation	EQU $0D010000	;Set character baseline vector
vst_font	EQU $15010000	;Set text face
vst_color	EQU $16010000	;Set graphic text color index
vst_effects	EQU $6A010000	;Set graphic text special effects
vst_alignment	EQU $27020000	;Set graphic text alignment
vsf_interior	EQU $17010000	;Set fill interior index
vsf_style	EQU $18010000	;Set fill style index
vsf_color	EQU $19010000	;Set fill color index
vsf_perimeter	EQU $68010000	;Set fill perimeter visibility
vsf_udpat	EQU $70000000	;Set user-defined fill pattern (Byte 2=16*planes)
;4. Rasteroperationen
vro_cpyfm	EQU $6D010004	;Copy raster, opaque
vrt_cpyfm	EQU $79030004	;Copy raster, transparent
vr_trnfm	EQU $6E000000	;Transform form
v_get_pixel	EQU $69000001	;Get pixel
;5. Eingabefunktionen
vsin_mode	EQU $21020000	;Set input mode
vrq_locator	EQU $1C000001	;Input locator, request mode
vsm_locator	EQU $1C000001	;Input locator, sample mode
vrq_valuator	EQU $1D010000	;Input valuator, request mode
vsm_valuator	EQU $1D010000	;Input valuator, sample mode
vrq_choice	EQU $1E010000	;Input choice, request mode
vsm_choice	EQU $1E010000	;Input choice, sample mode
vrq_string	EQU $1F020001	;Input string, request mode
vsm_string	EQU $1F020001	;Input string, sample mode
vsc_form	EQU $6F250000	;Set mouse form
vex_timv	EQU $76 	;Exchange timer interrupt vector
v_show_c	EQU $7A010000	;Show cursor
v_hide_c	EQU $7B 	;Hide cursor
vq_mouse	EQU $7C 	;Sample mouse button state
vex_butv	EQU $7D 	;Exchange button change vector
vex_motv	EQU $7E 	;Exchange mouse movement vector
vex_curv	EQU $7F 	;Exchange cursor change vector
vq_key_s	EQU $80000000	;Sample keyboard state information
;6. Auskunftsfunktionen
vq_extnd	EQU $66010000	;Extended inquire function
vq_color	EQU $1A020000	;Inquire color representation
vql_attributes	EQU $23 	;Inquire current polyline attributes
vqm_attributes	EQU $24 	;Inquire current polymarker attributes
vqf_attributes	EQU $25 	;Inquire current fill area attributes
vqt_attributes	EQU $26 	;Inquire current graphic text attributes
vqt_extent	EQU $74 	;Inquire text extent (Byte 2=n)
vqt_width	EQU $75010000	;Inquire character cell width
vqt_name	EQU $82010000	;Inquire face name and index
vq_cellarray	EQU $1B000002	;Inquire cell array
vqin_mode	EQU $73010000	;Inquire input mode
vqt_fontinfo	EQU $83000000	;Inquire current face information
vqt_justified	EQU $84020002	;Inquire just.graph.text (Byte 2=n+2) GEM 2.0!
;7. Escapes
vq_chcells	EQU $05000100	;Inquire addressable alpha character cells
v_exit_cur	EQU $05000200	;Exit alpha mode
v_enter_cur	EQU $05000300	;Enter alpha mode
v_curup 	EQU $05000400	;Alpha cursor up
v_curdown	EQU $05000500	;Alpha cursor down
v_curright	EQU $05000600	;Alpha cursor right
c_curleft	EQU $05000700	;Alpha cursor left
v_curhome	EQU $05000800	;Home alpha cursor
v_eeos		EQU $05000900	;Erase to end of alpha screen
v_eeol		EQU $05000A00	;Erase to end of alpha text line
v_curaddress	EQU $05020B00	;Direct alpha cursor address
v_curtext	EQU $05000C00	;Output cursor addressable alpha text (Byte 2=n)
v_rvon		EQU $05000D00	;Reverse video on
v_rvoff 	EQU $05000E00	;Reverse video off
vq_curaddress	EQU $05000F00	;Inquire current alpha cursor address
vq_tabstatus	EQU $05001000	;Inquire tablet status
v_hardcopy	EQU $05001100	;Hardcopy
v_dspcur	EQU $05001201	;Place graphic cursor at location
v_rmcur 	EQU $05001300	;Remove last graphic cursor
v_form_adv	EQU $05001400	;Form advance
v_output_window EQU $05001500	;Output window
v_clear_disp_list EQU $05001600 ;Clear display list
v_bit_image	EQU $05051702	;Output bit image file (Byte 2=n+5)
vq_scan 	EQU $05001800	;Inquire printer scan
v_alpha_text	EQU $05001900	;Output alpha text (Byte 2=n)
vs_palette	EQU $05013C00	;Select palette
v_sound 	EQU $05023D00	;Generate specified tone
vs_mute 	EQU $05013E00	;Set/clear tone muting flag
vt_resolution	EQU $05025100	;Set tablet axis resolution in lines/inch
vt_axis 	EQU $05025200	;Set table axis resolution in lines
vt_origin	EQU $05025300	;Set tablet x and y origin
vq_tdimensions	EQU $05005400	;Return tablet x and y dimensions
vt_alignment	EQU $05025500	;Set tablet alignment
vsp_film	EQU $05025B00	;Set camera file type and exposure time
vqp_filename	EQU $05015C00	;Inquire camera file name
vsc_expose	EQU $05015D00	;Disable or enable file exposure for frame preview
v_meta_extents	EQU $05006202	;Update metafile extents
v_write_meta	EQU $05006300	;Write metafile item (Byte 0=num_ptsin, Byte 2=num_intin)
vm_pagesize	EQU $05036300	;Physical page size
wm_coords	EQU $05056300	;Coordinate window
vm_filename	EQU $05006400	;Change gem vdi filename (Byte 2=n)
v_offset	EQU $05016500	;Set line offset
v_fontinit	EQU $05026600	;Init system font
;v_escape2000(times) -> (klappt mit dem Konzept leider nicht...)
		ENDPART
		END
