File: display4.S

package info (click to toggle)
lilo 1%3A22.2-3
  • links: PTS
  • area: main
  • in suites: woody
  • size: 1,780 kB
  • ctags: 2,725
  • sloc: asm: 8,355; ansic: 7,864; sh: 1,054; perl: 755; makefile: 365
file content (842 lines) | stat: -rw-r--r-- 14,016 bytes parent folder | download
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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
;  display4.S is
;
;  Copyright 2001 John Coffman.
;  All rights reserved.
;
;  Licensed under the terms contained in the file 'COPYING' in the 
;  source directory.
;
;
;
;	Static Name Aliases
;
;;        segment _TEXT PARA class=CODE
	.text


	.align	8

_bmp:   dd      0
_tp:    dd      0
_state: dw    -1
_Mode:  dw      0
_ypitch: dw     0






;
;       get a single byte in AX (zero extended)
;       and increment the HUGE pointer _tp
;
;       c = *tp++;
;
;
        .align   8
getbyte:
        lodsb
        push    ax
        cmp     si,#1
        sbb     ax,ax
        and     ax,#0x1000
	add     bp,ax
        mov     ds,bp
        pop     ax
        sub     ah,ah
        ret


        .align   4

d4_getrow4:
        pusha
        push    ds

;	rpt = -8                ; bh
;	repeat = -10            ; bl
;	skip = -12              ; dh
;	lp = -4                 ; es:di
;	c = -6
;	npix = DX               ; cx
;	compr = AX
;       tp was _tp              ; ds:si -- HUGE ptr  [bp:si]
	mov	di,#_line	;lp
        push    cs
        pop     es
	seg	cs
          lds     si,[_tp]        ;
        mov     cx,dx           ;npix
	cmp	ax,#1	        ;compr
        mov     bp,ds           ;
	ja	d4_I600
        je      d4_I601
d4_FC581:
        call    getbyte
        push    ax
	sar	ax,#4
        stosb                   ;*lp++
        pop     ax
	dec	cx	;npix
	and	al,#15	;000fH
        stosb                   ;*lp++
	loop	d4_FC581
        jmp     d4_I601
;
; compr == 2
;        
d4_FC590:
	cmp	cx,#0	;npix
	jle	d4_FB591
        call    getbyte
	mov	bh,al   	;rpt
	mov	bl,al   	;repeat
	or	ax,ax
	je	d4_L676
	sub	cx,ax	;npix
        call    getbyte
	jmp	d4_L675
d4_FC594:
        push    ax
	sar	ax,#4
        stosb                   ;*lp++
        pop     ax
	dec	bh	; 2001/06/23
	jz	d4_L676 ; 2001/06/23
        push    ax
	and	al,#15	;000fH
        stosb                   ;*lp++
        pop     ax
	dec	bh	;rpt 2001/06/23
d4_L675:
	or	bh,bh	;rpt
	jne	d4_FC594
d4_L676:
	or	bl,bl   ;repeat
	jne	d4_FC590
d4_FB591:
        jcxz    d4_I600   ;npix
        call    getbyte
	mov	bh,al	;rpt
	sub	cx,ax	;npix
        mov     dh,al
	inc	dh	; 2001/06/23
        and     dh,#2    ;skip
	jmp	d4_L677
d4_FC598:
        call    getbyte
        push    ax
	sar	ax,#4
        stosb                   ;*lp++
        pop     ax
	dec	bh	;rpt 2001/06/23
	jz	d4_L678	; 2001/06/23
	and	al,#15	;000fH
        stosb                   ;*lp++
	dec	bh	;rpt 2001/06/23
d4_L677:
	cmp	bh,#0	;rpt
	jne	d4_FC598
d4_L678:
	or	dh,dh	;skip
	je	d4_I600
        call    getbyte
d4_I600:
	mov	bl,#1	;repeat
	cmp	cx,#0	;npix
	jg	d4_L676
        call    getbyte
        call    getbyte
;;;     jmp     d4_I601

d4_I601:
	seg	cs
          mov     [_tp],si        ;
	seg	cs
	  mov     [_tp+2],ds      ;
        pop     ds
        popa
	ret	


        .align   4
d4_char10:
	enter	#6,#0
        pusha
        push    ds

