Hey,
This program takes a 400 character, one per line, file and converts it to a color coded picture. Is there any way. Is there anything I can do to tidy this up?
Thanks in advance...
-mallard
This program takes a 400 character, one per line, file and converts it to a color coded picture. Is there any way. Is there anything I can do to tidy this up?
TITLE MASM Template (main.asm)
; Description:
;
; Revision date:
INCLUDE Irvine32.inc
.data
num DWORD ?
;;;;;;;;;;;;;;;;;;;;;;;INSTRUCTIONS;;;;;;;;;;;;;;;;;;;;;;;
; Input: File - 400 numbers, one per line from ;
; the following list (0, 1, 2, 4, 6, 7) ;
; ;
; NOTE: In the line below (filename BYTE "pix.txt",0) ;
; edit pix.txt to the filename you want to input. ;
; ;
; ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
filename BYTE "pix.txt",0
fileHandle DWORD ?
col BYTE 1
row BYTE 1
counter DWORD 0
.code
main PROC
;Open the file
mov edx,OFFSET filename
call OpenInputFile
mov fileHandle,eax
;call writewindowsmsg
top:
mov eax,counter
cmp eax,400
je finish
mov eax,0
mov al,col
cmp al,21
je newrow
back:
;Read a character
mov edx,offset num
mov ecx,1
mov eax,fileHandle
call readfromfile
mov eax,num
cmp eax,48
je blackc
cmp eax,49
je bluec
cmp eax,50
je greenc
cmp eax,52
je redc
cmp eax,54
je yellowc
cmp eax,55
je whitec
here:
;Read a character
mov eax,fileHandle
mov edx,offset num
mov ecx,1
call readfromfile
;Read a character
mov eax,fileHandle
mov edx,offset num
mov ecx,1
call readfromfile
inc counter
jmp top
blackc:
mov dh,row
mov dl,col
call gotoxy
inc col
mov ax,00000000b
call settextcolor
mov al,' '
call writechar
jmp here
bluec:
mov dh,row
mov dl,col
call gotoxy
inc col
mov ax,00010001b
call settextcolor
mov al,' '
call writechar
jmp here
greenc:
mov dh,row
mov dl,col
call gotoxy
inc col
mov ax,10101010b
call settextcolor
mov al,' '
call writechar
jmp here
redc:
mov dh,row
mov dl,col
call gotoxy
inc col
mov ax,11001100b
call settextcolor
mov al,' '
call writechar
jmp here
yellowc:
mov dh,row
mov dl,col
call gotoxy
inc col
mov ax,11101110b
call settextcolor
mov al,' '
call writechar
jmp here
whitec:
mov dh,row
mov dl,col
call gotoxy
inc col
mov ax,11111111b
call settextcolor
mov al,' '
call writechar
jmp here
newrow:
inc row
mov col,1
jmp back
finish:
mov eax,fileHandle
call CloseFile
exit
main ENDP
END main
TITLE First 16-bit Program (main.asm)
; Description:
;
; Revision date:
INCLUDE Irvine16.inc
.data
infile BYTE "pix.txt",0
infp WORD ?
num BYTE 0
counter WORD ?
col BYTE 1
row BYTE 1
.code
main PROC
mov ax,@data
mov ds,ax ;these two lines required for 16-bit programs
; open an input file for reading
mov ah,3dh
mov al,0
mov dx,offset infile
int 21h
jc quit
mov infp,ax
top:
mov ah,02h
mov bh,0
mov dh,row
mov dl,col
int 10h
; read one byte from the file
mov ah,3fh
mov bx,infp
mov cx,1
mov dx,offset num
int 21h
mov ax,0
mov al,col
cmp al,20
je newrow
back:
mov ax,0
mov al,num
cmp al,48
je blackc
cmp al,49
je bluec
cmp al,50
je greenc
cmp al,52
je redc
cmp al,54
je yellowc
cmp al,55
je whitec
blackc:
mov ah,09h
mov al,' '
mov bh,0
mov bl,00000000b
mov cx,1
int 10h
; read one byte from the file
mov ah,3fh
mov bx,infp
mov cx,1
mov dx,offset num
int 21h
; read one byte from the file
mov ah,3fh
mov bx,infp
mov cx,1
mov dx,offset num
int 21h
inc col
mov ax,counter
inc counter
cmp ax,399
jne top
jmp done
bluec:
mov ah,09h
mov al,' '
mov bh,0
mov bl,00010001b
mov cx,1
int 10h
; read one byte from the file
mov ah,3fh
mov bx,infp
mov cx,1
mov dx,offset num
int 21h
; read one byte from the file
mov ah,3fh
mov bx,infp
mov cx,1
mov dx,offset num
int 21h
inc col
mov ax,counter
inc counter
cmp ax,399
jne top
jmp done
greenc:
mov ah,09h
mov al,' '
mov bh,0
mov bl,10101010b
mov cx,1
int 10h
; read one byte from the file
mov ah,3fh
mov bx,infp
mov cx,1
mov dx,offset num
int 21h
; read one byte from the file
mov ah,3fh
mov bx,infp
mov cx,1
mov dx,offset num
int 21h
inc col
mov ax,counter
inc counter
cmp ax,399
jne top
jmp done
redc:
mov ah,09h
mov al,' '
mov bh,0
mov bl,11001100b
mov cx,1
int 10h
; read one byte from the file
mov ah,3fh
mov bx,infp
mov cx,1
mov dx,offset num
int 21h
; read one byte from the file
mov ah,3fh
mov bx,infp
mov cx,1
mov dx,offset num
int 21h
inc col
mov ax,counter
inc counter
cmp ax,399
jne top
jmp done
yellowc:
mov ah,09h
mov al,' '
mov bh,0
mov bl,11101110b
mov cx,1
int 10h
; read one byte from the file
mov ah,3fh
mov bx,infp
mov cx,1
mov dx,offset num
int 21h
; read one byte from the file
mov ah,3fh
mov bx,infp
mov cx,1
mov dx,offset num
int 21h
inc col
mov ax,counter
inc counter
cmp ax,399
jne top
jmp done
whitec:
mov ah,09h
mov al,' '
mov bh,0
mov bl,11111111b
mov cx,1
int 10h
; read one byte from the file
mov ah,3fh
mov bx,infp
mov cx,1
mov dx,offset num
int 21h
; read one byte from the file
mov ah,3fh
mov bx,infp
mov cx,1
mov dx,offset num
int 21h
inc col
mov ax,counter
inc counter
cmp ax,399
jne top
jmp done
;makes new row, sets col to 0
newrow:
inc row
mov col,0
jmp back
done:
;close the file
;mov ah,3eh
;mov bx,infp
;int 21h
;jc quit
quit:
mov ah,2
mov dl,'-'
;int 21h
call crlf
mov ah,4ch ; terminate process
mov al,0 ; return code
int 21h
main ENDP
END main
Thanks in advance...
-mallard