Im trying to add mode 9 support in my emulation layer for the snakes game.
Specifically where is the color data embedded? Is it the first byte in each sequence?
Ive read over the wiki docs and I understand what the idea is behind it, but for the actual details on the raw data is formed I think is missing. I tried do a compare between the font demo and the snakes data. The first line for tile 0 has the same data for both app's except for the first word in 6 sections.
So im sure this tells me where each pixel section is located:
0xf,0xef,0x08,0xb9,0x19,0x91, 0xf,0xef,0x08,0xb9,0x15,0x9f
0x0,0xe0,0x08,0xb9,0x19,0x91, 0x0,0xe0,0x08,0xb9,0x15,0x9f
Since the color should be different I suspect its encoded in these first 2 bytes. But what I find strange is each pixel can be 3 or 4 words, the pattern is 334443. Without disassembly the raw hex im also not sure why theres a difference.
Video Mode 9 tile format
Re: Video Mode 9 tile format
The instruction 0xeN0M means "ldi r16, NM", so the pixel data is in byte 0 and byte 1. The pattern for the other instructions is different because you have to calculate the next tile address, this is done step by step interleaved with handling each pixel. The data is sent to the port with the 0xb908 (out PORTC,r16) instruction, *these* instructions have to be equidistant (by means of cycles, not instruction code count) to avoid video distortion. In contrast, when the pixel data is loaded is irrelevant.
Janka
Janka
Re: Video Mode 9 tile format
like Janka said, Some opcodes like mul (0x9f15) and ld (0x9119) take 2 cycles to execute.Pickle wrote:But what I find strange is each pixel can be 3 or 4 words, the pattern is 334443.
The exact format is documented in gconvert.cpp
Code: Select all
ldi r16, pixel1 ; ?1 e? ; 1 cycle
out 0x08, r16 ; 08 b9 ; 1 cycle
ld r17, Y+ ; 19 91 ; 2 cycles
ldi r16, pixel2 ; ?1 e? ; 1 cycle
out 0x08, r16 ; 08 b9 ; 1 cycle
mul r17, r21 ; 15 9f ; 2 cycles
ldi r16, pixel3 ; ?1 e? ; 1 cycle
out 0x08, r16 ; 08 b9 ; 1 cycle
add r0, r24 ; 08 0e ; 1 cycle
adc r1, r25 ; 19 1e ; 1 cycle
ldi r16, pixel4 ; ?1 e? ; 1 cycle
out 0x08, r16 ; 08 b9 ; 1 cycle
movw r30, r18 ; f9 01 ; 1 cycle
dec r20 ; 4a 95 ; 1 cycle
ldi r16, pixel5 ; ?1 e? ; 1 cycle
out 0x08, r16 ; 08 b9 ; 1 cycle
breq .+2 ; 09 f0 ; 1 cycle or 2 if r20 is 0
movw r30, r0 ; f0 01 ; 1 cycle
ldi r16, pixel6 ; ?1 e? ; 1 cycle
out 0x08, r16 ; 08 b9 ; 1 cycle
ijmp ; 09 94 ; 2 cycles
Re: Video Mode 9 tile format
Awesome it works now Thanks!
Edit: someone with access to the wiki, I think it would benefit this page greatly to have some of these specifics:
http://uzebox.org/wiki/index.php?title=Video_Mode_9
Edit: someone with access to the wiki, I think it would benefit this page greatly to have some of these specifics:
http://uzebox.org/wiki/index.php?title=Video_Mode_9
Re: Video Mode 9 tile format
Didn't even recall I did that, I was about to propose it as a future upgrade!Any of the "ldi r16, pixel" instructions can be replaced with "mov r16, r2" (02 2d) for the ability to change the background color at runtime.
Done! http://uzebox.org/wiki/index.php?title=Video_Mode_9Edit: someone with access to the wiki, I think it would benefit this page greatly to have some of these specifics: