1 | ; Project name : Assembly Library |
---|
2 | ; Description : Macros for preventing CGA snow. |
---|
3 | %ifndef CGASNOW_INC |
---|
4 | %define CGASNOW_INC |
---|
5 | |
---|
6 | ;-------------------------------------------------------------------- |
---|
7 | ; CALL_WAIT_FOR_RETRACE_IF_NECESSARY_THEN |
---|
8 | ; JMP_WAIT_FOR_RETRACE_IF_NECESSARY_THEN |
---|
9 | ; Parameters: |
---|
10 | ; %1: Instruction that accessed CGA memory |
---|
11 | ; AL: Character to output |
---|
12 | ; AH: Attribute to output (stosw only) |
---|
13 | ; DS: BDA segment (zero) |
---|
14 | ; ES:SI: Ptr to video memory where to read from (if %1 reads) |
---|
15 | ; ES:DI: Ptr to video memory where to output (if %1 writes) |
---|
16 | ; Returns: |
---|
17 | ; SI, DI: Updated according to instruction |
---|
18 | ; Corrupts registers: |
---|
19 | ; AX, DX |
---|
20 | ;-------------------------------------------------------------------- |
---|
21 | %macro CALL_WAIT_FOR_RETRACE_IF_NECESSARY_THEN 1 |
---|
22 | %ifdef ELIMINATE_CGA_SNOW |
---|
23 | %ifidn %1, stosb |
---|
24 | call CgaSnow_Stosb |
---|
25 | %elifidn %1, stosw |
---|
26 | call CgaSnow_Stosw |
---|
27 | %elifidn %1, rep movsb |
---|
28 | call CgaSnow_RepMovsb |
---|
29 | %else |
---|
30 | %error "Invalid instruction passed to CALL_WAIT_FOR_RETRACE_IF_NECESSARY_THEN" |
---|
31 | %endif |
---|
32 | %else ; No CGA snow prevention |
---|
33 | %ifidn %1, rep movsb |
---|
34 | eSEG_STR rep, es, movsb |
---|
35 | %else |
---|
36 | %1 ; Single instruction |
---|
37 | %endif |
---|
38 | %endif |
---|
39 | %endmacro |
---|
40 | |
---|
41 | %macro JMP_WAIT_FOR_RETRACE_IF_NECESSARY_THEN 1 |
---|
42 | %ifdef ELIMINATE_CGA_SNOW |
---|
43 | %ifidn %1, stosb |
---|
44 | jmp CgaSnow_Stosb |
---|
45 | %elifidn %1, stosw |
---|
46 | jmp CgaSnow_Stosw |
---|
47 | %elifidn %1, rep movsb |
---|
48 | jmp CgaSnow_RepMovsb |
---|
49 | %else |
---|
50 | %error "Invalid instruction passed to JMP_WAIT_FOR_RETRACE_IF_NECESSARY_THEN" |
---|
51 | %endif |
---|
52 | %else ; No CGA snow prevention |
---|
53 | %ifidn %1, rep movsb |
---|
54 | eSEG_STR rep, es, movsb |
---|
55 | ret |
---|
56 | %else |
---|
57 | %1 ; Single instruction |
---|
58 | ret |
---|
59 | %endif |
---|
60 | %endif |
---|
61 | %endmacro |
---|
62 | |
---|
63 | |
---|
64 | ;-------------------------------------------------------------------- |
---|
65 | ; WAIT_UNTIL_SAFE_CGA_WRITE |
---|
66 | ; Parameters: |
---|
67 | ; DX: CGA Status Register Address (3DAh) |
---|
68 | ; Returns: |
---|
69 | ; Nothing |
---|
70 | ; Corrupts registers: |
---|
71 | ; AL |
---|
72 | ;-------------------------------------------------------------------- |
---|
73 | %macro WAIT_UNTIL_SAFE_CGA_WRITE 0 |
---|
74 | %%WaitUntilNotInRetrace: |
---|
75 | in al, dx |
---|
76 | shr al, 1 ; 1 = Bit 0: A 1 indicates that regen-buffer memory access can be |
---|
77 | ; made without interfering with the display. (H or V retrace) |
---|
78 | jc SHORT %%WaitUntilNotInRetrace |
---|
79 | %%WaitUntilNextRetraceStarts: |
---|
80 | in al, dx |
---|
81 | shr al, 1 |
---|
82 | jnc SHORT %%WaitUntilNextRetraceStarts |
---|
83 | %endmacro |
---|
84 | |
---|
85 | |
---|
86 | %endif ; CGASNOW_INC |
---|