Category : C Source Code
Archive   : PCGRAPH.ZIP
Filename : HERCA.ASM

 
Output of file : HERCA.ASM contained in archive : PCGRAPH.ZIP
page 60,132

include dos.mac

SETX

MAX_X equ 720 ; maximum pixel x
MAX_Y equ 348 ; maximum pixel y
PSEG

BEGIN clrgraph
;**
; name clrgraph
;
; synopsis clrgraph(mask);
; int mask; Color-mask used to clear the screen
;
; description Clears the graphics screen (page 1) with a
; user-specified attribute (useally 0 or 0ffffh).
;**
push bp
mov bp, sp
push es
mov dx, 0b800h ; videoram-segment
mov es, dx
xor di, di ; offset zero
cld ; count upward
mov ax, [bp]+X ; load attribute
mov cx, 4000h ; num. words in memory
rep stosw ; clear the page!
pop es
pop bp
ret ; done!
clrgraph endp

BEGIN intoff
;**
; name intoff
;
; synopsis intoff();
;
; description This function switches all interrupts (except NMI)
; off.
;**
cli ; only one instruction!
ret
intoff endp

BEGIN inton
;**
; name inton
;
; synopsis inton();
;
; description This function switches all interrupts (except NMI)
; on.
;**
sti ; only one instruction!
ret
inton endp

BEGIN setpixel
;**
; name setpixel
;
; synopsis setpixel(x, y, color);
; int x, y; coordinate of the pixel
; int color; pixel-color
;
; description This function sets a pixel of color "color" at
; the specified coordinate.
;**
push bp
mov bp, sp
push es
mov ax, 0b800h ; load base adr of page 1
mov es, ax
mov si, [bp]+X ; load x value
mov ax, [bp]+X+2 ; load y value
mov bx, [bp]+X+4 ; load color
cmp si, MAX_X ; x range ok?
jae sexit
cmp ax, MAX_Y ; y range ok?
jae sexit
;
mov cx, ax ; select bank
and cx, 3
mov ch, cl
xor cl, cl
rept 5
shl ch, 1
endm
mov di, cx ; 0000 2000 4000 6000
shr ax, 1 ; drop last two bits
shr ax, 1
shl ax, 1 ; 2
add di, ax ; 2x
shl ax, 1 ; 4
shl ax, 1 ; 8
add di, ax ; 10x
shl ax, 1 ; 16
add di, ax ; 26x
shl ax, 1 ; 32
shl ax, 1 ; 64
add di, ax ; 90x
;
mov ax, si ; displ for x
rept 3
shr ax, 1 ; drop 01234567 bits
endm
add di, ax ; screen byte addr
;
mov ax, bx ; color
mov ah, 01h ; mask value
and al, ah ; 2 colors! => last bit only
mov cx, si ; x value
mov ch, 7 ; 0..7 (bitoffset)
and cl, ch ; last 3 bits only
sub ch, cl ; 7 - last 3 bits
mov cl, ch ; = shift count
shl ax,cl ; shift color and mask
not ah ; keep all other pixels
mov bl, es:[di] ; get screen byte
and bl, ah ; erase this pixel
or bl, al ; new color
mov es: [di],bl ; back to screen memory
sexit: pop es ; done!
pop bp
ret
setpixel endp

BEGIN getpixel
;**
; name getpixel
;
; synopsis color = getpixel(x, y);
; int x, y; coordinate of the pixel
; int color; returned color of that pixel
;
; description This function reads ("gets") the color of a
; specified pixel.
;**
push bp
mov bp, sp
push es
mov ax, 0b800h ; load segment graphic page 1
mov es, ax
mov si, [bp]+X ; load x coordinate
mov ax, [bp]+X+2 ; load y coordinate
cmp si, MAX_X ; x range ok?
jae gexit
cmp ax, MAX_Y ; y range ok?
jae gexit
;
mov cx, ax ; select bank
and cx, 3
mov ch, cl
xor cl, cl
rept 5
shl ch, 1
endm
mov di, cx ; 0000 2000 4000 6000
;
shr ax, 1 ; drop last 2 y bits
shr ax, 1 ; 90 times y/4
shl ax, 1 ; 2
add di, ax ; 2x
shl ax, 1 ; 4
shl ax, 1 ; 8
add di, ax ; 10x
shl ax, 1 ; 16
add di, ax ; 26x
shl ax, 1 ; 32
shl ax, 1 ; 64
add di, ax ; 90x
;
mov ax, si ; displ for x
rept 3 ; drop 01234567 bits
shr ax, 1
endm
add di, ax ; screen byte addr
;
mov cx, si ; x coordinate
mov ch, 7 ; last 3 bit (bitoffset)
mov al, es:[di] ; read byte with pixel
and cl, ch ; 0..7 (bit position in byte)
sub ch, cl ; shift count
mov cl, ch
shr al, cl ; select pixel
and ax, 01 ; mask color off
gexit: pop es ; done, retval in ax!
pop bp
ret
getpixel endp
ENDPS
end


  3 Responses to “Category : C Source Code
Archive   : PCGRAPH.ZIP
Filename : HERCA.ASM

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/