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


Forums > C64 Coding > KERNAL IO and the safe memory regions
2020-03-16 13:39
oziphantom

Registered: Oct 2014
Posts: 478
KERNAL IO and the safe memory regions

Does anybody have a handy dandy list of "places that need to be saved" for KERNAL drive IO on
C64
C128
C+4

I know the IDE64 docs have a 64 list.
2020-03-16 14:30
Krill

Registered: Apr 2002
Posts: 2825
Not sure if that's what you mean, but i have a list of ZP variables here that mustn't be overwritten during load.

From my loader's source (check the end of the lines, too lazy to remove the bloat now):
        .assert (loader_zp_first > STATUS) || (loader_zp_last < STATUS), error, "Loader zeropage variables cross KERNAL STATUS register at $90"
        .assert (loader_zp_first > C3PO) || (loader_zp_last < C3PO), error, "Loader zeropage variables cross KERNAL serial buffer output char buffered flag C3PO at $94"
        .assert (loader_zp_first > BSOUR) || (loader_zp_last < BSOUR), error, "Loader zeropage variables cross KERNAL serial buffer byte BSOUR at $95"

        .if PLATFORM = diskio::platform::COMMODORE_16
        .assert (loader_zp_first > LDTND) || (loader_zp_last < LDTND), error, "Loader zeropage variables cross KERNAL logical file index/open files count at $97"
        .assert (loader_zp_first > DFLTN) || (loader_zp_last < DFLTN), error, "Loader zeropage variables cross KERNAL input device variable DFLTN at $98"
        .assert (loader_zp_first > DFLTO) || (loader_zp_last < DFLTO), error, "Loader zeropage variables cross KERNAL output device variable DFLTO at $99"
        .assert (loader_zp_first > R2D2) || (loader_zp_last < R2D2), error, "Loader zeropage variables cross KERNAL serial bus EOI flag R2D2 at $a6"
        .assert (loader_zp_first > BSOUR1) || (loader_zp_last < BSOUR1), error, "Loader zeropage variables cross KERNAL serial bus shift counter BSOUR1 at $a8"
        .assert (loader_zp_first > COUNT) || (loader_zp_last < COUNT), error, "Loader zeropage variables cross KERNAL serial bus counter COUNT at $aa"
        .assert (loader_zp_first > USE4DY) || (loader_zp_last < USE4DY), error, "Loader zeropage variables cross KERNAL parallel drive state register USE4DY at $f9"
        .else; PLATFORM <> diskio::platform::COMMODORE_16
        .assert (loader_zp_first > LDTND) || (loader_zp_last < LDTND), error, "Loader zeropage variables cross KERNAL logical file index/open files count at $98"
        .assert (loader_zp_first > DFLTN) || (loader_zp_last < DFLTN), error, "Loader zeropage variables cross KERNAL input device variable DFLTN at $99"
        .assert (loader_zp_first > DFLTO) || (loader_zp_last < DFLTO), error, "Loader zeropage variables cross KERNAL output device variable DFLTO at $9a"
        .assert (loader_zp_first > R2D2) || (loader_zp_last < R2D2), error, "Loader zeropage variables cross KERNAL serial bus EOI flag R2D2 at $a3"
        .assert (loader_zp_first > BSOUR1) || (loader_zp_last < BSOUR1), error, "Loader zeropage variables cross KERNAL serial bus shift counter BSOUR1 at $a4"
        .assert (loader_zp_first > COUNT) || (loader_zp_last < COUNT), error, "Loader zeropage variables cross KERNAL serial bus counter COUNT at $a5"
        .endif; PLATFORM <> diskio::platform::COMMODORE_16
Note that C64 and C128 addresses are identical.
This list may not be complete.
2020-03-16 15:24
oziphantom

Registered: Oct 2014
Posts: 478
off the top of my head I can add
FNLEN
LA
SA
FA
FNADR
MYCH
STAL
IOPEN
ICLOSE
ILOAD
ISAVE
I guess some other Ivectors are needed

128 does move some of them. Also adds the Filename bank, load/save bank, JSRFAR,CMPFAR,STAFAR, LDAFAR routines
2020-03-16 15:48
chatGPZ

