* ******************************** * * * -< STRINGS DEMO >- * * * * VERSION 00.03.00 * * * * 20-JAN-2019 * * * ******************************** * * * NATHAN D. RIGGS * * NATHAN.RIGGS@OUTLOOK.COM * * * ******************************** * ** ASSEMBLER DIRECTIVES * CYC AVE TR ON EXP ONLY DSK STRINGS.DEMO OBJ $BFE0 ORG $6000 * *``````````````````````````````* * TOP INCLUDES (PUTS, MACROS) * *,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,* * PUT REQUIRED.VARS USE REQUIRED.MAC.MIN PUT REQUIRED.HOOKS.MIN USE STRINGS.MAC.MIN PUT STRINGS.HOOKS * * *``````````````````````````````* * PROGRAM MAIN BODY * *,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,* * _PRNT " ",8D8D8D8D _PRNT "STRINGS LIBRARY DEMO",8D _PRNT "--------------------",8D _PRNT " ",8D _PRNT "THE SCMP MACRO COMPARES TWO ",8D _PRNT "STRINGS AND SETS THE FLAGS",8D _PRNT "ACCORDINGLY. IF THE TWO ARE EQUAL,",8D _PRNT "THEN .Z IS SET TO ZERO; IF NOT, 1.",8D8D _PRNT "IF STRING1 LENGTH > STRING2 LENGTH,",8D _PRNT ".C(ARRY) = 0; ELSE, .C = 1.",8D8D _PRNT "SO, WE CAN COMPARE THE LITERAL 'A'",8D _PRNT "TO THE VALUE STORED IN ASTR, WHICH",8D _PRNT "HOLDS THE SAME STRING, THEN USE BNE TO",8D _PRNT "TEST IF THEY ARE EQUAL.",8D8D SCMP "A";ASTR BNE PE ; IS ZERO FLAG 1? BRANCH IF SO JMP CONT PE _PRNT "THE LITERAL A AND THE A STRING ARE",8D _PRNT "EQUAL.",8D8D8D CONT _WAIT _PRNT "NOTE THAT ONLY A SINGLE PARAMETER",8D _PRNT "MAY BE A LITERAL STRING IN SCMP;",8D _PRNT "THIS SAME RULE APPLIES TO ALL MACROS",8D _PRNT "THAT ACCEPT STRINGS AS PARAMETERS.",8D8D _PRNT "YOU CAN ALSO USE SCMP TO COMPARE",8D _PRNT "THE LENGTHS OF TWO DIFFERENT STRINGS.",8D8D _PRNT "THE CARRY FLAG IS SET TO 0 IF THE",8D _PRNT "FIRST STRING HAS A LENGTH > THAN THE ",8D _PRNT "SECOND STRING'S LENGTH. THIS CAN THEN",8D _PRNT "BE TESTED WITH BCS.",8D8D _PRNT "SO IF WE COMPARE THE LITERAL 'AA' ",8D _PRNT "TO THE SAME ASTR, WE WILL FIND THAT",8D _PRNT "THE LITERAL HAS A GREATER LENGTH.",8D8D * SCMP "AA";ASTR BCS LE JMP CONT2 LE _PRNT "THE LITERAL 'AA' IS GREATER THAN ",8D _PRNT "ASTR, WHICH HOLDS 'A'.",8D8D8D CONT2 _WAIT * _PRNT " ",8D8D8D8D _PRNT "THE SCAT MACRO CONCATENATES",8D _PRNT "A SECOND GIVEN STRING TO A ",8D _PRNT "FIRST GIVEN STRING. EITHER PARAMETER",8D _PRNT "MAY BE A LITERAL STRING, BUT NEVER BOTH.",8D8D _PRNT "SCAT 'WTF IS ';ASTR;#50 RETURNS: ",8D8D SCAT "WTF IS ";ASTR;#50 SPRN RETURN _PRNT " ",8D8D8D _WAIT * _PRNT "TO SHOW THE RESULT OF SCAT,",8D _PRNT "WE USED THE SPRN MACRO, WHICH",8D _PRNT "SIMPLY PRINTS A STRING. THIS",8D _PRNT "WORKS DIFFERENTLY THAN THE PRINT",8D _PRNT "ROUTINES IN STDIO OR THE _PRNT",8D _PRNT "ROUTINE, AS IT CAN ONLY HANDLE",8D _PRNT "A STRING ADDRESS.",8D8D _PRNT "SPRN BSTR RETURNS: " SPRN BSTR _PRNT " ",8D8D8D _WAIT _PRNT " ",8D8D8D _PRNT "TOSTR CONVERTS A 16-BIT INTEGER INTO",8D _PRNT "ITS STRING EQUIVALENT. THIS CAN",8D _PRNT "EITHER BE A LITERAL OR AN ADDRESS." _PRNT " ",8D8D _PRNT "TOSTR #5000 RETURNS: " TOSTR #5000 SPRN RETURN _PRNT " ",8D8D _PRNT "TOSTR $300 RETURNS " LDA #$FF STA $300 STA $301 TOSTR $300 SPRN RETURN _PRNT " ",8D8D _PRNT "NOTE THAT $FFFF RETURNS -1 BECAUSE",8D _PRNT "THE TOSTR ROUTINE ASSUMES A ",8D _PRNT "SIGNED VALUE. " _PRNT " ",8D8D8D _WAIT * _PRNT " ",8D8D8D _PRNT "AND THE TONUM MACRO DOES THE",8D _PRNT "OPPOSITE: IT RETURNS A 16-BIT ",8D _PRNT "INTEGER VALUE CONERTED FROM ITS",8D _PRNT "STRING EQUIVALENT. THUS:",8D8D _PRNT "TONUM '255' RETURNS:",8D TONUM "255" _DUMP RETURN;RETLEN _PRNT " ",8D8D8D _WAIT * _PRNT " ",8D8D8D8D _PRNT "SUBSTRING ROUTINES/MACROS",8D _PRNT "-------------------------",8D8D _PRNT "SPOS FINDS THE POSITION OF",8D _PRNT "A SUBSTRING WITHIN ANOTHER",8D _PRNT "STRING.",8D8D _PRNT "SPOS 'THIS IS A STRING';ASTR RETURNS: " SPOS "THIS IS A STRING";ASTR STA $300 LDA #0 STA $301 ; CLEAR HI BYTE TOSTR $300 SPRN RETURN _PRNT " ",8D8D8D * _PRNT " ",8D8D8D _PRNT "THE SCPY MACRO COPIES A ",8D _PRNT "SUBSTRING FROM ANOTHER STRING",8D _PRNT "AT THE SPECIFIED INDEX, HOLDING",8D _PRNT "THE SUBSTRING IN [RETURN].",8D8D _PRNT "SCPY 'ABCDEFGHIJK';#2;#4;#50 RETURNS: " SCPY "ABCDEFGHIJK";#2;#4;#$FF SPRN RETURN _PRNT " ",8D8D8D _WAIT * _PRNT " ",8D8D8D8D8D _PRNT "THE SDEL MACRO DELETES A SUBSTRING",8D _PRNT "FROM THE GIVEN SOURCE STRING. NOTE ",8D _PRNT "THAT THE SOURCE STRING MUST NOT",8D _PRNT "BE A LITERAL BECAUSE THIS ROUTINE",8D _PRNT "ALTERS THE STRING PASSED TO IT.",8D8D _PRNT "IF LSTR HOLDS 'THIS IS A STRING.'",8D _PRNT "THEN SDEL LSTR;#1;#7 RETURNS: ",8D8D SDEL LSTR;#1;#7 SPRN LSTR _PRNT " ",8D8D8D8D _WAIT * _PRNT "THE SINS MACRO DOES THE ",8D _PRNT "OPPOSITE OF SDEL: IT INSERTS",8D _PRNT "A SUBSTRING INTO A PARENT STRING",8D _PRNT "AT THE GIVEN INDEX. NOTE THAT",8D _PRNT "WHILE THE PARENT STRING CANNOT BE ",8D _PRNT "A LITERAL, THE SUBSTRING ITSELF CAN BE.",8D8D _PRNT "THUS SINS LSTR;#1;#50;'THIS IS NOT'",8D _PRNT "RETURNS: ",8D SINS LSTR;#1;#50;"THIS IS NOT" SPRN LSTR _PRNT " ",8D8D8D8D _WAIT * JMP REENTRY * ASTR STR "A" BSTR STR "B" LSTR STR "THIS IS A STRING." * *``````````````````````````````* * BOTTOM INCLUDES * *,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,* * ** BOTTOM INCLUDES * PUT REQUIRED.LIB.MIN * ** INDIVIDUAL SUBROUTINE INCLUDES * ** STRING SUBROUTINES * PUT NUM2STR.SUB.MIN PUT PRNSTR.SUB.MIN PUT STRCAT.SUB.MIN PUT STRCOMP.SUB.MIN PUT STR2NUM.SUB.MIN * ** SUBSTRING SUBROUTINES * PUT SUBCOPY.SUB.MIN PUT SUBDEL.SUB.MIN PUT SUBINS.SUB.MIN PUT SUBPOS.SUB.MIN *