swapping out basic on the 128..

Started by stiggity, November 29, 2010, 12:56 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

stiggity

Hello:
I came to this forum for assistance. It has been very helpful to me, and i appreciate all the input. Here is my question. Im writing a program on the c128, using the 80 column VDC screen, and right now, i use the "graphic1" command in basic, and my machine code occupies $1300 - $3FFF almost 45blocks. Well, i need to know any method to help me squeeze in another segment of machine code. I know on the 64 u can "swap-out-basic" and store code from $A000 - $BFFF, and i am very familiar with this method. I understand the 128 has the MMU register, but i dont fully understand it. How could i find more room for another machine language routine, while still being able to access the code from $1300 to $3FFF. I need about 10blocks, and if i could swap out basic, and store more machine code somewhere, thats the help im looking for. I appreciate anyone reading this, and since i have made the switch from the c64 to the 128, im having a blast. And only 9+ blocks from really partying it down.. eheheh thank you. :)

-Steve

dr.v

Steve - To begin I would HIGHLY recommend the 128 Programmers Ref. Guide:

http://cgi.ebay.com/Commodore-128-Programmers-Reference-Guide-/190453006712?pt=Video_Games_Games&hash=item2c57e24178

(Though I don't recommend buying it at that price.  You can get it for <$20 if you keep an eye on listings from time to time).  Now.. to your question.  There are several ways of doing this, but let me first ask - are you utilizing both 64k RAM banks?  Depending on your needs you could stash the code in the second bank and do a long jsr to the 2nd bank.  If there are portions of code from the 1st bank which are necessary while executing the from the 2nd bank, you can even create "common ram" between the 2 banks (upto 16K).

Tom

Wagner

Quote from: dr.v on November 30, 2010, 11:15 AMThere are several ways of doing this, but let me first ask - are you utilizing both 64k RAM banks?

Unfortunately, if he's using BASIC then the second bank is probably being clobbered by BASIC variables.  Would an REU RAM expander be a possibility to consider?  You can STASH and FETCH pretty easily from BASIC.

bacon

Quote from: dr.v on November 30, 2010, 11:15 AM
Steve - To begin I would HIGHLY recommend the 128 Programmers Ref. Guide:

http://cgi.ebay.com/Commodore-128-Programmers-Reference-Guide-/190453006712?pt=Video_Games_Games&hash=item2c57e24178

(Though I don't recommend buying it at that price.  You can get it for <$20 if you keep an eye on listings from time to time).
The Programmer's Reference Guide as well as a lot of other excellent books are available as PDFs from DHL's Commodore Archive. Look under Books - Commodore 128. I especially recommend Compute's Mapping the Commodore 128 and Compute's 128 Programmer's Guide. In my opinion they're better than Commodore's own book, especially if you use them together.
Bacon
-------------------------------------------------------
Das rubbernecken Sichtseeren keepen das cotton-pickenen Hands in die Pockets muss; relaxen und watschen die Blinkenlichten.

dr.v

QuoteI especially recommend Compute's Mapping the Commodore 128 ...

I second that motion.  If you are going to be doing any serious programming on the 128, this book is a "must have" reference.  I'm not as familiar with Computes 128 Programmers Guide.  I will take it under recommendation and put it on my reading list for the holidays.

Tom

BigDumbDinosaur

LDA #%00001110
STA $FF00


The above will expose contiguous RAM up to $0BFFF.
x86?  We ain't got no x86.  We don't need no stinking x86!

stiggity

Everyone:
Thank you for the replies, and BDD i understand what your saying, could you be more specific as too what your example routine does? Right now, I must do a "graphic1" before the 128 even allows me to load my machine code. Should i perform a graphic1, load my ML, and have a nested routine that simple does a

LDA #%00001110
STA $FF00
RTS

then load in my ML module that i have prepared external to the main body of ML code., that starts @ $B000 to $B900. I cannot seem to get anything cooperating. I think im failing with your example, or do i have to lda .A with anohter value, and return to my ML that resides in the $1300 - $3FFF range.

I have the 128 Programmers Reference Guide, and i use it so much its coming "Un-Bound" :)
I lost the link to "Mapping the 128", and online links also fail on me.

-Steve

Wagner

#7
I think what BDD is hinting at is to BLOAD your machine language program above BASIC--perhaps at $8000-$bfff.  This will give you 16K to work with.  Currently you do a GRAPHIC command and utilize the area between $1300 and $3fff.  Skip the GRAPHIC command entirely.  Instead, lower top of BASIC to $8000 with a POKE 4627,128; then BLOAD your ML at $8000.  Next, call your ML with a BANK 0:SYS 32768 (or whatever address).  Finally, in your ML routine, LDA #$0E  STA $FF00, to bank in I/O and the kernal.  Return to your BASIC program with a simple RTS.

10 poke 4627, 128
20 bload"ml",b0,p32768,u9
30 bank 0
40 sys 32768
50 print"hi"
60 sys 32779
70 print"bye"
80 end


8000 LDA #$0E
8002 STA $FF00
8005 LDA #$00
8007 STA $D020
800A RTS
800B LDA #$0E
800D STA $FF00
8010 LDA #$00
8012 STA $D021
8015 RTS

bacon

Quote from: stiggity on December 03, 2010, 06:40 AM
I have the 128 Programmers Reference Guide, and i use it so much its coming "Un-Bound" :)
I lost the link to "Mapping the 128", and online links also fail on me.
The links I posted work fine from here. Are you behind a corporate firewall or something?
Bacon
-------------------------------------------------------
Das rubbernecken Sichtseeren keepen das cotton-pickenen Hands in die Pockets muss; relaxen und watschen die Blinkenlichten.

