Skip to content
This repository has been archived by the owner. It is now read-only.
master
Switch branches/tags
Go to file
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
src
 
 
 
 
 
 
 
 
 
 

SDCC4 for gbz80 "far pointers" example

Features were implemented in the latest GBDK-2020 releases. You don't need this now, just use latest GBDK: header files, library support and example are included into the GBDK-2020 release.

Link to GBDK-2020: https://github.com/Zal0/gbdk-2020

The description below explains the how to use the feature.

GBDK-2020 v3.1.1 now supports transparent bank switching when calling __banked functions directly.

Unfortunately it is impossible to call those functions by pointer, because pointers do not contain information about the banks. I made a library, that allows to construct "far pointers" and call __banked functions indirectly with the help of some macros.

Far pointer type and helper macros are defined in far_ptr.h.

FAR_PTR is a "far pointer" type. low word contains a regular "near pointer", and high 
	word - the "segment" (or bank number).

TO_FAR_PTR(ofs, seg) macro that constructs a far pointer at compile time

FAR_SEG(ptr) gets a segment from a far pointer
FAR_OFS(ptr) gets an offset from a far pointer
FAR_FUNC(ptr, type) gets an offset from a far pointer and casts it to the given type

FAR_CALL(ptr, typ, ...) calls the function of a given type indirect by the given far 
	pointer and with provided parameters. banks are switched and restored 
	transparently.

to_far_ptr(ofs, seg) function that constructs a far pointer at runtime

Usage:

FAR_PTR farptr_var0 = TO_FAR_PTR(&some_bank1_proc1, sdcc4bank1code_bank);
res = FAR_CALL(farptr_var1, some_bank1_proc_t, 100, 50);

where some_bank1_proc1 is a __banked function located in sdcc4bank1code_bank, and some_bank1_proc_t is a typedef of that function. You may specify the type directly like this:

FAR_CALL(farptr_var2, void (*)(void));

where farptr_var2 is a far pointer to some __banked function without parameters and which is not returning result.

Thanks for reading this readme! Tony.

About

SDCC4 for gbz80 "far pointers" example: indirect __banked functions calls with trasparent bank switching

Resources

License

Releases

No releases published

Packages

No packages published