IEC Disk support for Corsham's xKIM and Microdoft's KB9

238 views
Skip to first unread message
Assigned to hansj...@gmail.com by me

Eduardo Casino

unread,
Mar 2, 2024, 12:11:53 PMMar 2
to PAL 6502 computer
Hi,

Hans thought that this could be of interest to the PAL-1 community ;)

I've been extending Dave McMurtrie's implementation of IEC disk support for the KIM-1 (from the ca65 port Nils Andres, a.k.a. netzherpes). I've added long file names, sending arbitrary commands to the disk, directory listing, verify and add a jump-table based interface, and used that to add disk support to Corsham's xKIM monitor and Microsoft's KB9. Here is a video of it working:

 

 

Code at my GitHub repository:

KB9 with disk support: https://github.com/eduardocasino/msbasic/tree/IEC_support


BUILD


This is still experimental, use at your own risk!


Requirements: Expanded KIM-1 (or PAL-1) with RAM from 2000 to DFFF, ROM from E000 to FFFF and the IEC circuit based on Dave's design.


Linux, WSL or any unix-like system with git, bash, gmake and Python.


Clone the xkim1541 repository and build using 'make'. You'll need to have Python installed as there is a script that generates the include file depending on the base address. By default, the code is generated to be loaded at 0xF000. You can change it editing the OFFSET variable in the Makefile. I do not recommend modifying the other two variables: ZPINIT and BSSINIT, as they have been chosen to not interfere with either xKIM or KB9.


Clone the xXIM repository and switch to the IEC_support branch. Copy the iecproto.inc file generated in the previous step. Build using 'make IEC_SUPPORT=1'. Burn the xKIM-0.bin file to a ROM at offset 0xE000


Clone the KB9 repository and switch to the IEC_support branch. Build with 'make'. By default, it is assumed that xkim1541 starts at 0xF000. Modify the defines_kimiec.s file if you put it anywhere else. Binary and hex files are generated in the tmp directory, with offset 0x2000. You can build it at a different one editing the PAGE variable in the makefile. For example, I built mine at PAGE = 40 (0x4000) because I've got a Visual Memory Card at 0x2000. You can build a prg file with 'make prg', so you can add it to a disk image.


Note: I've been experiencing what I think are hardware problems with xkim1541. Every now and then, I received premature EOI indications wher reading relatively large files or directories. It seems that occasionally, with my setup, my own KIM-1 clone with a dual 6530-6532 adapter, the timer is not correctly set. I suspect a timing problem with the adapter, but I haven't yet concluded what it is. I've discovered that reading the timer just before setting it seems to fix the symptoms. I would be very grateful if you edit xkim1541.s and set EOI_FIX to 0, build it and see if it is stable with your system.


USING


Jump to xKIM at addr 0xE000. There are some modified or new commands:


  C ........... Send a command to the drive
  D ........... Disk directory
  R ........... Read PRG file from disk
  V ........... Verify PRG file on disk
  W xxxx xxxx . Write memory to PRG file

If you are familiar with xKIM, they are self-explanatory. See also the video. When writing to disk, end address must actually be address of last byte + 1

If you can generate a physical or pi1541 or similar image, make one with kb9v2.prg and load using the 'R' command. You'll see the address where the program is loaded to. Just jump ('J') to that address to start MS Basic.

New and mofified BASIC tokens:

LOAD and SAVE, without arguments, work the same as the originals: loads and saves the current program from/to tape.

LOAD "<FILE>" and SAVE "<FILE>" will load and save file <FILE> from/to disk.

VERIFY "<FILE>" will compare the current program in memory against the <FILE> program on disk.

DIR will list disk directory contents to screen. The current program in memory is not altered.

DCMD "<CMD>" will send command <CMD> to disk. Example:

DCMD "S0:X*" will delete (scratch) all files beginning with "X".

Feedback, bug reports, pull requests, you name it, are most welcome!!!

Enjoy!


John Kennedy

unread,
Mar 2, 2024, 8:33:42 PMMar 2
to PAL 6502 computer
What a fantastic project! I wonder if it would work with the Pi-based 1541 disk emulators?

