game fix
This commit is contained in:
parent
8a8c347962
commit
9441581e8f
@ -15,7 +15,7 @@ LDSCRIPT := $(SRCDIR)/game.ld
|
||||
SRC := $(foreach sdir, $(SRCDIR), $(wildcard $(sdir)/*.S))
|
||||
OBJ := $(patsubst $(SRCDIR)/%.S, $(OBJDIR)/%.o, $(SRC))
|
||||
TARGET := $(OBJDIR)/game.elf
|
||||
ASFLAG := -D__ASSEMBLY__ -EL -g -mips32r2 -mno-abicalls -mno-shared
|
||||
ASFLAG := -D__ASSEMBLY__ -EL -g -mips32r2 -mno-abicalls -mno-shared -g
|
||||
|
||||
.PHONY: all clean checkdirs generate sim
|
||||
|
||||
|
@ -155,7 +155,7 @@ kb_readbuffer:
|
||||
9:
|
||||
slt t0, ball_x, t6
|
||||
beqz t0, 10f
|
||||
slti t1, WIDTH, ball_x
|
||||
nop
|
||||
la a0, UART1
|
||||
li a1, KB_SCORE
|
||||
jal WRITESERIAL
|
||||
@ -165,7 +165,8 @@ kb_readbuffer:
|
||||
j 14f
|
||||
sub ball_dx, zero, ball_dx
|
||||
10:
|
||||
beqz t1, 11f
|
||||
slti t1, ball_x, WIDTH + 1
|
||||
bnez t1, 11f
|
||||
addi t0, ball_x, -player1_x
|
||||
lui t1, %hi(score)
|
||||
lui t2, %hi(SEG7) + 1
|
||||
@ -195,18 +196,20 @@ kb_readbuffer:
|
||||
bgez t3, 14f
|
||||
sll t1, random, 13
|
||||
13:
|
||||
andi random, random, t1
|
||||
and random, random, t1
|
||||
sra t1, random, 7
|
||||
andi random, random, t1
|
||||
xori random, random, t5
|
||||
and random, random, t1
|
||||
xor random, random, t5
|
||||
sra t3, random, 2
|
||||
la t2, spx_table
|
||||
andi t3, t3, 0x7
|
||||
lw ball_spx, t3(t2)
|
||||
add t3, t3, t2
|
||||
lw ball_spx, 0(t3)
|
||||
sra t3, random, 5
|
||||
la t2, spy_table
|
||||
andi t3, t3, 0x7
|
||||
lw ball_spy, t3(t2)
|
||||
add t3, t3, t2
|
||||
lw ball_spy, 0(t3)
|
||||
sub ball_dx, zero, ball_dx
|
||||
14:
|
||||
j GAME_START
|
||||
|
@ -10,6 +10,7 @@
|
||||
.section .rodata
|
||||
.p2align 2
|
||||
|
||||
.global pingpong
|
||||
pingpong:
|
||||
.asciz "Ping Pong.\n"
|
||||
|
||||
|
@ -5,9 +5,21 @@
|
||||
.set noreorder
|
||||
.set noat
|
||||
|
||||
.section .text.ebase
|
||||
.p2align 2
|
||||
|
||||
la a0, UART0
|
||||
la a1, pingpong
|
||||
jal PRINT
|
||||
nop
|
||||
|
||||
.section .text.ebase180
|
||||
.p2align 2
|
||||
|
||||
la a0, UART0
|
||||
la a1, pingpong
|
||||
jal PRINT
|
||||
nop
|
||||
|
||||
mfc0 k1, CP0_STATUS
|
||||
la k0, 0
|
||||
@ -143,6 +155,10 @@ RESTART_SAVE:
|
||||
|
||||
.global RESTART_LOAD
|
||||
RESTART_LOAD:
|
||||
la a0, UART0
|
||||
la a1, pingpong
|
||||
jal PRINT
|
||||
nop
|
||||
lui k0, %hi(next_thread)
|
||||
lui k1, %hi(current_thread)
|
||||
lw k0, %lo(next_thread)(k0)
|
||||
|
119
resources/ping-pong-mips32/term/spv.py
Normal file
119
resources/ping-pong-mips32/term/spv.py
Normal file
@ -0,0 +1,119 @@
|
||||
import argparse
|
||||
import struct
|
||||
import serial
|
||||
|
||||
matrix = [[0] * 81 for _ in range(25)]
|
||||
pos = [0, 0, 0, 0] # p1y p2y bx by
|
||||
|
||||
|
||||
def init_serial(pipe_path, baudrate):
|
||||
global tty
|
||||
tty = serial.serial_for_url('loop://')
|
||||
return True
|
||||
tty = serial.Serial(port=pipe_path, baudrate=baudrate)
|
||||
tty.reset_input_buffer()
|
||||
return True
|
||||
|
||||
|
||||
def print_map():
|
||||
print("\033c", end="")
|
||||
ball = '◯'
|
||||
bat = '▮'
|
||||
border = '□'
|
||||
|
||||
print(hello)
|
||||
for i in range(83):
|
||||
print(border, end='')
|
||||
print()
|
||||
for i in matrix:
|
||||
print(border, end='')
|
||||
for j in i:
|
||||
if j == 0:
|
||||
print(' ', end='')
|
||||
elif j == 1:
|
||||
print(bat, end='')
|
||||
else:
|
||||
print(ball, end='')
|
||||
print(border)
|
||||
for i in range(83):
|
||||
print(border, end='')
|
||||
print()
|
||||
|
||||
|
||||
def clear_map():
|
||||
matrix[pos[0]][0] = 0
|
||||
if pos[0] < 24:
|
||||
matrix[pos[0] + 1][0] = 0
|
||||
|
||||
matrix[pos[1]][80] = 0
|
||||
if pos[1] < 24:
|
||||
matrix[pos[1] + 1][80] = 0
|
||||
|
||||
matrix[pos[3]][pos[2]] = 0
|
||||
|
||||
|
||||
def update_map():
|
||||
matrix[pos[0]][0] = 1
|
||||
if pos[0] < 24:
|
||||
matrix[pos[0] + 1][0] = 1
|
||||
|
||||
matrix[pos[1]][80] = 1
|
||||
if pos[1] < 24:
|
||||
matrix[pos[1] + 1][80] = 1
|
||||
|
||||
matrix[pos[3]][pos[2]] = 2
|
||||
|
||||
|
||||
def main():
|
||||
global hello
|
||||
hello = tty.readline()[:-1].decode('utf-8')
|
||||
|
||||
pause = False
|
||||
while True:
|
||||
line = tty.readline()
|
||||
if len(line) < 7 or line[0] != ord('<') or line[-2] != ord('>'):
|
||||
continue
|
||||
line = line[1:-2]
|
||||
|
||||
if line[0] == ord('r'):
|
||||
pause = False
|
||||
print_map()
|
||||
continue
|
||||
if pause:
|
||||
continue
|
||||
if line[0] == ord('p'):
|
||||
pause = True
|
||||
print('>>>')
|
||||
continue
|
||||
|
||||
if len(line) != 4:
|
||||
continue
|
||||
|
||||
clear_map()
|
||||
pos[0] = 24 - (line[0] - 129)
|
||||
pos[1] = 24 - (line[1] - 129)
|
||||
pos[2] = line[2] - 129
|
||||
pos[3] = 24 - (line[3] - 129)
|
||||
update_map()
|
||||
print_map()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
parser = argparse.ArgumentParser(description='Ping Pong MIPS UI')
|
||||
parser.add_argument('-s', '--serial', default='com3', type=str,
|
||||
help='Serial port name (e.g. /dev/ttyACM0, COM3)')
|
||||
parser.add_argument('-b', '--baud', default=57600, type=int,
|
||||
help='Serial port baud rate')
|
||||
args = parser.parse_args()
|
||||
|
||||
if not init_serial(args.serial, args.baud):
|
||||
print('Failed to open serial port')
|
||||
exit(1)
|
||||
|
||||
# tty.write('Hello World\n'.encode('utf-8'))
|
||||
# tty.write(serial.to_bytes([ord('<'), 128 + 3, 128 + 12, 128 + 40, 128 + 15, ord('>'), 0x0a]))
|
||||
# tty.write('<pause>\n'.encode('utf-8'))
|
||||
# tty.write('<resume>\n'.encode('utf-8'))
|
||||
# tty.write(serial.to_bytes([ord('<'), 128 + 25, 128 + 25, 128 + 81, 128 + 25, ord('>'), 0x0a]))
|
||||
|
||||
main()
|
Loading…
Reference in New Issue
Block a user