Path: utzoo!censor!geac!torsqnt!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!ucsd!ucbvax!bloom-beacon!mcgill-vision!thunder.mcrcim.mcgill.edu!clyde.concordia.ca!ganymede!terre.DMI.USherb.CA!sd05 From: sd05@terre.DMI.USherb.CA (Sylvain Tremblay / Eric Trepanier) Newsgroups: comp.sys.cbm Subject: Re: ML help!!! Message-ID: <1990Dec3.014909.3071@DMI.USherb.CA> Date: 3 Dec 90 01:49:09 GMT References: <1990Nov30.161424.2348@uoft02.utoledo.edu> Sender: usenet@DMI.USherb.CA (Pour courrier Usenet) Organization: Universite de Sherbrooke, Quebec Lines: 98 Nntp-Posting-Host: terre.dmi.usherb.ca In article <1990Nov30.161424.2348@uoft02.utoledo.edu> grx0644@uoft02.utoledo.edu writes: >I wrote an assembly program for my c128. Its a simple program that writes the >time on the screen in the upper left hand corner. To be useful, it is started >by a sys statement and returns basic when finished.It uses the cassette buffer >as its home. I want to have the C128 to execute this program as part of the >C128's normal routine so I don't have to keep sending a sys command. is there >a way to patch something the normal operating routine that will cause the >computer to JSR to my routine and then RTS back to what ever it was doing, >without interupting any basic programs that may be executing at the same time? >I am new to assembly so if anyone know the answer, please, I beg you, in every >day terms!!! :) >Thanks in advance >Tony. What you must do is an interrupt service routine. The 6502 processor is interrupted every 1/60th second to perform some housekeeping chores, such as scanning the keyboard for a key, displaying any new characters, and so on... When the "interruption" occurs, the current processor's volatil state (Acc, Xreg, Yreg, Processor Status, MMU cfg, ...) is saved on the stack, and then the 8502 jumps through an indirect vector to its interrupt service routine. When it is done, it exits via a RTI (ReTurn from Interrupt) instead of a RTS. It is possible to have a custom routine executed as part of the normal interrupt sequence by making the indirect vector point to your own routine, instead of the Kernal's. Once your routine is executed, you should JMP to the remainder of the Kernal's interrupt service routine, or else the 8502 will not scan the keyboard anymore, and the computer will appear to be locked (crashed). It is important to disable interruptions (with a SEI, SEt Interrupt disable bit) while you are modifying the indirect vector. If you don't, an interruption might occur just after you modify the low byte, but before you modify the high byte. This would cause the 8502 to jump to an invalid address, and thus, probably crash. This is what your code should look like: InitClk: sei ; disable interruptions lda IIRQ ; get interrupt vector value, low byte sta JumpIRQ+1 ; and store at end of custom interrupt routine lda IIRQ+1 ; get interrupt vector value, high byte sta JumpIRQ+2 ; and store at end of custom interrupt routine lda #Clock ; get high byte of custom interrupt routine sta IIRQ+1 ; and store at end of custom interrupt routine cli ; reenable interruptions rts ; exit from clock initialisation routine Clock: ... ; Clock interrupt service routine JumpIRQ: jmp $FFFF ; Jump to the remainder of the IRQ routine When you want to initialize the clock, just do a SYS to InitClk. And, provided that your clock service routine is ok, it should run continuously, without disturbing any basic program. You should probably have a clock disable routine which would restore the interrupt vector (IIRQ = $0314) back to its original value. One thing you must keep in mind is that you CANNOT fiddle with the VDC while you're in your interrupt routine. This is a more delicate subject and would require that you know exactly how the VDC works, and I'm not sure you do. This means that your clock can only work in 40 columns mode. It could be made to work in 80 columns mode too, but it would require a lot more work on your part. Stick with to 40 column clock first. If you can do it, then try doing it in 80 column. Well I hope that this short letter gives you a hint. Interrupts are the most powerful and intersting aspects of machine language programming. If you learn to master them, you make your C128 do great things, like a mouse driver or background jobs, or so on... There is a book by Jim Butterfield that I highly recommend to any novice or intermediate machine language programmers, it is called: Machine Language For The Commodore 64, 128 And Other Commodore Computers Its publisher's address is: A Brady Book, Published by Prentice Hall Press, New York, New York 10023 This book is an excellent ml tutorial which covers every aspects of machine language programming on the C128. Eric Trepanier -- +-----------------------------------------------------------------///------+ | Sylvain Tremblay INTERNET: sd05@terre.USherb.CA __ /// /| | | Eric Trepanier CIS: 71640,666 \\\/// # | | | Sherbrooke, Qc, Can TEL: (819) 820-0976 \XX/ _|_ |