     1                                  ; ****************************************************************************
     2                                  ; CLS.ASM (cls.s)
     3                                  ; ----------------------------------------------------------------------------
     4                                  ; Retro UNIX 386 v1 - cls (clear screen) file
     5                                  ;
     6                                  ; [ Last Modification: 02/02/2022 ]
     7                                  ;
     8                                  ; ****************************************************************************
     9                                  ; 02/02/2022
    10                                  ; Assembler: NASM 2.15
    11                                  ; 	nasm cls.s -l cls.txt -o cls -Z error.txt
    12                                  ;
    13                                  ; (Retro UNIX 386 v1 - cls.s, NASM 2.15)
    14                                  ; Derived from CLS.ASM (30/01/2022, Retro UNIX 8086 v1, MASM 6.14)  
    15                                  ;
    16                                  ; ****************************************************************************
    17                                  ; 02/02/2022
    18                                  ; ----------------------------------------------------------------------------
    19                                  
    20                                  ; UNIX v1 system calls
    21                                  _rele 	equ 0
    22                                  _exit 	equ 1
    23                                  _fork 	equ 2
    24                                  _read 	equ 3
    25                                  _write	equ 4
    26                                  _open	equ 5
    27                                  _close 	equ 6
    28                                  _wait 	equ 7
    29                                  _creat 	equ 8
    30                                  _link 	equ 9
    31                                  _unlink	equ 10
    32                                  _exec	equ 11
    33                                  _chdir	equ 12
    34                                  _time 	equ 13
    35                                  _mkdir 	equ 14
    36                                  _chmod	equ 15
    37                                  _chown	equ 16
    38                                  _break	equ 17
    39                                  _stat	equ 18
    40                                  _seek	equ 19
    41                                  _tell 	equ 20
    42                                  _mount	equ 21
    43                                  _umount	equ 22
    44                                  _setuid	equ 23
    45                                  _getuid	equ 24
    46                                  _stime	equ 25
    47                                  _quit	equ 26	
    48                                  _intr	equ 27
    49                                  _fstat	equ 28
    50                                  _emt 	equ 29
    51                                  _mdate 	equ 30
    52                                  _stty 	equ 31
    53                                  _gtty	equ 32
    54                                  _ilgins	equ 33
    55                                  _sleep	equ 34 ; Retro UNIX 8086 v1 feature only !
    56                                  _msg    equ 35 ; Retro UNIX 386 v1 feature only !
    57                                  
    58                                  ;;;
    59                                  ESCKey equ 1Bh
    60                                  EnterKey equ 0Dh
    61                                  
    62                                  %macro sys 1-4
    63                                      ; 03/09/2015
    64                                      ; 13/04/2015
    65                                      ; Retro UNIX 386 v1 system call.
    66                                      %if %0 >= 2   
    67                                          mov ebx, %2
    68                                          %if %0 >= 3    
    69                                              mov ecx, %3
    70                                              %if %0 = 4
    71                                                 mov edx, %4   
    72                                              %endif
    73                                          %endif
    74                                      %endif
    75                                      mov eax, %1
    76                                      int 30h	   
    77                                  %endmacro
    78                                  
    79                                  ; Retro UNIX 386 v1 system call format:
    80                                  ; sys systemcall (eax) <arg1 (ebx)>, <arg2 (ecx)>, <arg3 (edx)>
    81                                  
    82                                  [BITS 32] ; 32-bit intructions for protected mode
    83                                  
    84                                  [ORG 0] 
    85                                  
    86                                  START_CODE:
    87                                  	; clear screen
    88                                  	;
    89                                  	; eax = _stty = 31
    90                                  	; ebx = 0 (/dev/tty? name pointer will not be used)
    91                                  	; ecx = 00FFh 
    92                                  	;     ch = 0 -> clear screen condition 1 
    93                                  	;			     (ch must be 0)
    94                                  	;     cl = 0FFh -> clear console screen
    95                                  	; edx = 0FFFFh
    96                                  	;	clear screen condition 2
    97                                  	;		     (dx must be 0FFFFh
    98                                  
    99                                  	sys	_stty, 0, 00FFh, 0FFFFh
    63                              <1> 
    64                              <1> 
    65                              <1> 
    66                              <1>  %if %0 >= 2
    67 00000000 BB00000000          <1>  mov ebx, %2
    68                              <1>  %if %0 >= 3
    69 00000005 B9FF000000          <1>  mov ecx, %3
    70                              <1>  %if %0 = 4
    71 0000000A BAFFFF0000          <1>  mov edx, %4
    72                              <1>  %endif
    73                              <1>  %endif
    74                              <1>  %endif
    75 0000000F B81F000000          <1>  mov eax, %1
    76 00000014 CD30                <1>  int 30h
   100                                  
   101                                  	sys	_exit
    63                              <1> 
    64                              <1> 
    65                              <1> 
    66                              <1>  %if %0 >= 2
    67                              <1>  mov ebx, %2
    68                              <1>  %if %0 >= 3
    69                              <1>  mov ecx, %3
    70                              <1>  %if %0 = 4
    71                              <1>  mov edx, %4
    72                              <1>  %endif
    73                              <1>  %endif
    74                              <1>  %endif
    75 00000016 B801000000          <1>  mov eax, %1
    76 0000001B CD30                <1>  int 30h
   102                                  
   103                                  here:
   104 0000001D EBFE                    	jmp	here
