; Altirra Acid800 test suite ; Copyright (C) 2010 Avery Lee, All Rights Reserved. ; ; Permission is hereby granted, free of charge, to any person obtaining a copy ; of this software and associated documentation files (the "Software"), to deal ; in the Software without restriction, including without limitation the rights ; to use, copy, modify, merge, publish, distribute, sublicense, and/or sell ; copies of the Software, and to permit persons to whom the Software is ; furnished to do so, subject to the following conditions: ; ; The above copyright notice and this permission notice shall be included in ; all copies or substantial portions of the Software. ; ; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR ; IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, ; FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE ; AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER ; LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, ; OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ; SOFTWARE. _SAP_HEADER "CPU: Basic instructions" opt h+o+ icl 'library.s' opt o- icl 'options.s' opt o+ org $0080 dc_con dta $00 ;decompression control byte dc_in0 dta $60 ;instruction dc_in1 dta $60 dc_in2 dta $60 dta $60 dc_a1 dta 0 ;input data dc_x1 dta 0 dc_y1 dta 0 dc_p1 dta 0 dc_m1 dta 0 dc_a2 dta 0 ;output data dc_x2 dta 0 dc_y2 dta 0 dc_p2 dta 0 dc_m2 dta 0 rand0 dta $78 ;32-bit LFSR rand1 dta $56 rand2 dta $34 rand3 dta $12 randt dta 0 dc_conm dta 0 ;decompression: new control byte mask dc_conc dta 0 ;decompression: new control byte mask bit count dc_conv dta 0 ;decompression: tracked control byte org $2000 main: _INITTEST c"CPU: Basic instructions" mwa #test_start a0 loop_start: ldy #0 ;check if have to get a new mask byte dec dc_conc bpl no_newmask mva (a0),y+ dc_conm mva #7 dc_conc no_newmask: ;check next mask bit asl dc_conm bcc no_new_control ;load control byte mva (a0),y+ dc_conv no_new_control: mva dc_conv dc_con ;check if we should reload the opcode asl dc_con bcc same_opcode mva (a0),y+ dc_in0 lda #$60 sta dc_in1 sta dc_in2 same_opcode: ;update instruction bytes if needed asl dc_con scc:mva (a0),y+ dc_in1 asl dc_con scc:mva (a0),y+ dc_in2 ;compute implicit A1 jsr detrand2 sta dc_a1 ;decompress X1 and Y1; note that X1 = ~Y1 lda (a0),y+ sta dc_y1 eor #$ff sta dc_x1 ;compute implicit P1 and M1 jsr detrand2 ora #$30 and #$f7 sta dc_p1 jsr detrand2 sta dc_m1 ;decompress A2, X2, Y2, P2, and M2 asl dc_con lda dc_a1 scc:lda (a0),y+ sta dc_a2 asl dc_con lda dc_x1 scc:lda (a0),y+ sta dc_x2 asl dc_con lda dc_y1 scc:lda (a0),y+ sta dc_y2 asl dc_con lda dc_p1 scc:lda (a0),y+ sta dc_p2 asl dc_con lda dc_m1 scc:lda (a0),y+ sta dc_m2 ;bump test pointer tya add a0 sta a0 scc:inc a0+1 ;setup temp registers mwa #d5 a1 mwa #d4 a2 ;stash P lda dc_p1 pha ;load d5 mva dc_m1 d5 ;load A, X, Y lda dc_a1 ldx dc_x1 ldy dc_y1 ;load P plp ;execute insn jsr dc_in0 ;store registers sta d1 stx d2 sty d3 php pla ora #$30 sta d4 ;reset flags cli cld ;compare registers lda dc_a2 cmp d1 bne fail cpx dc_x2 bne fail cpy dc_y2 bne fail lda dc_p2 cmp d4 bne fail lda dc_m2 cmp d5 bne fail ;go another round lda a0 cmp #test_end beq loop_exit loop_end: jmp loop_start loop_exit: jmp _testPassed fail: cld cli jsr _imprintf dta c"FAIL.",$9b,c"Test failed: A=%x X=%x Y=%x P=%x M=%x",$9b,0 ldx #5 copyloop: lda dc_a1-1,x sta d0,x dex bne copyloop jsr _imprintf dta c"Input: A=%x X=%x Y=%x P=%x M=%x",$9b,0 mva dc_in0 d1 mva dc_in1 d2 mva dc_in2 d3 ldy #>failmsg lda #