Commit cd1be707 authored by Robert Sprowson's avatar Robert Sprowson
Browse files

Add support for wide translation tables for window tool furniture

With the introduction of 16bpp/32bpp modes it became possible to request tables from ColourTrans which used > 1 byte per colour, but the Wimp wasn't using this extension. Therefore tool sprites designed in 8bpp or less would be quantised horribly when plotted in a 16bpp or 32bpp mode.
The Wimp now requests and plots with a wide table, and to avoid thrashing ColourTrans so much with the prevalence of individually paletted icon sprites, keeps the table seperately to the icon sprites ones. At worst (in 32bpp) this uses an extra 256x4 bytes of RAM.
Trace.s: Split out the tracing routines from Wimp10 as it was getting a bit big.
Tiling.s: Namespace change for the icons versus tools distinction. Removed some unnecessary PC+8/PC+12 confused NOPs.
Tiling3D.s: Namespace change for the icons versus tools distinction.
Wimp01.s: New set of variables to track the tool translation tables separately. Various jiggling to keep ADRs in range.
Wimp02.s: Namespace change. Remove some double handling in Wimp_SetColourMapping.
Wimp04.s: Namespace change. Made factor rationalisation common to both the icon and tool grinding code. Removed dual use of cachespritedata for both icons and tools. The tintfunc moves to Wimp10. Service_InvalidateCache confusion resolved by adding a new flag to remember that the tools need regenerating rather than just marking the tool list as missing (which subsequently got restored in Tool_SpriteOp without actually doing any palette work.
Wimp10.s: Label tools_area renamed as it was immensely confusing to have that (which was actually holding the RMA allocation of the tool_list) and tool_area (which contains the sprite area) hanging around. Changed references to use tools-only cachetolspritedata routine. Added 'wide' flags to sprite op and colour trans calls. Tool_SpriteOp changed to actually regenerate the colour tables when they're known invalid (previously the tools list pointer was merely restored and no colour tables used). Trace functions extracted. Resolved confusion as to what recache_tools_trans and recache_tools_trans2 should be doing.

Tested with 4bpp "NewLook" sprites in 4bpp/8bpp/16bpp/32bpp and 8bpp smooth greyscaled "Steel" tool sprites in same modes.
Also ran a task window doing repeated Service_InvalidateCache calls while monitoring the RMA for leaks.
Generally navigated around some directories to ensure that inverse icons (during double click) and filer windows (with individually paletted sprites) were being rendered.

Version 5.20. Tagged as 'Wimp-5_20'
parent e937dd5d
......@@ -11,13 +11,13 @@
GBLS Module_HelpVersion
GBLS Module_ComponentName
GBLS Module_ComponentPath
Module_MajorVersion SETS "5.19"
Module_Version SETA 519
Module_MajorVersion SETS "5.20"
Module_Version SETA 520
Module_MinorVersion SETS ""
Module_Date SETS "09 Oct 2012"
Module_ApplicationDate SETS "09-Oct-12"
Module_Date SETS "28 Mar 2013"
Module_ApplicationDate SETS "28-Mar-13"
Module_ComponentName SETS "Wimp"
Module_ComponentPath SETS "castle/RiscOS/Sources/Desktop/Wimp"
Module_FullVersion SETS "5.19"
Module_HelpVersion SETS "5.19 (09 Oct 2012)"
Module_FullVersion SETS "5.20"
Module_HelpVersion SETS "5.20 (28 Mar 2013)"
END
/* (5.19)
/* (5.20)
*
* This file is automatically maintained by srccommit, do not edit manually.
* Last processed by srccommit version: 1.1.
*
*/
#define Module_MajorVersion_CMHG 5.19
#define Module_MajorVersion_CMHG 5.20
#define Module_MinorVersion_CMHG
#define Module_Date_CMHG 09 Oct 2012
#define Module_Date_CMHG 28 Mar 2013
#define Module_MajorVersion "5.19"
#define Module_Version 519
#define Module_MajorVersion "5.20"
#define Module_Version 520
#define Module_MinorVersion ""
#define Module_Date "09 Oct 2012"
#define Module_Date "28 Mar 2013"
#define Module_ApplicationDate "09-Oct-12"
#define Module_ApplicationDate "28-Mar-13"
#define Module_ComponentName "Wimp"
#define Module_ComponentPath "castle/RiscOS/Sources/Desktop/Wimp"
#define Module_FullVersion "5.19"
#define Module_HelpVersion "5.19 (09 Oct 2012)"
#define Module_LibraryVersionInfo "5:19"
#define Module_FullVersion "5.20"
#define Module_HelpVersion "5.20 (28 Mar 2013)"
#define Module_LibraryVersionInfo "5:20"
......@@ -48,8 +48,6 @@ plotspritebackground
wsaddr R4,clipx0
MOV R14,PC
MOV PC,R1
NOP
NOP
Pull "R0-R5,PC"
2
TEQ R0,#1 ; colour 1
......@@ -85,9 +83,9 @@ plotspritebackground
LDR R0,sprite_log2py
STR R0,tile_log2py
LDR R14,needsfactors
LDRB R14,sprite_needsfactors
TEQ R14,#0
ADRNE R14,factors
ADRNE R14,sprite_factors
Push R3
......@@ -97,7 +95,7 @@ plotspritebackground
STMIA R14,{R0-R3}
Pull R3
LDR R1,needsfactors ; needs preserving
LDRB R1,sprite_needsfactors ; needs preserving
Push R1
B %FT6
......@@ -129,15 +127,16 @@ plotspritebackground
MOV R0,#0
STR R0,lengthflags ; spritename is a pointer
LDR R0,tile_pixtable
LDR R1,needsfactors ; needs preserving
LDRB R1,sprite_needsfactors ; needs preserving
Push R1
STR R0,tile_temptab
LDR R0,tile_sc_block
STR R0,needsfactors
TEQ R0, #0
MOVNE R0, #-1
STRB R0,sprite_needsfactors
LDR R0,tile_pixtable
STR R0,tile_temptab
LDR R3,tile_width
LDR R4,tile_height
......@@ -210,7 +209,7 @@ err2
Pull "x0-y1"
Pull R0
STR R0,needsfactors
STRB R0,sprite_needsfactors
ADRL R14,tile_log2px ; restore global tile info
Pull "R0-R3"
......@@ -274,7 +273,7 @@ findwimptilesprite Entry "R0-R1"
STR R3,tile_width
STR R4,tile_height
LDR R1,needsfactors
LDRB R1,sprite_needsfactors
Push "R2-R3"
LDR R2,tile_pixtable
......@@ -284,7 +283,7 @@ findwimptilesprite Entry "R0-R1"
TEQ R1,#0
ADRNE R14,factors
ADRNE R14,sprite_factors
LDMNEIA R14,{R0-R3}
MOVEQ R0,#0
......@@ -347,7 +346,7 @@ findwimpspritefordepth
tile_putsprite
Push "R1-R7,LR"
;
LDR R0,needsfactors
LDRB R0,sprite_needsfactors
TEQ R0,#0 ; do I need to translate
;
MOVNE R0,#SpriteReason_PutSpriteScaled
......
......@@ -345,12 +345,12 @@ get_tile_sprite_info
mov r4,r4,LSL r0
str r4,[r8,#TileInfo_Height]
ldr r0,needsfactors
ldrb r0,sprite_needsfactors
teq r0,#0
moveq r0,#-1 ; if the scale factors are not needed then the first one is -1
adrne r14,factors
adrne r14,sprite_factors
ldmneia r14,{r0-r3}
add r14,r8,#TileInfo_ScaleFactors
......
; Copyright 2013 Castle Technology Ltd
;
; Licensed under the Apache License, Version 2.0 (the "License");
; you may not use this file except in compliance with the License.
; You may obtain a copy of the License at
;
; http://www.apache.org/licenses/LICENSE-2.0
;
; Unless required by applicable law or agreed to in writing, software
; distributed under the License is distributed on an "AS IS" BASIS,
; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
; See the License for the specific language governing permissions and
; limitations under the License.
;
; > Trace
; Some extra tracing routines by Jonathan. All preserve all registers and
; all flags
; HostFS_WriteC * &40102
;---------------------------------------------------------------------------
trace_char ROUT
; R0 = character to trace
EntryS "R0, R1, R2"
CMP R0, #32
BLT |trace_char: nonprintable character|
CMP R0, #127
BGE |trace_char: nonprintable character|
|trace_char: printable character|
;write character
SWI HostFS_WriteC
;if it's a backslash, write it again
CMP R0, #"\\"
SWIEQ HostFS_WriteC
B |trace_char: exit|
|trace_char: nonprintable character|
CMP R0, #:CHR: 10
BNE |trace_char: control character|
|trace_char: linefeed|
SWI HostFS_WriteC
MOV R0, #:CHR: 13
SWI HostFS_WriteC
B |trace_char: exit|
|trace_char: control character|
;save the character
MOV R1, R0
ADR R2, |trace_char: digits|
; R1 = character to trace
; R2 -> representation table
MOV R0, #"\\"
SWI HostFS_WriteC
MOV R0, #"x"
SWI HostFS_WriteC
;trace top nybble
MOV R0, R1, LSR #4
LDRB R0, [R2, R0]
SWI HostFS_WriteC
;trace bottom nybble
AND R0, R1, #&F
LDRB R0, [R2, R0]
SWI HostFS_WriteC
|trace_char: exit|
EXITS
|trace_char: digits|
= "0123456789ABCDEF"
ALIGN
;---------------------------------------------------------------------------
trace_string ROUT
; R0 -> string to trace
EntryS "R0, R1"
MOV R1, R0
; R1 -> string to trace
B |trace_string: end loop|
|trace_string: start loop|
BL trace_char
ADD R1, R1, #1
|trace_string: end loop|
LDRB R0, [R1]
CMP R0, #:CHR: 0
BNE |trace_string: start loop|
EXITS
;---------------------------------------------------------------------------
trace_decimal ROUT
; R0 = integer to trace
EntryS "R0, R1, R2"
SUB SP, SP, #16
MOV R1, SP
MOV R2, #15
SWI OS_ConvertInteger4
;trace it
BL trace_string
ADD SP, SP, #16
EXIT
;---------------------------------------------------------------------------
trace_hex ROUT
; R0 = integer to trace
Push "R0, R1, R2, LR"
SUB SP, SP, #16
MOV R1, SP
MOV R2, #15
SWI OS_ConvertHex8
;trace it
BL trace_string
ADD SP, SP, #16
Pull "R0, R1, R2, PC",, ^
;---------------------------------------------------------------------------
trace_nl ROUT
EntryS "R0"
MOV R0, #:CHR: 10
BL trace_char
EXITS
END
......@@ -106,5 +106,8 @@ LoadWimpOptions SETS "GET Options.s.$Options"
GET Wimp10.s
GET NewSWIs.s
GET AutoScroll.s
[ debug
GET Trace.s
]
END
......@@ -850,6 +850,7 @@ plotsprCB # 4 ; backdrop tiling CB
; these have moved!
RAM_SWIEntry # 12 ; 3 instructions for getting R12 back
OScopy_ChangeDynamic # 4 ; this must follow immediately
longjumpSP # 4 ; for cutting out the middle-man
ROMstart # 4 ; ROM base address
ROMend # 4 ; ROM end address (inclusive)
......@@ -949,7 +950,10 @@ gcolaction # 1 ; used by Wimp_SetColour
sysflags # 1 ; actions on moving windows (drag?)
memoryOK # 1 ; flag for ChangeDynamicArea
modechanged # 1 ; flag set on mode change
preservett # 1 ; used to hang onto translation tables
sprite_needsfactors # 1 ; otherwise 1:1 scaling for this mode
tsprite_needsfactors # 1 ; otherwise 1:1 scaling for this mode
tsprite_needsregen # 1 ; need to recalculate the tool sprite pixtrans
selecttable_crit # 1 ; ignore invalidate cache service calls if we're the cause
[ ChildWindows
openspending # 1 ; whether we're in the middle of a set of opens
]
......@@ -1059,7 +1063,6 @@ sender # 4
myref # 4
maxmenus * 8
longjumpSP # 4 ; for cutting out the middle-man
whichmenu # 4
menus_temporary # 4 ; if set, Wimp_Poll kills the menus
menuhandle # 4
......@@ -1234,34 +1237,41 @@ lastmode_x1 # 4 ; (xwindlimit+1) * px for previous mode
lastmode_y1 # 4 ; (ywindlimit+1) * py for previous mode
forceflags # 4 ; for putting windows back
lastmode # 4
ditheringflag # 4 ; flag to control dithering
sprite_lastmode # 4
sprite_log2bpp # 4 ; for mode-independent sprite plotting
sprite_log2px # 4
sprite_log2py # 4
needsfactors # 4
tsprite_lastmode # 4
tsprite_log2bpp # 4 ; for mode-independent toolsprite plotting
tsprite_log2px # 4
tsprite_log2py # 4
ALIGNHASH 16
factors # 16
ditheringflag # 4 ; flag to control dithering
sprite_factors # 16
tsprite_factors # 16
usephyspaltable # 4 ; use the physical palette table
physpaltable # 4*16 ; secondary palette table (disconnected from Wimp jobbie)
temppaltable # 4*16 ; temporary store for a palette
usephyspaltable # 4 ; use the physical palette table
transtable1 # 2 ; 1bpp mapping from wimp -> sprite pixels
transtable2 # 4 ; 2bpp ---------- "" ------------
transtable4 # 16 ; 4bpp ---------- "" ------------
ALIGNHASH 4
ALIGNHASH 16
selecttable_args # 4*6 ; parameters used for the last sprite select table call
pixtable_params # 4*6 ; parameters used for the select table call
pixtable_at # 4
pixtable_size # 4 ; size and position of pixtrans table currently setup
temppaltable # 4*16 ; temporary store for a palette
list_at # 4 ; head of sprite cache list
list_size # 4 ; size of buffer claimed
list_end # 4 ; end of list used for chop
tpixtable_at # 4
tpixtable_size # 4 ; size and position of tool pixtrans table currently setup
[ windowsprite :LAND: :LNOT: ThreeDPatch
tile_sc_block # 16
tile_log2px # 4
......@@ -1529,8 +1539,7 @@ errordynamic * errorbuffer+4 ; put these after stashed PC
errordynamicsize * ?errorbuffer-4
stackspace # 0 ; temporary stack for debugging!
tools_area # 4 ; area for tools list
tools_trans_size # 4 ; size of last tools_trans
tool_list_backup # 4 ; backup copy of tool_list
copyerror # 240 ; copy of error block
greys_mode # 1 ; last grey mode.
last_greys # 1 ; previous greys mode
......@@ -1594,6 +1603,8 @@ maxwork * :INDEX:@
! 0, "Free pool = R12+&" :CC: :STR: :INDEX: freepool
! 0, "#pixtable_at = R12+&" :CC: :STR: :INDEX: pixtable_at
! 0, "#pixtable_size = R12+&" :CC: :STR: :INDEX: pixtable_size
! 0, "#tpixtable_at = R12+&" :CC: :STR: :INDEX: tpixtable_at
! 0, "#tpixtable_size = R12+&" :CC: :STR: :INDEX: tpixtable_size
! 0, "#list_at = R12+&" :CC: :STR: :INDEX: list_at
! 0, "#list_size = R12+&" :CC: :STR: :INDEX: list_size
! 0, "#list_end = R12+&" :CC: :STR: :INDEX: list_end
......@@ -3654,9 +3665,15 @@ gotwork
MOV R0,#0
STR R0,automenu_inactivetimeout
;
STRB R0,selecttable_crit ; don't mind losing it on an invalidate cache service call
STRB R0,tsprite_needsregen ; doesn't because there isn't one
STR R0,pixtable_at ; no pixel translation table
STR R0,pixtable_size
STRB R0,preservett ; don't mind losing it on an invalidate cache service call
STR R0,tpixtable_at ; no tool pixel translation table
STR R0,tpixtable_size
STR R0,list_at
STR R0,list_size ; mark to indicate now list present
STR R0,filehandle
......@@ -3669,7 +3686,7 @@ gotwork
[ NewErrorSystem
STR R0,watchdogcodew
]
ADRL R14,tools_area
ADRL R14,tool_list_backup
STR R0,[R14]
; ADRL R14,wimpmodebefore
; STR R0,[R14]
......@@ -4306,20 +4323,20 @@ releasewrchvpremodechange
invalidatecache
Push "R0,R2,LR"
LDRB R2,preservett ; avoid discarding the table when we know
LDRB R2,selecttable_crit ; avoid discarding the table when we know
CMP R2,#0 ; that it is still valid
BNE %FT10
Pull "R0,R2,PC", NE
LDR R2,pixtable_at
CMP R2,#0 ; has a pixtable been setup?
MOVNE R0,#ModHandReason_Free
BLNE XROS_Module ; attempt to release - ignore errors
;
BLNE XROS_Module ; attempt to release - ignore errors
MOV R2,#0
STR R2,pixtable_at ; mark the pixtable as being zapped!
;
MOV R2,#-1 ; and the PixTrans mode
STR R2,lastmode
STR R2,sprite_lastmode
[ ThreeDPatch
; MB - must add invalidating of new tile pixel tables here
......@@ -4329,23 +4346,20 @@ invalidatecache
STR R2,tile_temptab
]
[ false
BL freetoollist ; Lose cached tool data
|
; tool translation table is invalid, try to recache
LDR R2,tool_area
CMP R2,#0
BEQ %FT99
LDR R2,tool_list
CMP R2,#0
BEQ %FT99
LDR R2,tpixtable_at
CMP R2,#0 ; has a tool pixtable been setup?
MOVNE R0,#ModHandReason_Free
BLNE XROS_Module ; attempt to release - ignore errors
MOV R2,#0
STR R2,tool_list ; force recache next time we need it
STR R2,tpixtable_at ; mark the tool pixtable as being zapped!
STR R2,tool_transtable
MOV R2,#-1 ; and the tool PixTrans mode
STR R2,tsprite_lastmode
STRB R2,tsprite_needsregen ; re-calcuate border based information
99
]
10
Pull "R0,R2,PC"
;
......@@ -4587,6 +4601,10 @@ deallocateptrs ROUT
LDR R2,pixtable_at
CMP R2,#0
BLNE XROS_Module ; release the pixtrans table (ignore errors)
;
LDR R2,tpixtable_at
CMP R2,#0
BLNE XROS_Module ; release the tools pixtrans table (ignore errors)
;
LDR R2,fileaddress
CMP R2,#0
......@@ -4594,6 +4612,8 @@ deallocateptrs ROUT
;
STR R1,pixtable_at
STR R1,pixtable_size
STR R1,tpixtable_at
STR R1,tpixtable_size
STR R1,filehandle
STR R1,fileaddress ; tag as free'd
;
......@@ -5384,7 +5404,7 @@ sysinfo_memclaim
B ExitWimp
sysinfo_transtables
LDR R0,pixtable_at
LDR R0,tpixtable_at
ADRL R2,tool_plotparams
LDR R1,[R2]
STMIA sp,{R1-R2}
......
......@@ -2965,7 +2965,7 @@ inittasks
STR R0,menutaskhandle
;
MOV R14,#-1 ; invalidate sprite translation stuff
STR R14,lastmode
STR R14,sprite_lastmode
;
; Braindead panic redraw indication.
;
......@@ -3320,10 +3320,12 @@ recalcpalette
;
BL readvduvars ; just in case
;
MOV R14,#-1 ; sprite stuff is now invalid (as is ColourTrans's cache)
STR R14,lastmode
SWI XColourTrans_InvalidateCache
;
[ false ; this stuff gets done in Service_InvalidateCache
MOV R14,#-1 ; sprite stuff is now invalid (as is ColourTrans's cache)
STR R14,sprite_lastmode
LDR R2,pixtable_at
TEQ R2,#0 ; pixtable currently claimed?
MOVNE R0,#ModHandReason_Free
......@@ -3331,6 +3333,7 @@ recalcpalette
;
MOV R2,#0
STR R2,pixtable_at ; mark block as released
]
;
; first set up border & mouse colours
;
......@@ -8855,7 +8858,7 @@ forcetint_on EntryS "R0,R2"
TEQ R0, #0
TEQNE R0, R14
STRNEB R0, tinted_tool
BLNE recache_tools_trans2 ; uses R2 as set up above (-> first sprite)
BLNE recache_tools_trans ; uses R2 as set up above (-> first sprite)
EXITS ; must preserve flags
;
......@@ -8871,7 +8874,7 @@ forcetint_off EntryS "R2"
TEQ R14, #0
MOVNE R14, #0
STRNEB R14, tinted_tool
BLNE recache_tools_trans2 ; uses R2 as set up above (-> first sprite)
BLNE recache_tools_trans ; uses R2 as set up above (-> first sprite)
EXITS ; must preserve flags
]
......
......@@ -2080,7 +2080,7 @@ icontext_paint
LDR R0,tool_list ; 320nk
TEQ R0,#0
BLEQ recache_tools_trans ; make sure there's something there
BLEQ restore_tool_list ; make sure there's something there
; just in case we're in the middle of
; plotting a title bar, for instance.
......@@ -2576,7 +2576,7 @@ iconformatted_width_ok
LDR R0,tool_list ; 320nk
TEQ R0,#0
BLEQ recache_tools_trans ; make sure there's something there
BLEQ restore_tool_list ; make sure there's something there
; just in case we're in the middle of
; plotting a title bar, for instance.
iconformatted_fancy_next
......@@ -3222,7 +3222,7 @@ SWIWimp_ReadPixTrans
BVS ExitWimp
;
CMP R6,#0
ADRNE R14,factors
ADRNE R14,sprite_factors
LDMNEIA R14,{R1-R4}
STMNEIA R6,{R1-R4} ; copy factors out
;
......@@ -3234,6 +3234,46 @@ SWIWimp_ReadPixTrans
;
B ExitWimp
;;----------------------------------------------------------------------------
;; Rationalise sprite scaling factors
;; Entry: R0,R1 sprite's eigx/eigy
;; R5,R6 mode's eigx/eigy
;; R2 --> where to store the factors
;; Exit: R0,R1,R5,R6 corrupted
;; [R2] factors stored (xmul,ymul,xdiv,ydiv)
;;----------------------------------------------------------------------------
rationalisefactors
Entry
MOV R14,#1
; all factors are ?:1 or 1:? so make R0:R5, R1:R6
; into this form
CMP R0,R5
MOVEQ R0,#1
MOVEQ R5,#1
MOVLT R5,R14,LSL R5
MOVLT R5,R5, LSR R0
MOVLT R0,#1
MOVGT R0,R14,LSL R0
MOVGT R0,R0, LSR R5
MOVGT R5,#1
CMP R1,R6
MOVEQ R1,#1
MOVEQ R6,#1
MOVLT R6,R14,LSL R6
MOVLT R6,R6, LSR R1
MOVLT R1,#1
MOVGT R1,R14,LSL R1
MOVGT R1,R1, LSR R6
MOVGT R6,#1
STMIA R2,{R0-R1,R5-R6} ; store the scaling block
EXIT