summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authormrb0nk500 <b0nk@b0nk.xyz>2019-12-14 23:58:01 -0500
committermrb0nk500 <b0nk@b0nk.xyz>2019-12-14 23:58:01 -0500
commit0b81224b6ab8cd6da45039525962c6490ed2df56 (patch)
treea76bfa10ee6ae726efb212442a68c17b253b49ba /test
parentc6d71bcf0e545a490fdeb0dfcafea2d5a02157c6 (diff)
We now have keyboard support!!!
I also added the WAI instruction, which puts the thread that executed it, into a catatonic stat, where it can't do anything, until an interrupt occurs. I will be starting work on GFsuX next. I also might start work on SuBAsm, the Sux Bootstrapping Assembler.
Diffstat (limited to 'test')
-rw-r--r--test/hello-world.s5
-rw-r--r--test/input.s127
2 files changed, 132 insertions, 0 deletions
diff --git a/test/hello-world.s b/test/hello-world.s
index 465583c..9138bc7 100644
--- a/test/hello-world.s
+++ b/test/hello-world.s
@@ -6,6 +6,11 @@
string:
.byte "Hello, world!\n"
+; Text buffer.
+.org $2000
+buffer:
+
+
; Get CPU into a known state.
.org $0
reset:
diff --git a/test/input.s b/test/input.s
new file mode 100644
index 0000000..9e5ef69
--- /dev/null
+++ b/test/input.s
@@ -0,0 +1,127 @@
+; Testing input.
+;
+; Writen in Sux assembly by
+; mr b0nk 500 <b0nk@b0nk.xyz>
+
+
+; Initalize some variables.
+.org $1000
+string:
+ .byte "Please, type something.\n"
+string2:
+ .byte "You typed, "
+end:
+ .byte $0
+
+; Input buffer.
+.org $2000
+buffer:
+
+; Main program
+.org $0
+reset:
+ cps
+ ldx.w #$FFFF
+ txs
+ ldy #$0
+clr_buf:
+ lda #$0
+ cpy.w #$1000
+ beq start
+ sta buffer, y
+ iny
+ jmp clr_buf
+
+start:
+ ldx.w #$0 ; Reset x.
+ ldy #$0 ; Reset y.
+ jmp print
+
+sleep:
+ wai ; Sleep until we get a character.
+ lda end
+ bne spin ; Are we done with getting input?
+ jmp sleep ; Loop until we get a newline.
+
+print:
+ lda string, x ; Get character at offset x.
+ beq sleep ; Did we find a null terminator?
+ sta $C001 ; Print character.
+ inx ; Increment offset.
+ jmp print ; Keep printing more characters.
+
+irq_routine:
+ lda $C002 ; Get typed character.
+ cmp #$A
+ beq nl ; Did the user type a newline?
+ cmp #$8
+ beq bs ; Did the user type a backspace?
+echo:
+ sta $C001 ; Echo typed character.
+ sta buffer, y ; Store typed character into the input buffer.
+ iny ; Increment buffer offset.
+return:
+ rti ; End of interrupt routine.
+
+nl:
+ sta $C001
+ lda #$0 ; Replace newline with a null terminator.
+ sta buffer, y ; Store said terminator into the input buffer.
+ ldy.w #$0 ; Reset y, to print the result.
+ jmp result
+
+bs:
+ cpy #$0
+ beq return ; Are we at the start of the buffer?
+ jmp echo ; We are not, so add the backspace to the buffer.
+
+result:
+ lda string2, y
+ beq rset_y ; Reset y, if we hit the null terminator.
+ sta $C001 ; Print 'You have typed, '
+ iny ; Increment offset.
+ jmp result ; Keep printing.
+
+rset_y:
+ ldy.w #$0
+ jmp print_buf ; Print the input buffer.
+
+print_buf:
+ lda buffer, y ; Get a character from the input buffer.
+ beq fin ; Are we done with printing the buffer?
+ sta $C001 ; Print said character.
+ iny
+ jmp print_buf ; Keep printing the buffer.
+
+fin:
+ lda #$A ; Load a newline.
+ sta $C001 ; Print the newline.
+ lda #$1 ; Tell the program that we are done.
+ sta end ; We are done.
+
+
+spin:
+ nop
+ nop
+ nop
+ jmp spin
+
+.org $FFC0
+.qword reset
+
+.org $FF50
+.qword spin
+.qword spin
+.qword spin
+.qword spin
+.qword spin
+.qword spin
+.qword spin
+
+.org $FFA0
+.qword irq_routine
+;.org $0
+;viewmem
+;q
+done
+