Difference between revisions of "Snippet:Plot"

From veswiki
Jump to: navigation, search
(Coordinate-Adjusted Version)
(Coordinate-Adjusted Version)
Line 3: Line 3:
 
== Coordinate-Adjusted Version ==  
 
== Coordinate-Adjusted Version ==  
  
The following is the annotated source, with adjustments for the coordinates:
+
The following is the annotated source, with adjustments for the coordinates.
 +
Routine takes 69 machine cycles including pi and pop instructions.
  
  
Line 35: Line 36:
  
 
; transfer data to the screen memory by toggling ARM
 
; transfer data to the screen memory by toggling ARM
li $60 ; %01100000, block controller input, set ARM to 1
+
lis 6
outs 0
+
sl 4
li $50 ; %01010000, block controller input, ARM = 0, bit 5 (which is N/C) is set to 1...
+
outs 0 ; %01100000, no controller inputs, set b5 ARM to 1
outs 0
+
sl 1
 +
outs 0 ; %11000000, no controller inputs, b5 ARM = 0, b7 (N/C) is set to 1
  
 
; delay until it's fully updated
 
; delay until it's fully updated

Revision as of 15:43, 31 May 2020

The plot subroutine takes a coordinate and a color, and plots it on the screen. The code was originally taken from Lights Out. Plotting individual pixels is slower than blitting an image to VRAM at once, but is useful in some applications. There are two versions here: the original version, and a coordinate-adjusted version to make programming easier.

Coordinate-Adjusted Version

The following is the annotated source, with adjustments for the coordinates. Routine takes 69 machine cycles including pi and pop instructions.


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

; plot out a single point on the screen
; uses three registers as "arguments"
; r1 = color $00 = green, $40 = %01000000 = red, $80 = %10000000 = blue, $C0 = %11000000 = background
; r2 = x (to screen) (0-101)
; r3 = y (to screen) (0-57)

plot:
	; set the color using r1
	lr	A, 1
	outs	1					; Color is set by bit 6 and 7 only

	; set the column using r2
	lis	4
	as	2					; adjust the x coordinate
	com
	outs	4					; place inverted coordinate for x on port 4 (bit 7 not used)

	; set the row using r3
	lis	4
	as	3					; adjust the y coordinate
	com
	outs	5					; place inverted coordinate for y on port 5 (bit 6, 7 not used, those are for sound)

	; transfer data to the screen memory by toggling ARM
	lis	6
	sl	4
	outs	0					; %01100000, no controller inputs, set b5 ARM to 1
	sl	1
	outs	0					; %11000000, no controller inputs, b5 ARM = 0, b7 (N/C) is set to 1

	; delay until it's fully updated
	lis	6					; Value here is 4 in Videocart 21, Bowling
.plotDelay:	
	ai	$ff
	bnz	.plotDelay

	pop						; return from the subroutine

The adjustment of x and y is to allow the coordinates 0, 0 to access the upper-left pixel of the screen (at least in MESS, for real it may be better or worse). VRAM in the Channel F actually expands four pixels above and to the left of that pixel. If you need a quicker plotting function, you can sacrifice this convenience and use the original version.

Original Version

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

; plot out a single point on the screen
; uses three registers as "arguments"
; r1 = color
; r2 = x (to screen) (4-105)
; r3 = y (to screen) (4-61)

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

	; set the column using r2
	lr	A, 2
	com
	outs	4

	; set the row using r3
	lr	A, 3
	com
	outs	5

	; transfer data to the screen memory
	li	$60
	outs	0
	li	$50
	outs	0

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

	pop							; return from the subroutine