void msx_set_char_form(int c, void* form, unsigned int place) { unsigned int addr = c; addr <<= 3; if (place & place_1) msx_vwrite_direct(form, addr, 8); if (place & place_2) msx_vwrite_direct(form, (256 * 8) + addr, 8); if (place & place_3) msx_vwrite_direct(form, (256 * 8 * 2) + addr, 8); }
void msx_set_char_attr(char c, void *attr, unsigned char place) { unsigned int addr = c; addr <<= 3; addr += MODE2_ATTR; if (place & place_1) msx_vwrite_direct(attr, addr, 8); if (place & place_2) msx_vwrite_direct(attr, (256 * 8) + addr, 8); if (place & place_3) msx_vwrite_direct(attr, (256 * 8 * 2) + addr, 8); }
void msx_blit_ram_vram(unsigned char* source, unsigned int dest, unsigned char w, unsigned char h, int sjmp, int djmp) { while (h--) { msx_vwrite_direct(source, dest, w); source += sjmp; dest += djmp; } }
void main() { //buf = (u_char*)malloc(MODE2_MAX); double m_pi; double a; int c, i; surface_t surf; point_t p[MAX_POINT]; printf("calculating, wait...\n"); m_pi = 8.0 * atan(1.0); // calculates points from circunference for (c = 0; c < MAX_POINT; c++) { a = (m_pi * (double)c) / (double)MAX_POINT; p[c].x = (int)(100.0 * cos(a) + 128.0); p[c].y = (int)(80.0 * sin(a) + 96.0); } // clear the off-screen surface printf("clearing buffer...\n"); memset(buf, 0, MODE2_MAX); printf("drawing...\n"); surf.data.ram = buf; // draw the eye's lines into the surface (obs: we are NOT in graphic mode yet) for (c = 0; c < MAX_POINT; c++) for (i = c+1; i < MAX_POINT; i++) surface_line(&surf, p[c].x, p[c].y, p[i].x, p[i].y); surface_circle(&surf, 128, 96, 50, 1); // set screen to graphic mode set_color(15, 1, 1); set_mode(mode_2); fill(MODE2_ATTR, 0xF1, MODE2_MAX); // finally show the surface msx_vwrite_direct(surf.data.ram, 0, MODE2_MAX); while (!get_trigger(0)) {} set_mode(mode_0); }
void poner_texto_tiles(unsigned char *texto, unsigned int size, unsigned int posicion, unsigned char color) { unsigned char i = 0; while (size) { if (texto[i] == ' ') { msx_vfill((posicion << 3), 0x00, 8); } else { msx_vwrite_direct(letras_tiles01 + ((*(texto + i) - 65) << 3), posicion << 3, 8); } size--; } }
main() { int c, l; unsigned char i; surface_t surf; //buf = (u_char*)malloc(MODE2_MAX); surf.data.ram = buf; set_color(15, 1, 1); set_mode(mode_2); fill(MODE2_ATTR, 0x31, MODE2_MAX); c = 0; //i = 0; // paint polygon for (;;) { memset(buf, 0, MODE2_MAX); // yeah... crap stencil_init(stencil); // calculate polygon //calculate_side stencil_add_side(128 + c, c + 20, 40, 180 - c, stencil); stencil_add_side(128 + c, c + 20, 255 - c, 96, stencil); stencil_add_side(255 - c, 96, 40, 180 - c, stencil); c = (c + 4) & 63; i = (c + 15) /6-2; surface_stencil_render(&surf, stencil, i); msx_vwrite_direct(surf.data.ram, 0, MODE2_MAX); if (get_trigger(0)) break; } set_mode(mode_0); }
void msx_set_sprite_16(unsigned int handle, void* data) { msx_vwrite_direct(data, 0x3800 + (handle << 5), 32); }
main() { bool flat = false; //int *low, *high; vector_t light; surface_t screen; // this is a vector buffer, for the transformations // our only object have 5 vertexes, but we'll make space for 32 anyway vector_t *pbuffer; // off-screen surface buffer //u_char* sbuffer = (u_char*)malloc(MODE2_MAX); // our solid :) object_t triangle; heapinit (HPSIZE); pbuffer = newa(vector_t, 32); triangle.mesh = build_mesh(); triangle.rot_x = triangle.rot_y = triangle.rot_z = 0; triangle.trans_x = triangle.trans_y = 0; triangle.trans_z = i2f(30); // remember: we are using fixed-point numbers screen.data.ram = sbuffer; // polygon rendering buffers //low = newa(int, MODE2_HEIGHT); //high = newa(int, MODE2_HEIGHT); // light source light.x = light.y = light.z = i2f(1); vector_normalize(&light, &light); printf("spinning solid demo\n\n"); printf("instructions:\n press [UP] to toggle flat shading\n\n"); printf("creating look-up tables, please wait\n"); create_lookup_tables(); // set screen to graphic mode set_color(15, 1, 1); set_mode(mode_2); fill(MODE2_ATTR, 0xF1, MODE2_MAX); //surface_line(&screen, 0, 0, 0, 0); // FIXME: won't compile without this crap while (!get_trigger(0)) { if (get_stick(0) == 1) flat = !flat; // rotate a bit triangle.rot_y += 2; triangle.rot_x += 3; triangle.rot_z += 1; // clear the off-screen buffer memset(sbuffer, 0, MODE2_MAX); // [*] //surface_line(screen, 0, 0, 10, 10); // render the object if (flat) //object_render_flatshading(&screen, &triangle, pbuffer, low, high, &light); object_render_flatshading(&screen, &triangle, pbuffer, stencil, &light); else object_render_wireframe(&screen, &triangle, pbuffer); // show the off-screen buffer //vwrite(screen.data.ram, 0, MODE2_MAX); // [*] msx_vwrite_direct(screen.data.ram, 0, MODE2_MAX); // [*] FIXME: there will be better ways of doing this (soon) } // go back to text mode set_mode(mode_0); // deallocate stuff mesh_delete(triangle.mesh); //free(sbuffer); //free(low); //free(high); //destroy_lookup_tables(); }