From: Alan Cox Date: Wed, 11 Feb 2015 00:28:51 +0000 (+0000) Subject: zx128: Further banking fixes X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=6d1dd94b04c8d3794fdce4a3c52af8d92c769413;p=FUZIX.git zx128: Further banking fixes With these in place we get as far as trying to call entries in a function table load 0xFFFF into HL and jump to it. Probably more binmunge debugging needed at this point. --- diff --git a/Kernel/platform-zx128/config.h b/Kernel/platform-zx128/config.h index 6603a236..c0a19a9f 100644 --- a/Kernel/platform-zx128/config.h +++ b/Kernel/platform-zx128/config.h @@ -32,7 +32,7 @@ #define CONFIG_FONT8X8SMALL /* We have 1 bank at C000 with 6 possible pages to map. - Our choise should be CONFIG_BANK_FIXED, but we are. + Our choice should be CONFIG_BANK_FIXED, but we are. using custom implementation of it */ #undef CONFIG_BANK_FIXED @@ -52,9 +52,9 @@ #define TICKSPERSEC 50 /* Ticks per second */ #define PROGBASE 0x8000 /* also data base */ -#define PROGLOAD 0xC000 /* also data base */ +#define PROGLOAD 0x8000 /* also data base */ #define PROGTOP 0xFD00 /* Top of program, base of U_DATA copy */ -#define PROC_SIZE 16 /* Memory needed per process */ +#define PROC_SIZE 32 /* Memory needed per process */ #define UDATA_BLOCKS 0 /* We swap the stash not the uarea */ #define UDATA_SWAPSIZE 0 diff --git a/Kernel/platform-zx128/crt0.s b/Kernel/platform-zx128/crt0.s index 588987a7..074088d6 100644 --- a/Kernel/platform-zx128/crt0.s +++ b/Kernel/platform-zx128/crt0.s @@ -90,6 +90,7 @@ init1: ldir init2: + di ld sp, #kstack_top ; Configure memory map @@ -102,12 +103,6 @@ init2: call init_hardware pop af -l1: ld a, #7 - out (0xfe), a - xor a - out (0xfe), a - jr l1 - ; Call the C main routine push af call _fuzix_main diff --git a/Kernel/platform-zx128/kernel.def b/Kernel/platform-zx128/kernel.def index 25add17f..de474aa3 100644 --- a/Kernel/platform-zx128/kernel.def +++ b/Kernel/platform-zx128/kernel.def @@ -7,8 +7,8 @@ U_DATA_STASH .equ 0xFD00 ; BD00-BFFF Z80_TYPE .equ 1 -PROGBASE .equ 0xC000 -PROGLOAD .equ 0xC000 +PROGBASE .equ 0x8000 +PROGLOAD .equ 0x8000 ; ; Ways we may boot diff --git a/Kernel/platform-zx128/zx128.s b/Kernel/platform-zx128/zx128.s index 2ddfd956..cf8ada54 100644 --- a/Kernel/platform-zx128/zx128.s +++ b/Kernel/platform-zx128/zx128.s @@ -85,9 +85,6 @@ init_hardware: ld hl, #(128 - 48) ; 48K for kernel ld (_procmem), hl - ld a, #4 - out (0xfe), a -l2: jr l2 ; screen initialization ; clear ld hl, #0xC000 @@ -117,12 +114,7 @@ l2: jr l2 ; We must keep the Spectrum 48K ROM image mapped at all times. The ; 128K image hasn't got the 0xFF space we use! ; - xor a - call setvectors - ld a, #1 - call setvectors - ld a, #7 - call setvectors + call setallvectors ld a, #0x39 ld i, a ; im 2 ; set CPU interrupt mode @@ -151,6 +143,15 @@ setvectors: ld (0xFFF5), a ; to IRQ handler ret +setallvectors: + call map_save + xor a + call setvectors + ld a, #1 + call setvectors + ld a, #7 + call setvectors + jp map_restore ; bank switching procedure. On entrance: ; A - bank number to set @@ -243,13 +244,17 @@ place_for_c: __bank_0_1: xor a ; switch to physical bank 0 (logical 1) bankina0: - call switch_bank ; Move to new bank + ; + ; Get the target address first, otherwise we will change + ; bank and read it from the wrong spot! + ; pop hl ; Return address (points to true function address) ld e, (hl) ; DE = function to call inc hl ld d, (hl) inc hl push hl ; Restore corrected return pointer + call switch_bank ; Move to new bank ex de, hl call callhl ; can't optimise - we need the stack depth right ret @@ -266,24 +271,17 @@ __bank_0_3: __bank_1_2: ld a, #1 bankina1: - call switch_bank ; Move to new bank pop hl ; Return address (points to true function address) ld e, (hl) ; DE = function to call inc hl ld d, (hl) inc hl push hl ; Restore corrected return pointer + call switch_bank ; Move to new bank ex de, hl - call outhl call callhl ; call the function xor a ; return to bank 1 (physical 0) - call switch_bank -l1: ld c, #0xfe - ld a, #2 - out (c), a - ld b, #0 - out (c),b - jr l1 + jp switch_bank __bank_1_3: ld a, #7 @@ -291,13 +289,13 @@ __bank_1_3: __bank_2_1: xor a bankina2: - call switch_bank ; Move to new bank pop hl ; Return address (points to true function address) ld e, (hl) ; DE = function to call inc hl ld d, (hl) inc hl push hl ; Restore corrected return pointer + call switch_bank ; Move to new bank ex de, hl call callhl ; call the function ld a, #1 ; return to bank 2 @@ -308,13 +306,13 @@ __bank_2_3: __bank_3_1: xor a bankina3: - call switch_bank ; Move to new bank pop hl ; Return address (points to true function address) ld e, (hl) ; DE = function to call inc hl ld d, (hl) inc hl push hl ; Restore corrected return pointer + call switch_bank ; Move to new bank ex de, hl call callhl ; call the function ld a, #7 ; return to bank 0 diff --git a/Kernel/platform-zx128/zxvideo.s b/Kernel/platform-zx128/zxvideo.s index a59da817..7b86416b 100644 --- a/Kernel/platform-zx128/zxvideo.s +++ b/Kernel/platform-zx128/zxvideo.s @@ -1,5 +1,9 @@ ; ; zx128 vt primitives +; +; FIXME: adjust for correct stack offsets in banked mode (only +; plot_char done so far) +; .module zx128 @@ -30,17 +34,19 @@ videopos: ld e,a ld a,d and #0x18 - or #0x40 + or #0xC0 ; not 0x40 as in screen 7 ld d,a ret _plot_char: + pop iy pop hl pop de ; D = x E = y pop bc push bc push de push hl + push iy call videopos diff --git a/Kernel/tools/bankld/lkrloc3.c b/Kernel/tools/bankld/lkrloc3.c index f8e7bb80..fe629b82 100644 --- a/Kernel/tools/bankld/lkrloc3.c +++ b/Kernel/tools/bankld/lkrloc3.c @@ -182,7 +182,7 @@ static int bankmagic(struct areax *ax) if (strcmp(a->a_id, "_VIDEO") == 0) return 3; if (strcmp(a->a_id, "_DISCARD") == 0) - return 3; + return 0; if (strncmp(a->a_id, "_CODE", 5)) return 0; if (a->a_id[5] == 0) /* We count _CODE and _CODE1 both as first bank */