home *** CD-ROM | disk | FTP | other *** search
/ Acorn User 4 / AUCD4.iso / utils / programing / silofer / Source / siolfer < prev   
Text File  |  1998-08-28  |  17KB  |  481 lines

  1. ;===============================================================================================;
  2. ;   Siolfer - program to conveniently manage CMOS files                                         ;
  3. ;   Copyright © 1998 Iain Truskett                                                            ;
  4. ;===============================================================================================;
  5. ;   This program is free software; you can redistribute it and/or modify                        ;
  6. ;   it under the terms of the GNU General Public License as published by                        ;
  7. ;   the Free Software Foundation; either version 2 of the License, or                           ;
  8. ;   (at your option) any later version.                                                         ;
  9. ;                                                                                               ;
  10. ;   This program is distributed in the hope that it will be useful,                             ;
  11. ;   but WITHOUT ANY WARRANTY; without even the implied warranty of                              ;
  12. ;   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                               ;
  13. ;   GNU General Public License for more details.                                                ;
  14. ;                                                                                               ;
  15. ;   You should have received a copy of the GNU General Public License                           ;
  16. ;   along with this program; if not, write to the Free Software                                 ;
  17. ;   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.                                   ;
  18. ;===============================================================================================;
  19.  
  20. ; and before you start, yes, i know i don't comment as much as i should
  21.  
  22. ;preprocessor macros, directives et al
  23.  
  24. #smile                        ; produce a smile if compilation successful
  25. #name ^.!Siolfer.!RunImage            ; from default directory structure
  26. #strset Version = "1.17 (28-Aug-1998) © Iain Truskett 1998"
  27.  
  28. #set ibarmenu_saveintoboot_option    = 5    ; component id of saveintoboot menu option
  29.                         ; used when fading the option
  30. #set Buffer_Len                = 2048    ; extra workspace required. Must be at least 240
  31. #set MinimumWimp            = 316    ; earliest version of wimp to work with
  32. #set cmos_size                = 240    ; number of bytes of cmos
  33.  
  34. #set toolbox_loadhelp        =    &2    ; toolbox message number for loading help file
  35. #set toolbox_save_ascmos    =    &4    ; ...prepare saveas box info for Config (&FF2)
  36. #set toolbox_save_asutil    =    &3    ; ...prepare saveas box info for Utility (&FFC)
  37. #set toolbox_save_immediate    =    &5    ; ...save file into !Boot immediately
  38. #set toolbox_menu_opening    =    &7    ; ...fade menu items if needed
  39. #set toolbox_proginfo        =    &82B40    ; ...fill in URL and version
  40. #set toolbox_saveshown        =    &82BC0    ; ...know when to fill the saveas box
  41. #set toolbox_quitmsg        =    &82A91    ; ...time to die
  42.  
  43. #set message_dataload        =    3    ; wimp dataload message
  44. #set message_quit        =    0    ; wimp quit message
  45.  
  46. #set ProgInfo_SetVersion    =    1    ; Toolbox_ObjectMiscOp codes used
  47. #set ProgInfo_SetUri        =    7
  48. #set Menu_SetFade        =    2
  49. #set SaveAs_SetFileName        =    3
  50. #set SaveAs_SetFileType        =    5
  51. #set SaveAs_SetFileSize        =    7
  52. #set SaveAs_SetDataAddress    =    10
  53.  
  54. #set ip    =    12    ; index pointer
  55. #set sp    =    13    ; stack pointer
  56. #set lr    =    14    ; link register
  57. ;#set pc    =    15    ; program counter 'Hard-coded' in extAsm
  58.  
  59. #set XMessageTrans_Lookup    =    &061502    ; the various swi calls used in the program
  60. #set XOS_Byte            =    &020006 ; not actually needed to be declared, but done
  61. #set XOS_CLI            =    &020005 ; for easy cross compilation stuff
  62. #set XOS_Exit            =    &020011
  63. #set XOS_File            =    &020008
  64. #set XOS_ReadMonotonicTime    =    &020042
  65. #set XOS_ReadVarVal        =    &020023
  66. #set XToolbox_Initialise    =    &064ECF
  67. #set XToolbox_ObjectMiscOp    =    &064EC6
  68. #set XWimp_PollIdle        =    &0600E1
  69. #set XWimp_ReportError        =    &0600DF
  70. #set XWimp_SlotSize        =    &0600EC
  71.  
  72. ;el code
  73. ;===============================================================================================;
  74. ; ensure memory requirements are fulfilled                                                      ;
  75. ;===============================================================================================;
  76.     MOV    R0,#4096        ; make sure we have at least 4KB
  77.     MVN    R1,#0            ; of memory available
  78.     SWI    XWimp_SlotSize        ; (minimum page size so shouldn't fail)
  79.     ADR    sp,end_of_program    ; sp is workspace
  80.     ADD    sp,sp,#Buffer_Len    ; tack some more memory onto end of workspace
  81.     MOV    ip,sp            ; ip is handy variable
  82.  
  83. ;===============================================================================================;
  84. ; initialise task with the toolbox                                                              ;
  85. ;===============================================================================================;
  86.     MOV    R0,#0
  87.     MOV    R1,#MinimumWimp
  88.     ADR    R2,list
  89.     ADR    R3,elist
  90.     ADR    R4,resources
  91.     ADR    R5,mfd
  92.     ADR    R6,idblk
  93.     SWI    XToolbox_Initialise
  94.     BVS    diegracefully
  95. ;===============================================================================================;
  96. ; determine boot sequence type                                                                  ;
  97. ;===============================================================================================;
  98.                     ; determine if a boot sequence is being used or not
  99.     ADR    R0,varname2
  100.     MOV    R1,#0
  101.     MVN    R2,#1
  102.     MOV    R3,#0
  103.     MOV    R4,#0
  104.     SWI    XOS_ReadVarVal
  105.     CMP    R2,#0            ; if negative then new boot sequence, else not.
  106.     MOVGE    R0,#1
  107.     STRGEB    R0,fadeit        ; fade menu entry since old style is being used
  108.     BGE    poll
  109.                     ; RISC OS 3.5+ boot sequence is being used...
  110.     ADR    R0,varname        ; whichversion using '<Boot$Unique>' existence
  111.     MOV    R1,#0
  112.     MVN    R2,#1
  113.     MOV    R3,#0
  114.     MOV    R4,#0
  115.     SWI    XOS_ReadVarVal
  116.     CMP    R2,#0            ; see if R2 is still negative, thus variable would exist.
  117.     MOVLT    R0,#0            ; if variable does exist, save as 'Config'
  118.     MOVGE    R0,#1            ; otherwise save as 'Utility'
  119.     STRB    R0,savetype
  120.     ADRLT    R0,sixtysavepath    ; if variable does exist save into !boot for autoload
  121.     ADRGE    R0,fiftysavepath    ; else do tricky into PreDesk save.
  122.     STR    R0,savepath
  123.  
  124. ;===============================================================================================;
  125. ; traditional poll loop                                                                         ;
  126. ;===============================================================================================;
  127. .poll
  128.     SWI    XOS_ReadMonotonicTime    ; poll idle rate is
  129.     ADD    R2,R0,#4096        ; 4096 centiseconds
  130.     MOV    R0,#%1100000110001
  131.     MOV    R1,ip
  132.     SWI    XWimp_PollIdle
  133.     CMP    R0,#&200        ; toolbox messages
  134.     BEQ    tbox
  135.     CMP    R0,#&11            ; normal wimp messages
  136.     CMPNE    R0,#&12
  137.     BNE    poll
  138. ;-----------------------------------------------------------------------------------------------;
  139.     LDR    R3,[R1,#16]        ; normal wimp message handler
  140.     CMP    R3,#message_quit    ; diediedie
  141.     SWIEQ    XOS_Exit
  142.     CMP    R3,#message_dataload    ; wimpmsg data_load
  143.     BNE    poll            ; if not data_load, go back to polling
  144.     LDR    R0,[R1,#40]        ; data load from file
  145.     LDR    R2,ctype
  146.     CMP    R0,R2            ; only allow Config (&FF2) files.
  147.     BNE    poll            ; but don't cause an error
  148.     MOV    R0,#16
  149.     ADD    R1,R1,#44
  150.     ADR    R2,save_block_cmos
  151.     MOV    R3,#0
  152.     SWI    XOS_File
  153.     BVS    stayalive
  154.     BL    loadcmosdata
  155.     B    poll
  156.  
  157. .tbox    LDR    R3,[R1,#8]        ; toolbox
  158.  
  159.     LDR    R4,quitmsg
  160.     CMP    R3,R4
  161.     SWIEQ    XOS_Exit        ; die
  162.  
  163.     LDR    R4,proginfo
  164.     CMP    R3,R4
  165.     BEQ    proginfo_displayed    ; proginfo_displayed
  166.  
  167.     LDR    R4,saveshown
  168.     CMP    R3,R4
  169.     BEQ    save_shown        ; save_about_to_be_shown
  170.  
  171.     CMP    R3,#toolbox_menu_opening
  172.     BEQ    fademenu        ; menu_opening
  173.  
  174.     CMP    R3,#toolbox_loadhelp
  175.     BEQ    load_help        ; load_help
  176.  
  177.     CMP    R3,#toolbox_save_ascmos
  178.     BEQ    save_initialise_cmos    ; save_ascmos
  179.  
  180.     CMP    R3,#toolbox_save_asutil
  181.     BEQ    save_initialise_util    ; save_asutil
  182.  
  183.     CMP    R3,#toolbox_save_immediate
  184.     BEQ    save_do_boot        ; save_immediate
  185.     B    poll
  186.  
  187. ;===============================================================================================;
  188. ; fade menu entry in event of old sequence                                                      ;
  189. ;===============================================================================================;
  190. .fademenu
  191.     LDR    R1,thisobj
  192.     MOV    R0,#0
  193.     MOV    R2,#Menu_SetFade
  194.     MOV    R3,#ibarmenu_saveintoboot_option
  195.     LDRB    R4,fadeit
  196.     SWI    XToolbox_ObjectMiscOp
  197.     BVS    stayalive
  198.     B    poll
  199. ;===============================================================================================
  200. ; part of the save routines, here due to the way I've been cutting down on instructions
  201. .save_do_boot
  202.     LDR    R1,savepath
  203. ;===============================================================================================;
  204. ; Create directory path given canonicalised file name                                           ;
  205. ;===============================================================================================;
  206. ; external calls
  207. ;   drawerror
  208. ; on entry:
  209. ;    R1    = address of path to create
  210. ; on exit: R0,R2,R3,R4 all corrupted
  211. ; exits to: next instruction
  212. ; developed from a BASIC routine by Alan Wrigley IIRC.
  213.  
  214.     MOV    R2,#0             ; Convert path to series of NUL-terminated strings
  215.     MOV    R3,#0
  216.  
  217.     LDRB    R0,[R1,R3]
  218. .cpls    CMP    R0,#46
  219.     STREQB  R2,[R1,R3]
  220.     MOVEQ    R6,R3
  221.     ADD    R3,R3,#1
  222.     LDRB    R0,[R1,R3]
  223.     CMP    R0,#0
  224.     BNE    cpls
  225.  
  226. ;    MOV    R0,#8            ; OS_File 8
  227. ;    ADR    R1,pathtomake        ; Path to create
  228. ;    MOV    R2,#0            ; Offset from R1
  229.     MOV    R3,#46            ; Convert the NULs to periods ('.').
  230.     MOV    R4,#255            ; Directory entries, only used with networks.
  231.     MOV    R5,#1            ; path terminator
  232. .cpsl
  233.     MOV    R0,#8
  234.     SWI    XOS_File;R0-R1,R4    ; Create first level.
  235.     BVS    stayalive        ; Check for error, and live always
  236.     LDRB    R0,[R1,R2]
  237. .cpsld  CMP    R2,R6
  238.     BEQ    cpsrs
  239.     CMP    R0,#0
  240.     STREQB  R3,[R1,R2]
  241.     ADD    R2,R2,#1
  242.     LDRB    R0,[R1,R2]
  243.     CMP    R0,#1
  244.     BGT    cpsld
  245.     BNE    cpsl
  246.  
  247. .cpsrs
  248.     MOV    R2,#0            ; (offset from addrbase)
  249.     MOV    R3,#0            ; (NUL)
  250.     MOV    R4,#46            ; ('.')
  251. .cpsr    LDRB    R0,[R1,R2]
  252.     CMP    R0,#0            ; Test for char = 0x00 = null
  253.     STREQB  R4,[R1,R2]
  254.     CMP    R0,#1            ; Test for char = 0x01
  255.     SUBEQ    R2,R2,#1
  256.     STREQB  R3,[R1,R2]
  257.     ADD    R2,R2,#1
  258.     BNE    cpsr
  259.  
  260. ;===============================================================================================;
  261. ; actual cmos saving routines                                                                   ;
  262. ;===============================================================================================;
  263.     BL    getcmosdata
  264.     LDRB    R7,savetype
  265.  
  266. ; on entry R1 = path to save to
  267.     MOV    R0,#10
  268.     CMP    R7,#0            ; Set conditions
  269.     LDREQ    R2,ctype        ; If saving as config    ; file type
  270.     LDRNE    R2,utype        ; If saving as utility
  271.     ADREQ    R4,cmos            ; If saving as config    ; start address
  272.     ADRNE    R4,startutility        ; If saving as utility
  273.     ADR    R5,cmos
  274.     ADD    R5,R5,#cmos_size                ; end address
  275.     SWI    XOS_File        ; Save file
  276.     BVS    stayalive
  277.     B    poll
  278.  
  279. .getcmosdata
  280.     STMFD    sp!,{R0-R3,lr}
  281.     MOV    R1,#cmos_size+1        ; Start at top of memory and work down
  282.     ADR    R3,cmos            ; Storage base
  283.     MOV    R0,#161            ; OS_Byte reason code
  284. .loop1    SUBS    R1,R1,#1        ; Decrement R1 and set flags
  285.     SWI    XOS_Byte        ; Call OS_Byte
  286.     STRB    R2,[R3,R1]        ; Store result at R3+R1
  287.     BNE    loop1            ; If R1=0 then die else repeat.
  288.     LDMFD    sp!,{R0-R3,pc}
  289.  
  290. ;===============================================================================================;
  291. ; save box                                                                                      ;
  292. ;===============================================================================================;
  293. .save_initialise_cmos            ; initialise save box for CMOS saving
  294.     LDR    R1,ctype
  295.     STR    R1,save_type
  296.     MOV    R1,#cmos_size
  297.     STR    R1,save_size
  298.     ADR    R1,save_block_cmos
  299.     STR    R1,save_block
  300.     B    poll
  301. .save_initialise_util            ; initialise save box for Utility saving
  302.     LDR    R1,utype
  303.     STR    R1,save_type
  304.     MOV    R1,#(cmos_size+endload-startutility)
  305.     STR    R1,save_size
  306.     ADR    R1,startutility
  307.     STR    R1,save_block
  308.     B    poll
  309. .save_shown                ; save box preshowing warning handler
  310.     ADR    R1,savename
  311.     BL    messlookup
  312.     MOV    R0,#0
  313.     LDR    R1,thisobj
  314.     MOV    R2,#SaveAs_SetFileName
  315.     SWI    XToolbox_ObjectMiscOp
  316.     MOV    R2,#SaveAs_SetFileType
  317.     LDR    R3,save_type
  318.     SWI    XToolbox_ObjectMiscOp
  319.     MOV    R2,#SaveAs_SetFileSize
  320.     LDR    R3,save_size
  321.     SWI    XToolbox_ObjectMiscOp
  322.     MOV    R2,#SaveAs_SetDataAddress
  323.     MOV    R4,R3
  324.     LDR    R3,save_block
  325.     SWI    XToolbox_ObjectMiscOp
  326.     BL    getcmosdata
  327.     B    poll
  328.  
  329. ;===============================================================================================;
  330. ; load help                                                                                     ;
  331. ;===============================================================================================;
  332. .load_help
  333.     ADR    R1,loadhelppath
  334.     BL    messlookup
  335.     MOV    R0,R3
  336.     SWI    XOS_CLI
  337.     BVS    stayalive
  338.     B    poll
  339.  
  340. ;===============================================================================================;
  341. ; look up a messagetrans token                                                                  ;
  342. ;===============================================================================================;
  343. ; On entry:    R1 = token
  344. ; On exit:    R3 = translated
  345. ; other registers preserved
  346.  
  347. .messlookup
  348.     STMFD    sp!,{R0,R2-R4,lr}
  349.     ADR    R0,mfd
  350.     MOV    R2,#0
  351.     SWI    XMessageTrans_Lookup
  352.     MOV    R3,R2
  353.     LDMFD    sp!,{R0-R2,R4,pc}
  354.  
  355. ;===============================================================================================;
  356. ; proginfo preshow warning, so write version and url in                                         ;
  357. ;===============================================================================================;
  358. .proginfo_displayed
  359.     MOV    R0,#0
  360. ;    ADR    R2,idblk
  361. ;    LDR    R4,[R2,#16]
  362.     LDR    R4,thisobj
  363.  
  364.     ADR    R1,version        ; Put current version in ProgInfo box
  365.     BL    messlookup
  366.     MOV    R1,R4
  367.     MOV    R2,#ProgInfo_SetVersion
  368.     SWI    XToolbox_ObjectMiscOp
  369.  
  370.     ADR    R1,url            ; Put url in ProgInfo box
  371.     BL    messlookup        ; only available in ProgInfo 0.14 or later, tmk
  372.     MOV    R1,R4
  373.     MOV    R2,#ProgInfo_SetUri
  374.     SWI    XToolbox_ObjectMiscOp
  375.  
  376.     B    poll
  377.  
  378. ;===============================================================================================;
  379. ; error handling                                                                                ;
  380. ;===============================================================================================;
  381. .drawerror
  382.     ADR    R2,name            ; report errors and return to caller
  383.     BL    messlookup
  384.     MOV    R1,#1
  385.     SWI    XWimp_ReportError
  386.     MOV    pc,lr
  387. .stayalive
  388.     BL    drawerror        ; report error and poll
  389.     B    poll
  390. .diegracefully
  391.     BL    drawerror        ; report error and die
  392.     SWI    XOS_Exit
  393.  
  394. ;===============================================================================================;
  395. ; lots of data for all the family                                                               ;
  396. ;===============================================================================================;
  397.  
  398. ALIGN
  399. ; -----------------------------------------------------------------------------
  400. .elist
  401.         DCD    toolbox_loadhelp            ; toolbox message list
  402.         DCD    toolbox_save_ascmos
  403.         DCD    toolbox_save_asutil
  404.         DCD    toolbox_save_immediate
  405.         DCD    toolbox_menu_opening
  406. .proginfo    DCD    toolbox_proginfo
  407. .saveshown    DCD    toolbox_saveshown
  408. .quitmsg    DCD    toolbox_quitmsg
  409.         DCD    0            ; end of list
  410. ; -----------------------------------------------------------------------------
  411. .resources    DCB    "|<siolfer$Dir>",0    ; program resources + boot path
  412.         ALIGN
  413. .name        DCB    "T",0            ; Program name
  414. .loadhelppath    DCB    "C",0            ; help command
  415. .version    DCB    "V",0            ; version of program
  416. .url        DCB    "U",0            ; url of program's website
  417. ; ----------------------------------------------------------------------
  418.         ALIGN
  419. ; -------------------- Program specific bits --------------------
  420. .fiftysavepath    DCB    "|<Boot$ToBeLoaded>.!!!!CMOS",0,1    ; Save path for RISC OS 3.5
  421.         ALIGN
  422. .sixtysavepath    DCB    "|<Boot$Dir>.MchConfig.|<Boot$Unique>."    ; Save path for new !Boot
  423.         DCB    "!RO|<Boot$OSVersion>CMOS",0,1
  424.         ALIGN
  425. .varname    DCB "Boot$Unique",0
  426.         ALIGN
  427. .varname2    DCB "Boot$ToBeTasks",0
  428.         ALIGN
  429. ;-----------------------------------------------------------------------------
  430. .mfd        DCD    0 ;0            ; message file descriptor
  431.         DCD    0 ;4
  432.         DCD    0 ;8
  433.         DCD    0 ;12
  434. .idblk      DCD    0 ;0  ancestor obj    ; toolbox id block
  435.         DCD    0 ;4  ancestor cmp
  436.         DCD    0 ;8  parent obj
  437.         DCD    0 ;12 parent cmp
  438. .thisobj    DCD    0 ;16 this obj
  439.         DCD    0 ;24 this cmp
  440. ;-----------------------------------------------------------------------------
  441. .list        DCD    message_dataload    ; Message_DataLoad    ; wimp message list
  442. ;        DCD    0            ; Message_Quit / end of list
  443. ; -----------------------------------------------------------------------------
  444. .savepath    DCD    0
  445. ;-----------------------------------------------------------------------------
  446. .save_type    DCD    0
  447. .save_size    DCD    0
  448. .save_block    DCD    0
  449. ;-----------------------------------------------------------------------------
  450. .utype        DCD    &FFC
  451. .ctype        DCD    &FF2
  452. .savename    DCB    "S",0
  453. .fadeit        DCB    0
  454. .savetype    DCB    0
  455.         ALIGN
  456.  
  457. ; =============== The bit which is saved ===============
  458.  
  459. ; -------------------- Load program --------------------
  460. .startutility
  461. .loadcmosdata
  462.     STMFD    sp!,{R0-R3,lr}
  463.     MOV    R1,#cmos_size+1    ; First byte
  464.     ADR    R3,cmos        ; Storage base
  465.     MOV    R0,#162        ; OS_Byte reason code
  466. .loop2    SUBS    R1,R1,#1    ; Decrement R1 and set flags
  467.     LDRB    R2,[R3,R1]    ; Load byte from R3+R1
  468.     SWI    XOS_Byte    ; Call OS_Byte
  469.     BNE    loop2        ; If not equal repeat.
  470.     LDMFD    sp!,{R0-R3,pc}
  471. .endload
  472. ; ---------------- Buffer for CMOS data ----------------
  473. ; Label for end of save. Anything after here is ignored
  474. ; Buffer_Len amount of bytes will be tacked onto here.
  475. .save_block_cmos
  476. .cmos
  477. .end_of_program
  478.     DCB    10,10,Version,10
  479.  
  480. ; The End.
  481.