Commodore 128 Alive!

Commodore 128 => 128 programmers => Assembly => Topic started by: MIRKOSOFT on June 28, 2010, 10:35 AM

Title: NEED HELP!!!! How to execute code after address $4000? NEED HELP!!!!
Post by: MIRKOSOFT on June 28, 2010, 10:35 AM
Hi all!


I need help for continue of development of aceCommander128...


I need to run subroutines at bank $4000 - $7fff.


I have here also data, they I can to read.
But executing any subroutine after address $4000 always crashes.


I tried to set non-standard bank:

lda #02 // set bank
sta $ff00


- this allows me to access data over $4000 - $7fff, all other is default.


But why my routines crashes?
I tried to call any with:

 lda #02
 sta $ff00 - I set range $4000 - $7fff as RAM0
 jsr cd.up - this routine I call
 jsr bank - back to bank $0f




But always this call crashes. It seems that I can only read data, but sure is that it's set as RAM0, I have data at $6000 - $7fff...


So, please please HELP me anybody!!!!


Many many thanks for everything what helps or explains or helps not...
Thanks for every reply.


Cheers,
Miro
Title: Re: NEED HELP!!!! How to execute code after address $4000? NEED HELP!!!!
Post by: LokalHorst on June 29, 2010, 12:16 AM
Quote from: MIRKOSOFT on June 28, 2010, 10:35 AM
Hi all!
I need help for continue of development of aceCommander128...
I need to run subroutines at bank $4000 - $7fff.
I have here also data, they I can to read.
But executing any subroutine after address $4000 always crashes.

I tried to set non-standard bank:

lda #02 // set bank
sta $ff00


- this allows me to access data over $4000 - $7fff, all other is default.

But why my routines crashes?
I tried to call any with:

lda #02
sta $ff00 - I set range $4000 - $7fff as RAM0
jsr cd.up - this routine I call
jsr bank - back to bank $0f

But always this call crashes. It seems that I can only read data, but sure is that it's set as RAM0, I have data at $6000 - $7fff...
...

Hi Miro,
your description lacks information needed to give an answer to your question:

Where is your switching code placed ? (must be below $4000)
Are the sub-routine(s) called using any Kernal or Rom-based code ? (jsr cd.up)
Is the switch back done with a call to kernal $ff6b ? (jsr bank)
Are interrupts enabled (which might change the config) ?

Title: Re: NEED HELP!!!! How to execute code after address $4000? NEED HELP!!!!
Post by: MIRKOSOFT on June 29, 2010, 12:37 AM
Hi!


thanks for correctly answer.
My suborutine JSR cd.up is in place $4000 - xxxx
So, switching code is placed at area $1300-$2000
Sub-routine calls only KERNAL routines (config of MMU is default except $4000 - $6fff)
jsr bank is routine called from address $a845
Interrupts are not changed.


Help this?


Cheers,


Miro

Title: Re: NEED HELP!!!! How to execute code after address $4000? NEED HELP!!!!
Post by: LokalHorst on June 29, 2010, 01:50 AM
I couldn't reproduce the error with a quick test-prog hacked in with the build-in monitor.
01c10: LDA #$02
STA $ff00
JSR $4000
JSR $a845
BRK

04000: JSR Primm ($ff7d)
some text here followed by 00 and RET

so I guess anything inside your code changes the MMU config while in the area $4000 & up. You might test the official variant via JSRFAR ($ff6e / $02cd) with index #12 (int rom) or 13 (ext rom) but ram @ 4000 to 7fff + i/o + kernal.


Title: Re: NEED HELP!!!! How to execute code after address $4000? NEED HELP!!!!
Post by: MIRKOSOFT on June 29, 2010, 02:25 AM
I know that $4000 - $7fff is RAM0.
Orher values are default.
So, I have I/O, KERNAL, BASIC-HI...


I ant to know how to execute routine stored after $4000...
Title: Re: NEED HELP!!!! How to execute code after address $4000? NEED HELP!!!!
Post by: MIRKOSOFT on June 29, 2010, 10:05 AM
It's impossible:
If I call routine with

lda #02
sta $ff00



and run this trivial routine with this call:



.namespace test {

do: lda #01
sta row
sta col
jsr pos
ag: lda text,x
jsr toscreen
inx
cpx #12
bne ag
rts

text:
.text "NO WARRANTY!"

}




