Laboratory excercises



Duty hours: Thu. 15.15-16.00, Fri. 12.15-13.00.

Description of BIOS interrupts and MSDOS operating system services: here
Borland C++: here

Exercise 1: Keyboard interrupt, console video memory.

Using Borland C++ 3.1, 16-bit compiler write a C++ program that hooks onto a keyboard interrupt 09h and using a keyboard port 60h checks what keyboard key has been recently pressed and displays it on a console screen. The keyboard interrupt handling routine should read a key Scan Code form the port 60h and convert it to ASCII value in order to display it on the screen. Only the numerical keys should be converted. In case of pressing the other key on the keyboard or depressing a key by the user the space character ' ' should be displayed. In order to display the pressed key on the screen write a single procedure that puts a single character on the console screen in a given horizontal and vertical position by writing it directly to console video memory starting at address 0xB800:0x0000.
Time of realisation: 2 weeks

Exercise 2: System timer interrupt.

Using Borland C++ 3.1, 16-bit compiler write a C++ program that hooks onto a system timer interrupt 08h and scrolls a given text on the screen. Scrolling should take place in the timer interrupt handling routine. To achieve this goal write a single procedure that displays a string of characters on the console screen in a given horizontal and vertical position.
Time of realisation: 1 week

Exercise 3: System timer interrupt, resident clock.

Using Borland C++ 3.1, 16-bit compiler write a C++ program that hooks onto a system timer interrupt 08h and constantly displays a current system time at the chosen corner on the console screen. In order to do that use the previous displaying procedures. To get to know system time use port 70h of the CMOS system timer. Remember to make a conversion form BCD code in which the time is reported to a binary time representation. The program should be resident, i.e. it should stay in system memory after it quits and still be active displaying the system time constantly. Use a keep() C++ routine to make your program resident.
Time of realisation: 1 week

Exercise 4: 8259A interrupt handler interrupt priority setting.

Using Borland C++ 3.1, 16-bit compiler write a C++ program that hooks onto a system timer interrupt 08h and a keyboard 09h interrupts. The main program should perform a loop and check weather some control key is pressed, you may choose '1' and '2' keys for example. When '1' key is pressed the program should use a 0x20 port of 8259A interrupt controller to set the priority of a system timer hardware IRQ0 interrupt to the highest setting. When '2' key is pressed program should use the same port to set IRQ2 keyboard interrupt to the highest one. In order to do that use proper OCW2 word, format of which is given in the Lecture, and send it to 0x20 port of 8259A interrupt controller. Visualize somehow the priority switch between the keyboard and timer interrupts. For example the timer interrupt routine may scroll, as above, some text on the console screen and the keyboard interrupt routine may perform a long idle loop lasting about 1 second. When priorities are switched so that the keyboard has higher priority the timer the text scrolling should be interrupted every time a key is pressed on the keyboard. When priorities are normal, i.e. the timer has the highest priority no side effects would be visible after pressing some keys on the keyboard.
Time of realisation: 1 week

Exercise 5: Graphics.

Using Borland C++ 3.1, 16-bit compiler write a C++ program that reads and displays a bitmap file. For convenience you can use 320x200, 8 bits/pixel bitmaps, which are a part of the materials prepared for this exercise. The program should first switch on VGA graphics mode 13h, which is standard 8-bit/pixel 320x200 graphics mode – it has the same characteristics as bitmaps that will be processed. Then the application should open and read a bitmap file directly to a video memory, which for mode 13h is located at address A000h:0000h (in segment:offset notation). After reading all bitmap pixels into memory the program should set video card's color palette in accordance with the palette declared in bitmap's header. The palette should be set directly by operating on video card's ports – do not utilize ready-to-use BIOS functions to set the card's palette. After setting the palette the bitmap should be visible on video screen. The application should then wait for a user to press any key on the keyboard and after it had been done, switch the screen back to the text mode 03h and exit.

Exemplary program with simple animation is added to the materials – you can freely use it to write your own. There are also two bitmaps – one with a grayscale palette and the other with non-standard color palette which you can use as exemplary images to be red and displayed. There is also a presentation on a bitmap file structure to ease you in making this exercise. Please use Internet materials to manage how to set the video card's palette manually by using only video card's ports.
Time of realisation: 2 weeks
Sample graphic mode application: here
Bitmap file format (presentation): here
Sample images: here,here,here,here

Exercise 6: Simple game.
The main goals of this exercise include learning of basics of low-level programing of Video Graphic Array (VGA) and such devices as mouse, keyboard and sound generator. The students' task include programming of one application chosen from the following list:
- Tetris game,
- Pong game,
- Snake game,
- Arkanoid game
or student's own idea for application.
An application is programmed in high-level programming language. However the graphic mode, mouse (if required), keyboard and sound generator should be programmed at low level using: interrupts, direct access to video memory, memory or configuration/status ports of the mentioned devices.
In option "own idea for application" any program can be implemented granted that it fulfills the above requirements and its algorithm is at least complicated as the algorithms of the remaining programs from the list.
Time of realisation: 3 weeks
Sample of sound generation: here
Sample of mouse handling: here

Lecture handouts



Lecture 1: here
Lecture 2: here
Lecture 3: here
Last update: 09:50 2010-04-15