LOAD in assembler

Started by MIRKOSOFT, March 01, 2010, 07:02 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

MIRKOSOFT

Hi!

I have problem which I can't believe... Loading file in assembler and start it. On Commodore 64 it was no problem, but don't understand why works not on Commodore 128.
Can anybody help me?

Here's code:

   lda #6
ldx #<filename1
ldy #>filename1
jsr $ffbd // setnam
lda #00
ldx #00
jsr $ff68 // setbnk
lda #00
ldx #08
ldy #00
jsr $ffba // setlfs
lda #00
ldx #$01
ldy #$40
jsr $ffd5 // load
lda #131 // RUN & CR
sta $0200
lda #00
sta $0201
rts




Thank you very much.

Miro
MIRKOSOFT of megabytes

Commodore 64 was great, Commodore 128 is bigger, better, faster and more!!!

http://www.mirkosoft.sk

Hydrophilic

First, since you are trying to RUN program, then I must assume that it is a BASIC program you are trying to run.  But you specified a load address of $4001.  This will work only if BASIC has bitmap allocated; otherwise the start address will probably be $1C01.

Probably the best way is to use the pointer to start-of-BASIC at $2d/2e like this:

lda #0
ldx $2d
ldy $2e
jsr $ffd5 ;load

This way the program will load to correct address, no matter how BASIC is configured.

Second, because you may be loading program to a different area than it was saved, the line-links need to be re-calculated.  This can be accomplished by call to BASIC ROM routine $4F4F.  Note upon return, MMU will be in BANK 14 configuration (like standard BANK 15, but with char ROM instead of I/O registers).

Third, I am not familiar with POKING text into input buffer; I know this was common practice on older machines but I never did it on C128.  But, it seems you should poke # characters (in your case) somewhere...

An alternative is to call BASIC jump table entry "RUN" at $AF7B, then JMP to $4AF6.  I would think indirect JMP ($0308) would be more friendly to user-set vectors but BASIC just isn't designed like that...

Another alternative which makes the code shorter is to simply JMP $5AA6.  This is the end of the "RUN+filename" command which will do the line-linking for you and run the program.  With this method you would code:

jsr $ffd5 ;load
jmp $5aa6 ;re-link and run program


Finally, don't bother trying to JSR because BASIC will reset the stack as part of RUN.  If you need to regain control, you need to change both the "direct mode" vector at ($0302) in case program ends okay, and also "error" vector at ($0300) in case of some error... but this part can be tricky if user anticipates errors with TRAP...

I hope this helps!
I'm kupo for kupo nuts!

MIRKOSOFT

Hi!


Ok, this works... but my problem is other, I think...


I used it in my aceDOS (which is BASIC extension) and there after using LOAD routine like you wrote, it outputs only SEARCHING FOR..., no loading and really don't understand why...


If I add confirm load through RETURN and after start loading, it outputs only SEARCHING FOR... and after shows current directory, nothing loaded.
If I do not want to confirm, it shows only SEARCHING FOR... and after standard prompt, nothing loaded.


That's the problem, can you help me?


Thank you very very much.
Miro
MIRKOSOFT of megabytes

Commodore 64 was great, Commodore 128 is bigger, better, faster and more!!!

http://www.mirkosoft.sk

MIRKOSOFT

if it helps, here's part of code which has to load FCOPY and HDMAN:


hdman:
ldx #00
wins: lda insert,x
jsr toscreen
inx
cpx #57
bne wins
scan: jsr scnkey
lda 212
cmp #88
bne scan
cakaj: lda 212
cmp #1
bne cakaj
/* lda #$c6
ldx #$4d
sta $302
stx $303 */
lda #6
ldx #<filename1
ldy #>filename1
jsr $ffbd // setnam
lda #00
ldx #00
jsr $ff68 // setbnk
lda #00
ldx #08
ldy #00
jsr $ffba // setlfs
lda #00
ldx $2d
ldy $2e
jsr $ffd5 // load
jsr $5aa6
rts


fcopy:
ldx #00
wins1: lda insert,x
jsr toscreen
inx
cpx #57
bne wins1
scan1: jsr scnkey
lda 212
cmp #88
bne scan1
cakaj1: lda 212
cmp #1
bne cakaj1
/* lda #$c6
ldx #$4d
sta $302
stx $303
lda #139
ldx #37
sta 774
stx 24 */
lda #5
ldx #<filename2
ldy #>filename2
jsr $ffbd // setnam
lda #00
ldx #00
jsr $ff68 // setbnk
lda #00
ldx #08
ldy #00
jsr $ffba // setlfs
lda #00
ldx $2d
ldy $2e
jsr $ffd5 // load
jsr $5aa6
 rts




