News:

Printed Amstrad Addict magazine announced, check it out here!

Main Menu

create good cpr for gx4000

Started by dub, 08:46, 23 September 16

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

roudoudou

Quote from: TotO on 19:12, 23 January 23There is a probability that you turn on the X-MEM and run an amazing DOOM game that nobody has programmed.
Maybe the board had an orgams ?
My pronouns are RASM and ACE

siudym

I cleared C000-FFFF and now ARNOLD doesn't show garbage in the background. But I don't know why, but the yellow background color sets me to light blue/green. No matter what color I set, WinAPE displays it correctly and ARNOLD displays light blue/green.


andycadley

Did you fix your palette selecting code?

As I mentioned on the previous page, the Plus palette registers are memory mapped rather than IO mapped, so you should be writing to them using LD rather than OUT (you can do it the old way but it limits you to the original 27 colours so I wouldn't if I were you).

siudym

I changed and now I have Border Black, Background Color Green - instead of Blue Border and Yellow BGR :/


LD A,$55
LD HL,$7F10 ; Border Blue.
LD (HL),A

LD A,$4A
LD HL,$6400 ; BGR Yellow.
LD (HL),A

;LD A,$55                                                  ; Same
;LD ($7F10),A ; Border Blue.
;
;LD A,$4A
;LD ($6400),A ; BGR Yellow.

LD A,$5C
LD HL,$6401
LD (HL),A

LD A,$56
LD HL,$6402
LD (HL),A

LD A,$4B
LD HL,$6403
LD (HL),A

LD A,$56 ; Kolor 4 - Green.
LD HL,$6404
LD (HL),A

LD A,$5E ; Kolor 5 - .
LD HL,$6405
LD (HL),A

LD A,$40 ; Kolor 6 - .
LD HL,$6406
LD (HL),A

LD A,$4E ; Kolor 7 - .
LD HL,$6407
LD (HL),A

LD A,$5D ; Kolor 8 - .
LD HL,$6408
LD (HL),A

LD A,$5C ; Kolor 9 - .
LD HL,$6409
LD (HL),A

LD A,$52 ; Kolor 10 - .
LD HL,$640A
LD (HL),A

LD A,$53 ; Kolor 11 - .
LD HL,$640B
LD (HL),A

LD A,$59 ; Kolor 12 - .
LD HL,$640C
LD (HL),A

LD A,$47 ; Kolor 13 - Pink.
LD HL,$640D
LD (HL),A

LD A,$4F ; Kolor 14 - Pastel Magenta.
LD HL,$640E
LD (HL),A

LD A,$5B ; Kolor 15 - Pastel Cyan.
LD HL,$640F
LD (HL),A

andycadley

#54
Each colour register is two bytes long, because you have 4-bits of R, 4-bits of G and 4-bits B. The first byte of each register is R in the high bits and B in the low bits, the second is G in the low bits. So:

LD HL, &6400
LD A, &2F
LD (HL), A
INC L
LD A,&07
LD (HL),A

Will set PEN 0 to have an RGB value of &2F7

Pen 1 starts at &6402 and so on up to the border at &6420. This is then followed by the sprite colours in the same format.

roudoudou

you can also use 16 bits write instruction

LD HL,#123 ; xGRB
LD (#6420),HL

@andy palette is from #6400 to #643F
My pronouns are RASM and ACE

siudym

#56
OK, now everything is clear, the colors work in both WinApe and Arnold.

LD HL,$000F ; xGRB Border max BLUE.
LD ($6420),HL

LD HL,$00F0 ; xGRB BGR 0 max RED.
LD ($6400),HL

LD HL,$0F00 ; xGRB BGR 1 max GREEN.
LD ($6402),HL

(...)

$6422+ = Sprite PAL.

siudym

I would like to know how to set the size of the visible screen. Is it possible to change the screen from 640x200 to e.g. 512x200? I understand that there is no concept of "character" but let's say if I have a default size of visible "characters" in MODE2 in 80x25, change it to 64x25? So that the visible number of pixels horizontally change from 640 (80x8pix) to 512 (64x8pix) in mode2.

andycadley

#58
For that, you want the CRTC. https://www.cpcwiki.eu/index.php/CRTC

"Characters" as far as the CRTC are concerned are effectively 2 bytes of screen data horizontally, so it's like working with MODE 1 sized characters. So you'd set the width to 32 and the height to 25 to get what you're after. And then probably fiddle the position of the screen to recentre it.

andycadley

To update the CRTC, first you select a register by OUTing to port BCxx, then send data to that register by OUTing to BDxx:

LD BC,&BC01; BCxx = Register Select
OUT (C), C : Select CRTC register 1
LD A, 32
INC B; BDxx = write data 
OUT (C), A; Set screen width to 64 bytes

DEC B
LD A,6
OUT (C), A; Select CRTC register 6
INC B
LD A, 25
OUT (C), A ; Set screen height to 25 chars

siudym

I don't know what happened or I did something wrong, but suddenly when I try to check the code under winape and arnold, the background color is downloaded depending on the emulator from a different address...  :-X
I have WinApe background color from $6400, while Arnold uses it from $641E ....

GUNHED

One is for colors, one is for sprites iirc.
http://futureos.de --> Get the revolutionary FutureOS (Update: 2023.11.30)
http://futureos.cpc-live.com/files/LambdaSpeak_RSX_by_TFM.zip --> Get the RSX-ROM for LambdaSpeak :-) (Updated: 2021.12.26)

andycadley

$641E/1F is PEN 15. So either something is wrong with the code to clear the screen or you've changed something in the colour changing code that's broken something, I suspect. 

siudym

sample code: winape yellow bgr (pen 0), on arnold red bgr (pen 15)

;------------------------------------------------

    ORG $0000

    JP Start

;------------------------------------------------

    ORG $0038
    EI
    RET

;------------------------------------------------

Start:

LD A,$00
LD ($C000),A

LD HL,$C000 ; clear screen
LD DE,$C001
LD BC,$3FF0
LDIR

    DI                            ; Disable Interrupts.
    IM 1                            ; Set interrupt Mode 1.

    LD BC,$F782                        ; Setup initial PPI port directions.
    OUT (C),C

    LD BC,$F400                        ; Set initial PPI port A (AY).
    OUT (C),C

    LD BC,$F600                        ; Set initial PPI port C (AY direction).
    OUT (C),C

    LD BC,$7FC0                        ; Set initial RAM configuration.
    OUT (C),C

;------------------------------------------------

    LD B,$BC                        ; Unlock ASIC so we can access ASIC registers.
    LD HL,Sequence

    LD E,17
Seq:

    LD A,(HL)
    OUT (C),A
    INC HL
    DEC E
    JR NZ,Seq

;------------------------------------------------
; Setup Sprite Pixel Data.
; The ASIC has internal "RAM" used to store the sprite pixel data.
; If you want to change the pixel data for a sprite then you need to copy new data into the internal "RAM".
; Page-in asic registers to $4000-$7FFF.
;------------------------------------------------

    LD BC,$7FB8
    OUT (C),C

    LD HL,Sprite_Pixel_Data                    ; Stored Sprite Pixel Data.

    LD DE,$4000                        ; Address of Sprite 0 pixel data, Sprite 0 pixel data is in the range $4000-$4100.

    LD BC,$100                        ; Length of pixel data for a single Sprite (16x16 = 256).
    LDIR

    LD BC,$7FA0                        ; Page-out ASIC Registers.
    OUT (C),C

;------------------------------------------------
; Setup Sprite Palette.
; The Sprites use a single 15 entry Sprite palette.
; Pen 0 is ALWAYS transparent.
; The Sprite palette is different to the screen palette.
;------------------------------------------------

    LD BC,$7FB8                        ; Page-in ASIC registers to $4000-$7FFF.
    OUT (C),C

    LD HL,Background_Colours
    LD DE,$6400
    LD BC,$22
    LDIR

    LD HL,Sprite_Colours                    ; Copy colours into ASIC sprite palette registers.
    LD DE,$6422
    LD BC,$20
    LDIR

    LD BC,$7FA0                        ; Page-out ASIC registers.
    OUT (C),C

;------------------------------------------------
; Setup Sprite Properties.
; Each sprite has properties which define the x,y coordinates and x,y magnification.
;------------------------------------------------

    LD BC,$7FB8                        ; Page-in ASIC registers to $4000-$7FFF.
    OUT (C),C

    LD HL,0080                        ; Set x coordinate for Sprite 0.
    LD ($6000),HL

    LD HL,0080                        ; Set y coordinate for Sprite 0.
    LD ($6002),HL

    LD A,%1111                        ; Set Sprite x and y magnification, x magnification = 1, y magnification = 1.
    LD ($6004),A                        ; LD A,%1010 zwiekszy 2x X/Y Sprite, natomiast %1111 zwiekszy 4x X/Y

    LD BC,$7FA0                        ; Page-out ASIC registers.
    OUT (C),C

;------------------------------------------------

    LD HL,CRTC_Data_end                    ; Set initial CRTC settings (screen dimensions etc).
    LD BC,$BC0F

CRTC_Loop:

    OUT (C),C
    DEC HL
    LD A,(HL)
    INC B
    OUT (C),A
    DEC B
    DEC C
    JP P,CRTC_Loop

;------------------------------------------------

    LD HL,$C9FB
    LD ($0038),HL

LD SP,$8000 ;  Set the Stack.

LD HL,$C9FB
LD ($8000),HL
EI

    LD BC,$7FB8                        ; Enable ASIC Ram (will be visible in range $4000-$7FFF).
    OUT (C),C

;------------------------------------------------

    LD A,%11111111                        ; Little square...
    LD ($C000),A
    LD A,%11111111
    LD ($C800),A
    LD A,%11111111
    LD ($D000),A
    LD A,%11111111
    LD ($D800),A
    LD A,%11111111
    LD ($E000),A
    LD A,%11111111
    LD ($E800),A
    LD A,%11111111
    LD ($F000),A
    LD A,%11111111
    LD ($F800),A

;------------------------------------------------

Forever:

    JR Forever

;------------------------------------------------

CRTC_Data:                            ; Your crtc setup values her ; these are examples

    DEFB $3f, $28, $2e, $8e, $26, $00, $19, $1e, $00, $07, $00,$00,$30,$00,$c0,$00

CRTC_Data_end:

;------------------------------------------------

Background_Colours: ; 16+1 color

DEFW $0FF0 ; xGRB Kolor 00 - Yellow ($6400).
DEFW $0FFF ; xGRB Kolor 01 - Bright White (255/255/255).
DEFW $0F00 ; xGRB Kolor 02 - MAX GREEN.
DEFW $0111 ; xGRB Kolor 03 -
DEFW $0111 ; xGRB Kolor 04 -
DEFW $0111 ; xGRB Kolor 05 -
DEFW $0111 ; xGRB Kolor 06 -
DEFW $0111 ; xGRB Kolor 07 -
DEFW $0111 ; xGRB Kolor 08
DEFW $0111 ; xGRB Kolor 09 -
DEFW $0111 ; xGRB Kolor 10 -
DEFW $0111 ; xGRB Kolor 11 -
DEFW $0111 ; xGRB Kolor 12 -
DEFW $0111 ; xGRB Kolor 13 -
DEFW $0111 ; xGRB Kolor 14 -
DEFW $00F0 ; xGRB Kolor 15 - MAX RED (ARNOLD BACKGROUND COLOR)...
DEFW $000F ; BORDER ($6420) - MAX Blue.

;------------------------------------------------

Sprite_Colours:

    DEFW $0000                       ; Colour for Sprite Pen 00.
    DEFW $0111                        ; Colour for Sprite Pen 01.
    DEFW $0222                        ; Colour for Sprite Pen 02.
    DEFW $0333                        ; Colour for Sprite Pen 03.
    DEFW $0444                        ; Colour for Sprite Pen 04.
    DEFW $0555                        ; Colour for Sprite Pen 05.
    DEFW $0666                        ; Colour for Sprite Pen 06.
    DEFW $0777                        ; Colour for Sprite Pen 07.
    DEFW $0888                        ; Colour for Sprite Pen 08.
    DEFW $0999                        ; Colour for Sprite Pen 09.
    DEFW $0AAA                        ; Colour for Sprite Pen 10.
    DEFW $0BBB                        ; Colour for Sprite Pen 11.
    DEFW $0CCC                        ; Colour for Sprite Pen 12.
    DEFW $0DDD                        ; Colour for Sprite Pen 13.
    DEFW $0EEE                        ; Colour for Sprite Pen 14.
    DEFW $0FFF                        ; Colour for Sprite Pen 15.

;------------------------------------------------

Sprite_Pixel_Data:

    DEFB $01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01        ; Line 00.
    DEFB $01,$01,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$01,$01        ; Line 01.
    DEFB $01,$00,$02,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$02,$00,$01        ; Line 02.
    DEFB $01,$00,$00,$03,$00,$00,$00,$00,$00,$00,$00,$00,$03,$00,$00,$01        ; Line 03.
    DEFB $01,$00,$00,$00,$04,$00,$00,$00,$00,$00,$00,$04,$00,$00,$00,$01        ; Line 04.
    DEFB $01,$00,$00,$00,$00,$05,$00,$00,$00,$00,$05,$00,$00,$00,$00,$01        ; Line 05.
    DEFB $01,$00,$00,$00,$00,$00,$06,$00,$00,$06,$00,$00,$00,$00,$00,$01        ; Line 06.
    DEFB $01,$00,$00,$00,$00,$00,$00,$07,$07,$00,$00,$00,$00,$00,$00,$01        ; Line 07.
    DEFB $01,$00,$00,$00,$00,$00,$00,$08,$08,$00,$00,$00,$00,$00,$00,$01        ; Line 08.
    DEFB $01,$00,$00,$00,$00,$00,$09,$00,$00,$09,$00,$00,$00,$00,$00,$01        ; Line 09.
    DEFB $01,$00,$00,$00,$00,$0A,$00,$00,$00,$00,$0A,$00,$00,$00,$00,$01        ; Line 10.
    DEFB $01,$00,$00,$00,$0B,$00,$00,$00,$00,$00,$00,$0B,$00,$00,$00,$01        ; Line 11.
    DEFB $01,$00,$00,$0C,$00,$00,$00,$00,$00,$00,$00,$00,$0C,$00,$00,$01        ; Line 12.
    DEFB $01,$00,$0D,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$0D,$00,$01        ; Line 13.
    DEFB $01,$0E,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$0E,$01        ; Line 14.
    DEFB $01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01,$01        ; Line 15.


;------------------------------------------------

Sequence:                            ; Sequence to unlock ASIC.

    DEFB $ff,$00,$ff,$77,$b3,$51,$a8,$d4,$62,$39,$9c,$46,$2b,$15,$8a,$cd,$ee

    ORG $3FFF
    DEFB $00

    END

andycadley

I can't see it with a quick skim. I assume everything else still works? Sprites displayed etc? I.e. you haven't accidentally switched Arnold over to emulating a non-Plus CPC?

siudym

Everything seems ok in the emulator settings.

roudoudou

#66
you cannot use LDIR "inside" the Asic, at least for colors because only green bits will be copied in blue/red
the 4 upper bits will be zeroed, as this is not a byte of memory, but an Asic register containing only 4 low bits
take a look at the source i posted some posts before
every init are done with stack (PUSH, PUSH, PUSH) or LD (HL),A : INC HL ... without reading a value to write it further
https://www.cpcwiki.eu/forum/programming/create-good-cpr-for-gx4000/msg224549/#msg224549

My pronouns are RASM and ACE

siudym

I found Sprtes code on cpcwiki:
https://www.cpcwiki.eu/index.php/Programming:CPC_Plus_Hardware_Sprites

So is there an error?


;; page-in asic registers to &4000-&7fff
ld bc,&7fb8
out (c),c

;; copy colours into ASIC sprite palette registers
ld hl,sprite_colours
ld de,&6422
ld bc,15*2
ldir

;; page-out asic registers
ld bc,&7fa0
out (c),c


roudoudou

#68
oups, sorry, i've read too fast

you can copy from memory to Asic with an LDIR

but you cant (it's not recommended i mean) zero Asic values with a LDIR (source & destination inside Asic mapping) because some addresses cant be fully read
My pronouns are RASM and ACE

siudym

#69
The ASIC has its own built-in 16KB RAM? Any interference requires switching the 4000-7FFF range to its internal RAM?

roudoudou

He surely have RAM (for sprites) but when reading in Asic memory-range, you do not read RAM. You read what Asic wants you to read, it's something else
As pixels of sprite are 4 bits only, you cannot assume you will have 0 or #F in the 4 upper bits
But you can write #FF in a sprite pixel because only 4 lower bits will be taken into account
some asic registers cannot be read back, they are write only (but winape will let you do such things...)
My pronouns are RASM and ACE

siudym

So it works by "mapping" certain cpu addresses into the internal RAM built into the ASIC? Doesn't replace the whole 4000-7FFF with "your" RAM?

andycadley

People use the phrase "ASIC RAM" unfortunately, because it's all memory mapped but there isn't really any RAM involved.

Paging the ASIC in just assigns the address space from $4000 to $7FFF to the ASICs registers. Some registers are duplicated (because they only partially decode the address bus), some are read/write. While the ASIC is paged in nothing should write to RAM in this address space (although using a non-compatible RAM expansion can cause issues if banked RAM is paged in when the ASIC is paged in)

andycadley

#73
Ah, I bet it'll be this bit:

LD A,$00
LD ($C000),A

LD HL,$C000 ; clear screen
LD DE,$C001
LD BC,$3FF0
LDIR


When you switch the CPC on, the Upper and Lower ROMs are paged in, but your cart only has a single 16K ROM so the upper ROM is effectively missing. I'll hazard a guess that WinAPE is treating that as a ROM full of 0's and Arnold (or RVM which I tried it in) is treating it as FFs (I suspect this is the correct value, but I'm not 100% on that).

So why does it break your code? Well when a ROM is paged in, reads come from the ROM by writes go to the RAM underneath. Using LDIR to block clear RAM like that doesn't work in that case, because instead of copying the RAM values, it's copying the ROM values instead. You could either turn the upper ROM off first (since you don't need it paged in) or just write a standard loop to iterate over the address range and write 0 to every byte.

roudoudou

when booting CPR, with any number of ROM, the ROM 0 is mapped both LOW and HIGH :) (even with a 16K cartridge)
My pronouns are RASM and ACE

Powered by SMFPacks Menu Editor Mod