;	buf =  0xA000:DI
;	cgen =  ES:SI
;	bits =  ax on top of stack
;	points	(bp-2)
;	shadow  (bp-4)
;	mask	(bp-6)

;	sch     (bp+4)  (arg);  DS:BX
;	y =     BX	(arg)
;	x =     DX	(arg)
;	c =     AX	(arg)

        push    WORD #0
        pop     ds
        mov	cx,WORD [0x485] ;points
	xor	ah,ah           ;AL is char to put out
	mov	WORD (bp-2),cx	;points
#ifdef LCF_M386
	imul	ax,cx           ;leave DX alone; 386 form of instruction
#else
	push	dx
	imul	cx		;8086 form of instruction
	pop	dx
#endif
	mov	si,#268	;010cH	; int 0x43 -> character bitmaps
        add	ax,WORD (si)
        mov	es,WORD (si+2)  ;cgen
        xchg    si,ax           ;cgen

;  call pixadr -----------------------------------
	mov	cx,dx		;x
	and	cx,#7		;mask for shift
	sar	dx,#3		;x
	mov	ax,#0x00FF	;mask

        imul    di,bx,#640/8	; DI = y * _ypitch
	ror	ax,cl		;AL is mask, AH is hi-mask
	add	di,dx		; + x
	mov	WORD (bp-6),ax	;save mask
;-------------------------------------------------
	mov	WORD (bp-4),#0	;shadow
        mov     dx,#0x03CE      ;
	lds	bx,(bp+4)	;sch
d4_FC527:
        seg	es
	  lodsb           ;cgen -> bits
        push    es
	sub	ah,ah
        push    WORD #0xA000
	ror	ax,cl	;rotated bits in AX
        pop     es
	push	ax	;save AX rotated bits

	not	ax
	and	ax,WORD (bp-6)	;mask complement
	push	ax

        mov	ah,BYTE (bx+2)	;sch->bg
        cmp	BYTE (bx),ah	;sch->fg
	pop	ax		; inserted ****
	je	d4_I529

	push	ax		;AH = bits high; AL = bits low
	mov	ah,al		;AH = bits low
	mov	al,#08
        out     dx,ax
	mov	ah,BYTE (bx+2)	;sch->bg
        seg	es
	  and	BYTE (di),ah    ;buf
	pop	ax		; get complemented bits back
	jcxz	d4_I529

	mov	al,#08		;AH = ~bits hi, AL = 8
        out     dx,ax
	mov	al,BYTE (bx+2)	;sch->bg
        seg	es
	  and	BYTE (di+1),al    ;buf
	
d4_I529:	; rotated bits in the stack
        mov	al,BYTE (bx+4)	;sch->sh
        cmp	BYTE (bx),al	;sch->fg
	je	d4_I530
	mov	ax,WORD (bp-4)	;get shadow
	rol	ax,#7		;	
	push	ax
	mov	al,#8
        out     dx,ax
	mov	ah,BYTE (bx+4)	;sch->sh
        seg	es
	  and	BYTE (di),ah
	pop	ax
	jcxz	d4_I530

	xchg	ah,al
	mov	al,#8
        out     dx,ax
	mov	ah,BYTE (bx+4)	;sch->sh
        seg	es
	  and	BYTE (di+1),ah
	
d4_I530:
	pop	ax		;rotated bits
	mov	WORD (bp-4),ax	; save shadow

	push	ax
	mov	ah,al
	mov	al,#8
        out     dx,ax
        mov	al,BYTE (bx)	;sch->fg
        seg	es
	  and	BYTE (di),al
	pop	ax
	jcxz	d4_I531

	mov	al,#8
        out     dx,ax
        mov	al,BYTE (bx)	;sch->fg
        seg	es
	  and	BYTE (di+1),al

d4_I531:
        add     di,#640/8        ;buf
        pop     es
        dec     WORD (bp-2)
        jne     d4_FC527

d4_EX519:
        pop     ds
        popa
	leave
	ret	


        .align   4
_text:
        push    bp
        mov     bp,sp
        push    ds

;	sch = 14
;	len = 12
;	cp = 8
;	ypos = 6
;	xpos = 4
        mov     ax,#2
	call	d4_setstate
	mov	cx,WORD (bp+12)	;len
	mov     bx,WORD (bp+6)	;ypos
	mov     dx,WORD (bp+4)	;xpos
