From f0518b15d62045b38e299889eb7e297124686867 Mon Sep 17 00:00:00 2001 From: GamingMadster <151962957+GamingMadster@users.noreply.github.com> Date: Fri, 27 Dec 2024 10:55:13 -0600 Subject: [PATCH 1/2] Add CXNN Test --- src/tests/3-corax+.8o | 1072 ++++++++++++++++++++++------------------- 1 file changed, 569 insertions(+), 503 deletions(-) diff --git a/src/tests/3-corax+.8o b/src/tests/3-corax+.8o index fc9fe85..7cd5efe 100644 --- a/src/tests/3-corax+.8o +++ b/src/tests/3-corax+.8o @@ -1,503 +1,569 @@ -# This is an adaptation and extension of the CHIP-8 test rom from corax89, -# original can be found here: -# https://github.com/corax89/chip8-test-rom - -# MIT License -# -# Copyright (c) 2019 corax89, 2023,2024 Timendus -# -# 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. - -:alias x0 v8 -:alias x1 v9 -:alias x2 vA -:alias y vB - -:macro drawop A B { - i := A - sprite x0 y 4 - - i := B - sprite x1 y 4 -} - -: test-2X-0E - v0 := 1 - return - # These opcodes will run if the interpreter doesn't have return (00EE) implemented: - v0 := 2 - jump test-2X-0E-hard-return - -: main - clear - - # Display current version - x0 := 50 - y := 26 - i := version-0-0 - sprite x0 y 4 - x0 := 58 - i := version-1-0 - sprite x0 y 4 - - # Show output in the first column - x0 := 2 - x1 := 6 - x2 := 11 - y := 1 - -################# -# Test 3xNN - - v5 := 42 - v6 := 43 - drawop im3 imX - i := image-ok - if v6 != 43 then i := image-no - sprite x2 y 4 - -################# -# Test 4xNN - - y := 6 - drawop im4 imX - i := image-no - if v5 == 42 then i := image-ok - sprite x2 y 4 - -################# -# Test 5xy0 - - y := 11 - drawop im5 imX - i := image-no - if v5 != v6 then i := image-ok - sprite x2 y 4 - -################# -# Test 7xNN - - y := 16 - drawop im7 imX - i := image-no - v6 += 255 - if v6 == 42 then i := image-ok - sprite x2 y 4 - -################# -# Test 9xy0 - - y += 5 - drawop im9 imX - i := image-no - if v5 == v6 then i := image-ok - sprite x2 y 4 - -################# -# Test 1NNN (displayed as 1X) - - y += 5 - drawop im1 imX - i := image-ok - jump test-1X-pass - i := image-no -: test-1X-pass - sprite x2 y 4 - - # Show output in the second column - x0 := 18 - x1 := 22 - x2 := 27 - y := 1 - -################# -# Test calling subroutines (2NNN, displayed as 2X) - - drawop im2 imX - v0 := 0 - test-2X-0E # Attempt to run a subroutine -: test-2X-0E-hard-return - i := image-ok - if v0 == 0 then i := image-no # Subroutine was never called - sprite x2 y 4 - -################# -# Test returning from subroutines (00EE, displayed as 0E) - - y += 5 - drawop im0 imE - i := image-ok - if v0 == 2 then i := image-no # Return didn't work - if v0 != 0 then sprite x2 y 4 # If subroutine wasn't called, return wasn't tested - -################# -# Test 8xy0 - - y += 5 - drawop im8 im0 - i := image-no - v5 := 42 - v7 := 0 - v7 := v5 - if v7 == 42 then i := image-ok - sprite x2 y 4 - -################# -# Test 8xy1 - - y += 5 - drawop im8 im1 - i := image-no - v6 := 11 - v7 := 42 - v7 |= v6 - if v7 == 43 then i := image-ok - sprite x2 y 4 - -################# -# Test 8xy2 - - y += 5 - drawop im8 im2 - i := image-no - v6 := 120 - v7 := 31 - v7 &= v6 - if v7 == 24 then i := image-ok - sprite x2 y 4 - -################# -# Test 8xy3 - - y += 5 - drawop im8 im3 - i := image-no - v6 := 120 - v7 := 31 - v7 ^= v6 - if v7 == 103 then i := image-ok - sprite x2 y 4 - - # Show output in the third column - x0 := 34 - x1 := 38 - x2 := 43 - y := 1 - -################# -# Test 8xy4 - - drawop im8 im4 - i := image-no - v6 := 140 - v7 := 140 - v7 += v6 - if v7 == 24 then i := image-ok - sprite x2 y 4 - -################# -# Test 8xy5 - - y += 5 - drawop im8 im5 - i := image-no - v6 := 140 - v7 := 120 - v7 -= v6 - if v7 == 236 then i := image-ok - sprite x2 y 4 - -################# -# Test 8xy7 - - y += 5 - drawop im8 im7 - i := image-no - v6 := 120 - v7 := 140 - v7 =- v6 - if v7 == 236 then i := image-ok - sprite x2 y 4 - -################# -# Test 8xy6 - - y += 5 - drawop im8 im6 - i := image-no - v6 := 15 - v6 >>= v6 - if v6 == 7 then i := image-ok - sprite x2 y 4 - -################# -# Test 8xyE - - y += 5 - drawop im8 imE - i := image-no - v6 := 224 - v6 <<= v6 - if v6 == 192 then i := image-ok - sprite x2 y 4 - -################# -# Test Fx65 - - y += 5 - drawop imF im6 - i := scratchpad - load v1 - i := image-ok - if v0 != 0xAA then i := image-no - if v1 != 0x55 then i := image-no - sprite x2 y 4 - -################# -# Test Fx55 - - x0 := 50 - x1 := 54 - x2 := 59 - y := 1 - drawop imF im5 - i := scratchpad - v0 := 0 - v1 := 48 - save v1 - i := scratchpad - load v0 - v1 := v0 - i := scratchpad-plus-1 - load v0 - i := image-ok - if v0 != 48 then i := image-no - if v1 != 0 then i := image-no - sprite x2 y 4 - -################# -# Test Fx33 - - y += 5 - drawop imF im3 - - # N >= 100 - i := scratchpad - v6 := 137 - bcd v6 - load v2 - i := image-no - if v0 != 1 then jump fx33-fail - if v1 != 3 then jump fx33-fail - if v2 != 7 then jump fx33-fail - - # N < 100 - i := scratchpad - v6 := 65 - bcd v6 - load v2 - i := image-no - if v0 != 0 then jump fx33-fail - if v1 != 6 then jump fx33-fail - if v2 != 5 then jump fx33-fail - - # N < 10 - i := scratchpad - v6 := 4 - bcd v6 - load v2 - i := image-no - if v0 != 0 then jump fx33-fail - if v1 != 0 then jump fx33-fail - if v2 != 4 then jump fx33-fail - - i := image-ok -: fx33-fail - sprite x2 y 4 - -################# -# Test Fx1E - - y += 5 - drawop imF imE - i := image-no - v6 := 4 - i += v6 - sprite x2 y 4 - -################# -# Test to see if registers are 8 bit, as thoroughly as possible. - - y += 5 - drawop imV imX - i := image-ok - - # Addition opcodes should not allow us to overflow - v6 := 255 - v6 += 10 - if v6 != 9 then i := image-no - v6 >>= v6 - if v6 != 4 then i := image-no - v6 := 255 - v0 := 10 - v6 += v0 - if v6 != 9 then i := image-no - v6 >>= v6 - if v6 != 4 then i := image-no - - # Shift opcodes should not retain bits - v6 := 255 - v6 <<= v6 - v6 >>= v6 - if v6 != 127 then i := image-no - v6 >>= v6 - v6 <<= v6 - if v6 != 126 then i := image-no - - # Subtraction should wrap back to positive - v6 := 5 - v6 -= 10 - if v6 != 251 then i := image-no - v6 := 5 - v6 -= v0 - if v6 != 251 then i := image-no - v6 := 5 - v0 =- v6 - if v0 != 251 then i := image-no - - sprite x2 y 4 - -################# -# Test is done! - - loop again - -:segment data - -: scratchpad - 0xAA -: scratchpad-plus-1 - 0x55 0 - -# Positive and negative images -: image-no - 0b00000000 - 0b10100000 - 0b01000000 - 0b10100000 -: image-ok - 0b00000000 - 0b10100000 - 0b11000000 - 0b10000000 - -# Individual characters, some taken from Corax89' test. -: im0 - 0b11100000 - 0b10100000 - 0b10100000 - 0b11100000 -: im1 - 0b11000000 - 0b01000000 - 0b01000000 - 0b11100000 -: im2 - 0b11100000 - 0b00100000 - 0b11000000 - 0b11100000 -: im3 - 0b11100000 - 0b01100000 - 0b00100000 - 0b11100000 -: im4 - 0b10100000 - 0b11100000 - 0b00100000 - 0b00100000 -: im5 - 0b11100000 - 0b11000000 - 0b00100000 - 0b11000000 -: im6 - 0b01100000 - 0b10000000 - 0b11100000 - 0b11100000 -: im7 - 0b11100000 - 0b00100000 - 0b01000000 - 0b01000000 -: im8 - 0b11100000 - 0b11100000 - 0b10100000 - 0b11100000 -: im9 - 0b11100000 - 0b11100000 - 0b00100000 - 0b11000000 -: imA - 0b01000000 - 0b10100000 - 0b11100000 - 0b10100000 -: imB - 0b11000000 - 0b11100000 - 0b10100000 - 0b11100000 -: imC - 0b11100000 - 0b10000000 - 0b10000000 - 0b11100000 -: imD - 0b11000000 - 0b10100000 - 0b10100000 - 0b11000000 -: imE - 0b11100000 - 0b11000000 - 0b10000000 - 0b11100000 -: imF - 0b11100000 - 0b10000000 - 0b11000000 - 0b10000000 -: imV - 0b00000000 - 0b10100000 - 0b10100000 - 0b01000000 -: imX - 0b10100000 - 0b01000000 - 0b10100000 - 0b10100000 - -: version - :include "../../pictures/version.png" +# This is an adaptation and extension of the CHIP-8 test rom from corax89, +# original can be found here: +# https://github.com/corax89/chip8-test-rom + +# MIT License +# +# Copyright (c) 2019 corax89, 2023,2024 Timendus +# +# 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. + +:alias x0 v8 +:alias x1 v9 +:alias x2 vA +:alias y vB + +:macro drawop A B { + i := A + sprite x0 y 4 + + i := B + sprite x1 y 4 +} + +: test-2X-0E + v0 := 1 + return + # These opcodes will run if the interpreter doesn't have return (00EE) implemented: + v0 := 2 + jump test-2X-0E-hard-return + +: main + clear + + # Display current version + x0 := 50 + y := 26 + i := version-0-0 + sprite x0 y 4 + x0 := 58 + i := version-1-0 + sprite x0 y 4 + + # Show output in the first column + x0 := 2 + x1 := 6 + x2 := 11 + y := 1 + +################# +# Test 3xNN + + v5 := 42 + v6 := 43 + drawop im3 imX + i := image-ok + if v6 != 43 then i := image-no + sprite x2 y 4 + +################# +# Test 4xNN + + y := 6 + drawop im4 imX + i := image-no + if v5 == 42 then i := image-ok + sprite x2 y 4 + +################# +# Test 5xy0 + + y := 11 + drawop im5 imX + i := image-no + if v5 != v6 then i := image-ok + sprite x2 y 4 + +################# +# Test 7xNN + + y := 16 + drawop im7 imX + i := image-no + v6 += 255 + if v6 == 42 then i := image-ok + sprite x2 y 4 + +################# +# Test 9xy0 + + y += 5 + drawop im9 imX + i := image-no + if v5 == v6 then i := image-ok + sprite x2 y 4 + +################# +# Test 1NNN (displayed as 1X) + + y += 5 + drawop im1 imX + i := image-ok + jump test-1X-pass + i := image-no +: test-1X-pass + sprite x2 y 4 + + # Show output in the second column + x0 := 18 + x1 := 22 + x2 := 27 + y := 1 + +################# +# Test calling subroutines (2NNN, displayed as 2X) + + drawop im2 imX + v0 := 0 + test-2X-0E # Attempt to run a subroutine +: test-2X-0E-hard-return + i := image-ok + if v0 == 0 then i := image-no # Subroutine was never called + sprite x2 y 4 + +################# +# Test returning from subroutines (00EE, displayed as 0E) + + y += 5 + drawop im0 imE + i := image-ok + if v0 == 2 then i := image-no # Return didn't work + if v0 != 0 then sprite x2 y 4 # If subroutine wasn't called, return wasn't tested + +################# +# Test 8xy0 + + y += 5 + drawop im8 im0 + i := image-no + v5 := 42 + v7 := 0 + v7 := v5 + if v7 == 42 then i := image-ok + sprite x2 y 4 + +################# +# Test 8xy1 + + y += 5 + drawop im8 im1 + i := image-no + v6 := 11 + v7 := 42 + v7 |= v6 + if v7 == 43 then i := image-ok + sprite x2 y 4 + +################# +# Test 8xy2 + + y += 5 + drawop im8 im2 + i := image-no + v6 := 120 + v7 := 31 + v7 &= v6 + if v7 == 24 then i := image-ok + sprite x2 y 4 + +################# +# Test 8xy3 + + y += 5 + drawop im8 im3 + i := image-no + v6 := 120 + v7 := 31 + v7 ^= v6 + if v7 == 103 then i := image-ok + sprite x2 y 4 + + # Show output in the third column + x0 := 34 + x1 := 38 + x2 := 43 + y := 1 + +################# +# Test 8xy4 + + drawop im8 im4 + i := image-no + v6 := 140 + v7 := 140 + v7 += v6 + if v7 == 24 then i := image-ok + sprite x2 y 4 + +################# +# Test 8xy5 + + y += 5 + drawop im8 im5 + i := image-no + v6 := 140 + v7 := 120 + v7 -= v6 + if v7 == 236 then i := image-ok + sprite x2 y 4 + +################# +# Test 8xy7 + + y += 5 + drawop im8 im7 + i := image-no + v6 := 120 + v7 := 140 + v7 =- v6 + if v7 == 236 then i := image-ok + sprite x2 y 4 + +################# +# Test 8xy6 + + y += 5 + drawop im8 im6 + i := image-no + v6 := 15 + v6 >>= v6 + if v6 == 7 then i := image-ok + sprite x2 y 4 + +################# +# Test 8xyE + + y += 5 + drawop im8 imE + i := image-no + v6 := 224 + v6 <<= v6 + if v6 == 192 then i := image-ok + sprite x2 y 4 + +################# +# Test Fx65 + + y += 5 + drawop imF im6 + i := scratchpad + load v1 + i := image-ok + if v0 != 0xAA then i := image-no + if v1 != 0x55 then i := image-no + sprite x2 y 4 + +################# +# Test Fx55 + + x0 := 50 + x1 := 54 + x2 := 59 + y := 1 + drawop imF im5 + i := scratchpad + v0 := 0 + v1 := 48 + save v1 + i := scratchpad + load v0 + v1 := v0 + i := scratchpad-plus-1 + load v0 + i := image-ok + if v0 != 48 then i := image-no + if v1 != 0 then i := image-no + sprite x2 y 4 + +################# +# Test Fx33 + + y += 5 + drawop imF im3 + + # N >= 100 + i := scratchpad + v6 := 137 + bcd v6 + load v2 + i := image-no + if v0 != 1 then jump fx33-fail + if v1 != 3 then jump fx33-fail + if v2 != 7 then jump fx33-fail + + # N < 100 + i := scratchpad + v6 := 65 + bcd v6 + load v2 + i := image-no + if v0 != 0 then jump fx33-fail + if v1 != 6 then jump fx33-fail + if v2 != 5 then jump fx33-fail + + # N < 10 + i := scratchpad + v6 := 4 + bcd v6 + load v2 + i := image-no + if v0 != 0 then jump fx33-fail + if v1 != 0 then jump fx33-fail + if v2 != 4 then jump fx33-fail + + i := image-ok +: fx33-fail + sprite x2 y 4 + +################# +# Test Fx1E + + y += 5 + drawop imF imE + i := image-no + v6 := 4 + i += v6 + sprite x2 y 4 + +################# +# Test to see if registers are 8 bit, as thoroughly as possible. + + y += 5 + drawop imV imX + i := image-ok + + # Addition opcodes should not allow us to overflow + v6 := 255 + v6 += 10 + if v6 != 9 then i := image-no + v6 >>= v6 + if v6 != 4 then i := image-no + v6 := 255 + v0 := 10 + v6 += v0 + if v6 != 9 then i := image-no + v6 >>= v6 + if v6 != 4 then i := image-no + + # Shift opcodes should not retain bits + v6 := 255 + v6 <<= v6 + v6 >>= v6 + if v6 != 127 then i := image-no + v6 >>= v6 + v6 <<= v6 + if v6 != 126 then i := image-no + + # Subtraction should wrap back to positive + v6 := 5 + v6 -= 10 + if v6 != 251 then i := image-no + v6 := 5 + v6 -= v0 + if v6 != 251 then i := image-no + v6 := 5 + v0 =- v6 + if v0 != 251 then i := image-no + + sprite x2 y 4 + +################# +# Test CxNN (Fairly long test, and also prone to failing) + + # See if a random number is returned +y += 5 + drawop imC imX + + i := image-no + + v6 := 0 + v7 := 0 + + loop + v7 += 1 + v6 := random 255 + + if v7 == 0 then jump cxnn-fail + if v6 > 255 then cxnn-fail + if v6 == 0 then + again + + # Masking tests + # Mask of 0x00 + v6 := 0 + v7 := 0 + + loop + v7 += 1 + v6 := random 0 + + if v6 != 0 then jump cxnn-fail + if v7 != 0 then + again + + # Mask of 0x0F + v6 := 0 + v7 := 0 + + loop + v7 += 1 + v6 := random 0xF + + if v6 > 0xF then jump cxnn-fail + if v7 != 0 then + again + + # Mask of 0xF0 + v6 := 0 + v7 := 0 + v4 := 0xF0 + + loop + v7 += 1 + v6 := random 0xF0 + v5 := v6 + v5 &= v4 + + if v6 > 0xF0 then jump cxnn-fail + if v6 != v5 then jump cxnn-fail + if v7 != 0 then + again + + i := image-ok +: cxnn-fail + sprite x2 y 4 + +################# +# Test is done! + + loop again + +:segment data + +: scratchpad + 0xAA +: scratchpad-plus-1 + 0x55 0 + +# Positive and negative images +: image-no + 0b00000000 + 0b10100000 + 0b01000000 + 0b10100000 +: image-ok + 0b00000000 + 0b10100000 + 0b11000000 + 0b10000000 + +# Individual characters, some taken from Corax89' test. +: im0 + 0b11100000 + 0b10100000 + 0b10100000 + 0b11100000 +: im1 + 0b11000000 + 0b01000000 + 0b01000000 + 0b11100000 +: im2 + 0b11100000 + 0b00100000 + 0b11000000 + 0b11100000 +: im3 + 0b11100000 + 0b01100000 + 0b00100000 + 0b11100000 +: im4 + 0b10100000 + 0b11100000 + 0b00100000 + 0b00100000 +: im5 + 0b11100000 + 0b11000000 + 0b00100000 + 0b11000000 +: im6 + 0b01100000 + 0b10000000 + 0b11100000 + 0b11100000 +: im7 + 0b11100000 + 0b00100000 + 0b01000000 + 0b01000000 +: im8 + 0b11100000 + 0b11100000 + 0b10100000 + 0b11100000 +: im9 + 0b11100000 + 0b11100000 + 0b00100000 + 0b11000000 +: imA + 0b01000000 + 0b10100000 + 0b11100000 + 0b10100000 +: imB + 0b11000000 + 0b11100000 + 0b10100000 + 0b11100000 +: imC + 0b11100000 + 0b10000000 + 0b10000000 + 0b11100000 +: imD + 0b11000000 + 0b10100000 + 0b10100000 + 0b11000000 +: imE + 0b11100000 + 0b11000000 + 0b10000000 + 0b11100000 +: imF + 0b11100000 + 0b10000000 + 0b11000000 + 0b10000000 +: imV + 0b00000000 + 0b10100000 + 0b10100000 + 0b01000000 +: imX + 0b10100000 + 0b01000000 + 0b10100000 + 0b10100000 + +: version + :include "../../pictures/version.png" From d74a43bdb4fa6306465ebecbaee6cf4d306deb10 Mon Sep 17 00:00:00 2001 From: GamingMadster <151962957+GamingMadster@users.noreply.github.com> Date: Fri, 27 Dec 2024 11:26:07 -0600 Subject: [PATCH 2/2] Fixed Line Endings --- src/tests/3-corax+.8o | 1138 ++++++++++++++++++++--------------------- 1 file changed, 569 insertions(+), 569 deletions(-) diff --git a/src/tests/3-corax+.8o b/src/tests/3-corax+.8o index 7cd5efe..aa1c185 100644 --- a/src/tests/3-corax+.8o +++ b/src/tests/3-corax+.8o @@ -1,569 +1,569 @@ -# This is an adaptation and extension of the CHIP-8 test rom from corax89, -# original can be found here: -# https://github.com/corax89/chip8-test-rom - -# MIT License -# -# Copyright (c) 2019 corax89, 2023,2024 Timendus -# -# 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. - -:alias x0 v8 -:alias x1 v9 -:alias x2 vA -:alias y vB - -:macro drawop A B { - i := A - sprite x0 y 4 - - i := B - sprite x1 y 4 -} - -: test-2X-0E - v0 := 1 - return - # These opcodes will run if the interpreter doesn't have return (00EE) implemented: - v0 := 2 - jump test-2X-0E-hard-return - -: main - clear - - # Display current version - x0 := 50 - y := 26 - i := version-0-0 - sprite x0 y 4 - x0 := 58 - i := version-1-0 - sprite x0 y 4 - - # Show output in the first column - x0 := 2 - x1 := 6 - x2 := 11 - y := 1 - -################# -# Test 3xNN - - v5 := 42 - v6 := 43 - drawop im3 imX - i := image-ok - if v6 != 43 then i := image-no - sprite x2 y 4 - -################# -# Test 4xNN - - y := 6 - drawop im4 imX - i := image-no - if v5 == 42 then i := image-ok - sprite x2 y 4 - -################# -# Test 5xy0 - - y := 11 - drawop im5 imX - i := image-no - if v5 != v6 then i := image-ok - sprite x2 y 4 - -################# -# Test 7xNN - - y := 16 - drawop im7 imX - i := image-no - v6 += 255 - if v6 == 42 then i := image-ok - sprite x2 y 4 - -################# -# Test 9xy0 - - y += 5 - drawop im9 imX - i := image-no - if v5 == v6 then i := image-ok - sprite x2 y 4 - -################# -# Test 1NNN (displayed as 1X) - - y += 5 - drawop im1 imX - i := image-ok - jump test-1X-pass - i := image-no -: test-1X-pass - sprite x2 y 4 - - # Show output in the second column - x0 := 18 - x1 := 22 - x2 := 27 - y := 1 - -################# -# Test calling subroutines (2NNN, displayed as 2X) - - drawop im2 imX - v0 := 0 - test-2X-0E # Attempt to run a subroutine -: test-2X-0E-hard-return - i := image-ok - if v0 == 0 then i := image-no # Subroutine was never called - sprite x2 y 4 - -################# -# Test returning from subroutines (00EE, displayed as 0E) - - y += 5 - drawop im0 imE - i := image-ok - if v0 == 2 then i := image-no # Return didn't work - if v0 != 0 then sprite x2 y 4 # If subroutine wasn't called, return wasn't tested - -################# -# Test 8xy0 - - y += 5 - drawop im8 im0 - i := image-no - v5 := 42 - v7 := 0 - v7 := v5 - if v7 == 42 then i := image-ok - sprite x2 y 4 - -################# -# Test 8xy1 - - y += 5 - drawop im8 im1 - i := image-no - v6 := 11 - v7 := 42 - v7 |= v6 - if v7 == 43 then i := image-ok - sprite x2 y 4 - -################# -# Test 8xy2 - - y += 5 - drawop im8 im2 - i := image-no - v6 := 120 - v7 := 31 - v7 &= v6 - if v7 == 24 then i := image-ok - sprite x2 y 4 - -################# -# Test 8xy3 - - y += 5 - drawop im8 im3 - i := image-no - v6 := 120 - v7 := 31 - v7 ^= v6 - if v7 == 103 then i := image-ok - sprite x2 y 4 - - # Show output in the third column - x0 := 34 - x1 := 38 - x2 := 43 - y := 1 - -################# -# Test 8xy4 - - drawop im8 im4 - i := image-no - v6 := 140 - v7 := 140 - v7 += v6 - if v7 == 24 then i := image-ok - sprite x2 y 4 - -################# -# Test 8xy5 - - y += 5 - drawop im8 im5 - i := image-no - v6 := 140 - v7 := 120 - v7 -= v6 - if v7 == 236 then i := image-ok - sprite x2 y 4 - -################# -# Test 8xy7 - - y += 5 - drawop im8 im7 - i := image-no - v6 := 120 - v7 := 140 - v7 =- v6 - if v7 == 236 then i := image-ok - sprite x2 y 4 - -################# -# Test 8xy6 - - y += 5 - drawop im8 im6 - i := image-no - v6 := 15 - v6 >>= v6 - if v6 == 7 then i := image-ok - sprite x2 y 4 - -################# -# Test 8xyE - - y += 5 - drawop im8 imE - i := image-no - v6 := 224 - v6 <<= v6 - if v6 == 192 then i := image-ok - sprite x2 y 4 - -################# -# Test Fx65 - - y += 5 - drawop imF im6 - i := scratchpad - load v1 - i := image-ok - if v0 != 0xAA then i := image-no - if v1 != 0x55 then i := image-no - sprite x2 y 4 - -################# -# Test Fx55 - - x0 := 50 - x1 := 54 - x2 := 59 - y := 1 - drawop imF im5 - i := scratchpad - v0 := 0 - v1 := 48 - save v1 - i := scratchpad - load v0 - v1 := v0 - i := scratchpad-plus-1 - load v0 - i := image-ok - if v0 != 48 then i := image-no - if v1 != 0 then i := image-no - sprite x2 y 4 - -################# -# Test Fx33 - - y += 5 - drawop imF im3 - - # N >= 100 - i := scratchpad - v6 := 137 - bcd v6 - load v2 - i := image-no - if v0 != 1 then jump fx33-fail - if v1 != 3 then jump fx33-fail - if v2 != 7 then jump fx33-fail - - # N < 100 - i := scratchpad - v6 := 65 - bcd v6 - load v2 - i := image-no - if v0 != 0 then jump fx33-fail - if v1 != 6 then jump fx33-fail - if v2 != 5 then jump fx33-fail - - # N < 10 - i := scratchpad - v6 := 4 - bcd v6 - load v2 - i := image-no - if v0 != 0 then jump fx33-fail - if v1 != 0 then jump fx33-fail - if v2 != 4 then jump fx33-fail - - i := image-ok -: fx33-fail - sprite x2 y 4 - -################# -# Test Fx1E - - y += 5 - drawop imF imE - i := image-no - v6 := 4 - i += v6 - sprite x2 y 4 - -################# -# Test to see if registers are 8 bit, as thoroughly as possible. - - y += 5 - drawop imV imX - i := image-ok - - # Addition opcodes should not allow us to overflow - v6 := 255 - v6 += 10 - if v6 != 9 then i := image-no - v6 >>= v6 - if v6 != 4 then i := image-no - v6 := 255 - v0 := 10 - v6 += v0 - if v6 != 9 then i := image-no - v6 >>= v6 - if v6 != 4 then i := image-no - - # Shift opcodes should not retain bits - v6 := 255 - v6 <<= v6 - v6 >>= v6 - if v6 != 127 then i := image-no - v6 >>= v6 - v6 <<= v6 - if v6 != 126 then i := image-no - - # Subtraction should wrap back to positive - v6 := 5 - v6 -= 10 - if v6 != 251 then i := image-no - v6 := 5 - v6 -= v0 - if v6 != 251 then i := image-no - v6 := 5 - v0 =- v6 - if v0 != 251 then i := image-no - - sprite x2 y 4 - -################# -# Test CxNN (Fairly long test, and also prone to failing) - - # See if a random number is returned -y += 5 - drawop imC imX - - i := image-no - - v6 := 0 - v7 := 0 - - loop - v7 += 1 - v6 := random 255 - - if v7 == 0 then jump cxnn-fail - if v6 > 255 then cxnn-fail - if v6 == 0 then - again - - # Masking tests - # Mask of 0x00 - v6 := 0 - v7 := 0 - - loop - v7 += 1 - v6 := random 0 - - if v6 != 0 then jump cxnn-fail - if v7 != 0 then - again - - # Mask of 0x0F - v6 := 0 - v7 := 0 - - loop - v7 += 1 - v6 := random 0xF - - if v6 > 0xF then jump cxnn-fail - if v7 != 0 then - again - - # Mask of 0xF0 - v6 := 0 - v7 := 0 - v4 := 0xF0 - - loop - v7 += 1 - v6 := random 0xF0 - v5 := v6 - v5 &= v4 - - if v6 > 0xF0 then jump cxnn-fail - if v6 != v5 then jump cxnn-fail - if v7 != 0 then - again - - i := image-ok -: cxnn-fail - sprite x2 y 4 - -################# -# Test is done! - - loop again - -:segment data - -: scratchpad - 0xAA -: scratchpad-plus-1 - 0x55 0 - -# Positive and negative images -: image-no - 0b00000000 - 0b10100000 - 0b01000000 - 0b10100000 -: image-ok - 0b00000000 - 0b10100000 - 0b11000000 - 0b10000000 - -# Individual characters, some taken from Corax89' test. -: im0 - 0b11100000 - 0b10100000 - 0b10100000 - 0b11100000 -: im1 - 0b11000000 - 0b01000000 - 0b01000000 - 0b11100000 -: im2 - 0b11100000 - 0b00100000 - 0b11000000 - 0b11100000 -: im3 - 0b11100000 - 0b01100000 - 0b00100000 - 0b11100000 -: im4 - 0b10100000 - 0b11100000 - 0b00100000 - 0b00100000 -: im5 - 0b11100000 - 0b11000000 - 0b00100000 - 0b11000000 -: im6 - 0b01100000 - 0b10000000 - 0b11100000 - 0b11100000 -: im7 - 0b11100000 - 0b00100000 - 0b01000000 - 0b01000000 -: im8 - 0b11100000 - 0b11100000 - 0b10100000 - 0b11100000 -: im9 - 0b11100000 - 0b11100000 - 0b00100000 - 0b11000000 -: imA - 0b01000000 - 0b10100000 - 0b11100000 - 0b10100000 -: imB - 0b11000000 - 0b11100000 - 0b10100000 - 0b11100000 -: imC - 0b11100000 - 0b10000000 - 0b10000000 - 0b11100000 -: imD - 0b11000000 - 0b10100000 - 0b10100000 - 0b11000000 -: imE - 0b11100000 - 0b11000000 - 0b10000000 - 0b11100000 -: imF - 0b11100000 - 0b10000000 - 0b11000000 - 0b10000000 -: imV - 0b00000000 - 0b10100000 - 0b10100000 - 0b01000000 -: imX - 0b10100000 - 0b01000000 - 0b10100000 - 0b10100000 - -: version - :include "../../pictures/version.png" +# This is an adaptation and extension of the CHIP-8 test rom from corax89, +# original can be found here: +# https://github.com/corax89/chip8-test-rom + +# MIT License +# +# Copyright (c) 2019 corax89, 2023,2024 Timendus +# +# 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. + +:alias x0 v8 +:alias x1 v9 +:alias x2 vA +:alias y vB + +:macro drawop A B { + i := A + sprite x0 y 4 + + i := B + sprite x1 y 4 +} + +: test-2X-0E + v0 := 1 + return + # These opcodes will run if the interpreter doesn't have return (00EE) implemented: + v0 := 2 + jump test-2X-0E-hard-return + +: main + clear + + # Display current version + x0 := 50 + y := 26 + i := version-0-0 + sprite x0 y 4 + x0 := 58 + i := version-1-0 + sprite x0 y 4 + + # Show output in the first column + x0 := 2 + x1 := 6 + x2 := 11 + y := 1 + +################# +# Test 3xNN + + v5 := 42 + v6 := 43 + drawop im3 imX + i := image-ok + if v6 != 43 then i := image-no + sprite x2 y 4 + +################# +# Test 4xNN + + y := 6 + drawop im4 imX + i := image-no + if v5 == 42 then i := image-ok + sprite x2 y 4 + +################# +# Test 5xy0 + + y := 11 + drawop im5 imX + i := image-no + if v5 != v6 then i := image-ok + sprite x2 y 4 + +################# +# Test 7xNN + + y := 16 + drawop im7 imX + i := image-no + v6 += 255 + if v6 == 42 then i := image-ok + sprite x2 y 4 + +################# +# Test 9xy0 + + y += 5 + drawop im9 imX + i := image-no + if v5 == v6 then i := image-ok + sprite x2 y 4 + +################# +# Test 1NNN (displayed as 1X) + + y += 5 + drawop im1 imX + i := image-ok + jump test-1X-pass + i := image-no +: test-1X-pass + sprite x2 y 4 + + # Show output in the second column + x0 := 18 + x1 := 22 + x2 := 27 + y := 1 + +################# +# Test calling subroutines (2NNN, displayed as 2X) + + drawop im2 imX + v0 := 0 + test-2X-0E # Attempt to run a subroutine +: test-2X-0E-hard-return + i := image-ok + if v0 == 0 then i := image-no # Subroutine was never called + sprite x2 y 4 + +################# +# Test returning from subroutines (00EE, displayed as 0E) + + y += 5 + drawop im0 imE + i := image-ok + if v0 == 2 then i := image-no # Return didn't work + if v0 != 0 then sprite x2 y 4 # If subroutine wasn't called, return wasn't tested + +################# +# Test 8xy0 + + y += 5 + drawop im8 im0 + i := image-no + v5 := 42 + v7 := 0 + v7 := v5 + if v7 == 42 then i := image-ok + sprite x2 y 4 + +################# +# Test 8xy1 + + y += 5 + drawop im8 im1 + i := image-no + v6 := 11 + v7 := 42 + v7 |= v6 + if v7 == 43 then i := image-ok + sprite x2 y 4 + +################# +# Test 8xy2 + + y += 5 + drawop im8 im2 + i := image-no + v6 := 120 + v7 := 31 + v7 &= v6 + if v7 == 24 then i := image-ok + sprite x2 y 4 + +################# +# Test 8xy3 + + y += 5 + drawop im8 im3 + i := image-no + v6 := 120 + v7 := 31 + v7 ^= v6 + if v7 == 103 then i := image-ok + sprite x2 y 4 + + # Show output in the third column + x0 := 34 + x1 := 38 + x2 := 43 + y := 1 + +################# +# Test 8xy4 + + drawop im8 im4 + i := image-no + v6 := 140 + v7 := 140 + v7 += v6 + if v7 == 24 then i := image-ok + sprite x2 y 4 + +################# +# Test 8xy5 + + y += 5 + drawop im8 im5 + i := image-no + v6 := 140 + v7 := 120 + v7 -= v6 + if v7 == 236 then i := image-ok + sprite x2 y 4 + +################# +# Test 8xy7 + + y += 5 + drawop im8 im7 + i := image-no + v6 := 120 + v7 := 140 + v7 =- v6 + if v7 == 236 then i := image-ok + sprite x2 y 4 + +################# +# Test 8xy6 + + y += 5 + drawop im8 im6 + i := image-no + v6 := 15 + v6 >>= v6 + if v6 == 7 then i := image-ok + sprite x2 y 4 + +################# +# Test 8xyE + + y += 5 + drawop im8 imE + i := image-no + v6 := 224 + v6 <<= v6 + if v6 == 192 then i := image-ok + sprite x2 y 4 + +################# +# Test Fx65 + + y += 5 + drawop imF im6 + i := scratchpad + load v1 + i := image-ok + if v0 != 0xAA then i := image-no + if v1 != 0x55 then i := image-no + sprite x2 y 4 + +################# +# Test Fx55 + + x0 := 50 + x1 := 54 + x2 := 59 + y := 1 + drawop imF im5 + i := scratchpad + v0 := 0 + v1 := 48 + save v1 + i := scratchpad + load v0 + v1 := v0 + i := scratchpad-plus-1 + load v0 + i := image-ok + if v0 != 48 then i := image-no + if v1 != 0 then i := image-no + sprite x2 y 4 + +################# +# Test Fx33 + + y += 5 + drawop imF im3 + + # N >= 100 + i := scratchpad + v6 := 137 + bcd v6 + load v2 + i := image-no + if v0 != 1 then jump fx33-fail + if v1 != 3 then jump fx33-fail + if v2 != 7 then jump fx33-fail + + # N < 100 + i := scratchpad + v6 := 65 + bcd v6 + load v2 + i := image-no + if v0 != 0 then jump fx33-fail + if v1 != 6 then jump fx33-fail + if v2 != 5 then jump fx33-fail + + # N < 10 + i := scratchpad + v6 := 4 + bcd v6 + load v2 + i := image-no + if v0 != 0 then jump fx33-fail + if v1 != 0 then jump fx33-fail + if v2 != 4 then jump fx33-fail + + i := image-ok +: fx33-fail + sprite x2 y 4 + +################# +# Test Fx1E + + y += 5 + drawop imF imE + i := image-no + v6 := 4 + i += v6 + sprite x2 y 4 + +################# +# Test to see if registers are 8 bit, as thoroughly as possible. + + y += 5 + drawop imV imX + i := image-ok + + # Addition opcodes should not allow us to overflow + v6 := 255 + v6 += 10 + if v6 != 9 then i := image-no + v6 >>= v6 + if v6 != 4 then i := image-no + v6 := 255 + v0 := 10 + v6 += v0 + if v6 != 9 then i := image-no + v6 >>= v6 + if v6 != 4 then i := image-no + + # Shift opcodes should not retain bits + v6 := 255 + v6 <<= v6 + v6 >>= v6 + if v6 != 127 then i := image-no + v6 >>= v6 + v6 <<= v6 + if v6 != 126 then i := image-no + + # Subtraction should wrap back to positive + v6 := 5 + v6 -= 10 + if v6 != 251 then i := image-no + v6 := 5 + v6 -= v0 + if v6 != 251 then i := image-no + v6 := 5 + v0 =- v6 + if v0 != 251 then i := image-no + + sprite x2 y 4 + +################# +# Test CxNN (Fairly long test, and also prone to failing) + + # See if a random number is returned +y += 5 + drawop imC imX + + i := image-no + + v6 := 0 + v7 := 0 + + loop + v7 += 1 + v6 := random 255 + + if v7 == 0 then jump cxnn-fail + if v6 > 255 then cxnn-fail + if v6 == 0 then + again + + # Masking tests + # Mask of 0x00 + v6 := 0 + v7 := 0 + + loop + v7 += 1 + v6 := random 0 + + if v6 != 0 then jump cxnn-fail + if v7 != 0 then + again + + # Mask of 0x0F + v6 := 0 + v7 := 0 + + loop + v7 += 1 + v6 := random 0xF + + if v6 > 0xF then jump cxnn-fail + if v7 != 0 then + again + + # Mask of 0xF0 + v6 := 0 + v7 := 0 + v4 := 0xF0 + + loop + v7 += 1 + v6 := random 0xF0 + v5 := v6 + v5 &= v4 + + if v6 > 0xF0 then jump cxnn-fail + if v6 != v5 then jump cxnn-fail + if v7 != 0 then + again + + i := image-ok +: cxnn-fail + sprite x2 y 4 + +################# +# Test is done! + + loop again + +:segment data + +: scratchpad + 0xAA +: scratchpad-plus-1 + 0x55 0 + +# Positive and negative images +: image-no + 0b00000000 + 0b10100000 + 0b01000000 + 0b10100000 +: image-ok + 0b00000000 + 0b10100000 + 0b11000000 + 0b10000000 + +# Individual characters, some taken from Corax89' test. +: im0 + 0b11100000 + 0b10100000 + 0b10100000 + 0b11100000 +: im1 + 0b11000000 + 0b01000000 + 0b01000000 + 0b11100000 +: im2 + 0b11100000 + 0b00100000 + 0b11000000 + 0b11100000 +: im3 + 0b11100000 + 0b01100000 + 0b00100000 + 0b11100000 +: im4 + 0b10100000 + 0b11100000 + 0b00100000 + 0b00100000 +: im5 + 0b11100000 + 0b11000000 + 0b00100000 + 0b11000000 +: im6 + 0b01100000 + 0b10000000 + 0b11100000 + 0b11100000 +: im7 + 0b11100000 + 0b00100000 + 0b01000000 + 0b01000000 +: im8 + 0b11100000 + 0b11100000 + 0b10100000 + 0b11100000 +: im9 + 0b11100000 + 0b11100000 + 0b00100000 + 0b11000000 +: imA + 0b01000000 + 0b10100000 + 0b11100000 + 0b10100000 +: imB + 0b11000000 + 0b11100000 + 0b10100000 + 0b11100000 +: imC + 0b11100000 + 0b10000000 + 0b10000000 + 0b11100000 +: imD + 0b11000000 + 0b10100000 + 0b10100000 + 0b11000000 +: imE + 0b11100000 + 0b11000000 + 0b10000000 + 0b11100000 +: imF + 0b11100000 + 0b10000000 + 0b11000000 + 0b10000000 +: imV + 0b00000000 + 0b10100000 + 0b10100000 + 0b01000000 +: imX + 0b10100000 + 0b01000000 + 0b10100000 + 0b10100000 + +: version + :include "../../pictures/version.png"