git.y1.nz

gbdk-2020

GameBoy Development Kit
download: https://git.y1.nz/archives/gbdk.tar.gz
README | Files | Log | Refs | LICENSE

commit 723d8b4351b17524cfd6f9b3d65727ec1d073628
parent b92bd4569472e40a9b9496d783edb2d7377b6059
Author: Toxa <untoxa@mail.ru>
Date:   Sun, 27 Jun 2021 22:52:37 +0300

fix banks_farptr example

Diffstat:
Dgbdk-lib/examples/broken/banks_farptr/banks_farptr.c51---------------------------------------------------
Rgbdk-lib/examples/broken/banks_farptr/Makefile -> gbdk-lib/examples/gb/banks_farptr/Makefile0
Rgbdk-lib/examples/broken/banks_farptr/bank2code.c -> gbdk-lib/examples/gb/banks_farptr/bank2code.c0
Agbdk-lib/examples/gb/banks_farptr/banks_farptr.c49+++++++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 49 insertions(+), 51 deletions(-)

diff --git a/gbdk-lib/examples/broken/banks_farptr/banks_farptr.c b/gbdk-lib/examples/broken/banks_farptr/banks_farptr.c @@ -1,50 +0,0 @@ -#include <gb/gb.h> -#include <stdint.h> -#include <gb/far_ptr.h> - -#include <stdio.h> - -typedef int (*some_bank2_proc_t)(int, int) __banked; - -// functions from bank2code.c -#define bank2code_bank 2 -extern void some_bank2_proc0() __banked; -extern int some_bank2_proc1(int param1, int param2) __banked; - -// compose far pointer at compile time -FAR_PTR farptr_var0 = TO_FAR_PTR(&some_bank2_proc1, bank2code_bank); -FAR_PTR farptr_var2 = TO_FAR_PTR(&some_bank2_proc0, bank2code_bank); - -// another far pointer -FAR_PTR farptr_var1; - -// result of a function call -int res; - -void run() { - // compose far pointer in runtime - farptr_var1 = to_far_ptr(&some_bank2_proc1, bank2code_bank); - - // output far pointers (must be identical) - printf("FAR PTR0: %x:%x\n", (int)FAR_SEG(farptr_var0), (int)FAR_OFS(farptr_var0)); - printf("FAR PTR1: %x:%x\n", (int)FAR_SEG(farptr_var1), (int)FAR_OFS(farptr_var1)); - - // try calling far function by far pointer without params - FAR_CALL(farptr_var2, void (*)(void)); - - // try calling far function directly - res = some_bank2_proc1(100, 50); - printf("CALL DIR: %d\n", res); - - // try calling far function by far pointer - res = FAR_CALL(farptr_var1, some_bank2_proc_t, 100, 50); - - printf("CALL IND: %d\n", res); -} - -void main() { - ENABLE_RAM_MBC1; - printf("START (bank=%d)\n", (int)_current_bank); - run(); - printf("DONE! (bank=%d)\n", (int)_current_bank); -} - diff --git a/gbdk-lib/examples/broken/banks_farptr/Makefile b/gbdk-lib/examples/gb/banks_farptr/Makefile diff --git a/gbdk-lib/examples/broken/banks_farptr/bank2code.c b/gbdk-lib/examples/gb/banks_farptr/bank2code.c diff --git a/gbdk-lib/examples/gb/banks_farptr/banks_farptr.c b/gbdk-lib/examples/gb/banks_farptr/banks_farptr.c @@ -0,0 +1,48 @@ +#include <gb/gb.h> +#include <stdint.h> +#include <gb/far_ptr.h> + +#include <stdio.h> + +typedef int (*some_bank2_proc_t)(int, int) __banked; + +// functions from bank2code.c +#define bank2code_bank 2 +extern void some_bank2_proc0() __banked; +extern int some_bank2_proc1(int param1, int param2) __banked; + +// far pointers +FAR_PTR farptr_var0, farptr_var1, farptr_var2; + +// result of a function call +int res; + +void run() { + // compose far pointer at runtime + farptr_var0 = to_far_ptr(&some_bank2_proc1, bank2code_bank); + farptr_var1 = to_far_ptr(&some_bank2_proc1, bank2code_bank); + farptr_var2 = to_far_ptr(&some_bank2_proc0, bank2code_bank); + + // output far pointers (must be identical) + printf("FAR PTR0: %x:%x\n", (int)FAR_SEG(farptr_var0), (int)FAR_OFS(farptr_var0)); + printf("FAR PTR1: %x:%x\n", (int)FAR_SEG(farptr_var1), (int)FAR_OFS(farptr_var1)); + + // try calling far function by far pointer without params + FAR_CALL(farptr_var2, void (*)(void)); + + // try calling far function directly + res = some_bank2_proc1(100, 50); + printf("CALL DIR: %d\n", res); + + // try calling far function by far pointer + res = FAR_CALL(farptr_var1, some_bank2_proc_t, 100, 50); + + printf("CALL IND: %d\n", res); +} + +void main() { + ENABLE_RAM_MBC1; + printf("START (bank=%d)\n", (int)_current_bank); + run(); + printf("DONE! (bank=%d)\n", (int)_current_bank); +} +

This webpage is intended to be an accessible preview of this repository. To get a fuller picture, clone it and use the git CLI.