#include "tdkpin_command_line.h" /* * 1020:0871 — scan one DOS command-tail token. * Bytes <= space are separators. A zero starting index intentionally wraps to * ffff after the first token and counts until the zero-length terminal scan. */ BorlandCommandToken borland_scan_command_token(uint16_t index) { Win16FarPtr cursor = g_borland_command_line; while (true) { uint8_t value; do { value = win16_read_u8(cursor); cursor = win16_far_add_offset(cursor, 1); } while (value != 0 && value <= 0x20); cursor = win16_far_add_offset(cursor, 0xffff); Win16FarPtr token = cursor; do { value = win16_read_u8(cursor); cursor = win16_far_add_offset(cursor, 1); } while (value > 0x20); cursor = win16_far_add_offset(cursor, 0xffff); uint16_t length = (uint16_t)(win16_far_offset(cursor) - win16_far_offset(token)); if (length == 0) { return (BorlandCommandToken){token, 0, index}; } index--; if (index == 0) { return (BorlandCommandToken){token, length, index}; } } } /* 1020:0866 — CX=0 scan followed by XCHG/NEG returns the token count. */ uint16_t borland_parameter_count(void) { BorlandCommandToken terminal = borland_scan_command_token(0); return (uint16_t)(0 - terminal.remaining_index); } /* * 1020:082e — ParamStr with a hidden far ShortString result. * For command tokens, AL becomes the length byte while REP MOVSB retains the * complete uint16 token length; this deliberately preserves >255 overflow. */ void borland_parameter_string(uint16_t index, Win16FarPtr destination) { if (index == 0) { uint16_t length = GetModuleFileNameFar16( g_win16_instance, win16_far_add_offset(destination, 1), 0xff); win16_write_u8(destination, (uint8_t)length); return; } BorlandCommandToken token = borland_scan_command_token(index); win16_write_u8(destination, (uint8_t)token.length); for (uint16_t offset = 0; offset < token.length; offset++) { win16_write_u8( win16_far_add_offset(destination, (uint16_t)(offset + 1)), win16_read_u8(win16_far_add_offset(token.token, offset))); } }