Problem with _cd_execoverlay

hu, cd, scd, acd, supergrafx discussions.
TOUKO
Posts: 41
Joined: Mon May 25, 2009 5:37 pm

Problem with _cd_execoverlay

Post by TOUKO »

Hi all, i have a big problem with cd_execoverlay function ..

It doesn't work ..
But loading datas(sound and gfx only) from a third, works fine ..

My question is, how overlay exec works in general (not the huc function) ..
I have two overlays (with different startup.asm,it's probaly the problem) and i can startup the first overlay, but not the second ..
i use huc only for bank mapping, 98% of code is in asm .

Individualy, all overlays works fine .

Thanks.
TOUKO
Posts: 41
Joined: Mon May 25, 2009 5:37 pm

Re: Problem with _cd_execoverlay

Post by TOUKO »

No answers ?? :(

i'am doing it more easily:
How to execute another overlay ???

Image

EDIT: ok resolved, it don't work because i have not desabled interupts before call cd_execoverlay

Thanks ..
TOUKO
Posts: 41
Joined: Mon May 25, 2009 5:37 pm

Re: Problem with _cd_execoverlay

Post by TOUKO »

But someone know how works cd_exec routine ???

Because huc function seems to load only datas after bank0, and i have different datas in this bank for all my overlays :(
Last edited by TOUKO on Tue Jan 10, 2012 9:21 am, edited 1 time in total.
User avatar
MooZ
Site Admin
Posts: 402
Joined: Sun Jun 22, 2008 3:19 pm
Location: Lvl 3
Contact:

Re: Problem with _cd_execoverlay

Post by MooZ »

Here's the doc for cd_exec taken from Hu7CD doc:
CD_EXEC: Read data from CD to specified Address.
IN :
  • _CL REC H
  • _CH REC M
  • _DL REC L
  • _DH Data read address type (01: LOCAL else MPR Number (2-6))
  • _BL ADR L: Bank number ($80-87)
  • _BH ADR H: No use
  • _AL REC Length
  • _AH ADR H: No use
As I understand it, you can't use MPR 0 (for obvious reasons) nor 1. By the way, I don't really get what they meant by "local"...
TOUKO
Posts: 41
Joined: Mon May 25, 2009 5:37 pm

Re: Problem with _cd_execoverlay

Post by TOUKO »

Thanks mooz, i have red this from the same pdf, but my understading of this function is :shock:

Do you think that is possible to reload all the banks from an overlay ???, because i'am using different vsync and hsync irq (and other functions) stored in bank 0.
Now i can load correcly an overlay, but not the bank 0,it's a pity if bank 0 free space cannot be used ..

REC H,REC M, REC L , what's this ?? , an overlay offset coded in 24 bits ??..
i know that _bx can be used, for store an address to jump, when all datas are loaded ..
Last edited by TOUKO on Tue Jan 10, 2012 9:21 am, edited 2 times in total.
User avatar
MooZ
Site Admin
Posts: 402
Joined: Sun Jun 22, 2008 3:19 pm
Location: Lvl 3
Contact:

Re: Problem with _cd_execoverlay

Post by MooZ »

About your vsync/hsync routines. If you are on a cd, you are using the bios. There's a piece of code in the bios that'll be called at each vsync/hsync and check if there are user specified routines (or callback if you want), and call them. I guess you are setting the vsync/hsync with ex_setvec?
So basically your vsync/hsync routines can be anywhere. You can't completely overwrite/replace interrupt bios routines. The mpr 1 is not accessible because it's always set to $f8 (RAM). mpr 0 is set to $ff (ROM).

I think you mixed up MPR and bank. They are 2 different things. A bank is a bloc of 8 kilobytes in ROM. A MPR is a register used to compute an address.
The PC-Engine has an 8 bits cpu with 16 bits addressing. As the addresses are represented as 16bits values, the CPU can't access the whole memory space which is 2M bytes wide. We will need an address of 21 bits to directly access it. So the trick used is to split the 16 bits address (the logical address) in 2 parts. One part will specify a memory space block of 8kB and the second part an offset in that block. This will gives us 13 bits for the 8kB offset and 3 bits for the 8kB block to use. But with 3 bits you can only specify 8 blocks. That's where MPR registers enter the game. The 3 bits don't specify directly a 8kB block but a MPR register. And this register stores a byte. So you can have up to 256 8kB block.
Erm.. Maybe a piece of C code will be clearer:

Code: Select all

// The address of an instruction. For example lda $cd81
uint16_t logical_address = 0xcd81;

uint8_t mprIndex = logical_address >> 13;
uint16_t offset = logical_address & 0x1fff;

// The real physical address
uint32_t physical_address = (mprRegister[mprIndex] << 13) + offset;
The other confusing stuff may be the .bank and .org directives. .bank i tells the assembler that your code/data will be stored at the ith 8kB block of your file. .org has a double role (and this is fucking annoying sometimes). It tells the assembler which is the logical address of your code/data. ie in which mpr your bank will be mapped. The second role is to specify the bank offset where your code/data will stored.
Again a little bit of C code:

Code: Select all

uint8_t bank = 9;
uint16_t org = 0x6000;

// let's say that this pointer points to the compiled code
uint8_t *data;

// pceas will write your code/data like this
fwrite(data, 1, (bank * 8192) + (org & 0x1fff), output);
And for the second purpose of .org, suppose the assembler is compiling this piece of code

Code: Select all

    .bank 11
    .org $6000
data:
    .db 1,2,3,4
foo:
    clx
    cly
loop:
    lda   data, X
    sta   [_di], Y
    iny
    inx
    cpx  #4
    bne  loop
    rts
The values of data, foo and loop are computed with the help of the .org value. data will be equal to $6000, foo $6004 and loop $6006. This means that your code will be translated as:

Code: Select all

    .bank 11
    .org $6000
data:
    .db 1,2,3,4
foo:
    clx
    cly
loop:
    lda   $6000, X  ; data = $6000
    sta   [_di], Y
    iny
    inx
    cpx  #4
    bne  $6006  ; loop = $6006
    rts
If you want to use this code, you'll have to first set the MPR used in your .org to the bank you specify in .bank. Here the mpr used is ($6000 >> 13) = 3. If you do a "jsr foo" and you forgot to map bank 11 to mpr 3, you'll end up where the mpr was set to and it will not be the place you wanted.

Code: Select all

    lda    #11 ; Map bank 11
    tam   #3   ; to MPR register 3
    stw    $2200, <_di ; _di will point to bss ram area
    jsr  foo ; You'll jump to your code
    ; and copy 1,2,3,4 into the first 4 bytes of the bss
Let's say you wrote this another piece of code:

Code: Select all

    .bank 9
    .org $6000
stuff
    .db 5,6,7,8
bar:
    clx
    cly
boink:
    lda   data, X
    sta   [_di], Y
    iny
    inx
    cmp  #8
    bne  boink
This code will copy the bytes stored at data into the area pointed by _di. It will stop if the byte copied is equal to 8.
Ok. Now imagine that we now do this:

Code: Select all

    lda    #9
    tam   #3
    stw    $2200, <_di
    jsr    foo
What will the first 4 bytes of $2200 contain?
You have 2 hours. :)
TOUKO
Posts: 41
Joined: Mon May 25, 2009 5:37 pm

Re: Problem with _cd_execoverlay

Post by TOUKO »

:o

Thanks mooz that's an explanation ..
i use this piece of code for my perso irq .

Code: Select all

stw	  #User_Vsync_Irq,vsync_hook	; // Gestionnaire VSYNC perso
smb   #4,<irq_m						; // enable new code

stw	  #User_Hsync_Irq,hsync_hook	; // Gestionnaire HSYNC perso
smb   #6,<irq_m						; // enable new code		
Bios irq are always available, and only hook my code .
i will study your very usefull post ;)

For ex_setvec, i agree with you, but if your code is in bank0, and bank0 is not reloaded with cd_exec ..
All your new code in this bank,who's not present in first overlay, is not loaded.

I also have a function in my second overlay placed in bank0, and it not works when this overlay is loaded from another ..
tomaitheous
Posts: 88
Joined: Mon Jun 23, 2008 1:58 pm

Re: Problem with _cd_execoverlay

Post by tomaitheous »

Ok, so what's the problem? CD_EXEC bios function won't load to bank $68 or $69 (00 or 01)?
TOUKO
Posts: 41
Joined: Mon May 25, 2009 5:37 pm

Re: Problem with _cd_execoverlay

Post by TOUKO »

Yes, if i put my irqs code in startup.asm, when i load the next overlay, it keep the last overlay startup code ..

it seems that only a part of bank0 was keep,bacause if i put my irq code in bank0 indeed my loaded overlay it works ..
I don't know if i 'am clear :mrgreen:
tomaitheous
Posts: 88
Joined: Mon Jun 23, 2008 1:58 pm

Re: Problem with _cd_execoverlay

Post by tomaitheous »

Can you give a small example code so I can look at it? Doesn't have to be your current game WIP code.
Post Reply