#ifndef PIXADDRESS
        shl     bx,#4            ;ypos
        shl     dx,#3            ;xpos
#endif
	lds	si,(bp+8)	;cp
        jcxz    d4_L672
	push	WORD (bp+16)
	push	WORD (bp+14)	;sch
d4_FC544:
        lodsb                   ;*cp
        call	d4_char10
	add	dx,#8	;xpos
	loop	d4_FC544
	add	sp,#4
d4_L672:
        xor     ax,ax
	call	d4_setstate
        pop     ds
	leave	
	ret	

#if 0
        .align   4

_setpalette:
	push	bp
	mov	bp,sp
;	blue = 10
;	green = 8
;	red = 6
;	color = 4

	push	bx
	mov	bh,bl
        mov     ax,#0x1000
        int     0x10

	mov	bx,#0x3fff	;00ffH
	mov	al,dh
	mul	bh
	div	bl
	mov	dh,al
	xor	dl,dl

	mov	al,ch
	mul	bh
	div	bl
	mov	ch,al

	mov	al,cl
	mul	bh
	div	bl
	mov	cl,al

	pop	bx		;color
        mov     ax,#0x1010
        int     0x10
	leave	
	ret	
#endif


        .align   4
d4_putrow4:
        pusha
        push    ds

;	mask = -2
;	lp = -6
;	tp = -10
;	vp = -14
;	vvp = -18
;	i = -20
;	nn = -22
;	x2 = 8
;	x1 = 6          ; DX
;	y = 4           ; AX
        push    ax      ;y
        push    dx      ;x2-x1+1

;begin pack4
	push	ds
        pop     es
        mov     si,#_line
	mov	di,si	;op = lp
        mov     ah,#640/8        ; npix/8
d4_FC185:
	mov	cx,#8
d4_F187:
	seg	es
	  lodsb
        shr     al,#1
        rcl     bl,#1    ;a
	shr	al,#1
        rcl     bh,#1    ;b
	shr	al,#1
        rcl     dl,#1    ;c
	shr	al,#1
        rcl     dh,#1    ;d
	loop	d4_F187
	mov	al,bl	;a
        stosb
	mov	al,bh	;b
        stosb
	mov	al,dl	;c
        stosb
	mov	al,dh	;d
        stosb
        dec     ah
        jne	d4_FC185
d4_EX175:
; end pack4

        pop     bx
	sar	bx,#3            ;nn
        pop     di              ;y
;;	imul	WORD [_ypitch]
        imul    di,#640/8
        push    WORD #0xA000
        pop     es
	mov	si,#_line	;lp
        mov     ax,#0x0102       ;mask
d4_FC563:
	mov     dx,#964	;03c4H
        out     dx,ax
        push    di
        push    si
        mov     cx,bx           ;nn
        push    ax                      ;mask
d4_FC566:
        lodsb
	seg	es
	  and	BYTE (di),al
	add	si,#3	;tp
	inc	di	;vp
	loop	d4_FC566

        pop     ax              ;mask
        pop     si
        pop     di
        shl     ah,#1
	inc	si      	;lp
	test	ah,#15	        ;000fH
	jne	d4_FC563

        pop     ds
        popa
	ret	

        .align   4
d4_setstate:
        push    ds

        push    cs
        pop     ds
#if 0
	pusha
	call	wout
	call	ss1
	.ascii	" = AX; setstate entered"
	.byte	10,0
ss1:	pop	bx
	call	say
;;	call	pause
	popa
#endif

;	new = 4
	mov     dx,#974	;03ceH
	cmp	ax,WORD [_state]
	je	d4_SB497
	mov	WORD [_state],ax
	dec	ax
	je	d4_SC502
	dec	ax
	je	d4_SC503

; state 0
        push    dx
	mov     ax,#3842	;0f02H
	mov     dx,#964	;03c4H
        out     dx,ax

        pop     dx
	mov     ax,#5    ;0005H
        out     dx,ax

	mov     ax,#3847	;0f07H
        jmp     d4_L669

; state 1
d4_SC502:
	mov     ax,#2053	;0805H
        jmp     d4_L670

