1 ; **************************************************************************** 2 ; setmode1.s - TRDOS 386 (TRDOS v2.0) Test Program - Set Video Mode 3 ; ---------------------------------------------------------------------------- 4 ; 5 ; 16/11/2020 (Erdogan Tan) 6 ; 7 ; **************************************************************************** 8 9 ; 14/07/2020 10 ; 31/12/2017 11 ; TRDOS 386 (v2.0) system calls 12 _ver equ 0 13 _exit equ 1 14 _fork equ 2 15 _read equ 3 16 _write equ 4 17 _open equ 5 18 _close equ 6 19 _wait equ 7 20 _create equ 8 21 _rename equ 9 22 _delete equ 10 23 _exec equ 11 24 _chdir equ 12 25 _time equ 13 26 _mkdir equ 14 27 _chmod equ 15 28 _rmdir equ 16 29 _break equ 17 30 _drive equ 18 31 _seek equ 19 32 _tell equ 20 33 _memory equ 21 34 _prompt equ 22 35 _path equ 23 36 _env equ 24 37 _stime equ 25 38 _quit equ 26 39 _intr equ 27 40 _dir equ 28 41 _emt equ 29 42 _ldrvt equ 30 43 _video equ 31 44 _audio equ 32 45 _timer equ 33 46 _sleep equ 34 47 _msg equ 35 48 _geterr equ 36 49 _fpstat equ 37 50 _pri equ 38 51 _rele equ 39 52 _fff equ 40 53 _fnf equ 41 54 _alloc equ 42 55 _dalloc equ 43 56 _calbac equ 44 57 _dma equ 45 58 59 %macro sys 1-4 60 ; 29/04/2016 - TRDOS 386 (TRDOS v2.0) 61 ; 03/09/2015 62 ; 13/04/2015 63 ; Retro UNIX 386 v1 system call. 64 %if %0 >= 2 65 mov ebx, %2 66 %if %0 >= 3 67 mov ecx, %3 68 %if %0 = 4 69 mov edx, %4 70 %endif 71 %endif 72 %endif 73 mov eax, %1 74 ;int 30h 75 int 40h ; TRDOS 386 (TRDOS v2.0) 76 %endmacro 77 78 ; TRDOS 386 (and Retro UNIX 386 v1) system call format: 79 ; sys systemcall (eax) , , 80 81 ;======================================================================== 82 ; SET VIDEO MODE 83 ;======================================================================== 84 85 [BITS 32] ; We need 32-bit intructions for protected mode 86 87 [ORG 0] 88 START_CODE: 89 00000000 BE[EB000000] mov esi, message1 90 00000005 E855000000 call print_msg 91 92 0000000A 30E4 xor ah, ah 93 0000000C CD32 int 32h ; real mode: int 16h 94 95 0000000E 66B80100 mov ax, 1 ; mode 1 ; 96 00000012 CD31 int 31h ; real mode: int 10h 97 98 ; DIRECT ACCESS TO VIDEO MEMORY 99 ;xor ebx, ebx 100 00000014 B704 mov bh, 4 ; Direct access/map to CGA memory (0B8000h) 101 ;mov eax, _video ; 1Fh 102 00000016 66B81F00 mov ax, 1Fh ; sys _video ; TRDOS 386 Video functions 103 0000001A CD40 int 40h ; TRDOS 386 system call 104 105 ; eax = 0B8000h 106 0000001C 21C0 and eax, eax 107 0000001E 7430 jz terminate ; error (eax = 0) 108 109 00000020 BE[1C010000] mov esi, message2 110 00000025 E849000000 call print_msg_x 111 key_loop: 112 0000002A 30E4 xor ah, ah 113 0000002C CD32 int 32h ; real mode: int 16h 114 115 0000002E 3C0D cmp al, 13 ; ENTER key 116 00000030 7415 je short crlf 117 118 00000032 3C1B cmp al, 27 ; ESCape key 119 00000034 741A je short terminate 120 121 00000036 3C03 cmp al, 3 ; CTRL+C 122 00000038 7416 je short terminate 123 124 0000003A 6683F800 cmp ax, 0 ; CTRL+BREAK 125 0000003E 7410 je short terminate 126 _next_char: 127 ; 17/11/2020 128 00000040 E841000000 call print_char 129 130 ;print_char: 131 ; mov ah, 0Eh 132 ; mov bx, 07h 133 ; int 31h ; real mode: int 10h 134 ; jmp short key_loop 135 ;crlf: 136 ; mov ah, 0Eh 137 ; ;mov al, 0Dh ; Carriage return 138 ; mov bx, 07h 139 ; int 31h ; real mode: int 10h 140 ; mov al, 0Ah ; Line feed 141 ; 142 ; jmp short print_char 143 144 ; 17/11/2020 145 00000045 EBE3 jmp short key_loop 146 crlf: 147 00000047 E83A000000 call print_char 148 0000004C B00A mov al, 10 149 0000004E EBF0 jmp short _next_char 150 151 terminate: 152 00000050 66B80300 mov ax, 3 ; mode 3 ; 153 00000054 CD31 int 31h ; real mode: int 10h 154 155 sys _exit 155 <1> 155 <1> 155 <1> 155 <1> 155 <1> %if %0 >= 2 155 <1> mov ebx, %2 155 <1> %if %0 >= 3 155 <1> mov ecx, %3 155 <1> %if %0 = 4 155 <1> mov edx, %4 155 <1> %endif 155 <1> %endif 155 <1> %endif 155 00000056 B801000000 <1> mov eax, %1 155 <1> 155 0000005B CD40 <1> int 40h 156 here: 157 0000005D EBFE jmp short here 158 159 print_msg: 160 sys _msg, esi, 255, 0Fh 160 <1> 160 <1> 160 <1> 160 <1> 160 <1> %if %0 >= 2 160 0000005F 89F3 <1> mov ebx, %2 160 <1> %if %0 >= 3 160 00000061 B9FF000000 <1> mov ecx, %3 160 <1> %if %0 = 4 160 00000066 BA0F000000 <1> mov edx, %4 160 <1> %endif 160 <1> %endif 160 <1> %endif 160 0000006B B823000000 <1> mov eax, %1 160 <1> 160 00000070 CD40 <1> int 40h 161 ; message with white color 162 ; (max. 255 chars) 163 00000072 C3 retn 164 165 ; 17/11/2020 166 print_msg_x: 167 00000073 89C7 mov edi, eax ; 0B8000h 168 00000075 31C0 xor eax, eax 169 00000077 31D2 xor edx, edx 170 00000079 B70F mov bh, 0Fh ; color (attribute) 171 _0: 172 0000007B AC lodsb 173 0000007C 08C0 or al, al 174 0000007E 7405 jz short _ok 175 176 00000080 E801000000 call print_char 177 _ok: 178 00000085 C3 retn 179 180 print_char: 181 00000086 3C0D cmp al, 13 ; Carriage return 182 00000088 7452 je short cr 183 0000008A 3C0A cmp al, 10 ; Line feed 184 0000008C 7452 je short lf 185 186 0000008E 3C08 cmp al, 8 ; Backspace 187 00000090 7522 jne short _alfanumeric 188 189 00000092 88C3 mov bl, al 190 00000094 B050 mov al, 80 ; columns * 2 191 00000096 F6E6 mul dh ; * row 192 00000098 D0E2 shl dl, 1 193 0000009A 00D0 add al, dl ; column * 2 194 0000009C 80D400 adc ah, 0 ; + 195 0000009F D0EA shr dl, 1 196 197 000000A1 66C704072007 mov word [edi+eax], 0720h ; clear current char 198 199 000000A7 FECA dec dl 200 000000A9 7930 jns short _retn 201 000000AB B227 mov dl, 39 ; column 39 202 000000AD FECE dec dh 203 000000AF 792A jns short _retn 204 000000B1 31D2 xor edx, edx 205 000000B3 C3 retn 206 _alfanumeric: 207 000000B4 88C3 mov bl, al 208 000000B6 B050 mov al, 80 ; columns * 2 209 000000B8 F6E6 mul dh ; * row 210 000000BA D0E2 shl dl, 1 211 000000BC 00D0 add al, dl ; column * 2 212 000000BE 80D400 adc ah, 0 ; + 213 000000C1 D0EA shr dl, 1 214 215 000000C3 B70F mov bh, 0Fh 216 000000C5 66891C07 mov [edi+eax], bx ; char and color/attrib 217 218 000000C9 FEC2 inc dl ; next column 219 000000CB 80FA28 cmp dl, 40 220 000000CE 720B jb short _retn 221 222 000000D0 30D2 xor dl, dl ; column 0 223 000000D2 FEC6 inc dh ; next row 224 000000D4 80FE19 cmp dh, 25 225 000000D7 7202 jb short _retn 226 000000D9 30F6 xor dh, dh ; row 0 227 _retn: 228 000000DB C3 retn 229 cr: 230 000000DC 30D2 xor dl, dl 231 000000DE EBFB jmp short _retn 232 lf: 233 000000E0 FEC6 inc dh 234 000000E2 80FE19 cmp dh, 25 235 000000E5 72F4 jb short _retn 236 000000E7 30F6 xor dh, dh 237 000000E9 EBF0 jmp short _retn 238 239 ;----------------------------------------------------------------- 240 ; MESSAGES 241 ;----------------------------------------------------------------- 242 243 message1: 244 000000EB 0D0A db 0Dh, 0Ah 245 000000ED 50726573732061206B- db "Press a key to set video mode 1 (40x25 text)" 245 000000F6 657920746F20736574- 245 000000FF 20766964656F206D6F- 245 00000108 646520312028343078- 245 00000111 3235207465787429 246 00000119 0D0A00 db 0Dh, 0Ah, 0 247 message2: 248 0000011C 0D0A0D0A db 0Dh, 0Ah, 0Dh, 0Ah 249 00000120 507265737320455343- db "Press ESC to exit" 249 00000129 20746F2065786974 250 00000131 0D0A00 db 0Dh, 0Ah, 0