This commit is contained in:
jede
2017-10-23 23:04:22 +02:00
267 changed files with 9426 additions and 5145 deletions

View File

@@ -1,4 +1,3 @@
ifneq ($(shell echo),)
CMD_EXE = 1
endif
@@ -15,24 +14,24 @@ CBMS = c128 \
GEOS = geos-apple \
geos-cbm
TARGETS = apple2 \
apple2enh \
atari \
atarixl \
atari2600 \
atari5200 \
atmos \
TARGETS = apple2 \
apple2enh \
atari \
atarixl \
atari2600 \
atari5200 \
atmos \
creativision \
$(CBMS) \
$(GEOS) \
gamate \
lynx \
nes \
osic1p \
pce \
sim6502 \
sim65c02 \
supervision\
$(CBMS) \
$(GEOS) \
gamate \
lynx \
nes \
osic1p \
pce \
sim6502 \
sim65c02 \
supervision \
telestrat
DRVTYPES = emd \
@@ -41,13 +40,13 @@ DRVTYPES = emd \
ser \
tgi
OUTPUTDIRS := lib \
asminc \
cfg \
include \
$(subst ../,,$(filter-out $(wildcard ../include/*.*),$(wildcard ../include/*)))\
$(subst ../,,$(wildcard ../target/*/drv/*))\
$(subst ../,,$(wildcard ../target/*/util))\
OUTPUTDIRS := lib \
asminc \
cfg \
include \
$(subst ../,,$(filter-out $(wildcard ../include/*.*),$(wildcard ../include/*))) \
$(subst ../,,$(wildcard ../target/*/drv/*)) \
$(subst ../,,$(wildcard ../target/*/util))
.PHONY: all mostlyclean clean install zip lib $(TARGETS)
@@ -73,7 +72,7 @@ endif
ifndef TARGET
datadir = $(prefix)/share/cc65
datadir = $(PREFIX)/share/cc65
all lib: $(TARGETS)
@@ -93,7 +92,7 @@ INSTALL = install
define INSTALL_recipe
$(if $(prefix),,$(error variable `prefix' must be set))
$(if $(PREFIX),,$(error variable `PREFIX' must be set))
$(INSTALL) -d $(DESTDIR)$(datadir)/$(dir)
$(INSTALL) -m0644 ../$(dir)/*.* $(DESTDIR)$(datadir)/$(dir)
@@ -197,6 +196,7 @@ DEPS = $(OBJS:.o=.d)
EXTRA_SRCPAT = $(SRCDIR)/extra/%.s
EXTRA_OBJPAT = ../lib/$(TARGET)-%.o
EXTRA_OBJS := $(patsubst $(EXTRA_SRCPAT),$(EXTRA_OBJPAT),$(wildcard $(SRCDIR)/extra/*.s))
DEPS += $(EXTRA_OBJS:../lib/%.o=../libwrk/$(TARGET)/%.d)
ZPOBJ = ../libwrk/$(TARGET)/zeropage.o
ifeq ($(TARGET),$(filter $(TARGET),$(EXTZP)))
@@ -280,9 +280,9 @@ endef # COMPILE_recipe
../libwrk/$(TARGET)/%.o: %.c | ../libwrk/$(TARGET)
$(COMPILE_recipe)
$(EXTRA_OBJPAT): $(EXTRA_SRCPAT) | ../lib
$(EXTRA_OBJPAT): $(EXTRA_SRCPAT) | ../libwrk/$(TARGET) ../lib
@echo $(TARGET) - $(<F)
@$(CA65) -t $(TARGET) $(CA65FLAGS) -o $@ $<
@$(CA65) -t $(TARGET) $(CA65FLAGS) --create-dep $(@:../lib/%.o=../libwrk/$(TARGET)/%.d) -o $@ $<
../lib/$(TARGET).lib: $(OBJS) | ../lib
$(AR65) a $@ $?

View File

@@ -46,17 +46,6 @@ PREAD := $FB1E ; Read paddle in X, return AD conv. value in Y
.addr $0000
; Button state masks (8 values)
.byte $10
.byte $20
.byte $04
.byte $08
.byte $40
.byte $80
.byte $00 ; Future expansion
.byte $00 ; Future expansion
; Jump table
.addr INSTALL
@@ -119,7 +108,7 @@ READJOY:
lda BUTN0-1,x ; Check button (1, 3)
asl
tya
ror ; FIRE DOWN !UP RIGHT !LEFT 0 0 0
ror ; BTN DOWN !UP RIGHT !LEFT 0 0 0
; Read secondary button
tay
@@ -130,10 +119,10 @@ READJOY:
lda BUTN0-1,x ; Check button (2, 0)
asl
tya
ror ; FIRE2 FIRE DOWN !UP RIGHT !LEFT 0 0
ror ; BTN2 BTN DOWN !UP RIGHT !LEFT 0 0
; Finalize
eor #%00010100 ; FIRE2 FIRE DOWN UP RIGHT LEFT 0 0
eor #%00010100 ; BTN2 BTN DOWN UP RIGHT LEFT 0 0
ldx #$00
bit $C080 ; Switch in LC bank 2 for R/O
rts

View File

@@ -6,9 +6,9 @@
;
.include "atari.inc"
.export _cgetc,setcursor
.export _cgetc
.import setcursor
.import KEYBDV_handler
.import cursor,mul40
_cgetc:
jsr setcursor
@@ -29,43 +29,3 @@ _cgetc:
pha
rts
.endif
.proc setcursor
ldy #0
lda OLDCHR
sta (OLDADR),y
lda ROWCRS
jsr mul40
clc
adc SAVMSC ; add start of screen memory
sta OLDADR
txa
adc SAVMSC+1
sta OLDADR+1
lda COLCRS
adc OLDADR
sta OLDADR
bcc nc
inc OLDADR+1
nc: lda (OLDADR),y
sta OLDCHR
ldx cursor ; current cursor setting as requested by the user
beq off
ldx #0
beq cont
off: inx
cont: stx CRSINH ; update system variable
beq turnon
and #$7f ; clear high bit / inverse flag
finish: sta (OLDADR),y ; update on-screen display
rts
turnon: ora #$80 ; set high bit / inverse flag
bne finish
.endproc

View File

@@ -35,17 +35,6 @@
.addr $0000
; Button state masks (8 values)
.byte $02 ; JOY_UP
.byte $04 ; JOY_DOWN
.byte $08 ; JOY_LEFT
.byte $10 ; JOY_RIGHT
.byte $01 ; JOY_FIRE
.byte $00 ; JOY_FIRE2 not available
.byte $00 ; Future expansion
.byte $00 ; Future expansion
; Jump table.
.addr INSTALL
@@ -115,10 +104,12 @@ READJOY:
; Read joystick
lda PORTA ; get position
and #%00001111
lda STRIG0 ; get button
asl a
ora TRIG0 ; add button information
eor #%00011111
asl a
asl a
asl a
ora PORTA ; add position information
eor #$1F
ldx #0 ; fix X
rts

View File

@@ -34,17 +34,6 @@
.addr $0000
; Button state masks (8 values)
.byte $01 ; JOY_UP
.byte $02 ; JOY_DOWN
.byte $04 ; JOY_LEFT
.byte $08 ; JOY_RIGHT
.byte $10 ; JOY_FIRE
.byte $00 ; JOY_FIRE2 not available
.byte $00 ; Future expansion
.byte $00 ; Future expansion
; Jump table.
.addr INSTALL

48
libsrc/atari/setcursor.s Normal file
View File

@@ -0,0 +1,48 @@
;
; Christian Groessler, November-2002
;
; cursor handling, internal function
.include "atari.inc"
.import cursor,mul40
.export setcursor
.proc setcursor
ldy #0
lda OLDCHR
sta (OLDADR),y
lda ROWCRS
jsr mul40
clc
adc SAVMSC ; add start of screen memory
sta OLDADR
txa
adc SAVMSC+1
sta OLDADR+1
lda COLCRS
adc OLDADR
sta OLDADR
bcc nc
inc OLDADR+1
nc: lda (OLDADR),y
sta OLDCHR
ldx cursor ; current cursor setting as requested by the user
beq off
ldx #0
beq cont
off: inx
cont: stx CRSINH ; update system variable
beq turnon
and #$7f ; clear high bit / inverse flag
finish: sta (OLDADR),y ; update on-screen display
rts
turnon: ora #$80 ; set high bit / inverse flag
bne finish
.endproc

View File

@@ -27,17 +27,6 @@
.addr $0000
; Button state masks (8 values)
.byte $01 ; JOY_UP
.byte $02 ; JOY_DOWN
.byte $04 ; JOY_LEFT
.byte $08 ; JOY_RIGHT
.byte $10 ; JOY_FIRE
.byte $20 ; JOY_FIRE2
.byte $00 ; Future expansion
.byte $00 ; Future expansion
; Jump table.
.addr INSTALL
@@ -99,7 +88,7 @@ READJOY:
lda #0 ; Initialize return value
cmp TRIG0,y
bne @notrg
lda #$10 ; JOY_FIRE
lda #$10 ; JOY_BTN
; Read joystick

View File

@@ -1,14 +1,18 @@
;
; Ullrich von Bassewitz, 2003-04-13
; 2003-04-13, Ullrich von Bassewitz
; 2017-06-15, Greg King
;
; void gotoxy (unsigned char x, unsigned char y);
;
.export _gotoxy
.export gotoxy, _gotoxy
.import popa
.include "atmos.inc"
gotoxy: jsr popa ; Get Y
.proc _gotoxy
sta CURS_Y ; Set Y
@@ -17,5 +21,3 @@
rts
.endproc

View File

@@ -28,17 +28,6 @@
.addr $0000
; Button state masks (8 values)
.byte $10 ; JOY_UP
.byte $08 ; JOY_DOWN
.byte $01 ; JOY_LEFT
.byte $02 ; JOY_RIGHT
.byte $20 ; JOY_FIRE
.byte $00 ; Future expansion
.byte $00 ; Future expansion
.byte $00 ; Future expansion
; Jump table.
.addr INSTALL

View File

@@ -30,17 +30,6 @@
.addr $0000
; Button state masks (8 values)
.byte $01 ; JOY_UP
.byte $02 ; JOY_DOWN
.byte $04 ; JOY_LEFT
.byte $08 ; JOY_RIGHT
.byte $10 ; JOY_FIRE
.byte $00 ; JOY_FIRE2 unavailable
.byte $00 ; Future expansion
.byte $00 ; Future expansion
; Jump table.
.addr INSTALL

View File

@@ -30,17 +30,6 @@
.addr $0000
; Button state masks (8 values)
.byte $01 ; JOY_UP
.byte $02 ; JOY_DOWN
.byte $04 ; JOY_LEFT
.byte $08 ; JOY_RIGHT
.byte $10 ; JOY_FIRE
.byte $00 ; JOY_FIRE2 unavailable
.byte $00 ; Future expansion
.byte $00 ; Future expansion
; Jump table.
.addr INSTALL
@@ -104,7 +93,7 @@ joy1: lda #$7F
sei
sta CIA1_PRA
lda CIA1_PRB
cli
back: cli
and #$1F
eor #$1F
rts
@@ -118,9 +107,4 @@ joy2: ldx #0
sta CIA1_DDRA
lda CIA1_PRA
sty CIA1_DDRA
cli
and #$1F
eor #$1F
rts
jmp back

14
libsrc/c128/kbrepeat.s Normal file
View File

@@ -0,0 +1,14 @@
;
; unsigned char __fastcall__ kbrepeat (unsigned char mode);
;
.export _kbrepeat
.include "c128.inc"
_kbrepeat:
ldx KBDREPEAT ; get old value
sta KBDREPEAT ; store new value
txa ; return old value
ldx #0
rts

30
libsrc/c128/waitvsync.s Normal file
View File

@@ -0,0 +1,30 @@
;
; Written by Groepaz <groepaz@gmx.net>
;
; void waitvsync (void);
;
.export _waitvsync
.include "c128.inc"
_waitvsync:
bit MODE
bmi @c80
@l1:
bit VIC_CTRL1
bpl @l1
@l2:
bit VIC_CTRL1
bmi @l2
rts
@c80:
;FIXME: do we have to switch banks?
@l3:
lda VDC_INDEX
and #$20
beq @l3
rts

View File

@@ -1,376 +1,376 @@
;
; Extended memory driver for 65816 based extra RAM. Driver works without
; problems when statically linked.
;
; Marco van den Heuvel, 2015-12-01
;
.include "zeropage.inc"
.include "em-kernel.inc"
.include "em-error.inc"
.macpack generic
.macpack module
; ------------------------------------------------------------------------
; Header. Includes jump table
module_header _c64_65816_emd
; Driver signature
.byte $65, $6d, $64 ; "emd"
.byte EMD_API_VERSION ; EM API version number
; Library reference
.addr $0000
; Jump table
.addr INSTALL
.addr UNINSTALL
.addr PAGECOUNT
.addr MAP
.addr USE
.addr COMMIT
.addr COPYFROM
.addr COPYTO
; ------------------------------------------------------------------------
; Data.
.bss
isnotscpu: .res 1 ; SuperCPU not present
curpage: .res 1 ; Current page number
curbank: .res 1 ; Current bank number (+1)
bankcount: .res 1 ; Number of available banks (pages = banks * 256)
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:
sei
clc
sed
lda #$99
adc #$01 ; on 65C02, 65SC02, 65CE02, 65802 and 65816 sets the zero flag correctly
cld
bne @not_present
clc
.P816
sep #$01 ; nop #$01 on 65C02/65SC02 and lda ($01,s),y on 65CE02
.P02
bcc @not_present
lda $d0bc
and #$80
sta isnotscpu
lda $07e8
pha ; save value incase it was used somewhere else
ldx #$ff
@fillloop: ; fill from top (bank 255) to bottom
txa
pha
.P816
plb ; pull dbr
.P02
stx $07e8
dex
cpx #$ff
bne @fillloop
inx
@compareloop: ; check from bottom to top
txa
pha
.P816
plb
.P02
cmp $07e8
bne @found_pages
.P816
inc
.P02
sta $07e8
cmp $07e8
bne @found_pages
inx
bne @compareloop
@found_pages:
dex
lda #$00
pha
.P816
plb
.P02
pla
sta $07e8
cli
lda isnotscpu
bne @noextradex
dex
@noextradex:
stx bankcount
lda #<EM_ERR_OK
ldx #>EM_ERR_OK
rts
@not_present:
cli
lda #<EM_ERR_NO_DEVICE
ldx #>EM_ERR_NO_DEVICE
; rts ; Run into UNINSTALL instead
; ------------------------------------------------------------------------
; UNINSTALL routine. Is called before the driver is removed from memory.
; Can do cleanup or whatever. Must not return anything.
;
UNINSTALL:
rts
; ------------------------------------------------------------------------
; PAGECOUNT: Return the total number of available pages in a/x.
;
PAGECOUNT:
lda #$00 ; a whole bank is either usable or not
ldx bankcount
rts
; ------------------------------------------------------------------------
; MAP: Map the page in a/x into memory and return a pointer to the page in
; a/x. The contents of the currently mapped page (if any) may be discarded
; by the driver.
;
MAP: sta curpage ; Remember the new page
stx curbank ; Remember the new bank
sta ptr2+1 ; src address low
lda #$00
sta ptr2 ; src address high
inx
ldy isnotscpu ; check if not scpu
bne @notscpu
inx
@notscpu:
stx tmp2 ; src bank
sta tmp1 ; dst bank
sta ptr3+1 ; length high
lda #$ff
sta ptr3 ; length low
lda #<window
sta ptr1 ; dst address low
ldx #>window
stx ptr1+1 ; dst address high
jsr transfer
rts
; ------------------------------------------------------------------------
; USE: Tell the driver that the window is now associated with a given page.
USE: sta curpage ; Remember the page
stx curbank ; Remember the bank
lda #<window
ldx #>window ; Return the window
rts
; ------------------------------------------------------------------------
; COMMIT: Commit changes in the memory window to extended storage.
COMMIT: lda curpage ; Get the current page
sta ptr1+1 ; dst high
ldx #$00
stx ptr1 ; dst low
lda #<window
sta ptr2 ; src low
lda #>window
sta ptr2+1 ; src high
stx ptr3+1 ; length high
lda #$ff
sta ptr3 ; length low
stx tmp2 ; src bank
ldy curbank ; Get the current bank
iny
ldx isnotscpu
bne @notascpu
iny
@notascpu:
sty tmp1 ; dst bank
jsr transfer
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 ptr4
stx ptr4+1 ; Save the passed em_copy pointer
ldy #EM_COPY::COUNT+1 ; start at the end of the struct
lda (ptr4),y ; get high byte of count
tax
dey
lda (ptr4),y ; get low byte of count
bne @nodex
dex
@nodex:
.P816
dec
.P02
sta ptr3 ; length low
stx ptr3+1 ; length high
dey
lda (ptr4),y ; get bank
.P816
inc
.P02
ldx isnotscpu
bne @notscpu64
.P816
inc
.P02
@notscpu64:
sta tmp2 ; src bank
dey
lda (ptr4),y ; get page
sta ptr2+1 ; src high
dey
lda (ptr4),y ; get offset in page
sta ptr2 ; src low
dey
lda (ptr4),y ; get memory buffer high
sta ptr1+1 ; dst high
dey
lda (ptr4),y ; get memory buffer low
sta ptr1 ; dst low
lda #$00
sta tmp1 ; dst bank
jsr transfer
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 ptr4
stx ptr4+1 ; Save the passed em_copy pointer
ldy #EM_COPY::COUNT+1 ; start at the end of the struct
lda (ptr4),y ; get high byte of count
tax
dey
lda (ptr4),y ; get low byte of count
bne @nodex2
dex
@nodex2:
.P816
dec
.P02
sta ptr3 ; length low
txa
sta ptr3+1 ; length high
dey
lda (ptr4),y ; get bank
.P816
inc
.P02
ldx isnotscpu
bne @notascpu64
.P816
inc
.P02
@notascpu64:
sta tmp1 ; dst bank
dey
lda (ptr4),y ; get page
sta ptr1+1 ; dst high
dey
lda (ptr4),y ; get page offset
sta ptr1 ; dst low
dey
lda (ptr4),y ; get memory buffer high
sta ptr2+1 ; src low
dey
lda (ptr4),y ; get memory buffer low
sta ptr2 ; src high
lda #$00
sta tmp2 ; src bank
jsr transfer
rts
; ------------------------------------------------------------------------
; Helper function for moving a block, the following is used:
; ptr1: dst
; ptr2: src
; ptr3: length
; tmp1: dst bank
; tmp2: src bank
transfer:
.P816
.A8
.I8
sei
pha
phx
phy
ldx tmp1 ; load srcbank
stx @move+1 ; store srcbank in move + 1
ldy tmp2 ; load dstbank
sty @move+2 ; store dstbank in move + 2
clc ; switch to native mode
xce
php ; save status bits
rep #%00110000 ; set A and index to 16bit
.A16
.I16
ldy ptr1
ldx ptr2
lda ptr3
@move:
mvn 0,0
plp ; restore status bits
.A8
.I8
lda #$00
pha
plb ; restore dbr
sec
xce ; switch to emul mode
ply
plx
pla
cli
rts
.P02
;
; Extended memory driver for 65816 based extra RAM. Driver works without
; problems when statically linked.
;
; Marco van den Heuvel, 2015-12-01
;
.include "zeropage.inc"
.include "em-kernel.inc"
.include "em-error.inc"
.macpack generic
.macpack module
; ------------------------------------------------------------------------
; Header. Includes jump table
module_header _c64_65816_emd
; Driver signature
.byte $65, $6d, $64 ; "emd"
.byte EMD_API_VERSION ; EM API version number
; Library reference
.addr $0000
; Jump table
.addr INSTALL
.addr UNINSTALL
.addr PAGECOUNT
.addr MAP
.addr USE
.addr COMMIT
.addr COPYFROM
.addr COPYTO
; ------------------------------------------------------------------------
; Data.
.bss
isnotscpu: .res 1 ; SuperCPU not present
curpage: .res 1 ; Current page number
curbank: .res 1 ; Current bank number (+1)
bankcount: .res 1 ; Number of available banks (pages = banks * 256)
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:
sei
clc
sed
lda #$99
adc #$01 ; on 65C02, 65SC02, 65CE02, 65802 and 65816 sets the zero flag correctly
cld
bne @not_present
clc
.P816
sep #$01 ; nop #$01 on 65C02/65SC02 and lda ($01,s),y on 65CE02
.P02
bcc @not_present
lda $d0bc
and #$80
sta isnotscpu
lda $07e8
pha ; save value incase it was used somewhere else
ldx #$ff
@fillloop: ; fill from top (bank 255) to bottom
txa
pha
.P816
plb ; pull dbr
.P02
stx $07e8
dex
cpx #$ff
bne @fillloop
inx
@compareloop: ; check from bottom to top
txa
pha
.P816
plb
.P02
cmp $07e8
bne @found_pages
.P816
inc
.P02
sta $07e8
cmp $07e8
bne @found_pages
inx
bne @compareloop
@found_pages:
dex
lda #$00
pha
.P816
plb
.P02
pla
sta $07e8
cli
lda isnotscpu
bne @noextradex
dex
@noextradex:
stx bankcount
lda #<EM_ERR_OK
ldx #>EM_ERR_OK
rts
@not_present:
cli
lda #<EM_ERR_NO_DEVICE
ldx #>EM_ERR_NO_DEVICE
; rts ; Run into UNINSTALL instead
; ------------------------------------------------------------------------
; UNINSTALL routine. Is called before the driver is removed from memory.
; Can do cleanup or whatever. Must not return anything.
;
UNINSTALL:
rts
; ------------------------------------------------------------------------
; PAGECOUNT: Return the total number of available pages in a/x.
;
PAGECOUNT:
lda #$00 ; a whole bank is either usable or not
ldx bankcount
rts
; ------------------------------------------------------------------------
; MAP: Map the page in a/x into memory and return a pointer to the page in
; a/x. The contents of the currently mapped page (if any) may be discarded
; by the driver.
;
MAP: sta curpage ; Remember the new page
stx curbank ; Remember the new bank
sta ptr2+1 ; src address low
lda #$00
sta ptr2 ; src address high
inx
ldy isnotscpu ; check if not scpu
bne @notscpu
inx
@notscpu:
stx tmp2 ; src bank
sta tmp1 ; dst bank
sta ptr3+1 ; length high
lda #$ff
sta ptr3 ; length low
lda #<window
sta ptr1 ; dst address low
ldx #>window
stx ptr1+1 ; dst address high
jsr transfer
rts
; ------------------------------------------------------------------------
; USE: Tell the driver that the window is now associated with a given page.
USE: sta curpage ; Remember the page
stx curbank ; Remember the bank
lda #<window
ldx #>window ; Return the window
rts
; ------------------------------------------------------------------------
; COMMIT: Commit changes in the memory window to extended storage.
COMMIT: lda curpage ; Get the current page
sta ptr1+1 ; dst high
ldx #$00
stx ptr1 ; dst low
lda #<window
sta ptr2 ; src low
lda #>window
sta ptr2+1 ; src high
stx ptr3+1 ; length high
lda #$ff
sta ptr3 ; length low
stx tmp2 ; src bank
ldy curbank ; Get the current bank
iny
ldx isnotscpu
bne @notascpu
iny
@notascpu:
sty tmp1 ; dst bank
jsr transfer
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 ptr4
stx ptr4+1 ; Save the passed em_copy pointer
ldy #EM_COPY::COUNT+1 ; start at the end of the struct
lda (ptr4),y ; get high byte of count
tax
dey
lda (ptr4),y ; get low byte of count
bne @nodex
dex
@nodex:
.P816
dec
.P02
sta ptr3 ; length low
stx ptr3+1 ; length high
dey
lda (ptr4),y ; get bank
.P816
inc
.P02
ldx isnotscpu
bne @notscpu64
.P816
inc
.P02
@notscpu64:
sta tmp2 ; src bank
dey
lda (ptr4),y ; get page
sta ptr2+1 ; src high
dey
lda (ptr4),y ; get offset in page
sta ptr2 ; src low
dey
lda (ptr4),y ; get memory buffer high
sta ptr1+1 ; dst high
dey
lda (ptr4),y ; get memory buffer low
sta ptr1 ; dst low
lda #$00
sta tmp1 ; dst bank
jsr transfer
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 ptr4
stx ptr4+1 ; Save the passed em_copy pointer
ldy #EM_COPY::COUNT+1 ; start at the end of the struct
lda (ptr4),y ; get high byte of count
tax
dey
lda (ptr4),y ; get low byte of count
bne @nodex2
dex
@nodex2:
.P816
dec
.P02
sta ptr3 ; length low
txa
sta ptr3+1 ; length high
dey
lda (ptr4),y ; get bank
.P816
inc
.P02
ldx isnotscpu
bne @notascpu64
.P816
inc
.P02
@notascpu64:
sta tmp1 ; dst bank
dey
lda (ptr4),y ; get page
sta ptr1+1 ; dst high
dey
lda (ptr4),y ; get page offset
sta ptr1 ; dst low
dey
lda (ptr4),y ; get memory buffer high
sta ptr2+1 ; src low
dey
lda (ptr4),y ; get memory buffer low
sta ptr2 ; src high
lda #$00
sta tmp2 ; src bank
jsr transfer
rts
; ------------------------------------------------------------------------
; Helper function for moving a block, the following is used:
; ptr1: dst
; ptr2: src
; ptr3: length
; tmp1: dst bank
; tmp2: src bank
transfer:
.P816
.A8
.I8
sei
pha
phx
phy
ldx tmp1 ; load srcbank
stx @move+1 ; store srcbank in move + 1
ldy tmp2 ; load dstbank
sty @move+2 ; store dstbank in move + 2
clc ; switch to native mode
xce
php ; save status bits
rep #%00110000 ; set A and index to 16bit
.A16
.I16
ldy ptr1
ldx ptr2
lda ptr3
@move:
mvn 0,0
plp ; restore status bits
.A8
.I8
lda #$00
pha
plb ; restore dbr
sec
xce ; switch to emul mode
ply
plx
pla
cli
rts
.P02

View File

@@ -29,17 +29,6 @@
.addr $0000
; Button state masks (8 values)
.byte $01 ; JOY_UP
.byte $02 ; JOY_DOWN
.byte $04 ; JOY_LEFT
.byte $08 ; JOY_RIGHT
.byte $10 ; JOY_FIRE
.byte $00 ; JOY_FIRE2 unavailable
.byte $00 ; Future expansion
.byte $00 ; Future expansion
; Jump table.
.addr INSTALL

View File

@@ -30,17 +30,6 @@
.addr $0000
; Button state masks (8 values)
.byte $02 ; JOY_UP "8"
.byte $10 ; JOY_DOWN "2"
.byte $20 ; JOY_LEFT "4"
.byte $08 ; JOY_RIGHT "6"
.byte $04 ; JOY_FIRE "5" ENTER
.byte $00 ; JOY_FIRE2 unavailable
.byte $00 ; Future expansion
.byte $00 ; Future expansion
; Jump table.
.addr INSTALL
@@ -58,6 +47,49 @@ JOY_COUNT = 1 ; Number of joysticks we support
; ------------------------------------------------------------------------
; Data.
.rodata
; <U>p '8' key
; <D>own '2' key
; <L>eft '4' key
; <R>ight '6' key
; <B>utton '5' or ENTER key
masktable:
; Input: LDRBU
; Output: BRLDU
.byte %00000000 ; $00
.byte %00000001 ; $01
.byte %00010000 ; $02
.byte %00010001 ; $03
.byte %00001000 ; $04
.byte %00001001 ; $05
.byte %00011000 ; $06
.byte %00011001 ; $07
.byte %00000010 ; $08
.byte %00000011 ; $09
.byte %00010010 ; $0A
.byte %00010011 ; $0B
.byte %00001010 ; $0C
.byte %00001011 ; $0D
.byte %00011010 ; $0E
.byte %00011011 ; $0F
.byte %00000100 ; $10
.byte %00000101 ; $11
.byte %00010100 ; $12
.byte %00010101 ; $13
.byte %00001100 ; $14
.byte %00001101 ; $15
.byte %00011100 ; $16
.byte %00011101 ; $17
.byte %00000110 ; $18
.byte %00000111 ; $19
.byte %00010110 ; $1A
.byte %00010111 ; $1B
.byte %00001110 ; $1C
.byte %00001111 ; $1D
.byte %00011110 ; $1E
.byte %00011111 ; $1F
.code
@@ -100,21 +132,23 @@ COUNT: lda #JOY_COUNT
;
READ: tax ; Clear high byte
lda #$FD
ldy #$FE
lda #$FD ; For ENTER and '6'
ldy #$FE ; For '8', '5', '2', '4'
sei
sta VIC_KBD_128
lda CIA1_PRB
and #%00110000
eor #%00110000
lsr
lsr
lsr ; Map ENTER ...
lsr ; ... onto '5'
sty VIC_KBD_128
eor CIA1_PRB
iny
sty VIC_KBD_128 ; Reset to $FF
cli
and #%11111110
eor #%11111110
and #%00111110
eor #%00111110
lsr
tay
lda masktable,y ; Convert LDRBU to BRLDU
rts

View File

@@ -29,17 +29,6 @@
.addr $0000
; Button state masks (8 values)
.byte $01 ; JOY_UP
.byte $02 ; JOY_DOWN
.byte $04 ; JOY_LEFT
.byte $08 ; JOY_RIGHT
.byte $10 ; JOY_FIRE
.byte $00 ; JOY_FIRE2 unavailable
.byte $00 ; Future expansion
.byte $00 ; Future expansion
; Jump table.
.addr INSTALL
@@ -133,8 +122,8 @@ joy3:
sta CIA2_PRB ; (output one at PB7)
lda CIA2_PRB ; cia 2 port B read/write
and #$1f ; get bit 4-0 (PB4-PB0)
eor #$1f
and #$1F ; get bit 4-0 (PB4-PB0)
eor #$1F
rts
; Read joystick 4
@@ -143,14 +132,14 @@ joy4: lda #$00 ; cia 2 port B read/write
sta CIA2_PRB ; (output zero at PB7)
lda CIA2_PRB ; cia 2 port B read/write
and #$0f ; get bit 3-0 (PB3-PB0)
and #$0F ; get bit 3-0 (PB3-PB0)
sta tmp1 ; joy 4 directions
lda CIA2_PRB ; cia 2 port B read/write
and #%00100000 ; get bit 5 (PB5)
lsr
ora tmp1
eor #$1f
eor #$1F
ldx #0
rts

View File

@@ -29,17 +29,6 @@
.addr $0000
; Button state masks (8 values)
.byte $01 ; JOY_UP
.byte $02 ; JOY_DOWN
.byte $04 ; JOY_LEFT
.byte $08 ; JOY_RIGHT
.byte $10 ; JOY_FIRE
.byte $00 ; JOY_FIRE2 unavailable
.byte $00 ; Future expansion
.byte $00 ; Future expansion
; Jump table.
.addr INSTALL

14
libsrc/c64/kbrepeat.s Normal file
View File

@@ -0,0 +1,14 @@
;
; unsigned char __fastcall__ kbrepeat (unsigned char mode);
;
.export _kbrepeat
.include "c64.inc"
_kbrepeat:
ldx KBDREPEAT ; get old value
sta KBDREPEAT ; store new value
txa ; return old value
ldx #0
rts

18
libsrc/c64/waitvsync.s Normal file
View File

@@ -0,0 +1,18 @@
;
; Written by Groepaz <groepaz@gmx.net>
;
; void waitvsync (void);
;
.export _waitvsync
.include "c64.inc"
_waitvsync:
@l1:
bit VIC_CTRL1
bpl @l1
@l2:
bit VIC_CTRL1
bmi @l2
rts

View File

@@ -30,17 +30,6 @@
.addr $0000
; Button state masks (8 values)
.byte $01 ; JOY_UP
.byte $02 ; JOY_DOWN
.byte $04 ; JOY_LEFT
.byte $08 ; JOY_RIGHT
.byte $10 ; JOY_FIRE
.byte $00 ; JOY_FIRE2 unavailable
.byte $00 ; Future expansion
.byte $00 ; Future expansion
; Jump table.
.addr INSTALL
@@ -105,7 +94,7 @@ READ: ldx #$0F ; Switch to the system bank
lda (cia2),y ; Read joystick inputs
sta tmp1
; Get the fire bits
; Get the push button bits
ldy #CIA::PRA
lda (cia2),y
@@ -115,12 +104,12 @@ READ: ldx #$0F ; Switch to the system bank
cpx #$00 ; Joystick 0?
bne @L1 ; Jump if no
; Joystick 1, fire is in bit 6, direction in bit 0-3
; Joystick 1, push button is in bit 6, direction in bit 0-3
asl a
jmp @L2
; Joystick 2, fire is in bit 7, direction in bit 5-7
; Joystick 2, push button is in bit 7, direction in bit 5-7
@L1: ldx #$00 ; High byte of return value
lsr tmp1
@@ -128,9 +117,9 @@ READ: ldx #$0F ; Switch to the system bank
lsr tmp1
lsr tmp1
; Mask the relavant bits, get the fire bit
; Mask the relavant bits, get the push button bit
@L2: asl a ; Fire bit into carry
@L2: asl a ; push button bit into carry
lda tmp1
and #$0F
bcc @L3

28
libsrc/cbm510/waitvsync.s Normal file
View File

@@ -0,0 +1,28 @@
;
; Written by Groepaz <groepaz@gmx.net>
;
; void waitvsync (void);
;
.export _waitvsync
.import PALFLAG
.import sys_bank, restore_bank
.importzp vic
.include "cbm510.inc"
_waitvsync:
jsr sys_bank ; Switch to the system bank
sei
ldy #VIC_CTRL1
@l1:
lda (vic),y
bpl @l1
@l2:
lda (vic),y
bmi @l2
cli
jmp restore_bank

286
libsrc/common/lz4.s Normal file
View File

@@ -0,0 +1,286 @@
;
; Lauri Kasanen, 6 Jun 2017
; (C) Mega Cat Studios
; An optimized LZ4 decompressor
;
; Almost 7 times faster, uses no RAM (vs 14 bytes BSS), and takes 1/4 the space
; vs the official C source.
;
.importzp sp, sreg, regsave, regbank
.importzp tmp1, tmp2, tmp3, tmp4, ptr1, ptr2, ptr3, ptr4
.macpack longbranch
.import memcpy_upwards,pushax,popax
.export _decompress_lz4
out = regsave
written = regsave + 2
tmp = tmp1
token = tmp2
offset = ptr3
in = sreg
outlen = ptr4
; ---------------------------------------------------------------
; void decompress_lz4 (const u8 *in, u8 * const out, const u16 outlen)
; ---------------------------------------------------------------
.segment "CODE"
.proc _decompress_lz4: near
sta outlen
stx outlen+1
jsr popax
sta out
stx out+1
jsr popax
sta in
stx in+1
;
; written = 0;
;
lda #$00
sta written
;
; while (written < outlen) {
;
jmp L0046
;
; token = *in++;
;
L0004: ldy #$00
lda (in),y
sta token
inc in
bne L000A
inc in+1
L000A:
;
; offset = token >> 4;
;
ldx #$00
lsr a
lsr a
lsr a
lsr a
sta offset
stx offset+1
;
; token &= 0xf;
; token += 4; // Minmatch
;
lda token
and #$0F
clc
adc #$04
sta token
;
; if (offset == 15) {
;
lda offset
cmp #$0F
L0013: bne L001A
;
; tmp = *in++;
;
ldy #$00
lda (in),y
sta tmp
inc in
bne L0017
inc in+1
L0017:
;
; offset += tmp;
;
clc
adc offset
sta offset
lda #$00
adc offset+1
sta offset+1
;
; if (tmp == 255)
;
lda tmp
cmp #$FF
;
; goto moreliterals;
;
jmp L0013
;
; if (offset) {
;
L001A: lda offset
ora offset+1
beq L001C
;
; memcpy(&out[written], in, offset);
;
lda out
clc
adc written
sta ptr2
lda out+1
adc written+1
tax
lda ptr2
stx ptr2+1
jsr pushax
lda in
ldx in+1
sta ptr1
stx ptr1+1
; ldy #$00 - not needed as pushax zeroes Y
jsr memcpy_upwards
;
; written += offset;
;
lda offset
clc
adc written
sta written
lda offset+1
adc written+1
sta written+1
;
; in += offset;
;
lda offset
clc
adc in
sta in
lda offset+1
adc in+1
sta in+1
;
; if (written >= outlen)
;
L001C: lda written
cmp outlen
lda written+1
sbc outlen+1
;
; return;
;
bcc L0047
rts
;
; memcpy(&offset, in, 2);
;
L0047: ldy #$00
lda (in),y
sta offset
iny
lda (in),y
sta offset+1
;
; in += 2;
;
lda #$02
clc
adc in
sta in
bcc L002F
inc in+1
;
; copysrc = out + written - offset;
;
L002F: lda out
clc
adc written
tay
lda out+1
adc written+1
tax
tya
sec
sbc offset
sta ptr1
txa
sbc offset+1
sta ptr1+1
;
; offset = token;
;
lda #$00
sta offset+1
lda token
sta offset
;
; if (token == 19) {
;
cmp #$13
L0045: bne L003C
;
; tmp = *in++;
;
ldy #$00
lda (in),y
sta tmp
inc in
bne L0039
inc in+1
L0039:
;
; offset += tmp;
;
clc
adc offset
sta offset
tya
adc offset+1
sta offset+1
;
; if (tmp == 255)
;
lda tmp
cmp #$FF
;
; goto morematches;
;
jmp L0045
;
; memcpy(&out[written], copysrc, offset);
;
L003C: lda out
clc
adc written
sta ptr2
lda out+1
adc written+1
tax
lda ptr2
stx ptr2+1
jsr pushax
jsr memcpy_upwards
;
; written += offset;
;
lda offset
clc
adc written
sta written
lda offset+1
adc written+1
L0046: sta written+1
;
; while (written < outlen) {
;
lda written
cmp outlen
lda written+1
sbc outlen+1
jcc L0004
rts
.endproc

View File

@@ -1,6 +1,6 @@
;
; 2003-08-20, Ullrich von Bassewitz
; 2009-09-13, Christian Krueger -- performance increase (about 20%)
; 2009-09-13, Christian Krueger -- performance increase (about 20%), 2013-07-25 improved unrolling
; 2015-10-23, Greg King
;
; void* __fastcall__ memmove (void* dest, const void* src, size_t size);
@@ -61,13 +61,10 @@ PageSizeCopy: ; assert Y = 0
dec ptr1+1 ; adjust base...
dec ptr2+1
dey ; in entry case: 0 -> FF
lda (ptr1),y ; need to copy this 'intro byte'
sta (ptr2),y ; to 'land' later on Y=0! (as a result of the '.repeat'-block!)
dey ; FF ->FE
@copyBytes:
.repeat 2 ; Unroll this a bit to make it faster...
lda (ptr1),y
sta (ptr2),y
.repeat 3 ; unroll this a bit to make it faster...
lda (ptr1),y ; important: unrolling three times gives a nice
sta (ptr2),y ; 255/3 = 85 loop which ends at 0
dey
.endrepeat
@copyEntry: ; in entry case: 0 -> FF

View File

@@ -2,6 +2,7 @@
; Randum number generator
;
; Written and donated by Sidney Cadot - sidney@ch.twi.tudelft.nl
; 2016-11-07, modified by Brad Smith
;
; May be distributed with the cc65 runtime using the same license.
;
@@ -13,10 +14,14 @@
; Multiplier must be 1 (mod 4)
; Added value must be 1 (mod 2)
; This guarantees max. period (2**32)
; Bits 8-22 are returned (positive 2-byte int)
; where 0 is LSB, 31 is MSB.
; This is better as lower bits exhibit easily
; detectable patterns.
; The lowest bits have poor entropy and
; exhibit easily detectable patterns, so
; only the upper bits 16-22 and 24-31 of the
; 4-byte state are returned.
;
; The best 8 bits, 24-31 are returned in the
; low byte A to provide the best entropy in the
; most commonly used part of the return value.
;
.export _rand, _srand

View File

@@ -1,5 +1,6 @@
;
; Ullrich von Bassewitz, 31.05.1998
; Christian Krueger: 2013-Jul-24, minor optimizations
;
; char* strcat (char* dest, const char* src);
;
@@ -7,49 +8,44 @@
.export _strcat
.import popax
.importzp ptr1, ptr2, tmp3
.macpack cpu
_strcat:
sta ptr1 ; Save src
stx ptr1+1
jsr popax ; Get dest
sta ptr2
stx ptr2+1
sta tmp3 ; Remember for function return
ldy #0
sta ptr1 ; Save src
stx ptr1+1
jsr popax ; Get dest
sta tmp3 ; Remember for function return
tay
.if (.cpu .bitand ::CPU_ISET_65SC02)
stz ptr2
.else
lda #0
sta ptr2 ; access from page start, y contains low byte
.endif
stx ptr2+1
; find end of dest
sc1: lda (ptr2),y
beq sc2
findEndOfDest:
lda (ptr2),y
beq endOfDestFound
iny
bne sc1
inc ptr2+1
bne sc1
bne findEndOfDest
inc ptr2+1
bne findEndOfDest
; end found, get offset in y into pointer
endOfDestFound:
sty ptr2 ; advance pointer to last y position
ldy #0 ; reset new y-offset
sc2: tya
clc
adc ptr2
sta ptr2
bcc sc3
inc ptr2+1
; copy src
sc3: ldy #0
sc4: lda (ptr1),y
sta (ptr2),y
beq sc5
copyByte:
lda (ptr1),y
sta (ptr2),y
beq done
iny
bne sc4
inc ptr1+1
inc ptr2+1
bne sc4
bne copyByte
inc ptr1+1
inc ptr2+1
bne copyByte ; like bra here
; done, return pointer to dest
sc5: lda tmp3 ; X does still contain high byte
; return pointer to dest
done: lda tmp3 ; X does still contain high byte
rts

View File

@@ -1,5 +1,6 @@
;
; Ullrich von Bassewitz, 31.05.1998
; Christian Krueger, 2013-Aug-04, minor optimization
;
; const char* strchr (const char* s, int c);
;
@@ -7,42 +8,45 @@
.export _strchr
.import popax
.importzp ptr1, tmp1
.macpack cpu
_strchr:
sta tmp1 ; Save c
jsr popax ; get s
sta ptr1
stx ptr1+1
ldy #0
sta tmp1 ; Save c
jsr popax ; get s
tay ; low byte of pointer to y
stx ptr1+1
.if (.cpu .bitand ::CPU_ISET_65SC02)
stz ptr1
.else
lda #0
sta ptr1 ; access from page start, y contains low byte
.endif
Loop: lda (ptr1),y ; Get next char
beq EOS ; Jump on end of string
cmp tmp1 ; Found?
beq Found ; Jump if yes
Loop: lda (ptr1),y ; Get next char
beq EOS ; Jump on end of string
cmp tmp1 ; Found?
beq Found ; Jump if yes
iny
bne Loop
inc ptr1+1
bne Loop ; Branch always
bne Loop
inc ptr1+1
bne Loop ; Branch always
; End of string. Check if we're searching for the terminating zero
EOS: lda tmp1 ; Get the char we're searching for
bne NotFound ; Jump if not searching for terminator
EOS:
lda tmp1 ; Get the char we're searching for
bne NotFound ; Jump if not searching for terminator
; Found. Calculate pointer to c.
; Found. Set pointer to c.
Found: ldx ptr1+1 ; Load high byte of pointer
tya ; Low byte offset
clc
adc ptr1
bcc Found1
inx
Found1: rts
Found:
ldx ptr1+1 ; Load high byte of pointer
tya ; low byte is in y
rts
; Not found, return NULL
NotFound:
lda #0
lda #0
tax
rts

View File

@@ -1,54 +1,53 @@
;
; Ullrich von Bassewitz, 11.06.1998
; Christian Krueger: 05-Aug-2013, optimization
;
; size_t strcspn (const char* s1, const char* s2);
;
.export _strcspn
.import popax
.importzp ptr1, ptr2, tmp1, tmp2, tmp3
.import popax, _strlen
.importzp ptr1, ptr2, tmp1, tmp2
_strcspn:
sta ptr2 ; Save s2
stx ptr2+1
jsr popax ; Get s1
sta ptr1
stx ptr1+1
ldx #0 ; low counter byte
stx tmp1 ; high counter byte
ldy #$00
jsr _strlen ; get length in a/x and transfer s2 to ptr1
; Note: It does not make sense to
; have more than 255 test chars, so
; we don't support a high byte here! (ptr1+1 is
; also unchanged in strlen then (important!))
; -> the original implementation also
; ignored this case
L1: lda (ptr1),y ; get next char from s1
beq L6 ; jump if done
sta tmp2 ; save char
sta tmp1 ; tmp1 = strlen of test chars
jsr popax ; get and save s1
sta ptr2 ; to ptr2
stx ptr2+1
ldx #0 ; low counter byte
stx tmp2 ; high counter byte
loadChar:
ldy #0
lda (ptr2),y ; get next char from s1
beq leave ; handly byte of s1
advance:
inc ptr2 ; advance string position to test
bne check
inc ptr2+1
dey ; correct next iny (faster/shorter than bne...)
checkNext:
iny
bne L2
inc ptr1+1
L2: sty tmp3 ; save index into s1
check: cpy tmp1 ; compare with length of test character string
beq endOfTestChars
cmp (ptr1),y ; found matching char?
bne checkNext
ldy #0 ; get index into s2
L3: lda (ptr2),y ;
beq L4 ; jump if done
cmp tmp2
beq L6
iny
bne L3
; The character was not found in s2. Increment the counter and start over
L4: ldy tmp3 ; reload index
inx
bne L1
inc tmp1
bne L1
; The character was found, or we reached the end of s1. Return count of
; characters
L6: txa ; get low counter byte
ldx tmp1 ; get high counter byte
leave: txa ; restore position of finding
ldx tmp2 ; and return
rts
endOfTestChars:
inx
bne loadChar
inc tmp2
bne loadChar ; like bra...

View File

@@ -53,11 +53,11 @@
size_t __fastcall__ strftime (char* buf, size_t bufsize, const char* format,
const struct tm* tm)
{
static const char* days[7] = {
static const char* const days[7] = {
"Sunday", "Monday", "Tuesday", "Wednesday",
"Thursday", "Friday", "Saturday"
};
static const char* months[12] = {
static const char* const months[12] = {
"January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December"
};

View File

@@ -1,6 +1,10 @@
;
; Ullrich von Bassewitz, 31.05.1998
;
; Note: strspn & strcspn call internally this function and rely on
; the usage of only ptr1 here! Keep in mind when appling changes
; and check the other implementations too!
;
; int strlen (const char* s);
;
@@ -23,4 +27,3 @@ L1: lda (ptr1),y
L9: tya ; get low byte of counter, hi's all set
rts

View File

@@ -1,5 +1,6 @@
;
; Ullrich von Bassewitz, 31.05.1998
; Christian Krueger: 12-Aug-2013, minor optimizations
;
; char* strncat (char* dest, const char* src, size_t n);
;
@@ -7,66 +8,66 @@
.export _strncat
.import popax
.importzp ptr1, ptr2, ptr3, tmp1, tmp2
.macpack cpu
_strncat:
eor #$FF ; one's complement to count upwards
sta tmp1
txa
eor #$FF
sta tmp2
jsr popax ; get src
sta ptr1
stx ptr1+1
jsr popax ; get dest
sta ptr2
stx ptr2+1
sta ptr3 ; remember for function return
stx ptr3+1
ldy #0
eor #$FF ; one's complement to count upwards
sta tmp1
txa
eor #$FF
sta tmp2
jsr popax ; get src
sta ptr1
stx ptr1+1
jsr popax ; get dest
sta ptr3 ; remember for function return
stx ptr3+1
stx ptr2+1
tay ; low byte as offset in Y
.if (.cpu .bitand ::CPU_ISET_65SC02)
stz ptr2
.else
ldx #0
stx ptr2 ; destination on page boundary
.endif
; find end of dest
L1: lda (ptr2),y
beq L2
iny
bne L1
inc ptr2+1
bne L1
L1: lda (ptr2),y
beq L2
iny
bne L1
inc ptr2+1
bne L1
; end found, get offset in y into pointer
L2: tya
clc
adc ptr2
sta ptr2
bcc L3
inc ptr2+1
; end found, apply offset to dest ptr and reset y
L2: sty ptr2
; copy src. We've put the ones complement of the count into the counter, so
; we'll increment the counter on top of the loop
L3: ldy #0
ldx tmp1 ; low counter byte
L3: ldy #0
ldx tmp1 ; low counter byte
L4: inx
bne L5
inc tmp2
beq L6 ; jump if done
L5: lda (ptr1),y
sta (ptr2),y
beq L7
iny
bne L4
inc ptr1+1
inc ptr2+1
bne L4
L4: inx
bne L5
inc tmp2
beq L6 ; jump if done
L5: lda (ptr1),y
sta (ptr2),y
beq L7
iny
bne L4
inc ptr1+1
inc ptr2+1
bne L4
; done, set the trailing zero and return pointer to dest
L6: lda #0
sta (ptr2),y
L7: lda ptr3
ldx ptr3+1
rts
L6: lda #0
sta (ptr2),y
L7: lda ptr3
ldx ptr3+1
rts

View File

@@ -1,47 +1,41 @@
;
; Ullrich von Bassewitz, 31.05.1998
; Christian Krueger: 2013-Aug-01, optimization
;
; char* strrchr (const char* s, int c);
;
.export _strrchr
.import popax
.importzp ptr1, ptr2, tmp1
.importzp ptr1, tmp1, tmp2
_strrchr:
sta tmp1 ; Save c
jsr popax ; get s
sta ptr1
stx ptr1+1
lda #0 ; function result = NULL
sta ptr2
sta ptr2+1
tay
sta tmp1 ; Save c
jsr popax ; get s
tay ; low byte to y
stx ptr1+1
ldx #0 ; default function result is NULL, X is high byte...
stx tmp2 ; tmp2 is low-byte
stx ptr1 ; low-byte of source string is in Y, so clear real one...
testChar:
lda (ptr1),y ; get char
beq finished ; jump if end of string
cmp tmp1 ; found?
bne nextChar ; jump if no
L1: lda (ptr1),y ; get next char
beq L3 ; jump if end of string
cmp tmp1 ; found?
bne L2 ; jump if no
charFound:
sty tmp2 ; y has low byte of location, save it
ldx ptr1+1 ; x holds high-byte of result
; Remember a pointer to the character
nextChar:
iny
bne testChar
inc ptr1+1
bne testChar ; here like bra...
tya
clc
adc ptr1
sta ptr2
lda ptr1+1
adc #$00
sta ptr2+1
; return the pointer to the last occurrence
; Next char
L2: iny
bne L1
inc ptr1+1
bne L1 ; jump always
; Return the pointer to the last occurrence
L3: lda ptr2
ldx ptr2+1
finished:
lda tmp2 ; high byte in X is already correct...
rts

View File

@@ -1,56 +1,53 @@
;
; Ullrich von Bassewitz, 11.06.1998
; Christian Krueger: 08-Aug-2013, optimization
;
; size_t strspn (const char* s1, const char* s2);
;
.export _strspn
.import popax
.importzp ptr1, ptr2, tmp1, tmp2, tmp3
.import popax, _strlen
.importzp ptr1, ptr2, tmp1, tmp2
_strspn:
sta ptr2 ; Save s2
stx ptr2+1
jsr popax ; get s1
sta ptr1
stx ptr1+1
ldx #0 ; low counter byte
stx tmp1 ; high counter byte
ldy #$00
jsr _strlen ; get length in a/x and transfer s2 to ptr1
; Note: It does not make sense to
; have more than 255 test chars, so
; we don't support a high byte here! (ptr1+1 is
; also unchanged in strlen then (important!))
; -> the original implementation also
; ignored this case
L1: lda (ptr1),y ; get next char from s1
beq L6 ; jump if done
sta tmp2 ; save char
sta tmp1 ; tmp1 = strlen of test chars
jsr popax ; get and save s1
sta ptr2 ; to ptr2
stx ptr2+1
ldx #0 ; low counter byte
stx tmp2 ; high counter byte
loadChar:
ldy #0
lda (ptr2),y ; get next char from s1
beq leave ; handly byte of s1
advance:
inc ptr2 ; advance string position to test
bne check
inc ptr2+1
dey ; correct next iny (faster/shorter than bne...)
checkNext:
iny
bne L2
inc ptr1+1
L2: sty tmp3 ; save index into s1
check: cpy tmp1 ; compare with length of test character string
beq leave
cmp (ptr1),y ; found matching char?
bne checkNext
ldy #0 ; get index into s2
L3: lda (ptr2),y ;
beq L6 ; jump if done
cmp tmp2
beq L4
iny
bne L3
; The character was found in s2. Increment the counter and start over
L4: ldy tmp3 ; reload index
foundTestChar:
inx
bne L1
inc tmp1
bne L1
bne loadChar
inc tmp2
bne loadChar ; like bra...
; The character was not found, or we reached the end of s1. Return count of
; characters
L6: txa ; get low counter byte
ldx tmp1 ; get high counter byte
leave: txa ; restore position of finding
ldx tmp2 ; and return
rts

View File

@@ -1,8 +1,8 @@
;
; Ullrich von Bassewitz, 06.08.1998
;
; void cputsxy (unsigned char x, unsigned char y, char* s);
; void cputs (char* s);
; void cputsxy (unsigned char x, unsigned char y, const char* s);
; void cputs (const char* s);
;
.export _cputsxy, _cputs

View File

@@ -18,7 +18,7 @@ _clrscr:
lda #$50 ; VRAM offset high ($10 OR $40)
sta VDP_CONTROL_W
lda #$C0 ; Space from ROM setup
lda #$40 ; Space char from ROM setup
ldx #0
ldy #3
@@ -34,8 +34,8 @@ L1: sta VDP_DATA_W
lda #0
sta CURSOR_X
sta CURSOR_Y
sta <SCREEN_PTR
sta SCREEN_PTR
lda #$10
sta >SCREEN_PTR
sta SCREEN_PTR+1
rts

View File

@@ -96,8 +96,8 @@ BAD_CHAR:
jmp plot
;-----------------------------------------------------------------------------
; Initialize the conio subsystem. Code goes into the INIT segment, which may
; be reused after startup.
; Initialize the conio subsystem. "INIT" segment is nothing special on the
; Creativision, it is part of the "ROM" memory.
.segment "INIT"
@@ -122,4 +122,4 @@ LL: lda boxchars,x
bne LL
cli
jmp plot
jmp plot

View File

@@ -31,9 +31,6 @@ entry:
ldx #<__RAM_START__ - 1
txs
; Start interrupts
cli
; Clear the BSS data
jsr zerobss
@@ -49,13 +46,21 @@ entry:
; Call module constructors
jsr initlib
; enable vertical blank interrupts in the display controller
lda #$E0 ; 16K RAM, Active Display, Mode 1, VBI enabled
ldx #$01 ; Register 1
jsr BIOS_WRITE_VDP_REG
; Start interrupts
cli
; Call main()
jsr callmain
; Call module destructors. This is also the _exit entry.
_exit: jsr donelib
; TODO: Replace with some sort of reset
; A Creativision program isn't supposed to exit.
loop: jmp loop
; ------------------------------------------------------------------------
@@ -81,7 +86,7 @@ irq2: jmp BIOS_IRQ2_ADDR
; VDP Setup
; This sets to Graphics Mode 1
.byte $00 ; Register 0
.byte $C0 ; Register 1 16K RAM, Active Display, Mode 1
.byte $C0 ; Register 1 16K RAM, Active Display, Mode 1, VBI disabled
.byte $04 ; Register 2 Name Table at $1000 - $12FF
.byte $60 ; Register 3 Colour Table at $1800 - $181F
.byte $00 ; Register 4 Pattern Table at $0000 - $07FF

View File

@@ -1,15 +1,19 @@
;
; Ullrich von Bassewitz, 06.08.1998
; 1998-08-06, Ullrich von Bassewitz
; 2017-06-15, Greg King
;
; void gotoxy (unsigned char x, unsigned char y);
;
.export _gotoxy
.export gotoxy, _gotoxy
.import setcursor
.import popa
.include "creativision.inc"
gotoxy: jsr popa ; Get Y
.proc _gotoxy
sta CURSOR_Y ; Set Y

View File

@@ -1,60 +1,56 @@
;
; Standard joystick driver for the Creativision.
;
; Christian Groessler, 2017-02-06
; Christian Groessler, 2017-03-08
;
.include "zeropage.inc"
.include "zeropage.inc"
.include "joy-kernel.inc"
.include "joy-error.inc"
.include "creativision.inc"
.include "joy-kernel.inc"
.include "joy-error.inc"
.include "creativision.inc"
.macpack module
.macpack module
; ------------------------------------------------------------------------
; Header. Includes jump table
module_header _creativisionstd_joy
module_header _creativisionstd_joy
; Driver signature
.byte $6A, $6F, $79 ; "joy"
.byte JOY_API_VERSION ; Driver API version number
.byte $6A, $6F, $79 ; "joy"
.byte JOY_API_VERSION ; Driver API version number
; Library reference
.addr $0000
; Button state masks (8 values)
.byte $10 ; JOY_UP
.byte $04 ; JOY_DOWN
.byte $20 ; JOY_LEFT
.byte $08 ; JOY_RIGHT
.byte $01 ; JOY_FIRE (button #1)
.byte $02 ; JOY_FIRE2 (button #2)
.byte $00 ; Future expansion
.byte $00 ; Future expansion
.addr $0000
; Jump table.
.addr INSTALL
.addr UNINSTALL
.addr COUNT
.addr READJOY
.addr 0 ; IRQ entry not used
.addr INSTALL
.addr UNINSTALL
.addr COUNT
.addr READJOY
.addr 0 ; IRQ entry not used
; ------------------------------------------------------------------------
; Constants
JOY_COUNT = 2 ; Number of joysticks we support
JOY_COUNT = 2 ; Number of joysticks we support
; Symbolic names for joystick masks (similar names like the defines in joystick.h, but not related to them)
JOY_UP = $10
JOY_DOWN = $04
JOY_LEFT = $20
JOY_RIGHT = $08
; ------------------------------------------------------------------------
; Code
.code
.code
; ------------------------------------------------------------------------
; INSTALL routine. Is called after the driver is loaded into memory. If
@@ -63,131 +59,180 @@ JOY_COUNT = 2 ; Number of joysticks we support
; Must return an JOY_ERR_xx code in a/x.
;
INSTALL:
lda #JOY_ERR_OK
ldx #0
; rts ; Fall through
INSTALL: lda #JOY_ERR_OK
ldx #0
; rts ; Fall through
; ------------------------------------------------------------------------
; UNINSTALL routine. Is called before the driver is removed from memory.
; Can do cleanup or whatever. Must not return anything.
;
UNINSTALL:
rts
UNINSTALL: rts
; ------------------------------------------------------------------------
; COUNT: Return the total number of available joysticks in a/x.
;
COUNT:
lda #<JOY_COUNT
ldx #>JOY_COUNT
rts
COUNT: lda #<JOY_COUNT
ldx #>JOY_COUNT
rts
; ------------------------------------------------------------------------
; READ: Read a particular joystick passed in A.
;
READJOY:
and #1 ; fix joystick number
bne READJOY_1 ; read right joystick
READJOY: and #1 ; fix joystick number
bne READJOY_1 ; read right joystick
; Read left joystick
ldx ZP_JOY0_DIR
lda ZP_JOY0_BUTTONS
jmp convert ; convert joystick state to sane cc65 values
ldx ZP_JOY0_DIR
lda ZP_JOY0_BUTTONS
jmp convert ; convert joystick state to cc65 values
; Read right joystick
READJOY_1:
ldx ZP_JOY1_DIR
lda ZP_JOY1_BUTTONS
lsr a
lsr a
;jmp convert ; convert joystick state to sane cc65 values
; fall thru...
READJOY_1: ldx ZP_JOY1_DIR
lda ZP_JOY1_BUTTONS
lsr a
lsr a
;jmp convert ; convert joystick state to cc65 values
; fall thru...
; ------------------------------------------------------------------------
; convert: make runtime lib compatible values
; A - buttons
; X - direction
; inputs:
; A - buttons
; X - direction
;
convert:
ldy #0
sty retval ; initialize return value
; ------
; buttons:
; Port values are for the left hand joystick (right hand joystick
; values were shifted to the right to be identical).
; Why are there two bits indicating a pressed trigger?
; According to the "Second book of programs for the Dick Smith Wizard"
; (pg. 88ff), the left hand fire button gives the value of
; %00010001 and the right hand button gives %00100010
; Why two bits? Am I missing something? Can there be cases that just
; one of those bits is set?
; We just test if any of those two bits is not zero...
; Port values are for the left hand joystick (right hand joystick
; values were shifted to the right to be identical).
; Why are there two bits indicating a pressed trigger?
; According to the "Second book of programs for the Dick Smith Wizard"
; (pg. 88ff), the left hand button gives the value of
; %00010001 and the right hand button gives %00100010
; Why two bits? Can there be cases that just one of those bits is set?
; Until these questions have been answered, we only use the lower two
; bits and ignore the upper ones...
tay
and #%00010001
beq cnv_1
inc retval ; left button pressed
cnv_1: tya
and #%00100010
beq cnv_2
lda #$02
ora retval
sta retval ; right button pressed
and #%00000011 ; button status came in in A, strip high bits
sta retval ; initialize 'retval' with button status
; ------
; direction:
cnv_2: txa
; tested with https://sourceforge.net/projects/creativisionemulator
; $49 - %01001001 - up
; $41 - %01000001 - down
; $4D - %01001101 - left
; $45 - %01000101 - right
;
; are these correct? "Second book of programs for the Dick Smith Wizard" pg. 85 says something different
; ignored for now...
; $85 - %10000101 - up + right
; $8D - %10001101 - down + left
; $89 - %10001001 - up + left
; $85 - %10000101 - down + right (emulator bug?)
; CV has a 16-direction joystick
;
; port values: (compass points)
; N - $49 - %01001001
; NNE - $48 - %01001000
; NE - $47 - %01000111
; ENE - $46 - %01000110
; E - $45 - %01000101
; ESE - $44 - %01000100
; SE - $43 - %01000011
; SSE - $42 - %01000010
; S - $41 - %01000001
; SSW - $40 - %01000000
; SW - $4F - %01001111
; WSW - $4E - %01001110
; W - $4D - %01001101
; WNW - $4C - %01001100
; NW - $4B - %01001011
; NNW - $4A - %01001010
; center - $00 - %00000000
;
; mapping to cc65 definitions (4-direction joystick with 8 possible directions thru combinations)
; N, E, S, W -> JOY_UP, JOY_RIGHT, JOY_DOWN, JOY_LEFT
; NE, SE, SW, NW -> (JOY_UP | JOY_RIGHT), (JOY_DOWN | JOY_RIGHT), (JOY_DOWN | JOY_LEFT), (JOY_UP | JOY_LEFT)
; NNE, ENE, ESE, SSE, SSW, WSW, WNW, NNW:
; toggle between straight and diagonal direction for every call, e.g.
; NNE:
; call to READJOY: return JOY_UP | JOY_RIGHT
; call to READJOY: return JOY_UP
; call to READJOY: return JOY_UP | JOY_RIGHT
; call to READJOY: return JOY_UP
; call to READJOY: return JOY_UP | JOY_RIGHT
; etc...
bit testbit ; bit #0 set?
beq done ; no, no direction
txa ; move direction status into A
beq done ; center position (no bits are set), nothing to do
and #%00001100 ; mask out other bits
lsr a
lsr a
tax
lda #%00000100 ; init bitmask
loop: dex
bmi done2
asl a
bne loop
and #$0F ; get rid of the "$40" bit
bit bit0 ; is it a "three letter" direction (NNE, ENE, etc.)?
beq special ; yes (bit #0 is zero)
done2: ora retval
rts
lsr a ; create index into table
tax
lda dirtable,x
done: ora retval ; include "button" bits
ldx #0
rts
done: lda retval
rts
; NNE, ENE, ESE, SSE, SSW, WSW, WNW, NNW
special: lsr a
tax
lda toggler ; toggle the toggler
eor #$01
sta toggler
bne spec_1 ; toggler is 1, use spectable_1 entry
lda spectable_0,x ; toggler is 0, use spectable_0 entry
bne done ; jump always
spec_1: lda spectable_1,x
bne done ; jump always
; ------------------------------------------------------------------------
;
.data
testbit:.byte $01
.rodata
; a mapping table of "port values" to "cc65 values"
; port value had been shifted one bit to the right (range 0..7)
dirtable: .byte JOY_DOWN ; S
.byte JOY_DOWN | JOY_RIGHT ; SE
.byte JOY_RIGHT ; E
.byte JOY_UP | JOY_RIGHT ; NE
.byte JOY_UP ; N
.byte JOY_UP | JOY_LEFT ; NW
.byte JOY_LEFT ; W
.byte JOY_DOWN | JOY_LEFT ; SW
; two "special" mapping tables for three-letter directions (NNE, etc.)
spectable_0: .byte JOY_DOWN ; SSW
.byte JOY_DOWN ; SSE
.byte JOY_RIGHT ; ESE
.byte JOY_RIGHT ; ENE
.byte JOY_RIGHT ; NNE
.byte JOY_UP ; NNW
.byte JOY_LEFT ; WNW
.byte JOY_LEFT ; WSW
spectable_1: .byte JOY_DOWN | JOY_LEFT ; SSW
.byte JOY_DOWN | JOY_RIGHT ; SSE
.byte JOY_DOWN | JOY_RIGHT ; ESE
.byte JOY_UP | JOY_RIGHT ; ENE
.byte JOY_UP | JOY_RIGHT ; NNE
.byte JOY_UP | JOY_LEFT ; NNW
.byte JOY_UP | JOY_LEFT ; WNW
.byte JOY_DOWN | JOY_LEFT ; WSW
; ------------------------------------------------------------------------
;
.bss
retval: .res 0
bit0: .byte $01
; ------------------------------------------------------------------------
;
.bss
toggler: .res 1
retval: .res 1
.end

View File

@@ -1,22 +0,0 @@
;
; Ullrich von Bassewitz, 2003-03-07
;
; Setup arguments for main
;
.constructor initmainargs, 24
.import __argc, __argv
;---------------------------------------------------------------------------
; Get possible command-line arguments. Goes into the special INIT segment,
; which may be reused after the startup code is run
.segment "INIT"
.proc initmainargs
rts
.endproc

View File

@@ -32,7 +32,7 @@ static char DumpHandler (void);
static char HelpHandler (void);
/* Forwards for other functions */
static void DisplayPrompt (char* s);
static void DisplayPrompt (const char* s);
static void SingleStep (char StepInto);
static void RedrawStatic (char Frame);
static void Redraw (char Frame);
@@ -166,7 +166,7 @@ extern unsigned DbgHI; /* High 16 bit of primary reg */
typedef struct {
unsigned char x;
unsigned char y;
char* text;
const char* text;
} TextDesc;
/* Window descriptor */
@@ -181,13 +181,13 @@ typedef struct {
unsigned char fd_visible; /* Is the window currently visible? */
char (*fd_func) (void); /* Handler function */
unsigned char fd_textcount; /* Number of text lines to print */
TextDesc* fd_text; /* Static text in the window */
const TextDesc* fd_text; /* Static text in the window */
} FrameDesc;
/* Texts for the windows */
static TextDesc RegText [] = {
static const TextDesc RegText [] = {
{ 1, 0, "PC" },
{ 1, 1, "SR" },
{ 1, 2, "A" },
@@ -197,7 +197,7 @@ static TextDesc RegText [] = {
{ 1, 6, "CS" },
{ 1, 7, "HI" }
};
static TextDesc HelpText [] = {
static const TextDesc HelpText [] = {
{ 1, 0, "F1, ? Help" },
{ 1, 1, "F2, t Toggle breakpoint" },
{ 1, 2, "F3, u Run until subroutine returns" },
@@ -220,7 +220,7 @@ static TextDesc HelpText [] = {
/* Window data */
static FrameDesc AsmFrame = {
static const FrameDesc AsmFrame = {
CH_ULCORNER, CH_TTEE, CH_LTEE, CH_CROSS,
0, 0, MAX_X - 10, 15,
MAX_X - 11, 14,
@@ -228,7 +228,7 @@ static FrameDesc AsmFrame = {
AsmHandler,
0, 0
};
static FrameDesc RegFrame = {
static const FrameDesc RegFrame = {
CH_TTEE, CH_URCORNER, CH_LTEE, CH_RTEE,
MAX_X - 10, 0, MAX_X - 1, 9,
8, 8,
@@ -236,7 +236,7 @@ static FrameDesc RegFrame = {
RegHandler,
sizeof (RegText) / sizeof (RegText [0]), RegText
};
static FrameDesc StackFrame = {
static const FrameDesc StackFrame = {
CH_LTEE, CH_RTEE, CH_CROSS, CH_RTEE,
MAX_X - 10, 9, MAX_X - 1, 15,
8, 5,
@@ -244,7 +244,7 @@ static FrameDesc StackFrame = {
StackHandler,
0, 0
};
static FrameDesc CStackFrame = {
static const FrameDesc CStackFrame = {
CH_CROSS, CH_RTEE, CH_BTEE, CH_LRCORNER,
MAX_X - 10, 15, MAX_X - 1, MAX_Y - 1,
8, MAX_Y - 17,
@@ -252,7 +252,7 @@ static FrameDesc CStackFrame = {
CStackHandler,
0, 0
};
static FrameDesc DumpFrame = {
static const FrameDesc DumpFrame = {
CH_LTEE, CH_CROSS, CH_LLCORNER, CH_BTEE,
0, 15, MAX_X - 10, MAX_Y-1,
MAX_X - 11, MAX_Y - 17,
@@ -260,7 +260,7 @@ static FrameDesc DumpFrame = {
DumpHandler,
0, 0
};
static FrameDesc HelpFrame = {
static const FrameDesc HelpFrame = {
CH_ULCORNER, CH_URCORNER, CH_LLCORNER, CH_LRCORNER,
0, 0, MAX_X - 1, MAX_Y-1,
MAX_X - 2, MAX_Y - 2,
@@ -268,7 +268,7 @@ static FrameDesc HelpFrame = {
HelpHandler,
sizeof (HelpText) / sizeof (HelpText [0]), HelpText
};
static FrameDesc* Frames [] = {
static const FrameDesc* const Frames [] = {
&AsmFrame,
&RegFrame,
&StackFrame,
@@ -297,7 +297,7 @@ static unsigned char StackAddr; /* Start address of output */
/* Prompt line data */
static char* ActivePrompt = 0; /* Last prompt line displayed */
static const char* ActivePrompt = 0; /* Last prompt line displayed */
static char PromptColor; /* Color behind prompt */
static char PromptLength; /* Length of current prompt string */
@@ -346,10 +346,10 @@ BreakPoint* DbgIsBreak (unsigned Addr);
static void DrawFrame (register FrameDesc* F, char Active)
static void DrawFrame (register const FrameDesc* F, char Active)
/* Draw one window frame */
{
TextDesc* T;
const TextDesc* T;
unsigned char Count;
unsigned char tl, tr, bl, br;
unsigned char x1, y1, width;
@@ -410,7 +410,7 @@ static void DrawFrames (void)
/* Draw all frames */
{
unsigned char I;
FrameDesc* F;
const FrameDesc* F;
/* Build the frame layout of the screen */
for (I = 0; I < sizeof (Frames) / sizeof (Frames [0]); ++I) {
@@ -427,7 +427,7 @@ static void ActivateFrame (int Num, unsigned char Clear)
/* Activate a new frame, deactivate the old one */
{
unsigned char y;
register FrameDesc* F;
register const FrameDesc* F;
if (ActiveFrame != Num) {
@@ -462,7 +462,7 @@ static void ActivateFrame (int Num, unsigned char Clear)
static void DisplayPrompt (char* s)
static void DisplayPrompt (const char* s)
/* Display a prompt */
{
unsigned char OldColor;
@@ -626,11 +626,11 @@ static char InputHex (char* Prompt, unsigned* Val)
static void ErrorPrompt (char* Msg)
static void ErrorPrompt (const char* Msg)
/* Display an error message and wait for a key */
{
/* Save the current prompt */
char* OldPrompt = ActivePrompt;
const char* OldPrompt = ActivePrompt;
/* Display the new one */
DisplayPrompt (Msg);

View File

@@ -9,7 +9,7 @@
.include "extzp.inc"
gotoxy:
jsr popa ; Get X
jsr popa ; Get Y
_gotoxy:
sta CURS_Y ; Set Y
@@ -20,6 +20,4 @@ _gotoxy:
;-------------------------------------------------------------------------------
; force the init constructor to be imported
.import initconio
conio_init = initconio
.forceimport initconio

View File

@@ -24,17 +24,6 @@
.addr $0000
; Button state masks (8 values)
.byte $01 ; JOY_UP
.byte $02 ; JOY_DOWN
.byte $04 ; JOY_LEFT
.byte $08 ; JOY_RIGHT
.byte $10 ; JOY_FIRE_A
.byte $20 ; JOY_FIRE_B
.byte $80 ; JOY_SELECT
.byte $40 ; JOY_START
; Jump table.
.addr INSTALL

View File

@@ -1,16 +1,18 @@
;
; void waitvblank (void);
; Written by Groepaz <groepaz@gmx.net>
;
; void waitvsync (void);
;
.include "gamate.inc"
.include "extzp.inc"
.forceimport ticktock
.export _waitvblank
.export _waitvsync
; FIXME: is this actually correct?
.proc _waitvblank
.proc _waitvsync
lda tickcount
@lp: cmp tickcount

View File

@@ -28,17 +28,6 @@
.addr $0000
; Button state masks (8 values)
.byte $01 ; JOY_UP
.byte $02 ; JOY_DOWN
.byte $04 ; JOY_LEFT
.byte $08 ; JOY_RIGHT
.byte $10 ; JOY_FIRE
.byte $00 ; Future expansion
.byte $00 ; Future expansion
.byte $00 ; Future expansion
; Jump table.
.word INSTALL

View File

@@ -10,21 +10,21 @@
void _mbprintout(void);
static dlgBoxStr _mbdlg_EMPTY = {
static const dlgBoxStr _mbdlg_EMPTY = {
DB_DEFPOS(1),
DB_OPVEC(&RstrFrmDialogue),
DB_USRROUT(&_mbprintout),
DB_END,
};
static dlgBoxStr _mbdlg_OK = {
static const dlgBoxStr _mbdlg_OK = {
DB_DEFPOS(1),
DB_USRROUT(&_mbprintout),
DB_ICON(OK, DBI_X_1, DBI_Y_2),
DB_END,
};
static dlgBoxStr _mbdlg_OKCANCEL = {
static const dlgBoxStr _mbdlg_OKCANCEL = {
DB_DEFPOS(1),
DB_USRROUT(&_mbprintout),
DB_ICON(OK, DBI_X_0, DBI_Y_2),
@@ -32,7 +32,7 @@ static dlgBoxStr _mbdlg_OKCANCEL = {
DB_END,
};
static dlgBoxStr _mbdlg_YESNO = {
static const dlgBoxStr _mbdlg_YESNO = {
DB_DEFPOS(1),
DB_USRROUT(&_mbprintout),
DB_ICON(YES, DBI_X_0, DBI_Y_2),
@@ -40,7 +40,7 @@ static dlgBoxStr _mbdlg_YESNO = {
DB_END,
};
static dlgBoxStr *_mbboxes[] = {
static const dlgBoxStr * const _mbboxes[] = {
&_mbdlg_EMPTY,
&_mbdlg_OK,
&_mbdlg_OKCANCEL,

View File

@@ -19,8 +19,6 @@
.bss
_joy_drv: .res 2 ; Pointer to driver
_joy_masks: .res .sizeof(JOY_HDR::MASKS)
; Jump table for the driver functions.
.data
joy_vectors:
@@ -65,38 +63,28 @@ _joy_install:
lda #>joy_libref
sta (ptr1),y
; Copy the mask array
ldy #JOY_HDR::MASKS + .sizeof(JOY_HDR::MASKS) - 1
ldx #.sizeof(JOY_HDR::MASKS)-1
@L1: lda (ptr1),y
sta _joy_masks,x
dey
dex
bpl @L1
; Copy the jump vectors
ldy #JOY_HDR::JUMPTAB
ldx #0
@L2: inx ; Skip the JMP opcode
@L1: inx ; Skip the JMP opcode
jsr copy ; Copy one byte
jsr copy ; Copy one byte
cpy #(JOY_HDR::JUMPTAB + .sizeof(JOY_HDR::JUMPTAB))
bne @L2
bne @L1
jsr joy_install ; Call driver install routine
tay ; Test error code
bne @L3 ; Bail out if install had errors
bne @L2 ; Bail out if install had errors
; Install the IRQ vector if the driver needs it. A/X contains the error code
; from joy_install, so don't use it.
ldy joy_irq+2 ; Check high byte of IRQ vector
beq @L3 ; Jump if vector invalid
beq @L2 ; Jump if vector invalid
ldy #$4C ; JMP opcode
sty joy_irq ; Activate IRQ routine
@L3: rts
@L2: rts
; Driver signature invalid

View File

@@ -31,18 +31,6 @@
.addr $0000
; Button state masks (8 values)
joy_mask:
.byte $80 ; JOY_UP
.byte $40 ; JOY_DOWN
.byte $20 ; JOY_LEFT
.byte $10 ; JOY_RIGHT
.byte $01 ; JOY_FIRE
.byte $02 ; JOY_FIRE1
.byte $00 ;
.byte $00 ;
; Jump table.
.addr INSTALL

View File

@@ -29,17 +29,6 @@
.addr $0000
; Button state masks (8 values)
.byte $10 ; JOY_UP
.byte $20 ; JOY_DOWN
.byte $40 ; JOY_LEFT
.byte $80 ; JOY_RIGHT
.byte $01 ; JOY_FIRE (A)
.byte $02 ; JOY_FIRE2 (B)
.byte $04 ; (Select)
.byte $08 ; (Start)
; Jump table.
.addr INSTALL

View File

@@ -1,15 +1,15 @@
;
; Written by Groepaz/Hitmen <groepaz@gmx.net>
; Written by Groepaz <groepaz@gmx.net>
; Cleanup by Ullrich von Bassewitz <uz@cc65.org>
;
; void waitvblank(void);
; void waitvsync(void);
;
.export _waitvblank
.export _waitvsync
.include "nes.inc"
.proc _waitvblank
.proc _waitvsync
wait: lda PPU_STATUS
bpl wait

View File

@@ -1,50 +1,50 @@
;
; char cgetc (void);
;
.constructor initcgetc
.export _cgetc
.import cursor
.include "osic1p.inc"
.include "extzp.inc"
.include "zeropage.inc"
; Initialize one-character buffer that is filled by kbhit()
.segment "ONCE"
initcgetc:
lda #$00
sta CHARBUF ; No character in buffer initially
rts
; Input routine from 65V PROM MONITOR, show cursor if enabled
.code
_cgetc:
lda CHARBUF ; character in buffer available?
beq nobuffer
tax ; save character in X
lda #$00
sta CHARBUF ; empty buffer
beq restorex ; restore X and return
nobuffer:
lda cursor ; show cursor?
beq nocursor
ldy CURS_X
lda (SCREEN_PTR),y ; fetch current character
sta tmp1 ; save it
lda #$A1 ; full white square
sta (SCREEN_PTR),y ; store at cursor position
nocursor:
jsr INPUTC ; get input character in A
ldx cursor
beq done ; was cursor on?
tax ; save A in X
lda tmp1 ; fetch saved character
ldy CURS_X
sta (SCREEN_PTR),y ; store at cursor position
restorex:
txa ; restore saved character from X
done:
ldx #$00 ; high byte of int return value
rts
;
; char cgetc (void);
;
.constructor initcgetc
.export _cgetc
.import cursor
.include "osic1p.inc"
.include "extzp.inc"
.include "zeropage.inc"
; Initialize one-character buffer that is filled by kbhit()
.segment "ONCE"
initcgetc:
lda #$00
sta CHARBUF ; No character in buffer initially
rts
; Input routine from 65V PROM MONITOR, show cursor if enabled
.code
_cgetc:
lda CHARBUF ; character in buffer available?
beq nobuffer
tax ; save character in X
lda #$00
sta CHARBUF ; empty buffer
beq restorex ; restore X and return
nobuffer:
lda cursor ; show cursor?
beq nocursor
ldy CURS_X
lda (SCREEN_PTR),y ; fetch current character
sta tmp1 ; save it
lda #$A1 ; full white square
sta (SCREEN_PTR),y ; store at cursor position
nocursor:
jsr INPUTC ; get input character in A
ldx cursor
beq done ; was cursor on?
tax ; save A in X
lda tmp1 ; fetch saved character
ldy CURS_X
sta (SCREEN_PTR),y ; store at cursor position
restorex:
txa ; restore saved character from X
done:
ldx #$00 ; high byte of int return value
rts

View File

@@ -0,0 +1,14 @@
;
; 2016-06, Christian Groessler
; 2017-06-26, Greg King
;
; unsigned char doesclrscrafterexit (void);
;
; Returns 0/1 if, after program termination, the screen isn't/is cleared.
;
.import return1
; cc65's OSI programs return to the monitor ROM which clears the screen.
.export _doesclrscrafterexit := return1

View File

@@ -1,4 +1,4 @@
; Addresses
INPUTC := $FD00 ; Input character from keyboard
RESET := $FF00 ; Reset address, show boot prompt
KBD := $DF00 ; Polled keyboard register
; Addresses
INPUTC := $FD00 ; Input character from keyboard
RESET := $FF00 ; Reset address, show boot prompt
KBD := $DF00 ; Polled keyboard register

View File

@@ -1,183 +1,183 @@
;
; Macro definitions for screen layout modules
;
.include "extzp.inc"
.linecont +
;
; Internal function for screensize()
;
.macro osi_screensize ScrWidth, ScrHeight
; Macro implementation of internal screensize
; function for given width and height in
; characters
.export screensize
.proc screensize
ldx #ScrWidth
ldy #ScrHeight
rts
.endproc
.endmacro
;
; void clrscr (void);
;
.macro osi_clrscr ScrBase, ScrRamSize
.export _clrscr
.proc _clrscr
lda #<ScrBase ; Fill whole video RAM with blanks by calling
ldx #>ScrBase ; memset appropriately
jsr pushax
lda #' '
ldx #$00
jsr pushax
lda #<ScrRamSize
ldx #>ScrRamSize
jsr _memset
lda #$00 ; Cursor in upper left corner
sta CURS_X
sta CURS_Y
jmp plot ; Set the cursor position
.endproc
.endmacro
;
; cputc/cputcxy for Challenger 1P
; Based on PET/CBM implementation
;
.macro osi_cputfuncs ScrBase, ScrFirstChar, ScrWidth, ScrHeight, \
ScrollDist, ScrLo, ScrHi
; Number of characters to move for scrolling
; by one line
ScrollLength = (ScrHeight - 1) * ScrollDist
;
; void cputcxy (unsigned char x, unsigned char y, char c);
; void cputc (char c);
;
.export _cputcxy, _cputc, cputdirect, putchar
.export newline, plot
_cputcxy:
pha ; Save C
jsr gotoxy ; Set cursor, drop x and y
pla ; Restore C
; Plot a character - also used as internal function
_cputc: cmp #$0A ; CR?
bne L1
lda #0
sta CURS_X
beq plot ; Recalculate pointers
L1: cmp #$0D ; LF?
beq newline ; Recalculate pointers
cputdirect:
jsr putchar ; Write the character to the screen
; Advance cursor position, register Y contains horizontal position after
; putchar
cpy #(ScrWidth - 1) ; Check whether line is full
bne L3
jsr newline ; New line
ldy #$FF ; + cr
L3: iny
sty CURS_X
rts
newline:
inc CURS_Y
lda CURS_Y
cmp #ScrHeight ; Screen height
bne plot
dec CURS_Y ; Bottom of screen reached, scroll
; Scroll destination address
lda #<(ScrBase + ScrFirstChar)
ldx #>(ScrBase + ScrFirstChar)
jsr pushax
; Scroll source address
lda #<(ScrBase + ScrFirstChar + ScrollDist)
ldx #>(ScrBase + ScrFirstChar + ScrollDist)
jsr pushax
; Number of characters to move
lda #<ScrollLength
ldx #>ScrollLength
jsr _memmove
; Address of first character in last line
; of screen
lda #<(ScrBase + ScrFirstChar + ScrollLength)
sta ptr1
lda #>(ScrBase + ScrFirstChar + ScrollLength)
sta ptr1+1
ldy #ScrWidth ; Fill last line with blanks
lda #' '
clrln: sta (ptr1),y
dey
bpl clrln
plot: ldy CURS_Y
lda ScrLo,y
sta SCREEN_PTR
lda ScrHi,y
sta SCREEN_PTR+1
rts
; Write one character to the screen without doing anything else, return X
; position in register Y
putchar:
ldy CURS_X
sta (SCREEN_PTR),y ; Set char
rts
.endmacro
.macro osi_screen_funcs ScrBase, ScrRamSize, ScrFirstChar, \
ScrWidth, ScrHeight, ScrollDist
.import gotoxy
.import _memmove, _memset, pushax
.importzp ptr1
.rodata
; Screen address tables - offset to real screen
ScrTabLo:
.repeat ScrHeight, I
.byte <(ScrBase + ScrFirstChar + I * ScrollDist)
.endrep
ScrTabHi:
.repeat ScrHeight, I
.byte >(ScrBase + ScrFirstChar + I * ScrollDist)
.endrep
.code
osi_cputfuncs ScrBase, ScrFirstChar, ScrWidth, ScrHeight, \
ScrollDist, ScrTabLo, ScrTabHi
osi_screensize ScrWidth, ScrHeight
osi_clrscr ScrBase, ScrRamSize
;
; Macro definitions for screen layout modules
;
.include "extzp.inc"
.linecont +
;
; Internal function for screensize()
;
.macro osi_screensize ScrWidth, ScrHeight
; Macro implementation of internal screensize
; function for given width and height in
; characters
.export screensize
.proc screensize
ldx #ScrWidth
ldy #ScrHeight
rts
.endproc
.endmacro
;
; void clrscr (void);
;
.macro osi_clrscr ScrBase, ScrRamSize
.export _clrscr
.proc _clrscr
lda #<ScrBase ; Fill whole video RAM with blanks by calling
ldx #>ScrBase ; memset appropriately
jsr pushax
lda #' '
ldx #$00
jsr pushax
lda #<ScrRamSize
ldx #>ScrRamSize
jsr _memset
lda #$00 ; Cursor in upper left corner
sta CURS_X
sta CURS_Y
jmp plot ; Set the cursor position
.endproc
.endmacro
;
; cputc/cputcxy for Challenger 1P
; Based on PET/CBM implementation
;
.macro osi_cputfuncs ScrBase, ScrFirstChar, ScrWidth, ScrHeight, \
ScrollDist, ScrLo, ScrHi
; Number of characters to move for scrolling
; by one line
ScrollLength = (ScrHeight - 1) * ScrollDist
;
; void cputcxy (unsigned char x, unsigned char y, char c);
; void cputc (char c);
;
.export _cputcxy, _cputc, cputdirect, putchar
.export newline, plot
_cputcxy:
pha ; Save C
jsr gotoxy ; Set cursor, drop x and y
pla ; Restore C
; Plot a character - also used as internal function
_cputc: cmp #$0A ; CR?
bne L1
lda #0
sta CURS_X
beq plot ; Recalculate pointers
L1: cmp #$0D ; LF?
beq newline ; Recalculate pointers
cputdirect:
jsr putchar ; Write the character to the screen
; Advance cursor position, register Y contains horizontal position after
; putchar
cpy #(ScrWidth - 1) ; Check whether line is full
bne L3
jsr newline ; New line
ldy #$FF ; + cr
L3: iny
sty CURS_X
rts
newline:
inc CURS_Y
lda CURS_Y
cmp #ScrHeight ; Screen height
bne plot
dec CURS_Y ; Bottom of screen reached, scroll
; Scroll destination address
lda #<(ScrBase + ScrFirstChar)
ldx #>(ScrBase + ScrFirstChar)
jsr pushax
; Scroll source address
lda #<(ScrBase + ScrFirstChar + ScrollDist)
ldx #>(ScrBase + ScrFirstChar + ScrollDist)
jsr pushax
; Number of characters to move
lda #<ScrollLength
ldx #>ScrollLength
jsr _memmove
; Address of first character in last line
; of screen
lda #<(ScrBase + ScrFirstChar + ScrollLength)
sta ptr1
lda #>(ScrBase + ScrFirstChar + ScrollLength)
sta ptr1+1
ldy #ScrWidth ; Fill last line with blanks
lda #' '
clrln: sta (ptr1),y
dey
bpl clrln
plot: ldy CURS_Y
lda ScrLo,y
sta SCREEN_PTR
lda ScrHi,y
sta SCREEN_PTR+1
rts
; Write one character to the screen without doing anything else, return X
; position in register Y
putchar:
ldy CURS_X
sta (SCREEN_PTR),y ; Set char
rts
.endmacro
.macro osi_screen_funcs ScrBase, ScrRamSize, ScrFirstChar, \
ScrWidth, ScrHeight, ScrollDist
.import gotoxy
.import _memmove, _memset, pushax
.importzp ptr1
.rodata
; Screen address tables - offset to real screen
ScrTabLo:
.repeat ScrHeight, I
.byte <(ScrBase + ScrFirstChar + I * ScrollDist)
.endrep
ScrTabHi:
.repeat ScrHeight, I
.byte >(ScrBase + ScrFirstChar + I * ScrollDist)
.endrep
.code
osi_cputfuncs ScrBase, ScrFirstChar, ScrWidth, ScrHeight, \
ScrollDist, ScrTabLo, ScrTabHi
osi_screensize ScrWidth, ScrHeight
osi_clrscr ScrBase, ScrRamSize
.endmacro

9
libsrc/osic1p/revers.s Normal file
View File

@@ -0,0 +1,9 @@
;
; 2017-06-26, Greg King
;
; unsigned char __fastcall__ revers (unsigned char onoff)
;
.import return0
.export _revers := return0 ; no attribute

View File

@@ -24,17 +24,6 @@
.addr $0000
; Button state masks (8 values)
.byte $10 ; JOY_UP
.byte $40 ; JOY_DOWN
.byte $80 ; JOY_LEFT
.byte $20 ; JOY_RIGHT
.byte $01 ; JOY_FIRE_A
.byte $02 ; JOY_FIRE_B
.byte $04 ; JOY_SELECT
.byte $08 ; JOY_RUN
; Jump table.
.addr INSTALL

View File

@@ -1,14 +1,16 @@
;
; void waitvblank (void);
; Written by Groepaz <groepaz@gmx.net>
;
; void waitvsync (void);
;
.include "pce.inc"
.include "extzp.inc"
.forceimport ticktock
.export _waitvblank
.export _waitvsync
.proc _waitvblank
.proc _waitvsync
lda tickcount
@lp: cmp tickcount

View File

@@ -28,17 +28,6 @@
.addr $0000
; Button state masks (8 values)
.byte $01 ; JOY_UP
.byte $02 ; JOY_DOWN
.byte $04 ; JOY_LEFT
.byte $08 ; JOY_RIGHT
.byte $10 ; JOY_FIRE
.byte $00 ; JOY_FIRE2 unavailable
.byte $00 ; Future expansion
.byte $00 ; Future expansion
; Jump table.
.addr INSTALL

View File

@@ -27,17 +27,6 @@
.addr $0000
; Button state masks (8 values)
.byte $01 ; JOY_UP
.byte $02 ; JOY_DOWN
.byte $04 ; JOY_LEFT
.byte $08 ; JOY_RIGHT
.byte $10 ; JOY_FIRE
.byte $00 ; JOY_FIRE2 unavailable
.byte $00 ; Future expansion
.byte $00 ; Future expansion
; Jump table.
.addr INSTALL

29
libsrc/pet/kbrepeat.s Normal file
View File

@@ -0,0 +1,29 @@
;
; unsigned char __fastcall__ kbrepeat (unsigned char mode);
;
; 2017-06-16, Groepaz
; 2017-09-05, Greg King
;
.export _kbrepeat
.include "pet.inc"
_kbrepeat:
ldx #>$0000
ldy SCR_LINELEN
cpy #40 + 1
bcc L1 ; branch if screen is 40 columns wide
ldy KBDREPEAT80 ; get old value
sta KBDREPEAT80 ; store new value
tya ; return old value
rts
L1: tay
lda KBDREPEAT40B ; get REPEAT-key flag (used by some editor ROMs)
lsr a ; move bit 0 into bit 7
ror a
ora KBDREPEAT40 ; combine with old key-REPEAT flags
sty KBDREPEAT40
rts

View File

@@ -31,17 +31,6 @@
.addr $0000
; Button state masks (8 values)
.byte $01 ; JOY_UP
.byte $02 ; JOY_DOWN
.byte $04 ; JOY_LEFT
.byte $08 ; JOY_RIGHT
.byte $80 ; JOY_FIRE
.byte $00 ; JOY_FIRE2 unavailable
.byte $00 ; Future expansion
.byte $00 ; Future expansion
; Jump table.
.addr INSTALL
@@ -107,7 +96,7 @@ READ: ldy #%11111011 ; Load index for joystick #1
cli
eor #%11111111
; The fire buttons are in bits 6 and 7. Both of them cannot be %1 together.
; The push buttons are in bits 6 and 7. Both of them cannot be %1 together.
; Therefore, bit 6 can be merged with bit 7.
clc

14
libsrc/plus4/kbrepeat.s Normal file
View File

@@ -0,0 +1,14 @@
;
; unsigned char __fastcall__ kbrepeat (unsigned char mode);
;
.export _kbrepeat
.include "plus4.inc"
_kbrepeat:
ldx KBDREPEAT ; get old value
sta KBDREPEAT ; store new value
txa ; return old value
ldx #0
rts

17
libsrc/plus4/waitvsync.s Normal file
View File

@@ -0,0 +1,17 @@
;
; Written by Groepaz <groepaz@gmx.net>
;
; void waitvsync (void);
;
.export _waitvsync
.include "plus4.inc"
_waitvsync:
@l1:
lda TED_VLINEHI
and #$01
ora TED_VLINELO
bne @l1
rts

View File

@@ -1,5 +1,6 @@
;
; Ullrich von Bassewitz, 05.08.1998
; Christian Krueger, 11-Mar-2017, spend two bytes for one cycle, improved 65SC02 optimization
;
; CC65 runtime: add ints
;
@@ -8,32 +9,46 @@
; called a lot!
.export tosadda0, tosaddax
.importzp sp
.importzp sp, tmp1
.macpack cpu
tosadda0:
ldx #0
tosaddax:
clc
.if (.cpu .bitand CPU_ISET_65SC02)
adc (sp) ; 65SC02 version - saves 2 cycles
ldy #1
.else
ldy #0
adc (sp),y ; lo byte
iny
.endif
pha ; save it
txa
adc (sp),y ; hi byte
tax
clc
lda sp
adc #2
sta sp
bcc L1
inc sp+1
L1: pla ; Restore low byte
rts
clc ; (2)
.if (.cpu .bitand ::CPU_ISET_65SC02)
adc (sp) ; (7)
tay ; (9)
inc sp ; (14)
bne hiadd ; (17)
inc sp+1 ; (-1+5)
hiadd: txa ; (19)
adc (sp) ; (24)
tax ; (26)
inc sp ; (31)
bne done ; (34)
inc sp+1 ; (-1+5)
done: tya ; (36)
.else
ldy #0 ; (4)
adc (sp),y ; (9) lo byte
iny ; (11)
sta tmp1 ; (14) save it
txa ; (16)
adc (sp),y ; (21) hi byte
tax ; (23)
clc ; (25)
lda sp ; (28)
adc #2 ; (30)
sta sp ; (33)
bcc L1 ; (36)
inc sp+1 ; (-1+5)
L1: lda tmp1 ; (39) restore low byte
.endif
rts ; (6502: 45 cycles, 26 bytes <-> 65SC02: 42 cycles, 22 bytes )

View File

@@ -1,5 +1,6 @@
;
; Ullrich von Bassewitz, 23.11.2002
; Christian Krueger, 11-Mar-2017, saved 5 bytes
;
; CC65 runtime: Convert char in ax into a long
;
@@ -9,16 +10,11 @@
; Convert A from char to long in EAX
along: ldx #$ff
cmp #$80 ; Positive?
bcs store ; no, apply $FF
aulong: ldx #0
stx sreg
store: stx sreg
stx sreg+1
rts
along: cmp #$80 ; Positive?
bcc aulong ; Yes, handle like unsigned type
ldx #$ff
stx sreg
stx sreg+1
rts

View File

@@ -1,5 +1,6 @@
;
; Ullrich von Bassewitz, 25.10.2000
; Christian Krueger, 02-Mar-2017, some bytes saved
;
; CC65 runtime: Convert int in ax into a long
;
@@ -9,18 +10,12 @@
; Convert AX from int to long in EAX
axlong: ldy #$ff
cpx #$80 ; Positive?
bcs store ; No, apply $FF
axulong:
ldy #0
sty sreg
store: sty sreg
sty sreg+1
rts
axlong: cpx #$80 ; Positive?
bcc axulong ; Yes, handle like unsigned type
ldy #$ff
sty sreg
sty sreg+1
rts

10
libsrc/runtime/callptr4.s Normal file
View File

@@ -0,0 +1,10 @@
;
; CC65 runtime: call function via pointer in ptr4
;
.export callptr4
.importzp ptr4
callptr4:
jmp (ptr4) ; jump there

View File

@@ -1,5 +1,6 @@
;
; Ullrich von Bassewitz, 07.04.2000
; Christian Krueger, 12-Mar-2017, added 65SC02 optimization
;
; CC65 runtime: += operator
;
@@ -10,6 +11,7 @@
.export laddeq1, laddeqa, laddeq
.importzp sreg, ptr1, tmp1
.macpack cpu
laddeq1:
lda #$01
@@ -20,14 +22,20 @@ laddeqa:
stx sreg+1
laddeq: sty ptr1+1 ; Store high byte of address
ldy #$00 ; Address low byte
clc
.if (.cpu .bitand ::CPU_ISET_65SC02)
adc (ptr1)
sta (ptr1)
ldy #$01 ; Address byte 1
.else
ldy #$00 ; Address low byte
adc (ptr1),y
sta (ptr1),y
iny ; Address byte 1
.endif
pha ; Save byte 0 of result for later
iny ; Address byte 1
txa
adc (ptr1),y ; Load byte 1
sta (ptr1),y

View File

@@ -1,5 +1,6 @@
;
; Ullrich von Bassewitz, 06.08.1998
; Christian Krueger, 11-Mar-2017, added 65SC02 optimization
;
; CC65 runtime: and on longs
;
@@ -8,17 +9,28 @@
.import addysp1
.importzp sp, sreg, tmp1
.macpack cpu
tosand0ax:
.if (.cpu .bitand ::CPU_ISET_65SC02)
stz sreg
stz sreg+1
.else
ldy #$00
sty sreg
sty sreg+1
.endif
tosandeax:
.if (.cpu .bitand ::CPU_ISET_65SC02)
and (sp) ; byte 0
ldy #1
.else
ldy #0
and (sp),y ; byte 0
sta tmp1
iny
.endif
sta tmp1
txa
and (sp),y ; byte 1
tax

View File

@@ -1,5 +1,6 @@
;
; Ullrich von Bassewitz, 06.08.1998
; Christian Krueger, 11-Mar-2017, added 65SC02 optimization
;
; CC65 runtime: function epilogue
;
@@ -13,6 +14,8 @@
.import addysp
.importzp sp
.macpack cpu
leave00:
lda #0
leave0: ldx #0
@@ -24,6 +27,20 @@ leavey0:
ldx #0 ; return < 256
leavey:
jsr addysp ; drop stack frame
.if (.cpu .bitand ::CPU_ISET_65SC02)
leave: tay ; save A a sec
lda (sp) ; that's the pushed arg size
sec ; Count the byte, the count's stored in
adc sp
sta sp
bcc L1
inc sp+1
L1: tya ; Get return value back
.else
leave: pha ; save A a sec
ldy #0
lda (sp),y ; that's the pushed arg size
@@ -33,5 +50,7 @@ leave: pha ; save A a sec
bcc L1
inc sp+1
L1: pla ; Get return value back
.endif
rts

View File

@@ -1,6 +1,6 @@
;
; Ullrich von Bassewitz, 07.08.1998
;
; Christian Krueger, 11-Mar-2017, added 65SC02 optimization
; CC65 runtime: modulo operation for long signed ints
;
@@ -11,10 +11,17 @@
.import poplsargs, udiv32, negeax
.importzp sreg, ptr1, ptr2, tmp1, tmp3, tmp4
.macpack cpu
tosmod0ax:
.if (.cpu .bitand ::CPU_ISET_65SC02)
stz sreg
stz sreg+1
.else
ldy #$00
sty sreg
sty sreg+1
.endif
tosmodeax:
jsr poplsargs ; Get arguments from stack, adjust sign

View File

@@ -1,5 +1,6 @@
;
; Ullrich von Bassewitz, 13.08.1998
; Christian Krueger, 11-Mar-2017, added 65SC02 optimization
;
; CC65 runtime: multiplication for long (unsigned) ints
;
@@ -8,20 +9,32 @@
.import addysp1
.importzp sp, sreg, tmp1, tmp2, tmp3, tmp4, ptr1, ptr3, ptr4
.macpack cpu
tosmul0ax:
tosumul0ax:
.if (.cpu .bitand ::CPU_ISET_65SC02)
stz sreg
stz sreg+1
.else
ldy #$00
sty sreg
sty sreg+1
.endif
tosmuleax:
tosumuleax:
mul32: sta ptr1
stx ptr1+1 ; op2 now in ptr1/sreg
.if (.cpu .bitand ::CPU_ISET_65SC02)
lda (sp)
ldy #1
.else
ldy #0
lda (sp),y
sta ptr3
iny
.endif
sta ptr3
lda (sp),y
sta ptr3+1
iny

View File

@@ -1,5 +1,6 @@
;
; Ullrich von Bassewitz, 06.08.1998
; Christian Krueger, 11-Mar-2017, added 65SC02 optimization
;
; CC65 runtime: or on longs
;
@@ -8,17 +9,28 @@
.import addysp1
.importzp sp, sreg, tmp1
.macpack cpu
tosor0ax:
.if (.cpu .bitand ::CPU_ISET_65SC02)
stz sreg
stz sreg+1
.else
ldy #$00
sty sreg
sty sreg+1
sty sreg+1
.endif
tosoreax:
.if (.cpu .bitand ::CPU_ISET_65SC02)
ora (sp)
ldy #1
.else
ldy #0
ora (sp),y ; byte 0
sta tmp1
iny
.endif
sta tmp1
txa
ora (sp),y ; byte 1
tax

View File

@@ -1,5 +1,6 @@
;
; Ullrich von Bassewitz, 29.12.1999
; Christian Krueger, 11-Mar-2017, added 65SC02 optimization
;
; CC65 runtime: long pop
;
@@ -8,6 +9,7 @@
.import incsp4
.importzp sp, sreg
.macpack cpu
popeax: ldy #3
lda (sp),y
@@ -18,8 +20,12 @@ popeax: ldy #3
dey
lda (sp),y
tax
.if (.cpu .bitand ::CPU_ISET_65SC02)
lda (sp)
.else
dey
lda (sp),y
.endif
jmp incsp4

View File

@@ -1,5 +1,6 @@
;
; Ullrich von Bassewitz, 06.08.1998
; Christian Krueger, 11-Mar-2017, added 65SC02 optimization
;
; CC65 runtime: long push
;
@@ -11,13 +12,20 @@
.import decsp4
.importzp sp, sreg
.macpack cpu
pushl0:
lda #0
tax
push0ax:
ldy #0
.if (.cpu .bitand ::CPU_ISET_65SC02)
stz sreg
stz sreg+1
.else
ldy #$00
sty sreg
sty sreg+1
.endif
pusheax:
pha ; decsp will destroy A (but not X)
jsr decsp4
@@ -30,8 +38,12 @@ pusheax:
dey
txa
sta (sp),y
dey
pla
.if (.cpu .bitand ::CPU_ISET_65SC02)
sta (sp)
.else
dey
sta (sp),y
.endif
rts

View File

@@ -1,5 +1,6 @@
;
; Ullrich von Bassewitz, 05.08.1998
; Christian Krueger, 11-Mar-2017, added 65SC02 optimization
;
; CC65 runtime: long sub reversed
;
@@ -11,18 +12,30 @@
.import addysp1
.importzp sp, sreg, tmp1
.macpack cpu
tosrsub0ax:
.if (.cpu .bitand ::CPU_ISET_65SC02)
stz sreg
stz sreg+1
.else
ldy #$00
sty sreg
sty sreg+1
.endif
tosrsubeax:
ldy #0
tosrsubeax:
sec
.if (.cpu .bitand ::CPU_ISET_65SC02)
sbc (sp)
ldy #1
.else
ldy #0
sbc (sp),y ; byte 0
iny
.endif
sta tmp1 ; use as temp storage
txa
iny
sbc (sp),y ; byte 1
tax
iny

View File

@@ -1,7 +1,8 @@
;
; Ullrich von Bassewitz, 08.08.1998
; Christian Krueger, 11-Mar-2017, optimization
;
; CC65 runtime: save ax into temp storage/restore ax from temp storage
; CC65 runtime: save eax into temp storage/restore eax from temp storage
;
.export saveeax, resteax
@@ -10,11 +11,10 @@
saveeax:
sta regsave
stx regsave+1
lda sreg
sta regsave+2
lda sreg+1
sta regsave+3
lda regsave
ldy sreg
sty regsave+2
ldy sreg+1
sty regsave+3
rts
resteax:
@@ -25,4 +25,3 @@ resteax:
ldx regsave+1
lda regsave
rts

View File

@@ -1,6 +1,6 @@
;
; Ullrich von Bassewitz, 05.08.1998
;
; Christian Krueger, 11-Mar-2017, ímproved 65SC02 optimization
; CC65 runtime: long sub
;
@@ -14,14 +14,19 @@
.macpack cpu
tossub0ax:
.if (.cpu .bitand ::CPU_ISET_65SC02)
stz sreg
stz sreg+1
.else
ldy #$00
sty sreg
sty sreg+1
.endif
tossubeax:
sec
eor #$FF
.if (.cpu .bitand CPU_ISET_65SC02)
.if (.cpu .bitand ::CPU_ISET_65SC02)
adc (sp) ; 65SC02 version - saves 2 cycles
ldy #1
.else

View File

@@ -1,5 +1,6 @@
;
; Ullrich von Bassewitz, 07.04.2000
; Christian Krueger, 12-Mar-2017, added 65SC02 optimization
;
; CC65 runtime: -= operator
;
@@ -10,6 +11,7 @@
.export lsubeq1, lsubeqa, lsubeq
.importzp sreg, ptr1
.macpack cpu
lsubeq1:
lda #$01
@@ -20,15 +22,20 @@ lsubeqa:
stx sreg+1
lsubeq: sty ptr1+1 ; Store high byte of address
ldy #$00 ; Address low byte
sec
eor #$FF
.if (.cpu .bitand ::CPU_ISET_65SC02)
adc (ptr1) ; Subtract byte 0
sta (ptr1)
ldy #$01 ; Address byte 1
.else
ldy #$00 ; Address low byte
adc (ptr1),y ; Subtract byte 0
sta (ptr1),y
iny ; Address byte 1
.endif
pha ; Save byte 0 of result for later
iny ; Address byte 1
txa
eor #$FF
adc (ptr1),y ; Subtract byte 1

View File

@@ -1,5 +1,6 @@
;
; Ullrich von Bassewitz, 17.08.1998
; Christian Krueger, 11-Mar-2017, added 65SC02 optimization
;
; CC65 runtime: division for long unsigned ints
;
@@ -8,10 +9,17 @@
.import addysp1
.importzp sp, sreg, tmp3, tmp4, ptr1, ptr2, ptr3, ptr4
.macpack cpu
tosudiv0ax:
.if (.cpu .bitand ::CPU_ISET_65SC02)
stz sreg
stz sreg+1
.else
ldy #$00
sty sreg
sty sreg+1
.endif
tosudiveax:
jsr getlop ; Get the paramameters
@@ -30,10 +38,15 @@ getlop: sta ptr3 ; Put right operand in place
lda sreg+1
sta ptr4+1
.if (.cpu .bitand ::CPU_ISET_65SC02)
lda (sp)
ldy #1
.else
ldy #0 ; Put left operand in place
lda (sp),y
sta ptr1
iny
.endif
sta ptr1
lda (sp),y
sta ptr1+1
iny

View File

@@ -1,5 +1,6 @@
;
; Ullrich von Bassewitz, 27.09.1998
; Christian Krueger, 11-Mar-2017, added 65SC02 optimization
;
; CC65 runtime: modulo operation for long unsigned ints
;
@@ -8,10 +9,17 @@
.import getlop, udiv32
.importzp sreg, tmp3, tmp4, ptr2
.macpack cpu
tosumod0ax:
.if (.cpu .bitand ::CPU_ISET_65SC02)
stz sreg
stz sreg+1
.else
ldy #$00
sty sreg
sty sreg+1
.endif
tosumodeax:
jsr getlop ; Get the paramameters

View File

@@ -1,5 +1,6 @@
;
; Ullrich von Bassewitz, 06.08.1998
; Christian Krueger, 11-Mar-2017, added 65SC02 optimization
;
; CC65 runtime: xor on longs
;
@@ -8,16 +9,28 @@
.import addysp1
.importzp sp, sreg, tmp1
.macpack cpu
tosxor0ax:
.if (.cpu .bitand ::CPU_ISET_65SC02)
stz sreg
stz sreg+1
.else
ldy #$00
sty sreg
sty sreg+1
.endif
tosxoreax:
tosxoreax:
.if (.cpu .bitand ::CPU_ISET_65SC02)
eor (sp) ; byte 0
ldy #1
.else
ldy #0
eor (sp),y ; byte 0
sta tmp1
iny
.endif
sta tmp1
txa
eor (sp),y ; byte 1
tax

View File

@@ -1,5 +1,6 @@
;
; Ullrich von Bassewitz, 05.10.1998
; Christian Krueger, 11-Mar-2017, optimization
;
; CC65 runtime: Make boolean according to flags
;
@@ -9,14 +10,14 @@
boolne: bne ret1
ldx #$00
ret0: ldx #$00
txa
rts
booleq: beq ret1
ldx #$00
txa
booleq: bne ret0
ret1: ldx #$00
lda #$01
rts
@@ -44,17 +45,9 @@ boolult:
boolugt:
beq L1
beq ret0
booluge:
bcs ret1
L1: ldx #$00
ldx #$00
txa
rol a
rts
ret1: ldx #$00
lda #$01
rts

View File

@@ -1,5 +1,6 @@
;
; Ullrich von Bassewitz, 05.08.1998
; Christian Krueger, 11-Mar-2017, added 65SC02 optimization
;
; CC65 runtime: or on ints
;
@@ -8,13 +9,20 @@
.import addysp1
.importzp sp, tmp1
.macpack cpu
tosora0:
ldx #$00
tosorax:
.if (.cpu .bitand ::CPU_ISET_65SC02)
ora (sp)
ldy #1
.else
ldy #0
ora (sp),y
sta tmp1
iny
.endif
sta tmp1
txa
ora (sp),y
tax

View File

@@ -1,5 +1,6 @@
;
; Ullrich von Bassewitz, 05.08.1998
; Christian Krueger, 11-Mar-2017, added 65SC02 optimization
;
; CC65 runtime: sub ints reversed
;
@@ -8,6 +9,8 @@
.import addysp1
.importzp sp, tmp1
.macpack cpu
;
; AX = AX - TOS
;
@@ -15,12 +18,17 @@
tosrsuba0:
ldx #0
tosrsubax:
ldy #0
sec
.if (.cpu .bitand CPU_ISET_65SC02)
sbc (sp)
ldy #1
.else
ldy #0
sbc (sp),y ; lo byte
iny
.endif
sta tmp1 ; save lo byte
txa
iny
sbc (sp),y ; hi byte
tax
lda tmp1

View File

@@ -1,5 +1,6 @@
;
; Ullrich von Bassewitz, 26.10.2000
; Christian Krueger, 12-Mar-2017, added 65SC02 optimization
;
; CC65 runtime: Store a/x indirect into address at top of stack with index
;
@@ -8,6 +9,8 @@
.import incsp2
.importzp sp, tmp1, ptr1
.macpack cpu
.proc staxspidx
sty tmp1 ; Save Y
@@ -15,8 +18,12 @@
ldy #1
lda (sp),y
sta ptr1+1
.if (.cpu .bitand ::CPU_ISET_65SC02)
lda (sp)
.else
dey
lda (sp),y
.endif
sta ptr1 ; Address now in ptr1
ldy tmp1 ; Restore Y
iny ; Address high byte

View File

@@ -1,5 +1,6 @@
;
; Ullrich von Bassewitz, 06.08.1998
; Christian Krueger, 11-Mar-2017, added 65SC02 optimization
;
; CC65 runtime: swap ax with TOS
;
@@ -7,6 +8,8 @@
.export swapstk
.importzp sp, ptr4
.macpack cpu
swapstk:
sta ptr4
stx ptr4+1
@@ -15,11 +18,18 @@ swapstk:
tax
lda ptr4+1
sta (sp),y
.if (.cpu .bitand ::CPU_ISET_65SC02)
lda (sp)
tay
lda ptr4
sta (sp)
tya
.else
dey
lda (sp),y
pha
lda ptr4
sta (sp),y
pla
.endif
rts ; whew!

View File

@@ -1,5 +1,6 @@
;
; Ullrich von Bassewitz, 05.08.1998
; Christian Krueger, 11-Mar-2017, added 65SC02 optimization
;
; CC65 runtime: xor on ints
;
@@ -8,13 +9,20 @@
.import addysp1
.importzp sp, tmp1
.macpack cpu
tosxora0:
ldx #$00
tosxorax:
.if (.cpu .bitand CPU_ISET_65SC02)
eor (sp)
ldy #1
.else
ldy #0
eor (sp),y
sta tmp1
iny
.endif
sta tmp1
txa
eor (sp),y
tax

View File

@@ -1,19 +1,26 @@
;
; jede jede@oric.org 2017-02-25
; 2017-02-25, jede <jede@oric.org>
; 2017-06-15, Greg King
;
; void gotoxy (unsigned char x, unsigned char y);
;
.export _gotoxy
.import popa
.importzp sp
.include "telestrat.inc"
.export gotoxy, _gotoxy
.import popa
.importzp sp
.include "telestrat.inc"
gotoxy: jsr popa ; Get Y
.proc _gotoxy
; This function move only cursor for display, it does not move the prompt position
; in telemon, there is position for prompt, and another for the cursor
sta SCRY
jsr popa
sta SCRX
rts
.endproc
; This function moves only the display cursor; it does not move the prompt position.
; In telemon, there is a position for the prompt, and another for the cursor.
sta SCRY
jsr popa
sta SCRX
rts
.endproc

View File

@@ -30,17 +30,6 @@
.addr $0000
; Button state masks (8 values)
.byte $01 ; JOY_UP
.byte $02 ; JOY_DOWN
.byte $04 ; JOY_LEFT
.byte $08 ; JOY_RIGHT
.byte $10 ; JOY_FIRE
.byte $00 ; JOY_FIRE2 unavailable
.byte $00 ; Future expansion
.byte $00 ; Future expansion
; Jump table.
.addr INSTALL
@@ -113,10 +102,21 @@ joy1: lda #$7F ; mask for VIA2 JOYBIT: sw3
sty VIA1_DDRA ; restore the state of DDRA
cli ; necessary?
ror ; Shift sw3 into bit 7
and #$9E ; Mask relevant bits
eor #$9E ; Active states are inverted
php ; Save sw3 in carry
lsr ; Shift sw0,sw1,sw2,sw4 into bits 1-4
tax ; Save sw0,sw1,sw2
and #$10 ; Extract sw4 in bit 4
sta tmp1 ; Save sw4 in bit 4
txa ; Restore sw0,sw1,sw2
lsr ; Shift sw0,sw1,sw2 into bits 0-2
and #$07 ; Mask bits 0-2
plp ; Restore sw3 in carry
bcc @L0 ; Is sw3 set?
ora #$08 ; Yes: Add sw3 in bit 3
@L0: ora tmp1 ; Add sw4 in bit 4
eor #$1F ; Active states are inverted
ldx #0
rts
; Read joystick 2
@@ -131,8 +131,8 @@ joy2: lda #%10000000 ; via port B Data-Direction
sta VIA1_PRB ; (output one at PB7)
lda VIA1_PRB ; via port B read/write
and #$1f ; get bit 4-0 (PB4-PB0)
eor #$1f
and #$1F ; get bit 4-0 (PB4-PB0)
eor #$1F
rts
; Read joystick 3
@@ -141,15 +141,14 @@ joy3: lda #$00 ; via port B read/write
sta VIA1_PRB ; (output zero at PB7)
lda VIA1_PRB ; via port B read/write
and #$0f ; get bit 3-0 (PB3-PB0)
and #$0F ; get bit 3-0 (PB3-PB0)
sta tmp1 ; joy 4 directions
lda VIA1_PRB ; via port B read/write
and #%00100000 ; get bit 5 (PB5)
lsr
ora tmp1
eor #$1f
eor #$1F
ldx #0
rts

View File

@@ -30,17 +30,6 @@
.addr $0000
; Button state masks (8 values)
.byte $02 ; JOY_UP
.byte $04 ; JOY_DOWN
.byte $08 ; JOY_LEFT
.byte $80 ; JOY_RIGHT
.byte $10 ; JOY_FIRE
.byte $00 ; JOY_FIRE2 unavailable
.byte $00 ; Future expansion
.byte $00 ; Future expansion
; Jump table.
.addr INSTALL
@@ -112,10 +101,19 @@ READ: lda #$7F ; mask for VIA2 JOYBIT: sw3
sty VIA1_DDRA ; restore the state of DDRA
cli ; necessary?
ror ; Shift sw3 into bit 7
and #$9E ; Mask relevant bits
eor #$9E ; Active states are inverted
php ; Save sw3 in carry
lsr ; Shift sw0,sw1,sw2,sw4 into bits 1-4
tax ; Save sw0,sw1,sw2
and #$10 ; Extract sw4 in bit 4
sta tmp1 ; Save sw4 in bit 4
txa ; Restore sw0,sw1,sw2
lsr ; Shift sw0,sw1,sw2 into bits 0-2
and #$07 ; Mask bits 0-2
plp ; Restore sw3 in carry
bcc @L0 ; Is sw3 set?
ora #$08 ; Yes: Add sw3 in bit 3
@L0: ora tmp1 ; Add sw4 in bit 4
eor #$1F ; Active states are inverted
ldx #0
rts

14
libsrc/vic20/kbrepeat.s Normal file
View File

@@ -0,0 +1,14 @@
;
; unsigned char __fastcall__ kbrepeat (unsigned char mode);
;
.export _kbrepeat
.include "vic20.inc"
_kbrepeat:
ldx KBDREPEAT ; get old value
sta KBDREPEAT ; store new value
txa ; return old value
ldx #0
rts

16
libsrc/vic20/waitvsync.s Normal file
View File

@@ -0,0 +1,16 @@
;
; Written by Groepaz <groepaz@gmx.net>
;
; void waitvsync (void);
;
.export _waitvsync
.include "vic20.inc"
_waitvsync:
@l2:
lda VIC_HLINE
bne @l2
rts