flat assembler
Message board for the users of flat assembler.

Index > DOS > help with a console program

Author
Thread Post new topic Reply to topic
zbenjudah



Joined: 11 Aug 2004
Posts: 17
zbenjudah 11 Dec 2004, 05:06
I was wondering if there was some one who could tell me another way of implementing this code i got it from another post about writeing color to the console and i have modified it slightly please forgive the
(crudity and the laimness) I am not a very good fasm programer, but it gets the idea accross. I do not know another way to do it in fasm assembler,
I have done it in C and seen tasm code but it is not the same. anyway here is the code that I wish to work as I am sure there is a better way of iplementing it. what i am looking for is useing this as a tutorial example of templet or boiler plate code for a generic console interface for dos. again this is hijacked code but I think that it is a good idea and i do thank the
guys who worked on this it is a fairly good piece of work. anyone with some suggestions would be quite welcome i would also like to place this in the examples list as I think it would be a very good piece of generic type code so that beginners could be able to see a fully implemplimented program
if implemented correctly

Code:
;-- ---------------------------------------------------------------


ORG 100H 
USE16 

TX = 80 


; Some color names to use instead of raw numbers 
BLACK         = 0 
BLUE          = 1 
GREEN         = 2 
PURPLE        = 3 
RED           = 4 
CYAN          = 5 
BROWN         = 6 
WHITE         = 7 
GREY          = 8 
BRIGHTBLUE    = 9 
BRIGHTGREEN   = 10 
BRIGHTPURPLE  = 11 
BRIGHTRED     = 12 
BRIGHTCYAN    = 13 
BRIGHTBROWN   = 14 
BRIGHTWHITE   = 15 

;------------------ 
; define procedure. 
;------------------ 

macro proc name,[arg] { 
common 
  if used name 
  name: 
  virtual at bp+6 
    if ~ arg eq 
      forward 
        local ..arg 
        ..arg dw ? 
        arg equ ..arg 
      common 
    end if 
    ..ret = $ - (bp+6) 
  end virtual 
  local ..dynamic_data, ..dynamic_size 

  dynamic_data equ ..dynamic_data 
  dynamic_size equ ..dynamic_size 

  virtual at bp - dynamic_size 
    dynamic_data: 
} 

;------------------------------ 
; begin procedure instructions. 
;------------------------------ 

macro begin { 
    dynamic_size = $ - dynamic_data 
  end virtual 
   enter dynamic_size,0 
} 

;----------------------- 
; Return from procedure. 
;----------------------- 

macro endp 
{ leave 
   if ..ret = 0 
     retf 
   else 
     retf ..ret 
   end if 
  end if        ; for "used" check in proc macro 
} 

;---------------- 
; Call procedure. 
;---------------- 

macro callhere proc,[arg] 
{ 
    if ~ arg eq 
      reverse 
        push arg 
    end if 
   common 
    call proc 
} 


;---------------------------------------- 
; Make far call in the same code segment. 
;---------------------------------------- 

macro callp proc,[arg] { 
    if ~ arg eq 
      reverse 
        push arg 
    end if 
   common 
    push cs 
    call proc 
} 


push cs 
pop ds 

mov ax,03h 
int 10h 


mov    ax,3
        int     10h     
    mov     ah,1
        mov     ch,20h
      int     10h             
    mov     ax,1003h
    xor     bx,bx
       int     10h             


;#####################################################################
;callp WriteStr,30,20,BLUE,BRIGHTBROWN,mm 
callp WriteStr,0,1,BLUE,BRIGHTWHITE,mm 
callp WriteStr,0,25,15,BRIGHTRED,mmm ;

;#####################################################################


xor ax,ax 
int 16h 

int 20h 

proc WriteStr,x,y,b,f,msg 
     begin 
        push  $B800 
        pop   es 

        mov   ax, [msg] 
        mov   si, ax 

        mov   ax, [y]       
        dec   ax            
        mov   cx, 80        
        mul   cx            ;
        add   ax, [x]       ; 
                            ; 
        ;mov   cx, 2        ;
        ;mul   cx           
        shl   ax, 1         

        mov   di, ax 

        mov   ah, byte [b]  
        mov   al, byte [f]  ; 
        shl   ah, 4         
        or    ah, al        ; 

        mov   al, byte [si] 
      Continue: 
        stosw 
        inc si 
        mov al, byte [si] 
        or  al,   0 
        jnz Continue 
     endp 


