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.

dub

Hi, I want to initialize the gx4000 for my cpc+ game.

It's working on cpc+ format disk but not cpr.

Arnoldemu give met his code to initialize the gx4000 but I can't make it works.
Unofficial Amstrad WWW Resource
;; This example shows a suggested startup for a cartridge

;; cartridge page 0 exists at &0000-&3fff
;; execution starts at &0000
;;
org &0000

start:

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

;; unlock ASIC so we can access ASIC registers
ld b,&bc
ld hl,sequence
ld e,17
seq:
ld a,(hl)
out (c),a
inc hl
dec e
jr nz,seq

;; set initial CRTC settings (screen dimensions etc)
ld hl,end_crtc_data
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
ei

;; enable asic ram (will be visible in range &4000-&7fff)
ld bc,&7fb8
out (c),c

;; your code here
loop:


jr loop

;; your crtc setup values here; these are examples
crtc_data:
defb &3f, &28, &2e, &8e, &26, &00, &19, &1e, &00, &07, &00,&00,&30,&00,&c0,&00
end_crtc_data:

;; sequence to unlock asic
sequence:
defb &ff,&00,&ff,&77,&b3,&51,&a8,&d4,&62,&39,&9c,&46,&2b,&15,&8a,&cd,&ee

end

What am I doing :

I add this little code in the loop: for adding color border, just for testing
LD        BC,#7F10
OUT      (C),C
LD        A,76
OUT      (C),A


I use winape for testing. And I have a black screen when I launch the cartridge.
If I launch an other cartridge before, and lauch my cartridge, I have red border.

I use two way for testing :

Directly in winape with a :
WRITE DIRECT 0,-1,&C0

or with the software cprtools after making the bin in winape with a : WRITE "cart.bin"

I certainly doing something wrong.


arnoldemu

Ok there is a bug in the code. Sorry my mistake.

The EI is enabling the interrupts and the default interrupt for im 1 is 0038.

Change it to this:


org &0000
jp start
org &0038
ei
ret
start:

di ;; disable interrupts
im 1 ;; set interrupt mode 1
ld bc,&f782 ;; setup initial PPI port directions.
.
.
.


and it'll work better.

You should change the mainloop and things to call your code.
You can copy your code into ram, disable the roms and then take over the hardware :)


My games. My Games
My website with coding examples: Unofficial Amstrad WWW Resource

Xifos

dub, it 's great to see you coding on the gx/cpc+ !
:)
Thanks for helping him, arnoldemu !
;)

dub

Thanks, I'll try this and make a test on gx4000

@Xifos : I'm just beginning, I need to rise my knowledge of the specificity of the hardware.  After I'll try to make a little game.

dub

I "almost" succeeded  ;D

On the winape emulator, I have a good red border and my sprite. But on gx4000, I think I need to erase the ram before sending my data, as the picture show.

When I'll have a clear start, I'll begin my game dev.


The orange on the photo is red on my TV  :P

Xifos

Well done !

And you are right, you need to clear memory.

The border is smaller on a tv ?
I did not know...

arnoldemu

Quote from: dub on 10:11, 24 September 16
I "almost" succeeded  ;D

On the winape emulator, I have a good red border and my sprite. But on gx4000, I think I need to erase the ram before sending my data, as the picture show.

When I'll have a clear start, I'll begin my game dev.


The orange on the photo is red on my TV  :P
Good that you test on a real gx4000. Always do that. :)

You can also test on my emulator if you want.
Unofficial Amstrad WWW Resource


You should assume hardware is not initialised and that you need to initialise it and clear the ram you want to use then you will have much more consistent and better results.

When testing with C4CPC you can do two things:
- connect PC to C4CPC with usb cable and run the cart direct on the C4CPC avoiding menu
- put the cpr into it's own slot and boot into that slot (select with dip switches).

If you use the menu it's possible some hardware will be initialised and you need to test it as close to "original" power on state.

:)
My games. My Games
My website with coding examples: Unofficial Amstrad WWW Resource

arnoldemu

Quote from: Xifos on 11:21, 24 September 16
Well done !

And you are right, you need to clear memory.

The border is smaller on a tv ?
I did not know...
Border can be smaller or larger on CRT tv and it really depends on the television.

When developing for Wii or older consoles that can use use CRT there were instructions to tell us not to put HUD too close to the edges of the screen. (I think the "safe area" was 80% of the display).

The border should be almost the same on LCD televisions.


