REM >BASIC:WimpSprite
REM
REM Copyright 1999-2014, Stephen Fryatt (info@stevefryatt.org.uk)
REM
REM This file is part of WimpLib:
REM
REM   http://www.stevefryatt.org.uk/software/
REM
REM Licensed under the EUPL, Version 1.2 only (the "Licence");
REM You may not use this work except in compliance with the
REM Licence.
REM
REM You may obtain a copy of the Licence at:
REM
REM   http://joinup.ec.europa.eu/software/page/eupl
REM
REM Unless required by applicable law or agreed to in
REM writing, software distributed under the Licence is
REM distributed on an "AS IS" basis, WITHOUT WARRANTIES
REM OR CONDITIONS OF ANY KIND, either express or implied.
REM
REM See the Licence for the specific language governing
REM permissions and limitations under the Licence.
:
REM Wimp sprite and sprite area handling library


REM Load a sprite file into a new block of memory, claimed via DIM. Use is made
REM of the standard Wimp suffixes (22, 23, 24...) in an attempt to get the
REM correct resoultion file.
REM
REM \param file_name$		The base filename of the file to load (no
REM				suffix).
REM \return			Pointer to new sprite area, or 0 on error.
:
DEF FNwimpsprite_load_user_sprites(file_name$)
LOCAL area%, size%, type%

SYS "OS_File", 17, file_name$ + FNwimpsprite_file_suffix TO type%,,,,size%

IF type% = 1 THEN
	file_name$ += FNwimpsprite_file_suffix
ELSE
	SYS "OS_File", 17, file_name$ TO type%,,,,size%
ENDIF

IF type% = 1 THEN
	size% += 4
	DIM area% size%
	!area% = size%
	area%!8 = 16
	SYS "OS_SpriteOp", &10A, area%, file_name$
ELSE
	area% = 0
ENDIF

=area%


REM Return the correct suffix for sprite files in the current mode. This does
REM the job of Wimp_ReadSysInfo 2, but gets it correct.
REM
REM \TODO -- This should probably now use Wimp_Extend 13 and Wimp_ReadSystInfo 2
REM          first to cover new systems?
REM
REM \return			The sprite file suffix for the current mode.
:
DEF FNwimpsprite_file_suffix
LOCAL suffix$, mode_flags%, y_eig%

suffix$ = ""

SYS "OS_ReadModeVariable", -1, 0 TO ,,mode_flags%

IF mode_flags% AND &10 THEN
	suffix$ = "23"
ELSE
	SYS "OS_ReadModeVariable", -1, 5 TO ,,y_eig%
	IF y_eig% < 2 THEN suffix$ = "22"
ENDIF

=suffix$

