From ecda79bcc60db5e3eacc31543d870d7d7df46bfe Mon Sep 17 00:00:00 2001 From: Nilton Constantino Date: Wed, 21 Jan 2026 09:49:38 +0000 Subject: [PATCH] more content into main.ts --- .../prometeu-compiler/src/codegen/codegen.rs | 24 ++--- .../color-square/build/program.disasm.txt | 42 ++++++--- .../color-square/build/program.pbc | Bin 677 -> 733 bytes .../color-square/build/symbols.json | 88 +++++++++++++++++- .../color-square/cartridge/program.pbc | Bin 677 -> 733 bytes test-cartridges/color-square/run.sh | 5 + test-cartridges/color-square/src/main.ts | 70 ++++++++------ 7 files changed, 172 insertions(+), 57 deletions(-) create mode 100755 test-cartridges/color-square/run.sh diff --git a/crates/prometeu-compiler/src/codegen/codegen.rs b/crates/prometeu-compiler/src/codegen/codegen.rs index 380e36c7..36c4fc68 100644 --- a/crates/prometeu-compiler/src/codegen/codegen.rs +++ b/crates/prometeu-compiler/src/codegen/codegen.rs @@ -295,18 +295,18 @@ impl Codegen { if full_name.to_lowercase().starts_with("color.") { match full_name.to_lowercase().as_str() { - "color.black" => self.emit_op(OpCode::PushI32, vec![Operand::I32(Color::BLACK.hex())], member.span), - "color.white" => self.emit_op(OpCode::PushI32, vec![Operand::I32(Color::WHITE.hex())], member.span), - "color.red" => self.emit_op(OpCode::PushI32, vec![Operand::I32(Color::RED.hex())], member.span), - "color.green" => self.emit_op(OpCode::PushI32, vec![Operand::I32(Color::GREEN.hex())], member.span), - "color.blue" => self.emit_op(OpCode::PushI32, vec![Operand::I32(Color::BLUE.hex())], member.span), - "color.yellow" => self.emit_op(OpCode::PushI32, vec![Operand::I32(Color::YELLOW.hex())], member.span), - "color.cyan" => self.emit_op(OpCode::PushI32, vec![Operand::I32(Color::CYAN.hex())], member.span), - "color.gray" | "color.grey" => self.emit_op(OpCode::PushI32, vec![Operand::I32(Color::GRAY.hex())], member.span), - "color.orange" => self.emit_op(OpCode::PushI32, vec![Operand::I32(Color::ORANGE.hex())], member.span), - "color.indigo" => self.emit_op(OpCode::PushI32, vec![Operand::I32(Color::INDIGO.hex())], member.span), - "color.magenta" => self.emit_op(OpCode::PushI32, vec![Operand::I32(Color::MAGENTA.hex())], member.span), - "color.colorKey" | "color.color_key" => self.emit_op(OpCode::PushI32, vec![Operand::I32(Color::COLOR_KEY.hex())], member.span), + "color.black" => self.emit_op(OpCode::PushI32, vec![Operand::I32(Color::BLACK.raw() as i32)], member.span), + "color.white" => self.emit_op(OpCode::PushI32, vec![Operand::I32(Color::WHITE.raw() as i32)], member.span), + "color.red" => self.emit_op(OpCode::PushI32, vec![Operand::I32(Color::RED.raw() as i32)], member.span), + "color.green" => self.emit_op(OpCode::PushI32, vec![Operand::I32(Color::GREEN.raw() as i32)], member.span), + "color.blue" => self.emit_op(OpCode::PushI32, vec![Operand::I32(Color::BLUE.raw() as i32)], member.span), + "color.yellow" => self.emit_op(OpCode::PushI32, vec![Operand::I32(Color::YELLOW.raw() as i32)], member.span), + "color.cyan" => self.emit_op(OpCode::PushI32, vec![Operand::I32(Color::CYAN.raw() as i32)], member.span), + "color.gray" | "color.grey" => self.emit_op(OpCode::PushI32, vec![Operand::I32(Color::GRAY.raw() as i32)], member.span), + "color.orange" => self.emit_op(OpCode::PushI32, vec![Operand::I32(Color::ORANGE.raw() as i32)], member.span), + "color.indigo" => self.emit_op(OpCode::PushI32, vec![Operand::I32(Color::INDIGO.raw() as i32)], member.span), + "color.magenta" => self.emit_op(OpCode::PushI32, vec![Operand::I32(Color::MAGENTA.raw() as i32)], member.span), + "color.colorKey" | "color.color_key" => self.emit_op(OpCode::PushI32, vec![Operand::I32(Color::COLOR_KEY.raw() as i32)], member.span), _ => return Err(anyhow!("Unsupported color constant: {} at {:?}", full_name, member.span)), } } else if full_name.to_lowercase().starts_with("pad.") { diff --git a/test-cartridges/color-square/build/program.disasm.txt b/test-cartridges/color-square/build/program.disasm.txt index 6e50329f..5f81f2f4 100644 --- a/test-cartridges/color-square/build/program.disasm.txt +++ b/test-cartridges/color-square/build/program.disasm.txt @@ -2,42 +2,42 @@ 0000000A Pop 0000000C FrameSync 0000000E Jmp U32(0) -00000014 PushI32 U32(4849796) ; ./src/main.ts:2 +00000014 PushI32 U32(18448) ; ./src/main.ts:2 0000001A Syscall U32(4097) ; ./src/main.ts:2 00000020 Pop ; ./src/main.ts:2 00000022 PushI32 U32(10) ; ./src/main.ts:4 00000028 PushI32 U32(10) ; ./src/main.ts:4 0000002E PushI32 U32(50) ; ./src/main.ts:4 00000034 PushI32 U32(50) ; ./src/main.ts:4 -0000003A PushI32 U32(16711680) ; ./src/main.ts:4 +0000003A PushI32 U32(63488) ; ./src/main.ts:4 00000040 Syscall U32(4098) ; ./src/main.ts:4 00000046 Pop ; ./src/main.ts:4 00000048 PushI32 U32(0) ; ./src/main.ts:5 0000004E PushI32 U32(0) ; ./src/main.ts:5 00000054 PushI32 U32(128) ; ./src/main.ts:5 0000005A PushI32 U32(128) ; ./src/main.ts:5 -00000060 PushI32 U32(16777215) ; ./src/main.ts:5 +00000060 PushI32 U32(65535) ; ./src/main.ts:5 00000066 Syscall U32(4099) ; ./src/main.ts:5 0000006C Pop ; ./src/main.ts:5 0000006E PushI32 U32(64) ; ./src/main.ts:6 00000074 PushI32 U32(64) ; ./src/main.ts:6 0000007A PushI32 U32(20) ; ./src/main.ts:6 -00000080 PushI32 U32(255) ; ./src/main.ts:6 +00000080 PushI32 U32(31) ; ./src/main.ts:6 00000086 Syscall U32(4100) ; ./src/main.ts:6 0000008C Pop ; ./src/main.ts:6 0000008E PushI32 U32(100) ; ./src/main.ts:7 00000094 PushI32 U32(100) ; ./src/main.ts:7 0000009A PushI32 U32(10) ; ./src/main.ts:7 -000000A0 PushI32 U32(65280) ; ./src/main.ts:7 -000000A6 PushI32 U32(16776960) ; ./src/main.ts:7 +000000A0 PushI32 U32(2016) ; ./src/main.ts:7 +000000A6 PushI32 U32(65504) ; ./src/main.ts:7 000000AC Syscall U32(4101) ; ./src/main.ts:7 000000B2 Pop ; ./src/main.ts:7 000000B4 PushI32 U32(20) ; ./src/main.ts:8 000000BA PushI32 U32(100) ; ./src/main.ts:8 000000C0 PushI32 U32(30) ; ./src/main.ts:8 000000C6 PushI32 U32(30) ; ./src/main.ts:8 -000000CC PushI32 U32(65535) ; ./src/main.ts:8 -000000D2 PushI32 U32(16711935) ; ./src/main.ts:8 +000000CC PushI32 U32(2047) ; ./src/main.ts:8 +000000D2 PushI32 U32(63519) ; ./src/main.ts:8 000000D8 Syscall U32(4102) ; ./src/main.ts:8 000000DE Pop ; ./src/main.ts:8 000000E0 PushI32 U32(0) ; ./src/main.ts:10 @@ -64,7 +64,7 @@ 00000156 Syscall U32(8449) ; ./src/main.ts:19 0000015C Syscall U32(8450) ; ./src/main.ts:19 00000162 PushI32 U32(5) ; ./src/main.ts:19 -00000168 PushI32 U32(16777215) ; ./src/main.ts:19 +00000168 PushI32 U32(65535) ; ./src/main.ts:19 0000016E Syscall U32(4100) ; ./src/main.ts:19 00000174 Pop ; ./src/main.ts:19 00000176 Jmp U32(380) @@ -111,8 +111,22 @@ 00000240 PushI32 U32(0) ; ./src/main.ts:31 00000246 PushI32 U32(5) ; ./src/main.ts:31 0000024C PushI32 U32(5) ; ./src/main.ts:31 -00000252 GetLocal U32(2) ; ./src/main.ts:31 -00000258 Syscall U32(4098) ; ./src/main.ts:31 -0000025E Pop ; ./src/main.ts:31 -00000260 PushConst U32(0) -00000266 Ret +00000252 PushI32 U32(255) ; ./src/main.ts:31 +00000258 PushI32 U32(3) ; ./src/main.ts:31 +0000025E Shr ; ./src/main.ts:31 +00000260 PushI32 U32(11) ; ./src/main.ts:31 +00000266 Shl ; ./src/main.ts:31 +00000268 PushI32 U32(128) ; ./src/main.ts:31 +0000026E PushI32 U32(2) ; ./src/main.ts:31 +00000274 Shr ; ./src/main.ts:31 +00000276 PushI32 U32(5) ; ./src/main.ts:31 +0000027C Shl ; ./src/main.ts:31 +0000027E BitOr ; ./src/main.ts:31 +00000280 PushI32 U32(0) ; ./src/main.ts:31 +00000286 PushI32 U32(3) ; ./src/main.ts:31 +0000028C Shr ; ./src/main.ts:31 +0000028E BitOr ; ./src/main.ts:31 +00000290 Syscall U32(4098) ; ./src/main.ts:31 +00000296 Pop ; ./src/main.ts:31 +00000298 PushConst U32(0) +0000029E Ret diff --git a/test-cartridges/color-square/build/program.pbc b/test-cartridges/color-square/build/program.pbc index 68fc2c1c7ccb7b4f536d6210a8fb30b319563872..2f3cfc0e038549f7c089403b4c79a1019cd1c367 100644 GIT binary patch delta 133 zcmZ3=dY5&ArR)MG28I9z5e5hlWN2Uj3IKsPgMbIa#4r`69}E*~ROJ~M3K*CL7#IYB z5)NQ#2no_C&LBVWfIQ~|b`bNye};)KR5-wF`5z3EMHr_tGE82@_;j)*lbt{T0~6Q~ JAOQq{3;>qM78L*h delta 135 zcmcc1x|DT-rECTh1496V2m=HNGBhv%1%N=Dp@qR~VwegO!~cmjs`CFC3K*CL7#IYB z5)NQ#2no_C4peeLo|EA}h{^E(|HKz69ANf;hX0dA7^gD+pS+6kshAVkqM78L*h delta 135 zcmcc1x|DT-rECTh1496V2m=HNGBhv%1%N=Dp@qR~VwegO!~cmjs`CFC3K*CL7#IYB z5)NQ#2no_C4peeLo|EA}h{^E(|HKz69ANf;hX0dA7^gD+pS+6kshAVk= 0) { + fs.write(h, "Hello Prometeu!"); + let content = fs.read(h); + if (content) log.writeTag(2, 101, content); + fs.close(h); + } +} + export function tick(): void { - gfx.clear(color.indigo); + do_init_gfx(); + do_pad(); + do_touch(); + do_fs(); - gfx.fillRect(10, 10, 50, 50, color.red); - gfx.drawLine(0, 0, 128, 128, color.white); - gfx.drawCircle(64, 64, 20, color.blue); - gfx.drawDisc(100, 100, 10, color.green, color.yellow); - gfx.drawSquare(20, 100, 30, 30, color.cyan, color.color_key); - - if (pad.up.down) { - log.write(2, "Up is down"); - } - - if (pad.a.pressed) { - audio.playSample(1, 0, 255, 128, 1.0); - } - - if (touch.button.down) { - gfx.drawCircle(touch.x, touch.y, 5, color.white); - } - - let h = fs.open("test.txt"); - if (h >= 0) { - fs.write(h, "Hello Prometeu!"); - let content = fs.read(h); - if (content) log.writeTag(2, 101, content); - fs.close(h); - } - - let c = color.rgb(255, 128, 0); - gfx.fillRect(0, 0, 5, 5, c); + let c = color.rgb(255, 128, 0); + gfx.fillRect(0, 0, 5, 5, c); } \ No newline at end of file