Registered: Dec 2001
Posts: 11100
- make a testprogram that uses all the function you want to use
- trace load store 2 3ff
- run the testprogram
- sort -u
- there is your list :)

(adjust range for other cbm computers)
2020-03-16 16:26
Krill

Registered: Apr 2002
Posts: 2825
What Groepaz said, then. I was only referring to the mentioned ZP addresses with regard to "same on C128". Some of the vectors aren't actually used by the ROM depending on what is called or running. Some of the mentioned variables don't need to be buffered because they're overwritten before calls. Etc. So yeah, what Groepaz said.

And as usual: what are you actually trying to do? :)
2020-03-16 17:33
oziphantom

Registered: Oct 2014
Posts: 478
load files on the C64, C128 and +4, prg and seq and not have to keep all of Kernal and 200-1000 saved in some cases as per how the machine needs it to be saved.

Basically to Expand Bucket Wars I need to "load" things(maybe save things as well). And I have a 64, 128 and +4 version to support. And maybe also a CX16 but In that case I have 512K of RAM so I can just blanket copy the "reserved" areas into one of the 8K RAM banks and be done with it ;) Also I will need to keep the vectors alive as you can't disable the KERNAL on it.
Normally on the 128, I disabled shared memory and then put my ZP and Stack in Bank 1, and save/restore the vectors. Switch ZP, stack back to bank 0, call kernal, switch back to bank 1. However since I have 64 and +4 support and I might want to use the other bank for other things, I'm going to do the save and restore route on it too.

So basically I'm going to have a
"saveIOVars" function that gets called, a custom version per machine. Then a "restoreIOVars" function that gets called, a custom version per machine.

Although at the moment I'm trying to get the codebase "save file byte by byte" example working. It write the first byte fine, then 2nd but it gives a "Drive no ready" error. The basic version works fine with the same filename...
2020-03-16 17:34
oziphantom

Registered: Oct 2014
Posts: 478
Quote: - make a testprogram that uses all the function you want to use
- trace load store 2 3ff
- run the testprogram
- sort -u
- there is your list :)

(adjust range for other cbm computers)


yeah on windows it is not so practical, luckily the VICE PDB has a script panel that lets me dump the really large pile of data into a text file.
2020-03-16 21:11
chatGPZ

Registered: Dec 2001
Posts: 11100
Quote:
on windows it is not so practical

this can be done exactly like this on windows
Quote:
uckily the VICE PDB has a script panel that lets me dump the really large pile of data into a text file

or just do the same thing right from the monitor (use a recent nightly)
2020-03-16 23:54
Bacchus

Registered: Jan 2002
Posts: 154
In the crack of Alternate Reality I just implemented a ZP swap routine. This swapped all of zero page as zpbase2 was 2 and I didn't just swap the pointers relevant for my own stuff (commented out the "stop"). ZPstore was under the dxxx block and hence the need to update 01...

swapzp: sei
lda #$34
sta $01

ldx #zpbase2

swapzp2: lda $00,x
pha
lda zpstore,x
sta $00,x
pla
sta zpstore,x
inx
// cpx #zpbase2+12
bne swapzp2

lda #$35
sta $01
rts


/Bacchus
2020-03-17 08:58
Comos

Registered: May 2004
Posts: 71
Depends which Kernal call you are acutally executing,some ZP addys can be overwritten temporarily.

Example when calling OPEN (when SETLFS and SETNAM are done before with a valid drive number @ $BA), ZP addy like $90 must be set to $00, because it's updated by OPEN ,other ZP that must be set $98=$00,$99=$00,$9A=$03 , or just call $FFE7 if some heavy ZP use is done before and these address are not relevant afterwards.
During CHKIN or CHKOUT, index tables @ $259-276 must not be tampered (if we are opening just one file,then the index table quite small), that counts also for $99 and $9a.
During CHRIN/CHROUT, the $99 & $9a still must be not tampered.
If the device is Kernal serial calls dependant, the ZP addy $02A1 must remain set to $00 during CHKIN/CHKOUT.
The vector table starting from $0314-$0333 needs to be preserved too, if you need to maintain compatability.
2020-03-17 09:19
TWW

