msx2: update megasd transfer functions for rawflag=1
authorgeijoenr <enric.geijo@gmail.com>
Tue, 27 Jan 2015 21:41:36 +0000 (21:41 +0000)
committergeijoenr <enric.geijo@gmail.com>
Tue, 27 Jan 2015 23:13:37 +0000 (23:13 +0000)
Kernel/platform-msx2/Makefile
Kernel/platform-msx2/devmegasd.c
Kernel/platform-msx2/msx2.def [new file with mode: 0644]
Kernel/platform-msx2/msx2.h [new file with mode: 0644]
Kernel/platform-msx2/msx2.s

index 5867070..7599b99 100644 (file)
@@ -17,7 +17,7 @@ JUNK = $(CSRCS:.c=.lst) $(CSRCS:.c=.asm) $(CSRCS:.c=.sym) $(ASRCS:.s=.lst) $(ASR
 all:   $(OBJS)
 
 $(DOBJS): %.rel: %.c
-       $(CROSS_CC) $(CROSS_CCOPTS) -c $<
+       $(CROSS_CC) $(CROSS_CCOPTS) --codeseg COMMONMEM -c $<
 
 $(COBJS): %.rel: %.c
        $(CROSS_CC) $(CROSS_CCOPTS) --codeseg CODE2 -c $<
index 1ba0da4..2287a7b 100644 (file)
@@ -8,6 +8,8 @@
 #include <timer.h>
 #include <stdbool.h>
 #include "config.h"
+#include <blkdev.h>
+#include "msx2.h"
 
 /*
  * MegaFlashRom SCC+ SD contains an slot expander with several devices.
@@ -35,8 +37,6 @@
 
 #ifdef DEVICE_SD
 
-extern int mapslot_bank1(uint8_t slot);
-extern uint8_t slotram;
 
 /* slot and subslot containing the sd interface */
 uint8_t slotmfr;
@@ -129,30 +129,125 @@ uint8_t sd_spi_receive_byte(uint8_t drive)
     return c;
 }
 
-bool sd_spi_receive_block(uint8_t drive, uint8_t *ptr, unsigned int length)
+/*
+ * Block transfer is now equivalent to memory copy from MegaSD mapped i/o to a ram page.
+ * Target page is always mapped to slot_page2, and the target address offset accordingly.
+ *
+ */
+bool sd_spi_receive_sector(uint8_t drive) __naked
 {
-    drive; /* not used */
-
-    sd_spi_map_interface();
-
-    while(length--) *ptr++ = readb(MSD_RDWR);
-
-    sd_spi_unmap_interface();
-
-    return true;
+    __asm
+
+    ; map sd interface
+    ;
+    ld a,(_slotmfr)
+    call _mapslot_bank1
+    ld a, #MSD_PAGE
+    ld (MFR_BANKSEL0),a
+
+    ld a, (_blk_op+BLKPARAM_IS_USER_OFFSET)
+    ld de, (_blk_op+BLKPARAM_ADDR_OFFSET)
+    push af
+    or a
+    jr z, starttx
+
+    ; map process target page in slot_page2 if needed
+    ;
+    ld a,d
+    and #0xC0
+    rlca
+    rlca    ;  a contains the page to map
+    ld b,#0
+    ld c,a
+    ld hl,#U_DATA__U_PAGE
+    add hl,bc
+    ld a,(hl)
+    out(_RAM_PAGE2),a
+
+starttx:
+    ; calculate offset address in target page
+    ld a,d
+    and #0x3F
+    or #0x80
+    ld d,a
+    ld hl,#MSD_RDWR
+    ld bc,#512
+    jp looptxrx
+    __endasm;
+
+    drive; /* silence compiler warning */
 }
 
