;; ;; Copyright (c) 2019 Marco Granati ;; ;; Permission to use, copy, modify, and distribute this software for any ;; purpose with or without fee is hereby granted, provided that the above ;; copyright notice and this permission notice appear in all copies. ;; ;; THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES ;; WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF ;; MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ;; ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES ;; WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ;; ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF ;; OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ;; ;; project: c16 bios ;; name: bios.inc ;; purpose: bios interface ;; revision: 1.0 ;; date: 2019/03/01 ;----------------------------------------------------------------------------- ; BIOS INTERFACE ; ; Bios functions are called by the 'cop $nn' instruction, where $nn, the ; signature byte, is the function number. ; These functions preserve status register (but not carry flag) & all ; register, unless otherwise stated. ; If an error occur the carry flag is set and the low byte of y register ; hold an error code, otherwise carry flag is reset and y register is ; either preserved or return a function result (if any). ; ; If a functions need some parameters on entry, they should be passed ; either by register or by stack: in the last case bios functions follow ; 'pascal convention' (parameters pushed on stack left-to-right). ; ; Stack cleanup is automatic when function exit. ; ; Below follow macro's for easily call bios functions by symbolic name. ; ;----------------------------------------------------------------------------- ;----------------------------------------------------------------------------- ; ; schrout function $00 ; ; print character on screen at current position ; ; entry: a = character ; ; exit: cf always cleared ; ;----------------------------------------------------------------------------- scharout .macro ; source code: f8/video.asm cop $00 .endm ;----------------------------------------------------------------------------- ;----------------------------------------------------------------------------- ; ; sinlinep function $01 ; ; print inline coded string (terminated with 0) on screen ; the string is coded inline after the calling instruction ; and terminate with a null ; ; entry: inline coded string ; ; exit: cf always cleared ; ;----------------------------------------------------------------------------- sinlinep .macro ; source code: f8/video.asm cop $01 .endm ;----------------------------------------------------------------------------- ;----------------------------------------------------------------------------- ; ; sstrout function $02 ; ; print string (terminated with 0) on screen ; ; entry: c = string address (16 bits) ; x = string bank ; ; ; exit: cf always cleared ; ;----------------------------------------------------------------------------- sstrout .macro ; source code: f8/video.asm cop $02 .endm ;----------------------------------------------------------------------------- ;----------------------------------------------------------------------------- ; ; sbufout function $03 ; ; print buffer on screen ; ; entry: c = buffer address (16 bits) ; x = buffer bank ; y = buffer size (16 bits) ; ; exit: cf always cleared ; ;----------------------------------------------------------------------------- sbufout .macro ; source code: f8/video.asm cop $03 .endm ;----------------------------------------------------------------------------- ;----------------------------------------------------------------------------- ; ; getkey function $04 ; ; get & remove a key from keyboard buffer (if available) ; ; entry: none ; ; exit: a = key code ; status register affected so: ; NF = 1 if key release (otherwise is a key make) ; ZF = 1 if buffer is empty (no key available) ; CF = 1 if key is control/extended, otherwise is acii ; ;----------------------------------------------------------------------------- getkey .macro ; source code: f8/video.asm cop $04 .endm ;----------------------------------------------------------------------------- ;----------------------------------------------------------------------------- ; ; kreadstr function $05 ; ; enter in edit mode, read a string from keyboard, store string in ; the buffer passed by caller, until cr or shift-cr is pressed ; ; prototype: kreadstr(pbuf, bsize, bmode) ; ; entry: param's passed on stack (5 bytes) ; pbuf = destination buffer long pointer ; bsize = buffer size (if bSize = 0 assume bSize = 256) ; bmode = edit mode ; <7>: line edit mode (otherwise full screen editor) ; <6>: single row line edit (ignored if bit 7 = 0) ; <0>: history on ; ; exit: a = input terminator (cr or shift-cr) ; y = preserved or error code if carry set (ed_data error) ; x = string length ; ; notes: ; destination buffer is filled with a null terminated string ; input terminator (cr or shift-cr) is not stored ; if buffer is too small, the string is truncated and the ; function return carry set ; buffer should have room for null terminator ; ;----------------------------------------------------------------------------- kreadstr .macro ; source code: f8/video.asm cop $05 .endm ;----------------------------------------------------------------------------- ; following functions must be implemented tcharout .macro cop $06 .endm tinlinep .macro cop $07 .endm tstrout .macro cop $08 .endm tbufout .macro cop $09 .endm tgetkey .macro cop $0a .endm treadstr .macro cop $0b .endm ;----------------------------------------------------------------------------- ; ; gettime function $0c - sub-function $00 ; ; get full time & date from rtc chip and put in 8-bytes user buffer ; ; entry: c = destination buffer address ; y = destination buffer bank ; ; exit: user buffer is filled with 8 bytes in that order: ; - seconds, minutes, hours, dayofweek ; - day, month, year, century ; dayofweek: 1=sunday, 2=monday, ..., 7=saturday ; cf always reset ; x = $00 (sub-function number) ; c,y preserved ; ;----------------------------------------------------------------------------- gettime .macro ; source code: f8/rtc.asm ldx #0 cop $0c .endm ;----------------------------------------------------------------------------- ;----------------------------------------------------------------------------- ; ; setdate function $0c - sub-function $01 ; ; set full date&time from initial portion of input string pointed by pbuf ; input string is expected in the following form: ; ; ccyyMMdd [hhmmss] ; ; cc = century (2 digits), yy = year (2 digits), MM = month (2 digits) ; dd = day (2 digits), hh = hours (2 digits), mm = minutes (2 digits) ; ss = seconds (2 digits). ; day of week (sunday, monday, ...) is automatic ; ; time part of input string is optional ; ; entry: c = input string address ; y = input string bank ; ; exit: cf = 1 if error (wrong data/time), y = ed_data error code ; x = $01 (sub-function number) ; ;----------------------------------------------------------------------------- setdate .macro ; source code: f8/rtc.asm ldx #1 cop $0c .endm ;----------------------------------------------------------------------------- ;----------------------------------------------------------------------------- ; ; settime function $0c - sub-function $02 ; ; set time only from initial portion of input string pointed by pbuf ; input string is expected in the following form: ; ; hhmmss ; ; hh = hours (2 digits), mm = minutes (2 digits), ss = seconds (2 digits) ; ; entry: c = input string address ; y = input string bank ; ; exit: cf = 1 if error (wrong time), y = ed_data error code ; x = $02 (sub-function number) ; ;----------------------------------------------------------------------------- settime .macro ; source code: f8/rtc.asm ldx #2 cop $0c .endm ;----------------------------------------------------------------------------- ;----------------------------------------------------------------------------- ; end of file ;-----------------------------------------------------------------------------