Jump to content
IGNORED

PET/cc65: opening file/dir from asm.?


Harry Potter

Recommended Posts

Hi!  I am currently working on a PET port of my DirMenu program and am having a problem: when I open the disk's directory, I get a syntax error.  I am using the same code for the PET that I'm using for the other CBM systems except that the length in SETNAM is three, as I'm opening "0:$".  Am I doing something wrong?  How do I open a file or dir on a PET from assembler?

Link to comment
Share on other sites

I never programmed the PET in assembler, but the page linked below states that pre-1982 PETs didn't have assembler-friendly KERNAL routines for OPEN/CLOSE/LOAD/SAVE – the ROM routines for those were intended to be called directly from within the BASIC interpreter, and therefore needed to parse the command line (or program text) for parameters.  In case of an error, I suppose there will be a call into BASIC's error reporting mechanism. So making it work would either require some insight into BASIC interpreter internals, or perhaps extracting the "meat" of the implementation from disassembling the ROM (unless someone already did that work and documented it, I guess).

 

https://www.pagetable.com/?p=926

 

 

Edited by westman
Link to comment
Share on other sites

46 minutes ago, Harry Potter said:

I have a PET memory map.  Will it tell me what addresses I have to set for the BASIC functions to work?

If you're not already familiar with BASIC internals, it will probably not be enough.  Also, I had a look at a ROM disassembly I found[1], and saw that it was making calls into a zero-page subroutine located at address $c8.  This didn't make sense according to the PET memory map I had, and it turned out that the memory map just didn't match the ROM disassembly – it seems the subroutine at $c8 had moved to $76 at some point.  This subroutine fetches characters from the command line / program text, and contains the address to read from as an absolute reference – the idea is that you change that address to the location you want to fetch characters from (the LDA #xxxx below):
 

0070            INC $77
                BNE $0076
                INC $78
0076            LDA $xxxx
                CMP #$3A
                BCS $0087
                CMP #$20
                BEQ $0070
                SEC
                SBC #$30
                SEC
                SBC #$D0
0087            RTS

 

But of course, if the address of that "buffer pointer" is not necessarily the same between different BASIC ROMs, it gets hairy. 
 

[1] https://web.archive.org/web/20060206181217/http://www.zimmers.net/anonftp/pub/cbm/firmware/computers/pet/d/rom-1.html

 

 

Link to comment
Share on other sites

The address is in the two bytes that follow the LDA instruction, so either $77 or $c9 in the two variations I saw.  It is in little-endian, i.e. the least significant byte first, followed by the most significant byte.  I'm not sure they correspond to BASIC 2.0 and 4.0, though ­– the KERNAL disassembly (that would be using $c9) might be for BASIC 1.0, while the memory map might apply both to PET BASIC 2.0 and 4.0 (this is suggested in https://stackoverflow.com/questions/31877835/what-does-the-commodore-pet-basic-assemble-starting-from-00c2).  Also (as the linked page points out) it changed to a third location on VIC-20 and C64, even though their BASIC identifies as BASIC V2.  (But for this purpose, I guess the latter is irrelevant as you wouldn't use the method on VIC-20/C64 anyway, but it's a sign that the address changes do not necessarily follow the officially stated BASIC version.)

Edited by westman
Link to comment
Share on other sites

Not 100% sure, but I can give you my best guess.  There are two entry points to the zero-page routine – one that increments TXTPTR first and one that doesn't.  The parameter parsing for OPEN starts with the latter one, which suggests to me that TXTPTR is assumed to point directly to the address of the arguments, not one less. 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...