Registered: Jul 2009
Posts: 541
If you can afford the Y-Register you shave of 7 cycle pr byte swapped and save a couple of bytes;

swapzp:
		sei
		lda #$34
		sta $01

		ldx #$02
swapzp2:
		lda $00,x
		ldy zpstore,x
		sty $00,x
		sta zpstore,x
		inx
		bne swapzp2

		lda #$35
		sta $01
		rts
2020-03-17 09:28
Krill

Registered: Apr 2002
Posts: 2825
Not sure if it's really necessary to post really trivial code that can be and was described in a few words, then show how to make it even more trivial.
2020-03-17 09:54
TWW

Registered: Jul 2009
Posts: 541
Awww… show me on the doll here where the trivial code touched you..
2020-03-17 10:18
Oswald

Registered: Apr 2002
Posts: 5017
Quote: Awww… show me on the doll here where the trivial code touched you..

ROFL!

(not funny because of what krill said or whatever, just in itself)
2020-03-17 10:39
oziphantom

Registered: Oct 2014
Posts: 478
results so far, C64 and C128 are done. +4 is being the special kooky butterfly we all hate it for...
AE/AF are modified by the "test code" and C1/2 is also used by the test code.

This does a "send command", save file, load, scratch file, save SEQ, load SEQ file.
C64 
0090 rw
0091 r
0093 rw
0094 rw
0095 rw
0098 rw
0099 rw
009a rw
009d rw
00a3 rw
00a4 rw
00a5 rw
00ac rw
00ad rw
00ae rw
00af rw
00b7 rw
00b8 rw
00b9 rw
00ba rw
00bb rw
00bc rw
00c1 rw
00c2 rw
00c3 w
00c4 w
0259 rw
0263 rw
026d rw
02a1 r
031a r
031b r
031c r
031d r
031e r
031f r
0320 r
0321 r
0322 r
0323 r
0324 r
0325 r
0326 r
0327 r
0328 r
0329 r
0330 r
0331 r
0332 r
0333 r

c128 2-138,200-3ff,800-1300

0090 rw
0091 rw
0092 rw
0093 w
0094 rw
0095 rw
0098 rw
0099 rw
009a rw
009d rw
009e w
009f rw
00a0 r
00a1 r
00a2 rw
00a3 rw
00a5 rw
00ac rw
00ad rw
00ae rw
00af rw
00b7 rw
00b8 rw
00b9 rw
00ba rw
00bb rw
00bc rw
00c0 w
00c1 rw
00c2 rw
00c3 w
00c4 w
00c6 r
00c7 r
00d3 w
00d4 rw
00d5 w
00d7 r
00d8 r
00d9 r
00e0 r
00e1 r
00e2 rw
00e3 rw
00ec r
00f1 r
02aa w
0314 r
0315 r
031a r
031b r
031c r
031d r
031e r
031f r
0320 r
0321 r
0322 r
0323 r
0324 r
0325 r
0326 r
0327 r
0328 r
0329 r
0330 r
0331 r
0332 r
0333 r
0362 rw
036c rw
0376 rw
08a9 r
09a9 r
0a03 r
0a04 r
0a0f r
0a1c rw
0a1d rw
0a25 rw
0a26 rw
0a27 r
0a28 rw
0a29 rw
0a2a rw
0a2c r
0a35 rw
0a36 rw
0a37 rw
0a38 rw
0a3a r
10a9 r
11d6 r
11d7 r
11d8 r
11d9 r
11da r
11db r
11dc r
11dd r
11de r
11df r
11e0 r
11e1 r
11e2 r
11e3 r
11e4 r
11e5 r
11e6 r
1224 r
1226 r
1228 r
1285 r
1286 r
1287 r
12fd rw

although the 128 doesn't show any executes for the 02a2-02fb range.. the 02aa shows that FETCH 02a2 was used.
The 128 also seems to have some IRQ values dirtying it.
2020-03-17 13:17
oziphantom

Registered: Oct 2014
Posts: 478
so when the Vice docs in the emulator say trace does load store exec by default, what it means is load store by default ;)

