News:

Printed Amstrad Addict magazine announced, check it out here!

Main Menu
avatar_ervin

DI, EI, EXX and the firmware

Started by ervin, 01:37, 17 August 16

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

ervin

Hi folks.

In my cpctelera/SDCC line drawing program, I'm now at the stage of optimisations in asm.
I'm starting to use the alternate (EXX) instructions a lot.

Now, as I've got the firmware disabled (as recommended when using cpctelera), I'm wondering if I need to use DI/EI around EXX blocks.
I don't have DI/EI around any of my EXX blocks (even when using BC) and so far I'm not having any problems.

Is it safe to ignore DI/EI when the firmware is disabled?

AMSDOS

Quote from: ervin on 01:37, 17 August 16
Hi folks.

In my cpctelera/SDCC line drawing program, I'm now at the stage of optimisations in asm.
I'm starting to use the alternate (EXX) instructions a lot.

Now, as I've got the firmware disabled (as recommended when using cpctelera), I'm wondering if I need to use DI/EI around EXX blocks.


I think so, though I could be wrong, the Alternative Register set are used in the inner workings (OS I think) of the computer. I read somewhere in another post that if it was in CP/M, you wouldn't need to Enable Disable Interrupts for the Alternative Register Set (CP/M doesn't use them being the reason).



QuoteI don't have DI/EI around any of my EXX blocks (even when using BC) and so far I'm not having any problems.

Is it safe to ignore DI/EI when the firmware is disabled?


I know you can't use DI/EI when using the Firmware, I only really ever used DI when moving chunks of code from the Screen Memory to where AMSDOS/the Firmware Resided.
* Using the old Amstrad Languages :D   * with the Firmware :P
* I also like to problem solve code in BASIC :)   * And type-in Type-Ins! :D

Home Computing Weekly Programs
Popular Computing Weekly Programs
Your Computer Programs
Updated Other Program Links on Profile Page (Update April 16/15 phew!)
Programs for Turbo Pascal 3

ervin

Quote from: AMSDOS on 01:57, 17 August 16
I think so, though I could be wrong, the Alternative Register set are used in the inner workings (OS I think) of the computer. I read somewhere in another post that if it was in CP/M, you wouldn't need to Enable Disable Interrupts for the Alternative Register Set (CP/M doesn't use them being the reason).

I know you can't use DI/EI when using the Firmware, I only really ever used DI when moving chunks of code from the Screen Memory to where AMSDOS/the Firmware Resided.

Hmmm, interesting.
Thanks man.

It certainly seems to be ok with the firmware disabled.

I know that I *had* to use DI/EI when I was writing Chunky Pixel Curator in ccz80.
I had the firmware enabled in that program, and if I didn't use DI/EI, the program would crash instantly (that program had a lot of EXX register usage).

AMSDOS

I found this PDF document on the CPCTech site, which might help explain where you can use the Alternative Register Set and what Alternative Registers are used, the Firmware does get a lot of mentions in it, so perhaps with the Firmware out of play, you're in the clear to use them?
* Using the old Amstrad Languages :D   * with the Firmware :P
* I also like to problem solve code in BASIC :)   * And type-in Type-Ins! :D

Home Computing Weekly Programs
Popular Computing Weekly Programs
Your Computer Programs
Updated Other Program Links on Profile Page (Update April 16/15 phew!)
Programs for Turbo Pascal 3

ervin

Quote from: AMSDOS on 02:25, 17 August 16
I found this PDF document on the CPCTech site, which might help explain where you can use the Alternative Register Set and what Alternative Registers are used, the Firmware does get a lot of mentions in it, so perhaps with the Firmware out of play, you're in the clear to use them?

That's fantastic!
Thanks!

Executioner

If you're not using the firmware, where does the interrupt vector go in CPCtelera? If CPCtelera has an interrupt routine that uses the alternate registers you might be in trouble. That said, if you disable interrupts at the start of your routine and enable them at the end you won't need to do it separately when using the registers, but if the routine takes some time you'll upset interrupts if anyone is using them for anything.

