void windows_init() { __dpmi_regs r; r.x.ax = 0x1600; __dpmi_int(0x2F, &r); if ((r.h.al == 0) || (r.h.al == 1) || (r.h.al == 0x80) || (r.h.al == 0xFF)) { windows_version = 0; clipboard_version = 0; return; } windows_version = ((int)r.h.al << 8) | (int)r.h.ah; r.x.ax = 0x168E; r.x.dx = 2; r.x.cx = sizeof(orig_title)-1; r.x.es = RM_SEGMENT(__tb); r.x.di = RM_OFFSET(__tb); __dpmi_int(0x2F, &r); dosmemget(MASK_LINEAR(__tb), sizeof(orig_title), orig_title); r.x.ax = 0x1700; __dpmi_int(0x2F, &r); if (r.x.ax == 0x1700) clipboard_version = 0; else clipboard_version = r.x.ax; }
DMP_INLINE(void) EP0_OutHandler(USB_Device *usb) { int i; WORD size; static int j = 0; if (usb->setup_out_handled == false) return; #ifdef DMP_86DUINO_MODE RX_LED_ON(); #endif size = (WORD)(io_inpdw(usb->EP[0].OutDLR) & 0x00001FFFFL); if (j < usb->OutDataSize) { #if defined DMP_DOS_DJGPP dosmemget(usb->EP[0].OutPhysical, EP0_MAX_PACKET_SIZE, usb->EP[0].OutBuf); #endif for (i = 0; i < size && j < usb->OutDataSize; i++, j++) { *usb->OutDataPtr++ = usb->EP[0].OutBuf[i]; } } if (j < usb->OutDataSize) { SetEPnDLR(usb, EP0, OUT, ENABLE | EP0_MAX_PACKET_SIZE); } else { j = 0; usb->OutDataSize = 0; usb->setup_out_handled = false; SetEPnDLR(usb, EP0, IN, ENABLE | STSACK); } }
// cd_getdriveletters: fills in the buffer with the number of each CD-ROM // drive (0=A, 1=B, etc). BUFF must be 26 bytes (in case all drives are // CD-ROMs!). Returns number of drives. int cd_getdriveletters(char *buff) { rrr.x.ax = 0x150D; SET_TB_ESBX __dpmi_int(0x2f, &rrr); dosmemget(__tb, 26, buff); return _cd_numdrives; }
DMP_INLINE(void) EP0_SetupHandler(USB_Device *usb) { #if defined DMP_DOS_DJGPP dosmemget(usb->EP[0].SetupPhysical, EP0_MAX_PACKET_SIZE, usb->EP[0].SetupBuf); #endif usb->Setup.bmRequestType = usb->EP[0].SetupBuf[0]; usb->Setup.bRequest = usb->EP[0].SetupBuf[1]; usb->Setup.wValue.Value = ((WORD)usb->EP[0].SetupBuf[3] << 8) + (WORD)usb->EP[0].SetupBuf[2]; usb->Setup.wIndex.Value = ((WORD)usb->EP[0].SetupBuf[5] << 8) + (WORD)usb->EP[0].SetupBuf[4]; usb->Setup.wLength = ((WORD)usb->EP[0].SetupBuf[7] << 8) + (WORD)usb->EP[0].SetupBuf[6]; if (usb->stall == true) { io_outpdw(usb->EP[0].CtrlTR, io_inpdw(usb->EP[0].CtrlTR) & 0xDFFF); io_outpdw(usb->EP[0].CtrlTR, io_inpdw(usb->EP[0].CtrlTR) | 0x2000); usb->stall = false; } switch (usb->Setup.bmRequestType) { case 0x00: case 0x01: case 0x02: case 0x80: case 0x81: case 0x82: USB_Standard_Request(usb); break; case 0x21: case 0xA1: USB_CDC_Request(usb); break; default: break; }; SetEPnDLR(usb, EP0, SETUP, ENABLE); }
// cd_sendrequest: Sends an IOCTL request to the driver. // Pass the drive number void cd_sendrequest(int drivlab, CD_DEVINFO * reqbuf) { rrr.x.ax = 0x1510; rrr.x.cx = drivlab; SET_TB_ESBX dosmemput(reqbuf, reqbuf->size, __tb); __dpmi_int(0x2f, &rrr); dosmemget(__tb, reqbuf->size, reqbuf); cd_lasterror = reqbuf->status; }
int gettext(int c, int r, int c2, int r2, void *buf) { short *cbuf = (short *)buf; /* we should check for valid parameters, and maybe return 0 */ r--, r2--, c--, c2--; for (; r <= r2; r++) { dosmemget(VIDADDR(r, c), (c2-c+1)*2, cbuf); cbuf += c2-c+1; } return 1; }
/** * Initializes registers. Provided by VBETEST.C. **/ ModeInfoBlock *get_mode_info(int mode) { static ModeInfoBlock info; __dpmi_regs r; /* Use the transfer buffer to store the results of VBE call */ r.x.ax = 0x4F01; r.x.cx = mode; r.x.es = __tb / 16; r.x.di = 0; __dpmi_int(0x10, &r); if(r.h.ah) return 0; dosmemget(__tb, sizeof(ModeInfoBlock), &info); return &info; }
DMP_INLINE(void) EP2_OutHandler(USB_Device *usb) { int i; WORD size; #ifdef DMP_86DUINO_MODE RX_LED_ON(); #endif size = (WORD)(io_inpdw(usb->EP[2].OutDLR) & 0x00001FFFFL); #if defined DMP_DOS_DJGPP dosmemget(usb->EP[2].OutPhysical, EP2_MAX_PACKET_SIZE_OUT, usb->EP[2].OutBuf); #endif for (i = 0; i < size; i++) PushQueue(usb->rcvd, usb->EP[2].OutBuf[i]); if (usb->rcvd->count < (usb->rcvd->size - NEAR_FULL_SIZE)) SetEPnDLR(usb, EP2, OUT, ENABLE | EP2_MAX_PACKET_SIZE_OUT); }
/* test_hard_err - test whether a critical error has occurred and return error code (0 if none or handler never installed). */ int did_hard_error_occur(void) { short error_code; if (handler_installed) { dosmemget(new_handler_info.rm_segment * 16 + 14, 2, &error_code); #ifdef XDEBUG if (error_code) { sprintf(Tempbuf, "Critical error code is %d", error_code); error_msg(Tempbuf, 0); } #endif return (error_code); } return (0); }
void cd_ioctl(int drivlab, int funccode, char *addinfo) { cdio.size = sizeof(cdio); //0x10; cdio.subunit = 0; cdio.function = funccode; // use a 50-byte offset into transfer buffer, because sendrequest uses // the start of the tb cdio.adata = ((_use_tb / 16) << 16) & 0xffff0000; cdio.adata |= (_use_tb % 16); // printf("adata: %08X tb: %08X\n",cdio.adata,_use_tb); cdio.adatasize = 20; dosmemput(addinfo, 20, _use_tb); // printf("at tb: %X %X\n",_farpeekb(_dos_ds,_use_tb),_farpeekb(_dos_ds,_use_tb+1)); cd_sendrequest(drivlab, (CD_DEVINFO *) & cdio); // printf("afterat tb: %X %X\n",_farpeekb(_dos_ds,_use_tb),_farpeekb(_dos_ds,_use_tb+1)); dosmemget(_use_tb, 20, addinfo); // printf("after in addinfo: %X %X\n",addinfo[0],addinfo[1]); }
char *get_clipboard_data(int *size) { __dpmi_regs r; int seg, sel; void *ret = NULL; if (!clipboard_version) return FALSE; r.x.ax = 0x1701; __dpmi_int(0x2F, &r); if (!r.x.ax) return NULL; r.x.ax = 0x1704; r.x.dx = 1; __dpmi_int(0x2F, &r); *size = (r.x.dx<<16) | r.x.ax; if (*size > 0) { seg = __dpmi_allocate_dos_memory((*size+15)>>4, &sel); if (seg > 0) { r.x.ax = 0x1705; r.x.dx = 1; r.x.es = seg; r.x.bx = 0; __dpmi_int(0x2F, &r); if (r.x.ax) { ret = malloc(*size); if (ret) dosmemget(seg*16, *size, ret); } __dpmi_free_dos_memory(sel); } }
struct port *__libnet_internal__serial_open(int portnum) { struct port *p; int uart, baudrate, cfg; if ((portnum < 0) || (portnum >= MAX_PORT)) return NULL; p = port_table[portnum]; memset(p, 0, sizeof *p); if (config[portnum].baseaddr == -1) { dosmemget(0x400 + portnum * 2, 2, &p->baseaddr); if (p->baseaddr == 0) p->baseaddr = fallback_baseaddr[portnum]; } else { p->baseaddr = config[portnum].baseaddr; } uart = detect_uart(p->baseaddr); if (!uart) return NULL; if (uart == UART_16550A) enable_fifo(p); else disable_fifo(p); install_isr(portnum, p, config[portnum].irq); set_config(p->baseaddr, config[portnum].baudrate, (config[portnum].bits | config[portnum].parity | config[portnum].stopbits)); return p; }
int file_get_lfn( const char *in, char *out ) { char src[MAX_PATH+32]; // jtbs char dst[MAX_PATH+32]; // jtbs strcpy( src, in ); __dpmi_regs r; dosmemput(src, strlen (src)+1, __tb); r.x.ax = 0x7160; /* Truename */ r.x.cx = 2; /* Get long name */ r.x.ds = r.x.es = __tb / 16; r.x.si = r.x.di = __tb & 15; __dpmi_int(0x21, &r); if (r.x.flags & 1 || r.x.ax == 0x7100) { strcpy( out, in ); return -1; } dosmemget (__tb, MAX_PATH, dst); strcpy( out, dst ); return 0; }
/* ///////////////////////////////////////////////////////////////////////////// // MAIN ROUTINE ///////////////////////////////////////////////////////////////////////////// */ int main(int argc, char *argv[]) { int ch; int index; int n; int found_format_sectors_per_track = 0; int found_format_heads = 0; #define MIRROR 1 #define UNFORMAT 2 #define WHAT_FORMAT 1 /* new 0.91p, for custom "... completed" messages */ #define WHAT_QUICK 2 #define WHAT_SAFE 3 #define WHAT_UN 4 #define WHAT_MIRROR 5 int what_completed = 0; /* new 0.91p */ int special = 0; /* mirror / unformat mode indicator */ int align = 1; /* new 0.91m */ int drive_letter_found = FALSE; Initialization(); param.n = FALSE; param.t = FALSE; param.v = FALSE; param.q = FALSE; param.u = FALSE; param.b = FALSE; param.s = FALSE; param.f = FALSE; param.one = FALSE; param.four = FALSE; param.eight = FALSE; /* if FORMAT is typed without any options */ if (argc == 1) { Display_Help_Screen(0); /* SHORT version */ return 0; } /* (jh) check command line */ while ( (index = getopt (argc, argv, "V:v:Z:z:QqUuBbSsYyAa148F:f:T:t:N:n")) != EOF) { switch(index) { case 'V': case 'v': param.v = TRUE; /* avoid overflow of param.volume_label (12 chars) */ /* need to skip over first character (':') */ strncpy (param.volume_label, optarg+1, 11); param.volume_label[11] = '\0'; for (n = 0; param.volume_label[n] != '\0'; n++) { ch = param.volume_label[n]; param.volume_label[n] = toupper (ch); } break; case 'Z': /* our getopt has no "long" support, so we use -Z:keyword */ case 'z': /* 0.91l - extra (long) options */ if (!stricmp(optarg+1,"mirror")) /* +1 to skip initial ":" */ { special = MIRROR; /* take a new mirror data snapshot */ break; } if (!stricmp(optarg+1,"unformat")) { special = UNFORMAT; /* revert to mirrored state, dangerous! */ break; } if (!stricmp(optarg+1,"seriously")) { param.force_yes = TRUE + TRUE; /* User MEANS to format harddisk */ break; } if (!stricmp(optarg+1,"longhelp")) { Display_Help_Screen(1); /* LONG version */ Exit(0,1); } printf("Invalid -Z:mode - valid: MIRROR, UNFORMAT, SERIOUSLY\n"); Exit(0,2); break; case 'Q': /* quick - flush metadata only */ case 'q': param.q = TRUE; break; case 'U': /* unconditional - full format */ case 'u': param.u = TRUE; break; case 'B': /* reserve space for system, deprecated */ case 'b': param.b = TRUE; break; case 'S': /* run SYS command */ case 's': param.s = TRUE; break; case 'Y': /* assume yes for confirmations - "undocumented" */ case 'y': if (param.force_yes == FALSE) param.force_yes = TRUE; break; case 'A': /* 0.91m - align mode, force FAT size to 2k*n and */ case 'a': /* so on to force data clusters to start at 4k*n */ align = 8; break; case '1': /* one side only */ param.one = TRUE; break; case '4': /* 360k disk in 1.2M drive */ param.four = TRUE; break; case '8': /* 8 sectors per track */ param.eight = TRUE; break; case 'F': /* -F:size */ case 'f': /* -F:size */ param.f = TRUE; n = atoi (optarg + 1); if ((n == 160) || (n == 180) || (n == 320) || (n == 360) || (n == 720) || (n == 1200) || (n == 1440) || (n == 2880) || (n == 400) || (n == 800) || (n == 1680) || (n == 3360) || (n == 1494) || (n == 1743) || (n == 3486)) { param.size = n; } else { printf("Ok: 160, 180, 320, 360, 720, 1200, 1440, 2880.\n"); printf("???: 400, 800, 1680, 3360, 1494, 1743, 3486.\n"); IllegalArg("-F",optarg); } break; case 'T': /* tracks (cylinders) */ case 't': /* tracks (cylinders) */ param.t = TRUE; n = atoi (optarg + 1); if ((n == 40) || (n == 80) || (n == 83)) { param.cylinders = n; } else { printf("Ok: 40, 80. ???: 83.\n"); IllegalArg("-T",optarg); } break; case 'N': /* sectors per track */ case 'n': /* sectors per track */ param.n = TRUE; n = atoi (optarg + 1); if ((n == 8) || (n == 9) || (n == 15) || (n == 18) || (n == 36) || (n == 10) || (n == 21) || (n == 42)) { param.sectors = n; } else { printf("Ok: 8, 9, 15, 18, 36. ???: 10, 21, 42.\n"); IllegalArg("-N",optarg); } break; case '~': param.drive_letter[0] = toupper (optarg[0]); param.drive_number = param.drive_letter[0] - 'A'; param.drive_letter[1] = ':'; drive_letter_found = TRUE; break; case '?': Display_Help_Screen(0); /* SHORT version */ Exit(0,1); default: printf("Unrecognized option: -%c\n", index); Display_Help_Screen(0); /* SHORT version */ Exit(4,2); } /* switch (index) */ } /* for all args (getopt) */ if ( (argc > optind) && (isalpha (argv[optind][0])) && (argv[optind][1] == ':') && (argv[optind][2] == '\0') && (drive_letter_found == FALSE) ) { param.drive_letter[0] = toupper (argv[optind][0]); param.drive_number = param.drive_letter[0] - 'A'; param.drive_letter[1] = ':'; } else if (drive_letter_found == FALSE) { printf("Required parameter missing - Drive Letter\n"); Exit(0,2); } /* (jh) done with parsing command line */ /* if FORMAT is typed with a drive letter */ #ifdef __FORMAT_DEBUG__ printf("\n[DEBUG] This is FORMAT " VERSION ", selected drive -> %c:\n", param.drive_letter[0]); printf("[DEBUG] Using 1 sector buffer at %4.4x:%4.4x and 1 track buffer at %4.4x:%4.4x\n", FP_SEG(sector_buffer), FP_OFF(sector_buffer), FP_SEG(huge_sector_buffer), FP_OFF(huge_sector_buffer) ); /* moved this message to this place in 0.91s */ #endif /* Set the type of disk */ if (param.drive_number>1) param.drive_type=HARD; else param.drive_type=FLOPPY; /* *** TODO: complain about ANY size determination if type HARD *** */ /* Ensure that valid switch combinations were entered */ if ( (param.b==TRUE) && (param.s==TRUE) ) Display_Invalid_Combination(); /* cannot reserve space for SYS and actually SYS at the same time */ if ( (param.v==TRUE) && (param.eight==TRUE) ) Display_Invalid_Combination(); /* no label allowed if 160k / 320k */ if ( ( (param.one==TRUE) || (param.four==TRUE) /* 360k in 1.2M drive */ ) && ( (param.f==TRUE) || (param.t==TRUE) || (param.n==TRUE) ) ) Display_Invalid_Combination(); /* cannot combine size/track/sector override with 1-sided / 360k */ if ( ( (param.t==TRUE) && (param.n!=TRUE) ) || ( (param.n==TRUE) && (param.t!=TRUE) ) ) { puts("You can only give -T _and_ -N or _neither_ of them."); Display_Invalid_Combination(); /* you must give BOTH track and sector arguments if giving either */ } if ( (param.f==TRUE) && ( (param.t==TRUE) || (param.n==TRUE) ) ) Display_Invalid_Combination(); /* you can only give EITHER size OR track/sector arguments */ /* we do allow /8 to reach 160k (with /1) and 320k (with /4) */ /* it is more the other way round: we do not want 8 sector/track > 320k! */ /* ... */ if (param.one==TRUE) /* one-sided: 160k and 180k only */ { param.sides = 1; param.cylinders = 40; /* *** this is actually handled in Set_Floppy_Media_Type mostly *** */ } if (param.four==TRUE) /* 360k in 1200k drive */ { param.cylinders = 40; param.sectors = 9; } if (param.eight==TRUE) /* DOS 1.0 formats: 160k and 320k only */ { param.sectors = 8; } Lock_Unlock_Drive(1); /* lock drive (needed in Win9x / DOS 7.x) */ /* FIRST lock, file system still enabled. */ next_disk: /* User interaction. */ if (param.drive_type==FLOPPY && param.force_yes==FALSE) Ask_User_To_Insert_Disk(); if (!special) { if (param.drive_type==HARD && (param.force_yes!=(TRUE+TRUE)) ) Confirm_Hard_Drive_Formatting(1); /* 1 means "format" */ /* disabled harddisk "/Y" forced confirmation in 0.91b unless ZAPME -ea */ /* replaced by "/Z:seriously" in 0.91l -ea */ } else { if ((param.force_yes == FALSE) && (special == UNFORMAT)) Confirm_Hard_Drive_Formatting(0); /* 0 means "unformat" - 0.91l */ /* no confirmation requested for MIRROR ! */ } /* "optimized" a lot in 0.91h, hopefully not too much... -ea */ if ((!special) && (param.u==TRUE) && (param.q==FALSE)) /* full format / wipe? */ { param.existing_format = FALSE; /* do not even check if /U non-/Q mode */ } else { /* /Q /U clears metadata but does no format / wipe */ /* /Q -- clears metadata after backing it up */ /* -- -- works like /Q */ /* CONCLUSION: We do not really have to worry about current */ /* for harddisks in /Q /U mode (uses DOS kernel default BPB) */ if ( (param.drive_type!=FLOPPY) && (param.u==TRUE) ) { /* no check for harddisk /U mode nor for /U /Q mode there. */ param.existing_format = FALSE; } else { /* it is a floppy --- or no /U flag given */ #ifdef __FORMAT_DEBUG__ if (special) { puts("[DEBUG] Checking for existing format"); } else { if (param.drive_type==FLOPPY) puts("[DEBUG] Checking whether we need low-level floppy format."); else puts("[DEBUG] Checking whether UNFORMAT data can be saved."); } #endif /* Check to see if the media is currently formatted. */ /* Needed for non-/U modes and for floppy disks, but in */ /* /U non-/Q mode we already assume "not formatted" anyway. */ param.existing_format = Check_For_Format(); /* trashes fat_type value! */ /* no problem, done before media type / harddisk parameter setup */ } /* check for existing format */ } /* not FORMAT /U mode */ Lock_Unlock_Drive(2); /* lock drive (needed in Win9x / DOS 7.x) */ /* SECOND lock, going lowlevel... - 0.91q */ /* Determine and set media parameters */ if (param.drive_type==FLOPPY) { /* <FLOPPY> */ if (param.existing_format==TRUE) { dosmemget(sector_buffer+0x18, 1, &found_format_sectors_per_track); dosmemget(sector_buffer+0x1a, 1, &found_format_heads); } Set_Floppy_Media_Type(); /* configure hardware, set up BPB, fat_type FAT12 */ #if DETECT_FLOPPY_TWICE if ((param.existing_format == FALSE) && (param.u==FALSE)) { /* try finding existing format again - after setting media type */ #ifdef __FORMAT_DEBUG__ puts("[DEBUG] Searching for existing format again..."); #endif Lock_Unlock_Drive(0); /* re-enable filesystem access - 0.91q */ param.existing_format = Check_For_Format(); /* trashes fat_type! No prob. */ /* ... because it is done just before Set_Floppy_Media_Type */ Lock_Unlock_Drive(2); /* re-disable filesystem access - 0.91q */ Set_Floppy_Media_Type(); /* configure hardware AGAIN, set up BPB, fat_type FAT12 */ /* set media type again! - 0.91i */ if (param.existing_format==TRUE) { /* depends on Check_For_Format to fill sector_buffer... */ dosmemget(sector_buffer+0x18, 1, &found_format_sectors_per_track); dosmemget(sector_buffer+0x1a, 1, &found_format_heads); } } /* not /U and no existing format found */ #endif /* DETECT_FLOPPY_TWICE */ /* if already formatted floppy, check whether geometry will change */ if (param.existing_format == TRUE) { if ( ( parameter_block.bpb.sectors_per_cylinder != found_format_sectors_per_track ) || ( found_format_heads != parameter_block.bpb.number_of_heads ) ) { puts("Will change size by formatting - forcing full format"); printf("Old: %d sectors per track, %d heads. New: %d sect. %d heads\n", found_format_sectors_per_track, found_format_heads, parameter_block.bpb.sectors_per_cylinder, parameter_block.bpb.number_of_heads); param.existing_format = FALSE; } } /* existing format */ /* if no existing format, we force full format anyway */ /* </FLOPPY> */ } else { /* if harddisk: */ /* <HARDDISK> */ /* 0.91m: the only place where "align" is used is here, in BPB setup!!! */ Set_Hard_Drive_Media_Parameters(align); /* get default BPB etc., find FATxx fat_type */ Enable_Disk_Access(); /* </HARDDISK> */ } /* *** Maybe we should have done drive setup earlier, for Check_...? *** */ if (param.existing_format == FALSE) /* details changed in 0.91h */ { if ( (param.drive_type==FLOPPY) && ( (param.u!=TRUE) || (param.q!=FALSE) ) ) puts("Cannot find existing format - forcing full format."); if ( (param.drive_type!=FLOPPY) && (param.u==FALSE) ) puts("Cannot find existing format - not saving UNFORMAT data."); } switch (special) /* 0.91l - special modes MIRROR and UNFORMAT */ { case 0: /* do nothing special */ break; case MIRROR: /* only update mirror data */ puts("Writing a copy of the system sectors to the end of the drive:"); puts("Boot sector, one FAT, root directory. Useful for UNFORMAT."); Save_File_System(0); /* includes filesystem usage stats display */ /* 0.91r: 0 is "abort if we would damage data" -ea */ what_completed = WHAT_MIRROR; /* new 0.91p */ goto format_complete; /* break; */ case UNFORMAT: /* only write back FAT/root/boot from mirror */ puts("Overwriting boot sector, FATs and root directory with"); puts("MIRROR/UNFORMAT data which you have saved earlier."); Restore_File_System(); /* restore is an euphemism for what it does! */ what_completed = WHAT_UN; /* new 0.91p */ goto format_complete; /* break; */ default: puts("/Z:what???"); /* should never be reached */ } /* switch special */ /* ask for label if none given yet - 0.91r */ if ((!param.v) && (!param.force_yes)) { param.v = (Ask_Label(param.volume_label) != 0); /* printf("\n[%s]%s\n", param.volume_label, (param.v) ? "" : " (none)"); */ } /* ask for label */ /* Format Drive */ if ( ( (param.existing_format==FALSE) && (param.drive_type==FLOPPY) ) || ( (param.u==TRUE) && (param.q==FALSE) ) ) { /* /U is Unconditional Format. */ /* If floppy is unformatted or geometry changes, we must use this. */ puts(" Full Formatting (wiping all data)"); Unconditional_Format(); Create_File_System(); what_completed = WHAT_FORMAT; /* new 0.91p */ goto format_complete; } if ( ( (param.existing_format==FALSE) && (param.drive_type!=FLOPPY) ) || ( (param.u==TRUE) && (param.q==TRUE) ) ) /* changed in 0.91h */ { /* /Q /U is Quick Unconditional format */ /* Even unformatted harddisks do not need full "/U" format */ /* (harddisk /U format means "wipe all data, do surface scan) */ /* (harddisk LOWLEVEL format is never done by this program!) */ puts(" QuickFormatting (only flushing metadata)"); puts(" Warning: Resets bad cluster marks if any."); Create_File_System(); what_completed = WHAT_QUICK; /* new 0.91p */ goto format_complete; } if ( (param.u==FALSE) /* && (param.q==TRUE) */ ) { /* this is the default, so if no /U given, it is irrelevant */ /* whether /Q is given or not... Should trigger FULL format */ /* if existing filesystem has other size or disk needs format */ /* /Q is Safe Quick Format (checking for existing bad cluster list) */ /* -- is Safe Quick Format (the same :-)) */ puts(" Safe QuickFormatting (trying to save UnFormat data)"); Save_File_System(1); /* side effect: checks for existing bad clust list */ /* 0.91r: 1 is "allow trashing of data clusters" -ea */ /* (unformat data is allowed to overwrite files) */ Create_File_System(); what_completed = WHAT_SAFE; /* new 0.91p */ goto format_complete; } format_complete: if ((bad_sector_map[0]>0) && (!special)) Record_Bad_Clusters(); /* write list of bad clusters */ /* may include copied list from previous filesystem - not in special modes! */ switch (what_completed) /* new 0.91p - custom message */ { case WHAT_FORMAT: printf("\nFormat"); break; case WHAT_QUICK: printf("\nQuickFormat"); break; case WHAT_SAFE: printf("\nSafe QuickFormat"); break; case WHAT_MIRROR: printf("\nMirror"); break; case WHAT_UN: printf("\nUnFormat"); break; } /* switch */ puts(" complete."); Lock_Unlock_Drive(0); /* unlock drive again (in Win9x / DOS 7.x) */ /* release SECOND lock: enable filesystem */ Force_Drive_Recheck(); /* just in case... - 0.91q */ Lock_Unlock_Drive(0); /* unlock drive again (in Win9x / DOS 7.x) */ /* release FIRST lock: allow full access! */ if ((param.s==TRUE) && (!special)) { Write_System_Files(); /* call SYS */ Force_Drive_Recheck(); /* just in case... - 0.91q */ } if (!special) Display_Drive_Statistics(); if ((param.drive_type==FLOPPY) && (param.force_yes==FALSE)) { /* printf("\nFormat another floppy (y/n)?\n"); */ if (!special) /* or use what_completed switch / case with WHAT_...? */ write(isatty(1) ? 1 : 2, "\nFormat", 7); else write(isatty(1) ? 1 : 2, "\nProcess", 8); write(isatty(1) ? 1 : 2, " another floppy (y/n)?\n", 23); /* write to STDERR to keep message visible even if STDOUT redirected */ /* Get keypress */ regs.h.al = toupper(getch()); if (regs.h.al == 'Y') { int bads; printf("\n%s next floppy...\n", special ? "Processing" : "Formatting"); drive_statistics.bad_sectors = 0; bad_sector_map_pointer = 0; for (bads=0; bads < MAX_BAD_SECTORS; bads++) { bad_sector_map[bads] = 0; } Lock_Unlock_Drive(1); /* lock drive (needed in Win9x / DOS 7.x) */ /* FIRST lock, file system still enabled. */ /* (second level will be entered again when we really need it...) */ param.v = FALSE; /* force asking for new label for next disk */ goto next_disk; /* *** LOOP AROUND FOR MULTIPLE FLOPPY DISKS *** */ } } /* another floppy question, possibly jumping back */ return 0; /* not using Exit() here: no dual errorlevel, no unlock */ }
/* Copy data into the clipboard, return zero if successful. */ unsigned set_clipboard_data (unsigned Format, void *Data, unsigned Size, int Raw) { __dpmi_regs regs; unsigned truelen; unsigned long xbuf_addr, buf_offset; unsigned char *dp = Data, *dstart = dp; if (Format != CF_OEMTEXT) return 3; /* need to know final size after '\r' chars are inserted (the standard CF_OEMTEXT clipboard format uses CRLF line endings, while Emacs uses just LF internally). */ truelen = Size + 1; /* +1 for the terminating null */ if (!Raw) { /* avoid using strchr because it recomputes the length everytime */ while ((dp = memchr (dp, '\n', Size - (dp - dstart))) != 0) { truelen++; dp++; } } if (clipboard_compact (truelen) < truelen) return 1; if ((xbuf_addr = alloc_xfer_buf (truelen)) == 0) return 1; /* Move the buffer into the low memory, convert LF into CR-LF if needed. */ if (Raw) { dosmemput (Data, Size, xbuf_addr); /* Terminate with a null, otherwise Windows does strange things when the text size is an integral multiple of 32 bytes. */ _farpokeb (_dos_ds, xbuf_addr + Size, '\0'); } else { dp = Data; buf_offset = xbuf_addr; _farsetsel (_dos_ds); while (Size--) { /* Don't allow them to put binary data into the clipboard, since it will cause yanked data to be truncated at the first null. */ if (*dp == '\0') return 2; if (*dp == '\n') _farnspokeb (buf_offset++, '\r'); _farnspokeb (buf_offset++, *dp++); } /* Terminate with a null, otherwise Windows does strange things when the text size is an integral multiple of 32 bytes. */ _farnspokeb (buf_offset, '\0'); } /* Stash away the data we are about to put into the clipboard, so we could later check inside get_clipboard_data whether the clipboard still holds our data. */ if (clipboard_storage_size < truelen) { clipboard_storage_size = truelen + 100; last_clipboard_text = (char *) xrealloc (last_clipboard_text, clipboard_storage_size); } if (last_clipboard_text) dosmemget (xbuf_addr, truelen, last_clipboard_text); /* Calls Int 2Fh/AX=1703h with: DX = WinOldAp-Supported Clipboard format ES:BX = Pointer to data SI:CX = Size of data in bytes Return Values AX == 0: Error occurred <> 0: OK. Data copied into the Clipboard. */ regs.x.ax = 0x1703; regs.x.dx = Format; regs.x.si = truelen >> 16; regs.x.cx = truelen & 0xffff; regs.x.es = xbuf_addr >> 4; regs.x.bx = xbuf_addr & 15; __dpmi_int (0x2f, ®s); free_xfer_buf (); /* If the above failed, invalidate the local copy of the clipboard. */ if (regs.x.ax == 0) *last_clipboard_text = '\0'; /* Zero means success, otherwise (1, 2, or 3) it's an error. */ return regs.x.ax > 0 ? 0 : 3; }
int GetCountryCode (void) { #if (DOSX & DJGPP) /* _osmajor/_osminor not set in crt0.o */ _get_dos_version (0); #endif if (_osmajor >= 3) { #if (DOSX & DJGPP) __dpmi_regs reg; reg.d.edx = 0; reg.x.ds = __tb / 16; reg.d.eax = 0x3800; __dpmi_int (0x21, ®); if (reg.x.flags & 1) return (0); dosmemget (__tb, sizeof(_country_info), &_country_info); return (reg.x.bx); #elif (DOSX & PHARLAP) SWI_REGS reg; if (_watt_dosTbSize < sizeof(_country_info)) return (0); reg.edx = RP_OFF (_watt_dosTbr); reg.ds = RP_SEG (_watt_dosTbr); reg.eax = 0x3800; _dx_real_int (0x21, ®); if (reg.flags & 1) return (0); ReadRealMem (&_country_info, _watt_dosTbr, sizeof(_country_info)); return (reg.ebx); #elif (DOSX & (DOS4GW|WDOSX)) union REGS reg; struct SREGS sreg; if (_watt_dosTbSize < sizeof(_country_info)) return (0); reg.x.edx = 0; sreg.ds = _watt_dosTbSeg; reg.x.eax = 0x3800; int386x (0x21, ®, ®, &sreg); if (reg.x.cflag) return (0); memcpy (&_country_info, SEG_OFS_TO_LIN(_watt_dosTbSeg,0), sizeof(_country_info)); return (reg.w.bx); #elif (DOSX & POWERPAK) UNFINISED(); #elif (DOSX == 0) /* real-mode */ union REGS reg; struct SREGS sreg; reg.x.dx = FP_OFF (_country_info); sreg.ds = FP_SEG (_country_info); reg.x.ax = 0x3800; int86x (0x21, ®, ®, &sreg); if (reg.x.cflag) return (0); return (reg.x.bx); #else #error Unsupported target #endif } return (0); }
/** * Try asking a LAN extension of DOS for a host-name. */ int _get_machine_name (char *buf, int size) { IREGS reg; char *h; char dosBuf[16]; int len; memset (®, 0, sizeof(reg)); reg.r_ax = 0x5E00; #if (DOSX & DJGPP) if (_go32_info_block.size_of_transfer_buffer < sizeof(dosBuf)) return (-1); reg.r_ds = __tb / 16; reg.r_dx = __tb & 15; #elif (DOSX & (PHARLAP|X32VM|POWERPAK)) if (_watt_dosTbSize < sizeof(dosBuf) || !_watt_dosTbr) return (-1); reg.r_ds = RP_SEG (_watt_dosTbr); reg.r_dx = RP_OFF (_watt_dosTbr); #elif (DOSX & DOS4GW) if (_watt_dosTbSize < sizeof(dosBuf) || !_watt_dosTbSeg) return (-1); reg.r_ds = _watt_dosTbSeg; reg.r_dx = 0; #elif (DOSX == 0) reg.r_ds = FP_SEG (dosBuf); reg.r_dx = FP_OFF (dosBuf); #else #error Help me! #endif GEN_INTERRUPT (0x21, ®); if ((reg.r_flags & CARRY_BIT) || hiBYTE(reg.r_cx) == 0) return (-1); #if (DOSX & DJGPP) dosmemget (__tb, sizeof(dosBuf), dosBuf); #elif (DOSX & (PHARLAP|X32VM|POWERPAK)) ReadRealMem ((void*)&dosBuf, _watt_dosTbr, sizeof(dosBuf)); #elif (DOSX & DOS4GW) memcpy (dosBuf, SEG_OFS_TO_LIN(_watt_dosTbSeg,0), sizeof(dosBuf)); #endif /* Remove right space padding */ h = dosBuf + min (strlen(dosBuf), sizeof(dosBuf)-1); while (h > dosBuf && h[-1] == ' ') h--; *h = '\0'; h = dosBuf; len = strlen (h); if (len + 1 > size) { SOCK_ERRNO (ERANGE); return (-1); } strcpy (buf, h); strlwr (buf); return (0); }
/* Do not confuse this with DOS 7.0+ drive locking */ void Enable_Disk_Access(void) /* DOS 4.0+ drive access flag / locking */ { unsigned char category_code; unsigned long error_code=0; category_code = (param.fat_type == FAT32) ? 0x48 : 0x08; /* Get the device parameters for the logical drive */ regs.h.ah = 0x44; /* IOCTL Block Device Request */ regs.h.al = 0x0d; /* IOCTL */ regs.h.bl = param.drive_number + 1; regs.h.ch = category_code; /* 0x08 if !FAT32, 0x48 if FAT32 */ regs.h.cl = 0x67; /* Get Access Flags */ regs.x.ds = FP_SEG(transfer_buffer); regs.x.dx = FP_OFF(transfer_buffer); /* TODO: Using linear address because the DS's base is 0x0? */ __dpmi_int(0x21, ®s); /* Copy to the access_flags from transfer buffer */ dosmemget(transfer_buffer, sizeof(AF), &access_flags); access_flags.special_function = 0; error_code = regs.h.al; if (regs.x.flags&CARRY_FLAG) { /* BO: if invalid function: try to format anyway maybe access flags do not work this way in this DOS (e.g. DRDOS 7.03) */ if (error_code == 0x1 || error_code == 0x16) { printf("No disk access flags used (IOCTL int 21.440d.x8.67)\n"); return; } /* Add error trapping here */ printf("\nCannot get disk access flags (error %02lx). Giving up.\n", error_code); Exit(4,26); } if (access_flags.disk_access==0) /* access not yet enabled? */ { access_flags.disk_access = 1; dosmemput(&access_flags, sizeof(AF), transfer_buffer); regs.h.ah = 0x44; /* IOCTL Block Device Request */ regs.h.al = 0x0d; /* IOCTL */ regs.h.bl = param.drive_number + 1; regs.h.ch = category_code; /* 0x08 if !FAT32, 0x48 if FAT32 */ regs.h.cl = 0x47; /* Set access flags */ regs.x.es = FP_SEG(transfer_buffer); regs.x.dx = FP_OFF(transfer_buffer); __dpmi_int(0x21, ®s); error_code = regs.h.al; /* Copy to the access_flags from transfer buffer */ dosmemget(transfer_buffer, sizeof(AF), &access_flags); if (regs.x.flags&CARRY_FLAG) { /* Add error trapping here */ printf("\nCannot enable disk access flags (error %02lx). Giving up.\n", error_code); Exit(4,27); } } #ifdef __FORMAT_DEBUG__ printf("[DEBUG] Enabled disk access flags.\n"); #endif }
vga_mode_t * vgahost_compute_vga_mode_list (void) { vesa_info_t vesa_info; static const vga_mode_t standard_vga_modes[NUM_STANDARD_VGA_MODES] = { { 640, 480, 80, 0x12, 2, TRUE, FALSE, FALSE, 0, 0, 65536, 65536, -1 } }; static const vga_mode_t standard_vesa_modes[NUM_VESA_MODES] = { /* Many of these fields are intentionally left blank or have defaults. */ { 640, 400, 0, 0x100, 3, FALSE, FALSE, TRUE, 0, 0, 65536, 65536, -1 }, { 640, 480, 0, 0x101, 3, FALSE, FALSE, TRUE, 0, 0, 65536, 65536, -1 }, { 800, 600, 0, 0x102, 2, TRUE, FALSE, FALSE, 0, 0, 65536, 65536, -1 }, { 800, 600, 0, 0x103, 3, FALSE, FALSE, TRUE, 0, 0, 65536, 65536, -1 }, { 1024, 768, 0, 0x104, 2, TRUE, FALSE, TRUE, 0, 0, 65536, 65536, -1 }, { 1024, 768, 0, 0x105, 3, FALSE, FALSE, TRUE, 0, 0, 65536, 65536, -1 }, { 1280, 1024, 0, 0x106, 2, TRUE, FALSE, TRUE, 0, 0, 65536, 65536, -1 }, { 1280, 1024, 0, 0x107, 3, FALSE, FALSE, TRUE, 0, 0, 65536, 65536, -1 }, }; int num_modes, i; __dpmi_regs regs; /* Default to an empty list. */ mode_list[0].width = 0; /* Add in the normal VGA modes we know about. */ memcpy (mode_list, standard_vga_modes, sizeof standard_vga_modes); num_modes = (sizeof standard_vga_modes) / (sizeof standard_vga_modes[0]); for (i = 0; i < num_modes; i++) mode_list[i].screen_selector = vga_window_selector; if (get_vesa_info_block (&vesa_info)) { unsigned long list, num_mode_numbers, n; unsigned short mode_num, *vesa_mode_numbers; /* Figure out what type of DAC we have. */ switchable_dac_p = (vesa_version >= 0x200 && (vesa_info.capabilities[0] & SWITCHABLE_DAC)); set_palette_during_vbl_mask = ((vesa_info.capabilities[0] & SET_PALETTE_DURING_VBL) ? 0x80 : 0); /* Count the number of modes in their list. */ list = (vesa_info.mode_list_segment * 16 + vesa_info.mode_list_offset); for (num_mode_numbers = 0, mode_num = 0; mode_num != 0xFFFF; num_mode_numbers++) { dosmemget (list + num_mode_numbers * sizeof (short), sizeof mode_num, &mode_num); } num_mode_numbers--; /* Don't count the 0xFFFF */ /* Allocate an array to hold the modes. */ vesa_mode_numbers = ((unsigned short *) alloca (num_mode_numbers * sizeof vesa_mode_numbers[0])); dosmemget (list, num_mode_numbers * sizeof vesa_mode_numbers[0], vesa_mode_numbers); for (n = 0; n < num_mode_numbers && num_modes < MAX_VGA_MODES; n++) { unsigned short mode_num; mode_info_t mode_info; vga_mode_t *m; /* Mask out all but the real mode bits. */ mode_num = vesa_mode_numbers[n] & 0x3FFF; if (!VESA_MODE_P (mode_num)) /* Is this not a VESA mode? */ continue; /* Call BIOS function to get SVGA mode information. */ dpmi_zero_regs (®s); regs.x.cx = mode_num; regs.x.es = dos_buf_segment; regs.x.di = 0; if (!vesa_call (VESA_GET_MODE_INFO, ®s)) continue; /* Pull the new information in from DOS memory. */ movedata (dos_buf_selector, 0, dos_pm_ds, (unsigned) &mode_info, sizeof mode_info); if (!(mode_info.mode_attributes & ATTR_LEGAL_MODE) || !(mode_info.mode_attributes & ATTR_GRAPHICS_MODE)) continue; m = &mode_list[num_modes]; memset (m, 0, sizeof *m); if (mode_info.mode_attributes & ATTR_EXTENDED_INFO) { /* Filter out unacceptable graphics modes. We want either * simple packed screens or 4bpp planar screens only. */ if (mode_info.width < VDRIVER_MIN_SCREEN_WIDTH || mode_info.height < VDRIVER_MIN_SCREEN_HEIGHT) continue; if (mode_info.bits_per_pixel > 8) continue; if (mode_info.memory_model != MEMORY_MODEL_PACKED_PIXELS && (mode_info.bits_per_pixel != 4 || (mode_info.memory_model != MEMORY_MODEL_FOUR_PLANES))) continue; if (mode_info.num_planes != 1 && (mode_info.num_planes != 4 || mode_info.bits_per_pixel != 4)) continue; m->width = mode_info.width; m->height = mode_info.height; m->log2_bpp = ROMlib_log2[mode_info.bits_per_pixel]; m->planar_p = (mode_info.num_planes != 1); } else if (mode_num >= 0x100 && mode_num < 0x108) { /* No explicit information about this mode. VESA spec * says this is legal as long as it is one of the * standard VESA-defined modes, which it is. */ *m = standard_vesa_modes[mode_num - 0x100]; } else continue; /* Strange; no information about this mode! */ m->row_bytes = mode_info.row_bytes; m->win_granularity = mode_info.win_granularity * 1024; m->interlaced_p = FALSE; if ((mode_info.win_a_attributes & 0x3) == 0x3) m->win_read = 0; else if ((mode_info.win_b_attributes & 0x3) == 0x3) m->win_read = 1; else continue; /* No readable window at all! */ if ((mode_info.win_a_attributes & 0x5) == 0x5) m->win_write = 0; else if ((mode_info.win_b_attributes & 0x5) == 0x5) m->win_write = 1; else continue; /* No writeable window at all! */ /* Default to not knowing the physical base address. */ m->phys_base_addr = 0; if (vesa_version >= 0x200 && (mode_info.mode_attributes & ATTR_LINEAR_FBUF) && mode_info.phys_base_addr >= 1024 * 1024) { int sel; m->phys_base_addr = mode_info.phys_base_addr; sel = selector_for_phys_mem (m->phys_base_addr, m->row_bytes * m->height); if (sel != -1) { mode_num |= USE_LINEAR_FBUF; m->multi_window_p = FALSE; m->screen_selector = sel; m->win_size = m->row_bytes * m->height; } } /* If we failed to set to linear mode, do it the * old-fashioned way. */ if (!(mode_num & USE_LINEAR_FBUF)) { m->multi_window_p = (m->row_bytes * m->height > 65536); m->screen_selector = vga_window_selector; m->win_size = mode_info.win_size * 1024; if (m->win_size > 65536) /* So we don't violate selector. */ m->win_size = 65536; } m->mode_number = mode_num; num_modes++; if (m->planar_p && m->row_bytes * m->height > m->win_size) { m->log2_bpp = 0; /* Only allow the 1bpp version. */ } else { /* If we found a 4bpp planar mode, add the corresponding * 1bpp mode we can get by only dealing with one of the * planes. */ if (num_modes < MAX_VGA_MODES && m->planar_p) { mode_list[num_modes] = *m; mode_list[num_modes].log2_bpp = 0; num_modes++; } } } } /* Terminate the mode list. */ mode_list[num_modes].width = 0; return mode_list; }
char peekb(unsigned short seg,unsigned short offs) { char res; dosmemget((seg<<4)+offs,1,&res); return(res); }
short peek(unsigned short seg,unsigned short offs) { short res; dosmemget((seg<<4)+offs,2,&res); return(res); }