ECE291 Computer Engineering II Lockwood, Spring 1999

Machine Problem 3: RPN Calculator GUI

Assigned Thursday 3/4/99
Due Date Thursday 3/25/99
Purpose Keyboard and Mouse Interrupts, 
Text-Mode Graphics
Points 50

 

Introduction

End users like a Graphical User Interface (GUI) because it provides them with a simple, easy-to-use, point-and-click interface. Programmers, however, typically prefer designing command line interfaces (CLI's) because their interface can be simpler and can more easily be used both from the keyboard and as a part scripting environment. In the end, though, GUI's are included as a part of all modern software because they are often more intuitive to use than CLI's and reduce the learning curve for the end-user of the application.

In MP2 you implemented a stack-based RPN calculator with a simple CLI. In MP3, you will start with the same three procedures from MP2 (ProcessInput, Calculate, and FormatOutput) and implement a GUI around them.  The new interface will accept both the keyboard commands from MP3 as well as commands created by pressing "buttons" on the graphical display.

Problem Description

For this machine problem, you will implement a graphical user interface for the RPN Calculator of MP2.
A screen dump of the running program is shown below:

Using the GUI, the calulation of 6+27 can be computed by:

The best way to understand how the MP works is to run it,.
Hit [Q] then [ENTER] to quit.

Major Features

Full-Screen Text-mode Video

The graphics for the GUI will be implemented using 40x25 text-mode video. For maximum speed, your code will write directly to video memory (beginning at address B8000h).  Each character block on the screen represents an ASCII character and its corresponding attributes.  The attributes include the foreground color,  background color, and whether the character blinks or not.  Text-mode video is discussed in lecture 12.  The 40x25 mode operates exactly like the 80x25 mode, except that there are only half as many characters in each row.

Since specifying the graphics yourself would be tedious, a 'skin' has been written as a single byte-array (calcskin) that contains an ASCII "image" of the calculator. This skin is stored in a separate data file called calcskin.dat.  Feel free to change the variable textattr, in order to vary the color scheme of your calculator. The color shown in the screendump has blue text on a white background.

Interrupt Service Routines

In MP2, we used LIB291's kbdine to read data from the keyboard. Calling this function causes your computer to poll the default keyboard handler until a key is read into the DOS keyboard buffer.

But what if you wanted to do something else while waiting for a keyboard input. Suppose, for example, you also wanted to read from a mouse at the same time you were waiting for input from the keyboard. You could not do this with blocking I/O.

The use of customized interrupt service routines (interrupt handlers) allows the program to handle asynchronous I/O. With asynchronous I/O, the program is able to do other things while waiting for data from one particular input.  In this MP you are required to watch for inputs from both the keyboard and the mouse at the same time.  By writing a routine for each, triggered only by external device interrupts, this will be possible. 

The subject of ISRs is discussed in lectures 13 through 16.  Read the lecture notes and Chapter 9 in the lab manual for more information.

Implementation

Variables

From MP2 : New for MP3 :

Procedures

For this program, you will write ten procedures and add one feature. You may use the library versions of the three MP2 procedures.

Program Assignment

You will begin this machine problem with a fully functional program. The skeleton file is given below. We have provided the library routines for each of the ten procedures above. You should complete MP3Main first, because the library version (LibMP3Main) will only call other library procedures.  You will score points by replacing the library procedures with your own code. Your score will be proportional to the percentage of the code that you write yourself. The breakdown in points is given below: Your routine MUST perform all functions of the subroutine to obtain credit.

Preliminary Procedure

Final Steps

  1. Download and print the MP3 grading sheet from the web site.
  2. Verify that your program meets all requirements for handin.
  3. Demonstrate MP3.EXE to a TA or to the instructor. Your program must work with all given input. Once approved, you are ready to turn in your program.
  4. Be prepared to answer questions about any aspect of the operation of your program. The TAs will not accept an MP if you cannot fully explain the operation of your code.
  5. Print MP3.ASM using GreenPrint32 and give it to to the same TA which approved your demonstration. Be sure that your name is the printout.
  6. Electrically submit your programs to the TA's handin floppy:

  7. A:\HANDIN MyWindowsLogin

Guidelines / Hints


MP3.ASM

TITLE ECE291:MP3-Calculator GUI - Your Name - Date

COMMENT % A GUI for MP2's RPN Calculator

          ECE291: Machine Problem 3
          Prof. John W. Lockwood
          Guest Author: Josh Scheid
          University of Illinois
          Dept. of Electrical & Computer Engineering
          Spring 1999
          
          Ver. 1.1
        %

;====== Constants =========================================================

;ASCII values for common characters
BEEP    EQU 7
CR      EQU 13
LF      EQU 10
ESCKEY  EQU 27
BSKEY   EQU 8
SEMI    EQU 59
SPACE   EQU 32

;====== Externals =========================================================

; -- LIB291 Routines (Free) ---
extrn dspmsg:near, dspout:near, kbdin:near
extrn rsave:near, rrest:near, binasc:near

; -- LIBMP3 Routines (Your code will replace calls to these functions) ---

extrn LibKbdInstall:near
extrn LibKbdUninstall:near
extrn LibKbdHandler:near

extrn LibMouseInstall:near
extrn LibMouseUninstall:near
extrn LibMouseHandler:near

extrn LibDrawScreen:near
extrn LibWaitForInput:near
extrn LibDisplayResult:near

extrn LibMP3Main:near

extrn MP3XIT:near           ; Exit program with a call to this procedure

; Routines from LIBMP2
extrn LibProcessInput:near
extrn LibCalculate:near
extrn LibFormatOutput:near

;====== Stack ========================================================
stkseg  segment stack                   ; *** STACK SEGMENT ***
        db      64 dup ('STACK   ')     ; 64*8 = 512 Bytes of Stack
stkseg  ends

;====== Begin Code/Data ==============================================
cseg    segment public  'CODE'    ; *** CODE SEGMENT ***
        assume  cs:cseg, ds:cseg, ss:stkseg, es:nothing

;====== Variables ====================================================

inputValid      db  0           ; 0: InputBuffer is not ready
                                ; 1: InputBuffer is ready
                                ;-1: Esc key pressed

oldKbdV         dd  ?           ;far pointer to default keyboard
                                ;  interrupt function

DispMode        dw  10          ; Operate in decimal mode by default


bottomOfStack   dw  0           ; Offset of stack at beginning of program
                                ; Used to calculate current number of 
                                ; operands on the stack
                                
operandsStr     db  'Operands: ','$'                                


OutputBuffer    db 16 dup(?),'$' ; Contains formatted output
                                 ; (Should be terminated with '$')
                                 
MAXBUFLENGTH    EQU 24
InputBuffer     db  MAXBUFLENGTH dup(?),'$' ; Contains one line of user input
BufLength       dw  ?                       ; Actual length of InputBuffer

include calcskin.dat            ; 2000 byte character array to define a
                                ; 40x25 screen

PUBLIC DispMode, InputBuffer, BufLength, OutputBuffer   ; Needed by LIBMP2/3
PUBLIC inputValid, oldKbdV, bottomOfStack, operandsStr  ; Needed by LIBMP3
PUBLIC calcskin                                         ; Needed by LIBMP3

                                   
;====== Procedures ========================================================

KbdInstall PROC NEAR

    ; Your code here
    
KbdInstall ENDP

;------------------------------------------------------------------------

KbdUninstall PROC NEAR

    ; Your code here
    
KbdUninstall ENDP

;------------------------------------------------------------------------

KbdHandler PROC NEAR

    ; Your code here
    
KbdHandler ENDP

;------------------------------------------------------------------------

MouseInstall PROC NEAR

    ; Your code here
    
MouseInstall ENDP

;------------------------------------------------------------------------

MouseUninstall PROC NEAR

    ; Your code here
    
MouseUninstall ENDP

;------------------------------------------------------------------------

MouseHandler PROC NEAR

    ; Your code here

MouseHandler ENDP

;------------------------------------------------------------------------

DrawScreen PROC NEAR

    ; Your code here
   
DrawScreen ENDP

;------------------------------------------------------------------------

WaitForInput PROC NEAR

    ; Your code here
    
WaitForInput ENDP

;------------------------------------------------------------------------

DisplayResult PROC NEAR

    ; Your code here

DisplayResult ENDP

;------------------------------------------------------------------------

MP3Main PROC NEAR

    ; Your code here

MP3Main ENDP

;====== Main Procedure ====================================================

MAIN    PROC    FAR

        MOV     AX, CSEG     ; Use common code and data segment
        MOV     DS, AX

        MOV     AX, 0B800h   ; Use extra segment to access video screen
        MOV     ES, AX

        MOV     AX, 0000h    ; Put display into 40x25 text mode
        INT     10h

        MOV     AH, 01h      ; hide text cursor
        MOV     CX, 2000h
        INT     10h

        CALL    LibMP3Main              ; Replace this call with a call to
                                        ; your MP3Main routine.
                                        ; Add nothing else to MAIN                                       

        ; Start your coding by writing main with all LIB routines
        ;
        ; ---------------- Pseudo-code for main ---------------
        ;
        ; Install Mouse and Keyboard handlers
        ; Draw initial screen
        ; Record initial stack pointer
        ;
        ; Loop {
        ;    Wait for user to finish entering string from keyboard or mouse
        ;     ..
        ;    Process the input text
        ;    Calculate Result
        ;    Format the Output
        ;    Display the result
        ;  }
        ;
        ; Un-install Mouse and Keyboard handlers
        
        CALL    MP3XIT                  ; Exit to DOS

MAIN    ENDP

CSEG    ENDS
        END     MAIN