Rasterbar Copperbar line short code

Last Updated or created 2023-10-05

Not interesting for most of you, but here is the minimal code to display a line using toggling the background color at a specific retrace.

https://www.henriaanstoot.nl/2023/09/12/copperbar-effect-with-image-on-80×86/

3C8h (R/W):  DAC Address Write Mode
 bit 0-7  The color data register (0..255) to be written to 3C9h.
 Note: After writing the 3 bytes at 3C9h this register will increment, pointing to the next data register.

3C9h (R/W):  DAC Data Register
 bit 0-8?  Color value
 Note:  Each read or write of this register will cycle through first the
        registers for Red, Blue and Green, then increment the appropriate
        address register, thus the entire palette can be loaded by writing 0 to
        the DAC Address Write Mode register 3C8h and then writing all 768 bytes
        of the palette to this register.

3DAh
Input Status #1 Register (Read at 3BAh (mono) or 3DAh (color))
7	6	5	4	3	2	1	0
                            VRetrace			DD
 
VRetrace -- Vertical Retrace
"When set to 1, this bit indicates that the display is in a vertical retrace interval.This bit can be programmed, through the Vertical Retrace End register, to generate an interrupt at the start of the vertical retrace."
DD -- Display Disabled
"When set to 1, this bit indicates a horizontal or vertical retrace interval. This bit is the real-time status of the inverted 'display enable' signal. Programs have used this status bit to restrict screen updates to the inactive display intervals in order to reduce screen flicker. The video subsystem is designed to eliminate this software requirement; screen updates may be made at any time without screen degradation."

Code (fasm)

use16
org 0x100

INPUT_STATUS = 0x03DA

start:

; set mode 320x200 256 colors palette
	mov ah,0x0
	mov al,13h
	int 10h

; press key to exit
waitforkeyloop:
	call effect 	; Calling the effect
	MOV AH,1
	INT 16h
	JZ waitforkeyloop
	XOR AH,AH
	INT 16h
Exit:
	MOV AX,3	; default text mode 3
	INT 10h
	MOV AX,4C00h	; exit to dos (terminate process)
	INT 21h

effect:
	cli		; stop interrupts
	call waitvretrace	; wait for vertical retrace
	mov al, 0    ; set color index 0 to black (needs to be converted to a function
	mov dx, 3c8h
	out dx, al
	inc dx       ; now 3c9h
	mov al, 0h
	out dx, al   ; set R = 0
	mov al, 0h
	out dx, al   ; set G = 0
	mov al, 0h
	out dx, al   ; set B = 0

	mov al,30h

; al = scanline, call wait for scanline
	call waithretrace
	mov al, 0    ; set color index 0 to white
	mov dx, 3c8h
	out dx, al
	inc dx       
	mov al, 255
	out dx, al   
	mov al, 255
	out dx, al   
	mov al, 255
	out dx, al   

; wait 1 scanlines (height of bar)
	mov al,1h
	call waithretrace

; draw black again
	mov al, 0    ; set color index 0's rgb value
	mov dx, 3c8h
	out dx, al
	inc dx       ; now 3c9h
	mov al, 0
	out dx, al   
	out dx, al   
	out dx, al   
		
	sti	; start interrupts again
	ret

; this waits for vertical retrace
waitvretrace:
	mov dx,INPUT_STATUS
waitv1:
	in al,dx
	test al,8
	jnz waitv1
waitv2:
	in al,dx
	test al,8
	jz waitv2
	ret

; routine that waits for horizontal retrace
; al sets number of retraces
waithretrace:
	mov cl,al
	mov dx,INPUT_STATUS
waith1:
	in al,dx
	test al,1
	jnz waith1
waith2:
	in al,dx
	test al,1
	jz waith2
	dec cl
	cmp cl,0
	jnz waith1
	ret

My bash file to copy com file to floppy image to use in PCem.

PCem right button disk change drive A:

fasm one-line.asm
# disk.img is een msdos boot floppy image
sudo mount -o loop disk.img mountpoint
sudo cp *com mountpoint/
sudo cp *bmp mountpoint/
sudo umount mountpoint
Spread the love

Leave a Reply

Your email address will not be published. Required fields are marked *