Compare commits
No commits in common. "481301023e26fc919dd9f9206369ac485670728a" and "5221fe45d9376a03df0b77ae4065b6a6195b48eb" have entirely different histories.
481301023e
...
5221fe45d9
102
assembler.rb
102
assembler.rb
|
@ -22,46 +22,9 @@ def string(s)
|
|||
end
|
||||
|
||||
|
||||
# # # REGISTER NAMES # # #
|
||||
def at() 1 end # assembler temporary
|
||||
|
||||
# subroutine return values, may be changed by subroutines
|
||||
def v0() 2 end ; def v0() 3 end
|
||||
|
||||
# subroutine arguments, may be changed by subroutines
|
||||
def a0() 4 end ; def a1() 5 end
|
||||
def a2() 6 end ; def a3() 7 end
|
||||
|
||||
# temporaries, may be changed by subroutines
|
||||
def t0() 8 end ; def t1() 9 end
|
||||
def t2() 10 end ; def t3() 11 end
|
||||
def t4() 12 end ; def t5() 13 end
|
||||
def t6() 14 end ; def t7() 15 end
|
||||
|
||||
# static variables, must be saved by subs
|
||||
def s0() 16 end ; def s1() 17 end
|
||||
def s2() 18 end ; def s3() 19 end
|
||||
def s4() 20 end ; def s5() 21 end
|
||||
def s6() 22 end ; def s7() 23 end
|
||||
|
||||
# temporaries, may be changed by subroutines
|
||||
def t8() 24 end ; def t9() 25 end
|
||||
|
||||
# reserved for kernel, detroyed by some irq handlers
|
||||
def k0() 26 end ; def k1() 27 end
|
||||
|
||||
def gp() 28 end # global pointer, rarely used
|
||||
def sp() 29 end # stack pointer
|
||||
def fp() 30 end # frame pointer
|
||||
def ra() 31 end # return address
|
||||
|
||||
|
||||
|
||||
# # # INSTRUCTIONS # # #
|
||||
|
||||
# ops should always be in format of
|
||||
# [src] [args] -> [dest]
|
||||
|
||||
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
|
||||
|
@ -82,7 +45,7 @@ end
|
|||
# load upper immediate
|
||||
# NOTE: val will be shifted left by 16
|
||||
def lui(val, dest)
|
||||
# oooooo ----- ddddd iiiiiiiiiiiiiiii
|
||||
# oooooo ----- ttttt iiiiiiiiiiiiiiii
|
||||
op = 0b001111_00000_00000_0000000000000000
|
||||
op |= 0xffff & val
|
||||
op |= (0b11111 & dest) << 16
|
||||
|
@ -105,20 +68,10 @@ def ori(src, bits, dest)
|
|||
op = 0b001101_00000_00000_00000000_00000000
|
||||
op |= (src & 0b11111) << 21
|
||||
op |= (bits & 0xffff)
|
||||
op |= (dest & 0b11111) << 16
|
||||
op |= (dest & 0x11111) << 16
|
||||
word op
|
||||
end
|
||||
|
||||
# store word
|
||||
# NOTE: this doesn't work unaligned
|
||||
def sw(src, offset, dest)
|
||||
# oooooo ddddd sssss iiiiiiii iiiiiiii
|
||||
op = 0b101011_00000_00000_00000000_00000000
|
||||
op |= (src & 0b11111) << 16
|
||||
op |= (offset & 0xffff)
|
||||
op |= (dest & 0b11111) << 21
|
||||
word op
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
@ -127,20 +80,9 @@ def nop
|
|||
word 0x00000000
|
||||
end
|
||||
|
||||
# load word immediate
|
||||
def lwi(val, dest)
|
||||
lui val >> 16, dest
|
||||
ori dest, val, dest
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
def label
|
||||
return $bytes.length + $base_addr
|
||||
end
|
||||
|
||||
# this is a terrible idea and im doing it
|
||||
#$labels = {}
|
||||
#def method_missing(m, *args)
|
||||
|
@ -151,9 +93,8 @@ end
|
|||
|
||||
# # # CONSTANTS # # #
|
||||
$base_addr = 0x80010000 # 0x10000 # 0x80010000
|
||||
$file_size = 0x800 * 3
|
||||
$file_size = 0x800
|
||||
$gp0 = 0x1F801810
|
||||
$gp1 = 0x1F801814
|
||||
|
||||
# # # EXE HEADER # # #
|
||||
string "PS-X EXE"
|
||||
|
@ -178,49 +119,20 @@ $bytes = []
|
|||
|
||||
|
||||
# # # PROGRAM CODE # # #
|
||||
nop
|
||||
nop ; jmp $base_addr + 16 ; nop ; word 0xdeadbeef
|
||||
|
||||
# ops should always be in format of
|
||||
# src [args] -> dest
|
||||
|
||||
# THIS IS NEEDED
|
||||
lwi $gp1, t0
|
||||
lwi 0x03_00_00_00, t1 # display enable
|
||||
sw t1, 0, t0
|
||||
|
||||
lwi $gp0, t0
|
||||
|
||||
lwi 0xe1_000000 + 0b0_0_0_1_0_01_00_0_0000, t1
|
||||
sw t1, 0, t0
|
||||
|
||||
# THIS IS NEEDED
|
||||
lwi 0xe4_000000 + (640) + (480 << 10), t1 # Drawing Area bottom right
|
||||
sw t1, 0, t0
|
||||
|
||||
def line(st, en)
|
||||
lwi 0x40_ffffff, t1 # monochrome line, color ffffff
|
||||
sw t1, 0, t0
|
||||
|
||||
lwi st, t1 # line vert 1
|
||||
sw t1, 0, t0
|
||||
|
||||
lwi en, t1 # line vert 2
|
||||
sw t1, 0, t0
|
||||
end
|
||||
|
||||
l_end_loop = label
|
||||
line 0x0010_0010, 0x0030_0030
|
||||
line 0x0030_0030, 0x0060_0000
|
||||
line 0x0060_0000, 0x00f0_0060
|
||||
lui $gp0 >> 16, 1
|
||||
ori 1, $gp0, 1
|
||||
|
||||
nop ; nop ; nop ; nop
|
||||
nop ; nop ; nop ; nop
|
||||
nop ; nop ; nop ; nop
|
||||
nop ; nop ; nop ; nop
|
||||
|
||||
# l_end_loop = label
|
||||
nop
|
||||
jmp l_end_loop
|
||||
jmp $base_addr
|
||||
nop
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue