; Sets up a wedge to tell time from a RTC-equipped device.
; When you RUN it, type the keypress '!' and hit the RETURN key to see the time
; and the date. Be sure to change the devadd to the device number containing the RTC.
; This technique illustrates how a simple command can be WEDGEd into the BASIC
; interpreter, and gives a sampling of accessing the Command channel of a disk drive.
; By Todd S. Elliott

; equates
  devadd = 11; Device Address 11
  chrget = $73; BASICMain Routine
  chrgot = $79; doesn't update the processing
  setlfs = $ffba; set logical file
  setnam = $ffbd; set command name
  open   = $ffc0; Kernal OPEN routine
  chkin  = $ffc6; redirect character input
  chkout = $ffc9; redirect character output
  chrout = $ffd2; Outputs a character
  clall  = $ffe7; closes all files
  chrin  = $ffcf; inputs a character
  clrchn = $ffcc; clears all channels
 
; set up CHRGET routine
  lda #$4c ; JMPinstruction
  sta chrget
  lda <wedge
  sta chrget+1
  lda >wedge
  sta chrget+2
  rts; we're done!

; Wedge routine
wedge inc $7a; increment TXTPTR
  bne +
  inc $7b
+ jsr chrgot
  cmp #$21; check for the '!' exclamation character
  beq +
- jmp chrgot; otherwise abort to usual routine.
+ lda $9d; check for direct mode flag
  bpl -; if not, go to the usual routine

; open the file first
  lda #15
  tay
  ldx #devadd; device number #11
  jsr setlfs; equal to 15,11,15
  lda #$00
  jsr setnam; specify no filename
  jsr open; equal to open15,11,15 and that's it.
  ldx #15
  jsr chkout; redirect output to disk
  ldy #4
- lda command,y
  jsr chrout; prints out the characters to the disk
  dey
  bpl -
  jsr clrchn
  ldx #15
  jsr chkin
- jsr chrin;
  jsr chrout
  cmp #13; check for end of message
  bne -
  jsr clall

; finish up routine
  jmp chrget

; data used by program
command .byte 13,65,82,45,84

; End file 64 RTC program