;  state 2
d4_SC503:
	mov     ax,#2565	;0a05H
d4_L670:
        out     dx,ax
	mov     ax,#7
d4_L669:
        out     dx,ax
	mov     ax,#3
        out     dx,ax
	mov     ax,#-248	;ff08H
        out     dx,ax
d4_SB497:
#if 0
	pusha
	call	ss2
	.ascii	"setstate exit"
	.byte	10,0
ss2:	pop	bx
	call	say
;;	call	pause
	popa
#endif
        pop     ds
	ret	

        .align   4
;
;  _display4:	display the BITMAP
;
;  Enter with:	ES:BX points to the possible bitmap image
;		DS==CS
;
;  Exit with:
;	Carry Clear	- bitmap was displayed
;	AX = 0
;
;	Carry Set	- error occurred
;	AX = 1		"BM" signature not found
;	AX = 2		not VGA adapter or display
;	AX = 3		not 640x480x16 bitmap
;
_display4:
; Line 286
	enter	#22,#0
	push	si
	push	di

;	bits = -2
;	colors = -6
;	i = -8
;	disable = -10
;	color = -14
;	bmfh = -18
;	bmh = -22
;	name = 4
; Line 296
	mov	WORD [_bmp],bx	;store for later
	mov	WORD [_bmp+2],es
;;;	les	bx,[_bmp]
	mov	WORD (bp-18),bx	;bmfh
	mov	WORD (bp-16),es
	seg	es
	  cmp	WORD (bx),#19778	;4d42H
	jne	d4_I573
	seg	es
	  cmp	WORD (bx+14+2),#0	; hi-order part of DWORD
	jne	d4_I573
	seg	es
	  cmp	WORD (bx+14),#40	; Windows/OS2 bitmap header
	je	d4_I574
	seg	es
	  cmp	WORD (bx+14),#12	; OS2 bitmap header
	je	d4_I574
; Line 297
d4_I573:
        mov     ax,#1
        stc
	br	_display4_ret

d4_I574:
	mov	ax,WORD [_bmp]
	mov	dx,WORD [_bmp+2]
	add	ax,#14	;000eH
;;	sbb	cx,cx
;;	and	cx,#0x1000
;;	add	dx,cx
	mov	WORD [_tp],ax
	mov	WORD [_tp+2],dx
	mov	WORD (bp-22),ax	;bmh
	mov	WORD (bp-20),dx
; Line 302
	mov	es,dx
	mov	bx,ax
	seg	es
	  cmp	BYTE (bx),#40		; Windows
	je	d4_I575

;  OS2 bitmaps
	seg	es
	  mov	ax,WORD (bx+8)
        seg	es
	  mul	WORD (bx+10)
	mov	WORD (bp-2),ax	;bits
; Line 305
	mov	cx,ax
	mov	ax,#1
	shl	ax,cl
	cwd	
	mov	WORD (bp-6),ax	;colors
; Line 317
	cmp	cx,#4	;bits
	jne	d4_I576
	seg	es
	  cmp	WORD (bx+4),#640	;0280H
	jne	d4_I576
	seg	es
	  cmp	WORD (bx+6),#480	;01e0H
	jne	d4_I576
	jmp	d4_I575a

; Windows/OS2 bitmaps
d4_I575:
	seg	es
	  mov	ax,WORD (bx+12)
        seg	es
	  mul	WORD (bx+14)
	mov	WORD (bp-2),ax	;bits
; Line 305
	mov	cx,ax
	mov	ax,#1
	shl	ax,cl
	cwd	
	mov	WORD (bp-6),ax	;colors
; Line 317
	cmp	cx,#4	;bits
	jne	d4_I576
	seg	es
;;;	  cmp	DWORD (bx+4),#640	;0280H
	  cmp	WORD (bx+4),#640	;0280H
	jne	d4_I576
	seg	es
;;;	  cmp	DWORD (bx+8),#480	;01e0H
	  cmp	WORD (bx+8),#480	;01e0H
	jne	d4_I576
d4_I575a:
	mov	WORD [_Mode],#18	;0012H
;;	mov	cx,#8
;;	cwd	
;;	idiv	cx
;;	mov	WORD [_ypitch],ax
; Line 318
	jmp	d4_I577
