PAL-1 monitor and IRQ

68 views
Skip to first unread message

Marek Karcz

unread,
Jan 29, 2023, 8:00:17 AM1/29/23
to PAL 6502 computer
Hello,

It appears that IRQ is disabled when monitor program is running and is activated when user program is started (GO). Am I correct? Is this an expected mode of operation?

Thanks,
---
Marek

Hans Otten

unread,
Jan 29, 2023, 8:48:27 AM1/29/23
to PAL 6502 computer
Yes, the SEI instruction, set Interupt Disable is in the Init part of the monitor. Location in the Init1 routine, line 976.
Understandable, with the software delays in the TTY bit banging you do not want interrupts. Also single step and interrupts is not a nice combination. So yes, expected,

Whether interrupts are disabled in the user program depends on what you start with in the Processor status, location F1. The usual is to store 0 there, so the interrupt flag is set to enabled.
See line 941 of the KIM-1 ROM listing. 

A user program should always make sure the status of Decimal and Interrupt and stack . 
That is why you see often CLD and SEI , LDX #$FF TSX as first in programs. Bill Gates forgot the CLD in the KB9 ;), leading to lost of confusion if F1 was not set right too.

Reading and understanding the KIM-1 monitor is essential for a KIM-1 programmer ;) so much smart things happening there.

Marek Karcz

