From: cuz Date: Mon, 15 Dec 2003 21:10:24 +0000 (+0000) Subject: New EM driver for the C16 X-Git-Tag: V2.12.0~1044 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=1c6de7dab26a7900edb9fd17b5c31ccf00cff67d;p=cc65 New EM driver for the C16 git-svn-id: svn://svn.cc65.org/cc65/trunk@2762 b7a2c559-68d2-44c3-8de9-860c34a00d81 --- diff --git a/libsrc/Makefile b/libsrc/Makefile index 6988fc51f..9cf401d74 100644 --- a/libsrc/Makefile +++ b/libsrc/Makefile @@ -99,6 +99,7 @@ c16lib: done mv c16/crt0.o c16.o cp c16/*.joy . + cp c16/*.emd . #----------------------------------------------------------------------------- # C64 @@ -131,7 +132,7 @@ c128lib: CFLAGS="-Osir -g -T -t c128 --forget-inc-paths -I. -I../../include" \ $(MAKE) -C $$i || exit 1; \ $(AR) a c128.lib $$i/*.o;\ - done + done mv c128/crt0.o c128.o cp c128/*.emd . cp c128/*.joy . diff --git a/libsrc/c16/Makefile b/libsrc/c16/Makefile index 80adaf9d1..e101f7189 100644 --- a/libsrc/c16/Makefile +++ b/libsrc/c16/Makefile @@ -20,6 +20,9 @@ %.joy: %.o ../runtime/zeropage.o @$(LD) -t module -o $@ $^ +%.ser: %.o ../runtime/zeropage.o + @$(LD) -t module -o $@ $^ + %.tgi: %.o ../runtime/zeropage.o @$(LD) -t module -o $@ $^ @@ -46,10 +49,12 @@ OBJS = _scrsize.o \ #-------------------------------------------------------------------------- # Drivers -EMDS = +EMDS = c16-ram.emd JOYS = c16-stdjoy.joy +SERS = + TGIS = #-------------------------------------------------------------------------- @@ -57,14 +62,14 @@ TGIS = .PHONY: all clean zap -all: $(OBJS) $(EMDS) $(JOYS) $(TGIS) +all: $(OBJS) $(EMDS) $(JOYS) $(SERS) $(TGIS) ../runtime/zeropage.o: $(MAKE) -C $(dir $@) $(notdir $@) clean: - @$(RM) $(OBJS) $(EMDS:.emd=.o) $(JOYS:.joy=.o) $(TGIS:.tgi=.o) + @$(RM) $(OBJS) $(EMDS:.emd=.o) $(JOYS:.joy=.o) $(SERS:.ser=.o) $(TGIS:.tgi=.o) zap: clean - @$(RM) $(EMDS) $(JOYS) $(TGIS) + @$(RM) $(EMDS) $(JOYS) $(SERS) $(TGIS) diff --git a/libsrc/c16/c16-ram.s b/libsrc/c16/c16-ram.s new file mode 100644 index 000000000..3d797c6ab --- /dev/null +++ b/libsrc/c16/c16-ram.s @@ -0,0 +1,295 @@ +; +; Extended memory driver for the C16 hidden RAM. Driver works without +; problems when statically linked. +; +; Ullrich von Bassewitz, 2003-12-15 +; + + .include "zeropage.inc" + + .include "em-kernel.inc" + .include "em-error.inc" + .include "../plus4/plus4.inc" + + .macpack generic + + +; ------------------------------------------------------------------------ +; Header. Includes jump table + +.segment "JUMPTABLE" + +; Driver signature + + .byte $65, $6d, $64 ; "emd" + .byte $00 ; EM API version number + +; Jump table. + + .word INSTALL + .word UNINSTALL + .word PAGECOUNT + .word MAP + .word USE + .word COMMIT + .word COPYFROM + .word COPYTO + +; ------------------------------------------------------------------------ +; Constants + +BASE = $8000 + +; ------------------------------------------------------------------------ +; Data. + +.bss +pages: .res 1 ; Number of pages +curpage: .res 1 ; Current page number +window: .res 256 ; Memory "window" + +.code + +; ------------------------------------------------------------------------ +; INSTALL routine. Is called after the driver is loaded into memory. If +; possible, check if the hardware is present and determine the amount of +; memory available. +; Must return an EM_ERR_xx code in a/x. +; + +INSTALL: + +; Determine how much memory is available. We will use all memory above +; $8000 up to MEMTOP + + sec + jsr $FF99 ; MEMTOP: Get top memory into Y/X + tya + sub #>BASE ; Low 32 K are used + bcc nomem + beq nomem ; Offering zero pages is a bad idea + sta pages + + ldx #$FF + stx curpage ; Invalidate the current page + inx ; X = 0 + txa ; A = X = EM_ERR_OK + rts + +nomem: ldx #>EM_ERR_NO_DEVICE + lda #BASE + sta ptr1+1 + ldy #$00 + sty ptr1 + + lda #window + sta ptr2+1 + +; Transfer one page + + jsr transfer ; Transfer one page + +; Return the memory window + + lda #window ; Return the window address + rts + +; ------------------------------------------------------------------------ +; USE: Tell the driver that the window is now associated with a given page. + +USE: sta curpage ; Remember the page + lda #window ; Return the window + rts + +; ------------------------------------------------------------------------ +; COMMIT: Commit changes in the memory window to extended storage. + +COMMIT: lda curpage ; Get the current page + bmi done ; Jump if no page mapped + + add #>BASE + sta ptr2+1 + ldy #$00 + sty ptr2 + + lda #window + sta ptr1+1 + +; Transfer one page. Y must be zero on entry. Because we bank out the +; kernal, we will run the routine with interrupts disabled but leave +; short breath times. Unroll the following loop to make it somewhat faster. + +transfer: + sei + sta ENABLE_RAM + + lda (ptr1),y + sta (ptr2),y + iny + + lda (ptr1),y + sta (ptr2),y + iny + + lda (ptr1),y + sta (ptr2),y + iny + + lda (ptr1),y + sta (ptr2),y + iny + + lda (ptr1),y + sta (ptr2),y + iny + + lda (ptr1),y + sta (ptr2),y + iny + + lda (ptr1),y + sta (ptr2),y + iny + + lda (ptr1),y + sta (ptr2),y + iny + + sta ENABLE_ROM + cli + + bne transfer + +; Done + +done: rts + +; ------------------------------------------------------------------------ +; COPYFROM: Copy from extended into linear memory. A pointer to a structure +; describing the request is passed in a/x. +; The function must not return anything. +; + +COPYFROM: + sta ptr3 + stx ptr3+1 ; Save the passed em_copy pointer + + ldy #EM_COPY_OFFS + lda (ptr3),y + sta ptr1 + ldy #EM_COPY_PAGE + lda (ptr3),y + add #>BASE + sta ptr1+1 ; From + + ldy #EM_COPY_BUF + lda (ptr3),y + sta ptr2 + iny + lda (ptr3),y + sta ptr2+1 ; To + +common: ldy #EM_COPY_COUNT+1 + lda (ptr3),y ; Get number of pages + beq @L2 ; Skip if no full pages + sta tmp1 + +; Copy full pages allowing interrupts after each page copied + + ldy #$00 +@L1: jsr transfer + inc ptr1+1 + inc ptr2+1 + dec tmp1 + bne @L1 + +; Copy the remainder of the page + +@L2: ldy #EM_COPY_COUNT + lda (ptr3),y ; Get bytes in last page + beq @L4 + tax + + sei ; Disable ints + sta ENABLE_RAM ; Bank out the ROM + +; Transfer the bytes in the last page + + ldy #$00 +@L3: lda (ptr1),y + sta (ptr2),y + iny + dex + bne @L3 + +; Restore the old memory configuration, allow interrupts + + sta ENABLE_ROM + cli + +; Done + +@L4: rts + +; ------------------------------------------------------------------------ +; COPYTO: Copy from linear into extended memory. A pointer to a structure +; describing the request is passed in a/x. +; The function must not return anything. +; + +COPYTO: sta ptr3 + stx ptr3+1 ; Save the passed em_copy pointer + + ldy #EM_COPY_OFFS + lda (ptr3),y + sta ptr2 + ldy #EM_COPY_PAGE + lda (ptr3),y + add #>BASE + sta ptr2+1 ; To + + ldy #EM_COPY_BUF + lda (ptr3),y + sta ptr1 + iny + lda (ptr3),y + sta ptr1+1 ; From + + jmp common + + diff --git a/packages/rpm/redhat/cc65.spec b/packages/rpm/redhat/cc65.spec index 16b92df4c..7d4cdef5b 100644 --- a/packages/rpm/redhat/cc65.spec +++ b/packages/rpm/redhat/cc65.spec @@ -195,6 +195,7 @@ programs for the Commodore C16/116 using the cc65 crosscompiler. %files c16 %attr(644,root,root) /usr/lib/cc65/lib/c16.lib %attr(644,root,root) /usr/lib/cc65/lib/c16.o +%attr(644,root,root) /usr/lib/cc65/emd/c16-*.emd %attr(644,root,root) /usr/lib/cc65/joy/c16-*.joy