Thank you.


Miro
MIRKOSOFT of megabytes

Commodore 64 was great, Commodore 128 is bigger, better, faster and more!!!

http://www.mirkosoft.sk

Hydrophilic

If it says "SEARCHING FOR..." then that means something is wrong with the filename... it is missing!  It should say "SEARCHING FOR FCOPY..." or "SEARCHING FOR HDMAN..." (or whatever filename you use).

Check you have right address assigned to "filename1" and "filename2"

Also there is no reason to use RTS:
Quote from: MIRKOSOFT

...
jsr $ffd5
jsr $5aa6
rts
Remember, when you use $5AA6, the BASIC ROM will take over and not return.  Instead just write

...
jsr $ffd5
jmp $5aa6


Everything else looks okay, but what is this?
Quote from: MIRKOSOFT
lda #139
ldx #37
sta 774
stx 24
I don't think it is the problem, but I don't understand either.

Anyway, good luck!
I'm kupo for kupo nuts!

MIRKOSOFT

Hi!


SEARCHING FOR... I wrote 'cause it loads FCOPY or HDMAN, so I wanted to write it easy.
Your solution is really good... I tried it separately and works correctly, but don't works in aceDOS.
You asked me what's... it's disabling listing (not important thing).
I tried other way:
I used 10 chars key-buffer at 842-851 and number of characters at 208.
So I place there: rU"fcopy" + Return code ($0d).
Works correctly.
Problem is still with FCOPY - it needs to be loaded to $1c01, at $4001 crashes.
Don't know which free filecopier I can use - FCOPY is from 1581 disk "UNI-COPY".
HDMAN is my program which uses two utilities from Jochen Adler (NLQ) for IEC-ATA.


Thanks.


Miro
MIRKOSOFT of megabytes

Commodore 64 was great, Commodore 128 is bigger, better, faster and more!!!

http://www.mirkosoft.sk

pearsoe

I recently disassembled FCOPY to modify it to work with the uIEC/SD and it does have very specific load requirements. Also after execution it copies a portion of it's ML payload that is parked behind the BASIC portion higher in memory.
My rig: C-128 w/JD SCPU, uIEC/SD, CMD-HD (500 MB), CMD-HD ZIP drive, CMD RAMLink, 1750XL 2 MB REU, FD-2000, 1581, Turbo232

RobertB

Quote from: pearsoe on March 03, 2010, 05:25 AM
I recently disassembled FCOPY to modify it to work with the uIEC/SD...
Was that the improved one recently posted?  I saw it but didn't download it.  Where was that again?

Truly,
Robert Bernardo
Fresno Commodore User Group
http://videocam.net.au/fcug

pearsoe

My rig: C-128 w/JD SCPU, uIEC/SD, CMD-HD (500 MB), CMD-HD ZIP drive, CMD RAMLink, 1750XL 2 MB REU, FD-2000, 1581, Turbo232

Hydrophilic

#9
Quote from: pearsoe on March 03, 2010, 05:25 AM
I recently disassembled FCOPY to modify it to work with the uIEC/SD...

Thanks, I can't wait to try it!

Quote from: MIRKOSOFT
...[FCOPY] needs to be loaded to $1c01, at $4001 crashes.

That could be a problem if BASIC is setup at $4001.  In that case you need to tell BASIC to de-allocate the VIC bitmap by calling $A022.  After return, MMU will be configured to BANK 14.  More importantly, BASIC will then be setup to load files at $1C01.

Quote from: MIRKOSOFTYour solution is really good... I tried it separately and works correctly, but don't works in aceDOS...
I used 10 chars key-buffer... Works correctly.
Wow, I don't know what your aceDOS is doing to make calling ROM directly not work.  Well, at least you found a solution.
I'm kupo for kupo nuts!

RobertB

Quote from: pearsoe on March 03, 2010, 10:05 AM
Its posted in the uIEC Google group files here:

http://groups.google.com/group/uIEC-users/files?hl=en
Ah, there it is.  Thanks!  Can you tell what changes you made to it?

Or show us a thread where it is discussed,
Robert Bernardo
Fresno Commodore User Group
http://videocam.net.au/fcug
The Other Group of Amigoids
http://www.calweb.com/~rabel1/
Southern California Commodore & Amiga Network
http://www.sccaners.org

MIRKOSOFT

Hi!


So, I solved the problem with FCOPY and HDMAN and now they're working correctly.
Problem was - oh, my dumb head - in IRQ and NMI vectors, I restore original vectors and everything is working,,,


Only one thing is strange: when I start load routine $ffd5 and after $5aa6, it outputs only e.g. SEARCHING FOR FCOPY and after only READY prompt...



