From ea7d9ff4ffb158294e3b35c40b9713850af852b1 Mon Sep 17 00:00:00 2001 From: xrip Date: Sun, 26 Nov 2023 10:59:29 +0300 Subject: [PATCH] win32 fix --- CMakeLists.txt | 2 +- drivers/usb/msc_disk.c | 15 ++++++++++++++- drivers/usb/usb.c | 8 ++++++-- drivers/usb/usb.h | 4 +++- src/a20.h | 1 + src/cpu.c | 22 +++++++++++++++++----- src/emm.h | 2 +- src/emulator.h | 2 ++ src/main.cpp | 6 +++--- src/ports.c | 7 +++++-- 10 files changed, 53 insertions(+), 16 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 14e5fa6..4168a47 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -57,7 +57,7 @@ pico_set_program_name(pico-xt "PICO PC/XT 8086 Emulator by xrip/DnCraptor") pico_set_program_version(pico-xt "test") #set(PICO_DEOPTIMIZED_DEBUG 1) -set(OVERCLOCKING 366) +#set(OVERCLOCKING 366) if (PICO_PLATFORM STREQUAL "host") target_link_libraries(${PROJECT_NAME} SDL2) diff --git a/drivers/usb/msc_disk.c b/drivers/usb/msc_disk.c index bb1ab9f..9c1e242 100644 --- a/drivers/usb/msc_disk.c +++ b/drivers/usb/msc_disk.c @@ -28,12 +28,16 @@ #include "usb.h" #include "emulator.h" + +#if FDD1 #include "fdd.h" +#endif #include "startup_disk.h" char* fdd0_rom() { return FDD0; } +#if FDD1 char* fdd1_rom() { #if ROM_DRIVE_B return FDD1; @@ -41,9 +45,12 @@ char* fdd1_rom() { return NULL; #endif } +#endif + size_t fdd0_sz() { return sizeof FDD0; } +#if FDD1 size_t fdd1_sz() { #if ROM_DRIVE_B return sizeof FDD1; @@ -51,6 +58,7 @@ size_t fdd1_sz() { return 0; #endif } +#endif #if CFG_TUD_MSC @@ -70,6 +78,7 @@ void tud_msc_inquiry_cb(uint8_t lun, uint8_t vendor_id[8], uint8_t product_id[16 memcpy(vendor_id, vid, strlen(vid)); } break; +#if 1 case 1: { const char vid[] = "Pico-XT B:"; memcpy(vendor_id, vid, strlen(vid)); @@ -136,7 +145,8 @@ void tud_msc_capacity_cb(uint8_t lun, uint32_t* block_count, uint16_t* block_siz *block_size = DISK_BLOCK_SIZE; } break; - case 1: { +#if FDD1 + case 1: { auto r = getFileB_sz(); #if ROM_DRIVE_B *block_count = (r ? r : sizeof(FDD1)) / DISK_BLOCK_SIZE; @@ -146,6 +156,7 @@ void tud_msc_capacity_cb(uint8_t lun, uint32_t* block_count, uint16_t* block_siz *block_size = DISK_BLOCK_SIZE; } break; +#endif case 2: { *block_count = getFileC_sz() / DISK_BLOCK_SIZE; *block_size = DISK_BLOCK_SIZE; @@ -213,6 +224,8 @@ int32_t tud_msc_read10_cb(uint8_t lun, uint32_t lba, uint32_t offset, void* buff #endif } break; +#endif + case 2: { return img_disk_read_sec(2, buffer, lba) ? bufsize : -1; } diff --git a/drivers/usb/usb.c b/drivers/usb/usb.c index 70f67c2..30c2e85 100644 --- a/drivers/usb/usb.c +++ b/drivers/usb/usb.c @@ -301,12 +301,16 @@ void if_swap_drives() { if (backspacePressed && tabPressed && ctrlPressed) { if (already_swapped_fdds) { insertdisk(0, fdd0_sz(), fdd0_rom(), "\\XT\\fdd0.img"); - insertdisk(1, fdd1_sz(), fdd1_rom(), "\\XT\\fdd1.img"); +#if FDD1 + insertdisk(1, fdd1_sz(), fdd1_rom(), "\\XT\\fdd1.img"); +#endif already_swapped_fdds = false; return; } insertdisk(1, fdd0_sz(), fdd0_rom(), "\\XT\\fdd0.img"); - insertdisk(0, fdd1_sz(), fdd1_rom(), "\\XT\\fdd1.img"); +#if FDD1 + insertdisk(0, fdd1_sz(), fdd1_rom(), "\\XT\\fdd1.img"); +#endif already_swapped_fdds = true; } } \ No newline at end of file diff --git a/drivers/usb/usb.h b/drivers/usb/usb.h index e49201b..7f6abad 100644 --- a/drivers/usb/usb.h +++ b/drivers/usb/usb.h @@ -9,9 +9,11 @@ void if_swap_drives(); int overclock(); char* fdd0_rom(); -char* fdd1_rom(); size_t fdd0_sz(); +#if FDD1 +char* fdd1_rom(); size_t fdd1_sz(); +#endif // msc_disk.c bool tud_msc_ejected(); diff --git a/src/a20.h b/src/a20.h index 13ae836..4bcd0d9 100644 --- a/src/a20.h +++ b/src/a20.h @@ -4,6 +4,7 @@ #include #include +#include "emulator.h" uint8_t set_a20(uint8_t cond); diff --git a/src/cpu.c b/src/cpu.c index a7d6764..a3160f2 100644 --- a/src/cpu.c +++ b/src/cpu.c @@ -826,7 +826,7 @@ static void custom_on_board_emm() { // AL = physical_page_number // BX = logical_page_number, if FFFFh, the physical page specified in AL will be unmapped // DX = emm_handle - auto AL = CPU_AL; + uint8_t AL = CPU_AL; CPU_AX = map_unmap_emm_page(CPU_AL, CPU_BX, CPU_DX); sprintf(tmp, "LIM40 FN %Xh res: phys page %Xh was mapped to %Xh log for %d EMM handler", FN, AL, CPU_AX, CPU_DX); logMsg(tmp); @@ -835,7 +835,7 @@ static void custom_on_board_emm() { } // Deallocate Pages deallocates the logical pages currently allocated to an EMM handle. case 0x45: { - auto emm_handle = CPU_DX; + uint16_t emm_handle = CPU_DX; CPU_AX = deallocate_emm_pages(emm_handle); sprintf(tmp, "LIM40 FN %Xh res: %Xh - EMM handler dealloc", FN, emm_handle); logMsg(tmp); if (CPU_AX) zf = 1; else zf = 0; @@ -1320,6 +1320,13 @@ void intcall86(uint8_t intnum) { case 0x10: //printf("INT 10h CPU_AH: 0x%x CPU_AL: 0x%x\r\n", CPU_AH, CPU_AL); switch (CPU_AH) { + + case 0x0f: + if (videomode < 8) break; + CPU_AL = videomode; + CPU_AH = 80; + CPU_BH = 0; + return; case 0x00: videomode = CPU_AL & 0x7F; if (videomode == 4) { @@ -1328,6 +1335,7 @@ void intcall86(uint8_t intnum) { else { port3D9 = 0; } + //if (videomode >= 8) CPU_AL = 4; // FIXME!! RAM[0x449] = videomode; @@ -1341,7 +1349,9 @@ void intcall86(uint8_t intnum) { #endif // http://www.techhelpmanual.com/114-video_modes.html // http://www.techhelpmanual.com/89-video_memory_layouts.html - // printf("VBIOS: Mode 0x%x (0x%x)\r\n", CPU_AX, videomode); + char tmp[40]; + sprintf(tmp, "VBIOS: Mode 0x%x (0x%x)\r\n", CPU_AX, videomode); + logMsg(tmp); #if PICO_ON_DEVICE switch (videomode) { case 0: @@ -1515,7 +1525,7 @@ void intcall86(uint8_t intnum) { case 0x19: #if PICO_ON_DEVICE insertdisk(0, fdd0_sz(), fdd0_rom(), "\\XT\\fdd0.img"); - insertdisk(1, fdd1_sz(), fdd1_rom(), "\\XT\\fdd1.img"); + //insertdisk(1, fdd1_sz(), fdd1_rom(), "\\XT\\fdd1.img"); insertdisk(128, 0, NULL, "\\XT\\hdd.img"); keyboard_send(0xFF); #else @@ -1523,7 +1533,9 @@ void intcall86(uint8_t intnum) { if (1 == insertdisk(0, 0, NULL, "fdd0.img") ) { insertdisk(0, sizeof FDD0, FDD0, NULL); } - insertdisk(1, sizeof FDD1, FDD1, NULL); +#if FDD1 + insertdisk(1, sizeof FDD1, FDD1, NULL); +#endif insertdisk(128, 0, NULL, "hdd.img"); #endif break; diff --git a/src/emm.h b/src/emm.h index dbc8aca..1bffc90 100644 --- a/src/emm.h +++ b/src/emm.h @@ -56,7 +56,7 @@ */ #pragma once #include - +#include "emulator.h" #define ON_BOARD_RAM_KB (8ul << 10) #define BASE_X86_KB 1024ul #define TOTAL_XMM_KB (ON_BOARD_RAM_KB - BASE_X86_KB) diff --git a/src/emulator.h b/src/emulator.h index 4b354ca..f00f012 100644 --- a/src/emulator.h +++ b/src/emulator.h @@ -15,7 +15,9 @@ #include "ram_page.h" #include "../assets/rom.h" #include "../assets/startup_disk.h" +#if FDD1 #include "../assets/fdd.h" +#endif //#define CPU_8086 #if PICO_ON_DEVICE #include diff --git a/src/main.cpp b/src/main.cpp index f489117..a526b1b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -177,7 +177,7 @@ int main() { #if PSRAM // TODO: сделать нормально - psram_spi = psram_spi_init_clkdiv(pio0, -1, 1.6, true); + psram_spi = psram_spi_init_clkdiv(pio0, -1, 1.8, true); psram_write32(&psram_spi, 0x313373, 0xDEADBEEF); PSRAM_AVAILABLE = 0xDEADBEEF == psram_read32(&psram_spi, 0x313373); @@ -335,9 +335,9 @@ int main() { uint32_t vidptr = ( (y / 2) &3) * 8192 + (y / 8 ) *160 + (x / 4); uint32_t color; if ( ( (x>>1) &1) ==0) - color = cga_palette[VRAM[vidptr] >> 4]; + color = tandy_palette[VRAM[vidptr] >> 4]; else - color = cga_palette[VRAM[vidptr] & 15]; + color = tandy_palette[VRAM[vidptr] & 15]; //prestretch[y][x] = color; *pix++ = color; } diff --git a/src/ports.c b/src/ports.c index 4850b9b..582a359 100644 --- a/src/ports.c +++ b/src/ports.c @@ -89,6 +89,7 @@ void portout(uint16_t portnum, uint16_t value) { //printf("port3D8 0x%x\r\n", value); // third cga palette (black/red/cyan/white) if (videomode == 5 && (port3D8 >> 2) & 1) { + logMsg("cga hacked palette\n"); #if PICO_ON_DEVICE graphics_set_palette(0, cga_palette[0]); graphics_set_palette(1, cga_palette[4]); @@ -126,11 +127,13 @@ void portout(uint16_t portnum, uint16_t value) { cga_colorset = value >> 5 & 1; cga_intensity = value >> 4 & 1; #if PICO_ON_DEVICE - if ((videomode == 6 && (port3D8 & 0x0f) == 0b1010) || videomode == 8) { + if ((videomode == 6 && (port3D8 & 0x0f) == 0b1010) || videomode >= 8) { break; } - printf("colorset %i, int %i\r\n", cga_colorset, cga_intensity); + char tmp[80]; + sprintf(tmp,"colorset %i, int %i\r\n", cga_colorset, cga_intensity); + logMsg(tmp); for (int i = 0; i < 4; i++) { graphics_set_palette(i, cga_palette[cga_gfxpal[cga_intensity][cga_colorset][i]]); }