home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Acorn User 4
/
AUCD4.iso
/
utils
/
programing
/
silofer
/
Source
/
siolfer
< prev
Wrap
Text File
|
1998-08-28
|
17KB
|
481 lines
;===============================================================================================;
; Siolfer - program to conveniently manage CMOS files ;
; Copyright © 1998 Iain Truskett ;
;===============================================================================================;
; This program 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 of the License, or ;
; (at your option) any later version. ;
; ;
; This program 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 this program; if not, write to the Free Software ;
; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. ;
;===============================================================================================;
; and before you start, yes, i know i don't comment as much as i should
;preprocessor macros, directives et al
#smile ; produce a smile if compilation successful
#name ^.!Siolfer.!RunImage ; from default directory structure
#strset Version = "1.17 (28-Aug-1998) © Iain Truskett 1998"
#set ibarmenu_saveintoboot_option = 5 ; component id of saveintoboot menu option
; used when fading the option
#set Buffer_Len = 2048 ; extra workspace required. Must be at least 240
#set MinimumWimp = 316 ; earliest version of wimp to work with
#set cmos_size = 240 ; number of bytes of cmos
#set toolbox_loadhelp = &2 ; toolbox message number for loading help file
#set toolbox_save_ascmos = &4 ; ...prepare saveas box info for Config (&FF2)
#set toolbox_save_asutil = &3 ; ...prepare saveas box info for Utility (&FFC)
#set toolbox_save_immediate = &5 ; ...save file into !Boot immediately
#set toolbox_menu_opening = &7 ; ...fade menu items if needed
#set toolbox_proginfo = &82B40 ; ...fill in URL and version
#set toolbox_saveshown = &82BC0 ; ...know when to fill the saveas box
#set toolbox_quitmsg = &82A91 ; ...time to die
#set message_dataload = 3 ; wimp dataload message
#set message_quit = 0 ; wimp quit message
#set ProgInfo_SetVersion = 1 ; Toolbox_ObjectMiscOp codes used
#set ProgInfo_SetUri = 7
#set Menu_SetFade = 2
#set SaveAs_SetFileName = 3
#set SaveAs_SetFileType = 5
#set SaveAs_SetFileSize = 7
#set SaveAs_SetDataAddress = 10
#set ip = 12 ; index pointer
#set sp = 13 ; stack pointer
#set lr = 14 ; link register
;#set pc = 15 ; program counter 'Hard-coded' in extAsm
#set XMessageTrans_Lookup = &061502 ; the various swi calls used in the program
#set XOS_Byte = &020006 ; not actually needed to be declared, but done
#set XOS_CLI = &020005 ; for easy cross compilation stuff
#set XOS_Exit = &020011
#set XOS_File = &020008
#set XOS_ReadMonotonicTime = &020042
#set XOS_ReadVarVal = &020023
#set XToolbox_Initialise = &064ECF
#set XToolbox_ObjectMiscOp = &064EC6
#set XWimp_PollIdle = &0600E1
#set XWimp_ReportError = &0600DF
#set XWimp_SlotSize = &0600EC
;el code
;===============================================================================================;
; ensure memory requirements are fulfilled ;
;===============================================================================================;
MOV R0,#4096 ; make sure we have at least 4KB
MVN R1,#0 ; of memory available
SWI XWimp_SlotSize ; (minimum page size so shouldn't fail)
ADR sp,end_of_program ; sp is workspace
ADD sp,sp,#Buffer_Len ; tack some more memory onto end of workspace
MOV ip,sp ; ip is handy variable
;===============================================================================================;
; initialise task with the toolbox ;
;===============================================================================================;
MOV R0,#0
MOV R1,#MinimumWimp
ADR R2,list
ADR R3,elist
ADR R4,resources
ADR R5,mfd
ADR R6,idblk
SWI XToolbox_Initialise
BVS diegracefully
;===============================================================================================;
; determine boot sequence type ;
;===============================================================================================;
; determine if a boot sequence is being used or not
ADR R0,varname2
MOV R1,#0
MVN R2,#1
MOV R3,#0
MOV R4,#0
SWI XOS_ReadVarVal
CMP R2,#0 ; if negative then new boot sequence, else not.
MOVGE R0,#1
STRGEB R0,fadeit ; fade menu entry since old style is being used
BGE poll
; RISC OS 3.5+ boot sequence is being used...
ADR R0,varname ; whichversion using '<Boot$Unique>' existence
MOV R1,#0
MVN R2,#1
MOV R3,#0
MOV R4,#0
SWI XOS_ReadVarVal
CMP R2,#0 ; see if R2 is still negative, thus variable would exist.
MOVLT R0,#0 ; if variable does exist, save as 'Config'
MOVGE R0,#1 ; otherwise save as 'Utility'
STRB R0,savetype
ADRLT R0,sixtysavepath ; if variable does exist save into !boot for autoload
ADRGE R0,fiftysavepath ; else do tricky into PreDesk save.
STR R0,savepath
;===============================================================================================;
; traditional poll loop ;
;===============================================================================================;
.poll
SWI XOS_ReadMonotonicTime ; poll idle rate is
ADD R2,R0,#4096 ; 4096 centiseconds
MOV R0,#%1100000110001
MOV R1,ip
SWI XWimp_PollIdle
CMP R0,#&200 ; toolbox messages
BEQ tbox
CMP R0,#&11 ; normal wimp messages
CMPNE R0,#&12
BNE poll
;-----------------------------------------------------------------------------------------------;
LDR R3,[R1,#16] ; normal wimp message handler
CMP R3,#message_quit ; diediedie
SWIEQ XOS_Exit
CMP R3,#message_dataload ; wimpmsg data_load
BNE poll ; if not data_load, go back to polling
LDR R0,[R1,#40] ; data load from file
LDR R2,ctype
CMP R0,R2 ; only allow Config (&FF2) files.
BNE poll ; but don't cause an error
MOV R0,#16
ADD R1,R1,#44
ADR R2,save_block_cmos
MOV R3,#0
SWI XOS_File
BVS stayalive
BL loadcmosdata
B poll
.tbox LDR R3,[R1,#8] ; toolbox
LDR R4,quitmsg
CMP R3,R4
SWIEQ XOS_Exit ; die
LDR R4,proginfo
CMP R3,R4
BEQ proginfo_displayed ; proginfo_displayed
LDR R4,saveshown
CMP R3,R4
BEQ save_shown ; save_about_to_be_shown
CMP R3,#toolbox_menu_opening
BEQ fademenu ; menu_opening
CMP R3,#toolbox_loadhelp
BEQ load_help ; load_help
CMP R3,#toolbox_save_ascmos
BEQ save_initialise_cmos ; save_ascmos
CMP R3,#toolbox_save_asutil
BEQ save_initialise_util ; save_asutil
CMP R3,#toolbox_save_immediate
BEQ save_do_boot ; save_immediate
B poll
;===============================================================================================;
; fade menu entry in event of old sequence ;
;===============================================================================================;
.fademenu
LDR R1,thisobj
MOV R0,#0
MOV R2,#Menu_SetFade
MOV R3,#ibarmenu_saveintoboot_option
LDRB R4,fadeit
SWI XToolbox_ObjectMiscOp
BVS stayalive
B poll
;===============================================================================================
; part of the save routines, here due to the way I've been cutting down on instructions
.save_do_boot
LDR R1,savepath
;===============================================================================================;
; Create directory path given canonicalised file name ;
;===============================================================================================;
; external calls
; drawerror
; on entry:
; R1 = address of path to create
; on exit: R0,R2,R3,R4 all corrupted
; exits to: next instruction
; developed from a BASIC routine by Alan Wrigley IIRC.
MOV R2,#0 ; Convert path to series of NUL-terminated strings
MOV R3,#0
LDRB R0,[R1,R3]
.cpls CMP R0,#46
STREQB R2,[R1,R3]
MOVEQ R6,R3
ADD R3,R3,#1
LDRB R0,[R1,R3]
CMP R0,#0
BNE cpls
; MOV R0,#8 ; OS_File 8
; ADR R1,pathtomake ; Path to create
; MOV R2,#0 ; Offset from R1
MOV R3,#46 ; Convert the NULs to periods ('.').
MOV R4,#255 ; Directory entries, only used with networks.
MOV R5,#1 ; path terminator
.cpsl
MOV R0,#8
SWI XOS_File;R0-R1,R4 ; Create first level.
BVS stayalive ; Check for error, and live always
LDRB R0,[R1,R2]
.cpsld CMP R2,R6
BEQ cpsrs
CMP R0,#0
STREQB R3,[R1,R2]
ADD R2,R2,#1
LDRB R0,[R1,R2]
CMP R0,#1
BGT cpsld
BNE cpsl
.cpsrs
MOV R2,#0 ; (offset from addrbase)
MOV R3,#0 ; (NUL)
MOV R4,#46 ; ('.')
.cpsr LDRB R0,[R1,R2]
CMP R0,#0 ; Test for char = 0x00 = null
STREQB R4,[R1,R2]
CMP R0,#1 ; Test for char = 0x01
SUBEQ R2,R2,#1
STREQB R3,[R1,R2]
ADD R2,R2,#1
BNE cpsr
;===============================================================================================;
; actual cmos saving routines ;
;===============================================================================================;
BL getcmosdata
LDRB R7,savetype
; on entry R1 = path to save to
MOV R0,#10
CMP R7,#0 ; Set conditions
LDREQ R2,ctype ; If saving as config ; file type
LDRNE R2,utype ; If saving as utility
ADREQ R4,cmos ; If saving as config ; start address
ADRNE R4,startutility ; If saving as utility
ADR R5,cmos
ADD R5,R5,#cmos_size ; end address
SWI XOS_File ; Save file
BVS stayalive
B poll
.getcmosdata
STMFD sp!,{R0-R3,lr}
MOV R1,#cmos_size+1 ; Start at top of memory and work down
ADR R3,cmos ; Storage base
MOV R0,#161 ; OS_Byte reason code
.loop1 SUBS R1,R1,#1 ; Decrement R1 and set flags
SWI XOS_Byte ; Call OS_Byte
STRB R2,[R3,R1] ; Store result at R3+R1
BNE loop1 ; If R1=0 then die else repeat.
LDMFD sp!,{R0-R3,pc}
;===============================================================================================;
; save box ;
;===============================================================================================;
.save_initialise_cmos ; initialise save box for CMOS saving
LDR R1,ctype
STR R1,save_type
MOV R1,#cmos_size
STR R1,save_size
ADR R1,save_block_cmos
STR R1,save_block
B poll
.save_initialise_util ; initialise save box for Utility saving
LDR R1,utype
STR R1,save_type
MOV R1,#(cmos_size+endload-startutility)
STR R1,save_size
ADR R1,startutility
STR R1,save_block
B poll
.save_shown ; save box preshowing warning handler
ADR R1,savename
BL messlookup
MOV R0,#0
LDR R1,thisobj
MOV R2,#SaveAs_SetFileName
SWI XToolbox_ObjectMiscOp
MOV R2,#SaveAs_SetFileType
LDR R3,save_type
SWI XToolbox_ObjectMiscOp
MOV R2,#SaveAs_SetFileSize
LDR R3,save_size
SWI XToolbox_ObjectMiscOp
MOV R2,#SaveAs_SetDataAddress
MOV R4,R3
LDR R3,save_block
SWI XToolbox_ObjectMiscOp
BL getcmosdata
B poll
;===============================================================================================;
; load help ;
;===============================================================================================;
.load_help
ADR R1,loadhelppath
BL messlookup
MOV R0,R3
SWI XOS_CLI
BVS stayalive
B poll
;===============================================================================================;
; look up a messagetrans token ;
;===============================================================================================;
; On entry: R1 = token
; On exit: R3 = translated
; other registers preserved
.messlookup
STMFD sp!,{R0,R2-R4,lr}
ADR R0,mfd
MOV R2,#0
SWI XMessageTrans_Lookup
MOV R3,R2
LDMFD sp!,{R0-R2,R4,pc}
;===============================================================================================;
; proginfo preshow warning, so write version and url in ;
;===============================================================================================;
.proginfo_displayed
MOV R0,#0
; ADR R2,idblk
; LDR R4,[R2,#16]
LDR R4,thisobj
ADR R1,version ; Put current version in ProgInfo box
BL messlookup
MOV R1,R4
MOV R2,#ProgInfo_SetVersion
SWI XToolbox_ObjectMiscOp
ADR R1,url ; Put url in ProgInfo box
BL messlookup ; only available in ProgInfo 0.14 or later, tmk
MOV R1,R4
MOV R2,#ProgInfo_SetUri
SWI XToolbox_ObjectMiscOp
B poll
;===============================================================================================;
; error handling ;
;===============================================================================================;
.drawerror
ADR R2,name ; report errors and return to caller
BL messlookup
MOV R1,#1
SWI XWimp_ReportError
MOV pc,lr
.stayalive
BL drawerror ; report error and poll
B poll
.diegracefully
BL drawerror ; report error and die
SWI XOS_Exit
;===============================================================================================;
; lots of data for all the family ;
;===============================================================================================;
ALIGN
; -----------------------------------------------------------------------------
.elist
DCD toolbox_loadhelp ; toolbox message list
DCD toolbox_save_ascmos
DCD toolbox_save_asutil
DCD toolbox_save_immediate
DCD toolbox_menu_opening
.proginfo DCD toolbox_proginfo
.saveshown DCD toolbox_saveshown
.quitmsg DCD toolbox_quitmsg
DCD 0 ; end of list
; -----------------------------------------------------------------------------
.resources DCB "|<siolfer$Dir>",0 ; program resources + boot path
ALIGN
.name DCB "T",0 ; Program name
.loadhelppath DCB "C",0 ; help command
.version DCB "V",0 ; version of program
.url DCB "U",0 ; url of program's website
; ----------------------------------------------------------------------
ALIGN
; -------------------- Program specific bits --------------------
.fiftysavepath DCB "|<Boot$ToBeLoaded>.!!!!CMOS",0,1 ; Save path for RISC OS 3.5
ALIGN
.sixtysavepath DCB "|<Boot$Dir>.MchConfig.|<Boot$Unique>." ; Save path for new !Boot
DCB "!RO|<Boot$OSVersion>CMOS",0,1
ALIGN
.varname DCB "Boot$Unique",0
ALIGN
.varname2 DCB "Boot$ToBeTasks",0
ALIGN
;-----------------------------------------------------------------------------
.mfd DCD 0 ;0 ; message file descriptor
DCD 0 ;4
DCD 0 ;8
DCD 0 ;12
.idblk DCD 0 ;0 ancestor obj ; toolbox id block
DCD 0 ;4 ancestor cmp
DCD 0 ;8 parent obj
DCD 0 ;12 parent cmp
.thisobj DCD 0 ;16 this obj
DCD 0 ;24 this cmp
;-----------------------------------------------------------------------------
.list DCD message_dataload ; Message_DataLoad ; wimp message list
; DCD 0 ; Message_Quit / end of list
; -----------------------------------------------------------------------------
.savepath DCD 0
;-----------------------------------------------------------------------------
.save_type DCD 0
.save_size DCD 0
.save_block DCD 0
;-----------------------------------------------------------------------------
.utype DCD &FFC
.ctype DCD &FF2
.savename DCB "S",0
.fadeit DCB 0
.savetype DCB 0
ALIGN
; =============== The bit which is saved ===============
; -------------------- Load program --------------------
.startutility
.loadcmosdata
STMFD sp!,{R0-R3,lr}
MOV R1,#cmos_size+1 ; First byte
ADR R3,cmos ; Storage base
MOV R0,#162 ; OS_Byte reason code
.loop2 SUBS R1,R1,#1 ; Decrement R1 and set flags
LDRB R2,[R3,R1] ; Load byte from R3+R1
SWI XOS_Byte ; Call OS_Byte
BNE loop2 ; If not equal repeat.
LDMFD sp!,{R0-R3,pc}
.endload
; ---------------- Buffer for CMOS data ----------------
; Label for end of save. Anything after here is ignored
; Buffer_Len amount of bytes will be tacked onto here.
.save_block_cmos
.cmos
.end_of_program
DCB 10,10,Version,10
; The End.