stiggity

Wagner:
I appreciate the depth, and explanation. Im from the old school, and am/was a c64 programmer, most of this is new too me. I assembled my 45block Machine code file starting at $8000, and i launched VICE, did a poke4627,128 then bload"ml.o",b0,p32768,u8 and it loads my ML, then i did a bank 0, and executed the embedded ML routine that simple does a LDA#$0E, STA $FF00, to bank in I/O and kernal, but when my machine code starts to initialize the swiftlink it locks-up. do ihave to do a bank0 before each ML call? btw, im heavily relying on BASIC to be working. I'm probably confusing you, and apologize for being so crude. Maybe some further explanation will work. (Not that you didnt single handingly write the entire routine).

-Steve

Wagner

#10
Quotedo ihave to do a bank0 before each ML call? btw, im heavily relying on BASIC to be working.

I'm not sure about the bank 0 before each call.  In my simple example it wasn't necessary.  But your ML will have to do a LDA #$0E  STA $FF00 every time you make a SYS call, before the ML can use any I/O registers or kernal ROM.  Does your ML make any calls to BASIC ROM?  If so, that obviously wouldn't work directly--you would have to do a JSRFAR.  I experimented with some kernal calls from the LDA #$0E  STA $FF00 customized bank, and didn't have any problems.  I did have problems from bank 1 RAM, though.  To use bank 1 RAM instead of bank 0 RAM, I had to have 4K in common at the bottom of memory before my routine could print anything to the screen.  Sorry if this isn't more helpful--I have no idea how to use a SwiftLink cartridge.  I take it that SwiftLink makes registers available in I/O space and is supposed to be kernal compatible?  I'm guessing here, but I'm thinking that having moved the ML from $1300-$3fff to $8000-$bfff has introduced some minor bug(s)--some assumption or other.  The idea of running code at $8000 is sound enough, and your code must have been sound enough, too, where it was.  Try to get small pieces going again.

stiggity

Wagner:
I cant seem to get anything at all working, with the style you recommended. I would Love to have a full 16k to work with, but somehow something isnt working.
everything worked when my prg was store @ $1300 - $3FFF, using the graphic1 command, but i need >9blocks free... somewhere to store an external machine
code protocol. Sad thing is, there's not a lot of example code for the 128. I'm not giving-up, but im stumped..

-Steve

Wagner

 :-\   Can you make any use of the $8000-$bfff area for other things?  That is, maybe you could split your code into two pieces--the larger piece at the usual GRAPHIC 1 place and some smaller stuff above BASIC.  If you can handle executing code under BASIC V2.0 ROM on the 64, then this really isn't that much different.  It should actually be easier, since BASIC 7.0 can SYS to RAM under ROM, whereas BASIC 2.0 cannot.  I guess if you're serious about using the 16K at $8000, then I would experiment with toy routines like I started doing, until you're sure of how the 128 banking scheme works.

