[comp.sys.cbm] C-128 programming questions concerning memory and ML

lockemer@iccgcc.decnet.ab.com (08/30/90)

I need some help in three areas of 128 ML programming.

1) I am trying to figure out how to use bank switching properly. Some questions
I have are:

- Can you transfer control to another bank configuration that will block out
  the area of memory that the program is currently executing in? If so, how?

For example:
             Bank 0                 Bank 15
	+---------------+       +---------------+
$ffd2	|LDA #0		| $ffd2	| BSOUT ROUTINE |
	|STA $ff00	|       |		|
	|JSR $ffd2	|       |               |

I don't think this works since when the bank is switched to 15, it would not
get to execute the jsr $ffd2, right?


2) Could comeone explain the purpose and/or benefits of relocating zero page
   and explain how to do it? What I don't understand most is, once zero page
   is relocated, does the system use this new zero page as well, or does it
   still use the original zero page? I'm concerned about what happens when
   interrupts take place. If it uses the new zero page, then is it necessary
   to copy values from the original zero page to the new location to prevent
   the system from going off in the weeds? Or do you simply avoid all these
   problems by disabling interrupts?


3) I am writing a program that needs to periodically load new code in, and that
   requires manipulating stored information from these many different sections
   of code. Is there a general strategy for organizing such a program in memory?
   That is, is there a certain structure that can be used which is the most
   efficient where variables are put in one section/bank of memory, the code to
   load new routines in another, and an area for loading new code? At the same
   time I am concerned about being able to access the kernal routines (related
   to (1) above).

   Any comments, suggestions, or most of all solutions will be greatly
   appreciated.

   Todd F. Lockemer

jb@cbmtor.UUCP (Jim Butterfield ) (09/05/90)

Short responses to bank switch questions:
1) You cannot literally bankswitch to another bank in the same
   address area.  The usual transfer sequences ($FF6E, $FF71 ==
   JSRFAR, JMPFAR) will get you there in many cases, but if you
   have switched out ROM, even the above will obviously get you
   nowhere.  In that case, replace the above addresses with
   $02CD and $02E3 .. it's instructive to read the code of these.
   Unless you have good reason, try not to put code in the RAM
   areas above $C000, where this kind of problem arises.
2) I've never MMU-relocated zero page, but since it's a hardware
   operation, I suspect that if you did switch it, EVERYTHING 
   would go to the newly defined area.  Doubt that there is much
   use for this feature on the 128.
3) The location of ML code may be a matter of style.  Generally,
   I prefer Bank 0, above any area that Basic might want.  Be
   careful here: it's not safe to assume that Basic always starts
   at $1C00 .. graphics activities can move it and the DOS wedge
   does truly horrible things.
   Keep in mind that your Basic trigger program can SYS anywhere
   to any RAM bank with code such as BANK 0 : SYS xxxxx.  The
   moment you get there, however, you are running M/L that has
   the whole Kernal switched out (interrupts will be OK).  It is
   strongly desirable that you put the main Kernal back with
   LDA #$0E : STA $FF00.  Before you RTS back to Basic, if ever,
   you should return to the BANK 0 setup with LDA #$3F : STA $FF00.
   Remember to have the resuming Basic program go back to BANK 15.
    ...
The 128 gets little play these days, but I've slipped a short article
   on this into a forthcoming issue of (the reconfigured) COMPUTE!
   magazine.  Watch for it sometime in autumn.

		--Jim Butterfield



-- 
--
:  My boss doesn't understand me...  :  Jim Butterfield, Toronto  :
:   .. and I'm my own boss!          :    jb@cbmtor               :