more content into main.ts

This commit is contained in:
Nilton Constantino 2026-01-21 09:49:38 +00:00
parent b3cc7ee384
commit ecda79bcc6
No known key found for this signature in database
7 changed files with 172 additions and 57 deletions

View File

@ -295,18 +295,18 @@ impl Codegen {
if full_name.to_lowercase().starts_with("color.") { if full_name.to_lowercase().starts_with("color.") {
match full_name.to_lowercase().as_str() { match full_name.to_lowercase().as_str() {
"color.black" => self.emit_op(OpCode::PushI32, vec![Operand::I32(Color::BLACK.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.hex())], 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.hex())], 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.hex())], 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.hex())], 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.hex())], 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.hex())], 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.hex())], 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.hex())], 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.hex())], 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.hex())], 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.hex())], 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)), _ => return Err(anyhow!("Unsupported color constant: {} at {:?}", full_name, member.span)),
} }
} else if full_name.to_lowercase().starts_with("pad.") { } else if full_name.to_lowercase().starts_with("pad.") {

View File

@ -2,42 +2,42 @@
0000000A Pop 0000000A Pop
0000000C FrameSync 0000000C FrameSync
0000000E Jmp U32(0) 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 0000001A Syscall U32(4097) ; ./src/main.ts:2
00000020 Pop ; ./src/main.ts:2 00000020 Pop ; ./src/main.ts:2
00000022 PushI32 U32(10) ; ./src/main.ts:4 00000022 PushI32 U32(10) ; ./src/main.ts:4
00000028 PushI32 U32(10) ; ./src/main.ts:4 00000028 PushI32 U32(10) ; ./src/main.ts:4
0000002E PushI32 U32(50) ; ./src/main.ts:4 0000002E PushI32 U32(50) ; ./src/main.ts:4
00000034 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 00000040 Syscall U32(4098) ; ./src/main.ts:4
00000046 Pop ; ./src/main.ts:4 00000046 Pop ; ./src/main.ts:4
00000048 PushI32 U32(0) ; ./src/main.ts:5 00000048 PushI32 U32(0) ; ./src/main.ts:5
0000004E PushI32 U32(0) ; ./src/main.ts:5 0000004E PushI32 U32(0) ; ./src/main.ts:5
00000054 PushI32 U32(128) ; ./src/main.ts:5 00000054 PushI32 U32(128) ; ./src/main.ts:5
0000005A 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 00000066 Syscall U32(4099) ; ./src/main.ts:5
0000006C Pop ; ./src/main.ts:5 0000006C Pop ; ./src/main.ts:5
0000006E PushI32 U32(64) ; ./src/main.ts:6 0000006E PushI32 U32(64) ; ./src/main.ts:6
00000074 PushI32 U32(64) ; ./src/main.ts:6 00000074 PushI32 U32(64) ; ./src/main.ts:6
0000007A PushI32 U32(20) ; ./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 00000086 Syscall U32(4100) ; ./src/main.ts:6
0000008C Pop ; ./src/main.ts:6 0000008C Pop ; ./src/main.ts:6
0000008E PushI32 U32(100) ; ./src/main.ts:7 0000008E PushI32 U32(100) ; ./src/main.ts:7
00000094 PushI32 U32(100) ; ./src/main.ts:7 00000094 PushI32 U32(100) ; ./src/main.ts:7
0000009A PushI32 U32(10) ; ./src/main.ts:7 0000009A PushI32 U32(10) ; ./src/main.ts:7
000000A0 PushI32 U32(65280) ; ./src/main.ts:7 000000A0 PushI32 U32(2016) ; ./src/main.ts:7
000000A6 PushI32 U32(16776960) ; ./src/main.ts:7 000000A6 PushI32 U32(65504) ; ./src/main.ts:7
000000AC Syscall U32(4101) ; ./src/main.ts:7 000000AC Syscall U32(4101) ; ./src/main.ts:7
000000B2 Pop ; ./src/main.ts:7 000000B2 Pop ; ./src/main.ts:7
000000B4 PushI32 U32(20) ; ./src/main.ts:8 000000B4 PushI32 U32(20) ; ./src/main.ts:8
000000BA PushI32 U32(100) ; ./src/main.ts:8 000000BA PushI32 U32(100) ; ./src/main.ts:8
000000C0 PushI32 U32(30) ; ./src/main.ts:8 000000C0 PushI32 U32(30) ; ./src/main.ts:8
000000C6 PushI32 U32(30) ; ./src/main.ts:8 000000C6 PushI32 U32(30) ; ./src/main.ts:8
000000CC PushI32 U32(65535) ; ./src/main.ts:8 000000CC PushI32 U32(2047) ; ./src/main.ts:8
000000D2 PushI32 U32(16711935) ; ./src/main.ts:8 000000D2 PushI32 U32(63519) ; ./src/main.ts:8
000000D8 Syscall U32(4102) ; ./src/main.ts:8 000000D8 Syscall U32(4102) ; ./src/main.ts:8
000000DE Pop ; ./src/main.ts:8 000000DE Pop ; ./src/main.ts:8
000000E0 PushI32 U32(0) ; ./src/main.ts:10 000000E0 PushI32 U32(0) ; ./src/main.ts:10
@ -64,7 +64,7 @@
00000156 Syscall U32(8449) ; ./src/main.ts:19 00000156 Syscall U32(8449) ; ./src/main.ts:19
0000015C Syscall U32(8450) ; ./src/main.ts:19 0000015C Syscall U32(8450) ; ./src/main.ts:19
00000162 PushI32 U32(5) ; ./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 0000016E Syscall U32(4100) ; ./src/main.ts:19
00000174 Pop ; ./src/main.ts:19 00000174 Pop ; ./src/main.ts:19
00000176 Jmp U32(380) 00000176 Jmp U32(380)
@ -111,8 +111,22 @@
00000240 PushI32 U32(0) ; ./src/main.ts:31 00000240 PushI32 U32(0) ; ./src/main.ts:31
00000246 PushI32 U32(5) ; ./src/main.ts:31 00000246 PushI32 U32(5) ; ./src/main.ts:31
0000024C PushI32 U32(5) ; ./src/main.ts:31 0000024C PushI32 U32(5) ; ./src/main.ts:31
00000252 GetLocal U32(2) ; ./src/main.ts:31 00000252 PushI32 U32(255) ; ./src/main.ts:31
00000258 Syscall U32(4098) ; ./src/main.ts:31 00000258 PushI32 U32(3) ; ./src/main.ts:31
0000025E Pop ; ./src/main.ts:31 0000025E Shr ; ./src/main.ts:31
00000260 PushConst U32(0) 00000260 PushI32 U32(11) ; ./src/main.ts:31
00000266 Ret 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

View File

@ -627,18 +627,102 @@
"pc": 594, "pc": 594,
"file": "./src/main.ts", "file": "./src/main.ts",
"line": 31, "line": 31,
"col": 28 "col": 38
}, },
{ {
"pc": 600, "pc": 600,
"file": "./src/main.ts", "file": "./src/main.ts",
"line": 31, "line": 31,
"col": 3 "col": 28
}, },
{ {
"pc": 606, "pc": 606,
"file": "./src/main.ts", "file": "./src/main.ts",
"line": 31, "line": 31,
"col": 28
},
{
"pc": 608,
"file": "./src/main.ts",
"line": 31,
"col": 28
},
{
"pc": 614,
"file": "./src/main.ts",
"line": 31,
"col": 28
},
{
"pc": 616,
"file": "./src/main.ts",
"line": 31,
"col": 43
},
{
"pc": 622,
"file": "./src/main.ts",
"line": 31,
"col": 28
},
{
"pc": 628,
"file": "./src/main.ts",
"line": 31,
"col": 28
},
{
"pc": 630,
"file": "./src/main.ts",
"line": 31,
"col": 28
},
{
"pc": 636,
"file": "./src/main.ts",
"line": 31,
"col": 28
},
{
"pc": 638,
"file": "./src/main.ts",
"line": 31,
"col": 28
},
{
"pc": 640,
"file": "./src/main.ts",
"line": 31,
"col": 48
},
{
"pc": 646,
"file": "./src/main.ts",
"line": 31,
"col": 28
},
{
"pc": 652,
"file": "./src/main.ts",
"line": 31,
"col": 28
},
{
"pc": 654,
"file": "./src/main.ts",
"line": 31,
"col": 28
},
{
"pc": 656,
"file": "./src/main.ts",
"line": 31,
"col": 3
},
{
"pc": 662,
"file": "./src/main.ts",
"line": 31,
"col": 3 "col": 3
} }
] ]

