-
Notifications
You must be signed in to change notification settings - Fork 0
/
buffer.asm
117 lines (92 loc) · 2.82 KB
/
buffer.asm
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
bufferA dw ?
bufferB dw ?
; word <si> setVideoBufferSeg(void)
; SI = ptr to error string, null if successful.
setVideoBufferSeg:
push ax
push bx
push es
if _target = target.dos
mov ah, 0x4A ; resize program's memory space to free unused memory
mov bx, ds ; DOS allocates the largest block available for COM executables
push es
mov es, bx
mov bx, 0x1000 ; resize for 64k; 16 bytes per paragraph
int 0x21
pop es
macro errorHandle_malloc _bufferPtr* {
local allOk
jc @f ; no error?
mov word [_bufferPtr], ax
xor si, si ; null si, save segment
jmp .#allOk
@@:
cmp ax, 0x07 ; error code 0x07?
jne @f
mov si, err_mcb
jmp .end
@@:
mov si, err_nomem ; error code 0x08?
jmp .end
.#allOk:
}
mov ah, 0x48 ; allocate memory for bufferA
mov bx, (320*200)/16 ; 16 bytes per paragraph
int 0x21
errorHandle_malloc bufferA ; handle any errors
mov ah, 0x48 ; allocate memory for bufferB
mov bx, (320*200)/16 ; 16 bytes per paragraph
int 0x21
errorHandle_malloc bufferB ; handle any errors
postpone {
err_mcb:
db "Can't allocate video buffer: memory control block destroyed", 0x0D, 0x0A, 0
err_nomem:
db "Can't allocate video buffer: insufficient memory", 0x0D, 0x0A, 0
}
else if _target = target.mikeos
mov ax, ds
add ax, 0x1000
mov word [bufferA], ax
add ax, 0x1000
mov word [bufferB], ax
xor si, si ; no errors thrown by MikeOS version
end if
.end:
pop es
pop bx
pop ax
ret
; word coordToPtr(word x, word y)
coordToPtr:
push bx
push dx
; Move (0,0) origin from top left to bottom left of canvas
mov dx, 199
sub dx, bx
mov bx, ax ; bx = x
mov ax, dx ; ax = newY
mov dx, 320 ; ax = (newY * 320) + x
mul dx
add ax, bx
pop dx
pop bx
ret
; void drawBuffer(word <ds> seg_srcBuffer, word <es> seg_destBuffer)
drawBuffer:
pusha
xor si, si
mov di, si
mov cx, (320*200)/4
rep movsd
popa
ret
; void clearBuffer(word <es> seg_destBuffer)
clearBuffer:
pusha
xor di, di
mov cx, (320*200)/4
xor eax, eax
rep stosd
popa
ret