summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/add-sub.s2
-rw-r--r--test/fib2.s14
-rw-r--r--test/hello-world.s22
-rw-r--r--test/input-2.s412
-rw-r--r--test/input-3.s900
-rw-r--r--test/input.s338
-rw-r--r--test/subroutine.s4
-rw-r--r--test/test.s17
8 files changed, 29 insertions, 1680 deletions
diff --git a/test/add-sub.s b/test/add-sub.s
index 694931d..3dfdca4 100644
--- a/test/add-sub.s
+++ b/test/add-sub.s
@@ -8,7 +8,7 @@ reset:
cps ; Clear the processor status register.
ldx.w #$FFFF ; Reset the stack pointer.
txs ;
- lsr #16 ; Reset A.
+ and #0 ; Reset A.
tab ; Reset B.
tax ; Reset X.
up:
diff --git a/test/fib2.s b/test/fib2.s
index 59830a2..9bb2406 100644
--- a/test/fib2.s
+++ b/test/fib2.s
@@ -1,19 +1,9 @@
-; Variables for thread 0.
-.org $1000
-x:
- .qword 0
-y:
- .qword 1
-z:
- .qword 0
-zero:
- .qword 0
.org 0
init:
cps ; Clear the Processor Status register.
start:
- lsr #63 ; Reset the accumulator.
+ and #0 ; Reset the accumulator.
tab ;
tax ;
tay ;
@@ -30,4 +20,4 @@ fib:
tay ;
jmp fib ; No, so keep looping.
a
-done
+d
diff --git a/test/hello-world.s b/test/hello-world.s
index 9138bc7..f3b540a 100644
--- a/test/hello-world.s
+++ b/test/hello-world.s
@@ -1,8 +1,12 @@
; Hello world.
; Writen in Sux assembly by mr b0nk 500 <b0nk@b0nk.xyz>
+status = $100 ; Status.
+scr = $101 ; Screen output.
+
+
; Initialize, and declare variables.
-.org $8000
+.org $A000
string:
.byte "Hello, world!\n"
@@ -12,7 +16,7 @@ buffer:
; Get CPU into a known state.
-.org $0
+.org $8000
reset:
cps ; Reset the processor status.
ldx.w #$FFFF ; Set up the stack pointer.
@@ -25,21 +29,22 @@ start:
line_count:
iny ; Increment the line count.
- cpy #$32
- beq spin ; Have we printed 50 lines?
- jmp start ; Keep looping until we have printed 50 lines.
+ cpy #50 ; Have we printed 50 lines?
+ beq disp ; Yes, so we're done.
+ jmp start ; No, so keep looping.
; Printing sub routine.
print:
lda string, x ; Get character at offset x.
beq line_count ; Did we find a null terminator?
- sta $C001 ; Print character.
+ sta scr ; Print character.
inx ; Increment offset.
jmp print ; Keep printing more characters.
; The other threads would clash, if we're running the same code.
; So, have them spin instead, please?
-.org $1000
+disp:
+ lda status
spin:
nop
nop
@@ -58,5 +63,6 @@ spin:
.qword spin
.qword spin
.qword spin
-done
+a
+d
diff --git a/test/input-2.s b/test/input-2.s
deleted file mode 100644
index f5cb49e..0000000
--- a/test/input-2.s
+++ /dev/null
@@ -1,412 +0,0 @@
-; Testing input.
-;
-; Writen in Sux assembly by
-; mr b0nk 500 <b0nk@b0nk.xyz>
-
-; Instruction mnemonics,
-; and opcodes.
-.org $1000
-tok:
- .byte "dab"
-msg:
- .byte "oof, you divided a, and b on me.\n"
-
-; Input buffer.
-.org $2000
-buffer:
-
-.org $2800
-cmd_buf:
-
-; Initalize some variables.
-.org $0
-scr_row:
- .byte $0
-scr_col:
- .byte $0
-a:
- .byte $0
-b:
- .byte $0
-c:
- .byte $0
-d:
- .byte $0
-e:
- .byte $0
-string:
- .byte "Please, type something.\n"
-string2:
- .byte "You typed, "
-end:
- .byte $0
-
-; String Pointer
-ptr:
- .qword buffer
-cptr:
- .qword cmd_buf
-tptr:
- .qword tok
-mptr:
- .qword msg
-
-
-; Main program
-.org $8000
-reset:
- cps
- ldx.w #$FFFF
- txs
- ldy #0
- lda #0
-clr_buf:
- cpy.w #$7FF
- beq start
- sta (ptr), y
- iny
- jmp clr_buf
-
-start:
- lda #0
- sta $C000
- tax ; Reset x.
- tay ; Reset y.
- jsl clr_cbuf
- jmp print
-
-clr_cbuf:
- cpy.w #$3FF
- beq clr_cbuf_end
- sta (cptr), y
- iny
- jmp clr_cbuf
-clr_cbuf_end:
- ldy #0
- rtl
-
-rset_a:
- lda #1
-read:
- lda $C000 ; Get control register.
- beq rset_a ; Loop until we get a character.
- jmp getchar ; We got a key.
-sleep:
- lda end
- bne spin ; Are we done with getting input?
-
-print:
- lda string, x ; Get character at offset x.
- beq rset_a ; Did we find a null terminator?
- sta $C001 ; Print character.
- inx ; Increment offset.
- cmp #$A
- beq inc_row
- inc scr_col
- jmp print
-inc_row:
- lda #0
- sta scr_col
- lda #$42
- sta c
- jsl isdown
- jmp print ; Keep printing more characters.
-
-getchar:
- lda $C002 ; Get typed character.
- cmp #$1B
- beq esc
- cmp #$A
- beq nl ; Did the user type a newline?
- cmp #8
- beq bs ; Did the user type a backspace?
- cmp #$7F
- beq bs ; Did the user type a backspace?
-echo:
- sta a
- ldx scr_col
- cpx #79
- bne echo_print
-linewrap:
- inc scr_row
- ldx #0
- stx scr_col
- lda scr_row
- jsl update_pos
-echo_print:
- lda a
- sta $C001 ; Echo typed character.
- inc scr_col ; Increment the cursor's x coordinate.
- sta (ptr), y ; Store typed character into the input buffer.
- iny
- jmp rset_a ; Start getting user input.
-
-esc:
- lda $C000 ; Skip the '['.
- lda $C000 ; Get the next character.
- beq read ; We have an error, so discard it, and go back to getting user input.
- lda $C002 ; Get the escape code.
- sta c ; Store the escape code, until we need it.
- jsl isup ; Check if the user pressed up.
- lda d
- bne esc_end
- jsl isdown ; Check if the user pressed down.
- lda d
- bne esc_end
- lda #0
- jsl isleft ; Check if the user pressed left.
- lda d
- bne esc_end
- jsl isright ; Check if the user pressed right.
-esc_end:
- lda #0
- sta d
- jmp rset_a ; Go back to getting user input.
-
-isup:
- lda scr_row ; Is the cursor at the top of the screen?
- beq isup_done ; Yes, so return.
- lda c ; No, so load the escape code back into the accumulator.
- cmp #$41 ; Did the user press the up arrow key?
- beq up ; Yes, so move the cursor up.
-isup_done:
- rtl ; End of isup.
-
-isdown:
- lda scr_row ; Start checking the y coordinate of the cursor.
- cmp #23 ; Is the cursor at the bottom of the screen?
- beq isdown_done ; Yes, so return.
- lda c ; No, so load the escape code back into the accumulator.
- cmp #$42 ; Did the user press the down arrow key?
- beq down ; Yes, so move the cursor down.
-isdown_done:
- rtl ; End of isdown.
-
-isright:
- lda scr_col ; Start checking the x coordinate of the cursor.
- cmp #79 ; Is the cursor at the far right of the screen?
- beq isright_end ; Yes, so return.
- lda c ; No, so load the escape code back into the accumulator.
- cmp #$43 ; Did the user press the right arrow key?
- beq right ; Yes, so move the cursor right.
-isright_end:
- rtl ; End of isright.
-
-isleft:
- lda scr_col ; Is the cursor at the far left of the screen?
- beq isleft_done ; Yes, so return.
- lda c ; No, so load the escape code back into the accumulator.
- cmp #$44 ; Did the user press the left arrow key?
- beq left ; Yes, so move the cursor left.
-isleft_done:
- rtl ; End of isleft.
-
-up:
- dec scr_row
- jsl update_pos
- lda #1
- sta d
- jmp isup_done
-down:
- inc scr_row
- jsl update_pos
- lda #1
- sta d
- jmp isdown_done
-right:
- inc scr_col
- jsl update_pos
- jmp isright_end
-left:
- dec scr_col
- jsl update_pos
- lda #1
- sta d
- jmp isleft_done
-
-update_pos:
- lda #$1B ; Print an escape character
- sta $C001 ; to the screen.
- lda #$5B ; Print '['
- sta $C001 ; to the screen, and start the escape sequence.
- jsl getrow ; Start printing the row number to the screen.
- jsl getcol ; Start printing the column number to the screen.
- lda #$48 ; Print 'H'
- sta $C001 ; to the screen.
- rtl ; End of update_pos.
-getrow:
- lda scr_row ; Get the cursor's y coordinate.
- div #10 ; Divide A by 10.
- adc #$30 ; Convert it to ascii, and
- sta $C001 ; print to the screen.
- tba ; Get the remainder.
- adc #$30 ; Convert it to ascii, and
- sta $C001 ; print to the screen.
- rtl ; End of getrow.
-getcol:
- lda #$3B ; Print ';'
- sta $C001 ; to the screen.
- lda scr_col ; Get the cursor's x coordinate.
- div #10 ; Divide A by 10.
- adc #$30 ; Convert it to ascii, and
- sta $C001 ; print to the screen.
- tba ; Get the remainder.
- adc #$30 ; Convert it to ascii, and
- sta $C001 ; print to the screen.
- rtl ; End of getrow.
-
-nl:
- lda #0
- sta scr_col
- sta (ptr), y ; Store said terminator into the input buffer.
- lda #$42
- sta c
- jsl isdown
- ldy.w #0 ; Reset y, to print the result.
- jsl dabbed
- beq start
- ldy #0
- jmp result
-
-back:
- sta $C001 ; Print backspace.
- lda #0 ; Put a null terminator, in place of the backspace.
- sta (ptr), y ; Place it into the input buffer.
- dey ; Decrement buffer offset.
- dec scr_col
- jmp read ; Get next character.
-
-bs:
- cpy #0 ; Are we at the start of the buffer?
- beq rset_a ; We are, so do not store the backspace into the buffer.
- jmp back ; We are not, so add the backspace to the buffer.
-
-result:
- ldx scr_col
- cpx #79
- bne result_print
-linewrap2:
- inc scr_row
- ldx #$0
- stx scr_col
- jsl update_pos
-result_print:
- lda string2, y
- beq rset_y ; Reset y, if we hit the null terminator.
- sta $C001 ; Print 'You have typed, '
- inc scr_col ; Increment the cursor's x coordinate.
- iny ; Increment offset.
- jmp result ; Keep printing.
-
-rset_y:
- ldy.w #0 ; Reset y.
- ldx.w #0 ; Reset x.
- lda.w #0 ; Reset a.
- jmp print_buf ; Print the input buffer.
-dabbed:
- lda (ptr), y ; Get a character from the input buffer.
- beq dab_nend ; Are we done with printing the buffer?
- cmp (tptr), y
- bcs dab_nend
- beq chk_str
- bcc dab_nend
-chk_str:
- iny
- cpy #3
- bne dabbed
- ldy #0
-pnt_msg:
- ldx scr_col
- cpx #79
- bne msg_pnt
-linewrap3:
- inc scr_row
- ldx #0
- stx scr_col
- jsl update_pos
-msg_pnt:
- lda (mptr), y ; Get a character from the input buffer.
- beq dab_eqnd ; Are we done with printing the buffer?
- sta $C001 ; Print said character.
- inc scr_col ; Increment the cursor's x coordinate.
- iny
- jmp pnt_msg ; Keep printing the buffer.
-dab_nend:
- lda #1
- jmp dab_end
-dab_eqnd:
- lda #0
- jmp dab_end
-dab_end:
- rtl
-
-
-
-print_buf:
- ldx scr_col
- cpx #79
- bne buf_print
-linewrap4:
- inc scr_row
- ldx #0
- stx scr_col
- jsl update_pos
-buf_print:
- lda (ptr), y ; Get a character from the input buffer.
- beq cmd_clr ; Are we done with printing the buffer?
- sta $C001 ; Print said character.
- inc scr_col ; Increment the cursor's x coordinate.
- iny
- jmp print_buf ; Keep printing the buffer.
-
-cmd_clr:
- lda #0
- sta scr_col
- lda #$42
- sta c
- jsl isdown
- jmp start
-
-scr_to_buf:
- tax
- mul #80
- adc scr_col
- tay
- txa
- rtl
-
-spin:
- nop
- nop
- nop
- jmp spin
-
-.org $1000
-v
-.org $1100
-v
-.org $1200
-v
-.org $8000
-v
-.org $8100
-v
-.org $8200
-v
-.org $8300
-v
-.org $FFC0
-.qword reset
-
-.org $FF50
-.qword spin
-.qword spin
-.qword spin
-.qword spin
-.qword spin
-.qword spin
-.qword spin
-.org $FF50
-v
-done
-
diff --git a/test/input-3.s b/test/input-3.s
deleted file mode 100644
index 35547a7..0000000
--- a/test/input-3.s
+++ /dev/null
@@ -1,900 +0,0 @@
-; Testing input.
-;
-; Writen in Sux assembly by
-; mr b0nk 500 <b0nk@b0nk.xyz>
-
-; Instruction mnemonics,
-; and opcodes.
-.org $1000
-tok:
- .byte "dab"
-msg:
- .byte "oof, you divided a, and b on me.\n"
-
-; Input buffer.
-.org $2000
-buffer:
-
-.org $4000
-cmd_buf:
-
-
-; Initalize some variables.
-.org $0
-scr_row:
- .byte $0
-scr_col:
- .byte $0
-scr_trow:
- .byte $0
-scr_tcol:
- .byte $0
-scr_ptr:
- .word $0
-a:
- .byte $0
-b:
- .byte $0
-c:
- .byte $0
-d:
- .byte $0
-e:
- .byte $0
-f:
- .byte $0
-string:
- .byte "Please, type something.\n"
-string2:
- .byte "You typed, "
-end:
- .byte $0
-bits:
- .byte $80
- .byte $40
- .byte $20
- .byte $10
- .byte $08
- .byte $04
- .byte $02
- .byte $01
-bitmask:
- .byte $0
-bitabl:
- .qword $0
- .qword $0
-scr_str:
-.byte $0
-scr_end:
-.byte $0
-wrapped:
-.byte $0
-
-; Pointers
-ptr:
- .qword buffer
-cptr:
- .qword cmd_buf
-tptr:
- .qword tok
-mptr:
- .qword msg
-
-; Main program
-.org $8000
-reset:
- cps
- ldx.w #$FFFF
- txs
- ldy #0
- lda #23
- sta scr_end
- lda #0
- sta scr_str
- ldx #8
- sta.q bitabl
- sta.q bitabl, x
- tax
- jsl clr_buf
- jmp start
-clr_buf:
- lda #0
- cpy.w #$1FFF
- beq clr_buf_end
- sta (ptr), y
- iny
- jmp clr_buf
-clr_buf_end:
- ldy.w #0
- rtl
-
-start:
- lda #0
- tax
- sta $C000
- phy #2
- ldy.w #0
- jsl clr_cbuf
- ply #2
- jmp print
-
-clr_cbuf:
- cpy.w #$3FF
- beq clr_cbuf_end
- sta (cptr), y
- iny
- jmp clr_cbuf
-clr_cbuf_end:
- rtl
-
-pull_y:
- ply #2
-rset_a:
- lda #0
- sta $C000
- inc
-read:
- lda $C000 ; Get control register.
- beq rset_a ; Loop until we get a character.
- jsl getchar ; We got a key.
- beq parse ; We got a newline, so start parsing the line.
- jmp rset_a ; We didn't get a newline, so keep getting more characters.
-
-print:
- phy #2
- txy
- lda string, y ; Get character at offset x.
- beq pull_y ; Did we find a null terminator?
- ply #2
- inx
- jsl print_char
- jmp print
-
-getbit:
- clc
- lda scr_str
- bne getbt0
- ldx scr_row
- jmp getbt1
-getbt0:
- lda scr_row
- adc scr_str
- tax
-getbt1:
- jsl bitpos
- ldb bitabl, x
- aba
- cmp #1
- jmp bitout
-
-;putbit:
-; ldx scr_row
-;putbt1:
-; bcc setbit
-
-
-clrbit:
- jsl bitpos
- xor #$FF
- ldb bitabl, x
- aba
-bitsav:
- sta bitabl, x
-bitout:
- ldx bitmask
- rtl
-
-setbit:
- jsl bitpos
- ldb bitabl, x
- oab
- jmp bitsav
-
-bitpos:
- stx bitmask
- txa
- and #7
- tax
- lda bits, x
- pha #1
- lda bitmask
- lsr #3
- tax
- pla #1
- rtl
-
-
-getchar:
- lda $C002 ; Get typed character.
- ldb #0
- stb e
- pha #1
- phy #2
- cmp #10
- beq cmd_cpy
-getchar_pnt:
- ply #2
- pla #1
- ldb e
- bne reset_row
-getchar_pnt1:
- jsl print_char
- lda a
- cmp #10
- beq getchar_line
- jmp getchar_char
-reset_row:
- ldb e
- stb scr_row
- jmp getchar_pnt1
-
-
-cmd_cpy:
- ldb scr_row
- stb e
- jsl findst
- clc
- lda scr_row
- adc scr_str
- mul #80
- tay
- ldx.w #$0
-cmd_cpy_strt:
- lda (ptr), y
- beq getchar_pnt
- phy #2
- txy
- sta (cptr), y
- inx
- ply #2
- iny
- jmp cmd_cpy_strt
-getchar_line:
- lda #0
- jmp getchar_end
-getchar_char:
- lda #1
-getchar_end:
- rtl
-
-findst:
- jsl getbit
- bcc findst_done
- dec scr_row
- bpo findst
- inc scr_row
-findst_done:
- rtl
-
-parse:
- lda #0
- tax
- jsl dabbed
- beq start
- lda #0
- tax
- jmp result
-
-print_char:
- sta a
- cmp #$1B
- beq esc
- cmp #$A
- beq nl ; Did the user type a newline?
- cmp #$C
- beq clr_scr
- cmp #19
- beq en_step
- cmp #18
- beq dis_step
- cmp #8
- beq bs ; Did the user type a backspace?
- cmp #$7F
- beq bs ; Did the user type a backspace?
- sta a
-printc:
- lda a
- sta (ptr), y ; Store typed character into the input buffer.
- inc scr_col ; Increment the cursor's x coordinate.
- iny
-printc_2:
- ldb #1
- stb f
- ldb scr_col
- cpb #80
- bcs printc_4
-printc_3:
- sta $C001 ; Echo typed character.
- ldb f
- beq printc_wrap
- jmp printc_end
-printc_4:
- ldb scr_row
- cpb #23
- bcs printc_scrl
-printc_5:
- ldb #0
- stb f
- jmp printc_3
-printc_scrl:
- sta $C001 ; Echo typed character.
- clc
- lda #1
- sta wrapped
- jsl scrl_down
-printc_wrap:
- ldb #0
- stb scr_col
- ldb scr_row
- cpb #23
- bcs printc_wrap2
-printc_wrap1:
- inc scr_row
-printc_wrap2:
- phx #2
- clc
- lda scr_row
- adc scr_str
- tax
- jsl setbit
- plx #2
- jsl update_pos
-printc_end:
- rtl
-
-nl:
- lda #0
- sta (ptr), y ; Store said terminator into the input buffer.
- sta scr_col
- lda scr_row
- cmp #23
- bne nl_inc
- jsl scrl_down
- lda #10
- sta a
- jmp printc_end
-nl_inc:
- inc scr_row
- jsl update_pos
- lda #10
- sta a
- jmp printc_end
-
-clr_scr:
- lda #23
- sta scr_end
- lda #0
- sta scr_str
- ldx #8
- sta.q bitabl
- sta.q bitabl, x
- tay
- jsl clr_buf
- sta scr_col
- sta scr_row
- jsl update_pos
- lda #$C
- sta $C001
- jmp printc_end
-
-en_step:
- lda $C010
- beq step_en
- jmp stp_end
-step_en:
- lda #1
- sta $C010
- jmp stp_end
-
-dis_step:
- lda $C010
- bne step_dis
- jmp stp_end
-step_dis:
- lda #0
- sta $C010
-stp_end:
- jmp printc_end
-
-back:
- lda #$7F
- sta $C001
- dey ; Decrement buffer offset.
- lda #0 ; Put a null terminator, in place of the backspace.
- sta (ptr), y ; Place it into the input buffer.
- dec scr_col
- jsl update_pos
- jmp printc_end ; Get next character.
-
-bs:
- lda scr_col ; Are we at the start of the buffer?
- beq back_wrap
- jmp back ; We are not, so add the backspace to the buffer.
-back_wrap:
- jsl getbit
- bcs back_wrap1
- jmp printc_end
-back_wrap1:
- lda scr_row
- beq back_wrap2
- jmp backwrp
-back_wrap2:
- lda scr_str
- bne back_scrl
- jmp printc_end
-back_scrl:
- clc
- jsl scrl_up
- inc scr_row
-backwrp:
- clc
- lda scr_row
- adc scr_str
- tax
-backwrp2:
- dec scr_row
- jsl clrbit
- ldb #80
- stb scr_col
- jsl update_pos
- jmp back
-
-esc:
- lda $C000 ; Skip the '['.
- lda $C002
- cmp #$1B
- beq shftesc
- lda $C000 ; Get the next character.
- beq printc_end ; We have an error, so discard it, and go back to getting user input.
- lda $C002 ; Get the escape code.
- sta c ; Store the escape code, until we need it.
- lda #0
- sta d
- jsl isup ; Check if the user pressed up.
- lda d
- bne esc_end
- jsl isdown ; Check if the user pressed down.
- lda d
- bne esc_end
- lda #0
- jsl isleft ; Check if the user pressed left.
- lda d
- bne esc_end
- jsl isright ; Check if the user pressed right.
-esc_end:
- lda #0
- sta d
- jmp printc_end ; Go back to getting user input.
-
-shftesc:
- lda $C000 ; Skip the '['.
- lda $C000 ; Get the next character.
- beq printc_end ; We have an error, so discard it, and go back to getting user input.
- lda $C002 ; Get the escape code.
- sta c ; Store the escape code, until we need it.
- lda #0
- sta d
- jsl isshftup ; Check if the user pressed shift+up.
- lda d
- bne shftesc_end
- jsl isshftdown ; Check if the user pressed shift+down.
-shftesc_end:
- lda #0
- sta d
- jmp printc_end ; Go back to getting user input.
-
-isup:
- lda c ; No, so load the escape code back into the accumulator.
- cmp #$41 ; Did the user press the up arrow key?
- bne isup_done ; Yes, so return.
- lda #1
- sta d
- lda scr_row ; Is the cursor at the top of the screen?
- beq isup_scrl ; Yes, so return.
-isup_2:
- lda c ; No, so load the escape code back into the accumulator.
- cmp #$41 ; Did the user press the up arrow key?
- beq up ; Yes, so move the cursor up.
- jmp isup_done
-isup_scrl:
- lda scr_str
- beq isup_done
- jsl scrl_up
-isup_done:
- rtl ; End of isup.
-
-isdown:
- lda c ; No, so load the escape code back into the accumulator.
- cmp #$42 ; Did the user press the down arrow key?
- bne isdown_done
- lda scr_row ; Start checking the y coordinate of the cursor.
- cmp #23 ; Is the cursor at the bottom of the screen?
- beq isdown_scrl ; Yes, so return.
- lda c ; No, so load the escape code back into the accumulator.
- cmp #$42 ; Did the user press the down arrow key?
- beq down ; Yes, so move the cursor down.
- jmp isdown_done
-isdown_scrl:
- lda scr_row
- sta scr_trow
- lda scr_col
- sta scr_tcol
- jsl scrl_down
- lda scr_trow
- sta scr_row
- lda scr_tcol
- sta scr_col
-isdown_done:
- rtl ; End of isdown.
-
-isright:
- lda c ; No, so load the escape code back into the accumulator.
- cmp #$43 ; Did the user press the right arrow key?
- bne isright_done
- lda scr_col ; Start checking the x coordinate of the cursor.
- cmp #79 ; Is the cursor at the far right of the screen?
- beq isright_wrp ; Yes, so check if this is a wrapped line.
- jmp right ; No, so move the cursor right, like normal.
-isright_wrp:
- inc scr_row
- jsl getbit
- bcs wrap_inc
- dec scr_row
- jmp isright_done
-isright_scrl:
- lda scr_str
- beq isright_end
- lda #1
- sta wrapped
- jsl scrl_down
- dec scr_row
- jmp isright_end
-wrap_inc:
- lda #0
- sta scr_col
- lda scr_row
- cmp #23
- bcs isright_scrl
-isright_end:
- jsl update_pos
-isright_done:
- lda #0
- sta wrapped
- rtl ; End of isright.
-
-isleft:
- lda c
- cmp #$43
- beq isleft_done
- lda scr_col ; Is the cursor at the far left of the screen?
- beq isleft_wrp ; Yes, so start checking if this is a wrapped line.
- lda c ; No, so load the escape code back into the accumulator.
- cmp #$44 ; Did the user press the left arrow key?
- beq left ; Yes, so move the cursor left.
- jmp isleft_done
-isleft_wrp:
- jsl getbit
- bcs wrap_dec
- jmp isleft_done
-wrap_dec:
- lda scr_row
- beq wrap_dec1
- lda #1
- sta wrapped
- dec scr_row
-wrap_dec1:
- lda #79
- sta scr_col
- lda #1
- sta d
- lda scr_row
- beq isleft_scrl
- jmp isleft_end
-isleft_scrl:
- lda wrapped
- bne isleft_end
- lda scr_str
- beq isleft_done
- jsl scrl_up
- jmp isleft_done
-isleft_end:
- jsl update_pos
-isleft_done:
- lda #0
- sta wrapped
- rtl ; End of isleft.
-
-up:
- dec scr_row
- jsl update_pos
- lda #1
- sta d
- jmp isup_done
-down:
- inc scr_row
- jsl update_pos
- lda #1
- sta d
- jmp isdown_done
-right:
- inc scr_col
- jsl update_pos
- jmp isright_done
-left:
- dec scr_col
- jsl update_pos
- lda #1
- sta d
- jmp isleft_done
-
-isshftup:
- lda c ; Load the escape code back into the accumulator.
- cmp #$41 ; Did the user press the up arrow key?
- bne isshftup_done
- lda #1
- sta d
- lda scr_str
- beq isshftup_done
- jmp shftup
-isshftup_done:
- rtl
-
-isshftdown:
- lda c ; Load the escape code back into the accumulator.
- cmp #$42 ; Did the user press the down arrow key?
- bne isshftdown_done
- lda #1
- sta d
- lda scr_end
- cmp #71
- bcs isshftdown_done
- jmp shftdown
-isshftdown_done:
- rtl
-
-shftup:
- jsl scrl_up
- lda #1
- sta d
- jmp isshftup_done
-
-shftdown:
- jsl scrl_down
- lda #1
- sta d
- jmp isshftdown_done
-
-update_pos:
- ldb #1
- stb f
- clc
- lda scr_row
- adc scr_str
- clc
- mul #80
- clc
- adc scr_col
- tay
- lda #$1B ; Print an escape character
- sta $C001 ; to the screen.
- lda #$5B ; Print '['
- sta $C001 ; to the screen, and start the escape sequence.
- jsl getrow ; Start printing the row number to the screen.
- jsl getcol ; Start printing the column number to the screen.
- lda #$48 ; Print 'H'
- sta $C001 ; to the screen.
- rtl ; End of update_pos.
-
-getrow:
- lda scr_row ; Get the cursor's y coordinate.
- div #10 ; Divide A by 10.
- adc #$30 ; Convert it to ascii, and
- sta $C001 ; print to the screen.
- tba ; Get the remainder.
- adc #$30 ; Convert it to ascii, and
- sta $C001 ; print to the screen.
- rtl ; End of getrow.
-
-getcol:
- lda #$3B ; Print ';'
- sta $C001 ; to the screen.
- lda scr_col ; Get the cursor's x coordinate.
- div #10 ; Divide A by 10.
- clc
- adc #$30 ; Convert it to ascii, and
- sta $C001 ; print to the screen.
- tba ; Get the remainder.
- clc
- adc #$30 ; Convert it to ascii, and
- sta $C001 ; print to the screen.
- rtl ; End of getrow.
-
-scrl_down:
-
- inc scr_str
- inc scr_end
- lda #$1B ; Print an escape character
- sta $C001 ; to the screen.
- lda #$5B ; Print '['
- sta $C001 ; to the screen, and start the escape sequence.
- lda #$54 ; Print 'T'
- sta $C001 ; to the screen, and end the escape sequence.
- lda wrapped
- beq scrldn_save
-scrldn1:
- jsl rdrw_row
- lda wrapped
- beq scrldn_load
- jmp scrldn_end
-scrldn_save:
- lda scr_row
- pha #1
- lda scr_col
- pha #1
- jmp scrldn1
-scrldn_load:
- pla #1
- sta scr_col
- pla #1
- sta scr_row
- jsl update_pos
-scrldn_end:
- lda #0
- sta wrapped
-scrldn_done:
- rtl
-
-scrl_up:
- dec scr_str
- dec scr_end
- lda #$1B ; Print an escape character
- sta $C001 ; to the screen.
- lda #$5B ; Print '['
- sta $C001 ; to the screen, and start the escape sequence.
- lda #$53 ; Print 'S'
- sta $C001 ; to the screen, and end the escape sequence.
- lda scr_row
- pha #1
- lda scr_col
- pha #1
- lda #0
- sta scr_row
- jsl rdrw_row
- pla #1
- sta scr_col
- pla #1
- sta scr_row
- jsl update_pos
-scrlup_done:
- rtl
-
-rdrw_row:
- lda #0
- sta scr_col
- jsl update_pos
-rdrow_st:
- lda (ptr), y
- beq rdrow_inc
- sta $C001
-rdrow_inc:
- inc scr_col
- lda (ptr), y
- beq rdrow_skip
- iny
-rdrow_inc1:
- lda scr_col
- cmp #80
- bcs rdrow_end
- jmp rdrow_st
-rdrow_skip:
- jsl update_pos
- jmp rdrow_inc1
-rdrow_end:
- lda #0
- sta scr_col
- jsl update_pos
-rdrow_done:
- rtl
-
-
-;rdrw_scr:
-; lda #$C
-; sta $C001
-; lda scr_col
-; sta scr_tcol
-; lda scr_row
-; sta scr_trow
-; lda #0
-; sta scr_col
-; sta scr_row
-; phy #2
-; jsl update_pos
-; ply #2
-; ldx scr_ptr
-; phy #2
-; txy
-; lda (ptr), y
-; sta $C001
-; ply #2
-; rtl
-
-result:
- phy #2
- txy
- lda string2, y
- beq rset_y ; Reset y, if we hit the null terminator.
- ply #2
- jsl print_char ; Print 'You have typed, '
- inx
- jmp result ; Keep printing.
-
-rset_y:
- ply #2
- lda #0 ; Reset a.
- tax ; Reset y.
- jmp print_buf ; Print the input buffer.
-
-dabbed:
- phy #2
- txy
- lda (cptr), y ; Get a character from the input buffer.
- beq dab_pend ; Are we done with printing the buffer?
- cmp (tptr), y
- bcc dab_pend
- beq chk_str
- bcs dab_pend
-chk_str:
- ply #2
- inx
- cpx #3
- bne dabbed
- ldx #0
-pnt_msg:
- phy #2
- txy
- lda (mptr), y ; Get a character from the input buffer.
- beq dab_peqnd ; Are we done with printing the buffer?
- ply #2
- jsl print_char
- inx
- jmp pnt_msg ; Keep printing the buffer.
-dab_pend:
- ply #2
- lda #1
- jmp dab_end
-dab_peqnd:
- ply #2
- lda #0
- jmp dab_end
-dab_end:
- rtl
-
-print_buf:
- phy #2
- txy
- lda (cptr), y ; Get a character from the input buffer.
- beq cmd_clr ; Are we done with printing the buffer?
- ply #2
- jsl print_char
- inx
- jmp print_buf ; Keep printing the buffer.
-
-cmd_clr:
- ply #2
- lda #10
- jsl print_char
- jmp start
-
-.org $FFC0
-.qword reset
-
-.org $FF50
-.qword spin
-.qword spin
-.qword spin
-.qword spin
-.qword spin
-.qword spin
-.qword spin
-done
-
diff --git a/test/input.s b/test/input.s
deleted file mode 100644
index a8b0830..0000000
--- a/test/input.s
+++ /dev/null
@@ -1,338 +0,0 @@
-; Testing input.
-;
-; Writen in Sux assembly by
-; mr b0nk 500 <b0nk@b0nk.xyz>
-
-
-; Input buffer.
-.org $4000
-buffer:
-
-; Initalize some variables.
-.org $0
-scr_row:
- .byte $0
-scr_col:
- .byte $0
-a:
- .byte $0
-b:
- .byte $0
-c:
- .byte $0
-d:
- .byte $0
-e:
- .byte $0
-string:
- .byte "Please, type something.\n"
-string2:
- .byte "You typed, "
-end:
- .byte $0
-
-; String Pointer
-ptr:
- .qword buffer
-
-; Main program
-.org $8000
-reset:
- cps
- ldx.w #$FFFF
- txs
- ldy #0
- lda #0
-clr_buf:
- cpy.w #$FFF
- beq start
- sta (ptr), y
- iny
- jmp clr_buf
-
-start:
- tax ; Reset x.
- tay ; Reset y.
- jmp print
-
-rset_a:
- lda #1
-
-read:
- lda $C000 ; Get control register.
- beq rset_a ; Loop until we get a character.
- lda #0
- sta $C000
- jmp getchar ; We got a key.
-sleep:
- lda end
- bne spin ; Are we done with getting input?
-
-print:
- lda string, x ; Get character at offset x.
- beq rset_a ; Did we find a null terminator?
- sta $C001 ; Print character.
- inx ; Increment offset.
- cmp #$A
- beq inc_row
- inc scr_col
- jmp print
-inc_row:
- inc scr_row
- lda #0
- sta scr_col
- jmp print ; Keep printing more characters.
-
-getchar:
- lda $C002 ; Get typed character.
- cmp #$1B
- beq esc
- cmp #$A
- beq nl ; Did the user type a newline?
- cmp #8
- beq bs ; Did the user type a backspace?
- cmp #$7F
- beq bs ; Did the user type a backspace?
-echo:
- sta a
- ldx scr_col
- cpx #79
- bne echo_print
-linewrap:
- inc scr_row
- ldx #0
- stx scr_col
- lda scr_row
- jsl update_pos
-echo_print:
- lda a
- sta $C001 ; Echo typed character.
- inc scr_col ; Increment the cursor's x coordinate.
- sta (ptr), y ; Store typed character into the input buffer.
- iny
- jmp rset_a ; Start getting user input.
-
-esc:
- lda $C000 ; Skip the '['.
- lda $C000 ; Get the next character.
- beq read ; We have an error, so discard it, and go back to getting user input.
- lda $C002 ; Get the escape code.
- sta c ; Store the escape code, until we need it.
- jsl isup ; Check if the user pressed up.
- lda d
- cmp #0
- bne esc_end
- jsl isdown ; Check if the user pressed down.
- lda d
- cmp #0
- bne esc_end
- lda #0
- jsl isleft ; Check if the user pressed left.
- lda d
- cmp #0
- bne esc_end
- jsl isright ; Check if the user pressed right.
-esc_end:
- lda #0
- sta d
- jmp rset_a ; Go back to getting user input.
-
-isup:
- lda scr_row ; Is the cursor at the top of the screen?
- beq isup_done ; Yes, so return.
- lda c ; No, so load the escape code back into the accumulator.
- cmp #$41 ; Did the user press the up arrow key?
- beq up ; Yes, so move the cursor up.
-isup_done:
- rtl ; End of isup.
-
-isdown:
- lda scr_row ; Start checking the y coordinate of the cursor.
- cmp #23 ; Is the cursor at the bottom of the screen?
- beq isdown_done ; Yes, so return.
- lda c ; No, so load the escape code back into the accumulator.
- cmp #$42 ; Did the user press the down arrow key?
- beq down ; Yes, so move the cursor down.
-isdown_done:
- rtl ; End of isdown.
-
-isright:
- lda scr_col ; Start checking the x coordinate of the cursor.
- cmp #79 ; Is the cursor at the far right of the screen?
- beq isright_end ; Yes, so return.
- lda c ; No, so load the escape code back into the accumulator.
- cmp #$43 ; Did the user press the right arrow key?
- beq right ; Yes, so move the cursor right.
-isright_end:
- rtl ; End of isright.
-
-isleft:
- lda scr_col ; Is the cursor at the far left of the screen?
- beq isleft_done ; Yes, so return.
- lda c ; No, so load the escape code back into the accumulator.
- cmp #$44 ; Did the user press the left arrow key?
- beq left ; Yes, so move the cursor left.
-isleft_done:
- rtl ; End of isleft.
-
-up:
- dec scr_row
- jsl update_pos
- lda #1
- sta d
- jmp isup_done
-down:
- inc scr_row
- jsl update_pos
- lda #1
- sta d
- jmp isdown_done
-right:
- inc scr_col
- jsl update_pos
- jmp isright_end
-left:
- dec scr_col
- jsl update_pos
- lda #1
- sta d
- jmp isleft_done
-
-update_pos:
- lda #$1B ; Print an escape character
- sta $C001 ; to the screen.
- lda #$5B ; Print '['
- sta $C001 ; to the screen, and start the escape sequence.
- jsl getrow ; Start printing the row number to the screen.
- jsl getcol ; Start printing the column number to the screen.
- lda #$48 ; Print 'H'
- sta $C001 ; to the screen.
- rtl ; End of update_pos.
-getrow:
- lda scr_row ; Get the cursor's y coordinate.
- div #10 ; Divide A by 10.
- adc #$30 ; Convert it to ascii, and
- sta $C001 ; print to the screen.
- tba ; Get the remainder.
- adc #$30 ; Convert it to ascii, and
- sta $C001 ; print to the screen.
- rtl ; End of getrow.
-getcol:
- lda #$3B ; Print ';'
- sta $C001 ; to the screen.
- lda scr_col ; Get the cursor's x coordinate.
- div #10 ; Divide A by 10.
- adc #$30 ; Convert it to ascii, and
- sta $C001 ; print to the screen.
- tba ; Get the remainder.
- adc #$30 ; Convert it to ascii, and
- sta $C001 ; print to the screen.
- rtl ; End of getrow.
-
-
-nl:
- lda #$A
- sta $C001
- inc scr_row
- lda #0 ; Replace newline with a null terminator.
- sta (ptr), y ; Store said terminator into the input buffer.
- sta scr_col
- ldy.w #0 ; Reset y, to print the result.
- jmp result
-
-back:
- sta $C001 ; Print backspace.
- lda #0 ; Put a null terminator, in place of the backspace.
- sta (ptr), y ; Place it into the input buffer.
- dey ; Decrement buffer offset.
- dec scr_col
- jmp read ; Get next character.
-
-bs:
- cpy #0 ; Are we at the start of the buffer?
- beq rset_a ; We are, so do not store the backspace into the buffer.
- jmp back ; We are not, so add the backspace to the buffer.
-
-result:
- ldx scr_col
- cpx #79
- bne result_print
-linewrap2:
- inc scr_row
- ldx #$0
- stx scr_col
- jsl update_pos
-result_print:
- lda string2, y
- beq rset_y ; Reset y, if we hit the null terminator.
- sta $C001 ; Print 'You have typed, '
- inc scr_col ; Increment the cursor's x coordinate.
- iny ; Increment offset.
- jmp result ; Keep printing.
-
-
-rset_y:
- ldy.w #0 ; Reset y.
- jmp print_buf ; Print the input buffer.
-
-print_buf:
- ldx scr_col
- cpx #79
- bne buf_print
-linewrap3:
- inc scr_row
- ldx #0
- stx scr_col
- jsl update_pos
-buf_print:
- lda (ptr), y ; Get a character from the input buffer.
- beq spin ; Are we done with printing the buffer?
- sta $C001 ; Print said character.
- inc scr_col ; Increment the cursor's x coordinate.
- iny
- jmp print_buf ; Keep printing the buffer.
-
-scr_to_buf:
- tax
- mul #80
- adc scr_col
- tay
- txa
- rtl
-
-spin:
- nop
- nop
- nop
- jmp spin
-
-.org $1000
-v
-.org $1100
-v
-.org $1200
-v
-.org $8000
-v
-.org $8100
-v
-.org $8200
-v
-.org $8300
-v
-.org $FFC0
-.qword reset
-
-.org $FF50
-.qword spin
-.qword spin
-.qword spin
-.qword spin
-.qword spin
-.qword spin
-.qword spin
-.org $FF50
-v
-;done
-q
-
diff --git a/test/subroutine.s b/test/subroutine.s
index 7db1b87..d39fc15 100644
--- a/test/subroutine.s
+++ b/test/subroutine.s
@@ -24,7 +24,7 @@ start:
;stb $C010
;deb
bench:
- jsl clr_buf
+ jsr clr_buf
jmp bench
clr_buf:
@@ -39,7 +39,7 @@ clr_buf:
jmp clr_buf ; Keep looping.
clr_buf_end:
tay ; Set the index back to zero.
- rtl ; End of clr_buf.
+ rts ; End of clr_buf.
;.org $C010
;.byte $1
diff --git a/test/test.s b/test/test.s
index 7c36579..14b9798 100644
--- a/test/test.s
+++ b/test/test.s
@@ -2,12 +2,15 @@
;
; Writen by mr b0nk 500 <b0nk@b0nk.xyz>
.org $8000
-cps ; Clear the processor status register.
-lda.w #$1000 ; Load 0x1000 into the accumulator.
-rol #$1 ; Then rotate the accumulator left by 1 bit.
-jmp $8005 ; And then loop.
+entry:
+ cps ; Clear the processor status register.
+ lda.w #$1000 ; Load 0x1000 into the accumulator.
+loop:
+ rol #$1 ; Then rotate the accumulator left by 1 bit.
+ jmp loop ; And then loop.
-.org $FFC0 ; Reset vector.
-.qword $8000
-done
+.org $FFC0 ; Reset vector.
+.qword entry
+a
+d