Q: What is a farcall? With only 64k of direcly addressable memory space "farcalls" are needed to jump execution to code in other memory pages. The code to call a function in another page (or bank) is quite simple, and is used extensively in the Rex firmware. The code called might be within the firmware or a further addin. For example, such a technique is used in "Adder" to call addins that have been stored in unused gaps in the firmware.
Q: Can't I just store my data in another addin?
Q: How do I make a farcall in z80 code? ld a,pagenum ; target page number(or: call $26d9 ; EXACTLY the same function - not sure why they duplicated this code!) A well-behaved firmware function will use the appropriate entry & return functions, to make sure it gets back to the calling page upon completion. (A normal addin, using DsAddinTerminate() at the end, will NOT return back to the caller, without modification)
Q: How do I make a farcall in C code? Main Addin: #define page xx file://this is the page number of the second addinSecond Addin: void SomeFunction() {Q: How do pass parameters between code? In Z80 you can simply store and retrieve values via the user variable space. Similarly in C if you define a global var in both of the addin pages at the same location, they both refer to the same address space.
In the RexDk kit there are some functions to assist with this: WritePar1(value); file://pass/return a parameter to the functionThe parameter you can pass is a 2-byte value. There is also a second pair of functions WritePar2/ReadPar2 to pass a second parameter.
Q: How do I know what page & offset to use? You can get get the page number of the currently loaded page with the REGISTER_READ function. ( REGISTER_READ(REG_BANK1_LO) ). The 8 addins use pages 0x80-87. (You can see this in RexTools, rightclick on an installed addin, look at properties, 3rd tab - it refers to this as "start page #".)
Q: Background
|