[41] | 1 | ; File name : DisplayCharOut.asm
|
---|
| 2 | ; Project name : Assembly Library
|
---|
| 3 | ; Created date : 26.6.2010
|
---|
[42] | 4 | ; Last update : 18.9.2010
|
---|
[41] | 5 | ; Author : Tomi Tilli
|
---|
| 6 | ; Description : Functions for outputting characters to video memory.
|
---|
| 7 | ; These functions are meant to be called by Display_CharacterFromAL
|
---|
| 8 | ; and Display_RepeatCharacterFromAL using function pointer
|
---|
| 9 | ; stored in DISPLAY_CONTEXT.
|
---|
| 10 |
|
---|
| 11 | ; Section containing code
|
---|
| 12 | SECTION .text
|
---|
| 13 |
|
---|
| 14 | ;--------------------------------------------------------------------
|
---|
[42] | 15 | ; WAIT_RETRACE_IF_NECESSARY_THEN
|
---|
| 16 | ; Parameters:
|
---|
| 17 | ; AL: Character to output
|
---|
| 18 | ; AH: Attribute to output (stosw only)
|
---|
| 19 | ; DS: BDA segment (zero)
|
---|
| 20 | ; ES:DI: Ptr to video memory where to output
|
---|
| 21 | ; Returns:
|
---|
| 22 | ; DI: Incremented for next character
|
---|
| 23 | ; Corrupts registers:
|
---|
| 24 | ; AX, DX
|
---|
| 25 | ;--------------------------------------------------------------------
|
---|
| 26 | %macro WAIT_RETRACE_IF_NECESSARY_THEN 1
|
---|
| 27 | %ifdef ELIMINATE_CGA_SNOW
|
---|
| 28 | %ifidn %1, stosb
|
---|
| 29 | call StosbWithoutCgaSnow
|
---|
| 30 | %else
|
---|
| 31 | call StoswWithoutCgaSnow
|
---|
| 32 | %endif
|
---|
| 33 | %else
|
---|
| 34 | %1 ; STOSB or STOSW
|
---|
| 35 | %endif
|
---|
| 36 | %endmacro
|
---|
| 37 |
|
---|
| 38 |
|
---|
| 39 | ;--------------------------------------------------------------------
|
---|
[41] | 40 | ; DisplayCharOut_TeletypeOutputWithAttribute
|
---|
| 41 | ; DisplayCharOut_TeletypeOutput
|
---|
| 42 | ; Parameters:
|
---|
| 43 | ; AL: Character to output
|
---|
| 44 | ; AH: Attribute to output
|
---|
| 45 | ; DS: BDA segment (zero)
|
---|
| 46 | ; ES:DI: Ptr to video memory where to output
|
---|
| 47 | ; Returns:
|
---|
| 48 | ; DI: Incremented for next character
|
---|
| 49 | ; Corrupts registers:
|
---|
| 50 | ; AX, DX
|
---|
| 51 | ;--------------------------------------------------------------------
|
---|
| 52 | ALIGN JUMP_ALIGN
|
---|
| 53 | DisplayCharOut_TeletypeOutputWithAttribute:
|
---|
| 54 | cmp al, ' ' ; Printable character?
|
---|
| 55 | jb SHORT DisplayCharOut_BiosTeletypeOutput
|
---|
[42] | 56 | WAIT_RETRACE_IF_NECESSARY_THEN stosw
|
---|
[41] | 57 | ret
|
---|
| 58 |
|
---|
| 59 | ALIGN JUMP_ALIGN
|
---|
| 60 | DisplayCharOut_TeletypeOutput:
|
---|
| 61 | cmp al, ' ' ; Printable character?
|
---|
| 62 | jae SHORT DisplayCharOut_Character
|
---|
| 63 | ; Fall to DisplayCharOut_BiosTeletypeOutput
|
---|
| 64 |
|
---|
| 65 | ;--------------------------------------------------------------------
|
---|
| 66 | ; DisplayCharOut_BiosTeletypeOutput
|
---|
| 67 | ; Parameters:
|
---|
| 68 | ; AL: Control character
|
---|
| 69 | ; DS: BDA segment (zero)
|
---|
| 70 | ; ES:DI: Ptr to video memory where to output
|
---|
| 71 | ; Returns:
|
---|
| 72 | ; DI: Incremented for next character
|
---|
| 73 | ; Corrupts registers:
|
---|
| 74 | ; AX, DX
|
---|
| 75 | ;--------------------------------------------------------------------
|
---|
| 76 | ALIGN JUMP_ALIGN
|
---|
| 77 | DisplayCharOut_BiosTeletypeOutput:
|
---|
| 78 | push ax
|
---|
| 79 | call DisplayCursor_SynchronizeCoordinatesToHardware
|
---|
| 80 | pop ax
|
---|
| 81 | call .OutputCharacterWithBIOS
|
---|
| 82 | call DisplayCursor_GetHardwareCoordinatesToAX
|
---|
| 83 | jmp DisplayCursor_SetCoordinatesFromAX
|
---|
| 84 |
|
---|
| 85 | ;--------------------------------------------------------------------
|
---|
| 86 | ; .OutputCharacterWithBIOS
|
---|
| 87 | ; Parameters:
|
---|
| 88 | ; AL: Character to output
|
---|
| 89 | ; DS: BDA segment
|
---|
| 90 | ; Returns:
|
---|
| 91 | ; Nothing
|
---|
| 92 | ; Corrupts registers:
|
---|
| 93 | ; AX
|
---|
| 94 | ;--------------------------------------------------------------------
|
---|
| 95 | ALIGN JUMP_ALIGN
|
---|
| 96 | .OutputCharacterWithBIOS:
|
---|
| 97 | push bx
|
---|
| 98 | mov ah, TELETYPE_OUTPUT
|
---|
| 99 | mov bh, [VIDEO_BDA.bActivePage]
|
---|
| 100 | int BIOS_VIDEO_INTERRUPT_10h
|
---|
| 101 | pop bx
|
---|
| 102 | ret
|
---|
| 103 |
|
---|
| 104 |
|
---|
| 105 | ;--------------------------------------------------------------------
|
---|
| 106 | ; DisplayCharOut_Attribute
|
---|
| 107 | ; DisplayCharOut_Character
|
---|
| 108 | ; DisplayCharOut_CharacterWithAttribute
|
---|
| 109 | ; Parameters:
|
---|
| 110 | ; AL: Character to output
|
---|
| 111 | ; AH: Attribute to output
|
---|
[42] | 112 | ; DS: BDA segment (zero)
|
---|
[41] | 113 | ; ES:DI: Ptr to video memory where to output
|
---|
| 114 | ; Returns:
|
---|
| 115 | ; DI: Incremented for next character
|
---|
| 116 | ; Corrupts registers:
|
---|
[42] | 117 | ; AX, DX
|
---|
[41] | 118 | ;--------------------------------------------------------------------
|
---|
| 119 | ALIGN JUMP_ALIGN
|
---|
| 120 | DisplayCharOut_Attribute:
|
---|
| 121 | xchg al, ah ; Swap character and attribute
|
---|
| 122 | inc di ; Skip character
|
---|
[42] | 123 | WAIT_RETRACE_IF_NECESSARY_THEN stosb
|
---|
[41] | 124 | ret
|
---|
| 125 |
|
---|
| 126 | ALIGN JUMP_ALIGN
|
---|
| 127 | DisplayCharOut_Character:
|
---|
[42] | 128 | WAIT_RETRACE_IF_NECESSARY_THEN stosb
|
---|
[41] | 129 | inc di ; Skip attribute
|
---|
| 130 | ret
|
---|
| 131 |
|
---|
| 132 | ALIGN JUMP_ALIGN
|
---|
| 133 | DisplayCharOut_CharacterWithAttribute:
|
---|
[42] | 134 | WAIT_RETRACE_IF_NECESSARY_THEN stosw
|
---|
[41] | 135 | ret
|
---|
| 136 |
|
---|
| 137 |
|
---|
| 138 | ;--------------------------------------------------------------------
|
---|
| 139 | ; DisplayCharOut_WriteCharacterToBuffer
|
---|
| 140 | ; Parameters:
|
---|
| 141 | ; AL: Character to output
|
---|
| 142 | ; DS: BDA segment (zero)
|
---|
| 143 | ; ES:DI: Ptr to destination string buffer
|
---|
| 144 | ; DISPLAY_CONTEXT.wCharOutParam: Offset to end of buffer (one past last)
|
---|
| 145 | ; Returns:
|
---|
| 146 | ; ES:DI: Updated for next character
|
---|
| 147 | ; Corrupts registers:
|
---|
| 148 | ; AX, DX
|
---|
| 149 | ;--------------------------------------------------------------------
|
---|
| 150 | ALIGN JUMP_ALIGN
|
---|
| 151 | DisplayCharOut_WriteCharacterToBuffer:
|
---|
| 152 | cmp di, [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.wCharOutParam]
|
---|
| 153 | jae SHORT .BufferFull
|
---|
| 154 | stosb
|
---|
| 155 | .BufferFull:
|
---|
| 156 | ret
|
---|
[42] | 157 |
|
---|
| 158 |
|
---|
| 159 | ; STOSB and STOSW replacement functions to prevent CGA snow. These will slow
|
---|
| 160 | ; drawing a lot so use them only if it is necessary to eliminate CGA snow.
|
---|
| 161 | %ifdef ELIMINATE_CGA_SNOW
|
---|
| 162 |
|
---|
| 163 | OFFSET_TO_CGA_STATUS_REGISTER EQU 6 ; Base port 3D4h + 6 = 3DAh
|
---|
| 164 | CGA_STATUS_REGISTER EQU 3DAh
|
---|
| 165 |
|
---|
| 166 | ;--------------------------------------------------------------------
|
---|
| 167 | ; WAIT_UNTIL_SAFE_CGA_WRITE
|
---|
| 168 | ; Parameters:
|
---|
| 169 | ; DX: CGA Status Register Address (3DAh)
|
---|
| 170 | ; Returns:
|
---|
| 171 | ; Interrupts disabled
|
---|
| 172 | ; Corrupts registers:
|
---|
| 173 | ; AL
|
---|
| 174 | ;--------------------------------------------------------------------
|
---|
| 175 | %macro WAIT_UNTIL_SAFE_CGA_WRITE 0
|
---|
| 176 | cli ; Interrupt request would mess up timing
|
---|
| 177 | %%WaitUntilNotInRetrace:
|
---|
| 178 | in al, dx
|
---|
| 179 | shr al, 1 ; 1 = Bit 0: A 1 indicates that regen-buffer memory access can be
|
---|
| 180 | ; made without interfering with the display. (H or V retrace)
|
---|
| 181 | jc SHORT %%WaitUntilNotInRetrace
|
---|
| 182 | sti
|
---|
| 183 | nop ; Should have time to serve IRQ here
|
---|
| 184 | cli
|
---|
| 185 | %%WaitUntilNextRetraceStarts:
|
---|
| 186 | in al, dx
|
---|
| 187 | shr al, 1
|
---|
| 188 | jnc SHORT %%WaitUntilNextRetraceStarts
|
---|
| 189 | %endmacro
|
---|
| 190 |
|
---|
| 191 | ;--------------------------------------------------------------------
|
---|
| 192 | ; StosbWithoutCgaSnow
|
---|
| 193 | ; StoswWithoutCgaSnow
|
---|
| 194 | ; Parameters:
|
---|
| 195 | ; AL: Character to output
|
---|
| 196 | ; AH: Attribute to output (StoswWithoutCgaSnow only)
|
---|
| 197 | ; DS: BDA segment (zero)
|
---|
| 198 | ; ES:DI: Ptr to video memory where to output
|
---|
| 199 | ; Returns:
|
---|
| 200 | ; DI: Incremented for next character
|
---|
| 201 | ; Corrupts registers:
|
---|
| 202 | ; AX, DX
|
---|
| 203 | ;--------------------------------------------------------------------
|
---|
| 204 | ALIGN JUMP_ALIGN
|
---|
| 205 | StosbWithoutCgaSnow:
|
---|
| 206 | call LoadAndVerifyStatusRegisterFromBDA
|
---|
| 207 | jne SHORT .StosbWithoutWaitSinceUnknownPort
|
---|
| 208 |
|
---|
| 209 | mov ah, al
|
---|
| 210 | WAIT_UNTIL_SAFE_CGA_WRITE
|
---|
| 211 | mov al, ah
|
---|
| 212 | stosb
|
---|
| 213 | sti
|
---|
| 214 | ret
|
---|
| 215 | ALIGN JUMP_ALIGN
|
---|
| 216 | .StosbWithoutWaitSinceUnknownPort:
|
---|
| 217 | stosb
|
---|
| 218 | ret
|
---|
| 219 |
|
---|
| 220 | ALIGN JUMP_ALIGN
|
---|
| 221 | StoswWithoutCgaSnow:
|
---|
| 222 | call LoadAndVerifyStatusRegisterFromBDA
|
---|
| 223 | jne SHORT .StoswWithoutWaitSinceUnknownPort
|
---|
| 224 |
|
---|
| 225 | push bx
|
---|
| 226 | xchg bx, ax
|
---|
| 227 | WAIT_UNTIL_SAFE_CGA_WRITE
|
---|
| 228 | xchg ax, bx
|
---|
| 229 | stosw
|
---|
| 230 | pop bx
|
---|
| 231 | sti
|
---|
| 232 | ret
|
---|
| 233 | ALIGN JUMP_ALIGN
|
---|
| 234 | .StoswWithoutWaitSinceUnknownPort:
|
---|
| 235 | stosw
|
---|
| 236 | ret
|
---|
| 237 |
|
---|
| 238 | ;--------------------------------------------------------------------
|
---|
| 239 | ; LoadAndVerifyStatusRegisterFromBDA
|
---|
| 240 | ; Parameters:
|
---|
| 241 | ; DS: BDA segment (zero)
|
---|
| 242 | ; Returns:
|
---|
| 243 | ; DX: CGA Status Register Address
|
---|
| 244 | ; ZF: Set if CGA Base Port found in BDA
|
---|
| 245 | ; Corrupts registers:
|
---|
| 246 | ; Nothing
|
---|
| 247 | ;--------------------------------------------------------------------
|
---|
| 248 | ALIGN JUMP_ALIGN
|
---|
| 249 | LoadAndVerifyStatusRegisterFromBDA:
|
---|
| 250 | mov dx, [BDA.wVidPort]
|
---|
| 251 | add dl, OFFSET_TO_CGA_STATUS_REGISTER
|
---|
| 252 | cmp dx, CGA_STATUS_REGISTER
|
---|
| 253 | ret
|
---|
| 254 |
|
---|
| 255 | %endif ; ELIMINATE_CGA_SNOW
|
---|