Log inRegister an accountBrowse CSDbHelp & documentationFacts & StatisticsThe forumsAvailable RSS-feeds on CSDbSupport CSDb Commodore 64 Scene Database
 Welcome to our latest new user Gabezcommodore ! (Registered 2025-07-24) You are not logged in - nap
CSDb User Forums


Forums > C64 Coding > How to correctly use KERNAL routines from a cartridge?
2013-03-22 21:45
Paulko64

Registered: Jul 2010
Posts: 24
How to correctly use KERNAL routines from a cartridge?

Hi there,

The last couple of days I've been struggling heavily to get the Kernal SCNKEY routine to work correctly when called from a cartridge build. I think I maybe missed something crucial in the memory init or something, but I can't figure out what I'm doing wrong. Perhaps somebody here can help me.

My cartridge starts with:
		.word launcher
		.word launcher
		.byte $c3 ;c
		.byte $c2 ;b
		.byte $cd ;m
		.byte $38 ;8
		.byte $30 ;0

launcher	sei
		cld
		ldx #$ff
		txs
		jsr $ff84	;init I/O
		ldx #$17
		lda #$00
lp1		sta $d400,x	;clear SID registers
		dex
		bpl lp1
		tay		;(A still contains zero)
lp2		sta $0002,y
		sta $0200,y
		sta $0300,y	;clear a bunch of low-memory locations
		iny
		bne lp2
		tax
		ldy #$a0
		jsr $fd8c	;init system constants (without the ram-test)
		jsr $ff8a	;restore kernal vectors
		jsr $ff81	;init screen editor
		cli
		ldx #$fb
		txs

Then I copy all my code to RAM, disable the cartridge, and start my game from RAM. The above is enough to get my game running. However, when I try to access the kernal with the following part, it does not register any keys pressed:
		lda #%00110110                  ;enable kernal
                sta $01
		jsr SCNKEY			;read keyboard
		lda #%00110101                  ;disable kernal
                sta $01

It should put the current key pressed in $0277, but there is nothing there. When starting the SAME build from the prompt, i.e. without copying first from cartridge it works correctly!
I already checked that all relevant ZP and $02XX adresses are set correctly. So I'm kind of lost here, maybe someone has some ideas?

Thanks,

Paul
 
... 10 posts hidden. Click here to view all posts....
 
2013-04-01 20:27
Pex Mahoney Tufvesson

Registered: Sep 2003
Posts: 54
Your slideshow is awesome, simply awesome! Congratulations on a world's first in 2013! This is one for the history books! :-D

---
Have a noise night!
http://mahoney.c64.org
2013-04-01 20:31
tlr

Registered: Sep 2003
Posts: 1822
Hehe, thanks! :)
I'm sure something more radical could be done with similar techniques.
2013-04-01 20:32
Zyron

Registered: Jan 2002
Posts: 2381
So much new amazing things still happening in the world of c64 coding it's insane!
2013-04-02 08:05
Mr. SID

Registered: Jan 2003
Posts: 425
Awesome idea!
2013-04-02 17:36
tlr

Registered: Sep 2003
Posts: 1822
@mahoney: Perhaps you should try to define your original rules a bit more stringenly?
It would be fun to try to do something more flexible. :)

Your original rules aren't too bad as is actually. Executing BASIC code is actually implicitly disallowed via the code execution restriction because it relies on executing CHRGET/CHRGOT at $0073 in zp.

The main thing that is unclear is what piece of RAM you may modify.
You could say $0000-$0400 but that is a bit harsh restriction on e.g screen mem.
You could say that ROM, e.g $ffd2, may modify RAM outside $0000-$0400 but that is kind of pointless because all code executed is ROM code.

How about allowing read/write to all RAM?

If the $0000-$0400 RAM write restriction is to be kept, can the initial LOAD still load any amount of RAM?
Previous - 1 | 2 - Next
RefreshSubscribe to this thread:

You need to be logged in to post in the forum.

Search the forum:
Search   for   in  
All times are CET.
Search CSDb
Advanced
Users Online
Knut Clausen/SHAPE/F..
Slummy/Spaceballs
Didi/Laxity
t0m3000/bo0M!^hf^ibex
Guests online: 66
Top Demos
1 Next Level  (9.7)
2 13:37  (9.7)
3 Codeboys & Endians  (9.7)
4 Mojo  (9.7)
5 Coma Light 13  (9.6)
6 Harminc  (9.6)
7 Edge of Disgrace  (9.6)
8 Comaland 100%  (9.6)
9 Wonderland XIV  (9.6)
10 Signal Carnival  (9.6)
Top onefile Demos
1 Morphing Starball  (9.9)
2 Nine  (9.8)
3 Layers  (9.6)
4 Cubic Dream  (9.6)
5 Party Elk 2  (9.6)
6 Copper Booze  (9.5)
7 Scan and Spin  (9.5)
8 Onscreen 5k  (9.5)
9 Grey  (9.5)
10 Dawnfall V1.1  (9.5)
Top Groups
1 Performers  (9.3)
2 Booze Design  (9.3)
3 Censor Design  (9.3)
4 Oxyron  (9.3)
5 Artline Designs  (9.3)
Top Logo Graphicians
1 t0m3000  (10)
2 Sander  (9.8)
3 Shine  (9.5)
4 Mermaid  (9.5)
5 Pal  (9.4)

Home - Disclaimer
Copyright © No Name 2001-2025
Page generated in: 0.033 sec.