Keep track of my fixes #20
Replies: 2 comments
(2) Output buffer overflowSympton: It comes to my attention that when the output reaches a certain amount, the output to the console screen will be chopped off. It happens when your program prints out massive output. Use the TYPE command to type out a long program. Use the DIR command to list the files (if you have a lot of file in that disk)... Findings: I found the output buffer is defined in globals.h as a 1024 bytes array. However, there is no logic to handle it's output when output is larger than 1024 bytes. (i.e. input to the buffer stop and wait for the output to screen finish before resuming input to the buffer) globals.h ** Fix 1 — cpu.h:2074-2079 UART_PORT: **Original code: case UART_PORT: //UART Write
txBuf[txInPtr] = v; //Write char to output buffer
txInPtr++;
if (txInPtr == sizeof(txBuf)) txInPtr = 0;
bitWrite(pIn[UART_LSR], 6, 1); //Set bit to indicate sent
break;Fixed code: case UART_PORT: //UART Write // Chip 2026-06-14
{ // UART_PORT: flow-controlled write to TX circular buffer
uint16_t next = txInPtr + 1;
if (next == sizeof(txBuf)) next = 0;
while (next == txOutPtr) vTaskDelay(1); // Buffer full - yield to serial task
txBuf[txInPtr] = v; //Write char to output buffer
txInPtr = next;
bitWrite(pIn[UART_LSR], 6, 1); //Set bit to indicate sent
}
break;** Fix 2 — serial.h:155-163 outString() **Original code: void outString(char buf[]) {
int i = 0;
while (buf[i] > 0) {
txBuf[txInPtr] = buf[i];
txInPtr++;
i++;
if (txInPtr == sizeof(txBuf)) txInPtr = 0;
}
}Fixed code: void outString(char buf[]) {
int i = 0;
while (buf[i] > 0) {
uint16_t next = txInPtr + 1;
if (next == sizeof(txBuf)) next = 0;
while (next == txOutPtr) vTaskDelay(1); // Buffer full - yield to serial task
txBuf[txInPtr] = buf[i];
txInPtr = next;
i++;
}
}Rgds, |
(3) Restore BDOS and/or BIOS memory from disk when transient program overwrite those location in memory.Sympton: DDT.COM does not exit back to CP/M via command G0 nor Ctrl+C I cannot find any logic in the emulator to handle the case when a transient program overwrite the BDOS/BIOS memory location, and upon exiting the program, restore back the BDOS/BIOS to memory. Fix 1: cpu.h line 23 block insert code after Line 45Original code: Modified code: Fix 2: cpu.h line 1491Original code: Modified code: It fixes the DDT.COM exit problem. Using command G0 or Ctrl+C can return to CP/M normally and stay on the current drive. Note 1: It also fixes the issue when exiting from MBASIC using the SYSTEM command. Before the fix, it will perform a COLD BOOT and will return to drive A instead of the current drive. Note 2: the Software Toolworks C80 3.0a starts to work after this fix. I finally have a C compiler to work with. Note 3: Microsoft BASIC Compiler works too One more compiler works... Rgds, |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
*** Warning: I have not done a detail regression testing after my fixes, so it potentially could break some other CP/M functions
*** My test is on a M5Stack Cardputer which has the ESP32-S3FN8 ***
I made some fixes to let the emulator runs better on the Cardputer and would like to use this discussion thread to keep track of my changes.
(1) Accidental mask off the high nibble and missing block {...} structure in the if-construct
Sympton: It all started when I try to find a usable program languages. After failing all the C compilers I can find on the web. I switch to the CP/M comes with ASM.COM. However, I found the output .HEX file produced by ASM.COM is corrupted. I did some investigation on the bad .HEX file against a good .HEX file using the same physical ASM.COM program run on RunCPM emulator, I found all the data portion of the .HEX file is converted to the output character's actual value rather than the ASCII code. (i.e. the correct .HEX file should contain the ASCII value of '0'-'9', 'A'-'F' on the data section.)
Here is the Bad .HEX file content
Here is the good one
Compare the second line
Notice that byte 11H on the bad file is 9, on the good file is 39 (i.e. the ASCII code for 9 is 39)
So I check the cpu.h file to check for mask off the high nibble's code. (i.e. binary AND &0x0f or divided by 16)
Findings:
I am able to find the high nibble masking code. To my surprise, I found some other bugs too. A couple of if constructs missing the begin and end block i.e. {...} and one typo as well.
Here are the codes:
Fix 1: file cpu.h Line 1597-1617 LDIR emulation
Here src and dst are 16 bit integer, the code tries to split a 16 bit integer into two 8 bit integers; but the logic here is for splitting a 8 bit integer into two 4 bit (nibble) integers.
Original code:
Modified code:
Fix 2: file cpu.h Line 1597-1617 CPIR emulation
typo and bug on splitting the 16 bit integer into the higher 8 bit integer
Original code:
Modified code:
Fix 3: cpu.h Line 306-329
Missing begin and end block {...} in the if construct
Original code:
Modified code:
With this fix, I have ASM.COM working correctly now.
Rgds,
Chip Ling
All reactions