summaryrefslogtreecommitdiff
path: root/assembly/win95
diff options
context:
space:
mode:
Diffstat (limited to 'assembly/win95')
-rw-r--r--assembly/win95/Makefile24
l---------assembly/win95/rvcontroller.ld1
-rw-r--r--assembly/win95/win95.S161
3 files changed, 186 insertions, 0 deletions
diff --git a/assembly/win95/Makefile b/assembly/win95/Makefile
new file mode 100644
index 0000000..007e470
--- /dev/null
+++ b/assembly/win95/Makefile
@@ -0,0 +1,24 @@
+MARCH ?= rv32imacbzicntr_zicond_zicsr_zifencei_zihintpause_zilsd_zclsd_zabha_zacas_zbkb_zbkx_zcb_zcmp_zcmt
+
+.PHONY: all dump load clean
+
+all: win95.hex
+
+win95.o: win95.S
+ riscv32-none-elf-as -I../rvcontroller-libraries -march=${MARCH} -o win95.o win95.S
+
+win95.elf: win95.o
+ riscv32-none-elf-ld -T rvcontroller.ld --no-warn-rwx-segments -o win95.elf win95.o
+
+dump: win95.elf
+ riscv32-none-elf-objdump -d win95.elf
+
+win95.hex: win95.elf
+ riscv32-none-elf-objcopy -O ihex win95.elf win95.hex
+
+load: win95.hex
+ bash -c "wl-copy < win95.hex"
+
+clean:
+ rm -f win95.hex win95.elf win95.o
+
diff --git a/assembly/win95/rvcontroller.ld b/assembly/win95/rvcontroller.ld
new file mode 120000
index 0000000..bc01402
--- /dev/null
+++ b/assembly/win95/rvcontroller.ld
@@ -0,0 +1 @@
+../../rvcontroller.ld \ No newline at end of file
diff --git a/assembly/win95/win95.S b/assembly/win95/win95.S
new file mode 100644
index 0000000..0ecd394
--- /dev/null
+++ b/assembly/win95/win95.S
@@ -0,0 +1,161 @@
+_start:
+
+# Clear the input buffer
+la t0,inputbuf
+sd x0,0(t0)
+sd x0,2(t0)
+sd x0,4(t0)
+sw x0,6(t0)
+
+# Print "Enter key: " message
+li a7,4
+la a0,keypromptmsg
+ecall
+
+# Read the user's input
+li a7,8
+la a0,inputbuf
+li a1,7
+ecall
+
+# Print it back, followed by a line feed
+li a7,4
+la a0,inputbuf
+ecall
+li a7,11
+li a0,'\n'
+ecall
+
+# Check if all characters are digits
+la t0,inputbuf
+li t1,5
+1:
+add t2,t0,t1
+lb t3,0(t2)
+li t4,0x30 # 0
+blt t3,t4,invalidinput # too low
+li t4,0x39 # 9
+blt t4,t3,invalidinput # too high
+addi t1,t1,-1
+bnez t1,1b
+
+# Convert the key into a decimal number, but backwards
+# Could I make this a loop? Probably. Does it matter? Not really.
+la t0,inputbuf
+
+lb s0,0(t0) # 1s place
+addi s0,s0,-0x30
+
+lb t1,1(t0) # 10s place
+addi t1,t1,-0x30
+li t2,10
+mul t1,t1,t2
+add s0,s0,t1
+
+lb t1,2(t0) # 100s place
+addi t1,t1,-0x30
+li t2,100
+mul t1,t1,t2
+add s0,s0,t1
+
+lb t1,3(t0) # 1000s place
+addi t1,t1,-0x30
+li t2,1000
+mul t1,t1,t2
+add s0,s0,t1
+
+lb t1,4(t0) # 10000s place
+addi t1,t1,-0x30
+li t2,10000
+mul t1,t1,t2
+add s0,s0,t1
+
+lb t1,5(t0) # 100000s place
+addi t1,t1,-0x30
+li t2,100000
+mul t1,t1,t2
+add s0,s0,t1
+
+# Calculate the password
+li t0,0x414d57
+xor s0,s0,t0
+li t0,1000000
+rem s0,s0,t0
+
+# Print out the password one character at a time
+# Yes, RVController has a function to print integers, but I wanted to have some fun here
+li a7,4
+la a0,passwordheadermsg
+ecall
+
+li t0,100000
+div a0,s0,t0
+addi a0,a0,0x30
+li a7,11
+ecall
+
+li t0,10000
+div a0,s0,t0
+li t0,10
+rem a0,a0,t0
+addi a0,a0,0x30
+li a7,11
+ecall
+
+li t0,1000
+div a0,s0,t0
+li t0,10
+rem a0,a0,t0
+addi a0,a0,0x30
+li a7,11
+ecall
+
+li t0,100
+div a0,s0,t0
+li t0,10
+rem a0,a0,t0
+addi a0,a0,0x30
+li a7,11
+ecall
+
+li t0,10
+div a0,s0,t0
+li t0,10
+rem a0,a0,t0
+addi a0,a0,0x30
+li a7,11
+ecall
+
+li t0,10
+rem a0,s0,t0
+addi a0,a0,0x30
+li a7,11
+ecall
+
+# Wait for user to press any key before clearing the screen and restarting
+li a7,4
+la a0,anykeymsg
+ecall
+li a7,8
+la a0,inputbuf
+li a1,7
+ecall
+li a7,4
+la a0,clearscreenmsg
+ecall
+j _start
+
+invalidinput:
+# Print error message and jump back to the start so the user can try again
+li a7,4
+la a0,inputerrormsg
+ecall
+j _start
+
+keypromptmsg: .asciz "Enter key: "
+passwordheadermsg: .asciz "Password: "
+inputerrormsg: .asciz "Invalid entry\n\n"
+anykeymsg: .asciz "\n\nPress any key..."
+clearscreenmsg: .asciz "\n\n\n\n\n\n"
+inputbuf: .skip 7
+.globl _start