ervin

Quote from: Executioner on 03:41, 17 August 16
If you're not using the firmware, where does the interrupt vector go in CPCtelera? If CPCtelera has an interrupt routine that uses the alternate registers you might be in trouble. That said, if you disable interrupts at the start of your routine and enable them at the end you won't need to do it separately when using the registers, but if the routine takes some time you'll upset interrupts if anyone is using them for anything.


Thanks Richard.
I actually don't know where the interrupt vector goes.
@ronaldo can you help?


ronaldo

#7
@ervin CPCtelera does nothing by itself: it's just a building system + a low-level library. Anything is done when you call functions of the low-level library, and anything a function does is detailed in the documentation.

With respect to interruptions, when you call cpct_disableFirmware(), the function writes a EI:RET in the interrupt vector (0038h). From then on, every time an interrupt happens, it only returns leaving interrupts enabled. Then, no other code than your code is executed. This is the reason why you can safely change any register. If you do not disable firmware, firmware code is called on every interrupt. Firmware code modifies the alternate register set, which surely will destroy your working values.

If you create your own interrupt handler, you have to take into account all this things: cpct_setInterruptHandler() creates a wrapper that automatically saves and restores standard registers, but not the alternate set. If you use them in your interrupt handling code, you have to take care by yourself.

Shining

I've looked into the cpctelera source:


When you disable firmware by using the cpctelera-function cpct_disableFirmware, cpctelera installs only a RET-instruction there.
So every interrupt, only a RET will be processed and no register in any of the two sets is altered.

Edit: Oh, ronaldo was faster :D .
TGS is back

Download my productions at:
cpc.scifinet.org

ervin

Thanks @ronaldo and @Shining , that's really useful information.

TFM

Ronaldo probably means &0038, not 39. However one thing is needed to mention. If you switch on the lower ROM (f.e. to access character set), then the interrupt handler of the ROM will be used... and Crash!

TFM of FutureSoft
Also visit the CPC and Plus users favorite OS: FutureOS - The Revolution on CPC6128 and 6128Plus

Executioner

Quote from: TFM on 17:47, 17 August 16
Ronaldo probably means &0038, not 39. However one thing is needed to mention. If you switch on the lower ROM (f.e. to access character set), then the interrupt handler of the ROM will be used... and Crash!

Yes, but either you shouldn't switch the lower ROM on, or if you do, you need to patch the vector also at #B9xx or alternatively switch to interrupt mode 2 and use a table in RAM. The way I normally do it (which may be better for CPCtelera disable firmware) is:


ld hl,(#39)
ld (hl),#fb    ;; EI
inc hl
ld (hl),#c9   ;; RET


This may not be a good idea if the compiler actually generates code at #B9xx and you're not using firmware at all, so maybe also patch #38 with EI:RET.

The original method is fine so long as whenever you use the lower ROM (not to call firmware routines) you disable interrupts first, then enable the ROM, then do whatever, disable the ROM and re-enable interrupts once the ROM is disabled again.

ervin

Thanks guys.
I'm not using the firmware at all, so it should be ok.

ronaldo

Quote from: TFM on 17:47, 17 August 16
Ronaldo probably means &0038, not 39.
Yes, @TFM, completely right :). I wrote the post too fast and didn't notice it. Thanks for pointing it out. I'll fix it right now in the post :)

TFM

@ronaldo : IMHO it's a great thing that CPCTelera can disable the firmware, so it serves a broader spectrum of development ideas.  :)


@Executioner : Yes, IM 2 is the way to go. Also makes things more easy when using PlayCity f.e.  :)
TFM of FutureSoft
Also visit the CPC and Plus users favorite OS: FutureOS - The Revolution on CPC6128 and 6128Plus

Powered by SMFPacks Menu Editor Mod