@@ -25,10 +25,10 @@ DataAreaStartLow = 4
2525BiosCHSDriveSizeHigh = 6
2626BiosCHSDriveSizeLow = 8
2727BiosCHSDriveSize = 8
28- ReadSectorsOffset = 10
29- ReadClusterOffset = 12
30- PutCharsOffset = 14
31- BootSectorStackTop = HEX(7C00) - 16
28+ ReadSectorsOffset = 12
29+ ReadClusterOffset = 16
30+ PutCharsOffset = 20
31+ BootSectorStackTop = HEX(7C00) - 22
3232
3333if 0
3434.macro DEBUG_STOP
@@ -244,9 +244,14 @@ FoundFreeLoader:
244244 * Save the addresses of needed functions so
245245 * the helper code will know where to call them
246246 * /
247- mov word ptr [ bp - ReadSectorsOffset ], offset ReadSectors // Save the address of ReadSectors
248- mov word ptr [ bp - ReadClusterOffset ], offset ReadCluster // Save the address of ReadCluster
249- mov word ptr [ bp - PutCharsOffset ], offset PrintString // Save the address of PrintString
247+ xor bx , bx
248+ mov word ptr [ bp - (ReadSectorsOffset - 2 ) ], bx // Save the segment of ReadSectors
249+ mov word ptr [ bp - (ReadClusterOffset - 2 ) ], bx // Save the segment of ReadCluster
250+ mov word ptr [ bp - (PutCharsOffset - 2 ) ], bx // Save the segment of PrintString
251+ mov word ptr [ bp - ReadSectorsOffset ], offset ReadSectors // Save the address of ReadSectors
252+ mov word ptr [ bp - ReadClusterOffset ], offset ReadCluster // Save the address of ReadCluster
253+ mov word ptr [ bp - PutCharsOffset ], offset PrintString // Save the address of PrintString
254+ mov byte ptr [ PatchedRet ], HEX(CB) // Patch 'ret' with 'retf'
250255
251256 / *
252257 * Now AX has start cluster of FreeLoader and we
@@ -256,7 +261,7 @@ FoundFreeLoader:
256261 * because they contain a jump instruction to skip
257262 * over the helper code in the FreeLoader image
258263 * /
259- ljmp16 0 , FREELDR_BASE + 3
264+ ljmp16 FREELDR_BASE / 16 , 3
260265
261266/ *
262267 * Reads cluster number in AX into [ ES : BX ]
@@ -347,7 +352,7 @@ ReadSectors:
347352 pop bx
348353 loop .ReadSectorsLoop // Increment read buffer for next sector , read next sector
349354
350- ret
355+ jmp PatchedRet
351356
352357/ *
353358 * Prints a character
@@ -385,7 +390,7 @@ PrintString:
385390 lodsb // Get a single char from a ptr
386391
387392 or al , al
388- jz short .PrintEnd // Found NULL
393+ jz short PatchedRet // Found NULL
389394
390395 cmp al , HEX(0D)
391396 jz short .PrintStringHandleCR // Found CR
@@ -403,7 +408,7 @@ PrintString:
403408 inc si // Skip the next LF character
404409 jmp short PrintString
405410
406- .PrintEnd :
411+ PatchedRet :
407412 ret
408413
409414if 0
@@ -478,8 +483,11 @@ msgDiskError:
478483 .ascii "ERR" , CR , LF , NUL
479484msgNotFoundError:
480485 .ascii "NFE" , CR , LF , NUL
486+ // Sorry , need the space...
487+ // msgAnyKey:
488+ // .ascii "Press any key" , NUL
481489msgAnyKey:
482- .ascii "Press any key" , NUL
490+ .ascii "Press key" , NUL
483491filename:
484492 .ascii "FREELDR SYS"
485493
0 commit comments