From e9eebbe260904c8c4506307ad6005fee1a7b4631 Mon Sep 17 00:00:00 2001 From: sorgelig Date: Mon, 20 Apr 2020 19:48:20 +0800 Subject: [PATCH] AtariST: fix memory fill, add aspect ratio option. --- menu.cpp | 75 ++++++++----------- support/st/st_tos.cpp | 162 +++++++++++++++++------------------------- support/st/st_tos.h | 7 +- 3 files changed, 99 insertions(+), 145 deletions(-) diff --git a/menu.cpp b/menu.cpp index aea6de8..d55b85a 100644 --- a/menu.cpp +++ b/menu.cpp @@ -2886,7 +2886,7 @@ void HandleUI(void) break; case MENU_ST_SYSTEM1: - menumask = 0x1fff; + menumask = 0x3fff; OsdSetTitle("Config", 0); m = 0; @@ -2907,16 +2907,16 @@ void HandleUI(void) snprintf(s, 29, " TOS: %s", tos_get_image_name()); OsdWrite(m++, s, menusub == 4); + strcpy(s, " Chipset: "); + // extract TOS_CONTROL_STE and TOS_CONTROL_MSTE bits + strcat(s, atari_chipset[(tos_system_ctrl() >> 23) & 3]); + OsdWrite(m++, s, menusub == 5); + // Blitter is always present in >= STE enable = (tos_system_ctrl() & (TOS_CONTROL_STE | TOS_CONTROL_MSTE)) ? 1 : 0; strcpy(s, " Blitter: "); strcat(s, ((tos_system_ctrl() & TOS_CONTROL_BLITTER) || enable) ? "On" : "Off"); - OsdWrite(m++, s, menusub == 5, enable); - - strcpy(s, " Chipset: "); - // extract TOS_CONTROL_STE and TOS_CONTROL_MSTE bits - strcat(s, atari_chipset[(tos_system_ctrl() >> 23) & 3]); - OsdWrite(m++, s, menusub == 6, 0); + OsdWrite(m++, s, menusub == 6, enable); // Viking card can only be enabled with max 8MB RAM enable = (tos_system_ctrl() & 0xe) <= TOS_MEMCONFIG_8M; @@ -2924,33 +2924,30 @@ void HandleUI(void) strcat(s, ((tos_system_ctrl() & TOS_CONTROL_VIKING) && enable) ? "On" : "Off"); OsdWrite(m++, s, menusub == 7, enable ? 0 : 1); - /* - strcpy(s, " CDC I/O: "); - strcat(s, config_tos_usb[tos_get_cdc_control_redirect()]); - OsdWrite(m++, s, menusub == 3, 0); - */ + strcpy(s, " Aspect: "); + strcat(s, (tos_system_ctrl() & TOS_CONTROL_VIDEO_AR) ? "16:9" : "4:3"); + OsdWrite(m++, s, menusub == 8); - OsdWrite(m++); strcpy(s, " Screen: "); if (tos_system_ctrl() & TOS_CONTROL_VIDEO_COLOR) strcat(s, "Color"); else strcat(s, "Mono"); - OsdWrite(m++, s, menusub == 8, 0); + OsdWrite(m++, s, menusub == 9); strcpy(s, " Border: "); if (tos_system_ctrl() & TOS_CONTROL_BORDER) strcat(s, "Visible"); else strcat(s, "Full"); - OsdWrite(m++, s, menusub == 9, 0); + OsdWrite(m++, s, menusub == 10); strcpy(s, " Scanlines: "); strcat(s, scanlines[(tos_system_ctrl() >> 20) & 3]); - OsdWrite(m++, s, menusub == 10, 0); + OsdWrite(m++, s, menusub == 11); strcpy(s, " YM-Audio: "); strcat(s, stereo[(tos_system_ctrl() & TOS_CONTROL_STEREO) ? 1 : 0]); - OsdWrite(m++, s, menusub == 11, 0); + OsdWrite(m++, s, menusub == 12); for (; m < OsdGetSize() - 1; m++) OsdWrite(m); - OsdWrite(15, STD_EXIT, menusub == 12, 0); + OsdWrite(15, STD_EXIT, menusub == 13); parentstate = menustate; menustate = MENU_ST_SYSTEM2; @@ -2963,8 +2960,7 @@ void HandleUI(void) menusub = 3; if(need_reset) tos_reset(1); } - - if (select) + else if (select) { switch (menusub) { @@ -2991,7 +2987,7 @@ void HandleUI(void) // RAM int mem = (tos_system_ctrl() >> 1) & 7; // current memory config mem++; - if (mem > 5) mem = 0; // cycle 4MB/8MB/14MB + if (mem > 5) mem = 0; tos_update_sysctrl((tos_system_ctrl() & ~0x0e) | (mem << 1)); need_reset = 1; menustate = MENU_ST_SYSTEM1; @@ -3002,33 +2998,19 @@ void HandleUI(void) SelectFile("IMG", SCANO_DIR, MENU_ST_SYSTEM_FILE_SELECTED, MENU_ST_SYSTEM1); break; - /* - case 3: - if (tos_get_cdc_control_redirect() == CDC_REDIRECT_MIDI) - { - tos_set_cdc_control_redirect(CDC_REDIRECT_NONE); - } - else - { - tos_set_cdc_control_redirect(tos_get_cdc_control_redirect() + 1); - } - menustate = MENU_ST_SYSTEM1; - break; - */ - case 5: - if (!(tos_system_ctrl() & TOS_CONTROL_STE)) { - tos_update_sysctrl(tos_system_ctrl() ^ TOS_CONTROL_BLITTER); + unsigned long chipset = (tos_system_ctrl() >> 23) + 1; + if (chipset == 4) chipset = 0; + tos_update_sysctrl((tos_system_ctrl() & ~(TOS_CONTROL_STE | TOS_CONTROL_MSTE)) | (chipset << 23)); menustate = MENU_ST_SYSTEM1; } break; case 6: + if (!(tos_system_ctrl() & TOS_CONTROL_STE)) { - unsigned long chipset = (tos_system_ctrl() >> 23) + 1; - if (chipset == 4) chipset = 0; - tos_update_sysctrl((tos_system_ctrl() & ~(TOS_CONTROL_STE | TOS_CONTROL_MSTE)) | (chipset << 23)); + tos_update_sysctrl(tos_system_ctrl() ^ TOS_CONTROL_BLITTER); menustate = MENU_ST_SYSTEM1; } break; @@ -3040,16 +3022,21 @@ void HandleUI(void) break; case 8: - tos_update_sysctrl(tos_system_ctrl() ^ TOS_CONTROL_VIDEO_COLOR); + tos_update_sysctrl(tos_system_ctrl() ^ TOS_CONTROL_VIDEO_AR); menustate = MENU_ST_SYSTEM1; break; case 9: - tos_update_sysctrl(tos_system_ctrl() ^ TOS_CONTROL_BORDER); + tos_update_sysctrl(tos_system_ctrl() ^ TOS_CONTROL_VIDEO_COLOR); menustate = MENU_ST_SYSTEM1; break; case 10: + tos_update_sysctrl(tos_system_ctrl() ^ TOS_CONTROL_BORDER); + menustate = MENU_ST_SYSTEM1; + break; + + case 11: { // next scanline state int scan = ((tos_system_ctrl() >> 20) + 1) & 3; @@ -3058,13 +3045,13 @@ void HandleUI(void) } break; - case 11: + case 12: tos_update_sysctrl(tos_system_ctrl() ^ TOS_CONTROL_STEREO); menustate = MENU_ST_SYSTEM1; break; - case 12: + case 13: menustate = MENU_ST_MAIN1; menusub = 3; if (need_reset) tos_reset(1); diff --git a/support/st/st_tos.cpp b/support/st/st_tos.cpp index e87d671..ab22c3a 100644 --- a/support/st/st_tos.cpp +++ b/support/st/st_tos.cpp @@ -49,30 +49,6 @@ static const char *acsi_cmd_name(int cmd) { return cmdname[cmd]; } -/* -int tos_get_cdc_control_redirect(void) -{ - return config.cdc_control_redirect; -} - -void tos_set_cdc_control_redirect(char mode) -{ - if (mode <= CDC_REDIRECT_MIDI) - { - config.cdc_control_redirect = mode; - - // core is only informed about redirections of rs232/par/midi - if (mode < CDC_REDIRECT_RS232) - mode = 0; - else - mode -= CDC_REDIRECT_RS232 - 1; - - tos_update_sysctrl((tos_system_ctrl() & ~0x0c000000) | - (((unsigned long)mode) << 26)); - } -} -*/ - static void set_control(uint32_t ctrl) { spi_uio_cmd_cont(UIO_SET_STATUS2); @@ -80,7 +56,13 @@ static void set_control(uint32_t ctrl) DisableIO(); } -static void memory_read(unsigned char *data, unsigned long words) +void tos_update_sysctrl(uint32_t ctrl) +{ + config.system_ctrl = ctrl; + set_control(config.system_ctrl); +} + +static void memory_read(uint8_t *data, uint32_t words) { EnableIO(); spi8(ST_READ_MEMORY); @@ -92,7 +74,7 @@ static void memory_read(unsigned char *data, unsigned long words) DisableIO(); } -static void memory_write(unsigned char *data, unsigned long words) +static void memory_write(uint8_t *data, uint32_t words) { EnableIO(); spi8(ST_WRITE_MEMORY); @@ -103,7 +85,7 @@ static void memory_write(unsigned char *data, unsigned long words) DisableIO(); } -static void dma_ack(unsigned char status) +static void dma_ack(uint8_t status) { EnableIO(); spi8(ST_ACK_DMA); @@ -122,26 +104,25 @@ static void handle_acsi(unsigned char *buffer) { static uint8_t buf[65536]; - static unsigned char asc[2] = { 0,0 }; - unsigned char target = buffer[10] >> 5; - unsigned char device = buffer[1] >> 5; - unsigned char cmd = buffer[0]; - unsigned long lba = 256 * 256 * (buffer[1] & 0x1f) + - 256 * buffer[2] + buffer[3]; - unsigned int length = buffer[4]; + static uint8_t asc[2] = { 0,0 }; + uint8_t target = buffer[10] >> 5; + uint8_t device = buffer[1] >> 5; + uint8_t cmd = buffer[0]; + uint32_t lba = 256 * 256 * (buffer[1] & 0x1f) + 256 * buffer[2] + buffer[3]; + uint32_t length = buffer[4]; if (length == 0) length = 256; if (0) { tos_debugf("ACSI: target %d.%d, \"%s\" (%02x)", target, device, acsi_cmd_name(cmd), cmd); - tos_debugf("ACSI: lba %lu (%lx), length %u", lba, lba, length); + tos_debugf("ACSI: lba %u (%x), length %u", lba, lba, length); } // only a harddisk on ACSI 0/1 is supported // ACSI 0/1 is only supported if a image is loaded if (((target < 2) && (hdd_image[target].size != 0))) { - unsigned long blocks = hdd_image[target].size / 512; + uint32_t blocks = hdd_image[target].size / 512; // only lun0 is fully supported switch (cmd) { @@ -229,7 +210,7 @@ static void handle_acsi(unsigned char *buffer) } else { - tos_debugf("ACSI: read (%lu+%d) exceeds device limits (%lu)", lba, length, blocks); + tos_debugf("ACSI: read (%u+%d) exceeds device limits (%u)", lba, length, blocks); dma_ack(0x02); asc[target] = 0x21; } @@ -277,8 +258,7 @@ static void handle_acsi(unsigned char *buffer) asc[target] = 0x00; } else { - tos_debugf("ACSI: write (%lu+%d) exceeds device limits (%lu)", - lba, length, blocks); + tos_debugf("ACSI: write (%u+%d) exceeds device limits (%u)", lba, length, blocks); dma_ack(0x02); asc[target] = 0x21; } @@ -307,7 +287,7 @@ static void handle_acsi(unsigned char *buffer) case 0x1a: // mode sense if (device == 0) { - tos_debugf("ACSI: mode sense, blocks = %lu", blocks); + tos_debugf("ACSI: mode sense, blocks = %u", blocks); bzero(dma_buffer, 512); dma_buffer[3] = 8; // size of extent descriptor list dma_buffer[5] = blocks >> 16; @@ -351,7 +331,7 @@ static void handle_acsi(unsigned char *buffer) static void get_dmastate() { - unsigned char buffer[16]; + uint8_t buffer[16]; EnableIO(); spi8(ST_GET_DMASTATE); @@ -361,18 +341,16 @@ static void get_dmastate() if (buffer[10] & 0x01) handle_acsi(buffer); } -static void fill_tx(unsigned char fill, unsigned int len, unsigned char index) +static void fill_tx(uint16_t fill, uint32_t len, int index) { user_io_set_index(index); user_io_set_download(1); - uint16_t wfill = (fill << 8) | fill; - len /= 2; - EnableIO(); + EnableFpga(); spi8(UIO_FILE_TX_DAT); - while(len--) spi_w(wfill); - DisableIO(); + while(len--) spi_w(fill); + DisableFpga(); user_io_set_download(0); } @@ -381,18 +359,18 @@ void tos_load_cartridge(const char *name) { if (name) strncpy(config.cart_img, name, 11); - // upload cartridge - if (config.cart_img[0] && FileExists(config.cart_img)) - { - user_io_file_tx(config.cart_img, 0x02); - tos_debugf("%s uploaded", config.cart_img); - return; - } - // erase that ram area to remove any previously uploaded // image tos_debugf("Erasing cart memory"); - fill_tx(0xff, 128 * 1024, 0x02); + fill_tx(0xff, 128 * 1024, 2); + + // upload cartridge + if (config.cart_img[0] && FileExists(config.cart_img)) + { + user_io_file_tx(config.cart_img, 2); + tos_debugf("%s uploaded", config.cart_img); + return; + } } char tos_cartridge_is_inserted() @@ -425,12 +403,6 @@ void tos_poll() } } -void tos_update_sysctrl(unsigned long n) -{ - config.system_ctrl = n; - set_control(config.system_ctrl); -} - const char *tos_get_disk_name(int index) { const char *name = 0; @@ -524,43 +496,41 @@ unsigned long tos_system_ctrl(void) return config.system_ctrl; } -static void tos_upload_mist2() -{ - // clear first 16k - tos_debugf("Clear first 16k"); - fill_tx(0, 16 * 1024, 0x03); - - // upload and verify tos image - int len = FileLoad(config.tos_img, 0, 0); - if (len) - { - tos_debugf("TOS.IMG:\n size = %d", len); - - if (len >= 256 * 1024) user_io_file_tx(config.tos_img, 0); - else if (len == 192 * 1024) user_io_file_tx(config.tos_img, 0x01); - else tos_debugf("WARNING: Unexpected TOS size!"); - } - else - { - tos_debugf("Unable to find tos.img"); - return; - } - - tos_load_cartridge(NULL); - - for (int i = 0; i < 2; i++) - { - if (FileExists(config.acsi_img[i])) - { - tos_select_hdd_image(i, config.acsi_img[i]); - } - } -} - void tos_reset(char cold) { tos_update_sysctrl(config.system_ctrl | TOS_CONTROL_CPU_RESET); // set reset - if (cold) tos_upload_mist2(); + if (cold) + { + // clear first 16k + tos_debugf("Clear first 16k"); + fill_tx(0, 16 * 1024, 3); + + // upload and verify tos image + int len = FileLoad(config.tos_img, 0, 0); + if (len) + { + tos_debugf("TOS.IMG:\n size = %d", len); + + if (len >= 256 * 1024) user_io_file_tx(config.tos_img, 0); + else if (len == 192 * 1024) user_io_file_tx(config.tos_img, 1); + else tos_debugf("WARNING: Unexpected TOS size!"); + } + else + { + tos_debugf("Unable to find tos.img"); + return; + } + + tos_load_cartridge(NULL); + + for (int i = 0; i < 2; i++) + { + if (FileExists(config.acsi_img[i])) + { + tos_select_hdd_image(i, config.acsi_img[i]); + } + } + } tos_update_sysctrl(config.system_ctrl & ~TOS_CONTROL_CPU_RESET); // release reset } diff --git a/support/st/st_tos.h b/support/st/st_tos.h index d6c9a7b..652fe33 100644 --- a/support/st/st_tos.h +++ b/support/st/st_tos.h @@ -34,7 +34,7 @@ #define TOS_CONTROL_FDC_WR_PROT_A 0x00000040 #define TOS_CONTROL_FDC_WR_PROT_B 0x00000080 #define TOS_CONTROL_VIDEO_COLOR 0x00000100 // input to mfp -#define TOS_CONTROL_PAL50HZ 0x00000200 // display pal at 50hz (56 hz otherwise) +#define TOS_CONTROL_VIDEO_AR 0x00000200 // 16:9 / 4:3 // up to eight acsi devices can be enabled #define TOS_ACSI0_ENABLE 0x00000400 @@ -71,7 +71,7 @@ unsigned long tos_system_ctrl(void); void tos_upload(const char *); void tos_poll(); -void tos_update_sysctrl(unsigned long); +void tos_update_sysctrl(uint32_t ctrl); char tos_disk_is_inserted(int index); void tos_insert_disk(int index, const char *name); void tos_eject_all(); @@ -82,9 +82,6 @@ const char *tos_get_cartridge_name(); char tos_cartridge_is_inserted(); void tos_load_cartridge(const char *); -int tos_get_cdc_control_redirect(void); -void tos_set_cdc_control_redirect(char mode); - void tos_config_load(int slot); // slot -1 == last config void tos_config_save(int slot); int tos_config_exists(int slot);