Author Topic: Problem setting Plus palette colours  (Read 476 times)

0 Members and 1 Guest are viewing this topic.

Offline Cwiiis

  • CPC664
  • ***
  • Posts: 127
  • Country: gb
    • Blog
    • Awards
Problem setting Plus palette colours
« on: 19:58, 11 August 21 »
I'm sure I'm doing something bone-headed here, but for the life of me, I can't seem to get Plus colours working - I enable the Plus ASIC features, copy the palette, but the screen is still using whatever palette was set before the code runs... Can anyone spot what I'm doing wrong? (working in Orgams, fwiw)


Code: [Select]
SetMode = &BC0E
ClearScreen = &BC14
WaitChar = &BB06

      ORG &1200

          ld a,0
          call SetMode
          call ClearScreen

; Generate a blue gradient palette
          ld a,0
          ld b,16
          ld hl,Scratch
GenPaletteLoop
          ld (hl),0
          inc hl
          ld (hl),a
          inc a
          inc hl
          djnz GenPaletteLoop

          di

          call EnablePlus

          ld bc,&7FB8   ; Map Plus registers
          out (c),c

          ld de,&6400   ; Copy palette
          ld hl,Scratch
          ld bc,32      ; Each colour is 2 bytes, so 32
          ldir

          ld bc,&7FA0   ; Unmap Plus registers
          out (c),c

          ei

; Fill the screen with a gradient
          ld de,TwoPixelLookup
          ld hl,LineLookup
          ld a,0        ; Palette nibble

GradientLoop
          push de
          ld b,12       ; Outer loop counter

Draw12LinesLoop
          ld d,(hl)     ; Lookup line address
          inc hl
          ld e,(hl)
          inc hl

          ld c,b        ; Backup outer loop counter

          ld b,80       ; Draw 160 pixels (80 * 2)
Draw1LineLoop
          ld (de),a
          inc de
          djnz Draw1LineLoop

          ld b,c        ; Restore outer loop counter
          djnz Draw12LinesLoop

          cp &FF        ; Check if we drew the last pixel pair

          pop de        ; Restore, increment and load pixel look-up
          inc de
          ld a,(de)

          jp nz,GradientLoop

; Exit
          call WaitChar
          ret

EnablePlus              ; Copy 17 byte sequence to enable Plus features
          ld hl,EnablePlusSeq
          ld b,&BC
          ld e,17
EnablePlusLoop
          ld a,(hl)
          out (c),a
          inc hl
          dec e
          jr nz,EnablePlusLoop
          ret

; Data

EnablePlusSeq
      BYTE &FF,&00,&FF,&77,&B3,&51,&A8,&D4
      BYTE &62,&39,&9C,&46,&2B,&15,&8A,&CD,&EE

LineLookup
      BYTE &C0,&00,&C8,&00,&D0,&00,&D8,&00
      BYTE &E0,&00,&E8,&00,&F0,&00,&F8,&00 ; 1-8

      BYTE &C0,&50,&C8,&50,&D0,&50,&D8,&50
      BYTE &E0,&50,&E8,&50,&F0,&50,&F8,&50 ; 9-16

      BYTE &C0,&A0,&C8,&A0,&D0,&A0,&D8,&A0
      BYTE &E0,&A0,&E8,&A0,&F0,&A0,&F8,&A0 ; 17-24

      BYTE &C0,&F0,&C8,&F0,&D0,&F0,&D8,&F0
      BYTE &E0,&F0,&E8,&F0,&F0,&F0,&F8,&F0 ; 25-32

      BYTE &C1,&40,&C9,&40,&D1,&40,&D9,&40
      BYTE &E1,&40,&E9,&40,&F1,&40,&F9,&40 ; 33-40

      BYTE &C1,&90,&C9,&90,&D1,&90,&D9,&90
      BYTE &E1,&90,&E9,&90,&F1,&90,&F9,&90 ; 41-48

      BYTE &C1,&E0,&C9,&E0,&D1,&E0,&D9,&E0
      BYTE &E1,&E0,&E9,&E0,&F1,&E0,&F9,&E0 ; 49-56

      BYTE &C2,&30,&CA,&30,&D2,&30,&DA,&30
      BYTE &E2,&30,&EA,&30,&F2,&30,&FA,&30 ; 57-64

      BYTE &C2,&80,&CA,&80,&D2,&80,&DA,&80
      BYTE &E2,&80,&EA,&80,&F2,&80,&FA,&80 ; 65-72

      BYTE &C2,&D0,&CA,&D0,&D2,&D0,&DA,&D0
      BYTE &E2,&D0,&EA,&D0,&F2,&D0,&FA,&D0 ; 73-80

      BYTE &C3,&20,&CB,&20,&D3,&20,&DB,&20
      BYTE &E3,&20,&EB,&20,&F3,&20,&FB,&20 ; 81-88

      BYTE &C3,&70,&CB,&70,&D3,&70,&DB,&70
      BYTE &E3,&70,&EB,&70,&F3,&70,&FB,&70 ; 89-96

      BYTE &C3,&C0,&CB,&C0,&D3,&C0,&DB,&C0
      BYTE &E3,&C0,&EB,&C0,&F3,&C0,&FB,&C0 ; 97-104

      BYTE &C4,&10,&CC,&10,&D4,&10,&DC,&10
      BYTE &E4,&10,&EC,&10,&F4,&10,&FC,&10 ; 105-112

      BYTE &C4,&60,&CC,&60,&D4,&60,&DC,&60
      BYTE &E4,&60,&EC,&60,&F4,&60,&FC,&60 ; 113-120

      BYTE &C4,&B0,&CC,&B0,&D4,&B0,&DC,&B0
      BYTE &E4,&B0,&EC,&B0,&F4,&B0,&FC,&B0 ; 121-128

      BYTE &C5,&00,&CD,&00,&D5,&00,&DD,&00
      BYTE &E5,&00,&ED,&00,&F5,&00,&FD,&00 ; 129-136

      BYTE &C5,&50,&CD,&50,&D5,&50,&DD,&50
      BYTE &E5,&50,&ED,&50,&F5,&50,&FD,&50 ; 137-144

      BYTE &C5,&A0,&CD,&A0,&D5,&A0,&DD,&A0
      BYTE &E5,&A0,&ED,&A0,&F5,&A0,&FD,&A0 ; 145-152

      BYTE &C5,&F0,&CD,&F0,&D5,&F0,&DD,&F0
      BYTE &E5,&F0,&ED,&F0,&F5,&F0,&FD,&F0 ; 153-160

      BYTE &C6,&40,&CE,&40,&D6,&40,&DE,&40
      BYTE &E6,&40,&EE,&40,&F6,&40,&FE,&40 ; 161-168

      BYTE &C6,&90,&CE,&90,&D6,&90,&DE,&90
      BYTE &E6,&90,&EE,&90,&F6,&90,&FE,&90 ; 169-176

      BYTE &C6,&E0,&CE,&E0,&D6,&E0,&DE,&E0
      BYTE &E6,&E0,&EE,&E0,&F6,&E0,&FE,&E0 ; 177-184

      BYTE &C7,&30,&CF,&30,&D7,&30,&DF,&30
      BYTE &E7,&30,&EF,&30,&F7,&30,&FF,&30 ; 185-192

      BYTE &C7,&80,&CF,&80,&D7,&80,&DF,&80
      BYTE &E7,&80,&EF,&80,&F7,&80,&FF,&80 ; 193-200

TwoPixelLookup
      BYTE %0
      BYTE %11
      BYTE %1100
      BYTE %1111
      BYTE %110000
      BYTE %110011
      BYTE %111100
      BYTE %111111
      BYTE %11000000
      BYTE %11000011
      BYTE %11001100
      BYTE %11001111
      BYTE %11110000
      BYTE %11110011
      BYTE %11111100
      BYTE %11111111

; Scratch area to store random stuff
Scratch   nop
like
0
No reactions

Offline demoniak

  • CPC664
  • ***
  • Posts: 107
  • Country: fr
    • Awards
Re: Problem setting Plus palette colours
« Reply #1 on: 20:14, 11 August 21 »
Your code is good, but when you do EI, the cpc system will set the "basic" palette every 1/50th seconds...So if you want to see your own palette, you should do a wait loop until doing the EI
like
0
No reactions

Offline Cwiiis

  • CPC664
  • ***
  • Posts: 127
  • Country: gb
    • Blog
    • Awards
Re: Problem setting Plus palette colours
« Reply #2 on: 20:52, 11 August 21 »
Thanks! It seems calling practically any of the BIOS functions seems to do that reset, is there any way to stop that or practically do you just have to not rely on firmware functions when using a non-default palette? Or am I missing some code to uninstall the basic interrupt handlers?
like
0
No reactions

Offline tronic

  • CPC464
  • **
  • Posts: 18
    • Awards
Re: Problem setting Plus palette colours
« Reply #3 on: 22:15, 11 August 21 »
is there any way to stop that
Hello,

Yes, there is a well-known tip usually used for that kind of issue.

At #B7F9 we have = SCR Event Block: Set Inks.
See there : https://cpcrulez.fr/codingBOOK_bible6128_2-02-2.htm

And, with a firmware call at #BCDD we have KL DEL FRAME FLY.
KL DEL FRAME FLY = Removes a frame flyback event block from the list of routines which are mn when a frame flyback occurs.
Entry HL contains the address of the event block
Exit AF, DE and HL are corrupt, and all others are preserved
See there : http://www.cantrell.org.uk/david/tech/cpc/cpc-firmware/kernel.htm

So, if we only put this following code at the beginning & just after your "call ClearScreen", the inks should not change anymore.

ld hl,#b7f9    ; SCR Event Block: Set Inks
call #bcdd    ; Call KL DEL FRAME FLY


And logically you'll be able to also keep your DI/EI where they are.

Best.

Tronic/GPA
https://rasmlive.amstrad.info/
like
0
No reactions

Offline Cwiiis

  • CPC664
  • ***
  • Posts: 127
  • Country: gb
    • Blog
    • Awards
Re: Problem setting Plus palette colours
« Reply #4 on: 23:18, 11 August 21 »
Thanks tronic, that's exactly what I needed :) I'm not sure what 'mn' means in the description of KL DEL FRAME FLY, but I understand what it does at least!
like
0
No reactions