Accessing VRAM

From veswiki
Revision as of 11:35, 17 November 2012 by E5frog (talk | contribs)
Jump to: navigation, search

... which means drawing graphics ...

To write data to video ram you have to load the x coordinate to port 4, y coordinate to port 5 and color to port 1 and then execute the transfer by writing to port 0. For compatibility with the first generation of Fairchild Video Entertainment System, especially the 2MHz PAL model, there needs to be a delay after sending the data through before the next pixel is loaded and sent.

Here's an example of the plot code needed to plot one pixel, coordinate (0,0) is top left corner and usually not visible on screen.

;---------------;
; Plot Function ;
;---------------;

; plot out a single point on the screen
; uses three registers as "arguments", load correct data 
; in these registers before making a subroutine call (pi).
; r1 = color
;------------------------
; Valid colors
;------------------------
; red	= $40 (%01000000)
; blue	= $80 (%10000000)
; green	= $00 (%00000000)
; bkg	= $C0 (%11000000)
;------------------------
; r2 = x (0-127)
; r3 = y (0-63)

plot:
	; set the color using r1
	lr	A, 1
	outs	1

	; set the column using r2
	lr	A, 2
	com				; x-coordinate needs to be inverted before it's stored
	outs	4			; loaded to port 4

	; set the row using r3
	lr	A, 3
	com				; y-coordinate needs to be inverted before it's stored
	outs	5			; loaded to port 5

	; transfer data to the screen memory
	; done by sending $60 and then $50 to port 0.
	li	$60
	outs	0
	li	$50
	outs	0

	; delay until it's fully updated
	lis	6
plot.delay:	
	ai	$ff
	bnz	plot.delay

	pop							; return from the subroutine