comparison vdp.c @ 323:8c01b4154480

Properly mask sprite X and Y coordinates
author Mike Pavone <pavone@retrodev.com>
date Sat, 11 May 2013 23:59:20 -0700
parents 8e2fa485c0f2
children 1b00258b1f29
comparison
equal deleted inserted replaced
322:8e2fa485c0f2 323:8c01b4154480
74 do { 74 do {
75 uint16_t address = current_index * 8 + sat_address; 75 uint16_t address = current_index * 8 + sat_address;
76 uint8_t height = ((context->vdpmem[address+2] & 0x3) + 1) * 8; 76 uint8_t height = ((context->vdpmem[address+2] & 0x3) + 1) * 8;
77 uint8_t width = (((context->vdpmem[address+2] >> 2) & 0x3) + 1) * 8; 77 uint8_t width = (((context->vdpmem[address+2] >> 2) & 0x3) + 1) * 8;
78 int16_t y = ((context->vdpmem[address] & 0x3) << 8 | context->vdpmem[address+1]) & 0x1FF; 78 int16_t y = ((context->vdpmem[address] & 0x3) << 8 | context->vdpmem[address+1]) & 0x1FF;
79 int16_t x = ((context->vdpmem[address+ 2] & 0x3) << 8 | context->vdpmem[address + 3]) & 0x1FF; 79 int16_t x = ((context->vdpmem[address+ 6] & 0x3) << 8 | context->vdpmem[address + 7]) & 0x1FF;
80 uint16_t link = context->vdpmem[address+3] & 0x7F; 80 uint16_t link = context->vdpmem[address+3] & 0x7F;
81 printf("Sprite %d: X=%d, Y=%d, Width=%u, Height=%u, Link=%u\n", current_index, x, y, width, height, link); 81 uint8_t pal = context->vdpmem[address + 4] >> 5 & 0x3;
82 uint8_t pri = context->vdpmem[address + 4] >> 7;
83 uint16_t pattern = ((context->vdpmem[address + 4] << 8 | context->vdpmem[address + 5]) & 0x7FF) << 5;
84 //printf("Sprite %d: X=%d(%d), Y=%d(%d), Width=%u, Height=%u, Link=%u, Pal=%u, Pri=%u, Pat=%X\n", current_index, x, x-128, y, y-128, width, height, link, pal, pri, pattern);
82 current_index = link; 85 current_index = link;
83 count++; 86 count++;
84 } while (current_index != 0 && count < 80); 87 } while (current_index != 0 && count < 80);
85 } 88 }
86 89
101 } 104 }
102 //TODO: Read from SAT cache rather than from VRAM 105 //TODO: Read from SAT cache rather than from VRAM
103 uint16_t sat_address = (context->regs[REG_SAT] & 0x7F) << 9; 106 uint16_t sat_address = (context->regs[REG_SAT] & 0x7F) << 9;
104 uint16_t address = context->sprite_index * 8 + sat_address; 107 uint16_t address = context->sprite_index * 8 + sat_address;
105 line += 128; 108 line += 128;
106 uint16_t y = ((context->vdpmem[address] & 0x3) << 8 | context->vdpmem[address+1]); 109 uint16_t y = ((context->vdpmem[address] & 0x3) << 8 | context->vdpmem[address+1]) & 0x1FF;
107 uint8_t height = ((context->vdpmem[address+2] & 0x3) + 1) * 8; 110 uint8_t height = ((context->vdpmem[address+2] & 0x3) + 1) * 8;
108 //printf("Sprite %d | y: %d, height: %d\n", context->sprite_index, y, height); 111 //printf("Sprite %d | y: %d, height: %d\n", context->sprite_index, y, height);
109 if (y <= line && line < (y + height)) { 112 if (y <= line && line < (y + height)) {
110 //printf("Sprite %d at y: %d with height %d is on line %d\n", context->sprite_index, y, height, line); 113 //printf("Sprite %d at y: %d with height %d is on line %d\n", context->sprite_index, y, height, line);
111 context->sprite_info_list[--(context->slot_counter)].size = context->vdpmem[address+2]; 114 context->sprite_info_list[--(context->slot_counter)].size = context->vdpmem[address+2];
114 } 117 }
115 context->sprite_index = context->vdpmem[address+3] & 0x7F; 118 context->sprite_index = context->vdpmem[address+3] & 0x7F;
116 if (context->sprite_index && context->slot_counter) 119 if (context->sprite_index && context->slot_counter)
117 { 120 {
118 address = context->sprite_index * 8 + sat_address; 121 address = context->sprite_index * 8 + sat_address;
119 y = ((context->vdpmem[address] & 0x3) << 8 | context->vdpmem[address+1]); 122 y = ((context->vdpmem[address] & 0x3) << 8 | context->vdpmem[address+1]) & 0x1FF;
120 height = ((context->vdpmem[address+2] & 0x3) + 1) * 8; 123 height = ((context->vdpmem[address+2] & 0x3) + 1) * 8;
124 //printf("Sprite %d | y: %d, height: %d\n", context->sprite_index, y, height);
121 if (y <= line && line < (y + height)) { 125 if (y <= line && line < (y + height)) {
122 //printf("Sprite %d at y: %d with height %d is on line %d\n", context->sprite_index, y, height, line); 126 //printf("Sprite %d at y: %d with height %d is on line %d\n", context->sprite_index, y, height, line);
123 context->sprite_info_list[--(context->slot_counter)].size = context->vdpmem[address+2]; 127 context->sprite_info_list[--(context->slot_counter)].size = context->vdpmem[address+2];
124 context->sprite_info_list[context->slot_counter].index = context->sprite_index; 128 context->sprite_info_list[context->slot_counter].index = context->sprite_index;
125 context->sprite_info_list[context->slot_counter].y = y-128; 129 context->sprite_info_list[context->slot_counter].y = y-128;
147 row = (context->sprite_info_list[context->cur_slot].y + height - 1) - line; 151 row = (context->sprite_info_list[context->cur_slot].y + height - 1) - line;
148 } else { 152 } else {
149 row = line-context->sprite_info_list[context->cur_slot].y; 153 row = line-context->sprite_info_list[context->cur_slot].y;
150 } 154 }
151 uint16_t address = ((tileinfo & 0x7FF) << 5) + row * 4; 155 uint16_t address = ((tileinfo & 0x7FF) << 5) + row * 4;
152 int16_t x = ((context->vdpmem[att_addr+ 2] & 0x3) << 8) | context->vdpmem[att_addr + 3]; 156 int16_t x = ((context->vdpmem[att_addr+ 2] & 0x3) << 8 | context->vdpmem[att_addr + 3]) & 0x1FF;
153 if (x) { 157 if (x) {
154 context->flags |= FLAG_CAN_MASK; 158 context->flags |= FLAG_CAN_MASK;
155 } else if(context->flags & (FLAG_CAN_MASK | FLAG_DOT_OFLOW)) { 159 } else if(context->flags & (FLAG_CAN_MASK | FLAG_DOT_OFLOW)) {
156 context->flags |= FLAG_MASKED; 160 context->flags |= FLAG_MASKED;
157 } 161 }