366: Systems Level Programming ================================ Low-level programming targeting DOS and x86 hardware, including device drivers and real-mode assembly. Topics ------ - x86 real-mode assembly (NASM/MASM) - DOS interrupt services (INT 21h, INT 10h) - Device driver architecture (block and character drivers) - Video memory-mapped I/O - Keyboard and timer interrupt handling Projects -------- Missile Command Game (``366/src/rocks.asm``) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ A "Missile Command"-style arcade game written entirely in x86 assembly. Uses INT 10h for video mode switching and direct VGA frame-buffer writes to animate missiles and explosions in real time. .. code-block:: nasm MAX_ROCKS equ 5 ; maximum rocks on screen at a time NEW_ROCK_CHANCE equ 10 TAU equ 8 ; controls fall speed (4=fast, 12=slow) ROCK_MAX_Y equ 20 TIMER_INT equ 1ch TIMER_INT_LOCATION equ 4*TIMER_INT ; A rock record (struct): x, y, active flag, momentum upper_left_x equ 0 ; byte upper_left_y equ 1 ; byte active equ 2 ; byte momentum equ 3 ; byte ROCK_SIZE equ 4 ; Hook the timer interrupt to drive game animation mov ax, 3500h + TIMER_INT ; DOS get interrupt vector int 21h mov [old_timer_seg], es mov [old_timer_off], bx DOS Block Device Driver (``366/src/blkdrv.asm``) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ A dummy block device driver implemented as a DOS ``.SYS`` file. Demonstrates the DOS device driver header structure, strategy/interrupt routines, and the request packet protocol used by the DOS kernel to communicate with drivers. .. code-block:: nasm ; DOS device driver header code segment assume cs:code dw -1 ; link to next driver (-1 = end of chain) dw -1 dw 2000h ; attribute word (block device) dw offset str ; strategy routine offset dw offset int ; interrupt routine offset db 3 ; number of units (block devices) db 7 dup (?) ; reserved for DOS int: cmp byte ptr es:[bx+2], 0 ; only Init command supported je init mov word ptr es:[bx+3], 8102h ; return "device not ready" jmp exit