-bool sd_spi_transmit_block(uint8_t drive, uint8_t *ptr, int length)
+bool sd_spi_transmit_sector(uint8_t drive) __naked
 {
-    drive; /* not used */
-
-    sd_spi_map_interface();
-
-    while(length--) writeb(*(ptr++), MSD_RDWR);
-
-    sd_spi_unmap_interface();
-
-    return true;
+    __asm
+
+    ; map sd interface
+    ;
+    ld a,(_slotmfr)
+    call _mapslot_bank1
+    ld a, #MSD_PAGE
+    ld (MFR_BANKSEL0),a
+
+    ; map process target page in slot_page2
+    ;
+    ld a, (_blk_op+BLKPARAM_IS_USER_OFFSET)
+    ld de, (_blk_op+BLKPARAM_ADDR_OFFSET);
+    push af
+    or a
+    jr z, startrx
+
+    ; map process target page in slot_page2 if needed
+    ;
+    ld a,d
+    and #0xC0
+    rlca
+    rlca    ;  a contains the page to map
+    ld b,#0
+    ld c,a
+    ld hl,#U_DATA__U_PAGE
+    add hl,bc
+    ld a,(hl)
+    out(_RAM_PAGE2),a
+
+startrx:
+    ; calculate offset address in target page
+    ld a,d
+    and #0x3F
+    or #0x80
+    ld d,a
+    ld hl,#MSD_RDWR
+    ex de,hl
+    ld bc,#512
+looptxrx:
+    ldi        ; 16x ldi: 19% faster
+    ldi
+    ldi
+    ldi
+    ldi
+    ldi
+    ldi
+    ldi
+    ldi
+    ldi
+    ldi
+    ldi
+    ldi
+    ldi
+    ldi
+    ldi
+    jp pe, looptxrx
+
+    ; unmap interface
+    ;
+    ld a,(_slotram)
+    call _mapslot_bank1
+    pop af
+    or a
+    ret z
+    jp _map_kernel
+    __endasm;
+    drive; /* silence compiler warning */
 }
 
 #endif
diff --git a/Kernel/platform-msx2/msx2.def b/Kernel/platform-msx2/msx2.def
new file mode 100644 (file)
index 0000000..165ec0e
--- /dev/null
@@ -0,0 +1,14 @@
+; msx2 fixed i/o ports and memory mapped i/o addresses
+
+SLOT_SEL                   .equ 0xA8         ; primary slot select register
+SUBSLOT_SEL                .equ 0xFFFF       ; seconday slot select register
+
+PAGE0_BASE                 .equ 0x0000
+PAGE1_BASE                 .equ 0x4000
+PAGE2_BASE                 .equ 0x8000
+PAGE3_BASE                 .equ 0xC000
+
+RAM_PAGE0                  .equ 0xFC         ; memory mapper registers
+RAM_PAGE1                  .equ 0xFD
+RAM_PAGE2                  .equ 0xFE
+RAM_PAGE3                  .equ 0xFF
diff --git a/Kernel/platform-msx2/msx2.h b/Kernel/platform-msx2/msx2.h
new file mode 100644 (file)
index 0000000..edd0027
--- /dev/null
@@ -0,0 +1,24 @@
+#ifndef __MSX2_DOT_H__
+#define __MSX2_DOT_H__
+
+__sfr __at (0xfc) RAM_PAGE0;
+__sfr __at (0xfd) RAM_PAGE1;
+__sfr __at (0xfe) RAM_PAGE2;
+__sfr __at (0xff) RAM_PAGE3;
+
+#define PAGE0_BASE  (uint8_t *)0x0000
+#define PAGE1_BASE  (uint8_t *)0x4000
+#define PAGE2_BASE  (uint8_t *)0x8000
+#define PAGE3_BASE  (uint8_t *)0xC000
+
+#define PAGE_SIZE   0x4000
+
+#define U_DATA         0xF000
+#define U_DATA__U_PAGE 0xF002
+
+extern int mapslot_bank1(uint8_t slot);
+extern int mapslot_bank2(uint8_t slot);
+
+extern uint8_t slotram;
+
+#endif
index 16d43eb..6d59493 100644 (file)
@@ -11,6 +11,7 @@
             .globl _program_vectors
            .globl map_kernel
            .globl map_process
+           .globl _map_kernel
            .globl map_process_always
            .globl map_save
            .globl map_restore
@@ -262,6 +263,7 @@ map_process:
 ;      Map in the kernel below the current common, go via the helper
 ;      so our cached copy is correct.
 ;
+_map_kernel:
 map_kernel:
            push hl
            ld hl, #map_kernel_data