pmgraphics Posted May 16, 2019 Author Share Posted May 16, 2019 Nukey Shay: things are working great with the USR code to detect the number of characters on screen. Can I use this same code that detects the designated character to replace that character with a different character as it counts them, or is does that require entire new USR routine? Quote Link to comment Share on other sites More sharing options...
Nukey Shay Posted May 16, 2019 Share Posted May 16, 2019 (edited) Code is a little changed. Dealing with 2 characters means they need to be stored in temp locations. Fortunately, zp Ram is unused by Basic up to 209... pla ;pull # of arguments pla ;set start address sta 204 pla sta 203 pla ;set # of bytes sta 206 pla sta 205 pla ;set replacement character pla ; (LSB needed only) sta 207 pla ;set character to look for pla ; (LSB needed only) ldy #0 ;clear counter sty 212 sty 213 ldx #255 ;used for rollover check loop cmp (203),y ;current pos = character bne nomatch ;branch if no pha lda 207 sta (203),y ;replace char pla inc 212 ;increase counter bne nomatch ;branch if no rollover inc 213 ;increase counter*256 nomatch: inc 203 ;move to next byte to check bne bumpindex ;branch if no rollover inc 204 ;bump MSB of next byte to check bumpindex dec 205 ;decrease the number of bytes left cpx 205 bne loop dec 206 cpx 206 bne loop rts ;no bytes left, return ;62 bytes total DATA 104,104,133,204,104,133,203,104,133,206 DATA 104,133,205,104,104,133,207,104,104,160 DATA 0,132,212,132,213,162,255,209,203,208 DATA 12,72,165,207,145,203,104,230,212,208 DATA 2,230,213,230,203,208,2,230,204,198 DATA 205,228,205,208,228,198,206,228,206,208 DATA 222,96 EDIT - made it a little quicker by swapping the last 2 arguments usage: SPC=USR(addr,screen,bytes,replacement,char) addr is the address where you saved the machine language program (A, 1536, or wherever) screen is the address to start checking, i.e. PEEK(88)+256*PEEK(89) bytes is the number of bytes to check replacement is the POKE code of the character to change it to (if found) (use the same code for replacement as char if you don't want a change) char is the POKE code of the character to be counted BCC probably works as it should, but INC doesn't change the carry flag... GAH! Rookie mistake. Guess I shouldn't post when drunk Edited May 16, 2019 by Nukey Shay 2 Quote Link to comment Share on other sites More sharing options...
carlsson Posted May 16, 2019 Share Posted May 16, 2019 I'm not sure if it is a sign of a good or a bad party if you end up writing Atari machine code routines during/at the end of it. Quote Link to comment Share on other sites More sharing options...
_The Doctor__ Posted May 16, 2019 Share Posted May 16, 2019 ??? coding on and off at all points of a party makes it a GREAT party, if that's your' groove... if you are just there to imbibe.. well then it's suggested you might stick to just playing and or watching and enjoying the festivities Quote Link to comment Share on other sites More sharing options...
pmgraphics Posted May 16, 2019 Author Share Posted May 16, 2019 (edited) Testing the replace code SPC=USR(A,SCREEN,458,58,56). Does replace X's with Z's. The SPC value is always 459. Should SPC value be the number of char's found to replace, or should I continue to use the find USR routine to get a count? 10 GRAPHICS 17 20 SCREEN=PEEK(88)+256*PEEK(89) 200 A=ADR(" the replace string ") 210 B=ADR(" the find any string ") 220 SPCA=USR(A,SCREEN,458,56,56):REM X,X SPCA=459 230 SPCB=USR(B,SCREEN,458,56):REM X SPCB=0 240 ?#6;"SPCA x's:";SPCA 250 ?#6;"SPCB x's:";SPCB 260 FOR XY=1 TO 160 270 ?#6;"XY"; 280 NEXT XY 290 SPCA=USR(A,SCREEN,458,56,56):REM X,X SPCA=459 300 SPCB=USR(B,SCREEN,458,56):REM X SPCB=160 310 ?#6;"SPCA x's:";SPCA 320 ?#6;"SPCB x's:";SPCB 330 SPCA=USR(A,SCREEN,458,58,56):REM Z REPLACE X SPCA=459 340 SPCB=USR(B,SCREEN,458,56):REM X SPCB=0 350 ?#6;"SPCA x's to z's:";SPCA 360 ?#6;"SPCB x's:";SPCB 390 GOTO 390 Edited May 16, 2019 by pmgraphics Quote Link to comment Share on other sites More sharing options...
Nukey Shay Posted May 16, 2019 Share Posted May 16, 2019 (edited) I forgot to change the middle branch length to skip adding when there's no match...change the 6 at the start of the 4th DATA line to be 12. Edited May 16, 2019 by Nukey Shay 2 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.