Jump to content
IGNORED

Assembly code samples


GDMike

Recommended Posts

I haven't found a repository for

"assembly language algorithms"

As I, myself, would love to be able to go somewhere to find a piece of code that solves a problem.

As in:

CLEARING a screen in graphics mode

 

CLS  LI R0, 0

          LI R1, >2000

CL      BLWP @VMBW

          INC R0

          CI R0,768

          JLT CL

If anyone wants to contribute, I'd love to see a string search routine, where I have a string, "APPLE" located in memory at >E1F2 and it's 5 bytes in length.

But, the string can change in length from 2-15. And I want to look for a match that could be in any memory address from >3000->9000

I was stuck when this string was on an even address I could find most of it, and would lose it if  it were on an odd address. but i resolved that, except for finding the last character.

And since I blew away my code to start fresh again, I don't have an example I was using, but I'll post again when I reach another stopping point, as I'll be trying again today! Yahooooooo

 

But I thought, shoot. How often would I like to see a place where I could find a piece of code, like a MABR, memory address byte read..I'd probably have my search routine fixed if I could compare using byte to byte memory, but I'm reading 16 bit "WORDS" and I'm having to swap out MSB with LSB to compare because everytime I read a memory address, the complete WORD is pulled where I only need 1 byte at a time.

Anyway, a simple thing, has become a lot of code, so far. Usually if my code starts to get large, I figure it's outta control and needs to be reduced, so it's then that I start looking for a way to do that.

 

 

 

 

 

Edited by GDMike
  • Like 1
Link to comment
Share on other sites

For screen clearing and/or initializing any part of VDP RAM I have preferred to write a little routine that I called VFILL.

It's like VMBW but writes the same byte over and over. The parameters are:

  • R0  VDP address
  • R1  the byte that will written
  • R2  number of bytes you want to write.

I don't have conventional source code for it so I won't put anything here that might muddy the water for a new Assembly language coder.

I suppose I could go all academic and say I will leave that as an exercise for the reader. :) 

 

 

Link to comment
Share on other sites

1 hour ago, GDMike said:

CLS  LI R0, 0

          LI R1, >2000

CL      BLWP @VMBW

          INC R0

          CI R0,768

          JLT CL

VSMW is looping for you. All you need is:

CLR  R0
LI   R1,>2000
LI   R2,768
BLWP @VSMW

The problem is there are many coding styles and ways to pass parameters in assembly. I even find it difficult to reuse my own routines from one game to the next. 

Edited by Asmusr
  • Like 1
  • Haha 1
Link to comment
Share on other sites

Of course, I wouldn't want anyone to rely solely on a certain routine unless it was clear as basic and a no brainer, and I still encourage everyone to continue finding great ways to accomplish a goal, but at least I, and my shadow could have an option to, sometimes, begin at,

that's what home automation has been providing me from time to time. I'd love to see routines with explanation. Shoot, who wouldn't? But i could definitely benefit and get something done so I can move on to other things.

The books are nice too, but one routine here and there sometimes isn't clear enough, and questions to the author are, well, not gonna happen. 

Thx so much

  • Thanks 1
Link to comment
Share on other sites

1 hour ago, Asmusr said:

VSMW is looping for you. All you need is:


CLR  R0
LI   R1,>2000
LI   R2,768
BLWP @VSMW

The problem is there are many coding styles and ways to pass parameters in assembly. I even find it difficult to reuse my own routines from one game to the next. 

I thought there was one of those in the conventional system but I couldn't remember the name. Thanks!

Link to comment
Share on other sites

2 hours ago, GDMike said:

CLEARING a screen in graphics mode

 

Here is the routine (modified for your register usage) used in fbForth and TI Forth:

VDPWA  EQU  >8C02          VDP Write Address
VDPWD  EQU  >8C00          VDP Write Data

*== VDP fill routine. ===================================================
*
*     R0: VRAM start address
*     R1: Fill character in MSB
*     R2: Fill count
*
VFILL  ORI  R0,>4000       Set bit for VDP write
       SWPB R0
       MOVB R0,@VDPWA      LS byte first
       SWPB R0
       MOVB R0,@VDPWA      Then MS byte
       NOP                 Kill time (maybe unnecessary)
FLOOP  MOVB R1,@VDPWD      Write a byte
       DEC  R2
       JNE  FLOOP          Not done, fill another
       B    *R11
*========================================================================

 

You would call it as follows (saving R11 before the call and restoring it after, if necessary}:

* Fill screen with blanks. 
*
       CLR  R0             My screen starts at VRAM = >0000
       LI   R1,>2000       Fill character = Blank in MSB
       LI   R2,768         Count for Graphics Mode screen
       BL   @VFILL         Fill screen with blanks

 

