%.o: %.s
@$(AS) -g -o $@ $(AFLAGS) $<
-%.emd: %.o ../runtime/zeropage.o
+%.emd: %.o ../runtime/zeropage.o cbm510zp.o
@$(LD) -t module -o $@ $^
-%.tgi: %.o ../runtime/zeropage.o
+%.joy: %.o ../runtime/zeropage.o cbm510zp.o
+ @$(LD) -t module -o $@ $^
+
+%.tgi: %.o ../runtime/zeropage.o cbm510zp.o
@$(LD) -t module -o $@ $^
#--------------------------------------------------------------------------
conio.o \
cputc.o \
crt0.o \
+ extzp.o \
kbhit.o \
kirq.o \
kplot.o \
peeksys.o \
pokesys.o \
randomize.o \
- readjoy.o \
revers.o \
rs232.o \
tgi_mode_table.o
#--------------------------------------------------------------------------
# Drivers
-TGIS =
-
EMDS = cbm510-ram.emd
+JOYS = cbm510-stdjoy.joy
+
+TGIS =
+
#--------------------------------------------------------------------------
# Targets
.PHONY: all clean zap
-all: $(OBJS) $(EMDS) $(TGIS)
+all: $(OBJS) $(EMDS) $(JOYS) $(TGIS)
../runtime/zeropage.o:
$(MAKE) -C $(dir $@) $(notdir $@)
clean:
- @rm -f $(OBJS) $(EMDS:.emd=.o) $(TGIS:.tgi=.o)
+ @rm -f $(OBJS) $(EMDS:.emd=.o) $(JOYS:.joy=.o) $(TGIS:.tgi=.o)
zap: clean
@rm -f $(EMDS) $(JOYS) $(TGIS)
--- /dev/null
+;
+; Standard joystick driver for the Commodore 510 (aka P500). May be used
+; multiple times when linked to the statically application.
+;
+; Ullrich von Bassewitz, 2003-02-16
+;
+
+ .include "zeropage.inc"
+ .include "extzp.inc"
+
+ .include "joy-kernel.inc"
+ .include "joy-error.inc"
+ .include "cbm510.inc"
+
+ .macpack generic
+
+
+; ------------------------------------------------------------------------
+; Header. Includes jump table
+
+.segment "JUMPTABLE"
+
+; Driver signature
+
+ .byte $6A, $6F, $79 ; "joy"
+ .byte $00 ; Driver API version number
+
+; 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
+ .word UNINSTALL
+ .word COUNT
+ .word READ
+
+; ------------------------------------------------------------------------
+; Constants
+
+JOY_COUNT = 2 ; Number of joysticks we support
+
+
+; ------------------------------------------------------------------------
+; Data.
+
+
+.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 JOY_ERR_xx code in a/x.
+;
+
+INSTALL:
+ lda #<JOY_ERR_OK
+ ldx #>JOY_ERR_OK
+
+; 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
+
+
+; ------------------------------------------------------------------------
+; COUNT: Return the total number of available joysticks in a/x.
+;
+
+COUNT:
+ lda #<JOY_COUNT
+ ldx #>JOY_COUNT
+ rts
+
+; ------------------------------------------------------------------------
+; READ: Read a particular joystick passed in A.
+;
+
+READ: ldx #$0F ; Switch to the system bank
+ stx IndReg
+ tax ; Save joystick number
+
+; Get the direction bits
+
+ ldy #CIA_PRB
+ lda (cia2),y ; Read joystick inputs
+ sta tmp1
+
+; Get the fire bits
+
+ ldy #CIA_PRA
+ lda (cia2),y
+
+; Make the result value
+
+ cpx #$00 ; Joystick 0?
+ bne @L1 ; Jump if no
+
+; Joystick 1, fire 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
+
+@L1: ldx #$00 ; High byte of return value
+ lsr tmp1
+ lsr tmp1
+ lsr tmp1
+ lsr tmp1
+
+; Mask the relavant bits, get the fire bit
+
+@L2: asl a ; Fire bit into carry
+ lda tmp1
+ and #$0F
+ bcc @L3
+ ora #$10
+@L3: eor #$1F ; All bits are inverted
+
+; Switch back to the execution bank and return the joystick mask in a/x
+
+ ldy ExecReg
+ sty IndReg
+ rts
+
;
.export _exit
- .exportzp vic, sid, cia1, cia2, acia, tpi1, tpi2, ktab1
- .exportzp ktab2, ktab3, ktab4, time, RecvBuf, SendBuf
.import _clrscr, initlib, donelib
.import push0, _main
.import __CHARRAM_START__, __CHARRAM_SIZE__, __VIDRAM_START__
+ .import __EXTZP_RUN__, __EXTZP_SIZE__
.import __BSS_RUN__, __BSS_SIZE__
.import irq, nmi
.import k_irq, k_nmi, PLOT, UDTIM, SCNKEY
.include "zeropage.inc"
- .include "cbm510.inc"
+ .include "extzp.inc"
+ .include "cbm510.inc"
; ------------------------------------------------------------------------
; To make things more simple, make the code of this module absolute.
.org $0001
-Head: .byte $03,$00,$11,$00,$0a,$00,$81,$20,$49,$b2,$30,$20,$a4,$20,$34,$00
+Head: .byte $03,$00,$11,$00,$0a,$00,$81,$20,$49,$b2,$30,$20,$a4,$20,$34,$00
.byte $19,$00,$14,$00,$87,$20,$4a,$00,$27,$00,$1e,$00,$97,$20,$32,$35
.byte $36,$aa,$49,$2c,$4a,$00,$2f,$00,$28,$00,$82,$20,$49,$00,$39,$00
.byte $32,$00,$9e,$20,$32,$35,$36,$00,$4f,$00,$3c,$00,$83,$20,$31,$32
.byte $30,$2c,$31,$36,$39,$2c,$30,$2c,$31,$33,$33,$2c,$30,$00,$00,$00
-; Since we need some vectors to access stuff in the system bank for our own,
-; we will include them here, starting from $60:
-
- .res $60-*
-
-vic: .word $d800
-sid: .word $da00
-cia1: .word $db00
-cia2: .word $dc00
-acia: .word $dd00
-tpi1: .word $de00
-tpi2: .word $df00
-ktab1: .word $eab1
-ktab2: .word $eb11
-ktab3: .word $eb71
-ktab4: .word $ebd1
-time: .dword $0000
-RecvBuf: .word $0100 ; RS232 received buffer
-SendBuf: .word $0200 ; RS232 send buffer
-
-
; The code in the target bank when switching back will be put at the bottom
; of the stack. We will jump here to switch segments. The range $F2..$FF is
; not used by any kernal routine.
ldy #vectable_size
L0: lda vectable-1,y
- sta $FF80,y
+ sta $FF81-1,y
dey
bne L0
+; Initialize the extended zero page variables
+
+ ldx #zptable_size
+L1: lda zptable-1,x
+ sta <(__EXTZP_RUN__-1),x
+ dex
+ bne L1
+
; Switch the indirect segment to the system bank
lda #$0F
lda #$00
sta ptr1+1
ldy #$62-1
-L1: lda (ptr1),y
+L2: lda (ptr1),y
sta $90,y
dey
- bpl L1
+ bpl L2
; Copy the page 3 vectors in place
ldy #$00
-L2: lda p3vectable,y
+L3: lda p3vectable,y
sta $300,y
iny
cpy #p3vectable_size
- bne L2
+ bne L3
; Copy the rest of page 3 from the system bank
sta ptr1
lda #$03
sta ptr1+1
-L3: lda (ptr1),y
+L4: lda (ptr1),y
sta $300,y
iny
- bne L3
+ bne L4
; Set the indirect segment to bank we're executing in
lda ExecReg
- sta IndReg
+ sta IndReg
; Zero the BSS segment. We will do that here instead calling the routine
; in the common library, since we have the memory anyway, and this way,
lda #<__BSS_RUN__
sta ptr1
- lda #>__BSS_RUN__
+ lda #>__BSS_RUN__
sta ptr1+1
- lda #0
- tay
+ lda #0
+ tay
; Clear full pages
; We expect to be in page 2 now
.if (* < $1FD)
- jmp $200
+ jmp $200
.res $200-*
.endif
.if (* < $200)
; Additional data that we need for initialization and that's overwritten
; later
+zptable:
+ .word $d800 ; vic
+ .word $da00 ; sid
+ .word $db00 ; cia1
+ .word $dc00 ; cia2
+ .word $dd00 ; acia
+ .word $de00 ; tpi1
+ .word $df00 ; tpi2
+ .word $eab1 ; ktab1
+ .word $eb11 ; ktab2
+ .word $eb71 ; ktab3
+ .word $ebd1 ; ktab4
+ .dword $0000 ; time
+ .word $0100 ; RecvBuf
+ .word $0200 ; SendBuf
+zptable_size = * - zptable
+
vectable:
jmp $0000 ; CINT
jmp $0000 ; IOINIT
jmp $0000 ; BASIN
jmp $0000 ; BSOUT
jmp $0000 ; LOAD
- jmp $0000 ; SAVE
+ jmp $0000 ; SAVE
jmp SETTIM
jmp RDTIM
jmp $0000 ; STOP
.export IOBASE
.proc IOBASE
- ldx cia2
- ldy cia2+1
+ ldx cia2
+ ldy cia2+1
rts
.endproc
--- /dev/null
+;
+; Ullrich von Bassewitz, 2003-02-16
+;
+; Additional zero page locations for the CBM510.
+;
+
+; ------------------------------------------------------------------------
+
+ .globalzp vic, sid, cia1, cia2, acia, tpi1, tpi2, ktab1
+ .globalzp ktab2, ktab3, ktab4, time, RecvBuf, SendBuf
+
--- /dev/null
+;
+; Ullrich von Bassewitz, 2003-02-16
+;
+; Additional zero page locations for the CBM510.
+; NOTE: The zeropage locations contained in this file get initialized
+; in the startup code, so if you change anything here, be sure to check
+; not only the linker config, but also the startup file.
+;
+
+; ------------------------------------------------------------------------
+
+ .include "extzp.inc"
+
+.segment "EXTZP", zeropage
+
+vic: .res 2
+sid: .res 2
+cia1: .res 2
+cia2: .res 2
+acia: .res 2
+tpi1: .res 2
+tpi2: .res 2
+ktab1: .res 2
+ktab2: .res 2
+ktab3: .res 2
+ktab4: .res 2
+time: .res 4
+RecvBuf: .res 2 ; RS232 receive buffer
+SendBuf: .res 2 ; RS232 transmit buffer
+
+++ /dev/null
-;
-; Ullrich von Bassewitz, 23.09.1998
-;
-; unsigned readjoy (unsigned char joy);
-;
-
- .export _readjoy
- .import sys_bank, restore_bank
- .importzp cia2, tmp1
-
- .include "cbm510.inc"
-
-; ------------------------------------------------------------------------
-; unsigned __fastcall__ readjoy (unsigned char joy);
-
-
-.proc _readjoy
-
- jsr sys_bank ; Switch to the system bank
- tax ; Save joystick number
-
-; Get the direction bits
-
- ldy #CIA_PRB
- lda (cia2),y ; Read joystick inputs
- sta tmp1
-
-; Get the fire bits
-
- ldy #CIA_PRA
- lda (cia2),y
-
-; Make the result value
-
- cpx #$00 ; Joystick 0?
- bne @L1 ; Jump if no
-
-; Joystick 1, fire 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
-
-@L1: ldy #$00 ; High byte of return value
- lsr tmp1
- lsr tmp1
- lsr tmp1
- lsr tmp1
-
-; Mask the relavant bits, get the fire bit
-
-@L2: asl a ; Fire bit into carry
- lda tmp1
- and #$0F
- bcc @L3
- ora #$10
-@L3: eor #$1F ; All bits are inverted
- jmp restore_bank
-
-.endproc
-