scu-dsp/parse10: implement end of chunk and end of input detection

This commit is contained in:
Zack Buhman 2025-08-10 00:04:12 -05:00
parent 55c38ebf5f
commit 4d51b47046

View File

@ -4,36 +4,55 @@
;; mov mc0,ra0 ;; mov mc0,ra0
;; variables: ;; variables:
;; m0[0] dma read start address (global) ;; m0[0]
;; m0[1] dma read value (local); post-shift 4-byte remainder (global) ;; m0[1] dma read value (local); post-shift 4-byte remainder (global)
;; m0[2] saved accumulator (global) ;; m0[2] saved accumulator (global)
caller_setup: setup:
mov 0,ct0 ;; [X ] [Y ] [D1 ]
;; start address mov 1,ct0
mov mc0,ra0 mov 0,ct3
mov 2,ct0 mov 0,mc0
;; mov 0,mc0 mov 0,mc0
mvi parse_base10,pc
mov 1,lop
;; parse_base10 return
mov all,mc3
mvi parse_base10,pc
mov 1,lop
;; parse_base10 return
mov all,mc3
nop
nop
nop
parse_base10: parse_base10:
next_chunk: ;; [X ] [Y ] [D1 ]
clr a mov 1,ct0 mov 1,ct0
mov m0,p mov m0,a
add
jmp nz,parse_loop
clr a ; delay slot
dma_next_chunk:
;; dma d0,mc0,1 ;; dma d0,mc0,1
;; begin fake number 0x39322033 "92 3" ;; begin fake number 0x39322033 "92 3"
mvi 0x393220,pl mvi 0x393220,pl
add mov alu,a mov 0x33,pl add mov alu,a mov 0x33,pl
rl8 mov alu,a rl8 mov alu,a mov 1,ct0
add mov all,mc0 add mov all,mc0
;; end fake number ;; end fake number
post_dma_load: end_dma_next_chunk:
parse_loop:
;; extract first (leftmost) digit ;; extract first (leftmost) digit
mov 1,ct0 mov 1,ct0
mov mc0,a mov 0x7f,pl mov mc0,a mov 0x7f,pl
rl8 mov alu,a ;;mov all,mc0 ; m0[1] 0x20323339 or
;; multiply saved accumulator by 10 jmp s,end_of_input
;; [X ] [Y ] [D1 ] rl8 mov alu,a mov 10,rx ; m0[2] 0x00000000
mov m0,y mov 10,rx ; m0[2] 0x00000000 jmp z,dma_next_chunk
and mov all,pl and mov m0,y mov all,pl
;; MUL: post-multiplication accumulator ;; MUL: post-multiplication accumulator
;; P: post-mask digit ;; P: post-mask digit
@ -41,8 +60,6 @@ post_dma_load:
mov 1,ct0 mov 1,ct0
xor clr a mov all,mc0 ; m0[1] 0x20323300 xor clr a mov all,mc0 ; m0[1] 0x20323300
;; FIXME: if 0x00 jump to "end of input"?
add mov alu,a mov 0x30,pl ; 0x30 ascii '0' add mov alu,a mov 0x30,pl ; 0x30 ascii '0'
;; A: post-mask digit ;; A: post-mask digit
@ -52,7 +69,7 @@ post_dma_load:
;; if ((0x39 - 0x30) < 0) goto non_digit; ;; if ((0x39 - 0x30) < 0) goto non_digit;
jmp s,non_digit jmp s,non_digit
;; possibly set S flag for `jmp ns,non_digit` ;; possibly set S flag for `jmp ns,non_digit`
sub ; sub in delay slot sub mov 2,ct0 ; sub in delay slot
;; if (((0x39 - 0x30) - 10) >= 0) goto non_digit; ;; if (((0x39 - 0x30) - 10) >= 0) goto non_digit;
jmp ns,non_digit jmp ns,non_digit
mov mul,p mov 2,ct0 ; mov in delay slot mov mul,p mov 2,ct0 ; mov in delay slot
@ -60,14 +77,17 @@ post_dma_load:
digit: digit:
;; we have a valid digit; add it to the accumulator; save to m0[2] ;; we have a valid digit; add it to the accumulator; save to m0[2]
;; [X ] [Y ] [D1 ] ;; [X ] [Y ] [D1 ]
jmp post_dma_load jmp parse_loop
add mov all,mc0 ; add in delay slot ; m0[2] 0x00000009 add mov all,mc0 ; add in delay slot ; m0[2] 0x00000009
non_digit: non_digit:
;; this is not a valid digit; return the accumulator ;; this is not a valid digit; return and clear the accumulator as A
;; [X ] [Y ] [D1 ] ;; [X ] [Y ] [D1 ]
btm btm
clr a ; clr in delay slot mov m0,a mov 0,mc0 ; clr in delay slot ; m0[2]
;; m0: ;; m0:
;; 00000000 32330000 00000009 0000000 ;; 00000000 32330000 00000009 0000000
end_of_input:
btm
clr a