Correct C128 values
0090 wr
0091 wr
0092 wr
0093 wr
0094 wr
0095 wr
0098 wr
0099 wr
009a wr
009d wr
009e wr
009f wr
00a3 wr
00a5 wr
00ac wr
00ad wr
00ae wr
00af wr
00b7 wr
00b8 wr
00b9 wr
00ba wr
00bb wr
00bc wr
00c1 wr
00c2 wr
00c3 w
00c4 w
00c6 r
00c7 r
02a2 re
02a3 r
02a4 r
02a5 re
02a6 r
02a7 r
02a8 re
02a9 re
02aa wr
02ab re
02ac r
02ad r
02ae re
02af re
02b0 re
02b1 r
02b2 r
02b3 re
02b4 r
02b5 r
02b6 re
02b7 re
02b8 re
02b9 wr
02ba re
02bb r
02bc r
02bd re
02be r
02bf r
02c0 r
02c1 r
031a r
031b r
031c r
031d r
031e r
031f r
0320 r
0321 r
0322 r
0323 r
0324 r
0325 r
0326 r
0327 r
0328 r
0329 r
0330 r
0331 r
0332 r
0333 r
0362 wr
036c wr
0376 wr
0a0f r
0a1c wr
0a35 wr
0a37 wr
0a38 wr
0a3a r

and the +4
0038 r
0090 rw
0091 r
0093 rw
0094 r
0095 w
0097 rw
0098 rw
0099 rw
009a rw
009b rw
009c rw
009d rw
009e rw
00ab rw
00ac rw
00ad rw
00ae rw
00af rw
00b0 rw
00b2 rw
00b3 rw
00b4 w
00b5 w
00ba rw
00d8 rw
00d9 rw
00f9 rw
0318 r
0319 r
031a r
031b r
031c r
031d r
031e r
031f r
0320 r
0321 r
0322 r
0323 r
0324 r
0325 r
0326 r
0327 r
032e r
032f r
0330 r
0331 r
0509 rw
0513 rw
051d rw
05e8 rw
07d9 er
07da re
07db re
07dc r
07dd r
07de re
07df rw
07e0 re
07e1 r
07e2 r
07e3 re
07e4 re
07e5 r
07e6 r
07e7 r
07e8 r
2020-03-17 14:47
Peiselulli

Registered: Oct 2006
Posts: 81
Where is the list of VIC20 ?
2020-03-17 15:37
chatGPZ

Registered: Dec 2001
Posts: 11100
"so when the Vice docs in the emulator say trace does load store exec by default, what it means is load store by default ;)"
that shouldnt be the case - please report a bug
2020-03-30 01:56
mr.micro

Registered: Aug 2010
Posts: 5
Quote: Awww… show me on the doll here where the trivial code touched you..

LMFAO!!
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
megasoftargentina
DanPhillips
Guests online: 102
Top Demos
1 Next Level  (9.8)
2 Mojo  (9.7)
3 Coma Light 13  (9.7)
4 Edge of Disgrace  (9.6)
5 Comaland 100%  (9.6)
6 No Bounds  (9.6)
7 Uncensored  (9.6)
8 Wonderland XIV  (9.6)
9 The Ghost  (9.6)
10 Bromance  (9.6)
Top onefile Demos
1 It's More Fun to Com..  (9.9)
2 Party Elk 2  (9.7)
3 Cubic Dream  (9.6)
4 Copper Booze  (9.5)
5 Rainbow Connection  (9.5)
6 TRSAC, Gabber & Pebe..  (9.5)
7 Onscreen 5k  (9.5)
8 Dawnfall V1.1  (9.5)
9 Quadrants  (9.5)
10 Daah, Those Acid Pil..  (9.5)
Top Groups
1 Oxyron  (9.3)
2 Nostalgia  (9.3)
3 Booze Design  (9.3)
4 Censor Design  (9.3)
5 Crest  (9.3)
Top Webmasters
1 Slaygon  (9.7)
2 Perff  (9.6)
3 Morpheus  (9.5)
4 Sabbi  (9.5)
5 CreaMD  (9.1)

Home - Disclaimer
Copyright © No Name 2001-2024
Page generated in: 0.056 sec.