diff --git a/assembler.rb b/assembler.rb new file mode 100644 index 0000000..2e29438 --- /dev/null +++ b/assembler.rb @@ -0,0 +1,83 @@ + +$bytes = [] + +def zero_fill(pos) + while ($bytes.length <= pos) do + $bytes.push(0) + end +end + +def int(i) + $bytes.push((i & 0x000000ff), + (i & 0x0000ff00) >> 8, + (i & 0x00ff0000) >> 16, + (i & 0xff000000) >> 24) +end + +def string(s) + $bytes.push *s.bytes + while (($bytes.length % 4) != 0) do + $bytes.push 0 + end +end + +def jmp(addr) + # TODO: this probs wont show up since we have < 3mb of ram but + # we can't jump to an address with a different 4 most significant bits + raise "jmp addr must be 4 byte aligned" if addr % 4 != 0 + op = 0b0000_1000_0000_0000_0000_0000_0000_0000 + op = op | ((addr >> 2) & 0b11_11111111_11111111_11111111) + int op +end + +def jal(addr) + # TODO: same problem as jmp + raise "jmp addr must be 4 byte aligned" if addr % 4 != 0 + op = 0b0000_1100_0000_0000_0000_0000_0000_0000 + op = op | ((addr >> 2) & 0b11_11111111_11111111_11111111) + int op +end + +def nop + int 0x00000000 +end + +$base_addr = 0x80010000 # 0x10000 # 0x80010000 + +string "PS-X EXE" +zero_fill 0x00f +int $base_addr # initial pc +int 0x00000000 # initial GP/R28 +int $base_addr # destintation address in RAM +int 0x800 # file size excluding header (must be N * 0x800) +int 0x00000000 # Unknown/Unused +int 0x00000000 # Unknown/Unused +int 0x00000000 # Memfill start address +int 0x00000000 # Memfill size in bytes +int 0x801ffff0 # Initial SP/R29 & FP/R30 Base +int 0x00000000 # Initial SP/R29 & FP/R30 Offs +zero_fill 0x4b # Reserved for A(43h) Function +# Ascii marker would go here +zero_fill 0x7ff + +# code +nop +nop +jal $base_addr +nop # nop (is always exec'd bc mips) + +string "this is a test lol" +int 0xFFAAFFAA + +zero_fill 0xfff + +f = File.new "LOADTHIS.EXE", "wb" +f.write $bytes.pack("C*") +f.close + + + + + + +