From: bpat@cs.mcgill.ca (Patrick BETREMIEUX)
Newsgroups: comp.sys.atari.st.tech
Subject: Re: Comparing Strings in 68000 Assembly
Date: 11 Oct 92 02:14:04 GMT
Organization: McGill University, Montreal, Canada

In article <mcarrico.1tqa@terapin.com> mcarrico@terapin.com (Michael Carrico) writes:
>I am working on a project that started out as a "Chat Mode" program for a
>friend of mine, for his BBS, and after he found a program, I decided to make it
>into something different. I have a small VT52 Terminal Emulator program written

um, so that you know, the ST has a built-in vt52 emulator. I mean, everything
you send to the screen is processed as if it were a vt52. (at least by GEMDOS
when you use 2 as output device. Using 5 will turn vt52 off)

>in Assembly langauge. I talked with my friend and we are discussing taking that
>program and re-arranging it so the single key routine reads a string instead.

There is a GEMDOS function for that. It's called READLINE

pea buffer
move.w #$0A,-(sp)
trap #1
addq.l #6,sp

and the string will be at the address buffer afterward. It does interpret
^C (It causes the program that called READLINE to terminate), as well as
keys like backspace and tab. Of course, this terminate on ^C stuff might not
be good, so doing your own is probably the way to go.

>The over-all goal is to make the chat mode one procedure in an online adventure
>game..I.E. The Local sysop can interrupt the player with say the F1 key.. and
>chat with him..then hit it again and the player resumes playing..anyway I'm
>finished with the Chat mode part, but now we need a routine that can read a
>string and compare it with some common commands, such as "North" or "Look" or
>"Open Door" These type..
> 
>Anyway, I found some routines to read a string using GEM, but it does'nt trap
>control C, so I decided to attempt to write my own variable length readstring
>routine. It takes one character at a time and adds it to a buffer, then when
>the user hits return, it ends adding to the buffer, and compares the buffer to
>the string I want.
> 
>Well I pretty much have the readstring part, but as soon as I compare the
>string..(exit from inputting) I get 2 bombs and it exits.. Addressing Error.
> 
>Well.. Here's the string compare assuming A1 holds the starting address of
>string 1 and A2 holds the starting address of string 2..
> 
>This is my compare routine..can someone please give me a hint as to want I am
>doing wrong? 
> 
>=========================================================================
> 
> ST D6      ;Set $FF to D6 we are using this as a True/False Register
> CLR.W D7   ;Set $00 to D7 we need a clean slate for a character counter
>LOOP CMPM.B (A1)+,(A2)+  Compare the bytes of each and increment pointer
>     BNE MISMAT          If they are different, then string does'nt match
> TST.B   -1(A1)          Did we reach a Null Byte ? (End of string)
> BEQ ENDOK               If we did then both are null, so end..
> ADDQ.W #1,D7            We tested one byte so far, so add 1 to the count!
> BRA LOOP                Branch back up and loop
>MISMAT CLR.B D6          Strings don't match so make D6 False ($00)
>ENDOK  ...               We continue here
> 

I must admit I'm puzzled as well. This routine by itself should work ok.
It's probably that you call it after calling GEM. There is one VERY important
thing to remember in assembly if you use the OS:

GEM (VDI or AES) will destroy d0-d3 and a0-a3.
GEMDOS, BIOS and XBIOS will destroy d0-d1 and a0-a1

So you should make sure that the values in those registers when you call your
string compare loop are yours, and not those GEM put in it, or else ...

Another thing might be that you did not pop the stack enough after some
GEMDOS, BIOS or XBIOS call, and a rts is reached inside your code.

If you'd like, you could send me the code (Or just the part that does all
this string input and compare if you prefer), and I'll take a look at it.
One thing for sure, the compare routine ain't at fault here.

>Ok soo using that I should be able to compare byte by byte right?
> 
>What am I doing wrong?
> 
>ST MASTER

					Patrick.