Eduardo Casino

unread,
Mar 2, 2024, 10:43:55 PMMar 2
to PAL 6502 computer
El dom., 3 mar. 2024 2:33, John Kennedy <johntk...@gmail.com> escribió:
What a fantastic project! I wonder if it would work with the Pi-based 1541 disk emulators?

It does indeed! It is my main test system. 

Neil Andretti

unread,
Mar 5, 2024, 2:28:30 AMMar 5
to PAL 6502 computer
Wow.
Just wow.
I set up my Laptop and the build process is working (very fast). I just need some confirmation of the other group members, that I am not doing any bs:

Our PAL-1 can not access the ROM from E000-FFFF, right?
"Last 8K is identical to first 8K due to K0 to K7 connection. " is what Hans said earlier.

So I need to place the Code below $DFFF.

My idea is to place the xkim1541 routines right below at like DF00
Then place the XKIM Monitor at D000.

and build the kb9 with Jim's wrapper, so it will be copierd to the correct start at $2000. 
Then burn this 3 programs in ROM and all my sorrows are gone.....

Did I miss something?

Nils

Hans Otten

unread,
Mar 5, 2024, 5:12:06 AMMar 5
to PAL 6502 computer
Sounds good!

Eduardo Casino

unread,
Mar 5, 2024, 5:59:19 AMMar 5
to Neil Andretti, PAL 6502 computer
Hi,

The modified xKIM monitor alone is 3041 bytes so, if you place it at D000, it will go up to DBE0

The xkim1541 routines weight 1343 bytes, so they won't fit below E000 (they woud reach E11F)

I'm sorry, I do not kwnow about Jim's wrapper for KB9, why do not just build it with the provided Makefile?

I'm eager to know if you get this working with the PAL-1!

Cheers,
Eduardo

--
You received this message because you are subscribed to the Google Groups "PAL 6502 computer" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pal6502+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pal6502/0c510edc-854e-4ca3-abe1-7bb6c9b3ad9dn%40googlegroups.com.

Neil Andretti

unread,
Mar 5, 2024, 7:06:21 AMMar 5
to PAL 6502 computer
I try to calculate where to put what and then try the loading routines with my SD2IEC device. By having the DOS commands I can hopefully also switch directories, which makes it the perfect mass storage device (for less than 40€).

Jims Wrapper:
In the PAL-1 ROM Card there is a bundle of programs that gets copied to RAM by the bootloader when chosen:

For example: KimBasic is being transformed into bytecode, 64TASS does understand:

basic_start:

 .byte $E9,$26,$07,$26,$C5,$2B,$44,$28,$8C,$2A,$9E,$2E
 .byte $B8,$2A,$F1,$28,$F1,$27,$C9,$27,$74,$28,$CA,$26
 .byte $D4,$27,$1E,$28,$87,$28,$E7,$26,$97,$28,$2A,$27
 .byte $18,$36,$8B,$27,$3B,$27,$B1,$31,$0F,$36,$80,$29
 .byte $10,$27,$78,$25,$3B,$25,$7D,$2A,$20,$25,$B1,$3A
 .byte $44,$3B,$D0,$3A,$4B,$30,$81,$31,$A2,$31,$C2,$3D
 .byte $E3,$3E,$30,$38,$3E,$3E,$1F,$3F,$26,$3F,$6F,$3F
 and so on....

The bootloader will then copy BASIC from whereever basic_start is (simply included) to $2000, do a CLD and start basic.
That way we can have basic in ROM...

I'm super excited to get it running...

Hans Otten

unread,
Mar 5, 2024, 7:55:37 AMMar 5
to PAL 6502 computer
Jim's wrapper is a simple ROM file system for the PAL-1 ROM extension. Store programs in the ROM, copy to RAM when needed via a menu. Nice when you do not have a external file system.
With the 1541 as file system one could just have all your programs on the 1541 and use the ROM space for Xkim and IEC support. 

Neil Andretti