Miro
MIRKOSOFT of megabytes

Commodore 64 was great, Commodore 128 is bigger, better, faster and more!!!

http://www.mirkosoft.sk

pearsoe

Quote from: RobertB on March 03, 2010, 03:18 PM
Ah, there it is.  Thanks!  Can you tell what changes you made to it?

Or show us a thread where it is discussed,

I basically re-wrote the ML that identifies the type of drive connected.  The documented ML source used by FCOPY appeared in CW #22 so that helped a lot in decyphering the dissasembly.  FCOPY used a "M-R" command and a table to identify the type of drive.  I changed this to use a "UI" command and then parse the results.

Here's the source, I used ZED as my editor and Karma for the assembly:

My rig: C-128 w/JD SCPU, uIEC/SD, CMD-HD (500 MB), CMD-HD ZIP drive, CMD RAMLink, 1750XL 2 MB REU, FD-2000, 1581, Turbo232

Hydrophilic

Ooooh, source code...  pearsoe, you're awesome!

I'm familiar with ZED (nice 80-column text editor), but can you provide links / info on CW and Karma?

Obviously I could google, but busy people like me (and others browsing this forum) would appreciate it very much!

Quote from: MIRKOSOFT
Problem was... in IRQ and NMI vectors
That makes sense... when you change the interrupt routines, really strange things can happen!  (this amounts to multi-tasking on an 8-bit system... very tricky)

Quote from: MIRKOSOFT
Only one thing is strange: when I start load routine $ffd5 and after $5aa6, it outputs only e.g. SEARCHING FOR FCOPY and after only READY prompt...
There is no "LOADING" message?  The $ffd5 KERNAL routine should always produce "LOADING" message if it produces "SEARCHING FOR filename..." message.  Did your aceDOS also change the LOAD/SAVE vectors?

The $5aa6 only does a few things.  First, it will setup BASIC pointers and flags to RUN a program, then it will re-link the file that has been loaded, and finally it will jump into the execute-program part of BASIC ROM.

If it says "READY" and program does not run, then it sounds like no program was ever loaded... very interesting...
I'm kupo for kupo nuts!

MIRKOSOFT

No, it outputs not LOADING.


Which LOAD/SAVE vectors you mean?


Miro
MIRKOSOFT of megabytes

Commodore 64 was great, Commodore 128 is bigger, better, faster and more!!!

http://www.mirkosoft.sk

pearsoe

Quote from: Hydrophilic on March 04, 2010, 03:48 PM
I'm familiar with ZED (nice 80-column text editor), but can you provide links / info on CW and Karma?

CW is Commodore World magazine.  You can get issue #22 here:
http://www.bombjack.org/commodore/magazines.htm

Karma is Karma 128 a macro assembler for the 128 from PHD Software Systems. I have a D81 somewhere, I'll upload it to the downloads section here as soon as I find it.
My rig: C-128 w/JD SCPU, uIEC/SD, CMD-HD (500 MB), CMD-HD ZIP drive, CMD RAMLink, 1750XL 2 MB REU, FD-2000, 1581, Turbo232

Hydrophilic

Quote from: MIRKOSOFT...it outputs not LOADING.

Then I think there is a problem with the way you issue the LOAD command.  There is probably an error like DEVICE NOT PRESENT or FILE NOT FOUND.

The code you provided looks correct:  use device 8 for call to $ffba; filename a=len, address x/y with $ffbd; bank 0 with $ff68; load not verify (a=0), address x/y with $ffd5.

You can try this to see what the error is:

jsr $ffd5
bcc okay
ora #$30
jsr $ffd2
lda #13
jmp $ffd2
okay:
jmp $5aa6

If load returns an error, the code will print a 1-digit number (and carriage return).  Possible errors:
4 - File not found
5 - Device not present
8 - Missing filename
9 - Illegal device number
0 - (shown as 0, in ML it is really 16) Out of memory

I hope that helps!

Quote from: MIRKOSOFT
Which LOAD/SAVE vectors you mean?
Load vector is ($0330) and save vector is ($0332).  These are normally unchanged unless you have special software like RAMDOS or JiffySoft 128.

Quote from: pearsoeCW is Commodore World magazine.
Thanks.  Bombjack is just full of goodies.

Quote from: pearsoe
Karma is Karma 128 a macro assembler for the 128 from PHD Software Systems. I have a D81 somewhere, I'll upload it to the downloads section here as soon as I find it.
Cool.  I'm familiar with Merlin, Buddy, and the assembler from C128 developement back... it's nice to see other C128 assemblers...  I use cross assemblers myself, but it is always interesting to see what these native applications can do.
I'm kupo for kupo nuts!