]> git.unchartedbackwaters.co.uk Git - francis/winuae.git/commitdiff
RAM board extra options (file load)
authorToni Wilen <twilen@winuae.net>
Sat, 15 Sep 2018 17:12:50 +0000 (20:12 +0300)
committerToni Wilen <twilen@winuae.net>
Sat, 15 Sep 2018 17:12:50 +0000 (20:12 +0300)
cfgfile.cpp
expansion.cpp
include/options.h

index 6fc99f34322db6823a8bf279bd101127b8f296ef..49d29961ae95f645b6462db85ffb712feb843739 100644 (file)
@@ -1435,6 +1435,7 @@ static void cfgfile_write_board_rom(struct uae_prefs *prefs, struct zfile *f, st
        if (!ert)
                return;
        for (int i = 0; i < MAX_BOARD_ROMS; i++) {
+               struct romconfig *rc = &br->roms[i];
                if (br->device_num == 0)
                        _tcscpy(name, ert->name);
                else
@@ -1442,18 +1443,18 @@ static void cfgfile_write_board_rom(struct uae_prefs *prefs, struct zfile *f, st
                if (i == 0 || _tcslen(br->roms[i].romfile)) {
                        _stprintf(buf, _T("%s%s_rom_file"), name, i ? _T("_ext") : _T(""));
                        cfgfile_write_rom (f, mp, br->roms[i].romfile, buf);
-                       if (br->roms[i].romident[0]) {
+                       if (rc->romident[0]) {
                                _stprintf(buf, _T("%s%s_rom"), name, i ? _T("_ext") : _T(""));
-                               cfgfile_dwrite_str (f, buf, br->roms[i].romident);
+                               cfgfile_dwrite_str (f, buf, rc->romident);
                        }
-                       if (br->roms[i].autoboot_disabled || ert->subtypes || ert->settings || ert->id_jumper || br->device_order > 0 || is_custom_romboard(br)) {
+                       if (rc->autoboot_disabled || ert->subtypes || ert->settings || ert->id_jumper || br->device_order > 0 || is_custom_romboard(br)) {
                                TCHAR buf2[256], *p;
                                buf2[0] = 0;
                                p = buf2;
                                _stprintf(buf, _T("%s%s_rom_options"), name, i ? _T("_ext") : _T(""));
                                if (ert->subtypes) {
                                        const struct expansionsubromtype *srt = ert->subtypes;
-                                       int k = br->roms[i].subtype;
+                                       int k = rc->subtype;
                                        while (k && srt[1].name) {
                                                srt++;
                                                k--;
@@ -1466,30 +1467,30 @@ static void cfgfile_write_board_rom(struct uae_prefs *prefs, struct zfile *f, st
                                        TCHAR *p2 = buf2 + _tcslen(buf2);
                                        _stprintf(p2, _T("order=%d"), br->device_order);
                                }
-                               if (br->roms[i].autoboot_disabled) {
+                               if (rc->autoboot_disabled) {
                                        if (buf2[0])
                                                _tcscat(buf2, _T(","));
                                        _tcscat(buf2, _T("autoboot_disabled=true"));
                                }
                                if (ert->id_jumper) {
                                        TCHAR tmp[256];
-                                       _stprintf(tmp, _T("id=%d"), br->roms[i].device_id);
+                                       _stprintf(tmp, _T("id=%d"), rc->device_id);
                                        if (buf2[0])
                                                _tcscat(buf2, _T(","));
                                        _tcscat(buf2, tmp);
                                }
-                               if ((br->roms[i].device_settings || br->roms[i].configtext[0]) && ert->settings) {
-                                       cfgfile_write_rom_settings(ert->settings, buf2, br->roms[i].device_settings, br->roms[i].configtext);
+                               if ((rc->device_settings || rc->configtext[0]) && ert->settings) {
+                                       cfgfile_write_rom_settings(ert->settings, buf2, rc->device_settings, rc->configtext);
                                }
                                if (is_custom_romboard(br)) {
-                                       if (br->roms[i].manufacturer) {
+                                       if (rc->manufacturer) {
                                                if (buf2[0])
                                                        _tcscat(buf2, _T(","));
                                                TCHAR *p2 = buf2 + _tcslen(buf2);
-                                               _stprintf(p2, _T("mid=%u,pid=%u"), br->roms[i].manufacturer, br->roms[i].product);
+                                               _stprintf(p2, _T("mid=%u,pid=%u"), rc->manufacturer, rc->product);
                                        }
-                                       if (br->roms[i].autoconfig[0]) {
-                                               uae_u8 *ac = br->roms[i].autoconfig;
+                                       if (rc->autoconfig[0]) {
+                                               uae_u8 *ac = rc->autoconfig;
                                                if (buf2[0])
                                                        _tcscat(buf2, _T(","));
                                                TCHAR *p2 = buf2 + _tcslen(buf2);
@@ -1502,9 +1503,9 @@ static void cfgfile_write_board_rom(struct uae_prefs *prefs, struct zfile *f, st
                                        cfgfile_dwrite_str (f, buf, buf2);
                        }
 
-                       if (br->roms[i].board_ram_size) {
+                       if (rc->board_ram_size) {
                                _stprintf(buf, _T("%s%s_mem_size"), name, i ? _T("_ext") : _T(""));
-                               cfgfile_write(f, buf, _T("%d"), br->roms[i].board_ram_size / 0x40000);
+                               cfgfile_write(f, buf, _T("%d"), rc->board_ram_size / 0x40000);
                        }
                }
        }
@@ -1541,6 +1542,7 @@ static bool cfgfile_readramboard(const TCHAR *option, const TCHAR *value, const
                else
                        _stprintf(tmp1, _T("%s_options"), name);
                if (!_tcsicmp(option, tmp1)) {
+                       TCHAR *endptr;
                        TCHAR *s, *s1, *s2;
                        s = cfgfile_option_get(value, _T("order"));
                        if (s)
@@ -1574,7 +1576,6 @@ static bool cfgfile_readramboard(const TCHAR *option, const TCHAR *value, const
                        s1 = cfgfile_option_get(value, _T("start"));
                        s2 = cfgfile_option_get(value, _T("end"));
                        if (s1 && s2) {
-                               TCHAR *endptr;
                                rb->start_address = _tcstol(s1, &endptr, 16);
                                rb->end_address = _tcstol(s2, &endptr, 16);
                                if (rb->start_address && rb->end_address > rb->start_address) {
@@ -1590,7 +1591,29 @@ static bool cfgfile_readramboard(const TCHAR *option, const TCHAR *value, const
                                rb->write_address = _tcstol(s1, &endptr, 16);
                        }
                        xfree(s1);
-
+                       s1 = cfgfile_option_get(value, _T("file"));
+                       if (s1) {
+                               TCHAR *p = cfgfile_unescape(s1, NULL);
+                               _tcscpy(rb->loadfile, p);
+                               xfree(p);
+                       }
+                       xfree(s1);
+                       s1 = cfgfile_option_get(value, _T("offset"));
+                       if (s1) {
+                               rb->loadoffset = _tcstol(s1, &endptr, 16);
+                       }
+                       xfree(s1);
+                       s1 = cfgfile_option_get(value, _T("fileoffset"));
+                       if (s1) {
+                               rb->fileoffset = _tcstol(s1, &endptr, 16);
+                       }
+                       xfree(s1);
+                       s1 = cfgfile_option_get(value, _T("filesize"));
+                       if (s1) {
+                               rb->filesize = _tcstol(s1, &endptr, 16);
+                       }
+                       xfree(s1);
+                       rb->readonly = cfgfile_option_find(value, _T("read-only"));
                        return true;
                }
        }
@@ -1643,6 +1666,18 @@ static void cfgfile_writeramboard(struct uae_prefs *prefs, struct zfile *f, cons
                _stprintf(p, _T(",write_address=%08x"), rb->write_address);
                p += _tcslen(p);
        }
+       if (rb->loadfile[0]) {
+               if (tmp2[0])
+                       _tcscat(p, _T(","));
+               TCHAR *path = cfgfile_escape(rb->loadfile, NULL, true);
+               _stprintf(p, _T("offset=%u,fileoffset=%u,filesize=%u,file=%s"), rb->loadoffset, rb->fileoffset, rb->filesize, path);
+               xfree(path);
+       }
+       if (rb->readonly) {
+               if (tmp2[0])
+                       _tcscat(p, _T(","));
+               _tcscat(p, _T("readonly"));
+       }
        if (tmp2[0]) {
                cfgfile_write(f, tmp1, tmp2);
        }
index 54aa3f8d7f2a0c7e6caa94421a6ee988aa6c4d05..ef895bb68bfb164ebd72d69957c567e49d5395c8 100644 (file)
@@ -1477,6 +1477,40 @@ static bool expamem_init_uaeboard(struct autoconfig_info *aci)
        return true;
 }
 
+static void REGPARAM2 empty_put(uaecptr addr, uae_u32 value)
+{
+}
+
+static void initramboard(addrbank *ab, struct ramboard *rb)
+{
+       if (!ab->baseaddr)
+               return;
+       if (rb->loadfile[0]) {
+               struct zfile *zf = zfile_fopen(rb->loadfile, _T("rb"));
+               if (zf) {
+                       int size = rb->filesize;
+                       if (!size) {
+                               size = ab->allocated_size;
+                       } else if (rb->loadoffset + size > ab->allocated_size)
+                               size = ab->allocated_size - rb->loadoffset;
+                       if (size > 0) {
+                               int total = zfile_fread(ab->baseaddr + rb->loadoffset, 1, size, zf);
+                               write_log(_T("Expansion file '%s': load %u bytes, offset %u, start addr %08x\n"),
+                                       rb->loadfile, total, rb->loadoffset, ab->start + rb->loadoffset);
+                       }
+                       zfile_fclose(zf);
+               } else {
+                       write_log(_T("Couldn't open expansion file '%s'\n"), rb->loadfile);
+               }
+       }
+       if (rb->readonly) {
+               ab->lput = empty_put;
+               ab->wput = empty_put;
+               ab->bput = empty_put;
+               ab->jit_write_flag = 0;
+       }
+}
+
 /*
 *  Z3fastmem Memory
 */
@@ -1536,14 +1570,16 @@ addrbank z3chipmem_bank = {
 
 static addrbank *expamem_map_fastcard(struct autoconfig_info *aci)
 {
+       int devnum = aci->devnum;
        uae_u32 start = ((expamem_hi | (expamem_lo >> 4)) << 16);
-       addrbank *ab = &fastmem_bank[aci->devnum];
+       addrbank *ab = &fastmem_bank[devnum];
        if (start == 0x00ff0000)
                return ab;
        uae_u32 size = ab->allocated_size;
        ab->start = start;
        if (ab->start && size) {
                map_banks_z2(ab, ab->start >> 16, size >> 16);
+               initramboard(ab, &currprefs.fastmem[devnum]);
        }
        return ab;
 }
@@ -1987,8 +2023,10 @@ static addrbank *expamem_map_z3fastmem (struct autoconfig_info *aci)
        uaecptr z3fs = expamem_board_pointer;
        uae_u32 size = currprefs.z3fastmem[devnum].size;
 
-       if (ab->allocated_size)
+       if (ab->allocated_size) {
                map_banks_z3(ab, z3fs >> 16, size >> 16);
+               initramboard(ab, &currprefs.z3fastmem[devnum]);
+       }
        return ab;
 }
 
@@ -3701,6 +3739,7 @@ void expansion_map(void)
                        } else if (rb->no_reset_unmap && rb->start_address) {
                                map_banks(&fastmem_bank[i], rb->start_address >> 16, rb->size >> 16, 0);
                        }
+                       initramboard(&fastmem_bank[i], rb);
                }
                rb = &currprefs.z3fastmem[i];
                if (rb->size) {
@@ -3709,6 +3748,7 @@ void expansion_map(void)
                        } else if (rb->no_reset_unmap && rb->start_address) {
                                map_banks(&z3fastmem_bank[i], rb->start_address >> 16, rb->size >> 16, 0);
                        }
+                       initramboard(&z3fastmem_bank[i], rb);
                }
        }
        if (currprefs.z3chipmem_size) {
index be4735766417dadedc87071ac6d6a86ab9d257eb..1e1a78e639197898f7d8bf9a22c6bd3842e112b3 100644 (file)
@@ -420,6 +420,10 @@ struct ramboard
        uae_u32 start_address;
        uae_u32 end_address;
        uae_u32 write_address;
+       bool readonly;
+       uae_u32 loadoffset;
+       uae_u32 fileoffset, filesize;
+       TCHAR loadfile[MAX_DPATH];
 };
 struct expansion_params
 {