...lee

  • Like 1
  • Thanks 1
Link to comment
Share on other sites

Mmmwahaha ...The SHADOW knows!

 

Well, I agree, It's hard to find, simple to absorb examples, that fit universal problems, for a given processor.

I'm surely not that far ahead of you, as I can easily recognize this situation. I've had to figure out the couple of things that I provided you, as well.

 

I have been learning 9900 assembly, since '96, when I first got my hands on a MINIMEMORY cartridge. Unfortunately, I could only make time, on several occasions over the years, to work on my sole encompassing/enveloping project. Maybe for about a month or 2 at a time, at best.  Also got stuck on a few things for extended periods. Now that everything seems to finally be on track ...I've lost inspiration! Once again I am enduring life's complete chaos as well. Perhaps the first real incarnation of my technical aspirations, will not come to pass. Oh well.:waving:


The extended time between my project's stints... have given my mind... time to digest. My electronics background has helped as well. I am only familiar with several instructions, and often have to figure things out from scratch. Without the E/A book, I'd be lost!

 

minnow.jpg.0b118158f16afd4386fedc084c0ec87e.jpg

 

I make surprising strides though, if only by my own standards. Leveraging what little I am familiar with, through a resilient enterprising!:grin: So, I think I can recognize the same, in your efforts!:cool:

 

As for clearing the screen I faced this for the first time myself, not too long ago.

After some consideration... I just did this...

 

       DEF VMBW
SPACE  BYTE 32
       CLR  R0
       LI   R1,SPACE
       LI   R2,768
       BLWP @VMBW

 

...I just typed this in now... didn't test.:-D

  • Thanks 1
Link to comment
Share on other sites

Oh my, this is scary. I actually understand this. Ok, I admit, I've seen this with Matt explaining to Owen in the past I believe, but I never understood it, so Even though I'm sure it worked, back then, and because I didn't understand it, I never used it and kept using the built in routines.  But I'm starting to see it.

I blame it on not understanding the ORI and what it does.

 

Link to comment
Share on other sites

I've been making a "cheat sheet" of sorts for my little routines, it seems as soon as or soon after making a routine, I'd forgotten part of it so soon. Now that's BS! How dare my brain give up on me....

So yeah, I have, how to switch to text mode, clearing screens, moving through colors stuff like that all in a neat booklet.

Edited by GDMike
  • Like 2
Link to comment
Share on other sites

Guess for the most part, everyone rolls their own. My take on it can be found here:

 

https://github.com/FilipVanVooren/spectra2/blob/master/spectra2 reference manual.pdf

 

As part of my Stevie editor I have done many, many changes since the original release of my spectra2 library.

But at its core its still the same though.

  • Like 1
  • Thanks 1
Link to comment
Share on other sites

2 hours ago, HOME AUTOMATION said:

As for clearing the screen I faced this for the first time myself, not too long ago.

After some consideration... I just did this...


       DEF VMBW
SPACE  BYTE 32
       CLR  R0
       LI   R1,SPACE
       LI   R2,768
       BLWP @VMBW

...I just typed this in now... didn't test.:-D

 

No, that will not do what you want. It will put a space at the first screen position and proceed to walk through your program and beyond, copying your machine code as it goes. VMBW is a multi-byte write. It copies one block of RAM to a block of VRAM. You want a single byte written multiple times. See my post above for one way to do that.

 

...lee

  • Like 1
  • Thanks 1
Link to comment
Share on other sites

The question was raised regarding a search string routine earlier.  I've been thinking about such a routine myself, and looked over the My-Word FindString function.  That code is buried in so many subroutines it is pretty useless.  In my case, I need to read in 4 lines of DIS/VAR 80 text, test for the string, and if found, display the 4 lines, and repeat until the end of the file (3000+ 4-line chunks).

 

I will need to make the string case-insensitive, so everything needs to be converted to caps as each 4-line record is read in.

 

String can be any length and need to strip empty spaces at end the user may type.

 

And, I need two buffers to do this, both 255 bytes in length with one the unmodified string, and the second the uppercase string so I can display the unmodified string if needed.

 

At least that is the way I see things at the moment.

 

It is looking like I will need to write it from scratch.  Didn't want to, but if it is going to be implemented, that appears to be the only way.

 

For yourself, you might look into the FunnelWeb source code for the similar Find String function.  I haven't chased that particular code down yet, but you may find something useful in it that may work well with your needs.

 

Just some rambling thoughts.


Beery

 

  • Thanks 1
Link to comment
Share on other sites

When coding for the TI console, I kept some assembly samples and reused them where possible, e.g. an INPUT routine: Give a position, wait for input, return pointer to the string. I kept the habit to use own workspaces for these routines (as I said some time ago, I am a big fan of BLWP) which makes reuse simpler. 

 

