Message 7.39 KB
Newer Older
Neil Turton's avatar
Neil Turton committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
; Copyright 1996 Acorn Computers 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.
;
; > Sources.Message

;---------------------------------------------------------------------------
; Message_Received
; Message_Recorded
;
;       In:     r1 -> message block
;       Out:    r0 corrupted
;
;       Deal with messages which require no ack.
;
Message_Received
Message_Recorded
28
        Entry   "r1-r6"
Neil Turton's avatar
Neil Turton committed
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67

        LDR     r0, [r1, #ms_action]

        Debug   msg,"Message",r0

        LDR     lr, =Message_MenuWarning
        TEQ     r0, lr
        BEQ     msg_menuwarning

        LDR     lr, =Message_MenusDeleted
        TEQ     r0, lr
        BEQ     msg_menusdeleted

        LDR     lr, =Message_HelpRequest
        TEQ     r0, lr
        BEQ     msg_helprequest

 [ LoadModeFiles
        TEQ     r0, #Message_DataLoad
        BEQ     msg_dataload

        TEQ     r0, #Message_DataSave
        BEQ     msg_datasave
 ]

        TEQ     r0, #Message_Quit
        EXIT    NE

msg_quit
        Debug   msg,"msg_quit"
        BL      Mod_ShutDown
        SWI     OS_Exit


msg_menuwarning
        Debug   msg,"msg_menuwarning"
        ADD     r1, r1, #20
        LDMIA   r1, {r1-r3}
        Push    "r1-r3"
68
        SUB     sp, sp, #GVPixelFormat_Size
Neil Turton's avatar
Neil Turton committed
69 70

        BL      Mode_GetCurrent
71
        MOV     r5, sp
Neil Turton's avatar
Neil Turton committed
72 73 74 75
        BLVC    Mode_GetInfo
        BLVC    Mode_TestPalette
        BLVC    Mode_SetModeString

76
        ADD     sp, sp, #GVPixelFormat_Size
Neil Turton's avatar
Neil Turton committed
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200
        Pull    "r1-r3"
        SWIVC   XWimp_CreateSubMenu

        EXIT


msg_menusdeleted
        Debug   msg,"msg_menusdeleted"
        LDR     r1, menu_handle
        BL      Menu_RemoveTick
        MOV     r1, #0
        STR     r1, menu_handle
        EXIT


msg_helprequest
        Debug   msg,"msg_helprequest"
        LDR     r2, [r1, #ms_data + b_window]
        LDR     r3, [r1, #ms_data + b_icon]

        CMP     r2, #iconbar_whandle
        MOVEQ   r2, #"B"
        MOVEQ   r3, #0
        BEQ     return_help

        LDR     lr, info_handle
        TEQ     r2, lr
        MOVEQ   r2, #"I"
        MOVEQ   r3, #0
        BEQ     return_help

        LDR     lr, display_handle
        TEQ     r2, lr
        MOVEQ   r2, #"D"
        BEQ     return_help

        LDR     lr, mode_handle
        TEQ     r2, lr
        MOVEQ   r2, #"W"
        BEQ     return_help

        CMP     r3, #0                  ; No help if not on a menu item.
        EXIT    LT

        Push    "r1,r3,lr"              ; Find menu item.
        MOV     r0, #1
        ADD     r1, sp, #4
        SWI     XWimp_GetMenuState
        Pull    "r1,r3,lr"              ; r3 = menu item
        EXIT    VS

        LDR     r0, menu_handle
        ADR     lr, m_iconbarmenu
        TEQ     r0, lr
        MOVEQ   r2, #"M"
        BEQ     return_help

        ADR     lr, m_coloursmenu
        TEQ     r0, lr
        MOVEQ   r2, #"C"
        BEQ     return_help

        LDR     lr, m_resolutionmenu
        TEQ     r0, lr
        MOVEQ   r2, #"R"
        BEQ     return_help

        LDR     lr, m_ratemenu
        TEQ     r0, lr
        EXIT    NE

        MOV     r2, #"F"                ; And drop through to...

return_help
        SUB     sp, sp, #8              ; Get some local stack.

        MOV     r1, sp                  ; Build message token.
        MOV     lr, #"H"
        STRB    lr, [r1], #1
        STRB    r2, [r1], #1
        MOV     r0, r3
        MOV     r2, #user_data_size - msHelp_message
        SWI     XOS_ConvertHex2

        BLVC    MsgTrans_OpenFile       ; Lookup help text.
        MOVVC   r1, sp
        ADRVC   r2, user_data + msHelp_message
        MOVVC   r3, #user_data_size - msHelp_message
        BLVC    MsgTrans_Lookup

        ADD     sp, sp, #8              ; Balance stack.

        LDRVC   r0, =Message_HelpReply
        SUBVC   r1, r2, #msHelp_message
        ADDVC   r3, r3, #msHelp_message + 4
        BICVC   r3, r3, #3              ; r3 = message size (including string terminator)
        STRVC   r3, [r1, #ms_size]
        BLVC    Message_SendAck
        EXIT


 [ LoadModeFiles

msg_dataload
        Debug   msg,"msg_dataload"
        LDR     lr, [r1, #msDataTransfer_filetype]
        LDR     r0, =FileType_Text
        TEQ     r0, lr                  ; Make sure it's a text file.
        ADRNE   r0, ErrorBlock_Modes_InvalidFile
        BLNE    MsgTrans_ErrorLookup
        EXIT    VS

        LDR     r6, [r1, #ms_yourref]   ; Save for later.
        Debug   msg," received ref",r6

        LDR     r0, =Message_DataLoadAck
        BL      Message_SendAck

        ADDVC   r1, r1, #msDataTransfer_filename
        BLVC    Mode_LoadFile
        BL      delete_scrap
        EXIT

delete_scrap
201
        EntryS  "r0"
Neil Turton's avatar
Neil Turton committed
202 203 204 205 206 207
        LDR     lr, scrap_ref
        TEQ     r6, lr                  ; If loading scrap file then
        MOVEQ   lr, #-1                 ;   clear scrap ref
        STREQ   lr, scrap_ref
        ADREQ   r0, deletescrap         ;   and delete scrap file we used.
        SWIEQ   XOS_CLI
208
        EXITS
Neil Turton's avatar
Neil Turton committed
209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265


msg_datasave
        Debug   msg,"msg_datasave"
        LDR     lr, [r1, #msDataTransfer_filetype]
        LDR     r0, =FileType_Text
        TEQ     r0, lr                  ; Make sure it's a text file.
        EXIT    NE

        ADR     r0, wimpscrapname       ; Check that Wimp$Scrap has been set.
        MOV     r2, #-1
        MOV     r3, #0
        MOV     r4, #VarType_Expanded
        SWI     XOS_ReadVarVal          ; Returns r2=0 if doesn't exist.
        CMP     r2, #0
        ADREQ   r0, ErrorBlock_Modes_NoScrap
        BLEQ    MsgTrans_ErrorLookup
        EXIT    VS

        MOV     lr, #-1
        STR     lr, [r1, #msDataTransfer_filesize]
        MOV     lr, #(msDataTransfer_filename + ?wimpscrapname2 + 3):AND::NOT:3
        STR     lr, [r1, #ms_size]

        ADR     r0, wimpscrapname2
        ADD     r1, r1, #msDataTransfer_filename
        BL      Mod_CopyString          ; r2 = length = -1 from above.

        LDR     r0, =Message_DataSaveAck
        ADR     r1, user_data
        BL      Message_SendAck

        LDRVC   lr, [r1, #ms_myref]     ; Note that we're using Wimp$Scrap.
        STRVC   lr, scrap_ref
        Debug   msg," sent ref",lr
        EXIT

wimpscrapname   DCB     "Wimp$Scrap",0
wimpscrapname2  DCB     "<Wimp$Scrap>",0
deletescrap     DCB     "%Delete <Wimp$Scrap>",0
                ALIGN

        MakeErrorBlock  Modes_InvalidFile
        MakeErrorBlock  Modes_NoScrap


;---------------------------------------------------------------------------
; Message_SendAck
;
;       In:     r0 = message to send
;               r1 -> message block to send
;       Out:    r0 corrupted
;
;       The references in the message block are updated and the message
;       is then sent to the appropriate task.
;
Message_SendAck
266
        Entry   "r1,r2"
Neil Turton's avatar
Neil Turton committed
267 268 269 270 271 272 273 274 275 276 277 278 279 280 281

        LDR     r2, [r1, #ms_taskhandle]
        LDR     lr, [r1, #ms_myref]
        STR     lr, [r1, #ms_yourref]
        STR     r0, [r1, #ms_action]

        MOV     r0, #User_Message
        SWI     XWimp_SendMessage

        EXIT
 ]

        LTORG

        END