Difference between revisions of "Snippet:Plot"
From veswiki
m (1 revision) |
|
(No difference)
|
Revision as of 23:23, 16 November 2012
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:
;---------------; ; Plot Function ; ;---------------; ; plot out a single point on the screen ; uses three registers as "arguments" ; r1 = color ; r2 = x (to screen) (0-101) ; r3 = y (to screen) (0-57) plot: ; set the color using r1 lr A, 1 outs 1 ; set the column using r2 lis 4 as 2 ; fix the x coordinate com outs 4 ; set the row using r3 lis 4 as 3 ; fix the y coordinate 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
The adjustment of x and y is to allow the coordinates 0, 0 to access the upper-left pixel of the screen. 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