One of the generic routines I wrote for the Geneve native mode is a command line parser which delivers the /arguments with their values.

 

While doing tests on the Geneve concerning wait state counting and video speed measurements, I reused one program and changed some parts of it each time.

  • Like 1
Link to comment
Share on other sites

1 hour ago, Lee Stewart said:

No, that will not do what you want.

Thank you... Lee.

 

...I don't get enough sleep at night ...about 4hrs. last night.:sleep:

 

So ...I wonder what I really did last time.:ponder:

 

I only needed  Classic99's Debugger the first time, for this!:grin:

The other 4 or 5 times I reassembled this, I could see what I did wrong immediately.:D


 

       AORG >7D00
       REF  VSBW
CLRSCN LI   R0,960
       LI   R1,>2000
CLRBYT BLWP @VSBW
       DEC  R0
       JNE  CLRBYT
       RT
       END

 

Hmm, It's slow enough that you can see the screen clearing from bottom to top.:twisted:

Could blank the screen first ...then re-enable after!:|

  • Like 1
Link to comment
Share on other sites


I haven't tried a string search algorithm yet...

 

7 hours ago, GDMike said:

And I want to look for a match that could be in any memory address from >3000->9000

 

Where exactly is a memory space from >3000 - >9000, that is user friendly??? You do mean in CPURAM?

I do have an interrupt handler that uses Compare with, indexed auto-increment, to look for "state changes".

 

7 hours ago, GDMike said:

I'd probably have my search routine fixed if I could compare using byte to byte memory, but I'm reading 16 bit "WORDS"

 

It sounds like you're using C instead of CB?

 

Maybe I'll take a stab at this ...in a while.:ponder:

:)

  • Thanks 1
Link to comment
Share on other sites

On 6/30/2020 at 4:07 PM, HOME AUTOMATION said:

 


       AORG >7D00
       REF  VSBW
CLRSCN LI   R0,960
       LI   R1,>2000
CLRBYT BLWP @VSBW
       DEC  R0
       JNE  CLRBYT
       RT
       END

 

 

Though VSBW certainly works, the reason it is slow is that the VRAM address is set every time you write a byte, which is initiated each time with the slow BLWP instruction. That is why a routine like VFILL or VSMW is much faster. They set the VRAM address once and rely on the VDP’s auto-incrementing for the rest.

 

...lee

  • Like 2
Link to comment
Share on other sites

As our machine language programs have direct hardware control, the VRAM address auto-increment should be used, of course. I sometimes wonder how things would like like when we had a full multitasking operating system (maybe for the Geneve 2020?). It would be reasonable to block all direct access to hardware, only offering a system call interface (which would be our XOPs). In that case, we would need lots of simple routines in the kernel, like filling VRAM space.

 

(I just had a short look at the TMS99000 manual; interestingly, there is no restriction on memory access in the user mode, so any memory-mapped device would be directly accessible. But at least some CRU address ranges are restricted to kernel mode, and a memory-mapped device could then be guarded by a CRU bit.)

  • Like 1
Link to comment
Share on other sites

I'm just getting my code back to where it was and I'll show what I have here in a bit,  and making my notes readable.

Then I'll place it here. I added a test routine to show me what chars matched and show it on the screen. This way I have feedback for good hits.

And, yes. I'm using C to test both bytes at once for = but that's a problem when the first byte isn't a hit, but the second byte could possibly be. 

--------------

In my programs:

LIBAD7 is EQU >FEBC.

This contains the text "APPLE" because earlier in my program I manually entered it with my F5, CALL SEARCH command <video>.

I'm also doing this:

LI R9,S32P1 where

S32P1 is EQU>23A4

S32P1 is 840 bytes of text that creates Page 1 in the program.

RRA2 is keeping track of the length of my string to search for, as "APPLE" is counted by the program and will place 5 into RRA2.

Then  once RRA2 is created my program drops here into this code.

Pictured. 

 

 

 

 

 

 

 

IMG_20200630_183227198_HDR.jpg

IMG_20200630_183329812.jpg

Edited by GDMike
Link to comment
Share on other sites

FW1 in the code above was just thrown in because it will or supposed to test for a hit. I'll be removing it once I know the search routine works. This may be messing up my code,as I see the word, "APPLE" that was on page 1 in the video disappeared. 

That wasn't supposed to happen. I just wanted FW1 to stop process once the search was successful.

Link to comment
Share on other sites

I adjusted my feedback routine in fw1. And it's reporting that the first 2 bytes are found and then reports that the last byte is found. So it's returning "APE" instead of "APPLE"

I'm still working it.

I'll do another video and show the code of FW1.

Edited by GDMike
Link to comment
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.
Note: Your post will require moderator approval before it will be visible.

Guest
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.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...