diff --git a/Programs/Libraries/math.asm b/Programs/Libraries/math.asm new file mode 100644 index 0000000..bb277fe --- /dev/null +++ b/Programs/Libraries/math.asm @@ -0,0 +1,63 @@ +; A library of math subroutines for SplitBit. + +#Program + +int16add: + ; Add two two-byte unsigned integers. + ; Operands are stored in a four-byte array in the following order: + ; Operand A, high byte + ; Operand A, low byte + ; Operand B, high byte + ; Operand B, low byte + ; The result is stored by overwriting Operand A. + ; This subroutine expects the Data Pointer to be set to the start of the array. + ; After execution, this routine leaves the data pointer set to the high byte of the result. + ; If the addtion results in a carry, the carry flag will be set. + CCF ; Clear the Carry Flag, just in case. + DPUP 0d03 ; Move to Operand B's low byte. + LDB ; Load it to B. + DPDN 0d02 ; Move to Operand A's low byte. + LDA ; Load it to A. + ADD ; Add them together. + STQ ; Store the result. + INCD ; Go to Operand B's high byte. + LDB ; Load it to B. + DPDN 0d02 ; Go to Operand A's high byte. + LDA ; Load it to A. + ADD ; Add them together. + STQ ; Store the result. + RET ; Return to the caller. + +int16sub: + ; Subtract two two-byte unsigned integers. + ; Operands are stored in a four-byte array in the following order: + ; Operand A, high byte + ; Operand A, low byte + ; Operand B, high byte + ; Operand B, low byte + ; Operand B is subtracted from Operand A and the result is stored by overwriting Operand A. + ; This subroutine expects the Data Pointer to be set to the start of the array. + ; After execution, this routine leaves the data pointer set to the high byte of the result. + ; If the addtion results in a carry, the carry flag will be set. + CCF ; Clear the Carry Flag, just in case. + DPUP 0d03 ; Move to Operand B's low byte. + LDB ; Load it to B. + DPDN 0d02 ; Move to Operand A's low byte. + LDA ; Load it to A. + SUB ; Subtract B from A. + STQ ; Store the result. + INCD ; Go to Operand B's high byte. + LDB ; Load it to B. + DPDN 0d02 ; Go to Operand A's high byte. + LDA ; Load it to A. + SUB ; Subtract B from A. + STQ ; Store the result. + RET ; Return to the caller. + +#Data + +Int16operands: + 0x00 ; Operand A high byte. + 0x00 ; Operand A low byte. + 0x00 ; Operand B high byte. + 0x00 ; Operand B low byte. diff --git a/Programs/Libraries/print.asm b/Programs/Libraries/print.asm index 468647a..56475ac 100644 --- a/Programs/Libraries/print.asm +++ b/Programs/Libraries/print.asm @@ -32,7 +32,7 @@ printString: ; Expects Data Pointer to be set to the beginning of INCD ; Increment Data Pointer to the next character. BRI printString ; Branch to the beginning of the loop. printDone: - RET ; Return to the caller. + RET ; Return to the caller. ; Expects A to contain the value to be printed in decimal form. printByteDecimal: @@ -132,6 +132,8 @@ DecimalValue: 0x00 ; The tens place. 0x00 ; The hundreds place. +; For convenience, I'll pad this out so programs using this library store their data in a fresh page of memory. + 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 diff --git a/Programs/primeSieve/8bitSieve.asm b/Programs/primeSieve/8bitSieve.asm index cba2716..da77bca 100644 --- a/Programs/primeSieve/8bitSieve.asm +++ b/Programs/primeSieve/8bitSieve.asm @@ -8,8 +8,8 @@ start: ; Search the list until we find a prime. SETD DataTop CCF ; Clear the carry flag. In later cycles, the carry flag will be set at the end of the next loop. We'll want it cleared. - INIA 0x00 - INIB 0x00 + RSTA + RSTB findPrimeLoop: LDB ; Load an element into B. BRB foundPrime ; If it's zero, it's a prime. diff --git a/Programs/testPrograms/inputTest.asm b/Programs/testPrograms/inputTest.asm new file mode 100644 index 0000000..046c909 --- /dev/null +++ b/Programs/testPrograms/inputTest.asm @@ -0,0 +1,55 @@ +; This program asks the user for input, then prints whatever they input back to the console again. +; It stores the input string in a buffer in the Data Memory. + +#Include ../Libraries/print.asm + +#Program + +start: + SETD Message0 ; Set the Data Pointer to the explanation message. + CALL printString ; Print it out. + CALL lineFeed + SETD Buffer ; Set the Data Pointer to the start of the buffer. + INIB 0x0A ; Load the value of a linefeed into B. + inputLoop: + INA 0x00 ; Poll the command line. + CCF + SUB + BRQ inputEnd ; If we encountered a linefeed, the string is over, proceed to processing. + STA ; Store A into the buffer. + INCD ; Increment to the next spot in the buffer. + BRI inputLoop ; Loop again to grab more string. + inputEnd: + INIA 0x00 ; Set A to 0. + STA ; Store it in the buffer. + SETD Buffer ; Set the Data Pointer to the start of the buffer again. + CALL printString ; Print it out. + CALL lineFeed + HALT ; End the program. + +#Data + +; A 256 character buffer for the input string. +; There will need to be some kind of way to define large arrays better than this... +Buffer: +0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 +0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 +0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 +0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 +0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 +0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 +0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 +0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 +0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 +0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 +0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 +0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 +0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 +0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 +0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 +0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 + +Message0: + "Input Test: Will echo anything you put in." + + diff --git a/Programs/testPrograms/mathTest.asm b/Programs/testPrograms/mathTest.asm new file mode 100644 index 0000000..42b17d2 --- /dev/null +++ b/Programs/testPrograms/mathTest.asm @@ -0,0 +1,27 @@ +; A test for the new math subroutines. + +#Include ../Libraries/print.asm +#Include ../Libraries/math.asm + +#Program + start: + SETD SomeInt16Operands + CALL int16sub + BRC end + LDA + CALL printByteHex + INCD + LDA + CALL printByteHex + INIA 0x3A + OUTA 0x00 + BRI start + end: + CALL lineFeed + HALT + +#Data + +SomeInt16Operands: + 0xFF 0xFF + 0x00 0x01