summaryrefslogtreecommitdiff
path: root/support/lgrind/example/egmasm.asm
blob: b4baa5962cff58112cd1a333216b19f0e721ea03 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
;************************************************
; vgac.asm
; PC VGA graphics control in assembly language
; uses BIOS for keyboard read and setting graphics
; modes, and procedure for setting a VGA pixel
; version for C calling convention :-
;	LARGE model
;	no MAIN entry point
;	assemble only (no link)
;	underscore for C-callable functions
;	don't pop arguments off stack (caller does this)
;
; J Leis
; 24 May 1994
;************************************************

TITLE	vgac.asm - vga assembler program, callable from C
.MODEL	LARGE
.286
.DOSSEG

; stack segment directive
.STACK

; data segment directive
.DATA

; code segment directive
.CODE


_VgaMode	   PROC

    pusha
    mov ah, 0	; function 0 = set video mode
    mov al, 12h ; mode 12 = vga graphics
    int 10h
    popa
    ret

_VgaMode     ENDP


_TextMode   PROC

    pusha
    mov ah, 0	; function 0 = set video
    mov al, 03h ; mode 3 = text
    int 10h
    popa
    ret

_TextMode	   ENDP


_ShowMessage	  PROC

    pusha	; save registers if necessary

    ; call DOS interrupt to display a message
    mov  bx, 01h
    lea	dx, mesg	 ; equivalent to mov dx, OFFSET mesg
    mov  cx, l_mesg
    mov  ah, 040h
    int  021h

    popa
    ret

_ShowMessage	  ENDP


_ReadKey	  PROC

    pusha	; save registers if necessary

    mov ah, 00h	; function 0 - wait for key & read it
    int 16h	; int 16h = keyboard services
    ; al now equals ascii code of key

    popa
    ret

_ReadKey	  ENDP


; setpixel( xc, yc, color )
; stacking order:
;	      memory   near call   far call
;  color      highest	[bp+8]	    [bp+10]
;  y-coord		[bp+6]	    [bp+8]
;  x-coord    lowest	[bp+4]	    [bp+6]
;
_SetPixel	  PROC

    push bp
    mov bp, sp

    pusha	; save registers if necessary

    mov dx, 03CEh		; graphics controller register

    mov ax, 0205h		; write mode 2
    out dx, ax

    mov ax, 0003h		; function
    out dx, ax

    mov ax, 0A000h		; graphics screen segment
    mov es, ax

    mov ax, [bp+8]	       ; get y co-ord
    mov bx, 640/8		; 80 bytes/line
    mul bx
    mov bx, [bp+6]	       ; get x-coord
    mov cl, 3			; divide by 8 bits/byte
    shr bx, cl
    add bx, ax

    mov al, es:[bx]		; dummy write to latch data in screen RAM
    mov cx, [bp+6]	       ; get x-coord
    and cx, 0007h		; get bit mask
    mov al, 07h
    sub al, cl
    mov ah, 80h
    shr ah, cl			 ; shift to bit position
    mov al, 08h			 ; set mask register

    mov dx, 03CEh		 ; dx destroyed by mul
    out dx, ax			 ; write bit mask

    mov cx, [bp+10]; color	 ; write the color value
    mov es:[bx], cl

    popa

    pop bp
    ret 	    ; don't pop args off stack - C does this

_SetPixel	  ENDP

;no  main procedure (main in C)

; end of file
END