<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>http://channelf.se/veswiki/index.php?action=history&amp;feed=atom&amp;title=Snippet%3ABlit</id>
		<title>Snippet:Blit - Revision history</title>
		<link rel="self" type="application/atom+xml" href="http://channelf.se/veswiki/index.php?action=history&amp;feed=atom&amp;title=Snippet%3ABlit"/>
		<link rel="alternate" type="text/html" href="http://channelf.se/veswiki/index.php?title=Snippet:Blit&amp;action=history"/>
		<updated>2026-06-13T12:12:57Z</updated>
		<subtitle>Revision history for this page on the wiki</subtitle>
		<generator>MediaWiki 1.28.0</generator>

	<entry>
		<id>http://channelf.se/veswiki/index.php?title=Snippet:Blit&amp;diff=125&amp;oldid=prev</id>
		<title>E5frog: 1 revision</title>
		<link rel="alternate" type="text/html" href="http://channelf.se/veswiki/index.php?title=Snippet:Blit&amp;diff=125&amp;oldid=prev"/>
				<updated>2012-11-16T21:23:42Z</updated>
		
		<summary type="html">&lt;p&gt;1 revision&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr style='vertical-align: top;' lang='en'&gt;
				&lt;td colspan='1' style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan='1' style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;Revision as of 21:23, 16 November 2012&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan='2' style='text-align: center;' lang='en'&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(No difference)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
		<author><name>E5frog</name></author>	</entry>

	<entry>
		<id>http://channelf.se/veswiki/index.php?title=Snippet:Blit&amp;diff=124&amp;oldid=prev</id>
		<title>E5frog at 12:18, 14 August 2007</title>
		<link rel="alternate" type="text/html" href="http://channelf.se/veswiki/index.php?title=Snippet:Blit&amp;diff=124&amp;oldid=prev"/>
				<updated>2007-08-14T12:18:39Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;The '''blit''' subroutine reads a two-color (1 bit per pixel) block of graphics data from ROM and displays it on the screen, using several parameters. It works much in the same way as the drawchar routine except for arbitrarily sized data. The code was originally taken from [[Disassembly:Videocart_26|Videocart 26]] and adapted to be more flexible and reusable.&lt;br /&gt;
&lt;br /&gt;
The routine is separated into two parts, '''blitGraphic''' and '''blit'''. '''blit''' takes parameters in registers r1-r6, and retrieves graphics data from the location DC0 points to. It can be called independently of '''blitGraphic'''. '''blitGraphic''' takes hard-coded parameters from ROM at the address pointed at by DC0 and then calls the '''blit''' routine. When the parameters do not need to be dynamic, storing the parameters in ROM and calling the '''blitGraphic''' routine directly can be more efficient than writing them to the registers and calling '''blit'''.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
;===========;&lt;br /&gt;
; Blit Code ;&lt;br /&gt;
;===========;&lt;br /&gt;
&lt;br /&gt;
;--------------;&lt;br /&gt;
; Blit Graphic ;&lt;br /&gt;
;--------------;&lt;br /&gt;
&lt;br /&gt;
; takes graphic parameters from ROM, stores them in r1-r6, &lt;br /&gt;
; changes the DC and calls the blit function with the parameters&lt;br /&gt;
;&lt;br /&gt;
; modifies: r1-r6, Q, DC&lt;br /&gt;
&lt;br /&gt;
blitGraphic:&lt;br /&gt;
	; load six bytes from the parameters into r0-r5&lt;br /&gt;
	lisu	0&lt;br /&gt;
	lisl	1&lt;br /&gt;
.blitGraphicGetParms:&lt;br /&gt;
	lm   &lt;br /&gt;
	lr	I, A						; store byte and increase ISAR&lt;br /&gt;
	br7	.blitGraphicGetParms				; not finished with the registers, loop&lt;br /&gt;
&lt;br /&gt;
	; load the graphics address&lt;br /&gt;
	lm&lt;br /&gt;
	lr	Qu, A						; into Q&lt;br /&gt;
	lm&lt;br /&gt;
	lr	Ql, A&lt;br /&gt;
	lr	DC, Q						; load it into the DC&lt;br /&gt;
&lt;br /&gt;
	; call the blit function&lt;br /&gt;
	jmp	blit&lt;br /&gt;
&lt;br /&gt;
;---------------;&lt;br /&gt;
; Blit Function ;&lt;br /&gt;
;---------------;&lt;br /&gt;
&lt;br /&gt;
; this function blits a graphic based on parameters set in r1-r6,&lt;br /&gt;
; and the graphic data pointed to by DC0, onto the screen&lt;br /&gt;
; originally from cart 26, modified and annotated&lt;br /&gt;
;&lt;br /&gt;
; modifies: r1-r9, DC&lt;br /&gt;
&lt;br /&gt;
; register reference:&lt;br /&gt;
; -------------------&lt;br /&gt;
; r1 = color 1 (off)&lt;br /&gt;
; r2 = color 2 (on)&lt;br /&gt;
; r3 = x position&lt;br /&gt;
; r4 = y position&lt;br /&gt;
; r5 = width&lt;br /&gt;
; r6 = height (and vertical counter)&lt;br /&gt;
;&lt;br /&gt;
; r7 = horizontal counter&lt;br /&gt;
; r8 = graphics byte&lt;br /&gt;
; r9 = bit counter&lt;br /&gt;
;&lt;br /&gt;
; DC = pointer to graphics&lt;br /&gt;
&lt;br /&gt;
blit:&lt;br /&gt;
	; fix the x coordinate&lt;br /&gt;
	lis	4&lt;br /&gt;
	as	3&lt;br /&gt;
	lr	3, A&lt;br /&gt;
	; fix the y coordinate&lt;br /&gt;
	lis	4&lt;br /&gt;
	as	4&lt;br /&gt;
	lr	4, A&lt;br /&gt;