unread,
Jan 29, 2023, 2:36:30 PM1/29/23
to PAL 6502 computer
Thank you very much for your detailed response.
That makes a lot of sense.
I noticed the issue because I keyed in a Clock program from "The First Book Of KIM" that I found here on my PAL-1.
However, since I do not have optional RIOT card, I have modified the code to use timer from the on-board RIOT and to use IRQ rather than NMI 
(as the NMI caused the program to crash - in original app. instructions say to connect PB7 to NMI and set the NMI vector, that didn't work - my modification was to NOT make the PB7 to NMI connection and set IRQ vector instead as IRQ pin from on-board RIOT is already connected to the MPU).

Clock seems to work fine with my modifications when I run the app. However, program also has a mechanism to exit to monitor and supposed to keep the clock running in the interrupt (Clock "display mode can be re-entered).
With my changes though, the clock stopped as soon as I exited to monitor. I guess with NMI and optional RIOT timer it would keep running, since NMI is non-maskable.
It is now clear why with IRQ it doesn't work, with your excellent explanation.

Can you please grant me one more request and  direct me / provide URL to the full KIM-1 ROM listing that you were referring to in your response.
I reviewed KIM's User Manual, but I only found listings of the Tape and TTY subroutines there.
I want to understand the PAL-1's operating system a little bit more, before I start to write my own code.

Greatly appreciated!

---
Marek


Marek Karcz

unread,
Jan 29, 2023, 2:53:44 PM1/29/23
to PAL 6502 computer
>>  I reviewed KIM's User Manual, but I only found listings of the Tape and TTY subroutines there.

As I am reviewing these listings further it appears that they may be indeed the full ROMl istings.
I just have a copy of PDF scan with missing pages. Off to internet to look for full listing.

Jim McClanahan

unread,
Jan 29, 2023, 3:10:02 PM1/29/23
to Marek Karcz, PAL 6502 computer
They are on Hans's site in several formats:


There isn't much to them--the monitor has a pretty limited feature set.

Thanks,
Jim W4JBM

--
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/f20a8e26-610d-4b05-b223-df4f1078193an%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Marek Karcz

unread,
Jan 29, 2023, 10:19:52 PM1/29/23
to PAL 6502 computer
After ROM / KIM monitor code analysis I conclude that in monitor mode IRQ is masked.
When Clock app. from "First Book of KIM" exits to monitor, it does so via 1C05 address.
That code sequence, among other things, calls INITS sub (1E88), before jumping to START (1C4F).
INITS sets various flags and calls CLD and SEI, effectively disabling IRQ.
The PREG variable ($F1, MPU processor status flags) is only saved and restored by monitor for user applications.
This is why IRQ only runs when I actually run my application.
The obvious solution to this issue is to use NMI instead of IRQ, but as I mentioned before, I am unable to make that work with the built-in RIOT in PAL-1.
Likely a conflict with the mode of RIOT chip used / programmed by the monitor.
I've been considering bulding my own expansion card with 6522 chip, which has the needed timers.
That'd allow me to run house keeping tasks in the background intependent of user / front program.
However, I have ordered the RIOT expansion kit instead to have full compatibility with the original KIM-1.
The price is kind of steep, due to shipping cost ($12 for such a small package), but - oh well.
Sourcing my own 6532 would probably cost me even more anyway, quite sure I can't save much, if anything, trying to roll my own RIOT expansion card.
I will build my own ROM and RAM expansions to make up for it (already have needed chips).

Cheers!
---
Marek

Hans Otten

unread,
Jan 30, 2023, 4:26:15 AM1/30/23
to PAL 6502 computer
Teh 6530 and 6532 are a bit different in respect to IRQ and PB7.


Quote from there:

The next difference is the fact that the 6532 has a separate IRQ and PB7 line. As we will see, the functionality of both lines is the same as with the 6530. To create the same circumstances we only have to connect them together.

Marek Karcz

unread,
Jan 30, 2023, 2:02:15 PM1/30/23
to PAL 6502 computer
>> To create the same circumstances we only have to connect them together.

In 6532 there is a dedicated IRQ pin, so it is not shared with PB7 anymore, like it was in 6530.
With 6530, PB7 had to be connected to MPU's NMI to complete the Clock application from the First KIM Book.
One could connect it to IRQ as well, if needed, but in this particular application NMI is desired, to keep the clock running in the background while using other apps or monitor program.
After studying schematic of RIOT expansion board for the PAL-1 I see that I'd have to make a modification to make the clock app work in NMI as it was originally intended. Specifically, I will have to cut IRQ connection from 6532 to IRQ on expansion bus and instead redirect it to NMI pin on the bus. I should probably rig some sort of a switch or a jumper so I can use IRQ or NMI depending on my needs.

On Monday, January 30, 2023 at 4:26:15 AM UTC-5 hansj...@gmail.com wrote:
Teh 6530 and 6532 are a bit different in respect to IRQ and PB7.


Quote from there:

The next difference is the fact that the 6532 has a separate IRQ and PB7 line. As we will see, the functionality of both lines is the same as with the 6530. To create the same circumstances we only have to connect them together [ ... ]

Marek Karcz

unread,
Feb 4, 2023, 3:15:35 AM2/4/23
to PAL 6502 computer
I figured it out. It's quite simple. In order to have clock application from "First Book of KIM" run in the background, I had to connect IRQ and NMI pins on the expansion bus together.
That solves the dillema of IRQ being disabled by monitor program. NMI cannot be disabled / masked, so clock runs even when escaped to monitor and clock display application can be later re-entered fromaddress $03C9.
Of course without optional RIOT, program must be modified to use timer from the on-board RIOT for time keeping, a few simple changes.
Below I include the Clock.ptp file and instructions.

;180300206A1FC901D00D201F1F206A1FC901D0034C051C60A0A000071C
;180318F5FF7FFE08201050A582D029A58138E5831024A580D006A90BEA
;1803301E8570D00AA901C580D014A9288570A9018D0317EE0217A509CE
;18034870AACA10FD30DC6000000052DFF72FFD00108300EFF7F7DF0C63
;180360488A489848A9838D44172C471710FBE680A904C580D038A90B27
;18037800858018F8A58169018581C960D028A9008581A5821869010AB7
;1803908582C960D019A9008582A5831869018583C912D002E684C90C06
;1803A813D004A9018583D8A9F48D4F1768A868AA6840FB00040A100AA7
;1803C0A9008580A9F48D4F17A58185F9A58285FAA58385FB201F1F0D69
;1803D8200003202003EAEAEAEAEAEAEAEAEAEAEAEAEAEAEAEAEAEA11CD
;1803F0EAEAEAEAEAEAEAEAEAEAEAEA4CC9037765EFFF3F204400011089
;00000B000B

Setup instructions:
1) Load program from tape / tape file.

2) Connect IRQ and NMI pins on the expansion bus.

3) Initialize NMI (17FA, 17FB) and IRQ pointers (17FE, 17FF) with 60 and 03.

4) Set up time and AM-PM counter locations on page 0:
    0081 - SEC (second counter)
    0082 - MIN (minute counter)

    0083 - HR   (hour counter)

    0084 - DAY (day counter for AM-PM)

5) Go to address 03C0 and press GO.

Note: To escape clock program to PAL monitor, press 1. Per original documentation, Clock is supposed to be still running in the interrupt. It will only run in background if signal IRQ from RIOT chip is connected to NMI pin on MPU. To return into clock display while clock is running, start program from location 03C9. If IRQ is not connected to NMI (only IRQ is used), clock is actually not running after escape to monitor (stops), because monitor program disables IRQ.

======================
Reply all
Reply to author
Forward
0 new messages