2

我正在研究一种二进制格式的解压缩算法,它为我的 NES 项目存储屏幕文件。NES 屏幕分辨率为 260x240。我正在创建 2x2 像素格式的元图块。压缩格式将指定哪些 2x2 文件应写入屏幕。

我选择的格式将写为

0000xxxx: right nibble = value of tile 1 - 16
xxxx0000; left nibble  = number of times a tile is written on that row 1 - 16

在上面的示例中,11110001将告诉导入例程写入 tile 1,16 次。

我还没有弄清楚的部分是如何取左半字节并将其转换为十六进制。我遇到的同样问题是取正确的半字节并将其也用作值。

我不确定是否有办法使用按位运算来做到这一点。我需要一种有效的方法来做到这一点。

4

2 回答 2

3

鉴于您在 .A 中的“压缩”(尽管“打包”是一个更好的术语)数据,您应该这样做:

(假设tile_id_to_writewrite_it_this_many_times是您想要解压到的零页面位置。)

lda packed_data,X             ;or however you're iterating through the packed data
and #%00001111                ;strip off top 4 bits; this is what AND dones
sta tile_id_to_write          ;store that somewhere
lda packed_data,X             ;get the original packed data again
lsr                           ;shift right 4 times
lsr 
lsr 
lsr
sta write_it_this_many_times

根据您读取打包数据的方式,您可能会做一些不同于lda packed_data,X. 我很确定lsr将 0 放在最重要的位上。请记住,旋转指令将进位旋转到最高有效位,因此您通常想要执行asllsr移位或乘以/除以 2。

于 2013-08-18T14:13:36.053 回答
2

刚刚想通了:

这样做的方法是执行以下操作:

val = %11110001
LDA #val
AND #%00001111 ; mask left nibble
STA rightn
LDA #val
AND #%11110000 ; mask right nibble
ROR
ROR
ROR
ROR ; rotate high bits 4 times
STA rightn
于 2013-02-10T07:03:22.800 回答