this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

textri() renamed to ttri(), restore old textri() for ancient carts #1862

nesbox 74ad203b 414034d8

+396 -42
+1 -1
CMakeLists.txt
··· 460 460 endif() 461 461 462 462 if(${BUILD_DEPRECATED}) 463 - target_compile_definitions(tic80core${SCRIPT} PRIVATE DEPRECATED_CHUNKS) 463 + target_compile_definitions(tic80core${SCRIPT} PRIVATE BUILD_DEPRECATED) 464 464 target_link_libraries(tic80core${SCRIPT} giflib) 465 465 endif() 466 466
+3 -3
demos/bunny/wasmmark/src/tic80.zig
··· 133 133 extern fn sfx(id: i32, note: i32, octave: i32, duration: i32, channel: i32, volumeLeft: i32, volumeRight: i32, speed: i32) void; 134 134 extern fn spr(id: i32, x: i32, y: i32, trans_colors: ?[*]const u8, color_count: i32, scale: i32, flip: i32, rotate: i32, w: i32, h: i32) void; 135 135 extern fn sync(mask: i32, bank: i32, tocart: bool) void; 136 - extern fn textri(x1: f32, y1: f32, x2: f32, y2: f32, x3: f32, y3: f32, u1: f32, v1: f32, u2: f32, v2: f32, u3: f32, v3: f32, texsrc: i32, trans_colors: ?[*]const u8, color_count: i32) void; 136 + extern fn ttri(x1: f32, y1: f32, x2: f32, y2: f32, x3: f32, y3: f32, u1: f32, v1: f32, u2: f32, v2: f32, u3: f32, v3: f32, texsrc: i32, trans_colors: ?[*]const u8, color_count: i32) void; 137 137 extern fn tri(x1: f32, y1: f32, x2: f32, y2: f32, x3: f32, y3: f32, color: i32) void; 138 138 extern fn trib(x1: f32, y1: f32, x2: f32, y2: f32, x3: f32, y3: f32, color: i32) void; 139 139 extern fn time() f32; ··· 265 265 transparent: []const u8 = .{}, 266 266 }; 267 267 268 - pub fn textri(x1: f32, y1: f32, x2: f32, y2: f32, x3: f32, y3: f32, @"u1": f32, v1: f32, @"u2": f32, v2: f32, @"u3": f32, v3: f32, args: TextriArgs) void { 268 + pub fn ttri(x1: f32, y1: f32, x2: f32, y2: f32, x3: f32, y3: f32, @"u1": f32, v1: f32, @"u2": f32, v2: f32, @"u3": f32, v3: f32, args: TextriArgs) void { 269 269 const color_count = @intCast(u8,args.transparent.len); 270 270 const trans_colors = args.transparent.ptr; 271 - raw.textri(x1, y1, x2, y2, x3, y3, @"u1", v1, @"u2", v2, @"u3", v3, args.texsrc, trans_colors, color_count); 271 + raw.ttri(x1, y1, x2, y2, x3, y3, @"u1", v1, @"u2", v2, @"u3", v3, args.texsrc, trans_colors, color_count); 272 272 } 273 273 274 274 // ----
+3 -3
demos/wasm/src/tic80.zig
··· 133 133 extern fn sfx(id: i32, note: i32, octave: i32, duration: i32, channel: i32, volumeLeft: i32, volumeRight: i32, speed: i32) void; 134 134 extern fn spr(id: i32, x: i32, y: i32, trans_colors: ?[*]const u8, color_count: i32, scale: i32, flip: i32, rotate: i32, w: i32, h: i32) void; 135 135 extern fn sync(mask: i32, bank: i32, tocart: bool) void; 136 - extern fn textri(x1: f32, y1: f32, x2: f32, y2: f32, x3: f32, y3: f32, u1: f32, v1: f32, u2: f32, v2: f32, u3: f32, v3: f32, texsrc: i32, trans_colors: ?[*]const u8, color_count: i32) void; 136 + extern fn ttri(x1: f32, y1: f32, x2: f32, y2: f32, x3: f32, y3: f32, u1: f32, v1: f32, u2: f32, v2: f32, u3: f32, v3: f32, texsrc: i32, trans_colors: ?[*]const u8, color_count: i32) void; 137 137 extern fn tri(x1: f32, y1: f32, x2: f32, y2: f32, x3: f32, y3: f32, color: i32) void; 138 138 extern fn trib(x1: f32, y1: f32, x2: f32, y2: f32, x3: f32, y3: f32, color: i32) void; 139 139 extern fn time() f32; ··· 265 265 transparent: []const u8 = .{}, 266 266 }; 267 267 268 - pub fn textri(x1: f32, y1: f32, x2: f32, y2: f32, x3: f32, y3: f32, @"u1": f32, v1: f32, @"u2": f32, v2: f32, @"u3": f32, v3: f32, args: TextriArgs) void { 268 + pub fn ttri(x1: f32, y1: f32, x2: f32, y2: f32, x3: f32, y3: f32, @"u1": f32, v1: f32, @"u2": f32, v2: f32, @"u3": f32, v3: f32, args: TextriArgs) void { 269 269 const color_count = @intCast(u8,args.transparent.len); 270 270 const trans_colors = args.transparent.ptr; 271 - raw.textri(x1, y1, x2, y2, x3, y3, @"u1", v1, @"u2", v2, @"u3", v3, args.texsrc, trans_colors, color_count); 271 + raw.ttri(x1, y1, x2, y2, x3, y3, @"u1", v1, @"u2", v2, @"u3", v3, args.texsrc, trans_colors, color_count); 272 272 } 273 273 274 274 // ----
+2 -2
src/api.h
··· 686 686 tic_mem*, float x1, float y1, float x2, float y2, float x3, float y3, u8 color) \ 687 687 \ 688 688 \ 689 - macro(textri, \ 690 - "textri(x1 y1 x2 y2 x3 y3 u1 v1 u2 v2 u3 v3 texsrc=0 chromakey=-1 z1=0 z2=0 z3=0)", \ 689 + macro(ttri, \ 690 + "ttri(x1 y1 x2 y2 x3 y3 u1 v1 u2 v2 u3 v3 texsrc=0 chromakey=-1 z1=0 z2=0 z3=0)", \ 691 691 \ 692 692 "It renders a triangle filled with texture from image ram, map ram or vbank.\n" \ 693 693 "Use in 3D graphics.\n" \
+69 -3
src/api/js.c
··· 807 807 return 0; 808 808 } 809 809 810 + #if defined(BUILD_DEPRECATED) 811 + 812 + void drawTexturedTriangleDep(tic_core* core, float x1, float y1, float x2, float y2, float x3, float y3, float u1, float v1, float u2, float v2, float u3, float v3, bool use_map, u8* colors, s32 count); 813 + 810 814 static duk_ret_t duk_textri(duk_context* duk) 811 815 { 812 816 float pt[12]; ··· 814 818 for (s32 i = 0; i < COUNT_OF(pt); i++) 815 819 pt[i] = (float)duk_to_number(duk, i); 816 820 tic_mem* tic = (tic_mem*)getDukCore(duk); 821 + bool use_map = duk_to_boolean(duk, 12); 822 + 823 + static u8 colors[TIC_PALETTE_SIZE]; 824 + s32 count = 0; 825 + { 826 + if(!duk_is_null_or_undefined(duk, 13)) 827 + { 828 + if(duk_is_array(duk, 13)) 829 + { 830 + for(s32 i = 0; i < TIC_PALETTE_SIZE; i++) 831 + { 832 + duk_get_prop_index(duk, 13, i); 833 + if(duk_is_null_or_undefined(duk, -1)) 834 + { 835 + duk_pop(duk); 836 + break; 837 + } 838 + else 839 + { 840 + colors[i] = duk_to_int(duk, -1); 841 + count++; 842 + duk_pop(duk); 843 + } 844 + } 845 + } 846 + else 847 + { 848 + colors[0] = duk_to_int(duk, 13); 849 + count = 1; 850 + } 851 + } 852 + } 853 + 854 + drawTexturedTriangleDep(getDukCore(duk), 855 + pt[0], pt[1], // xy 1 856 + pt[2], pt[3], // xy 2 857 + pt[4], pt[5], // xy 3 858 + pt[6], pt[7], // uv 1 859 + pt[8], pt[9], // uv 2 860 + pt[10], pt[11], // uv 3 861 + use_map, // use_map 862 + colors, count); // chroma 863 + 864 + return 0; 865 + } 866 + 867 + #endif 868 + 869 + static duk_ret_t duk_ttri(duk_context* duk) 870 + { 871 + float pt[12]; 872 + 873 + for (s32 i = 0; i < COUNT_OF(pt); i++) 874 + pt[i] = (float)duk_to_number(duk, i); 875 + tic_mem* tic = (tic_mem*)getDukCore(duk); 817 876 tic_texture_src src = duk_to_int(duk, 12); 818 877 819 878 static u8 colors[TIC_PALETTE_SIZE]; ··· 856 915 else z[i] = (float)duk_to_number(duk, index); 857 916 } 858 917 859 - tic_api_textri(tic, pt[0], pt[1], // xy 1 918 + tic_api_ttri(tic, pt[0], pt[1], // xy 1 860 919 pt[2], pt[3], // xy 2 861 920 pt[4], pt[5], // xy 3 862 921 pt[6], pt[7], // uv 1 ··· 989 1048 duk_pop(duk); 990 1049 } 991 1050 1051 + static const struct{duk_c_function func; s32 params; const char* name;} ApiItems[] = 1052 + { 992 1053 #define API_FUNC_DEF(name, _, __, paramsCount, ...) {duk_ ## name, paramsCount, #name}, 993 - static const struct{duk_c_function func; s32 params; const char* name;} ApiItems[] = {TIC_API_LIST(API_FUNC_DEF)}; 994 - #undef API_FUNC_DEF 1054 + TIC_API_LIST(API_FUNC_DEF) 1055 + #undef API_FUNC_DEF 1056 + 1057 + #if defined(BUILD_DEPRECATED) 1058 + {duk_textri, 14, "textri"}, 1059 + #endif 1060 + }; 995 1061 996 1062 for (s32 i = 0; i < COUNT_OF(ApiItems); i++) 997 1063 {
+79 -4
src/api/lua.c
··· 420 420 return 0; 421 421 } 422 422 423 + #if defined(BUILD_DEPRECATED) 424 + 425 + void drawTexturedTriangleDep(tic_core* core, float x1, float y1, float x2, float y2, float x3, float y3, float u1, float v1, float u2, float v2, float u3, float v3, bool use_map, u8* colors, s32 count); 426 + 423 427 static s32 lua_textri(lua_State* lua) 424 428 { 425 429 s32 top = lua_gettop(lua); ··· 434 438 tic_mem* tic = (tic_mem*)getLuaCore(lua); 435 439 static u8 colors[TIC_PALETTE_SIZE]; 436 440 s32 count = 0; 441 + bool use_map = false; 442 + 443 + // check for use map 444 + if (top >= 13) 445 + use_map = lua_toboolean(lua, 13); 446 + 447 + // check for chroma 448 + if(top >= 14) 449 + { 450 + if(lua_istable(lua, 14)) 451 + { 452 + for(s32 i = 1; i <= TIC_PALETTE_SIZE; i++) 453 + { 454 + lua_rawgeti(lua, 14, i); 455 + if(lua_isnumber(lua, -1)) 456 + { 457 + colors[i-1] = getLuaNumber(lua, -1); 458 + count++; 459 + lua_pop(lua, 1); 460 + } 461 + else 462 + { 463 + lua_pop(lua, 1); 464 + break; 465 + } 466 + } 467 + } 468 + else 469 + { 470 + colors[0] = getLuaNumber(lua, 14); 471 + count = 1; 472 + } 473 + } 474 + 475 + drawTexturedTriangleDep(getLuaCore(lua), 476 + pt[0], pt[1], // xy 1 477 + pt[2], pt[3], // xy 2 478 + pt[4], pt[5], // xy 3 479 + pt[6], pt[7], // uv 1 480 + pt[8], pt[9], // uv 2 481 + pt[10], pt[11], // uv 3 482 + use_map, // use map 483 + colors, count); // chroma 484 + } 485 + 486 + return 0; 487 + } 488 + 489 + #endif 490 + 491 + static s32 lua_ttri(lua_State* lua) 492 + { 493 + s32 top = lua_gettop(lua); 494 + 495 + if (top >= 12) 496 + { 497 + float pt[12]; 498 + 499 + for (s32 i = 0; i < COUNT_OF(pt); i++) 500 + pt[i] = (float)lua_tonumber(lua, i + 1); 501 + 502 + tic_mem* tic = (tic_mem*)getLuaCore(lua); 503 + static u8 colors[TIC_PALETTE_SIZE]; 504 + s32 count = 0; 437 505 tic_texture_src src = tic_tiles_texture; 438 506 439 507 // check for texture src ··· 482 550 persp = true; 483 551 } 484 552 485 - tic_api_textri(tic, pt[0], pt[1], // xy 1 553 + tic_api_ttri(tic, pt[0], pt[1], // xy 1 486 554 pt[2], pt[3], // xy 2 487 555 pt[4], pt[5], // xy 3 488 556 pt[6], pt[7], // uv 1 ··· 492 560 colors, count, // chroma 493 561 z[0], z[1], z[2], persp); // depth 494 562 } 495 - else luaL_error(lua, "invalid parameters, textri(x1,y1,x2,y2,x3,y3,u1,v1,u2,v2,u3,v3,[src=0],[chroma=off],[z1=0],[z2=0],[z3=0])\n"); 563 + else luaL_error(lua, "invalid parameters, ttri(x1,y1,x2,y2,x3,y3,u1,v1,u2,v2,u3,v3,[src=0],[chroma=off],[z1=0],[z2=0],[z3=0])\n"); 496 564 return 0; 497 565 } 498 566 ··· 1454 1522 1455 1523 void initLuaAPI(tic_core* core) 1456 1524 { 1525 + static const struct{lua_CFunction func; const char* name;} ApiItems[] = 1526 + { 1457 1527 #define API_FUNC_DEF(name, ...) {lua_ ## name, #name}, 1458 - static const struct{lua_CFunction func; const char* name;} ApiItems[] = {TIC_API_LIST(API_FUNC_DEF)}; 1459 - #undef API_FUNC_DEF 1528 + TIC_API_LIST(API_FUNC_DEF) 1529 + #undef API_FUNC_DEF 1530 + 1531 + #if defined(BUILD_DEPRECATED) 1532 + {lua_textri, "textri"}, 1533 + #endif 1534 + }; 1460 1535 1461 1536 for (s32 i = 0; i < COUNT_OF(ApiItems); i++) 1462 1537 registerLuaFunction(core, ApiItems[i].func, ApiItems[i].name);
+2 -2
src/api/mruby.c
··· 297 297 return mrb_nil_value(); 298 298 } 299 299 300 - static mrb_value mrb_textri(mrb_state* mrb, mrb_value self) 300 + static mrb_value mrb_ttri(mrb_state* mrb, mrb_value self) 301 301 { 302 302 mrb_value chroma = mrb_fixnum_value(0xff); 303 303 mrb_int src = tic_tiles_texture; ··· 329 329 330 330 tic_mem* memory = (tic_mem*)getMRubyMachine(mrb); 331 331 332 - tic_api_textri(memory, 332 + tic_api_ttri(memory, 333 333 x1, y1, x2, y2, x3, y3, 334 334 u1, v1, u2, v2, u3, v3, 335 335 src, chromas, count, z1, z2, z3, argc == 17);
+3 -3
src/api/squirrel.c
··· 469 469 return 0; 470 470 } 471 471 472 - static SQInteger squirrel_textri(HSQUIRRELVM vm) 472 + static SQInteger squirrel_ttri(HSQUIRRELVM vm) 473 473 { 474 474 SQInteger top = sq_gettop(vm); 475 475 ··· 527 527 persp = true; 528 528 } 529 529 530 - tic_api_textri(tic, pt[0], pt[1], // xy 1 530 + tic_api_ttri(tic, pt[0], pt[1], // xy 1 531 531 pt[2], pt[3], // xy 2 532 532 pt[4], pt[5], // xy 3 533 533 pt[6], pt[7], // uv 1 ··· 537 537 colors, count, // chroma 538 538 z[0], z[1], z[2], persp); // depth 539 539 } 540 - else return sq_throwerror(vm, "invalid parameters, textri(x1,y1,x2,y2,x3,y3,u1,v1,u2,v2,u3,v3,[texsrc=0],[chroma=off],[z1=0],[z2=0],[z3=0])\n"); 540 + else return sq_throwerror(vm, "invalid parameters, ttri(x1,y1,x2,y2,x3,y3,u1,v1,u2,v2,u3,v3,[texsrc=0],[chroma=off],[z1=0],[z2=0],[z3=0])\n"); 541 541 return 0; 542 542 } 543 543
+4 -4
src/api/wasm.c
··· 263 263 m3ApiSuccess(); 264 264 } 265 265 266 - // textri x1 y1 x2 y2 x3 y3 u1 v1 u2 v2 u3 v3 [texsrc=0] [trans=-1] [z1 z2 z3 persp] 267 - m3ApiRawFunction(wasmtic_textri) 266 + // ttri x1 y1 x2 y2 x3 y3 u1 v1 u2 v2 u3 v3 [texsrc=0] [trans=-1] [z1 z2 z3 persp] 267 + m3ApiRawFunction(wasmtic_ttri) 268 268 { 269 269 m3ApiGetArg (float, x1) 270 270 m3ApiGetArg (float, y1) ··· 291 291 292 292 tic_mem* tic = (tic_mem*)getWasmCore(runtime); 293 293 294 - tic_api_textri(tic, x1, y1, x2, y2, x3, y3, 294 + tic_api_ttri(tic, x1, y1, x2, y2, x3, y3, 295 295 u1, v1, u2, v2, u3, v3, texsrc, trans_colors, colorCount, z1, z2, z3, persp); 296 296 297 297 m3ApiSuccess(); ··· 996 996 _ (SuppressLookupFailure (m3_LinkRawFunction (module, "env", "trace", "v(*i)", &wasmtic_trace))); 997 997 _ (SuppressLookupFailure (m3_LinkRawFunction (module, "env", "tri", "v(iiiiiii)", &wasmtic_tri))); 998 998 _ (SuppressLookupFailure (m3_LinkRawFunction (module, "env", "trib", "v(iiiiiii)", &wasmtic_trib))); 999 - _ (SuppressLookupFailure (m3_LinkRawFunction (module, "env", "textri", "v(iiiiiiiiiiiiiiiiiii)", &wasmtic_textri))); 999 + _ (SuppressLookupFailure (m3_LinkRawFunction (module, "env", "ttri", "v(iiiiiiiiiiiiiiiiiii)", &wasmtic_ttri))); 1000 1000 _ (SuppressLookupFailure (m3_LinkRawFunction (module, "env", "vbank", "i(i)", &wasmtic_vbank))); 1001 1001 1002 1002 _catch:
+10 -10
src/api/wren.c
··· 74 74 foreign static mset(cell_x, cell_y)\n\ 75 75 foreign static mset(cell_x, cell_y, index)\n\ 76 76 foreign static mget(cell_x, cell_y)\n\ 77 - foreign static textri(x1, y1, x2, y2, x3, y3, u1, v1, u2, v2, u3, v3)\n\ 78 - foreign static textri(x1, y1, x2, y2, x3, y3, u1, v1, u2, v2, u3, v3, src)\n\ 79 - foreign static textri(x1, y1, x2, y2, x3, y3, u1, v1, u2, v2, u3, v3, src, alpha_color)\n\ 80 - foreign static textri(x1, y1, x2, y2, x3, y3, u1, v1, u2, v2, u3, v3, src, alpha_color, z1, z2, z3)\n\ 77 + foreign static ttri(x1, y1, x2, y2, x3, y3, u1, v1, u2, v2, u3, v3)\n\ 78 + foreign static ttri(x1, y1, x2, y2, x3, y3, u1, v1, u2, v2, u3, v3, src)\n\ 79 + foreign static ttri(x1, y1, x2, y2, x3, y3, u1, v1, u2, v2, u3, v3, src, alpha_color)\n\ 80 + foreign static ttri(x1, y1, x2, y2, x3, y3, u1, v1, u2, v2, u3, v3, src, alpha_color, z1, z2, z3)\n\ 81 81 foreign static pix(x, y)\n\ 82 82 foreign static pix(x, y, color)\n\ 83 83 foreign static line(x0, y0, x1, y1, color)\n\ ··· 731 731 wrenSetSlotDouble(vm, 0, value); 732 732 } 733 733 734 - static void wren_textri(WrenVM* vm) 734 + static void wren_ttri(WrenVM* vm) 735 735 { 736 736 int top = wrenGetSlotCount(vm); 737 737 ··· 789 789 persp = true; 790 790 } 791 791 792 - tic_api_textri(tic, pt[0], pt[1], // xy 1 792 + tic_api_ttri(tic, pt[0], pt[1], // xy 1 793 793 pt[2], pt[3], // xy 2 794 794 pt[4], pt[5], // xy 3 795 795 pt[6], pt[7], // uv 1 ··· 1389 1389 if (strcmp(signature, "static TIC.mset(_,_,_)" ) == 0) return wren_mset; 1390 1390 if (strcmp(signature, "static TIC.mget(_,_)" ) == 0) return wren_mget; 1391 1391 1392 - if (strcmp(signature, "static TIC.textri(_,_,_,_,_,_,_,_,_,_,_,_)" ) == 0) return wren_textri; 1393 - if (strcmp(signature, "static TIC.textri(_,_,_,_,_,_,_,_,_,_,_,_,_)" ) == 0) return wren_textri; 1394 - if (strcmp(signature, "static TIC.textri(_,_,_,_,_,_,_,_,_,_,_,_,_,_)" ) == 0) return wren_textri; 1395 - if (strcmp(signature, "static TIC.textri(_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_)" ) == 0) return wren_textri; 1392 + if (strcmp(signature, "static TIC.ttri(_,_,_,_,_,_,_,_,_,_,_,_)" ) == 0) return wren_ttri; 1393 + if (strcmp(signature, "static TIC.ttri(_,_,_,_,_,_,_,_,_,_,_,_,_)" ) == 0) return wren_ttri; 1394 + if (strcmp(signature, "static TIC.ttri(_,_,_,_,_,_,_,_,_,_,_,_,_,_)" ) == 0) return wren_ttri; 1395 + if (strcmp(signature, "static TIC.ttri(_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_,_)" ) == 0) return wren_ttri; 1396 1396 1397 1397 if (strcmp(signature, "static TIC.pix(_,_)" ) == 0) return wren_pix; 1398 1398 if (strcmp(signature, "static TIC.pix(_,_,_)" ) == 0) return wren_pix;
+3 -3
src/cart.c
··· 22 22 23 23 #include "cart.h" 24 24 25 - #if defined(DEPRECATED_CHUNKS) 25 + #if defined(BUILD_DEPRECATED) 26 26 #include "tools.h" 27 27 #include "ext/gif.h" 28 28 #endif ··· 108 108 ptr += chunkSize(chunk); 109 109 } 110 110 111 - #if defined(DEPRECATED_CHUNKS) 111 + #if defined(BUILD_DEPRECATED) 112 112 // workaround to support ancient carts without palette 113 113 // load DB16 palette if it not exists 114 114 if (EMPTY(cart->bank0.palette.vbank0.data)) ··· 147 147 case CHUNK_CODE: 148 148 code[chunk->bank] = (struct CodeChunk){chunkSize(chunk), ptr}; 149 149 break; 150 - #if defined(DEPRECATED_CHUNKS) 150 + #if defined(BUILD_DEPRECATED) 151 151 case CHUNK_CODE_ZIP: 152 152 tic_tool_unzip(cart->code.data, TIC_CODE_SIZE, ptr, chunk->size); 153 153 break;
+5 -1
src/core/draw.c
··· 804 804 return data->mapping[tic_tool_peek4(data->vram->data, v * TIC80_WIDTH + u)]; 805 805 } 806 806 807 - void tic_api_textri(tic_mem* tic, 807 + void tic_api_ttri(tic_mem* tic, 808 808 float x1, float y1, 809 809 float x2, float y2, 810 810 float x3, float y3, ··· 866 866 { 867 867 drawLine(memory, x0, y0, x1, y1, mapColor(memory, color)); 868 868 } 869 + 870 + #if defined(BUILD_DEPRECATED) 871 + #include "draw_dep.c" 872 + #endif
+209
src/core/draw_dep.c
··· 1 + // MIT License 2 + 3 + // Copyright (c) 2020 Vadim Grigoruk @nesbox // grigoruk@gmail.com 4 + 5 + // Permission is hereby granted, free of charge, to any person obtaining a copy 6 + // of this software and associated documentation files (the "Software"), to deal 7 + // in the Software without restriction, including without limitation the rights 8 + // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 + // copies of the Software, and to permit persons to whom the Software is 10 + // furnished to do so, subject to the following conditions: 11 + 12 + // The above copyright notice and this permission notice shall be included in all 13 + // copies or substantial portions of the Software. 14 + 15 + // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 + // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 + // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 + // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 + // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 + // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 + // SOFTWARE. 22 + 23 + typedef struct 24 + { 25 + float x, y, u, v; 26 + } TexVertDep; 27 + 28 + static struct 29 + { 30 + s16 Left[TIC80_HEIGHT]; 31 + s16 Right[TIC80_HEIGHT]; 32 + s32 ULeft[TIC80_HEIGHT]; 33 + s32 VLeft[TIC80_HEIGHT]; 34 + } SidesBufferDep; 35 + 36 + static void setSideTexPixel(s32 x, s32 y, float u, float v) 37 + { 38 + s32 yy = y; 39 + if (yy >= 0 && yy < TIC80_HEIGHT) 40 + { 41 + if (x < SidesBufferDep.Left[yy]) 42 + { 43 + SidesBufferDep.Left[yy] = x; 44 + SidesBufferDep.ULeft[yy] = (s32)(u * 65536.0f); 45 + SidesBufferDep.VLeft[yy] = (s32)(v * 65536.0f); 46 + } 47 + if (x > SidesBufferDep.Right[yy]) 48 + { 49 + SidesBufferDep.Right[yy] = x; 50 + } 51 + } 52 + } 53 + 54 + static void ticTexLine(tic_mem* memory, TexVertDep* v0, TexVertDep* v1) 55 + { 56 + TexVertDep* top = v0; 57 + TexVertDep* bot = v1; 58 + 59 + if (bot->y < top->y) 60 + { 61 + top = v1; 62 + bot = v0; 63 + } 64 + 65 + float dy = bot->y - top->y; 66 + float step_x = (bot->x - top->x); 67 + float step_u = (bot->u - top->u); 68 + float step_v = (bot->v - top->v); 69 + 70 + if ((s32)dy != 0) 71 + { 72 + step_x /= dy; 73 + step_u /= dy; 74 + step_v /= dy; 75 + } 76 + 77 + float x = top->x; 78 + float y = top->y; 79 + float u = top->u; 80 + float v = top->v; 81 + 82 + if (y < .0f) 83 + { 84 + y = .0f - y; 85 + 86 + x += step_x * y; 87 + u += step_u * y; 88 + v += step_v * y; 89 + 90 + y = .0f; 91 + } 92 + 93 + s32 botY = (s32)bot->y; 94 + if (botY > TIC80_HEIGHT) 95 + botY = TIC80_HEIGHT; 96 + 97 + for (; y < botY; ++y) 98 + { 99 + setSideTexPixel((s32)x, (s32)y, u, v); 100 + x += step_x; 101 + u += step_u; 102 + v += step_v; 103 + } 104 + } 105 + 106 + void drawTexturedTriangleDep(tic_core* core, float x1, float y1, float x2, float y2, float x3, float y3, float u1, float v1, float u2, float v2, float u3, float v3, bool use_map, u8* colors, s32 count) 107 + { 108 + tic_mem* memory = &core->memory; 109 + tic_vram* vram = &memory->ram->vram; 110 + 111 + u8* mapping = getPalette(memory, colors, count); 112 + TexVertDep V0, V1, V2; 113 + 114 + const u8* map = memory->ram->map.data; 115 + tic_tilesheet sheet = getTileSheetFromSegment(memory, memory->ram->vram.blit.segment); 116 + 117 + V0.x = x1; V0.y = y1; V0.u = u1; V0.v = v1; 118 + V1.x = x2; V1.y = y2; V1.u = u2; V1.v = v2; 119 + V2.x = x3; V2.y = y3; V2.u = u3; V2.v = v3; 120 + 121 + // calculate the slope of the surface 122 + // use floats here 123 + float denom = (V0.x - V2.x) * (V1.y - V2.y) - (V1.x - V2.x) * (V0.y - V2.y); 124 + if (denom == 0.0) 125 + { 126 + return; 127 + } 128 + float id = 1.0f / denom; 129 + float dudx, dvdx; 130 + // this is the UV slope across the surface 131 + dudx = ((V0.u - V2.u) * (V1.y - V2.y) - (V1.u - V2.u) * (V0.y - V2.y)) * id; 132 + dvdx = ((V0.v - V2.v) * (V1.y - V2.y) - (V1.v - V2.v) * (V0.y - V2.y)) * id; 133 + // convert to fixed 134 + s32 dudxs = (s32)(dudx * 65536.0f); 135 + s32 dvdxs = (s32)(dvdx * 65536.0f); 136 + // fill the buffer 137 + for (s32 i = 0; i < COUNT_OF(SidesBuffer.Left); i++) 138 + SidesBufferDep.Left[i] = TIC80_WIDTH, SidesBufferDep.Right[i] = -1; 139 + 140 + // parse each line and decide where in the buffer to store them ( left or right ) 141 + ticTexLine(memory, &V0, &V1); 142 + ticTexLine(memory, &V1, &V2); 143 + ticTexLine(memory, &V2, &V0); 144 + 145 + for (s32 y = 0; y < TIC80_HEIGHT; y++) 146 + { 147 + // if it's backwards skip it 148 + s32 width = SidesBufferDep.Right[y] - SidesBufferDep.Left[y]; 149 + // if it's off top or bottom , skip this line 150 + if ((y < core->state.clip.t) || (y > core->state.clip.b)) 151 + width = 0; 152 + if (width > 0) 153 + { 154 + s32 u = SidesBufferDep.ULeft[y]; 155 + s32 v = SidesBufferDep.VLeft[y]; 156 + s32 left = SidesBufferDep.Left[y]; 157 + s32 right = SidesBufferDep.Right[y]; 158 + // check right edge, and CLAMP it 159 + if (right > core->state.clip.r) 160 + right = core->state.clip.r; 161 + // check left edge and offset UV's if we are off the left 162 + if (left < core->state.clip.l) 163 + { 164 + s32 dist = core->state.clip.l - SidesBufferDep.Left[y]; 165 + u += dudxs * dist; 166 + v += dvdxs * dist; 167 + left = core->state.clip.l; 168 + } 169 + // are we drawing from the map . ok then at least check before the inner loop 170 + if (use_map == true) 171 + { 172 + for (s32 x = left; x < right; ++x) 173 + { 174 + enum { MapWidth = TIC_MAP_WIDTH * TIC_SPRITESIZE, MapHeight = TIC_MAP_HEIGHT * TIC_SPRITESIZE }; 175 + s32 iu = (u >> 16) % MapWidth; 176 + s32 iv = (v >> 16) % MapHeight; 177 + 178 + while (iu < 0) iu += MapWidth; 179 + while (iv < 0) iv += MapHeight; 180 + 181 + u8 tileindex = map[(iv >> 3) * TIC_MAP_WIDTH + (iu >> 3)]; 182 + tic_tileptr tile = tic_tilesheet_gettile(&sheet, tileindex, true); 183 + 184 + u8 color = mapping[tic_tilesheet_gettilepix(&tile, iu & 7, iv & 7)]; 185 + if (color != TRANSPARENT_COLOR) 186 + setPixel(core, x, y, color); 187 + u += dudxs; 188 + v += dvdxs; 189 + } 190 + } 191 + else 192 + { 193 + // direct from tile ram 194 + for (s32 x = left; x < right; ++x) 195 + { 196 + enum { SheetWidth = TIC_SPRITESHEET_SIZE, SheetHeight = TIC_SPRITESHEET_SIZE * TIC_SPRITE_BANKS }; 197 + s32 iu = (u >> 16) & (SheetWidth - 1); 198 + s32 iv = (v >> 16) & (SheetHeight - 1); 199 + 200 + u8 color = mapping[tic_tilesheet_getpix(&sheet, iu, iv)]; 201 + if (color != TRANSPARENT_COLOR) 202 + setPixel(core, x, y, color); 203 + u += dudxs; 204 + v += dvdxs; 205 + } 206 + } 207 + } 208 + } 209 + }
+3 -3
templates/zig/src/tic80.zig
··· 133 133 extern fn sfx(id: i32, note: i32, octave: i32, duration: i32, channel: i32, volumeLeft: i32, volumeRight: i32, speed: i32) void; 134 134 extern fn spr(id: i32, x: i32, y: i32, trans_colors: ?[*]const u8, color_count: i32, scale: i32, flip: i32, rotate: i32, w: i32, h: i32) void; 135 135 extern fn sync(mask: i32, bank: i32, tocart: bool) void; 136 - extern fn textri(x1: f32, y1: f32, x2: f32, y2: f32, x3: f32, y3: f32, u1: f32, v1: f32, u2: f32, v2: f32, u3: f32, v3: f32, texsrc: i32, trans_colors: ?[*]const u8, color_count: i32, z1: f32, z2: f32, z3: f32, persp: bool) void; 136 + extern fn ttri(x1: f32, y1: f32, x2: f32, y2: f32, x3: f32, y3: f32, u1: f32, v1: f32, u2: f32, v2: f32, u3: f32, v3: f32, texsrc: i32, trans_colors: ?[*]const u8, color_count: i32, z1: f32, z2: f32, z3: f32, persp: bool) void; 137 137 extern fn tri(x1: f32, y1: f32, x2: f32, y2: f32, x3: f32, y3: f32, color: i32) void; 138 138 extern fn trib(x1: f32, y1: f32, x2: f32, y2: f32, x3: f32, y3: f32, color: i32) void; 139 139 extern fn time() f32; ··· 269 269 persp : bool = false, 270 270 }; 271 271 272 - pub fn textri(x1: f32, y1: f32, x2: f32, y2: f32, x3: f32, y3: f32, @"u1": f32, v1: f32, @"u2": f32, v2: f32, @"u3": f32, v3: f32, args: TextriArgs) void { 272 + pub fn ttri(x1: f32, y1: f32, x2: f32, y2: f32, x3: f32, y3: f32, @"u1": f32, v1: f32, @"u2": f32, v2: f32, @"u3": f32, v3: f32, args: TextriArgs) void { 273 273 const color_count = @intCast(u8,args.transparent.len); 274 274 const trans_colors = args.transparent.ptr; 275 - raw.textri(x1, y1, x2, y2, x3, y3, @"u1", v1, @"u2", v2, @"u3", v3, args.texsrc, trans_colors, color_count, args.z1, args.z2, args.z3, args.persp); 275 + raw.ttri(x1, y1, x2, y2, x3, y3, @"u1", v1, @"u2", v2, @"u3", v3, args.texsrc, trans_colors, color_count, args.z1, args.z2, args.z3, args.persp); 276 276 } 277 277 278 278 // ----