(Link to AcmlmWiki) Offline: thank ||bass
Register | Login
Views: 13,040,846
Main | Memberlist | Active users | Calendar | Chat | Online users
Ranks | FAQ | ACS | Stats | Color Chart | Search | Photo album
05-17-24 10:17 PM
0 users currently in Programming.
Acmlm's Board - I3 Archive - Programming - PC -> SNES address conversion code problem New poll | |
Add to favorites | Next newer thread | Next older thread
User Post
Sukasa

Birdo
Not quite as active as before.
Xkeeper supporter
Xk > ||bass
I IP Banned myself! Twice!








Since: 11-17-05
From: Somewhere over there

Last post: 6299 days
Last view: 6297 days
Posted on 12-16-05 10:21 PM Link | Quote
Like the title suggests, I'm working on some code to convert a PC address into a SNES LoROM address for SMW, but when I try to get the bank number, I can either get it correctly in decimal, or way off in hex. I'm working with qbasic right now, and the code does this to get the bank number:

LET SNES = (PC - (PC MOD &H8000) / &H8000 ' get decimal bank number
LET SNES$ = STR$(SNES) ' get decimal bank number, string form

That works perfectly fine, as does the rest of the code, but only if I want the bank number to be decimal (the code to get the lower 16 bits of the address works perfectly, and outputs hex).

However, LET SNES$ = HEX$(SNES) in place of LET SNES$ = STR$(SNES) puts out this, when &H316557 is the input PC address:

FFFFFF9E:E557

Also, if STR$ is used, it gives me

98:E557.

instead of 62:E557, which is what Lunar address gives me.

Could anyone please tell me what I am doing wrong? I tried HEX$(&H100000000 - SNES), but it got an overflow error (presumably because &H100000000 is a 33-bit number, on a 32-bit proc).
Euclid



 





Since: 11-17-05
From: Australia
hmm...

Last post: 6304 days
Last view: 6298 days
Posted on 12-16-05 11:17 PM Link | Quote
i don't know what language that code is in but here's how i usually do it (for lorom anyway)

addr = PC mod 0x8000 + 0x8000
bank = PC / 0x8000 (decimal division, just truncate decimals or something similar if the programming language you're using leaves decimals)

after that it's your choice what you do with those 2 values.
Sukasa

Birdo
Not quite as active as before.
Xkeeper supporter
Xk > ||bass
I IP Banned myself! Twice!








Since: 11-17-05
From: Somewhere over there

Last post: 6299 days
Last view: 6297 days
Posted on 12-16-05 11:29 PM Link | Quote
Ah. I'm using qbasic right now, since that's easily available to me for quick stuff. I will try your bank calcultion method, I just hope the HEX$() won't mess up like it has been.

EDIT: I think I know one problem: It keeps using 16-bit numbers. Print &HA000 gives me -24576 or something similar to that. No wonder- If it ran in 32-bit natively, I wouldn't have had any problems in the first place!


(edited by Sukasa on 12-17-05 02:09 AM)
Euclid



 





Since: 11-17-05
From: Australia
hmm...

Last post: 6304 days
Last view: 6298 days
Posted on 12-17-05 06:37 AM Link | Quote
if that's the case you can always replace &H8000 with 32768, but if the variables PC and SNES are 16 bits then it's already impossible to do this calculation since snes addresses are 24 bits long.
Sukasa

Birdo
Not quite as active as before.
Xkeeper supporter
Xk > ||bass
I IP Banned myself! Twice!








Since: 11-17-05
From: Somewhere over there

Last post: 6299 days
Last view: 6297 days
Posted on 12-17-05 04:05 PM Link | Quote
Nah, I use SNES as a base for the calculations, but the final result is a String, SNES$. Do you know how to make a variable 32 bit? I have rebuilt this computer, and although I didn't install and OS'es onto it, I know that the processor IS a 32 bit proc. SNES is just used because I wondered if converting to a string and back all the time was casing a problem, but the original code only had PC and SNES$, not PC, SNES$, and SNES.

EDIT: Oh, and I tried using the decimal form of it. It screwed that up, too.


(edited by Sukasa on 12-17-05 03:06 PM)
Add to favorites | Next newer thread | Next older thread
Acmlm's Board - I3 Archive - Programming - PC -> SNES address conversion code problem |


ABII

Acmlmboard 1.92.999, 9/17/2006
©2000-2006 Acmlm, Emuz, Blades, Xkeeper

Page rendered in 0.006 seconds; used 368.45 kB (max 443.38 kB)