d4_I576:
; Line 319
        mov     ax,#3
        stc
	br	_display4_ret
; Line 321
d4_I577:
; Line 322
; Line 323
	mov     bx,#0
	mov     ax,#6656	;1a00H
        int     0x10
	cmp	al,#26	;001aH
	jne	d4_I578
	cmp	bl,#7
	je	d4_I579
	cmp	bl,#8
	je	d4_I579
d4_I578:
        mov     ax,#2
        stc
	br	_display4_ret
; Line 324
d4_I579:
	mov     bx,#49	;0031H
	mov     ax,#4609	;1201H
        int     0x10
; Line 325
	mov	WORD (bp-10),#128	;0080H	;disable
; Line 326
	mov	ax,WORD [_Mode]
	or	al,#128	;0080H
        int     0x10
; Line 327
        mov     dx,#480/16
        mov     bx,#0
        mov     ax,#0x1124               ;set for 8x16 characters
        int     0x10
; Line 331
	cmp	WORD (bp-10),#0	;disable
	je	d4_I580
	mov     bx,#54	;0036H
	mov     ax,#4609	;1201H
        int     0x10
; Line 333
d4_I580:
	les	bx,(bp-22)	;bmh
	seg	es
	  mov	si,WORD (bx)
	add	si,WORD [_tp]

	push	ds

	mov	ds,WORD [_tp+2]
; Line 334
	xor	bx,bx		;i
d4_FC582:
; Line 335
	push	bx
	mov	bh,bl
        mov     ax,#0x1000
        int     0x10

	mov	bx,#0x3fff	;00ffH

	lodsb
	mul	bh
	div	bl
	mov	cl,al

	lodsb
	mul	bh
	div	bl
	mov	ch,al

	lodsb
	mul	bh
	div	bl
	mov	dh,al
	xor	dl,dl

	pop	bx		;color = i
        mov     ax,#0x1010
        int     0x10

; Line 336
	mov	di,(bp-22)	;bmh
	  cmp	BYTE (di),#12
	je	d4_F580
	inc	si
d4_F580:
; Line 337
	inc	bx	;WORD (bp-8)	;i
d4_F581:
	cmp	WORD (bp-6),bx	;colors
	jg	d4_FC582

	pop	ds

; Line 339
	les	bx,(bp-18)	;bmfh
	seg	es
	  mov	ax,WORD (bx+10)
	seg	es
	  mov	dx,WORD (bx+12)
	add	ax,WORD [_bmp]
	adc	dx,#0
	shl	dx,#12
	add	dx,WORD [_bmp+2]
	mov	WORD [_tp],ax
	mov	WORD [_tp+2],dx
; Line 340
        xor     ax,ax
	call	d4_setstate
; Line 341
        mov     ax,#1
	call	d4_setstate
; Line 342
	les	bx,(bp-22)	;bmh
;;	seg	es
;;	  mov	ax,WORD (bx+8)		; 480
	mov	ax,#480			; Windows or OS2
;;	seg	es
;;	  mov	dx,WORD (bx+4)		; 640
	mov	dx,#640			; Windows or OS2
	seg	es
	  cmp	BYTE (bx),#13		; OS2
	sbb	cx,cx			; OS2 = -1, Win = 0
	not	cx
	seg	es
	  and	cx,WORD (bx+16)		; compression

	mov	bx,cx			; compression to BX
d4_FC586:
	dec	ax
        js      d4_FC587
; Line 343
        xchg    ax,bx
	call	d4_getrow4
; Line 344
        xchg    ax,bx
	call	d4_putrow4
; Line 345
	jmp	d4_FC586
d4_FC587:
; Line 346
	mov	ax,#2			;set for character display
	call	d4_setstate
; Line 348
	mov     bx,#54	;0036H          ;enable refresh
	mov     ax,#4608	;1200H
        int     0x10

        xor     ax,ax           ;clears the carry
_display4_ret:
	pop	di
	pop	si
	leave	
	ret	

        .align   4
_done4:
	xor	ax,ax
	call	d4_setstate	;restore state
; Line 356
; enable default palette loading
	mov     bx,#49	;0031H
	mov     ax,#4608	;1200H
        int     0x10
; Line 357
	mov     ax,#0x0003       ; set video mode
        int     0x10
; Line 359
	ret