From de0bc5120f7ae63d96b49cad5d0be0995b46977c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carl-Henrik=20Sk=C3=A5rstedt?= Date: Thu, 19 Sep 2019 21:07:04 -0700 Subject: [PATCH] Fixed 16 bit immediate mode, tweaked unit tests, added |/! as WDC syntax for absolute addressing --- .gitignore | 3 +- sln/dump_x65/dump_x65.vcxproj | 2 +- sln/x65.vcxproj | 2 +- test/AddrMode_65816.s | 29 +++++++++++++ test/local_label.s | 77 +++++++++++++++++++++++++++++++++++ test/unittest.bat | 73 ++++++++++++++++++--------------- x65.cpp | 25 +++++++++--- 7 files changed, 170 insertions(+), 41 deletions(-) create mode 100644 test/local_label.s diff --git a/.gitignore b/.gitignore index f1bcc4c..654c9dd 100644 --- a/.gitignore +++ b/.gitignore @@ -17,4 +17,5 @@ *.db *.obj.enc *.user -*.db* \ No newline at end of file +*.db* +test/results/* \ No newline at end of file diff --git a/sln/dump_x65/dump_x65.vcxproj b/sln/dump_x65/dump_x65.vcxproj index 1da3962..af24e18 100644 --- a/sln/dump_x65/dump_x65.vcxproj +++ b/sln/dump_x65/dump_x65.vcxproj @@ -23,7 +23,7 @@ {57EFF4A4-7BF2-43F0-AD62-A79092DA67D1} Win32Proj dump_x65 - 10.0.15063.0 + 10.0.16299.0 diff --git a/sln/x65.vcxproj b/sln/x65.vcxproj index 7cced22..6825dba 100644 --- a/sln/x65.vcxproj +++ b/sln/x65.vcxproj @@ -23,7 +23,7 @@ {2823019A-A423-4A40-BB9C-5CE242019BD0} Win32Proj x65 - 10.0.15063.0 + 10.0.16299.0 diff --git a/test/AddrMode_65816.s b/test/AddrMode_65816.s index d326d5b..cd97db3 100644 --- a/test/AddrMode_65816.s +++ b/test/AddrMode_65816.s @@ -1,5 +1,15 @@ cpu 65816 Test65816_ForceAddrMode: +i8 + ldx #0 +i16 + ldx #0 +a8 + lda #0 +a16 + lda #0 + lda.b #0 + { jmp >$123456 lda >$123456,x @@ -33,6 +43,25 @@ Test65816_ForceAddrMode: endif } + { + lda <$101030 // $101030 // .l force long + if !((*-!) == 4) + err Expected zero page instruction + endif + } { jmp [$1010] diff --git a/test/local_label.s b/test/local_label.s new file mode 100644 index 0000000..1816a25 --- /dev/null +++ b/test/local_label.s @@ -0,0 +1,77 @@ +CheckLocalPeriod: + lda #0 +.loop + dex + sta $1000,x + bne .loop + +CheckLocalColon: + lda #0 +:loop + dex + sta $1000,x + bne :loop + +CheckLocalSnabelA: + lda #0 +@loop + dex + sta $1000,x + bne @loop + +CheckLocalExclamation: + lda #0 +!loop + dex + sta $1000,x + bne !loop + +CheckLocalDallasSign: + lda #0 +loop$ + dex + dex + sta $1000,x + bne loop$ + + + +CheckLocalPeriod2: + lda #0 +.loop + dex + sta $1000,x + bne .loop + +CheckLocalColon2: + lda #0 +:loop + dex + sta $1000,x + bne :loop + +CheckLocalSnabelA2: + lda #0 +@loop + dex + sta $1000,x + bne @loop + +CheckLocalExclamation2: + lda #0 +!loop + dex + sta $1000,x + bne !loop + +CheckLocalDallasSign2: + lda #0 +loop$ + dex + sta $1000,x + bne loop$ + + + + + diff --git a/test/unittest.bat b/test/unittest.bat index 281248d..7ef9d4d 100644 --- a/test/unittest.bat +++ b/test/unittest.bat @@ -1,74 +1,83 @@ @echo off -echo Unit tests for x65 assembler >unittest.txt -echo >>unittest.txt +if NOT EXIST results mkdir results -echo 65816 OpCodes Test >>unittest.txt -..\bin\x64\x65 Test65816_OpCodes.s -cpu=65816 -lst >> unittest.txt -if %errorlevel% EQU 0 goto opcodes_65816_pass -:opcodes_65816_fail -echo 65816 OpCodes failed -goto exit -:opcodes_65816_pass +echo Unit tests for x65 assembler >results\unittest.txt +echo >>results\unittest.txt - -echo 65816 Force Addressing Mode Test >>unittest.txt -..\bin\x64\x65 AddrMode_65816.s -cpu=65816 -lst >> unittest.txt +echo 65816 Force Addressing Mode Test >>results\unittest.txt +..\bin\x64\x65 AddrMode_65816.s -cpu=65816 -lst >>results\unittest.txt if %errorlevel% EQU 0 goto addrmode_pass :addrmode_fail echo Force Addressing Mode failed goto exit :addrmode_pass -echo Merlin Macro Test >>unittest.txt -echo ----------------- >>unittest.txt -..\bin\x64\x65 merlin_macro.s merlin_macro.bin -bin -org=$1000 -merlin -lst >>unittest.txt +echo 65816 Local Label Symbol Test >>results\unittest.txt +..\bin\x64\x65 local_label.s -cpu=65816 -lst >>results\unittest.txt +if %errorlevel% EQU 0 goto locallabel_pass +:locallabel_feil +echo Local Label Symbol Test failed +goto exit +:locallabel_pass + +echo 65816 OpCodes Test >>results\unittest.txt +..\bin\x64\x65 Test65816_OpCodes.s -cpu=65816 -lst >>results\unittest.txt +if %errorlevel% EQU 0 goto opcodes_65816_pass +:opcodes_65816_fail +echo 65816 OpCodes failed +goto exit +:opcodes_65816_pass + +echo Merlin Macro Test >>results\unittest.txt +echo ----------------- >>results\unittest.txt +..\bin\x64\x65 merlin_macro.s results\merlin_macro.bin -bin -org=$1000 -merlin -lst >>results\unittest.txt if %errorlevel% GTR 0 goto mermac_fail -fc /B compare\merlin_macro_cmp.bin merlin_macro.bin >>unittest.txt +fc /B compare\merlin_macro_cmp.bin results\merlin_macro.bin >>results\unittest.txt if %errorlevel% EQU 0 goto mermac_pass :mermac_fail echo Merlin macro test failed goto exit :mermac_pass -echo 8BitDiff Test >>unittest.txt -echo ------------- >>unittest.txt -..\bin\x64\x65 8BitDiff_6502.s 8BitDiff_6502.prg -kickasm -sym 8BitDiff_6502.sym -lst >>unittest.txt +echo 8BitDiff Test >>results\unittest.txt +echo ------------- >>results\unittest.txt +..\bin\x64\x65 8BitDiff_6502.s results\8BitDiff_6502.prg -kickasm -sym results\8BitDiff_6502.sym -lst >>results\unittest.txt if %errorlevel% GTR 0 goto 8BitDiff_6502_fail -fc /B compare\8BitDiff_6502_cmp.prg 8BitDiff_6502.prg >>unittest.txt +fc /B compare\8BitDiff_6502_cmp.prg results\8BitDiff_6502.prg >>results\unittest.txt if %errorlevel% EQU 0 goto 8BitDiff_6502_pass :8BitDiff_6502_fail echo 8BitDiff_6502 test failed goto exit :8BitDiff_6502_pass -echo Alias Test >>unittest.txt -echo ---------- >>unittest.txt -..\bin\x64\x65 alias_test.s alias_test.prg -sym alias_test.sym -lst >>unittest.txt +echo Alias Test >>results\unittest.txt +echo ---------- >>results\unittest.txt +..\bin\x64\x65 alias_test.s results\alias_test.prg -sym results\alias_test.sym -lst >>results\unittest.txt if %errorlevel% GTR 0 goto alias_test_fail -fc /B compare\alias_test_cmp.prg alias_test.prg >>unittest.txt +fc /B compare\alias_test_cmp.prg results\alias_test.prg >>results\unittest.txt if %errorlevel% EQU 0 goto alias_test_pass :alias_test_fail echo Alias test failed goto exit :alias_test_pass -echo x65macro.i Test >>unittest.txt -echo --------------- >>unittest.txt -..\bin\x64\x65 x65macro_test.s x65macro_test.prg -org=$1000 -sym x65macro_test.sym -lst >>unittest.txt +echo x65macro.i Test >>results\unittest.txt +echo --------------- >>results\unittest.txt +..\bin\x64\x65 x65macro_test.s results\x65macro_test.prg -org=$1000 -sym results\x65macro_test.sym -lst >>results\unittest.txt if %errorlevel% GTR 0 goto x65macro_test_fail -fc /B compare\x65macro_test_cmp.prg x65macro_test.prg >>unittest.txt +fc /B compare\x65macro_test_cmp.prg results\x65macro_test.prg >>results\unittest.txt if %errorlevel% EQU 0 goto x65macro_test_pass :x65macro_test_fail echo x65macro.i test failed goto exit :x65macro_test_pass -echo Merlin LUP Test >>unittest.txt -echo --------------- >>unittest.txt -..\bin\x64\x65 merlin_lup.s merlin_lup.bin -bin -org=$1000 -merlin -lst >>unittest.txt +echo Merlin LUP Test >>results\unittest.txt +echo --------------- >>results\unittest.txt +..\bin\x64\x65 merlin_lup.s results\merlin_lup.bin -bin -org=$1000 -merlin -lst >>results\unittest.txt if %errorlevel% GTR 0 goto merlup_fail -fc /B compare\merlin_lup_cmp.bin merlin_lup.bin >>unittest.txt +fc /B compare\merlin_lup_cmp.bin results\merlin_lup.bin >>results\unittest.txt if %errorlevel% EQU 0 goto merlup_pass :merlup_fail echo Merlin LUP test failed diff --git a/x65.cpp b/x65.cpp index 1822fbd..3764ac6 100644 --- a/x65.cpp +++ b/x65.cpp @@ -5372,6 +5372,23 @@ StatusCode Asm::GetAddressMode(strref line, bool flipXY, uint32_t &validModes, A } else { addrMode = AMB_ZP; validModes &= AMM_ZP; } + } else if (c == '<') { + validModes &= AMM_ZP | AMM_ZP_X | AMM_ZP_REL_X | AMM_ZP_Y_REL | + AMM_ZP_REL | AMM_ZP_ABS | AMM_ZP_REL_L | AMM_ZP_REL_Y_L | AMM_FLIPXY; + } else if( c == '|' || c == '!' ) { + ++line; line.trim_whitespace(); + strref suffix = line.after( ',' ); suffix.skip_whitespace(); + expression = line.before_or_full( ',' ); expression.trim_whitespace(); + addrMode = AMB_NON; + if( suffix ) { + if( suffix.get_first() == 'x' || suffix.get_first() == 'X' ) { + addrMode = AMB_ABS_X; validModes &= AMM_ABS_X; + } else if( suffix.get_first() == 'y' || suffix.get_first() == 'Y' ) { + addrMode = AMB_ABS_Y; validModes &= AMM_ABS_Y; + } + } else { + addrMode = AMB_ABS; validModes &= AMM_ABS; + } } else if( c == '>' ) { ++line; line.trim_whitespace(); strref suffix = line.after( ',' ); suffix.skip_whitespace(); @@ -5385,20 +5402,16 @@ StatusCode Asm::GetAddressMode(strref line, bool flipXY, uint32_t &validModes, A else { addrMode = AMB_ABS_L; validModes &= AMM_ABS_L; } - } else if (c == '#') { ++line; addrMode = AMB_IMM; - validModes &= AMM_IMM; + validModes &= AMM_IMM | AMM_IMM_DBL_A | AMM_IMM_DBL_XY; expression = line; - } else if (c == '<') { - validModes &= AMM_ZP | AMM_ZP_X | AMM_ZP_REL_X | AMM_ZP_Y_REL | - AMM_ZP_REL | AMM_ZP_ABS | AMM_ZP_REL_L | AMM_ZP_REL_Y_L | AMM_FLIPXY; } else if (line) { if (line[0]=='.' && strref::is_ws(line[2])) { switch (strref::tolower(line[1])) { case 'z': force_zp = true; line += 3; need_more = true; len = 1; break; - case 'b': line += 3; need_more = true; len = 1; break; + case 'b': line += 3; need_more = true; len = 1; validModes &= ~(AMM_IMM_DBL_A | AMM_IMM_DBL_XY); break; case 'w': line += 3; need_more = true; len = 2; break; case 'l': force_24 = true; line += 3; need_more = true; len = 3; break; case 'a': force_abs = true; line += 3; need_more = true; break;