-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathdigits.asm
171 lines (141 loc) · 3.52 KB
/
digits.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
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
SEGMENT CODE ; 9
; Clock graphics
; Data:
; 172a hModule
; 1720 HGLOBAL returned by LoadResource
; 16c4 far pointer returned by LockResource
; 16f0-1720 near pointers to digits (length 24)
;
; a18 Color mode
%include "base.inc"
%include "variables.asm"
%include "func.mac"
%include "extern.inc"
%include "windows.inc"
%define DigitWidth 17
%define DigitHeight 23
func FindBitmap
%arg name:word
sub sp,byte +0x2
push word [MainInstance] ; hModule
mov ax,[name] ; lpName
sub dx,dx
push dx
push ax
push dx ; lpType
push byte +0x2 ; RT_BITMAP
call far KERNEL.FindResource ; 1b
endfunc
; 28
; Computes the data size of a 4-bpp bitmap with the given width and height.
func BitmapSize
sub sp,byte +0x2
%arg w:word, h:word
; Compute the stride (size of a row).
; ax = (((w << 2) + 31) & ~24) >> 3
;
; Equivalent to
; ax = ((w + 7) & ~7) >> 1
; or
; ax = (w*4 + 31) / 32 * 4
mov ax,[w]
shl ax,byte 0x2
add ax,0x1f
and al,0xe7
sar ax,byte 0x3
; Multiply by the height.
imul word [h]
endfunc
; 4e
func LoadDigits
sub sp,byte +0x8
push di
push si
push word 200 ; ID of the digits resource
call far FindBitmap ; 60 9:0
add sp,byte +0x2
mov si,ax
push word [MainInstance] ; hModule
push si ; hResInfo
call far KERNEL.LoadResource ; 6f
mov [DigitResourceHandle],ax
or ax,ax
jz .end
push ax ; hResInfo
call far KERNEL.LockResource ; 7c
mov [DigitBitmapData+FarPtr.Off],ax
mov [DigitBitmapData+FarPtr.Seg],dx
push byte DigitHeight ; y dimension of digits
push byte DigitWidth ; x dimension of digits
call far BitmapSize ; 8c 9:28 9:0x28
add sp,byte +0x4
; Store near pointers to digits in DigitPtrArray
mov si,ax
mov di,0x68 ; bitmap header length
mov word [bp-0x4],DigitPtrArray
mov bx,[bp-0x4]
mov dx,si
.loop: ; a3
mov [bx],di
add di,dx
add bx,byte +0x2
cmp bx,DigitPtrArray.end
jb .loop
mov ax,0x1
.end: ; b3
pop si
pop di
endfunc
; bc
func FreeDigits
sub sp,byte +0x2
cmp word [DigitResourceHandle],byte +0x0
jz .null
push word [DigitResourceHandle]
call far KERNEL.GlobalUnlock ; d4
push word [DigitResourceHandle]
call far KERNEL.FreeResource ; dd
.null: ; e2
endfunc
; ea
func DrawDigit
sub sp,byte +0x4
%arg hdc:word, xDest:word, yDest:word, digit:word, color:word
%define colorOffset (bp-4)
cmp word [color],byte +0x0
jnz .label3
cmp word [ColorMode],byte +0x1
jz .label3
mov word [colorOffset],0x0
jmp short .label4
nop
.label3: ; 10c
mov word [colorOffset],0xc
.label4: ; 111
; http://msdn.microsoft.com/en-us/library/dd162974%28v=vs.85%29.aspx
push word [hdc] ; HDC
push word [xDest] ; XDest
push word [yDest] ; YDest
push byte DigitWidth; Width
push byte DigitHeight;Height
push byte 0 ; XSrc
push byte 0 ; YSrc
push byte 0 ; uStartScan
push byte DigitHeight;cScanLines
mov bx,[digit]
add bx,[colorOffset]
shl bx,1
mov ax,[DigitPtrArray+bx]
add ax,[DigitBitmapData+FarPtr.Off]
mov dx,[DigitBitmapData+FarPtr.Seg]
push dx ; lpvBits
push ax
push dx ; lpbmi
push word [DigitBitmapData]
push byte +0x0 ; fuColorUse
call far GDI.SetDIBitsToDevice ; 143
endfunc
; 150
GLOBAL _segment_9_size
_segment_9_size equ $ - $$
; vim: syntax=nasm