From b7e7864fc58a57725a7dd81710417eb82c8e790b Mon Sep 17 00:00:00 2001 From: cuz Date: Fri, 22 Nov 2002 22:16:20 +0000 Subject: [PATCH] Added wrappers for the kernal functions git-svn-id: svn://svn.cc65.org/cc65/trunk@1587 b7a2c559-68d2-44c3-8de9-860c34a00d81 --- libsrc/plus4/Makefile | 23 ++++++++++- libsrc/plus4/cgetc.s | 13 +++++- libsrc/plus4/clrscr.s | 11 +++++- libsrc/plus4/crt0.s | 76 ++++++++++++++++++++++++++--------- libsrc/plus4/kacptr.s | 20 ++++++++++ libsrc/plus4/kbasin.s | 20 ++++++++++ libsrc/plus4/kbsout.s | 20 ++++++++++ libsrc/plus4/kchkin.s | 20 ++++++++++ libsrc/plus4/kciout.s | 20 ++++++++++ libsrc/plus4/kckout.s | 20 ++++++++++ libsrc/plus4/kclall.s | 20 ++++++++++ libsrc/plus4/kclose.s | 20 ++++++++++ libsrc/plus4/kclrch.s | 20 ++++++++++ libsrc/plus4/kernal.s | 90 ------------------------------------------ libsrc/plus4/kiobase.s | 20 ++++++++++ libsrc/plus4/klisten.s | 20 ++++++++++ libsrc/plus4/kload.s | 20 ++++++++++ libsrc/plus4/kopen.s | 20 ++++++++++ libsrc/plus4/krdtim.s | 22 +++++++++++ libsrc/plus4/kreadst.s | 18 +++++++++ libsrc/plus4/ksave.s | 20 ++++++++++ libsrc/plus4/ksetlfs.s | 20 ++++++++++ libsrc/plus4/ksetnam.s | 62 +++++++++++++++++++++++++++++ libsrc/plus4/ksettim.s | 22 +++++++++++ libsrc/plus4/ktalk.s | 20 ++++++++++ libsrc/plus4/kunlsn.s | 20 ++++++++++ libsrc/plus4/kuntlk.s | 20 ++++++++++ libsrc/plus4/plus4.inc | 11 +++++- 28 files changed, 595 insertions(+), 113 deletions(-) create mode 100644 libsrc/plus4/kacptr.s create mode 100644 libsrc/plus4/kbasin.s create mode 100644 libsrc/plus4/kbsout.s create mode 100644 libsrc/plus4/kchkin.s create mode 100644 libsrc/plus4/kciout.s create mode 100644 libsrc/plus4/kckout.s create mode 100644 libsrc/plus4/kclall.s create mode 100644 libsrc/plus4/kclose.s create mode 100644 libsrc/plus4/kclrch.s delete mode 100644 libsrc/plus4/kernal.s create mode 100644 libsrc/plus4/kiobase.s create mode 100644 libsrc/plus4/klisten.s create mode 100644 libsrc/plus4/kload.s create mode 100644 libsrc/plus4/kopen.s create mode 100644 libsrc/plus4/krdtim.s create mode 100644 libsrc/plus4/kreadst.s create mode 100644 libsrc/plus4/ksave.s create mode 100644 libsrc/plus4/ksetlfs.s create mode 100644 libsrc/plus4/ksetnam.s create mode 100644 libsrc/plus4/ksettim.s create mode 100644 libsrc/plus4/ktalk.s create mode 100644 libsrc/plus4/kunlsn.s create mode 100644 libsrc/plus4/kuntlk.s diff --git a/libsrc/plus4/Makefile b/libsrc/plus4/Makefile index a503225af..8dc900462 100644 --- a/libsrc/plus4/Makefile +++ b/libsrc/plus4/Makefile @@ -19,8 +19,29 @@ OBJS = _scrsize.o \ conio.o \ cputc.o \ crt0.o \ + kacptr.o \ + kbasin.o \ kbhit.o \ - kernal.o \ + kbsout.o \ + kchkin.o \ + kciout.o \ + kckout.o \ + kclall.o \ + kclose.o \ + kclrch.o \ + kiobase.o \ + klisten.o \ + kload.o \ + kopen.o \ + krdtim.o \ + kreadst.o \ + ksave.o \ + ksetlfs.o \ + ksetnam.o \ + ksettim.s \ + ktalk.o \ + kunlsn.o \ + kuntlk.o \ randomize.o \ readjoy.o \ tgi_mode_table.o diff --git a/libsrc/plus4/cgetc.s b/libsrc/plus4/cgetc.s index c48676745..0bcd6013a 100644 --- a/libsrc/plus4/cgetc.s +++ b/libsrc/plus4/cgetc.s @@ -9,9 +9,10 @@ .include "plus4.inc" - ; -------------------------------------------------------------------------- +.segment "LOWMEM" ; Accesses the ROM - must go into low mem + _cgetc: lda KEY_COUNT ; Get number of characters ora FKEY_COUNT ; Or with number of function key chars bne L2 ; Jump if there are already chars waiting @@ -44,7 +45,9 @@ L1: lda KEY_COUNT sta TED_CURSLO ; Cursor off sta TED_CURSHI -L2: jsr KBDREAD ; Read char and return in A +L2: sta ENABLE_ROM ; Bank in the ROM + jsr KBDREAD ; Read char and return in A (ROM routine) + sta ENABLE_RAM ; Reenable the RAM ldx #0 rts @@ -56,6 +59,8 @@ L2: jsr KBDREAD ; Read char and return in A .constructor initkbd .destructor donekbd +.code ; Can go into the normal code segment + .proc initkbd ldy #15 @@ -68,13 +73,17 @@ L2: jsr KBDREAD ; Read char and return in A .endproc +.segment "LOWMEM" ; Accesses the ROM - must go into low mem + .proc donekbd ldx #$39 ; Copy the original function keys + sta ENABLE_ROM ; Bank in the ROM @L1: lda FKEY_ORIG,x sta FKEY_SPACE,x dex bpl @L1 + sta ENABLE_RAM ; Bank out the ROM rts .endproc diff --git a/libsrc/plus4/clrscr.s b/libsrc/plus4/clrscr.s index 4b6c48355..6641c336b 100644 --- a/libsrc/plus4/clrscr.s +++ b/libsrc/plus4/clrscr.s @@ -8,7 +8,16 @@ .include "plus4.inc" -_clrscr = CLRSCR +.segment "LOWCODE" ; Must go into low memory + +.proc _clrscr + sta ENABLE_ROM ; Enable the ROM + jsr CLRSCR ; Call the ROM routine + sta ENABLE_RAM ; Switch back to RAM + rts ; Return to caller +.endproc + + diff --git a/libsrc/plus4/crt0.s b/libsrc/plus4/crt0.s index 9c8b66fea..503d086d5 100644 --- a/libsrc/plus4/crt0.s +++ b/libsrc/plus4/crt0.s @@ -7,61 +7,71 @@ .export _exit .import initlib, donelib .import push0, _main, zerobss - .import MEMTOP, RESTOR, BSOUT, CLRCH + .import __IRQFUNC_TABLE__, __IRQFUNC_COUNT__ .include "zeropage.inc" .include "plus4.inc" ; ------------------------------------------------------------------------ -; BASIC header with a SYS call +; Place the startup code in a special segment to cope with the quirks of +; plus/4 banking. -.code +.segment "STARTUP" - .org $0FFF .word Head ; Load address Head: .word @Next .word 1000 ; Line number .byte $9E,"4109" ; SYS 4109 .byte $00 ; End of BASIC line @Next: .word 0 ; BASIC end marker - .reloc ; ------------------------------------------------------------------------ ; Actual code + sei ; No interrupts since we're banking out the ROM + sta ENABLE_RAM ldx #zpspace-1 L1: lda sp,x sta zpsave,x ; save the zero page locations we need dex bpl L1 + sta ENABLE_ROM + cli ; Close open files - jsr CLRCH + jsr $FFCC ; CLRCH ; Switch to second charset lda #14 - jsr BSOUT + jsr $FFD2 ; BSOUT + +; Setup the IRQ vector in the banked RAM and switch off the ROM + + sei ; No ints, handler not yet in place + sta ENABLE_RAM + lda #IRQ + sta $FFFF + cli ; Allow interrupts ; Clear the BSS data jsr zerobss -; Save system stuff and setup the stack +; Save system stuff and setup the stack. The stack starts at the top of the +; usable RAM. tsx stx spsave ; save system stk ptr - sec - jsr MEMTOP ; Get top memory - cpy #$80 ; We can only use the low 32K :-( - bcc MemOk - ldy #$80 - ldx #$00 -MemOk: stx sp - sty sp+1 ; set argument stack ptr + lda #<$FD00 + sta sp + lda #>$FD00 + sta sp+1 ; Call module constructors @@ -92,10 +102,40 @@ L2: lda zpsave,x dex bpl L2 -; Reset changed vectors +; Enable the ROM, reset changed vectors and return to BASIC + + sta ENABLE_ROM + jmp $FF8A ; RESTOR - jmp RESTOR +; ------------------------------------------------------------------------ +; IRQ handler + +.segment "LOWCODE" + +IRQ: pha + txa + pha + tsx ; Get the stack pointer + lda $0103,x ; Get the saved status register + tax + lda #>irqret ; Push new return address + pha + lda #DOS_FN1 + +; Instead of banking in the ROM, store the values directly into the zeropage + +@L3: stx FNAM_ADR + sty FNAM_ADR+1 + +; Return to caller + + rts + +.endproc + + diff --git a/libsrc/plus4/ksettim.s b/libsrc/plus4/ksettim.s new file mode 100644 index 000000000..b3c59836a --- /dev/null +++ b/libsrc/plus4/ksettim.s @@ -0,0 +1,22 @@ +; +; Ullrich von Bassewitz, 22.11.2002 +; +; SETTIM replacement function +; + + .export SETTIM + + .include "plus4.inc" + +; Set the clock by writing directly to zero page to avoid banking in the ROM + +.proc SETTIM + sei ; No interrupts + sta TIME+2 + stx TIME+1 + sty TIME ; Set the time + cli ; Allow interrupts + rts ; Return to caller +.endproc + + diff --git a/libsrc/plus4/ktalk.s b/libsrc/plus4/ktalk.s new file mode 100644 index 000000000..bad693bfe --- /dev/null +++ b/libsrc/plus4/ktalk.s @@ -0,0 +1,20 @@ +; +; Ullrich von Bassewitz, 22.11.2002 +; +; TALK replacement function +; + + .export TALK + + .include "plus4.inc" + +.segment "LOWCODE" ; Must go into low memory + +.proc TALK + sta ENABLE_ROM ; Enable the ROM + jsr $FFB4 ; Call the ROM routine + sta ENABLE_RAM ; Switch back to RAM + rts ; Return to caller +.endproc + + diff --git a/libsrc/plus4/kunlsn.s b/libsrc/plus4/kunlsn.s new file mode 100644 index 000000000..486bb969b --- /dev/null +++ b/libsrc/plus4/kunlsn.s @@ -0,0 +1,20 @@ +; +; Ullrich von Bassewitz, 22.11.2002 +; +; UNLSN replacement function +; + + .export UNLSN + + .include "plus4.inc" + +.segment "LOWCODE" ; Must go into low memory + +.proc UNLSN + sta ENABLE_ROM ; Enable the ROM + jsr $FFAE ; Call the ROM routine + sta ENABLE_RAM ; Switch back to RAM + rts ; Return to caller +.endproc + + diff --git a/libsrc/plus4/kuntlk.s b/libsrc/plus4/kuntlk.s new file mode 100644 index 000000000..52a5633d8 --- /dev/null +++ b/libsrc/plus4/kuntlk.s @@ -0,0 +1,20 @@ +; +; Ullrich von Bassewitz, 22.11.2002 +; +; UNTLK replacement function +; + + .export UNTLK + + .include "plus4.inc" + +.segment "LOWCODE" ; Must go into low memory + +.proc UNTLK + sta ENABLE_ROM ; Enable the ROM + jsr $FFAB ; Call the ROM routine + sta ENABLE_RAM ; Switch back to RAM + rts ; Return to caller +.endproc + + diff --git a/libsrc/plus4/plus4.inc b/libsrc/plus4/plus4.inc index 259fc7540..680a9611a 100644 --- a/libsrc/plus4/plus4.inc +++ b/libsrc/plus4/plus4.inc @@ -6,18 +6,22 @@ ; --------------------------------------------------------------------------- ; Zero page, Commodore stuff +TMPPTR = $22 ; Temporary ptr used by BASIC ST = $90 ; IEC status byte - TIME = $A3 ; 60HZ clock FNAM_LEN = $AB ; Length of filename +LFN = $AC ; Logical file number SECADR = $AD ; Secondary address DEVNUM = $AE ; Device number +FNAM_ADR = $AF ; Pointer to filename for OPEN KEY_COUNT = $EF ; Number of keys in input buffer CURS_X = $CA ; Cursor column CURS_Y = $CD ; Cursor row SCREEN_PTR = $C8 ; Pointer to current char in text screen CRAM_PTR = $EA ; Pointer to current char in color RAM +DOS_FN1 = $25E ; DOS filename buffer #1 +DOS_FN1LEN = $26E ; DOS filename length #1 CHARCOLOR = $53B FKEY_COUNT = $55D ; Characters for function key FKEY_SPACE = $55F ; Function key definitions @@ -63,5 +67,10 @@ TED_HPOS = $FF1E TED_ROMSEL = $FF3E TED_RAMSEL = $FF3F +; --------------------------------------------------------------------------- +; RAM/ROM selection addresses + +ENABLE_ROM = $FF3E +ENABLE_RAM = $FF3F -- 2.39.5