Processing Messages

You process and prepare static messages for display by using the GET_MESSAGE_PTR macro. The following example shows how to retrieve the addresses of two static messages declared in the file USAMSG.INC:

include usamsg.inc

GET_MESSAGE_PTR MSG_BootErrorMsg eax
  ; address of MSG_BootErrorMsg message now in eax

GET_MESSAGE_PTR MSG_DiskPlease edx
  ; address of MSG_DiskPlease message now in edx

You process messages containing parameter placeholders by using the PUSH_SPRINTF macro. Because this macro places a new string on the stack, you must use the POP_SPRINTF macro to remove the string from the stack after displaying it.

Of course, since the message is on the stack, it goes away once you call POP_SPRINTF. A common error is passing the pointer to a pushed string to another procedure (such as SHELL_Message), then popping the string before the called procedure is finished with it. If you need a message to be placed somewhere other than the stack, use the LOCALIZED_SPRINTF macro instead.

The following example shows how to process the MSG_CantOpen message:

include usamsg.inc

PUSH_SPRINTF MSG_CantOpen, eax, <offset32 DriveBuf>
  ; address of new string now in eax

PUSHED_SPRINTF_LENGTH ebx
  ; string length now in ebx

; Call output function here

POP_SPRINTF     ; Remove the string from stack

In this example, the EAX register contains the address of a null-terminated string specifying a filename and the DriveBuf variable contains a null terminated string specifying the drive letter. The parameter placeholders are assumed to be %0s and %1s. The macro creates a new string by replacing the parameter placeholders in the original message with the filename and driver letter. The macro leaves the new string on the stacks copies its address to the EAX register.

See Also

GET_MESSAGE_PTR, POP_SPRINTF, PUSH_SPRINTF, PUSHED_SPRINTF_LENGTH