&lt;br /&gt;
	lis	1&lt;br /&gt;
	lr	9, A						; load #1 into r9 so it'll be reset when we start&lt;br /&gt;
	lr	A, 4						; load the y offset&lt;br /&gt;
	com							; invert it&lt;br /&gt;
.blitRow:&lt;br /&gt;
	outs	5						; load accumulator into port 5 (row)&lt;br /&gt;
&lt;br /&gt;
	; check vertical counter&lt;br /&gt;
	ds	6						; decrease r6 (vertical counter)&lt;br /&gt;
	bnc	.blitExit					; if it rolls over exit&lt;br /&gt;
&lt;br /&gt;
	; load the width into the horizontal counter&lt;br /&gt;
	lr	A, 5&lt;br /&gt;
	lr	7, A&lt;br /&gt;
&lt;br /&gt;
	lr	A, 3						; load the x position&lt;br /&gt;
	com							; complement it&lt;br /&gt;
.blitColumn:&lt;br /&gt;
	outs	4						; use the accumulator as our initial column&lt;br /&gt;
	; check to see if this byte is finished&lt;br /&gt;
	ds	9						; decrease r9 (bit counter)&lt;br /&gt;
	bnz	.blitDrawBit					; if we aren't done with this byte, branch&lt;br /&gt;
&lt;br /&gt;
.blitGetByte:&lt;br /&gt;
	; get the next graphics byte and set related registers&lt;br /&gt;
	lis	8&lt;br /&gt;
	lr	9, A						; load #8 into r9 (bit counter)&lt;br /&gt;
	lm&lt;br /&gt;
	lr	8, A						; load a graphics byte into r8&lt;br /&gt;
&lt;br /&gt;
.blitDrawBit:&lt;br /&gt;
	; shift graphics byte&lt;br /&gt;
	lr	A, 8						; load r8 (graphics byte)&lt;br /&gt;
	as	8						; shift left one (with carry)&lt;br /&gt;
	lr	8, A						; save it&lt;br /&gt;
&lt;br /&gt;
	; check color to use&lt;br /&gt;
	lr	A, 2						; load color 1&lt;br /&gt;
	bc	.blitSavePixel					; if this bit is on, draw the color&lt;br /&gt;
	lr	A, 1						; load color 2&lt;br /&gt;
.blitSavePixel:&lt;br /&gt;
	inc&lt;br /&gt;
	bc	.blitCheckColumn				; branch if the color is &amp;quot;clear&amp;quot;&lt;br /&gt;
	outs	1						; output A in p1 (color)&lt;br /&gt;
&lt;br /&gt;
.blitTransferData:&lt;br /&gt;
	; transfer the pixel data&lt;br /&gt;
	li	$60&lt;br /&gt;
	outs	0&lt;br /&gt;
	li	$c0&lt;br /&gt;
	outs	0&lt;br /&gt;
	; and delay a little bit&lt;br /&gt;
.blitSavePixelDelay:&lt;br /&gt;
	ai	$60						; add 96&lt;br /&gt;
	bnz	.blitSavePixelDelay				; loop if not 0 (small delay)&lt;br /&gt;
&lt;br /&gt;
.blitCheckColumn:&lt;br /&gt;
	ds	7						; decrease r7 (horizontal counter)&lt;br /&gt;
	bz	.blitCheckRow					; if it's 0, branch&lt;br /&gt;
&lt;br /&gt;
	ins	4						; get p4 (column)&lt;br /&gt;
	ai	$ff						; add 1 (complemented)&lt;br /&gt;
	br	.blitColumn					; branch&lt;br /&gt;
&lt;br /&gt;
.blitCheckRow:&lt;br /&gt;
	ins	5						; get p5 (row)&lt;br /&gt;
	ai	$ff						; add 1 (complemented)&lt;br /&gt;
	br	.blitRow					; branch&lt;br /&gt;
&lt;br /&gt;
.blitExit:&lt;br /&gt;
	; return from the subroutine&lt;br /&gt;
	pop&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;em&amp;gt;Note: the adjustment of x and y in '''blit''' are to allow the coodinates 0, 0 to access the upper left pixel &amp;lt;/em&amp;gt;visible to the screen&amp;lt;em&amp;gt;, not to VRAM, which expands four pixels above and to the left of that pixel.&amp;lt;/em&amp;gt;&lt;br /&gt;
&lt;br /&gt;
To call the above functions, you should use:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
	dci	graphic.parameters	; address of parameters&lt;br /&gt;
	pi	blitGraphic&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
for '''blitGraphic''', and:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
	; parameters have been loaded into r1-r6 beforehand&lt;br /&gt;
	dci	graphic.data		; address of graphic data&lt;br /&gt;
	pi	blit&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
for '''blit'''. If you're using parameters stored in ROM, they should be in this order:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
graphic.parameters:&lt;br /&gt;
	.byte	bkg			; color 1&lt;br /&gt;
	.byte	blue			; color 2&lt;br /&gt;
	.byte	4			; x position&lt;br /&gt;
	.byte	18			; y position&lt;br /&gt;
	.byte	$60			; width&lt;br /&gt;
	.byte	$13			; height&lt;br /&gt;
	.word	graphic.data		; address for the graphics&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== See Also ==&lt;br /&gt;
* [[Snippet:Multiblit|Multiblit Subroutine]]&lt;/div&gt;</summary>
		<author><name>E5frog</name></author>	</entry>

	</feed>