]> cloudbase.mooo.com Git - z180-stamp.git/commitdiff
new command: memsize. new function z80_memsize_detect().
authorLeo C <erbl259-lmu@yahoo.de>
Thu, 6 Sep 2018 13:39:49 +0000 (15:39 +0200)
committerLeo C <erbl259-lmu@yahoo.de>
Thu, 6 Sep 2018 13:39:49 +0000 (15:39 +0200)
avr/cmd_loadihex.c
avr/cmd_mem.c
avr/command_tbl.c
avr/z80-if.c
include/cmd_mem.h
include/z80-if.h

index d55a63a2a01b0d4bb774aeb131490228989a5e00..a7c9238d675f69913631e1466de7ad24fc79f992 100644 (file)
 #include "debug.h"
 
 
 #include "debug.h"
 
 
-static uint32_t detect_ramsize(void)
-{
-       uint32_t addr;
-       uint8_t save_addr, save_0;
-       const uint8_t PATTERN_1 = 0x55;
-       const uint8_t PATTERN_2 = ~PATTERN_1;
-
-       if (!(z80_bus_cmd(Request) & ZST_ACQUIRED)) {
-               my_puts_P(PSTR("Bus timeout\n"));
-               return  0;
-       }
-
-       save_0 = z80_read(0);
-       z80_write(0, PATTERN_1);
-
-       for (addr=1; addr < CONFIG_SYS_RAMSIZE_MAX; addr <<= 1) {
-               save_addr = z80_read(addr);
-               z80_write(addr, PATTERN_2);
-               if (z80_read(0) != PATTERN_1 || z80_read(addr) != PATTERN_2)
-                       break;
-               z80_write(addr, save_addr);
-       }
-       z80_write(0, save_0);
-       z80_bus_cmd(Release);
-
-       return addr;
-}
-
 typedef enum {
        IHX_OK,
        IHX_BROKEN,
 typedef enum {
        IHX_OK,
        IHX_BROKEN,
@@ -149,15 +121,22 @@ command_ret_t do_loadihex(cmd_tbl_t *cmdtp UNUSED, uint_fast8_t flag UNUSED, int
 {
        long offset = 0;
        uint32_t base_address = 0;
 {
        long offset = 0;
        uint32_t base_address = 0;
-       uint32_t address_max = detect_ramsize();
        uint32_t address_high = 0;
        uint32_t address_high = 0;
-       uint32_t address_low = address_max;
+       uint32_t address_max;
+       uint32_t address_low;
        bool firstrec = true;
        ihex_t rec;
 
        if (argc > 1)
                offset = strtol(argv[1], NULL, 16);
 
        bool firstrec = true;
        ihex_t rec;
 
        if (argc > 1)
                offset = strtol(argv[1], NULL, 16);
 
+       int32_t ram = z80_memsize_detect();
+       if (ram < 0)
+               cmd_error(CMD_RET_FAILURE, (ERRNUM) -ram, NULL);
+
+       address_max = ram;
+       address_low = address_max;
+
        my_puts_P(PSTR("Waiting for Intel Hex Records...\n"));
 
        while (ihex_get_record(&rec) > 0 &&
        my_puts_P(PSTR("Waiting for Intel Hex Records...\n"));
 
        while (ihex_get_record(&rec) > 0 &&
index 7a8781cc7b7432d036bfc9c11cf2db5940eb686e..d641410639e3abcba368f99fbd0d3806cf335b80 100644 (file)
  * Copied from FADS ROM, Dan Malek (dmalek@jlc.net)
  */
 
  * Copied from FADS ROM, Dan Malek (dmalek@jlc.net)
  */
 
-#include "common.h"
-#include <ctype.h>
+#include "cmd_mem.h"
 #include <avr/interrupt.h>
 
 #include <avr/interrupt.h>
 
-#include "command.h"
 #include "cli_readline.h"
 #include "print-utils.h"
 #include "con-utils.h"
 #include "cli_readline.h"
 #include "print-utils.h"
 #include "con-utils.h"
@@ -55,6 +53,19 @@ static ERRNUM z180_read_buf(uint8_t *buf, uint32_t addr, uint8_t count)
 
 /*--------------------------------------------------------------------------*/
 
 
 /*--------------------------------------------------------------------------*/
 
+command_ret_t do_mem_size(cmd_tbl_t *cmdtp UNUSED, uint_fast8_t flag UNUSED, int argc UNUSED, char * const argv[] UNUSED)
+{
+       int32_t ramsize = z80_memsize_detect();
+
+       if (ramsize < 0)
+               cmd_error(CMD_RET_FAILURE, (ERRNUM) -ramsize, PSTR("Couldn't access RAM"));
+
+       printf_P(PSTR("Detected RAM: Start %.5lx, End: %.5lx, Size: %.5lx (%ld dec)\n"),
+               0l, ramsize ? ramsize-1 : 0l, ramsize, ramsize);
+
+       return CMD_RET_SUCCESS;
+}
+
 /* Memory Display
  *
  * Syntax:
 /* Memory Display
  *
  * Syntax:
index 232d71889b71c13389494262887228b6f4e47b17..5d185ba995ad865ec60da679111acffde5f50eb7 100644 (file)
@@ -74,6 +74,11 @@ CMD_TBL_ITEM(
        ""
 ),
 #endif
        ""
 ),
 #endif
+CMD_TBL_ITEM(
+       msize,  1,      1,      do_mem_size,
+       "Detect memory size",
+       ""
+),
 CMD_TBL_ITEM(
        mstep,  2,      1,      do_busreq_pulse,
        "execute one M cycle",
 CMD_TBL_ITEM(
        mstep,  2,      1,      do_busreq_pulse,
        "execute one M cycle",
index 618384950874db2abd9ae8e70ac33ee7dbcfac84..6d831724dbb2cbc718a03282159eb3bcf48327dd 100644 (file)
@@ -463,6 +463,39 @@ void z80_setaddress(uint32_t addr)
        PIN_ADB = (((addr >> 16) << ADB_SHIFT) ^ P_ADB) & MASK(ADB_WIDTH) << ADB_SHIFT;
 }
 
        PIN_ADB = (((addr >> 16) << ADB_SHIFT) ^ P_ADB) & MASK(ADB_WIDTH) << ADB_SHIFT;
 }
 
+int32_t z80_memsize_detect(void)
+{
+       const uint8_t PATTERN_1 = 0x55;
+       const uint8_t PATTERN_2 = ~PATTERN_1;
+       uint32_t addr;
+
+       if (!(z80_bus_cmd(Request) & ZST_ACQUIRED))
+               return  -EBUSTO;
+
+       uint8_t ram_0 = z80_read(0);
+       uint8_t ram_1 = z80_read(1);
+
+       z80_write(0, ram_0 ^ 0xff);
+       z80_write(1, ram_1);
+       if ((z80_read(0) ^ ram_0) != 0xff) {
+               addr = 0;
+       } else {
+               z80_write(0, PATTERN_1);
+               for (addr=1; addr < CONFIG_SYS_RAMSIZE_MAX; addr <<= 1) {
+                       uint8_t ram_i = z80_read(addr);
+                       z80_write(addr, PATTERN_2);
+                       if (z80_read(0) != PATTERN_1 || z80_read(addr) != PATTERN_2)
+                               break;
+                       z80_write(addr, ram_i);
+               }
+       }
+
+       z80_write(0, ram_0);
+       z80_bus_cmd(Release);
+
+       return addr;
+}
+
 void z80_write(uint32_t addr, uint8_t data)
 {
        z80_setaddress(addr);
 void z80_write(uint32_t addr, uint8_t data)
 {
        z80_setaddress(addr);
index b019d27e023690deb0382209ddafafa519901efc..4b370cc7b9985ef8966d37fdc9c3251c68afbfd4 100644 (file)
@@ -1,5 +1,5 @@
 /*
 /*
- * (C) Copyright 2014 Leo C. <erbl259-lmu@yahoo.de>
+ * (C) Copyright 2014,2018 Leo C. <erbl259-lmu@yahoo.de>
  *
  * SPDX-License-Identifier:    GPL-2.0
  */
  *
  * SPDX-License-Identifier:    GPL-2.0
  */
@@ -9,21 +9,21 @@
 
 #include "command.h"
 
 
 #include "command.h"
 
-
-extern command_ret_t do_mem_md(cmd_tbl_t *, uint_fast8_t, int, char * const []);
-extern command_ret_t do_mem_mm(cmd_tbl_t *, uint_fast8_t, int, char * const []);
-extern command_ret_t do_mem_nm(cmd_tbl_t *, uint_fast8_t, int, char * const []);
-extern command_ret_t do_mem_mw(cmd_tbl_t *, uint_fast8_t, int, char * const []);
-extern command_ret_t do_mem_cp(cmd_tbl_t *, uint_fast8_t, int, char * const []);
-extern command_ret_t do_mem_cmp(cmd_tbl_t *, uint_fast8_t, int, char * const []);
-extern command_ret_t do_mem_base(cmd_tbl_t *, uint_fast8_t, int, char * const []);
-extern command_ret_t do_mem_loop(cmd_tbl_t *, uint_fast8_t, int, char * const []);
-extern command_ret_t do_mem_loopw(cmd_tbl_t *, uint_fast8_t, int, char * const []);
+command_ret_t do_mem_size(cmd_tbl_t *, uint_fast8_t, int, char * const []);
+command_ret_t do_mem_md(cmd_tbl_t *, uint_fast8_t, int, char * const []);
+command_ret_t do_mem_mm(cmd_tbl_t *, uint_fast8_t, int, char * const []);
+command_ret_t do_mem_nm(cmd_tbl_t *, uint_fast8_t, int, char * const []);
+command_ret_t do_mem_mw(cmd_tbl_t *, uint_fast8_t, int, char * const []);
+command_ret_t do_mem_cp(cmd_tbl_t *, uint_fast8_t, int, char * const []);
+command_ret_t do_mem_cmp(cmd_tbl_t *, uint_fast8_t, int, char * const []);
+command_ret_t do_mem_base(cmd_tbl_t *, uint_fast8_t, int, char * const []);
+command_ret_t do_mem_loop(cmd_tbl_t *, uint_fast8_t, int, char * const []);
+command_ret_t do_mem_loopw(cmd_tbl_t *, uint_fast8_t, int, char * const []);
 #ifdef CONFIG_CMD_MEMTEST
 #ifdef CONFIG_CMD_MEMTEST
-extern command_ret_t do_mem_mtest(cmd_tbl_t *, uint_fast8_t, int, char * const []);
+command_ret_t do_mem_mtest(cmd_tbl_t *, uint_fast8_t, int, char * const []);
 #endif
 #ifdef CONFIG_MX_CYCLIC
 #endif
 #ifdef CONFIG_MX_CYCLIC
-extern command_ret_t do_mem_mdc(cmd_tbl_t *, uint_fast8_t, int, char * const []);
+command_ret_t do_mem_mdc(cmd_tbl_t *, uint_fast8_t, int, char * const []);
 #endif /* CONFIG_MX_CYCLIC */
 
 #endif /* CMD_MEM_H */
 #endif /* CONFIG_MX_CYCLIC */
 
 #endif /* CMD_MEM_H */
index d5a5f568476b4e4484de380ab4ca1fa01f45a9fd..0ad14f5c170a2a779bbff3952b4a27e18c13d16b 100644 (file)
@@ -37,6 +37,7 @@ int z80_stat_reset(void);
 int z80_stat_halt(void);
 
 
 int z80_stat_halt(void);
 
 
+int32_t z80_memsize_detect(void);
 void z80_write(uint32_t addr, uint8_t data);
 uint8_t z80_read(uint32_t addr);
 void z80_memset(uint32_t addr, uint8_t data, uint32_t length);
 void z80_write(uint32_t addr, uint8_t data);
 uint8_t z80_read(uint32_t addr);
 void z80_memset(uint32_t addr, uint8_t data, uint32_t length);