;
; border.sh
;
; Plots borders given an icon block and a definition of the border shape
;
;  1995-1998 Straylight
;

;----- Licensing note -------------------------------------------------------
;
; This file is part of Straylight's Sculptrix.
;
; Sculptrix is free software; you can redistribute it and/or modify
; it under the terms of the GNU General Public License as published by
; the Free Software Foundation; either version 2, or (at your option)
; any later version.
;
; Sculptrix is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
; GNU General Public License for more details.
;
; You should have received a copy of the GNU General Public License
; along with Sculptrix.  If not, write to the Free Software Foundation,
; 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

;----- Overview -------------------------------------------------------------
;
; Functions provided:
;
;  border_plot

		[	:LNOT::DEF:border__dfn
		GBLL	border__dfn

; --- border_plot ---
;
; On entry:	R0 == pointer to border defintion
;		R1 == pointer to icon block
;		R2,R3 == window origin position
;		R4 == pointer to colour table
;		R5 == group box title width (optional)
;		R6 == group box title address (optional)
;
; On exit:	May return an error
;
; Use:		Plots a border using the border definition.

		IMPORT	border_plot

;----- Command codes --------------------------------------------------------
;
; We try to organise these in a way which makes it easy to decode.  The
; bottom two bits end up as an immediate operand in most cases, allowing us
; to select entries in the icon bounding box easily.

		^	-4

		#	4
bCmd_ret	EQU	{VAR}			;End border operation

		#	4
bCmd_ldix0	EQU	{VAR}+0			;Fetch X0 of the icon
bCmd_ldiy0	EQU	{VAR}+1			;Fetch Y0 of the icon
bCmd_ldix1	EQU	{VAR}+2			;Fetch X1 of the icon
bCmd_ldiy1	EQU	{VAR}+3			;Fetch Y1 of the icon

		#	4
bCmd_ldx0	EQU	{VAR}+0			;Fetch last stored X0
bCmd_ldy0	EQU	{VAR}+1			;Fetch last stored Y0
bCmd_ldx1	EQU	{VAR}+2			;Fetch last stored X1
bCmd_ldy1	EQU	{VAR}+3			;Fetch last stored Y1

		#	4
bCmd_ldhc	EQU	{VAR}+0			;Fetch horizontal centre
bCmd_ldvc	EQU	{VAR}+1			;Fetch vertical centre

		#	4
bCmd_add	EQU	{VAR}+0			;Add next byte
bCmd_sub	EQU	{VAR}+1			;Subtract next byte

		#	4
bCmd_stx0	EQU	{VAR}+0			;Store as the X0 parameter
bCmd_sty0	EQU	{VAR}+1			;Store as the Y0 parameter
bCmd_stx1	EQU	{VAR}+2			;Store as the X1 parameter
bCmd_sty1	EQU	{VAR}+3			;Store as the Y1 parameter

		#	4
bCmd_dark	EQU	{VAR}+0			;Use the current `dark' col
bCmd_light	EQU	{VAR}+1			;Use the current `light' col
bCmd_raw	EQU	{VAR}+2			;Switch to uninverted colours

		#	4
bCmd_icon	EQU	{VAR}+0			;Set colours from icon
bCmd_indCol	EQU	{VAR}+1			;Indirected colour
bCmd_litCol	EQU	{VAR}+2			;Literal colour

		#	4
bCmd_plot	EQU	{VAR}+0			;Plot a rule (arg == branch)

		#	4
bCmd_skpt	EQU	{VAR}+0			;Skip past the `title'

		#	4
bCmd_group	EQU	{VAR}+0			;Plot a group box

		#	4
bCmd_jmp	EQU	{VAR}+0			;Jump to a routine
bCmd_call	EQU	{VAR}+1			;Call subroutine

;----- Macros ---------------------------------------------------------------

		; --- Return ---

		MACRO
$label		BRET
$label		DCB	bCmd_ret
		MEND

		; --- Load values ---

		MACRO
$label		BLDIX0
$label		DCB	bCmd_ldix0
		MEND

		MACRO
$label		BLDIY0
$label		DCB	bCmd_ldiy0
		MEND

		MACRO
$label		BLDIX1
$label		DCB	bCmd_ldix1
		MEND

		MACRO
$label		BLDIY1
$label		DCB	bCmd_ldiy1
		MEND

		; --- Load values ---

		MACRO
$label		BLDX0
$label		DCB	bCmd_ldx0
		MEND

		MACRO
$label		BLDY0
$label		DCB	bCmd_ldy0
		MEND

		MACRO
$label		BLDX1
$label		DCB	bCmd_ldx1
		MEND

		MACRO
$label		BLDY1
$label		DCB	bCmd_ldy1
		MEND

		; --- Centring ---

		MACRO
$label		LDHC
$label		DCB	bCmd_ldhc
		MEND

		MACRO
$label		BLDVC
$label		DCB	bCmd_ldvc
		MEND

		; --- Arithmetic ---

		MACRO
$label		BADD	$val
$label		DCB	bCmd_add,$val
		MEND

		MACRO
$label		BSUB	$val
$label		DCB	bCmd_sub,$val
		MEND

		MACRO
$label		BSKIPT
$label		DCB	bCmd_skpt
		MEND

		; --- Storing values ---

		MACRO
$label		BSTX0
$label		DCB	bCmd_stx0
		MEND

		MACRO
$label		BSTY0
$label		DCB	bCmd_sty0
		MEND

		MACRO
$label		BSTX1
$label		DCB	bCmd_stx1
		MEND

		MACRO
$label		BSTY1
$label		DCB	bCmd_sty1
		MEND

		; --- Colouring ---

		MACRO
$label		BLIGHT
$label		DCB	bCmd_light
		MEND

		MACRO
$label		BDARK
$label		DCB	bCmd_dark
		MEND

		MACRO
$label		BRAW
$label		DCB	bCmd_raw
		MEND

		MACRO
$label		BICON
$label		DCB	bCmd_icon
		MEND

		MACRO
$label		BINDCOL	$colour
$label		DCB	bCmd_indCol,:INDEX:$colour
		MEND

		MACRO
$label		BLITCOL	$colour
$label		DCB	bCmd_litCol,$colour
		MEND

		; --- Plotting ---

		MACRO
$label		BPLOT	$rule
$label		DCB	bCmd_plot
		ALIGN
		B	$rule
		MEND

		MACRO
$label		BGROUP	$flags
$label		DCB	bCmd_group
		ALIGN
		DCD	$flags
		MEND

		; --- Subroutines ---

		MACRO
$label		BJMP	$addr
$label		DCB	bCmd_jmp
		ALIGN
		DCD	$addr-{PC}-4
		MEND

		MACRO
$label		BCALL	$addr
$label		DCB	bCmd_call
		ALIGN
		DCD	$addr-{PC}-4
		MEND

		]

;----- That's all, folks ----------------------------------------------------

		END