There are still other options to try too.  Like raising BASIC variables so you can BLOAD some code into bank 1 RAM and JSRFARing to it.  Or you could raise BASIC text a little higher than what you can get with just the GRAPHIC command.

stiggity

Wagner:

>>Or you could raise BASIC text a little higher than what you can get with just the GRAPHIC command.

how would i go about raising the BASIC text a little higher, and Yes, i would like to keep the 45block of code in the $1300 - $3FFF area, and i only need 10 more blocks, to make my program complete. I could load in the main body as 1 chunk, and then store the 10block file above BASIC. Sorry to sound desperate, but if you could include a routine(s) on storing machine code above basic, and if i could stay in bank15 that would be cool too.


Wagner

#14
Probably the easiest way to raise BASIC text is with another smaller BASIC program.

10 POKE 46, 80
15 POKE 20480,0
20 RUN"main", U9


This code will move the start of BASIC text to $5000 and RUN a BASIC program called "main" from device 9.  From within "main" BLOAD your ML code into $1300-$4fff.

Keep in mind that the area from $4000-$4fff is under BASIC ROM.  You need to bank switch BASIC in and out to call anything there.

By the way, if you raise BASIC text using this method and then do a GRAPHIC command, BASIC will be raised yet higher to $7400.  If you then do a GRAPHIC CLR, it will be lowered back down to $5000.

stiggity

Wagner:
I'm learning alot. I also downloaded "Mapping the 128" and plan on doing some reading. When you say that i have to bank switch basic in and out, what exactly do you mean? the LDA  #$0E STA $FF00, or just a simple bank0?


stiggity

Now that I think of it, im bloading (2) files. 1 file from $1300 to $3fff, and anohter from from $4000 to $4900, what would be the proper bload strings, to load each file into bank15? or do i have to load them using bank 0? This may sound stupid, but I'm probably making this more difficult than it is. Any more help will be much appreciated.


Wagner

#17
Quotewhat would be the proper bload strings, to load each file into bank15? or do i have to load them using bank 0?

10 BLOAD"ml1"
15 BLOAD"ml2"


The result of BLOADing into bank 15 at those addresses will have the same result as BLOADing into bank 0--the code will be put into bank 0 RAM.  BLOADing into $d000 in bank 15 will clobber I/O.

QuoteWhen you say that i have to bank switch basic in and out, what exactly do you mean? the LDA  #$0E STA $FF00, or just a simple bank0?

This is the proverbial can of worms.  When you call your ML routines in the $1300-$3fff area, you can use SYS in bank 15 or bank 0, since that area is visible to the microprocessor in either bank.  If you want to stay in bank 15, you can't SYS to RAM 0 for any address above $4000 since that is all BASIC ROM, I/O, and kernal ROM.  I guess if I were you, I would create a JMP table at $1300 something like this...

1300 LDA #$0E
1302 STA $FF00
1305 JMP sub1
1308 LDA #$0E
130A STA $FF00
130D JMP sub2
...


You can call subroutines in RAM 0 then without needing to know whether sub1 or sub2 are or are not visible in BANK 15; they will be made visible as soon as the JMP is executed.  You can return to BANK 15 (from sub1 and sub2) with an ordinary RTS, even though the BANK configuration has changed.

stiggity

Wagner:
I really appreciate the help. Got it all working, 100%. I look back on my posts on this forum, and think "wow.. was i that ignorant??". Your patience and time is valued.

-Steve

stiggity

Wagner:
Think you could make some sense of this..

(Pardon the crude source)

loop2   lda crc+1
        bpl shft
        lda crc
        asl
        eor #<$1021        is this the same as eor#$21
        sta crc
        lda crc+1
        rol
        eor  #>$1021   ;#$10 ???????????????
        sta  crc+1
        jmp cksum2
shft    asl crc
        rol  crc+1
cksum2  dex
        bne  loop2

Wagner

#20
QuoteI really appreciate the help. Got it all working, 100%.
;) :)


I simplified the code using 16-bit registers. 

        lda crc
-       asl
        bcc +
        eor #$1021
+       dex
        bne  -
        sta crc


Briefly, it left-shifts crc, then exclusive-ORs it with $1021 (a prime number) whenever the high-bit of crc had been set.  It keeps doing this till the x-register is zero.  The result ends up back in crc.  Was the x-register 16 (base decimal) at the start?