-
Notifications
You must be signed in to change notification settings - Fork 25
/
lightpen3.asm
143 lines (121 loc) · 2.15 KB
/
lightpen3.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
%include "../../defaults_bin.asm"
initCGA 9, 6, 2
clear:
; Clear screen to white
mov ax,0xb800
mov es,ax
mov ds,ax
mov ax,0x0fdb
mov cx,80*100
xor di,di
cld
rep stosw
; Draw 15 3x13 coloured blocks (aspect ratio is 3*8*5 : 6*2*6 = 5 : 3) on the right for the palette
mov di,77*2+1
mov cx,15
colourLoop:
push cx
mov al,16
sub al,cl
mov cx,6
yLoop:
stosb
inc di
stosb
inc di
stosb
add di,77*2+1
loop yLoop
pop cx
loop colourLoop
; Draw an "all colours" palette entry (10 rows high, aspect ratio of each block is 8*5 : 2*2*6 = 5:3
mov byte[di],1
mov byte[di+2],2
mov byte[di+4],3
mov byte[di+160],1
mov byte[di+162],2
mov byte[di+164],3
mov byte[di+320],4
mov byte[di+322],5
mov byte[di+324],6
mov byte[di+480],4
mov byte[di+482],5
mov byte[di+484],6
mov byte[di+640],7
mov byte[di+642],8
mov byte[di+644],9
mov byte[di+800],7
mov byte[di+802],8
mov byte[di+804],9
mov byte[di+960],10
mov byte[di+962],11
mov byte[di+964],12
mov byte[di+1120],10
mov byte[di+1122],11
mov byte[di+1124],12
mov byte[di+1280],13
mov byte[di+1282],14
mov byte[di+1284],15
mov byte[di+1440],13
mov byte[di+1442],14
mov byte[di+1444],15
mov si,4
loopTop:
; Wait for strobe
mov dx,0x3da
waitLoop:
in al,dx
test al,2
jz waitLoop
; Read light pen position:
mov dl,0xd4
mov al,0x10
out dx,al
inc dx
in al,dx
mov ah,al
dec dx
mov al,0x11
out dx,al
inc dx
in al,dx ; Light pen character position now in AX
mov bx,ax
add bx,ax ; Multiply by 2 to get memory position (offset from 0xb8000)
inc bx
mov cl,80
div cl
; Now, al = quotient = y position
; ah = remainder = x position
cmp ah,77
jl plot
; Obtain new colour from palette
mov dl,6
mov ah,0
div dl
inc ax
mov si,ax
jmp done
plot:
mov ax,si
cmp al,16
jl normalPlot
; Special colour plot
mov al,byte[bx]
inc al
and al,0x0f
jnz doSpecialPlot
inc al
doSpecialPlot:
mov byte[bx],al
jmp done
normalPlot:
mov byte[bx],al
done:
mov dx,0x3da
waitForVerticalSync
; Reset strobe
inc dx
out dx,al
dec dx
waitForNoVerticalSync
jmp loopTop