[48] | 1 | ; Project name : Assembly Library |
---|
| 2 | ; Description : Functions for preventing CGA snow. |
---|
| 3 | |
---|
| 4 | ; Section containing code |
---|
| 5 | SECTION .text |
---|
| 6 | |
---|
[50] | 7 | ;-------------------------------------------------------------------- |
---|
| 8 | ; CgaSnow_IsCgaPresent |
---|
| 9 | ; Parameters: |
---|
| 10 | ; DS: BDA segment (zero) |
---|
| 11 | ; Returns: |
---|
| 12 | ; CF: Set if CGA detected |
---|
| 13 | ; Cleared if CGA not detected |
---|
| 14 | ; Corrupts registers: |
---|
| 15 | ; AX |
---|
| 16 | ;-------------------------------------------------------------------- |
---|
[369] | 17 | ALIGN DISPLAY_JUMP_ALIGN |
---|
[50] | 18 | CgaSnow_IsCgaPresent: |
---|
| 19 | cmp WORD [BDA.wVidPort], CGA_STATUS_REGISTER - OFFSET_TO_CGA_STATUS_REGISTER |
---|
| 20 | jne SHORT .CgaNotFound |
---|
[52] | 21 | |
---|
| 22 | ; All standard CGA modes use 25 rows but only EGA and later store it to BDA. |
---|
| 23 | cmp BYTE [BDA.bVidRows], 25 |
---|
| 24 | jge SHORT .CgaNotFound |
---|
[50] | 25 | stc |
---|
| 26 | ret |
---|
[369] | 27 | ALIGN DISPLAY_JUMP_ALIGN |
---|
[50] | 28 | .CgaNotFound: |
---|
| 29 | clc |
---|
| 30 | ret |
---|
[48] | 31 | |
---|
[50] | 32 | |
---|
[162] | 33 | ; CGA snow prevention must be kept optional to avoid unnecessary |
---|
| 34 | ; overhead when building programs meant for non-CGA systems. |
---|
[48] | 35 | %ifdef ELIMINATE_CGA_SNOW |
---|
| 36 | |
---|
| 37 | ;-------------------------------------------------------------------- |
---|
[49] | 38 | ; CgaSnow_Stosb |
---|
| 39 | ; CgaSnow_Stosw |
---|
[48] | 40 | ; Parameters: |
---|
| 41 | ; AL: Character to output |
---|
| 42 | ; AH: Attribute to output (CgaSnow_StoswWithoutCgaSnow only) |
---|
| 43 | ; DS: BDA segment (zero) |
---|
| 44 | ; ES:DI: Ptr to video memory where to output |
---|
| 45 | ; Returns: |
---|
| 46 | ; DI: Incremented for next character |
---|
| 47 | ; Corrupts registers: |
---|
| 48 | ; AX, DX |
---|
| 49 | ;-------------------------------------------------------------------- |
---|
[369] | 50 | ALIGN DISPLAY_JUMP_ALIGN |
---|
[49] | 51 | CgaSnow_Stosb: |
---|
[50] | 52 | call LoadCgaStatusRegisterAddressToDXifCgaPresent |
---|
| 53 | jz SHORT .StosbWithoutWaitSinceUnknownPort |
---|
[48] | 54 | |
---|
| 55 | mov ah, al |
---|
| 56 | cli ; Interrupt request would mess up timing |
---|
| 57 | WAIT_UNTIL_SAFE_CGA_WRITE |
---|
| 58 | mov al, ah |
---|
| 59 | .StosbWithoutWaitSinceUnknownPort: |
---|
| 60 | stosb |
---|
| 61 | sti |
---|
| 62 | ret |
---|
| 63 | |
---|
[369] | 64 | ALIGN DISPLAY_JUMP_ALIGN |
---|
[49] | 65 | CgaSnow_Stosw: |
---|
[48] | 66 | push bx |
---|
[50] | 67 | call LoadCgaStatusRegisterAddressToDXifCgaPresent |
---|
| 68 | jz SHORT .StoswWithoutWaitSinceUnknownPort |
---|
[48] | 69 | |
---|
| 70 | xchg bx, ax |
---|
| 71 | cli ; Interrupt request would mess up timing |
---|
| 72 | WAIT_UNTIL_SAFE_CGA_WRITE |
---|
| 73 | xchg ax, bx |
---|
| 74 | .StoswWithoutWaitSinceUnknownPort: |
---|
| 75 | stosw |
---|
[162] | 76 | sti |
---|
[48] | 77 | pop bx |
---|
| 78 | ret |
---|
| 79 | |
---|
| 80 | |
---|
| 81 | ;-------------------------------------------------------------------- |
---|
[49] | 82 | ; CgaSnow_RepMovsb |
---|
[48] | 83 | ; Parameters: |
---|
| 84 | ; CX: Number of characters to copy |
---|
| 85 | ; DS: BDA segment (zero) |
---|
| 86 | ; ES:SI: Ptr to video memory where to read from |
---|
| 87 | ; ES:DI: Ptr to video memory where to write to |
---|
| 88 | ; Returns: |
---|
| 89 | ; SI, DI: Updated for next character |
---|
| 90 | ; Corrupts registers: |
---|
| 91 | ; AX, CX, DX |
---|
| 92 | ;-------------------------------------------------------------------- |
---|
[369] | 93 | ALIGN DISPLAY_JUMP_ALIGN |
---|
[49] | 94 | CgaSnow_RepMovsb: |
---|
[50] | 95 | call LoadCgaStatusRegisterAddressToDXifCgaPresent |
---|
| 96 | jz SHORT .RepMovsbWithoutWaitSinceUnknownPort |
---|
[48] | 97 | |
---|
| 98 | .MovsbNextByte: |
---|
| 99 | cli ; Interrupt request would mess up timing |
---|
| 100 | WAIT_UNTIL_SAFE_CGA_WRITE |
---|
[223] | 101 | es movsb |
---|
[48] | 102 | sti |
---|
| 103 | loop .MovsbNextByte |
---|
| 104 | ret |
---|
| 105 | .RepMovsbWithoutWaitSinceUnknownPort: |
---|
| 106 | eSEG_STR rep, es, movsb |
---|
| 107 | ret |
---|
| 108 | |
---|
| 109 | |
---|
| 110 | ;-------------------------------------------------------------------- |
---|
[50] | 111 | ; LoadCgaStatusRegisterAddressToDXifCgaPresent |
---|
[48] | 112 | ; Parameters: |
---|
| 113 | ; DS: BDA segment (zero) |
---|
| 114 | ; Returns: |
---|
| 115 | ; DX: CGA Status Register Address |
---|
[50] | 116 | ; ZF: Set if CGA not present |
---|
| 117 | ; Cleared if CGA present |
---|
[48] | 118 | ; Corrupts registers: |
---|
| 119 | ; Nothing |
---|
| 120 | ;-------------------------------------------------------------------- |
---|
[369] | 121 | ALIGN DISPLAY_JUMP_ALIGN |
---|
[50] | 122 | LoadCgaStatusRegisterAddressToDXifCgaPresent: |
---|
| 123 | test BYTE [VIDEO_BDA.displayContext+DISPLAY_CONTEXT.bFlags], FLG_CONTEXT_CGA |
---|
| 124 | jz SHORT .NoCgaDetected |
---|
| 125 | mov dx, CGA_STATUS_REGISTER |
---|
[369] | 126 | ALIGN DISPLAY_JUMP_ALIGN, ret |
---|
[50] | 127 | .NoCgaDetected: |
---|
[48] | 128 | ret |
---|
| 129 | |
---|
| 130 | |
---|
| 131 | %endif ; ELIMINATE_CGA_SNOW |
---|