It works, I'm confused - can I use only simple routines?????
Title: Re: NEED HELP!!!! How to execute code after address $4000? NEED HELP!!!!
Post by: BigDumbDinosaur on June 29, 2010, 10:07 AM
Didn't we already hash through this somewhere else on the forum?  I think you (Mirko) don't fully understand the C-128 architecture and the difference between bank and actual machine configuration.  Try writing %00001110 into the MMU high configuration register at $FF00 and see what happens.  Also, read Mapping the Commodore 128, which has a lucid discussion of the machine's architecture.  You should know that both the 80 Column Display Manager and Clock-Calendar 128 run underneath the kernel ROM, with the latter being interrupt-driven.  Obviously it can be done, but you must fully understand what is going on in there.
Title: Re: NEED HELP!!!! How to execute code after address $4000? NEED HELP!!!!
Post by: MIRKOSOFT on June 29, 2010, 10:22 AM
Yes, your advices are on regular places.


But I understand MMU config - from where?


MAPPING COMMODORE 128...


So, I selected config of if it's possible to say "bank" which have all memory blocks default except $4000 - $7fff...


So, I'm only confused 'cause this needs new routines to fit it to $4000 - $7fff...


Also, thanks for calling me "Mirko" 'cause it's in our language nickname - and from there's is my name MIRKOSOFT - we were two called Miro (or Mirko) and have fun to crash Microsoft name...


Yes, my friend is gone and I stayed lonely, so I created also old-new group Megabytes...
But it's out of theme...


Also thanks for advices, I hope that it will work 'cause I need apprx. 6kB to finalize program...
Title: Re: NEED HELP!!!! How to execute code after address $4000? NEED HELP!!!!
Post by: BigDumbDinosaur on July 01, 2010, 03:36 AM
Quote from: MIRKOSOFT on June 29, 2010, 10:22 AMSo, I selected config of if it's possible to say "bank" which have all memory blocks default except $4000 - $7fff...
"Bank" has no direct relationship to the memory map.  The "bank" thing is merely a set of 16 maps that are built into the kernel ROM.  You don't have to use them in machine language and, in fact, I recommend that you establish your configuration by writing directly to the MMU high configuration register at $FF00.

Here is the (slightly condensed) MMU declaration code I use in my C-128 programs:

;8722 MEMORY MANAGEMENT UNIT DECLARATIONS
;
mmucr    =$ff00                 ;configuration...
;
;    0xxxxxxx
;     |||||||
;     ||||||+---> $D000-$DFFF:  0 = I/O hardware
;     ||||||                    1 = RAM or character ROM
;     |||||+----> $4000-$7FFF:  0 = system ROM
;     |||||                     1 = RAM
;     |||++-----> $8000-$BFFF: 00 = system ROM
;     |||                      01 = internal function ROM
;     |||                      10 = external function ROM
;     |||                      11 = RAM
;     |++-------> $C000-$FFFF: 00 = system ROM
;     |                        01 = internal function ROM
;     |                        10 = external function ROM
;     |                        11 = RAM
;     +---------> RAM bank:     0 = RAM-0
;                               1 = RAM-1
;
lcra     =mmucr+1               ;select configuration A
lcrb     =mmucr+2               ;select configuration B
lcrc     =mmucr+3               ;select configuration C
lcrd     =mmucr+4               ;select configuration D


If this doesn't do it for you, you will have to download and read Mapping the Commodore 128, which I believe is in the archives somewhere around here.

Several points worth noting.  The lcra-lcrd definitions are established at reset and are arranged for BASIC's convenience, not the programmer's.  However, it's perfectly acceptable to change the definitions to suit your own code (you have to read and write the preconfiguration registers in the I/O block), but you must be careful to restore them prior to returning to BASIC.

Calling BASIC ROM functions from M/L is somewhat problematic because, upon exit, many of these routines will leave the system configured to the equivalent of bank 14, and your RAM-0 code may become invisible, resulting in a crash.  You don't mention whether you are calling BASIC, but if you are, you need to do so through the JSRFAR method to make sure you return to your code.

This is a somewhat difficult subject to explain well, so I strongly recommend you spend less time posting questions and more time reading  Mapping the Commodore 128.  That tome will do a much better job explaining memory management than can be accomplished on a forum.
Title: Re: NEED HELP!!!! How to execute code after address $4000? NEED HELP!!!!
Post by: bacon on July 01, 2010, 06:11 PM
Jim Butterfield wrote two excellent articles about using C128 memory configurations in assembly language in the Transactor. Here (http://csbruce.com/%7Ecsbruce/cbm/transactor/v7/i1/p034.html) and here (http://csbruce.com/%7Ecsbruce/cbm/transactor/v7/i4/p056.html).
EhPortal 1.34 © 2025, WebDev