From 1cf54309cca646b845794b46a9b44de510aa019f Mon Sep 17 00:00:00 2001 From: Toni Wilen Date: Sat, 2 Dec 2017 18:42:57 +0200 Subject: [PATCH] Gigatron Arriba and KS12 boot hack fix. --- expansion.cpp | 58 +++++++++++++++++++++---- filesys.cpp | 31 +------------- ide.cpp | 91 +++++++++++++++++++++++++++++++--------- idecontrollers.cpp | 74 ++++++++++++++++++++++++++++++-- include/autoconf.h | 1 + include/idecontrollers.h | 3 ++ include/rommgr.h | 1 + 7 files changed, 200 insertions(+), 59 deletions(-) diff --git a/expansion.cpp b/expansion.cpp index a153615c..382d6801 100644 --- a/expansion.cpp +++ b/expansion.cpp @@ -1807,16 +1807,50 @@ static addrbank *expamem_map_filesys (struct autoconfig_info *aci) } #if KS12_BOOT_HACK -extern uaecptr ks12_resident; -static void set_ks12_boot_hack(bool enable) +static uaecptr ks12_resident; +static void set_ks12_boot_hack(void) { uaecptr old = here(); org(ks12_resident); - dw(enable ? 0x4afc : 0x0000); - org(ks12_resident + 9); + dw(ks12orolder() ? 0x4afc : 0x0000); + org(ks12_resident + 11); db((uae_u8)kickstart_version); org(old); } + +void create_ks12_boot(void) +{ + // KS 1.2 boot resident + uaecptr name = ds(_T("UAE boot")); + align(2); + uaecptr code = here(); + // allocate fake diagarea + dl(0x48e73f3e); // movem.l d2-d7/a2-a6,-(sp) + dw(0x203c); // move.l #x,d0 + dl(0x0300); + dw(0x7201); // moveq #1,d1 + dl(0x4eaeff3a); // jsr -0xc6(a6) + dw(0x2440); // move.l d0,a2 ;diag area + dw(0x9bcd); // sub.l a5,a5 ;expansionbase + dw(0x97cb); // sub.l a3,a3 ;configdev + dw(0x4eb9); // jsr + dl(ROM_filesys_diagentry); + dl(0x4cdf7cfc); // movem.l (sp)+,d2-d7/a2-a6 + dw(0x4e75); + // struct Resident + ks12_resident = here(); + dw(0x0000); + dl(ks12_resident); + dl(ks12_resident + 26); + db(1); // RTF_COLDSTART + db((uae_u8)kickstart_version); // version + db(0); // NT_UNKNOWN + db(1); // priority + dl(name); + dl(name); + dl(code); + set_ks12_boot_hack(); +} #endif static bool expamem_init_filesys(struct autoconfig_info *aci) @@ -1895,7 +1929,7 @@ static bool expamem_init_filesys(struct autoconfig_info *aci) put_word_host(expamem + FILESYS_DIAGAREA + FILESYS_BOOTPOINT, 0x4EF9); /* JMP */ put_long_host(expamem + FILESYS_DIAGAREA + FILESYS_BOOTPOINT + 2, EXPANSION_bootcode); - set_ks12_boot_hack(ks12); + set_ks12_boot_hack(); return true; } @@ -3540,6 +3574,7 @@ void expamem_reset (void) } } + set_ks12_boot_hack(); call_card_init(0); } } @@ -4225,11 +4260,11 @@ static const struct expansionboardsettings cubo_settings[] = { _T("dip_2_5") }, { - _T("DIP2 #6)"), + _T("DIP2 #6"), _T("dip_2_6") }, { - _T("DIP2 #7 "), + _T("DIP2 #7"), _T("dip_2_7") }, { @@ -4746,6 +4781,15 @@ const struct expansionromtype expansionroms[] = { 0, 0, 0, false, NULL, false, 0, dataflyersplus_settings }, + { + _T("arriba"), _T("Arriba"), _T("Gigatron"), + NULL, arriba_init, NULL, arriba_add_ide_unit, ROMTYPE_ARRIBA | ROMTYPE_NOT, 0, 0, BOARD_AUTOCONFIG_Z2, false, + NULL, 0, + false, EXPANSIONTYPE_IDE, + 0, 0, 0, false, NULL, + false, 0, NULL, + { 0xc1, 0x01, 0x00, 0x00, 0x08, 0x3d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, + }, { _T("gvp1"), _T("GVP Series I"), _T("Great Valley Products"), NULL, gvp_init_s1, NULL, gvp_s1_add_scsi_unit, ROMTYPE_GVPS1 | ROMTYPE_NONE, ROMTYPE_GVPS12, 0, BOARD_AUTOCONFIG_Z2, false, diff --git a/filesys.cpp b/filesys.cpp index f43a60fc..d30ae45e 100644 --- a/filesys.cpp +++ b/filesys.cpp @@ -134,7 +134,6 @@ static void aino_test_init (a_inode *aino) #define UAEFS_VERSION "UAEfs 0.5" uaecptr filesys_initcode, filesys_initcode_ptr, filesys_initcode_real; -uaecptr ks12_resident; static uaecptr bootrom_start; static uae_u32 fsdevname, fshandlername, filesys_configdev; static uae_u32 cdfs_devname, cdfs_handlername; @@ -9044,35 +9043,7 @@ void filesys_install (void) org (loop); - // KS 1.2 boot resident - uaecptr name = ds(_T("UAE boot")); - align(2); - uaecptr code = here(); - // allocate fake diagarea - dl(0x48e73f3e); // movem.l d2-d7/a2-a6,-(sp) - dw(0x203c); // move.l #x,d0 - dl(0x0300); - dw(0x7201); // moveq #1,d1 - dl(0x4eaeff3a); // jsr -0xc6(a6) - dw(0x2440); // move.l d0,a2 ;diag area - dw(0x9bcd); // sub.l a5,a5 ;expansionbase - dw(0x97cb); // sub.l a3,a3 ;configdev - dw(0x4eb9); // jsr - dl(ROM_filesys_diagentry); - dl(0x4cdf7cfc); // movem.l (sp)+,d2-d7/a2-a6 - dw(0x4e75); - // struct Resident - ks12_resident = here(); - dw(0x0000); - dl(ks12_resident); - dl(ks12_resident + 26); - db(1); // RTF_COLDSTART - db((uae_u8)kickstart_version); // version - db(0); // NT_UNKNOWN - db(1); // priority - dl(name); - dl(name); - dl(code); + create_ks12_boot(); } uaecptr filesys_get_entry(int index) diff --git a/ide.cpp b/ide.cpp index 86aa357b..f65f7a4f 100644 --- a/ide.cpp +++ b/ide.cpp @@ -6,7 +6,7 @@ * (c) 2006 - 2015 Toni Wilen */ -#define IDE_LOG 0 +#define IDE_LOG 1 #include "sysconfig.h" #include "sysdeps.h" @@ -123,7 +123,6 @@ bool ata_get_identity(struct ini_data *ini, uae_u8 *out, bool overwrite) return true; } - uae_u16 adide_decode_word(uae_u16 w) { uae_u16 o = 0; @@ -277,8 +276,6 @@ static void pw (struct ide_hdf *ide, int offset, uae_u16 w) if (ide->byteswap) { w = (w >> 8) | (w << 8); } - if (ide->adide) - w = adide_decode_word(w); ide->secbuf[offset * 2 + 0] = (uae_u8)w; ide->secbuf[offset * 2 + 1] = w >> 8; } @@ -288,8 +285,6 @@ static void pwand (struct ide_hdf *ide, int offset, uae_u16 w) if (ide->byteswap) { w = (w >> 8) | (w << 8); } - if (ide->adide) - w = adide_decode_word(w); ide->secbuf[offset * 2 + 0] &= ~((uae_u8)w); ide->secbuf[offset * 2 + 1] &= ~(w >> 8); } @@ -299,8 +294,6 @@ static void pwor (struct ide_hdf *ide, int offset, uae_u16 w) if (ide->byteswap) { w = (w >> 8) | (w << 8); } - if (ide->adide) - w = adide_decode_word(w); ide->secbuf[offset * 2 + 0] |= (uae_u8)w; ide->secbuf[offset * 2 + 1] |= w >> 8; } @@ -323,8 +316,6 @@ static void ps (struct ide_hdf *ide, int offset, const TCHAR *src, int max) if (ide->byteswap) { w = (w >> 8) | (w << 8); } - if (ide->adide) - w = adide_decode_word(w); ide->secbuf[offset * 2 + 0] = w >> 8; ide->secbuf[offset * 2 + 1] = w >> 0; offset++; @@ -556,6 +547,14 @@ static void ide_identify_drive (struct ide_hdf *ide) ide_data_ready (ide); ide->direction = 0; ide_identity_buffer(ide); + if (ide->adide) { + for (int i = 0; i < 256; i++) { + uae_u16 w = (ide->secbuf[i * 2 + 0] << 8) | (ide->secbuf[i * 2 + 1] << 0); + uae_u16 we = adide_decode_word(w); + ide->secbuf[i * 2 + 0] = we >> 8; + ide->secbuf[i * 2 + 1] = we >> 0; + } + } } static void set_signature (struct ide_hdf *ide) @@ -912,9 +911,16 @@ static void do_process_rw_command (struct ide_hdf *ide) { unsigned int cyl, head, sec, nsec, nsec_total; uae_u64 lba; - bool last; + bool last = true; ide->data_offset = 0; + + if (ide->direction > 1) { + // FORMAT TRACK? + // Don't write anything + goto end; + } + nsec = get_nsec (ide); get_lbachs (ide, &lba, &cyl, &head, &sec); if (IDE_LOG > 1) @@ -966,6 +972,7 @@ static void do_process_rw_command (struct ide_hdf *ide) hdf_write (&ide->hdhfd.hfd, ide->secbuf, ide->start_lba * ide->blocksize, ide->start_nsec * ide->blocksize); } +end: if (ide->direction) { if (last) { ide_fast_interrupt(ide); @@ -1058,6 +1065,34 @@ static void ide_write_sectors (struct ide_hdf *ide, int flags) ide->regs.ide_status &= ~IDE_STATUS_BSY; } +static void ide_format_track(struct ide_hdf *ide) +{ + unsigned int cyl, head, sec; + uae_u64 lba; + + gui_flicker_led(LED_HD, ide->num, 2); + cyl = (ide->regs.ide_hcyl << 8) | ide->regs.ide_lcyl; + head = ide->regs.ide_select & 15; + sec = ide->regs.ide_nsector; + lba = (((cyl) * ide->hdhfd.heads + (head)) * ide->hdhfd.secspertrack); + if (lba >= ide->max_lba) { + ide_interrupt(ide); + return; + } + if (IDE_LOG > 0) + write_log(_T("IDE%d format cyl=%d, head=%d, sectors=%d\n"), ide->num, cyl, head, sec); + + ide->data_multi = 1; + ide->data_offset = 0; + ide->data_size = ide->blocksize; + ide->direction = 2; + ide->buffer_offset = 0; + + // write start: set DRQ and clear BSY. No interrupt. + ide->regs.ide_status |= IDE_STATUS_DRQ; + ide->regs.ide_status &= ~IDE_STATUS_BSY; +} + static void ide_do_command (struct ide_hdf *ide, uae_u8 cmd) { int lba48 = ide->lba48; @@ -1072,7 +1107,9 @@ static void ide_do_command (struct ide_hdf *ide, uae_u8 cmd) if (ide->atapi) { - gui_flicker_led (LED_CD, ide->num, 1); + if (ide->scsi->device_type == UAEDEV_CD) { + gui_flicker_led(LED_CD, ide->num, 1); + } ide->atapi_drdy = true; if (cmd == 0x00) { /* nop */ ide_interrupt (ide); @@ -1121,8 +1158,8 @@ static void ide_do_command (struct ide_hdf *ide, uae_u8 cmd) ide_write_sectors (ide, 1); } else if (cmd == 0x39 && lba48) { /* write multiple ext */ ide_write_sectors (ide, 1|2); - } else if (cmd == 0x50) { /* format track (nop) */ - ide_interrupt (ide); + } else if (cmd == 0x50) { /* format track */ + ide_format_track (ide); } else if (cmd == 0xef) { /* set features */ ide_set_features (ide); } else if (cmd == 0x00) { /* nop */ @@ -1557,10 +1594,10 @@ struct ide_hdf *add_ide_unit (struct ide_hdf **idetable, int max, int ch, struct memcpy (&ide->hdhfd.hfd.ci, ci, sizeof (struct uaedev_config_info)); if (ci->type == UAEDEV_CD && ci->device_emu_unit >= 0) { - device_func_init (0); - ide->scsi = scsi_alloc_cd (ch, ci->device_emu_unit, true); + device_func_init(0); + ide->scsi = scsi_alloc_cd(ch, ci->device_emu_unit, true); if (!ide->scsi) { - write_log (_T("IDE: CD EMU unit %d failed to open\n"), ide->cd_unit_num); + write_log(_T("IDE: CD EMU unit %d failed to open\n"), ide->cd_unit_num); return NULL; } @@ -1568,9 +1605,25 @@ struct ide_hdf *add_ide_unit (struct ide_hdf **idetable, int max, int ch, struct ide->cd_unit_num = ci->device_emu_unit; ide->atapi = true; ide->blocksize = 512; - gui_flicker_led (LED_CD, ch, -1); + gui_flicker_led(LED_CD, ch, -1); + + write_log(_T("IDE%d CD %d\n"), ch, ide->cd_unit_num); + + } else if (ci->type == UAEDEV_TAPE) { + + ide->scsi = scsi_alloc_tape(ch, ci->rootdir, ci->readonly); + if (!ide->scsi) { + write_log(_T("IDE: TAPE EMU unit %d failed to open\n"), ch); + return NULL; + } + + ide_identity_buffer(ide); + ide->atapi = true; + ide->blocksize = 512; + ide->cd_unit_num = -1; + + write_log(_T("IDE%d TAPE %d\n"), ch, ide->cd_unit_num); - write_log (_T("IDE%d CD %d\n"), ch, ide->cd_unit_num); } else if (ci->type == UAEDEV_HDF) { diff --git a/idecontrollers.cpp b/idecontrollers.cpp index 338ba1fe..a2b61a24 100644 --- a/idecontrollers.cpp +++ b/idecontrollers.cpp @@ -36,7 +36,8 @@ #define GVP_IDE 0 // GVP A3001 #define ALF_IDE 1 -#define APOLLO_IDE (ALF_IDE + MAX_DUPLICATE_EXPANSION_BOARDS) +#define ARRIBA_IDE 2 +#define APOLLO_IDE (ARRIBA_IDE + MAX_DUPLICATE_EXPANSION_BOARDS) #define MASOBOSHI_IDE (APOLLO_IDE + MAX_DUPLICATE_EXPANSION_BOARDS) #define ADIDE_IDE (MASOBOSHI_IDE + MAX_DUPLICATE_EXPANSION_BOARDS) #define MTEC_IDE (ADIDE_IDE + MAX_DUPLICATE_EXPANSION_BOARDS) @@ -102,6 +103,7 @@ static struct ide_board *golemfast_board[MAX_DUPLICATE_EXPANSION_BOARDS]; static struct ide_board *buddha_board[MAX_DUPLICATE_EXPANSION_BOARDS]; static struct ide_board *dataflyerplus_board[MAX_DUPLICATE_EXPANSION_BOARDS]; static struct ide_board *ateam_board[MAX_DUPLICATE_EXPANSION_BOARDS]; +static struct ide_board *arriba_board[MAX_DUPLICATE_EXPANSION_BOARDS]; static struct ide_board *fastata4k_board[MAX_DUPLICATE_EXPANSION_BOARDS]; static struct ide_hdf *idecontroller_drive[TOTAL_IDE * 2]; @@ -518,6 +520,16 @@ static int get_ateam_reg(uaecptr addr, struct ide_board *board) return addr; } +static int get_arriba_reg(uaecptr addr, struct ide_board *board) +{ + if (!(addr & 0x8000)) + return -1; + if (addr & 1) + return -1; + int reg = ((addr & 0x0fff) >> 9) & 7; + return reg; +} + static int get_fastata4k_reg(uaecptr addr, struct ide_board *board, int *portnum) { *portnum = 0; @@ -798,6 +810,13 @@ static uae_u32 ide_read_byte(struct ide_board *board, uaecptr addr) } } + } else if (board->type == ARRIBA_IDE) { + + int reg = get_arriba_reg(addr, board); + if (reg >= 0) { + v = get_ide_reg(board, reg); + } + } else if (board->type == FASTATA4K_IDE) { int portnum; @@ -1019,6 +1038,13 @@ static uae_u32 ide_read_word(struct ide_board *board, uaecptr addr) v = get_ide_reg_multi(board, IDE_DATA, 0, 1); } + } else if (board->type == ARRIBA_IDE) { + + int reg = get_arriba_reg(addr, board); + if (reg == 0) { + v = get_ide_reg_multi(board, IDE_DATA, 0, 1); + } + } else if (board->type == FASTATA4K_IDE) { int portnum; @@ -1265,6 +1291,13 @@ static void ide_write_byte(struct ide_board *board, uaecptr addr, uae_u8 v) } } + } else if (board->type == ARRIBA_IDE) { + + int reg = get_arriba_reg(addr, board); + if (reg >= 0) { + put_ide_reg(board, reg, v); + } + } else if (board->type == FASTATA4K_IDE) { int portnum; @@ -1412,11 +1445,18 @@ static void ide_write_word(struct ide_board *board, uaecptr addr, uae_u16 v) } } else if (board->type == ATEAM_IDE) { - + if (board->configured && (addr & 0xf800) == 0xf800) { put_ide_reg_multi(board, IDE_DATA, v, 0, 1); } - + + } else if (board->type == ARRIBA_IDE) { + + int reg = get_arriba_reg(addr, board); + if (!reg) { + put_ide_reg_multi(board, IDE_DATA, v, 0, 1); + } + } else if (board->type == FASTATA4K_IDE) { int portnum; @@ -2192,6 +2232,34 @@ void fastata4k_add_ide_unit(int ch, struct uaedev_config_info *ci, struct romcon add_ide_standard_unit(ch, ci, rc, fastata4k_board, FASTATA4K_IDE, false, false, 2); } +bool arriba_init(struct autoconfig_info *aci) +{ + const struct expansionromtype *ert = get_device_expansion_rom(ROMTYPE_ARRIBA); + if (!aci->doinit) { + aci->autoconfigp = ert->autoconfig; + return true; + } + + struct ide_board *ide = getide(aci); + + ide->bank = &ide_bank_generic; + ide->mask = 65536 - 1; + + for (int i = 0; i < 16; i++) { + uae_u8 b = ert->autoconfig[i]; + ew(ide, i * 4, b); + } + + aci->addrbank = ide->bank; + return true; +} + +void arriba_add_ide_unit(int ch, struct uaedev_config_info *ci, struct romconfig *rc) +{ + add_ide_standard_unit(ch, ci, rc, arriba_board, ARRIBA_IDE, false, false, 2); +} + + extern void x86_xt_ide_bios(struct zfile*, struct romconfig*); static bool x86_at_hd_init(struct autoconfig_info *aci, int type) { diff --git a/include/autoconf.h b/include/autoconf.h index 0dbf21b0..4d21a48b 100644 --- a/include/autoconf.h +++ b/include/autoconf.h @@ -135,6 +135,7 @@ extern void filesys_vsync (void); extern void filesys_install (void); extern void filesys_install_code (void); +extern void create_ks12_boot(void); extern uaecptr filesys_get_entry(int); extern void filesys_store_devinfo (uae_u8 *); extern void hardfile_install (void); diff --git a/include/idecontrollers.h b/include/idecontrollers.h index 781a78fc..9200d595 100644 --- a/include/idecontrollers.h +++ b/include/idecontrollers.h @@ -48,6 +48,9 @@ void ateam_add_ide_unit(int ch, struct uaedev_config_info *ci, struct romconfig bool fastata4k_init(struct autoconfig_info *aci); void fastata4k_add_ide_unit(int ch, struct uaedev_config_info *ci, struct romconfig *rc); +bool arriba_init(struct autoconfig_info *aci); +void arriba_add_ide_unit(int ch, struct uaedev_config_info *ci, struct romconfig *rc); + uae_u32 REGPARAM3 apollo_ide_lget (uaecptr addr) REGPARAM; uae_u32 REGPARAM3 apollo_ide_wget (uaecptr addr) REGPARAM; uae_u32 REGPARAM3 apollo_ide_bget (uaecptr addr) REGPARAM; diff --git a/include/rommgr.h b/include/rommgr.h index 0cf7f741..7cc3638f 100644 --- a/include/rommgr.h +++ b/include/rommgr.h @@ -161,6 +161,7 @@ extern int decode_cloanto_rom_do (uae_u8 *mem, int size, int real_size); #define ROMTYPE_CUBO 0x0010006b #define ROMTYPE_GOLEMHD3000 0x0010006c #define ROMTYPE_WEDGE 0x0010006d +#define ROMTYPE_ARRIBA 0x0010006e #define ROMTYPE_NOT 0x00800000 #define ROMTYPE_QUAD 0x01000000 -- 2.47.3