| www.retrosoftware.co.uk http://www.retrosoftware.co.uk/forum/ |
|
| Writing code to run from ROM or SWRAM http://www.retrosoftware.co.uk/forum/viewtopic.php?f=73&t=830 |
Page 1 of 1 |
| Author: | sweh [ Mon Jun 24, 2013 6:47 pm ] |
| Post subject: | Writing code to run from ROM or SWRAM |
(also posted to *.) I'm thinking of writing a new ROM. This ROM will require workspace memory. What I would like to do is have the ROM autodetect if it's running from SWR, and if so then use memory from &B800 (for example) else use the standard service calls to reserve memory. The detection code is simple enough, but what I don't know is how to _efficiently_ access the memory. For example, what would be the best equivalent of Code: ORG &E00 myvar1 DS 1 myvar2 DS 1 myvar3 DS 1 ORG &8000 .... LDA myvar1 STA myvar2 ... I can no longer refer to myvar1/2/3 in absolute terms, yet setting up an indirection each and every time I need to access a variable (and preserving a register since the 6502 doesn't have a (zp) address mode) seems painful. Is there a better way? |
|
| Author: | tricky [ Sun Jun 30, 2013 7:39 am ] |
| Post subject: | Re: Writing code to run from ROM or SWRAM |
If you have a few small common routines, you could copy them into your scratch space and patch the addresses. If you don't need much space, you could use the end of the stack page for temporary storage, but you would probably need to copy them each time. Other than those "hacks", it isn't that bad. |
|
| Author: | MartinP [ Fri Jul 11, 2014 7:35 pm ] |
| Post subject: | Re: Writing code to run from ROM or SWRAM |
I know it's been a while since the original question was posted, but I thought I'd add my £0.02's-worth (fow what it's worth)... As part of my "MUTILS" ROM (available under the thread "A pair of ROMs - at last!" elsewhere in the 8-bit Acorn Programming forum), I wanted to find out if a particular Sideways socket was empty, contained a ROM, or contained Sideways RAM. The solution I used for the "Sideways RAM" test (and look for the routine "SWRTEST" in the source code) was to put the test routine onto the stack, which would then switch to the relevant Sideways socket and test the "version" byte (address: &8008) to see if it was writable. Would this kind of test achieve what you're after? --Martin |
|
| Author: | sweh [ Fri Jul 11, 2014 7:49 pm ] |
| Post subject: | Re: Writing code to run from ROM or SWRAM |
Oh, I know how to test to see if a bank is RAM or not. I wrote that BITD for my Solidisk 2M128 board, and revised it recently to handle Steve Picton's RAM/ROM board (needed delays between the write and the read 'cos otherwise the FLASH ROM would fake it out). That's the easy part I mentioned The hard part is, once I've detected I'm running in SWR, how to efficiently access the memory. The method mentioned by tricky is a good idea. Patching my own binary might also work. I'll have to see how much free space I have after I've actually sat down and written the ROM (a round tuit; one day I'll get a round tuit....) |
|
| Author: | MartinP [ Fri Jul 11, 2014 8:04 pm ] |
| Post subject: | Re: Writing code to run from ROM or SWRAM |
Oops - my bad, I'd speed-read the original post, so mis-read it. A thought re using main RAM or Sideways RAM; depending on the size/complexity of the code, one solution could be to have duplicate routines for the "memory access" sections of the code, with the "main RAM" version being the default, and patching the JSR's to switch to the "Sideways RAM" versions during initialisation (say, when the ROM's service code receives the "Absolute Workspace" call). --Martin |
|
| Author: | sweh [ Fri Jul 11, 2014 8:42 pm ] |
| Post subject: | Re: Writing code to run from ROM or SWRAM |
Yup, that's one of the ideas on the table. However it could turn out to be impractical if dealing with too many locations; I'm not sure I'd want to do "JSR read_var1_into_A" instead of LDA var1 (and similar to LDY and LDX) for a few hundred variables! Another thought I had was to assemble my code twice; once with the variable base at 0e00, once at b800 and then use the difference to create a "patch table"; basically loop doing LDA patch_locn; ADC #&AA: STA patch_locn for each location in the patch table. |
|
| Page 1 of 1 | All times are UTC [ DST ] |
| Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group http://www.phpbb.com/ |
|