This code is intended to be included with X86-16 writing ASCIIZ strings directly to video and is dependent upon some of the declarations in that code. When combined with that code a string declared @ 1000:0 in the following manner would;
AscTxt: db 01, 84H ; View page 0 output to 4 db 'This is an example', 01, 40H ; View page 4 output to 0 db 'This is replacing whatever is on top line of page 0' db 0, 01, 0FH, 0, 0 ; Waits for response then view page 0
As an example, let's start with this.
This is the next thing you would see after entering your .COM filename @ command prompt.
Notice how the cursor has not moved to EOS. That is by design. Then after pressing any key except ESC, we'll revert back to page 0 with top line being replaced.
; ============================================================================================= ; Change display and/or destination page ; ENTER: 00 - 7 = Set do not change current page being displayed ; 6-4 = Display page. Ignored if equal to active or but 7 set ; 3 = Set, do not change display page ; 2-0 = Destination page. Ignored if already pointing there or bit 3 set. ; LEAVE: DI = New pointer when applicable ; DX = volatile, all others unchanged. ; FLAGS: Undefined ; --------------------------------------------------------------------------------------------- F01: cmp al, 1 jnz F02 lodsb ; Read only parameter for this function ; Real mode has a few limitations in addressing far data, so this just seems to be the ; most practical way of addressing data in BDA push bx ; Test bit 7 to determine if display page should be changed. If so, then bits 6-4 are ; ignored. test al, 10000000B ; Is bit 7 on jnz .cDest ; if so we are not changing display page push ax ; Still going to need low nibble shr ax, 4 ; Shift page number into low nibble cmp al, [fs:DispPg] ; Check BDA if anything actually needs done jz .cDest - 1 ; Already on that page ; The intent of procedurd e as a whole is to avoid BIOS as much as possible, but I ; did not want to implement code to manipulate controller. mov ah, SAP int VIDEO pop ax ; Restore value in low nibble .cDest: test al, 1000B ; Is bit 3 on jnz .exit ; if so we are not changing destination page ; Return to instruction just before label .next ; Check if there is any need to do anything by determining if destination video segment ; is already being pointed too. and al, 7 mov dx, es ; Get current video segment mov dl, al add dl, 0B8H cmp dh, dl ; ZF will be set if same segments jz .exit ; Set new segment and then determine offset based on that pages cursor position from ; x/y coordinates specified in BDA. shl dx, 8 mov es, dx ; Set new segment ; Caret position of new page or even one that has been written to before is assumed ; to be the starting point of next write. mov bx, Cursors ; Point to beginning of array of vectors shl ax, 1 add bl, al mov dx, [bx] ; Points into arrary of vectors in BDA mov di, dx ; Just in case we are already at 0,0. or dx, dx jz .exit ; If position is top/left, not much point multiplying by zero mov al, dh imul ax, 80 ; 80 x 25 x 16 color assumed and di, 0FFH add di, ax shl di, 1 ; ES:DI set to new page & offset ; Restore non-volatile .exit: pop bx ret F02: ret