View File

@ -0,0 +1,5 @@
#!/bin/bash
./prometeu-sdk/prometeu build .
cp build/program.pbc cartridge
./prometeu-sdk/prometeu run cartridge

View File

@ -1,12 +1,13 @@
export function tick(): void { function do_init_gfx(): void {
gfx.clear(color.indigo); gfx.clear(color.indigo);
gfx.fillRect(10, 10, 50, 50, color.red); gfx.fillRect(10, 10, 50, 50, color.red);
gfx.drawLine(0, 0, 128, 128, color.white); gfx.drawLine(0, 0, 128, 128, color.white);
gfx.drawCircle(64, 64, 20, color.blue); gfx.drawCircle(64, 64, 20, color.blue);
gfx.drawDisc(100, 100, 10, color.green, color.yellow); gfx.drawDisc(100, 100, 10, color.green, color.yellow);
gfx.drawSquare(20, 100, 30, 30, color.cyan, color.color_key); gfx.drawSquare(20, 100, 30, 30, color.cyan, color.color_key);
}
function do_pad(): void {
if (pad.up.down) { if (pad.up.down) {
log.write(2, "Up is down"); log.write(2, "Up is down");
} }
@ -14,11 +15,15 @@ export function tick(): void {
if (pad.a.pressed) { if (pad.a.pressed) {
audio.playSample(1, 0, 255, 128, 1.0); audio.playSample(1, 0, 255, 128, 1.0);
} }
}
function do_touch(): void {
if (touch.button.down) { if (touch.button.down) {
gfx.drawCircle(touch.x, touch.y, 5, color.white); gfx.drawCircle(touch.x, touch.y, 5, color.white);
} }
}
function do_fs(): void {
let h = fs.open("test.txt"); let h = fs.open("test.txt");
if (h >= 0) { if (h >= 0) {
fs.write(h, "Hello Prometeu!"); fs.write(h, "Hello Prometeu!");
@ -26,6 +31,13 @@ export function tick(): void {
if (content) log.writeTag(2, 101, content); if (content) log.writeTag(2, 101, content);
fs.close(h); fs.close(h);
} }
}
export function tick(): void {
do_init_gfx();
do_pad();
do_touch();
do_fs();
let c = color.rgb(255, 128, 0); let c = color.rgb(255, 128, 0);
gfx.fillRect(0, 0, 5, 5, c); gfx.fillRect(0, 0, 5, 5, c);