Harry Potter Posted February 25, 2023 Share Posted February 25, 2023 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? Quote Link to comment Share on other sites More sharing options...
westman Posted February 27, 2023 Share Posted February 27, 2023 (edited) 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 February 28, 2023 by westman Quote Link to comment Share on other sites More sharing options...
Harry Potter Posted February 28, 2023 Author Share Posted February 28, 2023 Oh. I'll check your page now. Quote Link to comment Share on other sites More sharing options...
Harry Potter Posted February 28, 2023 Author Share Posted February 28, 2023 I have a PET memory map. Will it tell me what addresses I have to set for the BASIC functions to work? Quote Link to comment Share on other sites More sharing options...
westman Posted February 28, 2023 Share Posted February 28, 2023 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 Quote Link to comment Share on other sites More sharing options...
Harry Potter Posted February 28, 2023 Author Share Posted February 28, 2023 Thank you. I could make versions for both BASIC 2.0 and 4.0. I can set the pointer in the code to the address one byte before the string that contains the command that would be an argument to the OPEN command, right? What is the address of the pointer in the routine that reads the current byte from a BASIC program? Quote Link to comment Share on other sites More sharing options...
westman Posted February 28, 2023 Share Posted February 28, 2023 (edited) 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 February 28, 2023 by westman Quote Link to comment Share on other sites More sharing options...
Harry Potter Posted February 28, 2023 Author Share Posted February 28, 2023 I have a memory map of the PET, and it says that the TXTPTR pointer is at $77. I believe I'm almost ready to continue working on the PET port of DirMenu. Just one last thing: when passing the argument to the PET's OPEN routine, do I need to pass the pointer to the OPEN arguments or one less? Quote Link to comment Share on other sites More sharing options...
westman Posted February 28, 2023 Share Posted February 28, 2023 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. Quote Link to comment Share on other sites More sharing options...
Harry Potter Posted February 28, 2023 Author Share Posted February 28, 2023 Thank you. Quote Link to comment Share on other sites More sharing options...
westman Posted February 28, 2023 Share Posted February 28, 2023 Glad I could help – hope it works out! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.