TITLE MASM Week_4						(Wk4.asm)

; Description:
;   This program decrypts an encrypted file and saves the decryption into another file.
;   This program also puts random colored '*' on the screen.

; Author:             Robert Markham
;   Written For:        Westwood College Online: CSPG-360
;   Instructor:         Panos Mastrogiannis
; Date:               29 October 2012 - 4 November 2012
; Revision date:      none

INCLUDE Irvine32.inc
.data
introMsg   BYTE  "Bob Markham - Week 4",0dh,0ah,"CSPG 360 - Panos Mastrogiannis",0dh,0ah,0

inputFile  BYTE  "InputFile.txt",0
outputFile BYTE  "OutputFile.txt",0
fileHandle DWORD ?

BUFFER_SIZE =     5000
fileBuffer  BYTE  BUFFER_SIZE DUP(?)
fileBytes   DWORD ?

xAxisChr    BYTE "-"
yAxisChr    BYTE "|"
pointChr    BYTE "*"

pointx      DWORD 32 DUP (?)
pointy      DWORD 32 DUP (?)

.code
main PROC
	call Clrscr

	mov	 edx,OFFSET introMsg
	call WriteString

; Problem 1a: Open the file "InputFile.txt" and read its contents
  
  mov  edx, OFFSET inputFile
  call OpenInputFile

  mov  fileHandle,  eax
  mov  edx,         OFFSET fileBuffer
  mov  ecx,         BUFFER_SIZE
  call ReadFromFile
  mov  fileBytes,   eax

  mov  eax,         fileHandle
  call CloseFile

; Problem 1b: XOR each byte of the file with 0ffh.

  mov  ecx, fileBytes
xorLoop:
  xor   fileBuffer[ecx], 0ffh
loop xorLoop

; Problem 1c: Print the contents of the decoded string to the console window.

  mov  edx, OFFSET fileBuffer
  call WriteString

; Problem 1d: Print the output to a file "OutputFile.txt".

  mov  edx, OFFSET outputFile
  call CreateOutputFile
  
  mov  edx, OFFSET fileBuffer
  mov  ecx, fileBytes
  call WriteToFile

; Problem 1e: Use a comment in this .asm file to answer the bonus question.

; According to a FAQ website about polar bears, they go into a walking hibernation instead of a true hibernation.
; Pregnant mothers will den for about 3 months.
; http://www.polarbearsinternational.org/about-polar-bears/faqs

  call WaitMsg

; Problem 2: Create 32 random points which have (x, y) co-ordinates.  (-15 <= x <= 14) and (-15 <= y <= 14)

; Problem 2b: Draw the x- and y-axis
;   I'm going to draw this first as to not draw over any plotted points

  call ClrScr

  mov  ecx, 30
  mov  ebx, 15
axisLoop:
  mov  dh, cl
  mov  dl, bl
  call Gotoxy
  mov  al, yAxis
  call WriteChar

  mov  dh, bl
  mov  dl, cl
  call Gotoxy
  mov  al, xAxis
  call WriteChar
loop axisLoop

; Problem 2a: Plot the points in the console screen: Q1--Yellow  Q2--Cyan  Q3--Red  Q4--Green

  mov  ecx, 32
  call Randomize
graphLoop:
  mov  eax, 30               ; Create the x-part
  call RandomRange
  mov  pointx[ecx], eax

  mov  eax, 30               ; Create the y-part
  call RandomRange
  mov  pointy[ecx], eax


loop graphLoop

	call WaitMsg
  exit
main ENDP

END main
