News:

Printed Amstrad Addict magazine announced, check it out here!

Main Menu

Questions about cart development

Started by Curlypaul, 12:57, 05 June 22

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Curlypaul

Hey, I've been toying with my new(ish)ly required GX4000 and trying to assemble a cart image. So far I've learned that LDIR doesn't work when trying to draw to the screen area, as I've an (empty) cart rom mapped there. Is there a documented to disable a rom given I'm on a GX4000 and don't have any firmware?

My main question is around the rastor interupt though, so far I've been following the example here: https://cpctech.cpc-live.com/source/cart.html but I'm having some issues with the #0038 interrupt, as rather than reading the EI/RET value that the code writes there in ram, it reads a line from the rom and executes that, generating confusion .

I could arrange the file so that the correct code is at #0038 but I'd prefer understand why the example doesn't work for me, I looked at some of the converted 464 games, and they didn't seem to be using im1, but I suppose I'm really asking for pointers on the usefulness of being about to write to the ram that normally sits at the address that a rom is currently mapped to.

For simplicity, my code, which is pretty just the example from cpctech with RASM headers and some visisble bytes.
 

;; This example shows a suggested startup for a cartridge

;; cartridge page 0 exists at #0000-#3fff
;; execution starts at #0000
;;
BUILDCRT
BANK 0
ORG #0000

start:
breakpoint
di ;; disable interrupts
im 1 ;; set interrupt mode 1
ld sp,#bfff
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


;; Fill the screen so we can see if we got this far
ld a,15
ld e,#47
ld bc,#7F00
out (c),a ;; PENR:#7F{pp} - where pp is the palette/pen number
out (c),e ;; INKR:#7F{hc} - where hc is the hardware colour number


ld b,#100
ld hl,#C000
ld a,%11111111
fill
ld (hl),a
inc hl
djnz fill

;; 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

 

pelrun

LDIR will definitely work, it just depends what you expect to happen. The upper bank has both rom and ram mapped separately; writes will always go to the ram, and reads will come from either the ram or the rom depending on whether the upper rom is enabled or not.

Curlypaul

Quote from: pelrun on 14:14, 05 June 22LDIR will definitely work, it just depends what you expect to happen. The upper bank has both rom and ram mapped separately; writes will always go to the ram, and reads will come from either the ram or the rom depending on whether the upper rom is enabled or not.
True, it's more accurate to say it didn't work the way I expected it to :)

Is there a way to disable the rom without the firmware? Say if I wanted to read from vram to OR the values

andycadley

Writes will always go to RAM. What has probably happened is that you haven't set up the CRTC with appropriate values to have a stable screen, located in your expected position in RAM.

One of the first lessons of cart development is that the system has literally done nothing at all to configure the hardware, so you basically have to do everything yourself. It's not like something that is launched from BASIC, which will already have configured a 40*25 screen, centered in the monitor using RAM from &c000 etc

andycadley

Quote from: Curlypaul on 16:18, 05 June 22Is there a way to disable the rom without the firmware? Say if I wanted to read from vram to OR the values
You just write to the paging register manually. 

Curlypaul

Quote from: andycadley on 16:19, 05 June 22
Quote from: Curlypaul on 16:18, 05 June 22Is there a way to disable the rom without the firmware? Say if I wanted to read from vram to OR the values
You just write to the paging register manually.
Thank you, that gives me enough to find the correct things to read up on.

So is my original example just incorrect? I know the CRTC reads directly from ram and ignores the rom and active ram banks, but the interrupt will always just read from #0038 and therefore get the ROM?

My simple example works as expected now that I've made sure that the ROM contains a reasonable handler

andycadley

Yeah, the interrupt should go to ROM since the machine always starts with the lower ROM enabled and Z80 reads always use paged in ROM rather than RAM.

The rest might be right, I haven't had chance to check it all properly as I'm moving house this weekend and so a bit rushed around.  :laugh:

Have fun cart programming. The GX hardware is lovely when you start playing with it properly.

Curlypaul

Good luck with the move, and thanks for taking the time to help me  :D 

There's def an error in the og example then, and on top of that I've confused myself quite a lot but I think I'm on my way again

Powered by SMFPacks Menu Editor Mod