2021-12-27 20:35:23 -05:00
|
|
|
( test-math32.tal )
|
2021-12-27 15:04:41 -05:00
|
|
|
( )
|
2021-12-27 20:35:23 -05:00
|
|
|
( methods for testing math32 and emitting output )
|
2021-12-27 15:04:41 -05:00
|
|
|
|
2021-12-28 21:16:21 -05:00
|
|
|
%EMIT { #18 DEO }
|
2021-12-27 15:04:41 -05:00
|
|
|
%DIGIT { #00 SWP ;digits ADD2 LDA EMIT }
|
|
|
|
%SPACE { #20 EMIT }
|
|
|
|
%NEWLINE { #0a EMIT }
|
|
|
|
%RESET-POS { #0000 ;pos STA2 #00 ;buf STA }
|
|
|
|
%EMIT-BYTE { DUP #04 SFT DIGIT #0f AND DIGIT }
|
|
|
|
|
|
|
|
( devices )
|
|
|
|
|10 @Console [ &vector $2 &read $1 &pad $5 &write $1 ]
|
|
|
|
|
|
|
|
( program )
|
|
|
|
|0100 ;test-interact .Console/vector DEO2 BRK
|
|
|
|
|
|
|
|
( include math32 library )
|
|
|
|
|
|
|
|
~math32.tal
|
|
|
|
|
|
|
|
( testing )
|
|
|
|
|
|
|
|
( parses hex representation e.g. #31 #33 -> #13 )
|
|
|
|
@parse-byte ( c0 c1 -> x^ )
|
|
|
|
( lower char )
|
|
|
|
DUP #3a LTH ,&lo-digit JCN
|
|
|
|
#57 ,&lo JMP &lo-digit #30
|
|
|
|
&lo SUB SWP
|
|
|
|
|
2021-12-28 21:16:21 -05:00
|
|
|
( higher char )
|
2021-12-27 15:04:41 -05:00
|
|
|
DUP #3a LTH ,&hi-digit JCN
|
|
|
|
#57 ,&hi JMP &hi-digit #30
|
|
|
|
&hi SUB #40 SFT ORA
|
|
|
|
RTN
|
|
|
|
|
|
|
|
@buf $24 ( buffer used by test-interact )
|
|
|
|
@pos $2 ( position in buffer used by test-interact )
|
|
|
|
|
|
|
|
( save character input and execute tests on \n )
|
|
|
|
( tests always start with a single character and a space )
|
|
|
|
( then additional arguments are passed. )
|
|
|
|
@test-interact
|
|
|
|
.Console/read DEI ( char^ )
|
|
|
|
DUP #0a EQU ( char^ char=\n? )
|
|
|
|
,&exec JCN ( char^ )
|
|
|
|
;pos LDA2 ;buf ADD2 STA
|
|
|
|
;pos LDA2k INC2 SWP2 STA2 BRK
|
|
|
|
&exec
|
|
|
|
POP ( )
|
|
|
|
;buf LDA LIT '+ EQU ;test-add32 JCN2
|
|
|
|
;buf LDA LIT '* EQU ;test-mul32 JCN2
|
|
|
|
;buf LDA LIT '- EQU ;test-sub32 JCN2
|
|
|
|
;buf LDA LIT '/ EQU ;test-div32 JCN2
|
2021-12-29 16:17:01 -05:00
|
|
|
;buf LDA LIT '% EQU ;test-mod32 JCN2
|
2021-12-29 01:00:07 -05:00
|
|
|
;buf LDA LIT 'L EQU ;test-lshift32 JCN2
|
|
|
|
;buf LDA LIT 'R EQU ;test-rshift32 JCN2
|
2021-12-27 15:04:41 -05:00
|
|
|
;buf LDA LIT 'B EQU ;test-bitcount32 JCN2
|
|
|
|
;buf LDA LIT '& EQU ;test-and32 JCN2
|
|
|
|
;buf LDA LIT '| EQU ;test-or32 JCN2
|
|
|
|
;buf LDA LIT '^ EQU ;test-xor32 JCN2
|
|
|
|
;buf LDA LIT '~ EQU ;test-complement32 JCN2
|
|
|
|
;buf LDA LIT 'N EQU ;test-negate32 JCN2
|
|
|
|
;buf LDA LIT '= EQU ;test-eq32 JCN2
|
|
|
|
;buf LDA LIT '! EQU ;test-ne32 JCN2
|
|
|
|
;buf LDA LIT '0 EQU ;test-is-zero32 JCN2
|
|
|
|
;buf LDA LIT 'Z EQU ;test-non-zero32 JCN2
|
|
|
|
;buf LDA LIT '< EQU ;test-lt32 JCN2
|
|
|
|
;buf LDA LIT '> EQU ;test-gt32 JCN2
|
|
|
|
;buf LDA LIT '{ EQU ;test-lteq32 JCN2
|
|
|
|
;buf LDA LIT '} EQU ;test-gteq32 JCN2
|
|
|
|
LIT '? EMIT NEWLINE RESET-POS BRK
|
|
|
|
|
|
|
|
@read-byte ( addr* -> x^ )
|
|
|
|
LDA2 ;parse-byte JSR2
|
|
|
|
RTN
|
|
|
|
|
|
|
|
@read-long ( addr* -> x** )
|
|
|
|
DUP2 ,&loc STR2 LDA2 ;parse-byte JSR2
|
|
|
|
,&loc LDR2 #0002 ADD2 LDA2 ;parse-byte JSR2
|
|
|
|
,&loc LDR2 #0004 ADD2 LDA2 ;parse-byte JSR2
|
|
|
|
,&loc LDR2 #0006 ADD2 LDA2 ;parse-byte JSR2
|
|
|
|
RTN
|
|
|
|
[ &loc $2 ]
|
|
|
|
|
|
|
|
( format: ". xxxxxxxx" -> "zzzzzzzz" )
|
|
|
|
@unary-32-test
|
|
|
|
;buf #0002 ADD2 ;read-long JSR2
|
|
|
|
ROT2 JSR2 ;emit-long JSR2
|
|
|
|
NEWLINE RESET-POS BRK
|
|
|
|
|
|
|
|
( format: ". xxxxxxxx" -> "zz" )
|
|
|
|
@unary-32-8-test
|
|
|
|
;buf #0002 ADD2 ;read-long JSR2
|
|
|
|
ROT2 JSR2 ;emit-byte JSR2
|
|
|
|
NEWLINE RESET-POS BRK
|
|
|
|
|
|
|
|
( format: ". xxxxxxxx yyyyyyyy" -> "zzzzzzzz" )
|
|
|
|
@binary-32-test
|
|
|
|
;buf #0002 ADD2 ;read-long JSR2
|
|
|
|
ROT2
|
|
|
|
;buf #000b ADD2 ;read-long JSR2
|
|
|
|
ROT2 JSR2 ;emit-long JSR2
|
|
|
|
NEWLINE RESET-POS BRK
|
|
|
|
|
|
|
|
( format: ". xxxxxxxx yy" -> "zzzzzzzz" )
|
|
|
|
@binary-32-8-32-test
|
|
|
|
;buf #0002 ADD2 ;read-long JSR2
|
|
|
|
ROT2
|
|
|
|
;buf #000b ADD2 ;read-byte JSR2
|
|
|
|
TOR JSR2 ;emit-long JSR2
|
|
|
|
NEWLINE RESET-POS BRK
|
|
|
|
|
|
|
|
( format: ". xxxxxxxx yyyyyyyy" -> "zz" )
|
|
|
|
@binary-32-32-8-test
|
|
|
|
;buf #0002 ADD2 ;read-long JSR2
|
|
|
|
ROT2
|
|
|
|
;buf #000b ADD2 ;read-long JSR2
|
|
|
|
ROT2 JSR2 ;emit-byte JSR2
|
|
|
|
NEWLINE RESET-POS BRK
|
|
|
|
|
|
|
|
( different test executors )
|
|
|
|
@test-add32 ;add32 ;binary-32-test JMP2
|
|
|
|
@test-mul32 ;mul32 ;binary-32-test JMP2
|
|
|
|
@test-sub32 ;sub32 ;binary-32-test JMP2
|
|
|
|
@test-div32 ;div32 ;binary-32-test JMP2
|
2021-12-29 16:17:01 -05:00
|
|
|
@test-mod32 ;mod32 ;binary-32-test JMP2
|
2021-12-29 01:00:07 -05:00
|
|
|
@test-lshift32 ;lshift32 ;binary-32-8-32-test JMP2
|
|
|
|
@test-rshift32 ;rshift32 ;binary-32-8-32-test JMP2
|
2021-12-27 15:04:41 -05:00
|
|
|
@test-bitcount32 ;bitcount32 ;unary-32-8-test JMP2
|
|
|
|
@test-and32 ;and32 ;binary-32-test JMP2
|
|
|
|
@test-or32 ;or32 ;binary-32-test JMP2
|
|
|
|
@test-xor32 ;xor32 ;binary-32-test JMP2
|
|
|
|
@test-complement32 ;complement32 ;unary-32-test JMP2
|
|
|
|
@test-negate32 ;negate32 ;unary-32-test JMP2
|
|
|
|
@test-eq32 ;eq32 ;binary-32-32-8-test JMP2
|
|
|
|
@test-ne32 ;ne32 ;binary-32-32-8-test JMP2
|
|
|
|
@test-is-zero32 ;is-zero32 ;unary-32-8-test JMP2
|
|
|
|
@test-non-zero32 ;non-zero32 ;unary-32-8-test JMP2
|
|
|
|
@test-lt32 ;lt32 ;binary-32-32-8-test JMP2
|
|
|
|
@test-lteq32 ;lteq32 ;binary-32-32-8-test JMP2
|
|
|
|
@test-gt32 ;gt32 ;binary-32-32-8-test JMP2
|
|
|
|
@test-gteq32 ;gteq32 ;binary-32-32-8-test JMP2
|
|
|
|
|
|
|
|
@emit-long ( hi* lo* -> )
|
|
|
|
SWP2
|
|
|
|
SWP EMIT-BYTE EMIT-BYTE
|
|
|
|
SWP EMIT-BYTE EMIT-BYTE
|
|
|
|
RTN
|
|
|
|
|
|
|
|
@emit-byte ( x^ -> )
|
|
|
|
EMIT-BYTE
|
|
|
|
RTN
|
|
|
|
|
|
|
|
( convenience for less branching when printing hex )
|
|
|
|
@digits
|
|
|
|
30 31 32 33 34 35 36 37
|
|
|
|
38 39 61 62 63 64 65 66
|