summaryrefslogtreecommitdiff
path: root/programs
diff options
context:
space:
mode:
Diffstat (limited to 'programs')
-rw-r--r--programs/forg.s17
-rw-r--r--programs/hex-to-bcd.s7
-rw-r--r--programs/subasm.s296
3 files changed, 269 insertions, 51 deletions
diff --git a/programs/forg.s b/programs/forg.s
new file mode 100644
index 0000000..3e6aea1
--- /dev/null
+++ b/programs/forg.s
@@ -0,0 +1,17 @@
+forg:
+ iny ; Increment offset.
+ lda buf, y
+ jsr iswhite
+ bcs forg ; Reset y, if we hit the null terminator.
+ cmp #$2E ; Is this character a '.'?
+ bne forg_exit ; No, so return.
+ sty org ; Yes, so store the origin.
+forg_end:
+ iny ; Increment offset.
+ lda buf, y
+ jsr istoken
+ bcs forg_end
+ dey
+ sty scr_col
+forg_exit:
+ rts ; End of forg.
diff --git a/programs/hex-to-bcd.s b/programs/hex-to-bcd.s
new file mode 100644
index 0000000..53a3ff2
--- /dev/null
+++ b/programs/hex-to-bcd.s
@@ -0,0 +1,7 @@
+hex_to_bcd:
+ pla #1 ; Get argument.
+ div #10 ; Divide A by 10.
+ lsl #4 ; Shift the result left by 4 bits.
+ oab ; Or the result, with the remainder.
+ pha #1 ; Push the packed BCD result to the stack.
+ rts ; Return the result.
diff --git a/programs/subasm.s b/programs/subasm.s
index ddb7ba2..50f2e8d 100644
--- a/programs/subasm.s
+++ b/programs/subasm.s
@@ -12,6 +12,111 @@ ver_txt:
ver_num:
.byte "0.1"
+; Directives.
+dir:
+ .byte "org"
+ .byte "byte"
+ .byte "word"
+ .byte "dword"
+ .byte "qword"
+
+; Instruction mnemonics.
+mne:
+ .byte "CPS"
+ .byte "ADC"
+ .byte "AAB"
+ .byte "PHB"
+ .byte "PHP"
+ .byte "PHA"
+ .byte "PHY"
+ .byte "TAY"
+ .byte "PHX"
+ .byte "TAX"
+ .byte "TYX"
+ .byte "JMP"
+ .byte "SBC"
+ .byte "SAB"
+ .byte "PLB"
+ .byte "PLP"
+ .byte "PLA"
+ .byte "PLY"
+ .byte "TYA"
+ .byte "PLX"
+ .byte "TXA"
+ .byte "TXY"
+ .byte "JSR"
+ .byte "AND"
+ .byte "ABA"
+ .byte "STT"
+ .byte "TAB"
+ .byte "TSX"
+ .byte "BPO"
+ .byte "ORA"
+ .byte "OAB"
+ .byte "TBA"
+ .byte "SEI"
+ .byte "TXS"
+ .byte "BNG"
+ .byte "XOR"
+ .byte "XAB"
+ .byte "CLI"
+ .byte "BCS"
+ .byte "LSL"
+ .byte "LLB"
+ .byte "STB"
+ .byte "SEC"
+ .byte "STA"
+ .byte "STY"
+ .byte "STX"
+ .byte "BCC"
+ .byte "LSR"
+ .byte "LRB"
+ .byte "LDB"
+ .byte "CLC"
+ .byte "LDA"
+ .byte "LDY"
+ .byte "LDX"
+ .byte "BEQ"
+ .byte "ROL"
+ .byte "RLB"
+ .byte "SSP"
+ .byte "BNE"
+ .byte "ROR"
+ .byte "RRB"
+ .byte "CSP"
+ .byte "BVS"
+ .byte "MUL"
+ .byte "MAB"
+ .byte "SEV"
+ .byte "BVC"
+ .byte "DIV"
+ .byte "DAB"
+ .byte "CLV"
+ .byte "RTS"
+ .byte "CMP"
+ .byte "CAB"
+ .byte "CPY"
+ .byte "CPX"
+ .byte "CPB"
+ .byte "ENT"
+ .byte "RTI"
+ .byte "INC"
+ .byte "IAB"
+ .byte "INY"
+ .byte "INX"
+ .byte "DEC"
+ .byte "DBA"
+ .byte "DEY"
+ .byte "DEX"
+ .byte "WAI"
+ .byte "JSL"
+ .byte "ASR"
+ .byte "ARB"
+ .byte "NOP"
+ .byte "RTL"
+ .byte "BRK"
+
+
scr_row:
.byte $0
scr_col:
@@ -31,6 +136,13 @@ str_buf:
.org $2000
buf:
+.org $2400
+ptr1:
+ .qword $2500
+
+ptr2:
+ .qword $2900
+
; Control Register.
.org $C000
ctrl_reg:
@@ -49,22 +161,22 @@ reset:
cps
ldx.w #$FFFF
txs
- ldy #$0
+ ldy #0
jsr clr_buf
- ldx.w #$0 ; Reset x.
- ldy #$0 ; Reset y.
+ ldx.w #0 ; Reset x.
+ ldy #0 ; Reset y.
jmp print_title
read:
lda ctrl_reg ; Is the keyboard ready?
beq read ; Loop until the keyboard is ready.
- lda #$0 ; Start resetting the control register.
+ lda #0 ; Start resetting the control register.
sta ctrl_reg ; Reset the control register.
jmp getchar ; We got a key.
rset_x:
- ldx #$0 ; Reset x.
+ ldx #0 ; Reset x.
stx.w x
rts
@@ -94,7 +206,7 @@ getline:
lda #$A
sta scr ; Print newline
inc scr_row
- lda #$0
+ lda #0
sta scr_col
inc y
jsr rset_x
@@ -106,7 +218,7 @@ getchar:
beq esc ; Yes, so start getting the escape code.
cmp #$A ; Did the user type a newline?
beq nl ; Yes, so start parsing the input.
- cmp #$8 ; Did the user type a backspace?
+ cmp #8 ; Did the user type a backspace?
beq bs ; Yes, so start checking the buffer.
jsr echo ; Print character to screen.
@@ -123,16 +235,16 @@ esc:
sta c ; Store the escape code, until we need it.
jsr isup ; Check if the user pressed up.
lda d
- cmp #$0
+ cmp #0
bne esc_end
jsr isdown ; Check if the user pressed down.
lda d
- cmp #$0
+ cmp #0
bne esc_end
- lda #$0
+ lda #0
jsr isleft ; Check if the user pressed left.
lda d
- cmp #$0
+ cmp #0
bne esc_end
jsr isright ; Check if the user pressed right.
esc_end:
@@ -181,13 +293,13 @@ isleft_done:
up:
dec scr_row
jsr update_pos
- lda #$1
+ lda #1
sta d
jmp isup_done
down:
inc scr_row
jsr update_pos
- lda #$1
+ lda #1
sta d
jmp isdown_done
right:
@@ -197,7 +309,7 @@ right:
left:
dec scr_col
jsr update_pos
- lda #$1
+ lda #1
sta d
jmp isleft_done
@@ -237,47 +349,81 @@ getcol:
nl:
sta scr ; Print newline.
inc scr_row ; Move the cursor down one line.
- lda #$0 ; Put a null terminator, in place of the newline.
+ lda #0 ; Put a null terminator, in place of the newline.
sta scr_col ; Move the cursor back to column 0.
- sta str_buf, y ; Place it into the input buffer.
- ldy.w #$0 ; Reset y, to parse the input.
+ sta buf, y ; Place it into the input buffer.
+ ldy.w #0 ; Reset y, to parse the input.
jsr parse ; Start parsing input.
back:
sta scr ; Print backspace.
- lda #$0 ; Put a null terminator, in place of the backspace.
- sta str_buf, y ; Place it into the input buffer.
+ lda #0 ; Put a null terminator, in place of the backspace.
+ sta buf, 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?
+ cpy #0 ; Are we at the start of the buffer?
beq read ; We are, so do not store the backspace into the buffer.
jmp back ; We are not, so add the backspace to the buffer.
parse:
- jmp parse ; Keep printing.
- jsr clr_sbuf
+ jsr getdir
+ jsr
rts
-forg:
+getdir:
iny ; Increment offset.
- lda str_buf, y
+ lda buf, y
jsr iswhite
- bcs forg ; Reset y, if we hit the null terminator.
+ bcs getdir ; Reset y, if we hit the null terminator.
cmp #$2E ; Is this character a '.'?
- bne forg_exit ; No, so return.
- sty org ; Yes, so store the origin.
-forg_end:
+ bne getdir_exit ; No, so return.
+ jsr clr_ptr
+
+getdir_end:
iny ; Increment offset.
- lda str_buf, y
+ lda buf, y
+ jsr iswhite
+ bcs getdir_cmp
+ ora #%00100000 ; Make character lower case.
+ sta (ptr1), y
+ jmp getdir_end
+gettok:
+ ply #1
+ iny
+gettok2:
+ lda buf, y
jsr istoken
- bcs forg_end
- dey
- sty scr_col
-forg_exit:
- rts ; End of forg.
+ bcs gettok3
+ jmp gettok2
+gettok3:
+ cmp #$
+ cmp #$24 ; Is this character, a '$'?
+ beq getaddr ; Yes, so start getting the address.
+
+
+
+getdir_cmp:
+ phy #1
+ ldy.w #0
+ tyx
+getdir_cpl:
+ ldb dir, x ; Start checking if the directive we're using, is "org".
+ stb (ptr2), y
+ beq getdir_scmp
+ inx
+ iny
+ jmp getdir_cpl
+getdir_scmp:
+ ldy #0
+ jsr strcmp
+ cpx #0
+ beq getdir_tok
+getdir_exit:
+ rts ; End of getdir.
+
istoken:
cmp #$20 ; Is this character a space?
@@ -288,7 +434,7 @@ istoken:
beq istoken_f ; Yes, so return false.
cmp #$3B ; Is this character a ';'?
beq istoken_f ; Yes, so return false.
- cmp #$0 ; Is this character a null terminator?
+ cmp #0 ; Is this character a null terminator?
beq istoken_f ; Yes, so return false.
sec ; Return true.
rts ; End of istoken.
@@ -299,7 +445,7 @@ istoken_f
iswhite:
cmp #$20 ; Is this character a space?
beq iswhite_t ; Yes, so return true.
- cmp #$09 ; Is this character a tab?
+ cmp #9 ; Is this character a tab?
beq iswhite_t ; Yes, so return true.
clc ; No, so return false.
rts ; End of iswhite.
@@ -308,7 +454,7 @@ iswhite_t:
rts ; End of iswhite_t.
rset_y:
- ldy.w #$0
+ ldy.w #0
jmp print_buf ; Print the input buffer.
print_buf:
@@ -325,15 +471,15 @@ spin:
jmp spin
clr_buf:
- lda #$0
- cpy.w #$1000
+ lda #0
+ cpy.w #$3FF
beq clr_end
sta buf, y
iny
jmp clr_buf
clr_sbuf:
- lda #$0
- cpy.w #$40
+ lda #0
+ cpy.w #$1FF
beq clr_end
sta str_buf, y
iny
@@ -343,7 +489,7 @@ clr_end:
rts
echo:
- sta a
+ tab
ldx scr_col
cpx #$4F
bne echo_print
@@ -351,17 +497,51 @@ echo:
beq linewrap
linewrap:
inc scr_row
- ldx #$0
+ ldx #0
stx scr_col
jsr update_pos
echo_print:
- lda a
+ tba
sta scr ; Echo typed character.
inc scr_col ; Increment the cursor's x coordinate.
- sta str_buf, y ; Store typed character into the input buffer.
+ sta buf, y ; Store typed character into the input buffer.
iny ; Increment the buffer offset.
rts ; Return.
+clr_ptr:
+ lda #0
+ cpy.w #$3FF
+ beq ptr_end
+ sta (ptr1), y
+ sta (ptr2), y
+ iny
+ jmp clr_ptr
+ptr_end:
+ rts
+
+strcmp:
+ lda (ptr1), y
+ cmp (ptr2), y
+ bne strcmp_l1
+ tax
+ beq strcmp_l3
+ iny
+ bne strcmp
+ jmp strcmp
+
+
+strcmp_l1:
+ bcs strcmp_l2
+ ldx #0
+ dex
+ rts
+
+strcmp_l2:
+ ldx #1
+strcmp_l3:
+ rts
+
+
.org $FFC0
.qword reset
@@ -376,9 +556,23 @@ echo_print:
.org $FFA0
.qword irq_routine
-;.org $0
-;viewmem
-;.org $100
-;viewmem
-;q
-done
+.org $0
+v
+.org $100
+v
+.org $200
+v
+.org $300
+v
+.org $1000
+v
+.org $1100
+v
+.org $1200
+v
+.org $1300
+v
+.org $1400
+v
+q
+