Announcement

Collapse

Forum Rules and Etiquette

Our mission ...

This forum is part of our mission to promote the preservation of vintage computers through education and outreach. (In real life we also run events and have a museum.) We encourage you to join us, participate, share your knowledge, and enjoy.

This forum has been around in this format for over 15 years. These rules and guidelines help us maintain a healthy and active community, and we moderate the forum to keep things on track. Please familiarize yourself with these rules and guidelines.


Rule 1: Remain civil and respectful

There are several hundred people who actively participate here. People come from all different backgrounds and will have different ways of seeing things. You will not agree with everything you read here. Back-and-forth discussions are fine but do not cross the line into rude or disrespectful behavior.

Conduct yourself as you would at any other place where people come together in person to discuss their hobby. If you wouldn't say something to somebody in person, then you probably should not be writing it here.

This should be obvious but, just in case: profanity, threats, slurs against any group (sexual, racial, gender, etc.) will not be tolerated.


Rule 2: Stay close to the original topic being discussed
  • If you are starting a new thread choose a reasonable sub-forum to start your thread. (If you choose incorrectly don't worry, we can fix that.)
  • If you are responding to a thread, stay on topic - the original poster was trying to achieve something. You can always start a new thread instead of potentially "hijacking" an existing thread.



Rule 3: Contribute something meaningful

To put things in engineering terms, we value a high signal to noise ratio. Coming here should not be a waste of time.
  • This is not a chat room. If you are taking less than 30 seconds to make a post then you are probably doing something wrong. A post should be on topic, clear, and contribute something meaningful to the discussion. If people read your posts and feel that their time as been wasted, they will stop reading your posts. Worse yet, they will stop visiting and we'll lose their experience and contributions.
  • Do not bump threads.
  • Do not "necro-post" unless you are following up to a specific person on a specific thread. And even then, that person may have moved on. Just start a new thread for your related topic.
  • Use the Private Message system for posts that are targeted at a specific person.


Rule 4: "PM Sent!" messages (or, how to use the Private Message system)

This forum has a private message feature that we want people to use for messages that are not of general interest to other members.

In short, if you are going to reply to a thread and that reply is targeted to a specific individual and not of interest to anybody else (either now or in the future) then send a private message instead.

Here are some obvious examples of when you should not reply to a thread and use the PM system instead:
  • "PM Sent!": Do not tell the rest of us that you sent a PM ... the forum software will tell the other person that they have a PM waiting.
  • "How much is shipping to ....": This is a very specific and directed question that is not of interest to anybody else.


Why do we have this policy? Sending a "PM Sent!" type message basically wastes everybody else's time by making them having to scroll past a post in a thread that looks to be updated, when the update is not meaningful. And the person you are sending the PM to will be notified by the forum software that they have a message waiting for them. Look up at the top near the right edge where it says 'Notifications' ... if you have a PM waiting, it will tell you there.

Rule 5: Copyright and other legal issues

We are here to discuss vintage computing, so discussing software, books, and other intellectual property that is on-topic is fine. We don't want people using these forums to discuss or enable copyright violations or other things that are against the law; whether you agree with the law or not is irrelevant. Do not use our resources for something that is legally or morally questionable.

Our discussions here generally fall under "fair use." Telling people how to pirate a software title is an example of something that is not allowable here.


Reporting problematic posts

If you see spam, a wildly off-topic post, or something abusive or illegal please report the thread by clicking on the "Report Post" icon. (It looks like an exclamation point in a triangle and it is available under every post.) This send a notification to all of the moderators, so somebody will see it and deal with it.

If you are unsure you may consider sending a private message to a moderator instead.


New user moderation

New users are directly moderated so that we can weed spammers out early. This means that for your first 10 posts you will have some delay before they are seen. We understand this can be disruptive to the flow of conversation and we try to keep up with our new user moderation duties to avoid undue inconvenience. Please do not make duplicate posts, extra posts to bump your post count, or ask the moderators to expedite this process; 10 moderated posts will go by quickly.

New users also have a smaller personal message inbox limit and are rate limited when sending PMs to other users.


Other suggestions
  • Use Google, books, or other definitive sources. There is a lot of information out there.
  • Don't make people guess at what you are trying to say; we are not mind readers. Be clear and concise.
  • Spelling and grammar are not rated, but they do make a post easier to read.
See more
See less

Is it safe to use RST 28h in CP/M assembly programs?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Is it safe to use RST 28h in CP/M assembly programs?

    Would any CP/M programmers out there care to comment on this scheme for implementing "call relative" functionality under CP/M? Is it safe? I can't see anything in the RST 28h vector prior to doing this on the CP/M implementation I'm doing it on, but I wanted to check...

    Code:
    	.org 100h
    
    	; setup the RST 28 code ;
    	ld	a,0e1h		; pop hl
    	ld	(028h),a	;
    	ld	a,0e5h		; push hl
    	ld	(029h),a	;
    	ld	a,0c9h		; ret
    	ld	(02ah),a	;
    	
    	; relative call to testfn
    	ld	de,0004
    	rst	28h	; PC into HL
    	add	hl,de
    	push	hl	; to stack
    	jr	testfn
    
    	; exit program (in CP/M, to CCP)
    	jp	0
    	
    testfn:	ld a,0ffh		; do something
    	ret			; and return
    	
    	.end
    	
    	; EOF
    So, first I copy a short subroutine to one of the RST vector addresses, 28h:

    Code:
    ; RST 28h routine
    0028	pop hl		; get return address into HL
    0029	push hl		; restore return address to stack
    002A	ret		; ..and return
    Now, when I issue the instruction RST 28h I get the value of the address immediately following the RST instruction in HL. From there I can calculate and push a return address onto the stack, then use JR to take me to the subroutine. When it hits the RET, I am back where I expect to be. This seems to work fine under ZSID and I expect it will be fine in any other code. Unless 28h is in use, which I think it isn't...

    #2
    Interrupt vectors are not used by CP/M, so from CP/M's perspective, it is OK to use RST 28h. Not to say, however, that someone's computer isn't configured with a device at interrupt vector 5 which would use RST 28h.

    You can shorten the code at RST 28h to:

    Code:
            pop h
            pchl
    Which can be stored at 28h by

    Code:
            lxi h,0E9E1h        ;H=PCHL, L=POP H
            shld 28h
    If you know the value of the stack pointer when doing this (e.g., this call is made when the stack is at its initialization value, say the equate "STACK"), then you can do this without RST 28h:

    Code:
            lxi h,0E9E1h   ;H=PCHL, L=POP H
            push h
            call STACK-2   ;HL=address following call
            lxi d,7        ;DE=offset past jr instruction
            dad d
            push h
            jr testfn
    And, of course, you could do this with a two byte fixed location as well to hold the PCHL, POP H.

    Mike
    Last edited by deramp5113; November 7, 2016, 05:38 PM.

    Comment


      #3
      As Mike said, it depends on the system and its I/O routines. You're probably safe in most cases, but I wouldn't spec that at 100%.

      Reminds me of the usage of the page 0 (direct memory) on the 6502 or the low-memory BIOS area on a PC. What's safe can vary.


      What CP/M system (I can't think of it offhand) used a different vector for DDT breakpoints than the one at 0038H? Apparently it was already used for someone's keyboard routine. Memory fails me.
      Reach me: vcfblackhole _at_ protonmail dot com.

      Comment


        #4
        Now that I do like.

        Code:
        pop HL
        jp (HL)
        Neat!

        I have to use a fixed address because the code that is calling it is going to be completely relocatable.

        However, I may be better off leaving the calls as calls, and patching the call addresses once the code is relocated, because this wouldn't incur performance overhead. A bit of a headache if the code is changed though (because I would have to redo all the offsets to the called code).

        Isn't this sort of how MOVCPM works?

        Comment


          #5
          Very much so--I think I've referenced PRL files and how they originally got their start with MOVCPM, but became an integral part of MP/M and CP/M 3.0.

          But PRL files use a bit map in which every bit corresponds to a memory location; one bits indicate that a page relocation offset should be added to the corresponding memory location.

          If you have very few absolute memory references (as opposed to relative ones) you may want to employ a pointer list (2 bytes per reference) rather than a bitmap. This is unlikely in 8080 code which doesn't have relative jumps, but may be a consideration for Z80 code. The trick to quickly find this out is to assemble your program twice; the second time offset by 100H, then compare the two binaries.

          The advantage of run-time relocation is that you don't have to incur a penalty for code that attempts to get around the relocation issue--no "tricks"; just write straight code.
          Reach me: vcfblackhole _at_ protonmail dot com.

          Comment


            #6
            Yes indeedy. I may try that later on, but for now there are only a few relative calls so I'm going to try and get it going with RST 28h. It's the IDE driver, so I probably won't be happy with the lower performance (if I can perceive it). But as an exercise it'd be fun to use a bitmap. Looks easy enough.... (famous last words eh?) but I would like it to be easy to build, and automatic, so I can edit the code without updating any absolute address references manually.

            Comment


              #7
              Jon I am planning to write IDE driver as well (in 8080 assembly).. when you are finished, and would be willing to share drop me a PM please.

              Comment


                #8
                Originally posted by Chuck(G) View Post
                What CP/M system (I can't think of it offhand) used a different vector for DDT breakpoints than the one at 0038H? Apparently it was already used for someone's keyboard routine. Memory fails me.
                Anything that used a Z80 in IM1 (such as the Spectrum +3) would need RST 38h for interrupts, so DDT / SID were modified to use RST 30h for breakpoints.

                Comment

                Working...
                X