Jump to content

looking for faster method to check for blank spaces

Recommended Posts

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?

Share this post

Link to post
Share on other sites

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
  sta 203
  pla           ;set # of bytes
  sta 206
  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
  cmp (203),y   ;current pos = character
  bne nomatch   ;branch if no
  lda 207
  sta (203),y   ;replace char
  inc 212       ;increase counter
  bne nomatch   ;branch if no rollover
  inc 213       ;increase counter*256
  inc 203       ;move to next byte to check
  bne bumpindex ;branch if no rollover
  inc 204       ;bump MSB of next byte to check
  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 :P

Edited by Nukey Shay
  • Like 2

Share this post

Link to post
Share on other sites

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.

Share this post

Link to post
Share on other sites

??? 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 :)

Share this post

Link to post
Share on other sites

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?

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
240 ?#6;"SPCA x's:";SPCA
250 ?#6;"SPCB x's:";SPCB
260 FOR XY=1 TO 160
270 ?#6;"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
350 ?#6;"SPCA x's to z's:";SPCA
360 ?#6;"SPCB x's:";SPCB
390 GOTO 390

Edited by pmgraphics

Share this post

Link to post
Share on other sites

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 by Nukey Shay
  • Like 2

Share this post

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...