mm db '                                                                                ',0 
mmm db '                                                                                ',0    
Post 11 Dec 2004, 05:06
View user's profile Send private message Reply with quote
Matrix



Joined: 04 Sep 2004
Posts: 1166
Location: Overflow
Matrix 11 Dec 2004, 05:41
Hello,
i think its a nice example you posted using and implementing stack procedures,

i used to do it this way if i can ( due to limited number of registers )
Code:
org $100
mainloop:

mov cx,1
call scroll80x25down ; CX = lines to scroll ( must be valid )

mov dx,press_key
xor bx,bx
mov cl,15
call writestring80x25 ; DX = address of string bl=x bh=y cl=color , 0 terminated

call breadkey
push ax

mov dh,15
mov dx,ax
xor bx,bx
mov bl,12
mov ch,15
call writehexword80x25 ; DL = byte input bl=x bh=y ch=color ( writes 2 nibbles from input )

mov dx,ascii_txt
mov cl,15
xor bx,bx
mov bl,18
call writestring80x25 ; DX = address of string bl=x bh=y cl=color , 0 terminated

pop ax
push ax

mov dl,ah
mov dh,15
xor bx,bx
mov bl,24
call write80x25 ; DL = Char to write DH = Color bl=x bh=y , returns: AX = DX, DI = offset
pop ax
push ax

mov dl,al
mov dh,15
xor bx,bx
mov bl,25
call write80x25 ; DL = Char to write DH = Color bl=x bh=y , returns: AX = DX, DI = offset

pop ax
cmp al,27
jne mainloop
mov dx,esc_key
mov cl,15
xor bx,bx
mov bl,30
call writestring80x25 ; DX = address of string bl=x bh=y cl=color , 0 terminated
int 20h

esc_key db 'Escape pressed',0
press_key db 'Press a key',0
ascii_txt db 'ascii',$3e,'  ',$3c,0

write80x25: ; DL = Char to write DH = Color bl=x bh=y , returns: AX = DX, DI = offset
push es
mov ax,$b800
mov es,ax

xor ax,ax
xchg al,bh   ;  mov ax,80
mov di,ax    ;  mul bh
shl di,2     ;  xor bh,bh
add di,ax    ;  add ax,bx
shl di,4     ;  shl ax,1
add di,bx    ;  mov di,ax
shl di,1

mov ax,dx
stosw
pop es
ret

writestring80x25: ; DX = address of string bl=x bh=y cl=color , 0 terminated string !
push es
mov ax,$b800
mov es,ax
mov si,dx

xor ax,ax
xchg al,bh   ;  mov ax,80
mov di,ax    ;  mul bh
shl di,2     ;  xor bh,bh
add di,ax    ;  add ax,bx
shl di,4     ;  shl ax,1
add di,bx    ;  mov di,ax
shl di,1

mov ah,cl
again:
lodsb
cmp al,0
je ext2
stosw
jmp again
ext2:
pop es
ret

writehexword80x25: ; DX = 16 bit input bl=x bh=y ch=color ( writes 4 nibbles from input )
push es             ; does not remove leading zeroes
mov ax,$b800
mov es,ax
xor ax,ax
xchg al,bh
mov di,ax
shl di,2
add di,ax
shl di,4
add di,bx
shl di,1
mov cl,4
.roll1:
rol dx,4
mov al,dl
and al,$f
cmp al,10
sbb al,69h
das
mov ah,ch
stosw
dec cl
jnz .roll1
pop es
ret

scroll80x25down: ; CX = lines to scroll ( must be valid )
push es
push ds
std
mov ax,$b800
mov ds,ax
mov es,ax
mov di,4000
mov ax,cx
shl ax,2
add ax,cx
shl ax,5
mov si,di
sub si,ax
mov dx,ax
mov ax,25
sub ax,cx
mov cx,ax
shl ax,2
add ax,cx
shl ax,3
xor ecx,ecx
mov cx,ax
inc cx
rep movsd
mov eax,$07200720
mov cx,dx
shr cx,2
rep stosd
cld
pop ds
pop es
ret

breadkey:  ;biosreadkey returns ax
mov ah,$10
int $16
ret
    
Post 11 Dec 2004, 05:41
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.