Category : BASIC Source Code
Archive   : PSETMA.ZIP
Filename : CPIXADDR.ASM
NAME CGAPixelAddr
;
; Name: CGAPixelAddr
;
; Function: Determine buffer address of pixel in 640x200 2-color mode
;
; Caller: AX = y-coordinate (0-199)
; BX = x-coordinate (0-639)
;
; Returns: AH = bit mask
; BX = byte offset in buffer
; CL = number of bits to shift left
; ES = video buffer segment
;
OriginOffset EQU 0 ; byte offset of (0,0)
VideoBufferSeg EQU 0B800h
CGAParams SEGMENT byte public 'CODE'
ASSUME cs:CGAParams
PUBLIC CGAPixelAddr
CGAPixelAddr PROC near
mov cl,bl ; CL := low-order byte of x
xchg ah,al ; AX := 100h * y
shr bx,1 ; BX := x/2
shr ax,1 ; AL := 80h*(y&1)
add bh,al ; BX := x/2 + 8000h*(y&1)
xor al,al ; AX := 100h*(y/2)
add bx,ax ; BX := x/2 + 8000h*(y&1) + 100h*(y/2)
shr ax,1
shr ax,1 ; AX := 40h*(y/2)
add bx,ax ; BX := x/2 + 8000h*(y&1) + 140h*(y/2)
shr bx,1
shr bx,1 ; BX := x/8 + 2000h*(y&1) + 50h*(y/2)
add bx,OriginOffset ; BX := byte offset in video buffer
mov ax,VideoBufferSeg
mov es,ax ; ES:BX := byte address of pixel
and cl,7 ; CL := x & 7
xor cl,7 ; CL := number of bits to shift left
mov ah,1 ; AH := unshifted bit mask
ret
CGAPixelAddr ENDP
CGAParams ENDS
END
Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!
This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.
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/