unread,
Mar 5, 2024, 8:00:06 AMMar 5
to PAL 6502 computer
Hans is right, this makes it even easier ;)

xKIM at CE00
xkim1541 at DA00
done.  \o/

 And if I still want I could add the bootloader and basic at A000

John Kennedy

unread,
Mar 5, 2024, 6:27:28 PMMar 5
to PAL 6502 computer
Hi - what is the physical connection to the disk drive or Pi1541?

Is there a ready-to-burn EPROM image somewhere, for the lazy?

Neil Andretti

unread,
Mar 6, 2024, 12:43:47 AMMar 6
to PAL 6502 computer
Gooood morning Group
Here's the earlybird....
John: This is the connection to the IEC Bus: https://netzherpes.de/content/images/20220627075711-kim1541.png

I've build a the PAL rom and the MSBASIC for it, but not tested it yet (it runs on the kimsim)
Has someone beside me a iec interface at the PAL1?
Anyway: This is the ROM with XKIM starting at CE00 and the MSBASIC with 1541 support 

i have no idea where the coldstart adress is... 
Eduardo: Did you place a jmp coldstart: at the beginning? in your video you run MSBASIC from 2000...)

CUL8R

Nils
kb9v2_1541.prg
PALROM_xkim1541.bin

Eduardo Casino

unread,
Mar 6, 2024, 10:07:58 AMMar 6
to Neil Andretti, PAL 6502 computer
Hi Nils, everybody, 

Yes, there is a jump to coldstar at the beginning. 

Cheers, 
Eduardo

John Kennedy

unread,
Mar 6, 2024, 11:46:05 AMMar 6
to PAL 6502 computer
1 chip and some resistors? Hopefully I can manage that!

Hans Otten

unread,
Mar 6, 2024, 1:06:17 PMMar 6
to PAL 6502 computer
7406 or 7416 will do, typical commodore IEC interface

Neil Andretti

unread,
Mar 7, 2024, 4:49:36 PMMar 7
to PAL 6502 computer
The builld PAL-1 ROM I postted above seems to work.


confirm.png
The xKIM monitor does not like the SD2IEC directory. I need to check how to enter a disk image and pack msbasic to an image.
With my real 1541 it works like a charme!

Eduardo Casino

unread,
Mar 7, 2024, 9:29:32 PMMar 7
to Neil Andretti, PAL 6502 computer
El jue, 7 mar 2024 a las 22:49, 'Neil Andretti' via PAL 6502 computer (<pal...@googlegroups.com>) escribió:
The builld PAL-1 ROM I postted above seems to work.
The xKIM monitor does not like the SD2IEC directory. I need to check how to enter a disk image and pack msbasic to an image.
With my real 1541 it works like a charme!

I think I know what is going on...

19279 is 0x4F4B, which happens to be "OK", so it seems that we are getting four bytes (the DIRLIST command discards the first 4 bytes received because it expect them to be the fake file load address followed by the next program line) followed by "OK,0,0", which is the default error message of SD2IEC, which is placed in the uninitialized buffer.

Inspecting the SD2IEC code, I see that it expects the secondary address to be 0 in order to construct the directory list header and place it to the buffer.

But in my code, I'm not sending the SA for s directory listing, which seems to be OK with a real disk, but not with the emulated SD2IEC drive.

Something similar seems to happen with the pi1541. In this case, the directory listing in SD2IEC mode just hangs, but d64 images, for which pi1541 does a perfect emulation of a 1541 drive, work perfectly.

I' won't be able to test it until tomorrow afternoon (my lab is in my country house) but, being an early bird as you are, Nils, would you please apply the attached patch to xkim1541.s and see if it works?

Thanks!

Eduardo

diff --git a/xkim1541.s b/xkim1541.s
index d09f0ad..d2088e8 100644
--- a/xkim1541.s
+++ b/xkim1541.s
@@ -285,7 +285,8 @@ RDIRLIST:       lda     #1              ; Filename length
                 ;
                 lda     FA
                 jsr     TALK
