Why don't my simple palette changes stick?

Post programming questions related to the CPC Here!
Post Reply
CurlyPaul
Posts: 14
Joined: Sun May 09, 2021 11:24 am

Why don't my simple palette changes stick?

Post by CurlyPaul » Sat May 22, 2021 10:29 am

I've been having trouble getting my palette changes to actually take effect. I've read a few places that this is sometimes due to using interrupts, so I striped it right back to the bare minimum:

Code: Select all

org &8000

exx
ld bc,&7F10	; penr, select pen 10
out (c),c	

ld bc,&7F54	; &54 is black
out (c),c
exx

InfLoop:
	halt
jp InfLoop
And even this, without the exx, it turns black for a frame or two, and then goes back to how it was.

I've tried this with firmware calls, and the result is the same. I feel I'm missing something here?

CurlyPaul
Posts: 14
Joined: Sun May 09, 2021 11:24 am

Re: Why don't my simple palette changes stick?

Post by CurlyPaul » Sat May 22, 2021 10:44 pm

Been reading a lot, seems like it's linked the ability to make colours flash and a system interrupt is constantly switching the ink values back and forth.

http://www.cpcwiki.eu/forum/programming ... -commands/
https://www.cpcwiki.eu/forum/programmin ... nterrupts/

Found that I don't need the firtst exx, only the last one, and on the exxecution of the last exx, there is clearly something else happening in the background as the registers/shadow registers had unexpected values... and what's properly odd is that the debugger jump back a few steps and run the out (c) commands again. Not sure what was about, but I think I'm happy with at least why I'm having to do this ;P

User avatar
akuyou
Posts: 563
Joined: Mon Apr 22, 2019 3:19 am
Contact:

Re: Why don't my simple palette changes stick?

Post by akuyou » Sun May 23, 2021 10:04 am

Yes, sorry - well done for solving your own problem!

You are correct, the firmware interrupt handler will change the colors and screen mode.

The interrupt handler will change the shadow registers, and will probably crash if you change BC' to a value it doesn't like, so you should probably avoid shadow registers unless you're writing your own interrupt handler.

you can simply solve the problem with a DI at the start of your code (Disable interrupts) , provided you don't need the firmware for anything.
Chibi Akuma(s) Comedy-Horror 8-bit Bullet Hell shooter! // 「チビ悪魔」可笑しいゴシックSTG ! // Work in Progress: ChibiAliens

Interested in CPU's :Z80,6502,68000,6809,ARM,8086,RISC-V
Learning: 65816,ARM,8086,6809

CurlyPaul
Posts: 14
Joined: Sun May 09, 2021 11:24 am

Re: Why don't my simple palette changes stick?

Post by CurlyPaul » Sun May 23, 2021 10:33 am

Yeah I noticed it's fine after a di, which is what led me to dive into it, as I want them on to listen for the rastor interrupt.

I'm intrigued by what exactly the system is doing here, and if I can change it or abuse it some way lol.

User avatar
akuyou
Posts: 563
Joined: Mon Apr 22, 2019 3:19 am
Contact:

Re: Why don't my simple palette changes stick?

Post by akuyou » Sun May 23, 2021 10:38 am

The best thing to do is write your own interrupt handler... you just write a 'JP xxxx' command at ram address &0038 where xxxx is your interrupt handler.

There's disassembled sources of the firmware if you want to see what it's doing, but they're pretty complex, so it's not something I've looked at much.

You can't really 'Change' the firmware interrupt handler on a running machine, because it's in ROM, so is 'Read Only'
Chibi Akuma(s) Comedy-Horror 8-bit Bullet Hell shooter! // 「チビ悪魔」可笑しいゴシックSTG ! // Work in Progress: ChibiAliens

Interested in CPU's :Z80,6502,68000,6809,ARM,8086,RISC-V
Learning: 65816,ARM,8086,6809

Post Reply

Return to “Amstrad CPC Assembly Programming”