My games. My Games
My website with coding examples: Unofficial Amstrad WWW Resource

gerald

Quote from: Xifos on 11:21, 24 September 16
The border is smaller on a tv ?
If you can properly read the C4CPC logo on the screen, that mean the CRCT is still configured for the cartridge selector : ie overscan.
That's why the border is so small.

dub

Thanks
I'm used to deal with the safe area when I'm working on raspberry pi or with my 800xl.

I try try my cpr on his own slot (c4cpc) and I have only black on screen with bad frequency (or like bad screen refresh rate).
I try your emulator too and that's doesn't work. I have black left border and some color on top of the screen :  cf screenshot  :(

I continue my investigation   ;D

arnoldemu

Try this instead:

Unofficial Amstrad WWW Resource

There are some examples here that may help. They are better tested. My code here must be old and not working fully.

"single": Good for single files to be executed from ram.
The boot program copies the code into ram and executes it. You still need to initialise the h/w. Look at the example.

"fs": The cart is treated like a read only filesystem.
You can read and write files as you need in your program. See the example. This is much easier if your used to disks and loading files. It's similar to how a lot of C64 carts work.

"absolute": You take control over each 16KB cart page so you need to manage both your code and your data to work with it.

Maybe it is better to work with these?

You can freely use this code in your own game. I would like a credit if you use it please.
My games. My Games
My website with coding examples: Unofficial Amstrad WWW Resource

dub

I'm cursed or what ?  ;D

I try the arnoldemulator and the "single" example for beginning. And I had weird results.

I use the make.bat with pasmo for Windows. Everything compil. I've just add my code to see red border.
I launch arnold emu with the gx4000 configuration as you can see on the screenshot. And When I launch the cart, I have left black border and two color lines on the top.

I try my my_cart.bin and the cpr with the cprtools.

If I insert my_cart.cpr on winape emulator, I have the game working : red border and flashing in screen. (On the bottom of my screenshot).
But I need to compiling with pasmo and after use the crptools gui. Lot of manipulation.

Xifos

What does cprtools ?

Transform a bin file into a cpr file ?

Kris

Quote from: Xifos on 17:46, 25 September 16
What does cprtools ?

Transform a bin file into a cpr file ?


Exactly, in both way bin => CPR or CPR=> bin

siudym

Is there any information about switching banks in the GX4000 cartridge? Some examples in ASM. How does the Bank Switch work in GX - are $0000-3FFF (Lower) and $C000-FFFF (upper) switched independently or, for example, $0000 as a fixed bank and $C000 is switched?

asertus

Quote from: siudym on 19:27, 06 January 23Is there any information about switching banks in the GX4000 cartridge? Some examples in ASM. How does the Bank Switch work in GX - are $0000-3FFF (Lower) and $C000-FFFF (upper) switched independently or, for example, $0000 as a fixed bank and $C000 is switched?

@reidrac has written about that.

https://www.usebox.net/jjm/blog/cpc-cartridges-bank-switching/

andycadley

The bank's can be switched independently. Any of the first 8 cartridge pages can be mapped using RMR2 and this can map to address 0000, 4000h or 8000h

Separately, the upper ROM mapping can be used to put any of the 32 cartridge pages into the memory at C000h (it could even be the same page, if desired). These are mapped using the old RMR register of the gate array, but with ROM numbers of 128 to 159 (7 selects the disk ROM and anything else selects ROM 0)

reidrac

Released The Return of Traxtor, Golden Tail, Magica, The Dawn of Kernel, Kitsune`s Curse, Brick Rick and Hyperdrive for the CPC.

If you like my games and want to show some appreciation, you can always buy me a coffee.

siudym

Are there any template/skeleton cartridge (pasm) code containing an example of a bank organization scheme? And how to compile it to create the proper bin ROM.

roudoudou

Quote from: siudym on 20:41, 06 January 23Are there any template/skeleton cartridge (pasm) code containing an example of a bank organization scheme? And how to compile it to create the proper bin ROM.
you can use the skeleton above with RASM, then add at the beggining

buildcpr
bank 0
<the code>

bank 1
<another code>

bank 2
<...>

up to bank 31 for a 512K cartridge

it will generate a CPR as output file
My pronouns are RASM and ACE

siudym

#20
Thanks.

Do I need to set/define the cartridge format somehow? Is the bank switch method always the same everywhere?

Unfortunately there are quite a few compilation errors.
"- PASMO" is a compatibility mode?

rasm_x64 -pasmo main.asm
Pre-processing [main.asm]
Assembling
Error: [main.asm:11] Missing operand for calculation [&0000] Did you use & for an hexadecimal value?
Error: [main.asm:14] Missing operand for calculation [&0038] Did you use & for an hexadecimal value?
Error: [main.asm:14] ORG (output at #0000) located in a previous ORG section [#0000-#0003-B0] file [main.asm] line 11
Error: [main.asm:113] Assembling overwrite [main.asm] L11 [#0000-#0003-B0] with [main.asm] L14 [#0000/#0071]
Error: [main.asm:21] expression [&F782] keyword [F782] not found in variables, labels or aliases
Error: [main.asm:21] Missing operand for calculation [&F782] Did you use & for an hexadecimal value?
Error: [main.asm:23] expression [&F400] keyword [F400] not found in variables, labels or aliases
Error: [main.asm:23] Missing operand for calculation [&F400] Did you use & for an hexadecimal value?
Error: [main.asm:25] expression [&F600] keyword [F600] not found in variables, labels or aliases
Error: [main.asm:25] Missing operand for calculation [&F600] Did you use & for an hexadecimal value?
Error: [main.asm:28] expression [&7FC0] - 7FC0 is not a valid number
Error: [main.asm:28] Missing operand for calculation [&7FC0] Did you use & for an hexadecimal value?
Error: [main.asm:32] cannot use register &BC in this context
Error: [main.asm:32] Missing operand for calculation [&BC] Did you use & for an hexadecimal value?
Error: [main.asm:44] expression [&BC0F] keyword [BC0F] not found in variables, labels or aliases
Error: [main.asm:44] Missing operand for calculation [&BC0F] Did you use & for an hexadecimal value?
Error: [main.asm:55] expression [&C9FB] keyword [C9FB] not found in variables, labels or aliases
Error: [main.asm:55] Missing operand for calculation [&C9FB] Did you use & for an hexadecimal value?
Error: [main.asm:56] Missing operand for calculation [(&0038)]
Error: Too many errors!

roudoudou

#21
you should read (quickly) the documentation (and the error messages!) ;)

"&" is used for boolean AND operator. We may keep this hexadecimal syntax using -ampersand command line option but you will miss & for AND (you can still write plain AND)

the CPR produced is 100% compatible with C4CPC and Amstrad Plus emulators

ps: and i can quickly answer to you on discord (see the doc again :p )
My pronouns are RASM and ACE

siudym

Quote from: arnoldemu on 13:11, 23 September 16org &0038
ei
ret

I'll ask just to be sure: shouldn't it be RETI instead of RET?

andycadley

Quote from: siudym on 11:38, 07 January 23
Quote from: arnoldemu on 13:11, 23 September 16org &0038
ei
ret

I'll ask just to be sure: shouldn't it be RETI instead of RET?
It doesn't matter. RETI is designed so that Z80 aware peripherals can spot it on the bus and detect the end of an interrupt routine, mostly for daisy chained devices.

None of the hardware in the CPC pays any attention to it, so it's just a slower version of RET.

siudym

I'm a total noob on Amstrad. I would like to display some text, display a simple sprite in this code.
For now, I'm trying to write Hello World but nothing comes out :)

pasmo test.asm test.bin
python mkcpr.py test.bin
pause

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

; This example shows a suggested startup for a Cartridge.
; Cartridge page 0 exists at $0000-$3FFF.
; Execution starts at $0000.

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

PrintChar EQU $BB5A

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

 ORG $0000

 JP Start

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

 ORG $0038
 EI
 RET ; Not RETI ?

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

Start:

 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

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

 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

 EI

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

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

; Your Code here...

 LD BC,$7F10 ; Kolor Border na Blue.
 OUT (C),C
 LD C,$55
 OUT (C),C

 LD BC,$6400 ; Kolor Border na Yellow.
 OUT (C),C
 LD C,$4A
 OUT (C),C

 LD HL,Message ; Jakies dziwne dziwadla sie dzieja...
 CALL PrintString

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

Forever:

; HALT

 JR Forever

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

PrintString:

 LD A,(HL) ; Print a '255' terminates String.
 CP 255
 RET Z
 INC HL
 CALL PrintChar
 JR PrintString

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

Message:

 DEFB "HELLO WORLD",255

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

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:

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

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




Powered by SMFPacks Menu Editor Mod