コード例 #1
0
ファイル: twitalu_Math_16_2.py プロジェクト: TwitALU/Twitalu
def Rotate_r(num1, num_bits):
	if num_bits > 8: # limits the number of cycles
		num_bits = 8
	OP.SEC(num1 & 0b1)
	for x in range(0, num_bits):
		OP.LDA(num1)
		OP.ROR()
		num1 = OP.STA()
		OP.SEC(ALU.read_C_OUT())
	return(num1, ALU.read_C_OUT())
	
# shift l, rotate r, rotate l
コード例 #2
0
ファイル: twitalu_Math_16_2.py プロジェクト: TwitALU/Twitalu
def Add(num1, num2):
	# Split the two 16 bit input numbers into four 8 bit integers
	num1lo = extract_byte(num1, 'low')
	num1hi = extract_byte(num1, 'high')
	num2lo = extract_byte(num2, 'low')
	num2hi = extract_byte(num2, 'high')
	
	if globals.debug == True:
		print("num1lo: " , num1lo) 
		print("num1hi: " , num1hi << 8) 
		print("num2lo: " , num2lo) 
		print("num2hi: " , num2hi << 8) 
	
	# 6502 Assembly for 16 bit addition
	OP.CLC()			# clear the carry in
	OP.LDA(num1lo)
	cout = OP.ADC(num2lo)
	reslo = OP.STA()	# store sum of LSBs
	if globals.debug == True:
		print("cout1: " , cout)	
	ALU.set_C_IN(cout)
	OP.LDA(num1hi)
	OP.ADC(num2hi)		# add the MSBs using the carry from above
	reshi = OP.STA()	# store sum of MSBs
	cout = ALU.read_C_OUT()
	
	# Debug
	if globals.debug == True:
		print("cout: " , cout)
		print("reslo: " , reslo)
		print("reshi: " , reshi)
	
	# Return result
	return((cout << 16) + (reshi << 8) + reslo)
コード例 #3
0
ファイル: ALU_Test.py プロジェクト: TwitALU/Twitalu
def counter_test():
	numA = 1
	numB = 1
	
	while numB < 256:
		write_register(numA, numB)
		RegADD.clock_data()
		result = RegADD.read_register() + (ALU.read_C_OUT() << 8)
		print(numA, " +", numB, " = ", result)
		if result != (numA + numB):
			print("NumA: ", numA)
			print("Numb: ", numB)
			print("NumA: ", result)
			break
		numB += 1
		time.sleep(delayTime)
コード例 #4
0
ファイル: twitalu_OPCODES.py プロジェクト: TwitALU/Twitalu
def ADC(addend): # ADd with Carry
	# Write to register A
	RegA.write_register(addend)
	
	# Activate Adder Output
	ALU.unset_all()
	ALU.set_ADD(1)
	
	# Read result
	C_OUT = ALU.read_C_OUT()
	RegADD.clock_data()
	SUM = RegADD.read_register()
	
	# Store result in Accumulator
	LDA(SUM)
	
	return(C_OUT)
コード例 #5
0
ファイル: twitalu_OPCODES.py プロジェクト: TwitALU/Twitalu
def AND(num): # bitwise AND with accumulator
	# Write to register A
	RegA.write_register(num)
	
	# Activate AND output
	ALU.unset_all()
	ALU.set_AND(1)
	
	# Read result
	C_OUT = ALU.read_C_OUT()
	RegADD.clock_data()
	AND = RegADD.read_register()
	
	# Store result in Accumulator
	LDA(AND)

	return(C_OUT)
コード例 #6
0
ファイル: twitalu_OPCODES.py プロジェクト: TwitALU/Twitalu
def SBC(subtrahend): # SuBtract with Carry
	# Locally store Accumulator
	minuend = STA()
	
	# Invert the subtrahend
	# RegB.write_inverted_register(subtrahend)	
	RegB.write_inverted_register(subtrahend)
	
	# Add 1 to the inverted subtrahend. Result is 2's complement
	ADC(1)
	twos_comp = STA()
	
	# Add the result of step 2 to the minuend
	LDA(minuend)
	ADC(twos_comp)
	
	C_OUT = ALU.read_C_OUT()
	
	return(C_OUT)	
コード例 #7
0
ファイル: twitalu_OPCODES.py プロジェクト: TwitALU/Twitalu
def BCC(): # Branch on Carry Clear
	carry = ALU.read_C_OUT()
	if carry == 0:
		return(True)
	else:
		return(False)