-                jsr     TKATN           ; SA is 0 for dir reading, no need to send it
+                lda     SA
+                jsr     TKSA
                 bit     STATUS          ; Did he listen?
                 bpl     @CONT
                 jmp     ERROR5          ; Nope, device not present


Neil Andretti

unread,
Mar 8, 2024, 1:15:10 AMMar 8
to PAL 6502 computer
\o/ thats fixed it...

confirm1.png

Neil Andretti

unread,
Mar 8, 2024, 1:22:55 AMMar 8
to PAL 6502 computer
a little further testing:
changing directories and jumping into images in SD2IEC is working also and kb9_iec is working.

confirm3.png
Eduardo, again thank you so much for this.

Liu: How about an SD card add on ;) ?

Eduardo Casino

unread,
Mar 8, 2024, 2:15:05 AMMar 8
to PAL 6502 computer
I'm very happy you got it working. Changes pushed to the GitHub repository.

Thanks fot the testing!

--
You received this message because you are subscribed to the Google Groups "PAL 6502 computer" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pal6502+u...@googlegroups.com.

Neil Andretti

unread,
Mar 8, 2024, 2:49:14 AMMar 8
to PAL 6502 computer
Good morning Group,
sorry for being so noisy, but it's all fascinating.

More changes:
Our PAL-1 has RAM from 2000-9FFF and ROM from A000-DFFF
Eduardo used 'his' RAM at AF80, but this will not work on our PAL-1....
When I tested this earlier I used my upper RAM Card for testing and I did not notice it.

So here it is: THE PAL-1 xKIM 1541 Routine ROM, working with some RAM usage at 9F80....
Start xKIM at $CE00

With kb9V2_1541 on a disk image.
BASIC.D64
PALROM_xkim1541.bin

GN Liu

unread,
Mar 8, 2024, 4:03:34 AMMar 8
to PAL 6502 computer
Thank Eduardo, Nils and everyone for such a great post!

Nils,
you work so fast, I'm still studying these....
and the SD card add-on is an amazing idea, will try!

The conversation in this post is very enlightening, thank you all!!!

Liu

Michael Doornbos

unread,
Mar 8, 2024, 9:22:13 AMMar 8
to GN Liu, PAL 6502 computer
This is so great. I love the SD Shield on my Corsham board and I'm pleased to see Bob's work live on with another KIM-1 clone. Excellent work! 



--
--
Michael Doornbos
Imapenguin.com
Evadot.com
michaeldoornbos.com
myzenith750.com <—- yes I’m building an airplane in my garage (hangar)
828-450-7418
HAM: N4LNX 

Neil Andretti

unread,
Mar 10, 2024, 3:55:47 PMMar 10
to PAL 6502 computer
Hans:
Can you add the option to save  commodore prg files in the 8bit converter?
It's very simple the starting address and the binary... 
... too lazy for HxD

Have a nice evening
Nils

Hans Otten

unread,
Mar 11, 2024, 3:19:25 AMMar 11
to PAL 6502 computer
PRG format is already supported since december 2023.

Neil Andretti

unread,
Mar 11, 2024, 5:55:04 AMMar 11
to PAL 6502 computer
Ooops. I need to update I guess.
Message has been deleted
Message has been deleted
Message has been deleted

Hans Otten

unread,
Mar 29, 2024, 6:57:29 AMMar 29
to PAL 6502 computer

Subject: Re: IEC Disk support for Corsham's xKIM and Microdoft's KB9

From: Neil Andretti

Date: Mar 26 03:10AM -0700

 

A wonderful lovely morning group,

 

This is the 3rd try to post something here in this thread, I am sorry if you already recieved the first two attempts....

 

I build a RAM only version of xKIM1541 for the PAL-1. Just in case you do 

Jeff M. Nay

unread,
Mar 30, 2024, 8:44:51 PMMar 30
to Hans Otten, PAL 6502 computer

Implementing Commodore's IEC bus protocol on a KIM-1 single board computer

This guy has a couple of really good videos working with the KIM-1

 

https://youtu.be/cK7mzGhBfHs?feature=shared

Reply all
Reply to author
Forward
0 new messages