Skip to content

Commit

Permalink
win32 fix
Browse files Browse the repository at this point in the history
  • Loading branch information
xrip committed Nov 26, 2023
1 parent e7b5d9c commit ea7d9ff
Show file tree
Hide file tree
Showing 10 changed files with 53 additions and 16 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
15 changes: 14 additions & 1 deletion drivers/usb/msc_disk.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,29 +28,37 @@
#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;
#else
return NULL;
#endif
}
#endif

size_t fdd0_sz() {
return sizeof FDD0;
}
#if FDD1
size_t fdd1_sz() {
#if ROM_DRIVE_B
return sizeof FDD1;
#else
return 0;
#endif
}
#endif

#if CFG_TUD_MSC

Expand All @@ -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));
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down
8 changes: 6 additions & 2 deletions drivers/usb/usb.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
4 changes: 3 additions & 1 deletion drivers/usb/usb.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
1 change: 1 addition & 0 deletions src/a20.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include <stdbool.h>
#include <inttypes.h>
#include "emulator.h"


uint8_t set_a20(uint8_t cond);
Expand Down
22 changes: 17 additions & 5 deletions src/cpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
Expand Down Expand Up @@ -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) {
Expand All @@ -1328,6 +1335,7 @@ void intcall86(uint8_t intnum) {
else {
port3D9 = 0;
}
//if (videomode >= 8) CPU_AL = 4;

// FIXME!!
RAM[0x449] = videomode;
Expand All @@ -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:
Expand Down Expand Up @@ -1515,15 +1525,17 @@ 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
//insertdisk(0, sizeof FDD0, FDD0, NULL);
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;
Expand Down
2 changes: 1 addition & 1 deletion src/emm.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
*/
#pragma once
#include <inttypes.h>

#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)
Expand Down
2 changes: 2 additions & 0 deletions src/emulator.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <hardware/pwm.h>
Expand Down
6 changes: 3 additions & 3 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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;
}
Expand Down
7 changes: 5 additions & 2 deletions src/ports.c
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down Expand Up @@ -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]]);
}
Expand Down

0 comments on commit ea7d9ff

Please sign in to comment.