You're not going to like this... (Trying HiROM again)

This is an archive of a topic from NESdev BBS, taken in mid-October 2019 before a server upgrade.
View original topic
You're not going to like this... (Trying HiROM again)
by on (#172691)
Yep... :oops: Hopefully though, I might be a bit more knowledgeable in that I now know what I'm going into now. All I want to do is initialize the SNES, get a vblank handler running, and turn on the screen, making it white or some other color. That's a relatively large amount for someone of my skillset, but I remember koitsu (who has already helped me more than enough with this exact same problem) has said that there's an official SNES initialization routine for LoROM. However, is there one for HiROM that has already been made?

I need to look at the memory map again to see exactly I need to do. I don't even remember, how do you set B (which I remember is the selector for the bank you're getting data from) and K (which is the bank where you're getting program data from)? Isn't it only through the stack?
Re: You're not going to like this... (Trying HiROM again)
by on (#172693)
Program bank (K) is set with long jumps (JML, JSL, and RTL). Data bank is set with PLB, often after a PEA or PHK.
Re: You're not going to like this... (Trying HiROM again)
by on (#172695)
Well, K can also be set by PHK. I have no idea what PEA means, even after this description:

Quote:
Pushes a 16-bit operand onto the stack. The instruction is very misleading because you are really pushing an immediate onto the stack. eg.

Does that mean we're pushing the value at an address? It says you're pushing an immediate though.

Also, I made a picture that shows LoROM and HiROM:

Attachment:
LoROM and HiROM.png
LoROM and HiROM.png [ 292.78 KiB | Viewed 2267 times ]

I'm dumb though, I forgot, shouldn't $00-3F, and $80-$BF, function about the same in LoROM and HiROM? I mean, each bank should look the same, but across all the banks here, the order of how they are arranged is different due to the fact that it's not all continuous like in LoROM, correct?
Re: You're not going to like this... (Trying HiROM again)
by on (#172697)
Espozo wrote:
Well, K can also be set by PHK.

That reads the program bank register but doesn't set it.

Quote:
I have no idea what PEA means, even after this description:

Quote:
Pushes a 16-bit operand onto the stack. The instruction is very misleading because you are really pushing an immediate onto the stack. eg.

Does that mean we're pushing the value at an address? It says you're pushing an immediate though.

The "effective address" instructions might be difficult to understand if you don't come from a 68000 background. For example, this code loads the number 4660 ($1234) into A:
Code:
  rep #$20
  ; Stack contents: ...
  pea $1234
  ; Stack contents: 34 12 ...
  pla
  ; A = $1234; stack contents: ...


But for now, just think of PEA pushing an immediate 16-bit value. When PEA is used with PLB, it's used like this:
Code:
; Stack contents: ...
pea (second_bank) << 8 | (first_bank)
; Stack contents: first_bank second_bank ...
plb
; B = first_bank; stack contents: second_bank ...
; Do things with first data bank here
plb            ; Right now, B = second_bank
; B = second_bank; stack contents: ...
; Do things with second data bank here

The instruction that reads 2 bytes from a zero page location and pushes the value found there is PEI:

Code:
  rep #$e0
  ldy #$2345
  sty $64
  ; Stack contents: ...
  pei ($64)
  ; Stack contents: 45 23 ...
  pla
  ; A = $2345; stack contents: ...




Quote:
shouldn't $00-3F, and $80-$BF, function about the same in LoROM and HiROM?

The CPU sees banks $80-$BF in LoROM (mode $20) and the second half of each bank $80-$BF in HiROM (mode $21) the same way. In addition, $00-$3F and $80-$BF behave the same except for speed.
Re: You're not going to like this... (Trying HiROM again)
by on (#172698)
K cannot be set by PHK (it's a push operation, not a pull). There is no PLK instruction. If you want to change banks, you use a long jump or equivalent.

There are no "official" SNES initialisation routines "for LoROM". All Nintendo provides is what all the SNES registers (not CPU registers) need to be set to on power-on (i.e. reset). This aspect has nothing to do with mode 20, 21, 25, or any other aspect.

The only thing you need to know is that K is $00 on power-on because it has to be (vectors are all accessed and read + executed from there), so if you're using mode 21, you need to keep in mind that any code you have in $0000-7FFF won't exist in bank $00. See the memory maps you've already linked. That's why a long jump (to the next instruction) is required ASAP. This aspect applies regardless of high-speed mode or normal-speed mode. I've attached the official documentation on this matter. The ~ on labels in Nintendo's code examples are specific to their assembler; it indicates a 24-bit address (i.e. a long jump).

Edit: Nintendo's docs refer to K as "PBR" (Program Bank Register). Just thought I'd add that as for clarification. There's no "universal standard" for these acronyms; the ones I use stem from doing 65816 on the Apple IIGS wayyyyy before SNES. I think they're also what Western Design Center uses, but I forget.
Re: You're not going to like this... (Trying HiROM again)
by on (#172700)
The only difference is that Lorom does not have address pin A15 connected to ROM. That's pretty much it. You can think of memory map as just a repeating ROM, with holes cut in it to place RAM and PPU registers. It's like making paper dolls, and cutting half of the doll's legs off.
Re: You're not going to like this... (Trying HiROM again)
by on (#172709)
psycopathicteen wrote:
You can think of memory map as just a repeating ROM, with holes cut in it to place RAM and PPU registers. It's like making paper dolls, and cutting half of the doll's legs off.

So would this be LoROM (because she's low to the ground) or HiROM (because she's waving hello)?
Re: You're not going to like this... (Trying HiROM again)
by on (#172712)
Yeah, koitsu is right, I'm an idiot for trying to start this again. I'm just going to let this topic die: I got way too compulsive. (My OCD took over.) Yeah, so, good day. :lol:
Re: You're not going to like this... (Trying HiROM again)
by on (#172715)
tepples wrote:
psycopathicteen wrote:
You can think of memory map as just a repeating ROM, with holes cut in it to place RAM and PPU registers. It's like making paper dolls, and cutting half of the doll's legs off.

So would this be LoROM (because she's low to the ground) or HiROM (because she's waving hello)?


It depends. If she has a twin sister with legs, she's a hirom. If she has legless twin brothers conjoined in the butt, she's lorom.