[b]MOJO2 WritePixels - Help![/b]

Monkey Forums/Monkey Programming/[b]MOJO2 WritePixels - Help![/b]

APC(Posted 2016) [#1]
Does anyone knows how WritePixels in MOJO2 stores the data?

I am porting my 8080 Arcade Emulator and for some reason the emulator screen shows the images 4 times! I played around with pitch but no luck. May be it has to do with the way WritePixels stores the data. Here are the images for MOJO

and MOJO2

I played with pitch but no luck, pitch needs to be 244 , the image is 244 x 256.

For comparison below are the MOJO and MOJO2 codes of my CopyScreen, it copies the data from the arcade memory to the image screen of Monkey:
MOJO WritePixels
Method CopyScreen:Int()
		For Local j:Int = 0 Until 224
			Local src:Int = $2400 + (j Shl 5)
			Local dst:Int = (sh - 1) * pitch + j
			For Local i:Int = 0 Until 32
				Local vram:Int = cpu.memory[src] 
				src += 1
				For Local bit:Int = 0 Until 8
					Local color:Int = 0
					If (vram & 1) Then color = $FFFFFFFF
					dp[dst] = color
					dst -= pitch
					vram = vram Shr 1
				Next
			Next
		Next
	
		screen.WritePixels(dp, 0, 0, sw, sh, 0, pitch)
	
		Return 0
	End 

MOJO2 WritePixels
	Method CopyScreen:Int()
		Local rgba:= a * 255 Shl 24 | b * 255 Shl 16 | g * 255 Shl 8 | r * 255
		For Local j:Int = 0 Until 224
			Local src:Int = $2400 + (j Shl 5)
			Local dst:Int = (sh - 1) * pitch + j
			For Local i:Int = 0 Until 32
				Local vram:Int = cpu.memory[src] '& $ff
				src += 1
				For Local bit:Int = 0 Until 8
					'Local color:Int = $FF000000
					a = 1.0; b = 0.0; g = 0.0; r = 0.0
					rgba = a * 255 Shl 24 | b * 255 Shl 16 | g * 255 Shl 8 | r * 255
					If (vram & 1) Then 'color = $FFFFFFFF
					        'dp[dst] = color
						a = 1.0; b = 1.0; g = 1.0; r = 1.0
						rgba = a * 255 Shl 24 | b * 255 Shl 16 | g * 255 Shl 8 | r * 255
					EndIf
					dp.PokeInt(dst, rgba)                    'dp.PokeInt (dst, color)
					dst -= pitch
					vram = vram Shr 1
				Next
			Next
		Next

		screen.WritePixels(0, 0, sw, sh, dp, 0, pitch)
	
		Return 0
	End 



APC(Posted 2016) [#2]
Hi after a while I figured it out.

I found the issue, the MOJO2 DrawPixels DataBuffer has to be 4 times the size compared to the MOJO 1, that is because each pixel requires 4 bytes for color and Alpha - RGBA,
Besides that pitch has to be multiplied by 4.

Field sw:Int = 224
   Field sh:Int = 256
   Field screen:Image
   Field dp:DataBuffer
   
Method Init:Int()
     sw = 224
     sh = 256 
     pitch = sw * 4
     screen = New Image(sw, sh)
     screen.SetHandle(0, 0)
      
     dp = New DataBuffer(sw * sh * 4)
End
   Method CopyScreen:Int()
         Local dst:Int = 0
         For Local j:Int = 0 Until 224
            Local src:Int = $2400 + j Shl 5
            Local dst:Int = j * pitch

            For Local i:Int = 0 Until 32
               Local vram:Int = cpu.memory[src]
               src += 1
               For Local bit:Int = 0 Until 8
                  Local color:Int = 0
                  If (vram & 1) Then color = $FFFFFFFF
                  dp.PokeInt(dst, color)
                  dst += 4
                  vram = vram Shr 1
               Next
            Next
         Next
   
         screen.WritePixels(0, 0, sw, sh, dp, 0, pitch)
         Return 0
   End