Compare commits

..

4 Commits

Author SHA1 Message Date
bx 481301023e we now have lines! 2021-08-31 17:32:08 +01:00
bx d5fbe1a89b added register names, base on no$ docs 2021-08-31 11:13:55 +01:00
bx 19e844f43e added load word immediate(lwi) pseudo-instruction 2021-08-31 10:50:42 +01:00
bx b666aa05e9 fixed bug in ori encoding 2021-08-31 10:37:09 +01:00
1 changed files with 95 additions and 7 deletions

View File

@ -22,9 +22,46 @@ def string(s)
end 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 # # # # # # INSTRUCTIONS # # #
# ops should always be in format of
# [src] [args] -> [dest]
def jmp(addr) def jmp(addr)
# TODO: this probs wont show up since we have < 3mb of ram but # 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 # we can't jump to an address with a different 4 most significant bits
@ -45,7 +82,7 @@ end
# load upper immediate # load upper immediate
# NOTE: val will be shifted left by 16 # NOTE: val will be shifted left by 16
def lui(val, dest) def lui(val, dest)
# oooooo ----- ttttt iiiiiiiiiiiiiiii # oooooo ----- ddddd iiiiiiiiiiiiiiii
op = 0b001111_00000_00000_0000000000000000 op = 0b001111_00000_00000_0000000000000000
op |= 0xffff & val op |= 0xffff & val
op |= (0b11111 & dest) << 16 op |= (0b11111 & dest) << 16
@ -68,10 +105,20 @@ def ori(src, bits, dest)
op = 0b001101_00000_00000_00000000_00000000 op = 0b001101_00000_00000_00000000_00000000
op |= (src & 0b11111) << 21 op |= (src & 0b11111) << 21
op |= (bits & 0xffff) op |= (bits & 0xffff)
op |= (dest & 0x11111) << 16 op |= (dest & 0b11111) << 16
word op word op
end 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
@ -80,9 +127,20 @@ def nop
word 0x00000000 word 0x00000000
end 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 # this is a terrible idea and im doing it
#$labels = {} #$labels = {}
#def method_missing(m, *args) #def method_missing(m, *args)
@ -93,8 +151,9 @@ end
# # # CONSTANTS # # # # # # CONSTANTS # # #
$base_addr = 0x80010000 # 0x10000 # 0x80010000 $base_addr = 0x80010000 # 0x10000 # 0x80010000
$file_size = 0x800 $file_size = 0x800 * 3
$gp0 = 0x1F801810 $gp0 = 0x1F801810
$gp1 = 0x1F801814
# # # EXE HEADER # # # # # # EXE HEADER # # #
string "PS-X EXE" string "PS-X EXE"
@ -119,20 +178,49 @@ $bytes = []
# # # PROGRAM CODE # # # # # # PROGRAM CODE # # #
nop ; jmp $base_addr + 16 ; nop ; word 0xdeadbeef nop
# ops should always be in format of # ops should always be in format of
# src [args] -> dest # src [args] -> dest
lui $gp0 >> 16, 1 # THIS IS NEEDED
ori 1, $gp0, 1 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
nop ; nop ; nop ; nop nop ; nop ; nop ; nop
nop ; nop ; nop ; nop nop ; nop ; nop ; nop
nop ; nop ; nop ; nop nop ; nop ; nop ; nop
nop ; nop ; nop ; nop nop ; nop ; nop ; nop
jmp $base_addr # l_end_loop = label
nop
jmp l_end_loop
nop nop