Home » Archimedes archive » Acorn Computing » 1994 09 subscription disc.adf » 9409s » MEMCPatch/!ReadMe
MEMCPatch/!ReadMe
This website contains an archive of files for the Acorn Electron, BBC Micro, Acorn Archimedes, Commodore 16 and Commodore 64 computers, which Dominic Ford has rescued from his private collection of floppy disks and cassettes.
Some of these files were originally commercial releases in the 1980s and 1990s, but they are now widely available online. I assume that copyright over them is no longer being asserted. If you own the copyright and would like files to be removed, please contact me.
Tape/disk: | Home » Archimedes archive » Acorn Computing » 1994 09 subscription disc.adf » 9409s |
Filename: | MEMCPatch/!ReadMe |
Read OK: | ✔ |
File size: | 0981 bytes |
Load address: | 0000 |
Exec address: | 0000 |
File contents
Many programs running under RISC OS 2 tried to squeeze every ounce of speed out of the machine. One common trick to achieve this was to speed up the ROMs from 4MHz to 8MHz, and thus doing away with the need for a *RMFaster, the legal way to speed up the ROMs, which takes up memory. Some programs performed a check to see whether the ROMs could be speeded up, while others, mainly games and Public Domain programs, didn't bother and just performed a SYS "OS_UpdateMEMC",64,64. This was fine under RISC OS 2 as most ROMs could be speeded up. However, when RISC OS 3 arrived, the ROMs acted differently and when this call is issued the computer crashes and needs to be reset. Some of these calls were in easily alterable BASIC code, but others were embedded deeply in machine code files, virtually inaccessible, except to those with a disassembler and a lot of time. This is where MEMCPatch comes in. Instead of hacking into the code to try and remove the offending call, load the MEMCPatch module before running the program. This module intercepts any call to OS_UpdateMEMC and makes sure that bit 6 of the MEMC control register is never set. If a call with bit 6 set is detected, bit 6 is cleared and then the call is carried out as normal, to ensure that any parameters requested are returned intact. If OS_UpdateMEMC was any normal, everyday SWI, it would be software vectored, so that it could be modified easily. But because it is associated with the hardware, and there are very few reasons why you would want to alter it, it is not software vectored, and therefore is more difficult to alter. MEMCPatch redirects the hardware vector at &08 to its own routine, and then stores the old instruction within itself. Whenever a SWI is called, part of MEMCPatch is run, which checks to see if the SWI being called is OS_UpdateMEMC, and if it is clears bit 6 of both the new value to be set and the mask, and then continues with the call. If the SWI is not OS_UpdateMEMC then the original instruction is run which calls the RISC OS SWI handler. This is the method outlined in the December Techforum, and MEMCPatch also serves as a more useful example. Indeed, parts of the code are taken from the Zippy demo of this function. Note: The type of game that tries illegal pokes for speed is also the type that does a RMClear and therefore removes the MEMCPatch module Theo Markettos 5 Willow Close Liphook Hants GU30 7HX
00000000 4d 61 6e 79 20 70 72 6f 67 72 61 6d 73 20 72 75 |Many programs ru| 00000010 6e 6e 69 6e 67 20 75 6e 64 65 72 20 52 49 53 43 |nning under RISC| 00000020 20 4f 53 20 32 20 74 72 69 65 64 20 74 6f 20 73 | OS 2 tried to s| 00000030 71 75 65 65 7a 65 20 65 76 65 72 79 20 6f 75 6e |queeze every oun| 00000040 63 65 20 6f 66 20 73 70 65 65 64 0a 6f 75 74 20 |ce of speed.out | 00000050 6f 66 20 74 68 65 20 6d 61 63 68 69 6e 65 2e 20 |of the machine. | 00000060 20 4f 6e 65 20 63 6f 6d 6d 6f 6e 20 74 72 69 63 | One common tric| 00000070 6b 20 74 6f 20 61 63 68 69 65 76 65 20 74 68 69 |k to achieve thi| 00000080 73 20 77 61 73 20 74 6f 20 73 70 65 65 64 20 75 |s was to speed u| 00000090 70 20 74 68 65 0a 52 4f 4d 73 20 66 72 6f 6d 20 |p the.ROMs from | 000000a0 34 4d 48 7a 20 74 6f 20 38 4d 48 7a 2c 20 61 6e |4MHz to 8MHz, an| 000000b0 64 20 74 68 75 73 20 64 6f 69 6e 67 20 61 77 61 |d thus doing awa| 000000c0 79 20 77 69 74 68 20 74 68 65 20 6e 65 65 64 20 |y with the need | 000000d0 66 6f 72 20 61 20 2a 52 4d 46 61 73 74 65 72 2c |for a *RMFaster,| 000000e0 0a 74 68 65 20 6c 65 67 61 6c 20 77 61 79 20 74 |.the legal way t| 000000f0 6f 20 73 70 65 65 64 20 75 70 20 74 68 65 20 52 |o speed up the R| 00000100 4f 4d 73 2c 20 77 68 69 63 68 20 74 61 6b 65 73 |OMs, which takes| 00000110 20 75 70 20 6d 65 6d 6f 72 79 2e 20 20 53 6f 6d | up memory. Som| 00000120 65 20 70 72 6f 67 72 61 6d 73 0a 70 65 72 66 6f |e programs.perfo| 00000130 72 6d 65 64 20 61 20 63 68 65 63 6b 20 74 6f 20 |rmed a check to | 00000140 73 65 65 20 77 68 65 74 68 65 72 20 74 68 65 20 |see whether the | 00000150 52 4f 4d 73 20 63 6f 75 6c 64 20 62 65 20 73 70 |ROMs could be sp| 00000160 65 65 64 65 64 20 75 70 2c 20 77 68 69 6c 65 20 |eeded up, while | 00000170 6f 74 68 65 72 73 2c 0a 6d 61 69 6e 6c 79 20 67 |others,.mainly g| 00000180 61 6d 65 73 20 61 6e 64 20 50 75 62 6c 69 63 20 |ames and Public | 00000190 44 6f 6d 61 69 6e 20 70 72 6f 67 72 61 6d 73 2c |Domain programs,| 000001a0 20 64 69 64 6e 27 74 20 62 6f 74 68 65 72 20 61 | didn't bother a| 000001b0 6e 64 20 6a 75 73 74 20 70 65 72 66 6f 72 6d 65 |nd just performe| 000001c0 64 20 61 0a 53 59 53 20 22 4f 53 5f 55 70 64 61 |d a.SYS "OS_Upda| 000001d0 74 65 4d 45 4d 43 22 2c 36 34 2c 36 34 2e 20 20 |teMEMC",64,64. | 000001e0 54 68 69 73 20 77 61 73 20 66 69 6e 65 20 75 6e |This was fine un| 000001f0 64 65 72 20 52 49 53 43 20 4f 53 20 32 20 61 73 |der RISC OS 2 as| 00000200 20 6d 6f 73 74 20 52 4f 4d 73 20 63 6f 75 6c 64 | most ROMs could| 00000210 0a 62 65 20 73 70 65 65 64 65 64 20 75 70 2e 20 |.be speeded up. | 00000220 20 48 6f 77 65 76 65 72 2c 20 77 68 65 6e 20 52 | However, when R| 00000230 49 53 43 20 4f 53 20 33 20 61 72 72 69 76 65 64 |ISC OS 3 arrived| 00000240 2c 20 74 68 65 20 52 4f 4d 73 20 61 63 74 65 64 |, the ROMs acted| 00000250 20 64 69 66 66 65 72 65 6e 74 6c 79 0a 61 6e 64 | differently.and| 00000260 20 77 68 65 6e 20 74 68 69 73 20 63 61 6c 6c 20 | when this call | 00000270 69 73 20 69 73 73 75 65 64 20 74 68 65 20 63 6f |is issued the co| 00000280 6d 70 75 74 65 72 20 63 72 61 73 68 65 73 20 61 |mputer crashes a| 00000290 6e 64 20 6e 65 65 64 73 20 74 6f 20 62 65 20 72 |nd needs to be r| 000002a0 65 73 65 74 2e 20 0a 53 6f 6d 65 20 6f 66 20 74 |eset. .Some of t| 000002b0 68 65 73 65 20 63 61 6c 6c 73 20 77 65 72 65 20 |hese calls were | 000002c0 69 6e 20 65 61 73 69 6c 79 20 61 6c 74 65 72 61 |in easily altera| 000002d0 62 6c 65 20 42 41 53 49 43 20 63 6f 64 65 2c 20 |ble BASIC code, | 000002e0 62 75 74 20 6f 74 68 65 72 73 20 77 65 72 65 0a |but others were.| 000002f0 65 6d 62 65 64 64 65 64 20 64 65 65 70 6c 79 20 |embedded deeply | 00000300 69 6e 20 6d 61 63 68 69 6e 65 20 63 6f 64 65 20 |in machine code | 00000310 66 69 6c 65 73 2c 20 76 69 72 74 75 61 6c 6c 79 |files, virtually| 00000320 20 69 6e 61 63 63 65 73 73 69 62 6c 65 2c 20 65 | inaccessible, e| 00000330 78 63 65 70 74 20 74 6f 0a 74 68 6f 73 65 20 77 |xcept to.those w| 00000340 69 74 68 20 61 20 64 69 73 61 73 73 65 6d 62 6c |ith a disassembl| 00000350 65 72 20 61 6e 64 20 61 20 6c 6f 74 20 6f 66 20 |er and a lot of | 00000360 74 69 6d 65 2e 20 20 54 68 69 73 20 69 73 20 77 |time. This is w| 00000370 68 65 72 65 20 4d 45 4d 43 50 61 74 63 68 20 63 |here MEMCPatch c| 00000380 6f 6d 65 73 0a 69 6e 2e 20 20 49 6e 73 74 65 61 |omes.in. Instea| 00000390 64 20 6f 66 20 68 61 63 6b 69 6e 67 20 69 6e 74 |d of hacking int| 000003a0 6f 20 74 68 65 20 63 6f 64 65 20 74 6f 20 74 72 |o the code to tr| 000003b0 79 20 61 6e 64 20 72 65 6d 6f 76 65 20 74 68 65 |y and remove the| 000003c0 20 6f 66 66 65 6e 64 69 6e 67 20 63 61 6c 6c 2c | offending call,| 000003d0 0a 6c 6f 61 64 20 74 68 65 20 4d 45 4d 43 50 61 |.load the MEMCPa| 000003e0 74 63 68 20 6d 6f 64 75 6c 65 20 62 65 66 6f 72 |tch module befor| 000003f0 65 20 72 75 6e 6e 69 6e 67 20 74 68 65 20 70 72 |e running the pr| 00000400 6f 67 72 61 6d 2e 20 20 54 68 69 73 20 6d 6f 64 |ogram. This mod| 00000410 75 6c 65 0a 69 6e 74 65 72 63 65 70 74 73 20 61 |ule.intercepts a| 00000420 6e 79 20 63 61 6c 6c 20 74 6f 20 4f 53 5f 55 70 |ny call to OS_Up| 00000430 64 61 74 65 4d 45 4d 43 20 61 6e 64 20 6d 61 6b |dateMEMC and mak| 00000440 65 73 20 73 75 72 65 20 74 68 61 74 20 62 69 74 |es sure that bit| 00000450 20 36 20 6f 66 20 74 68 65 20 4d 45 4d 43 0a 63 | 6 of the MEMC.c| 00000460 6f 6e 74 72 6f 6c 20 72 65 67 69 73 74 65 72 20 |ontrol register | 00000470 69 73 20 6e 65 76 65 72 20 73 65 74 2e 20 20 49 |is never set. I| 00000480 66 20 61 20 63 61 6c 6c 20 77 69 74 68 20 62 69 |f a call with bi| 00000490 74 20 36 20 73 65 74 20 69 73 20 64 65 74 65 63 |t 6 set is detec| 000004a0 74 65 64 2c 20 62 69 74 20 36 0a 69 73 20 63 6c |ted, bit 6.is cl| 000004b0 65 61 72 65 64 20 61 6e 64 20 74 68 65 6e 20 74 |eared and then t| 000004c0 68 65 20 63 61 6c 6c 20 69 73 20 63 61 72 72 69 |he call is carri| 000004d0 65 64 20 6f 75 74 20 61 73 20 6e 6f 72 6d 61 6c |ed out as normal| 000004e0 2c 20 74 6f 20 65 6e 73 75 72 65 20 74 68 61 74 |, to ensure that| 000004f0 20 61 6e 79 0a 70 61 72 61 6d 65 74 65 72 73 20 | any.parameters | 00000500 72 65 71 75 65 73 74 65 64 20 61 72 65 20 72 65 |requested are re| 00000510 74 75 72 6e 65 64 20 69 6e 74 61 63 74 2e 20 0a |turned intact. .| 00000520 0a 49 66 20 4f 53 5f 55 70 64 61 74 65 4d 45 4d |.If OS_UpdateMEM| 00000530 43 20 77 61 73 20 61 6e 79 20 6e 6f 72 6d 61 6c |C was any normal| 00000540 2c 20 65 76 65 72 79 64 61 79 20 53 57 49 2c 20 |, everyday SWI, | 00000550 69 74 20 77 6f 75 6c 64 20 62 65 20 73 6f 66 74 |it would be soft| 00000560 77 61 72 65 0a 76 65 63 74 6f 72 65 64 2c 20 73 |ware.vectored, s| 00000570 6f 20 74 68 61 74 20 69 74 20 63 6f 75 6c 64 20 |o that it could | 00000580 62 65 20 6d 6f 64 69 66 69 65 64 20 65 61 73 69 |be modified easi| 00000590 6c 79 2e 20 20 42 75 74 20 62 65 63 61 75 73 65 |ly. But because| 000005a0 20 69 74 20 69 73 20 61 73 73 6f 63 69 61 74 65 | it is associate| 000005b0 64 0a 77 69 74 68 20 74 68 65 20 68 61 72 64 77 |d.with the hardw| 000005c0 61 72 65 2c 20 61 6e 64 20 74 68 65 72 65 20 61 |are, and there a| 000005d0 72 65 20 76 65 72 79 20 66 65 77 20 72 65 61 73 |re very few reas| 000005e0 6f 6e 73 20 77 68 79 20 79 6f 75 20 77 6f 75 6c |ons why you woul| 000005f0 64 20 77 61 6e 74 20 74 6f 0a 61 6c 74 65 72 20 |d want to.alter | 00000600 69 74 2c 20 69 74 20 69 73 20 6e 6f 74 20 73 6f |it, it is not so| 00000610 66 74 77 61 72 65 20 76 65 63 74 6f 72 65 64 2c |ftware vectored,| 00000620 20 61 6e 64 20 74 68 65 72 65 66 6f 72 65 20 69 | and therefore i| 00000630 73 20 6d 6f 72 65 20 64 69 66 66 69 63 75 6c 74 |s more difficult| 00000640 20 74 6f 0a 61 6c 74 65 72 2e 20 20 4d 45 4d 43 | to.alter. MEMC| 00000650 50 61 74 63 68 20 72 65 64 69 72 65 63 74 73 20 |Patch redirects | 00000660 74 68 65 20 68 61 72 64 77 61 72 65 20 76 65 63 |the hardware vec| 00000670 74 6f 72 20 61 74 20 26 30 38 20 74 6f 20 69 74 |tor at &08 to it| 00000680 73 20 6f 77 6e 20 72 6f 75 74 69 6e 65 2c 0a 61 |s own routine,.a| 00000690 6e 64 20 74 68 65 6e 20 73 74 6f 72 65 73 20 74 |nd then stores t| 000006a0 68 65 20 6f 6c 64 20 69 6e 73 74 72 75 63 74 69 |he old instructi| 000006b0 6f 6e 20 77 69 74 68 69 6e 20 69 74 73 65 6c 66 |on within itself| 000006c0 2e 20 20 57 68 65 6e 65 76 65 72 20 61 20 53 57 |. Whenever a SW| 000006d0 49 20 69 73 0a 63 61 6c 6c 65 64 2c 20 70 61 72 |I is.called, par| 000006e0 74 20 6f 66 20 4d 45 4d 43 50 61 74 63 68 20 69 |t of MEMCPatch i| 000006f0 73 20 72 75 6e 2c 20 77 68 69 63 68 20 63 68 65 |s run, which che| 00000700 63 6b 73 20 74 6f 20 73 65 65 20 69 66 20 74 68 |cks to see if th| 00000710 65 20 53 57 49 20 62 65 69 6e 67 0a 63 61 6c 6c |e SWI being.call| 00000720 65 64 20 69 73 20 4f 53 5f 55 70 64 61 74 65 4d |ed is OS_UpdateM| 00000730 45 4d 43 2c 20 61 6e 64 20 69 66 20 69 74 20 69 |EMC, and if it i| 00000740 73 20 63 6c 65 61 72 73 20 62 69 74 20 36 20 6f |s clears bit 6 o| 00000750 66 20 62 6f 74 68 20 74 68 65 20 6e 65 77 20 76 |f both the new v| 00000760 61 6c 75 65 20 74 6f 0a 62 65 20 73 65 74 20 61 |alue to.be set a| 00000770 6e 64 20 74 68 65 20 6d 61 73 6b 2c 20 61 6e 64 |nd the mask, and| 00000780 20 74 68 65 6e 20 63 6f 6e 74 69 6e 75 65 73 20 | then continues | 00000790 77 69 74 68 20 74 68 65 20 63 61 6c 6c 2e 20 20 |with the call. | 000007a0 49 66 20 74 68 65 20 53 57 49 20 69 73 20 6e 6f |If the SWI is no| 000007b0 74 0a 4f 53 5f 55 70 64 61 74 65 4d 45 4d 43 20 |t.OS_UpdateMEMC | 000007c0 74 68 65 6e 20 74 68 65 20 6f 72 69 67 69 6e 61 |then the origina| 000007d0 6c 20 69 6e 73 74 72 75 63 74 69 6f 6e 20 69 73 |l instruction is| 000007e0 20 72 75 6e 20 77 68 69 63 68 20 63 61 6c 6c 73 | run which calls| 000007f0 20 74 68 65 20 52 49 53 43 20 4f 53 0a 53 57 49 | the RISC OS.SWI| 00000800 20 68 61 6e 64 6c 65 72 2e 20 20 54 68 69 73 20 | handler. This | 00000810 69 73 20 74 68 65 20 6d 65 74 68 6f 64 20 6f 75 |is the method ou| 00000820 74 6c 69 6e 65 64 20 69 6e 20 74 68 65 20 44 65 |tlined in the De| 00000830 63 65 6d 62 65 72 20 54 65 63 68 66 6f 72 75 6d |cember Techforum| 00000840 2c 20 61 6e 64 0a 4d 45 4d 43 50 61 74 63 68 20 |, and.MEMCPatch | 00000850 61 6c 73 6f 20 73 65 72 76 65 73 20 61 73 20 61 |also serves as a| 00000860 20 6d 6f 72 65 20 75 73 65 66 75 6c 20 65 78 61 | more useful exa| 00000870 6d 70 6c 65 2e 20 20 49 6e 64 65 65 64 2c 20 70 |mple. Indeed, p| 00000880 61 72 74 73 20 6f 66 20 74 68 65 20 63 6f 64 65 |arts of the code| 00000890 0a 61 72 65 20 74 61 6b 65 6e 20 66 72 6f 6d 20 |.are taken from | 000008a0 74 68 65 20 5a 69 70 70 79 20 64 65 6d 6f 20 6f |the Zippy demo o| 000008b0 66 20 74 68 69 73 20 66 75 6e 63 74 69 6f 6e 2e |f this function.| 000008c0 0a 0a 4e 6f 74 65 3a 20 54 68 65 20 74 79 70 65 |..Note: The type| 000008d0 20 6f 66 20 67 61 6d 65 20 74 68 61 74 20 74 72 | of game that tr| 000008e0 69 65 73 20 69 6c 6c 65 67 61 6c 20 70 6f 6b 65 |ies illegal poke| 000008f0 73 20 66 6f 72 20 73 70 65 65 64 20 69 73 20 61 |s for speed is a| 00000900 6c 73 6f 20 74 68 65 20 74 79 70 65 0a 74 68 61 |lso the type.tha| 00000910 74 20 64 6f 65 73 20 61 20 52 4d 43 6c 65 61 72 |t does a RMClear| 00000920 20 61 6e 64 20 74 68 65 72 65 66 6f 72 65 20 72 | and therefore r| 00000930 65 6d 6f 76 65 73 20 74 68 65 20 4d 45 4d 43 50 |emoves the MEMCP| 00000940 61 74 63 68 20 6d 6f 64 75 6c 65 0a 0a 54 68 65 |atch module..The| 00000950 6f 20 4d 61 72 6b 65 74 74 6f 73 0a 35 20 57 69 |o Markettos.5 Wi| 00000960 6c 6c 6f 77 20 43 6c 6f 73 65 0a 4c 69 70 68 6f |llow Close.Lipho| 00000970 6f 6b 0a 48 61 6e 74 73 0a 47 55 33 30 20 37 48 |ok.Hants.GU30 7H| 00000980 58 |X| 00000981