; 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 = $0380; BASICMain Routine
  chrgot = $0386; doesn't update the processing
  mmureg = $ff00; MMUConfiguration Register
  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 $3d; increment TXTPTR
  bne +
  inc $3e
+ jsr chrgot
  cmp #$21; check for the '!' exclamation character
  beq +
- jmp chrgot; otherwise abort to usual routine.
+ lda $7f; check for direct mode flag
  bne -; if not, go to the usual routine
  lda #$00; select bank 15
  sta mmureg

; 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 C128 RTC file

