repo_id
stringlengths
5
115
size
int64
590
5.01M
file_path
stringlengths
4
212
content
stringlengths
590
5.01M
wagiminator/C64-Collection
1,586
C64_xu1541/software/tools/cc65-2.13.2/libsrc/atari/graphics.s
; ; Christian Groessler, June 2004 ; ; this file provides an equivalent to the BASIC GRAPHICS function ; ; int __fastcall__ _graphics(unsigned char mode); ; ; .export __graphics .import findfreeiocb .import __do_oserror,__oserror .import fddecusage .import clriocb .import fdtoiocb .import newfd .importzp tmp1,tmp2,tmp3 .include "atari.inc" .include "errno.inc" .code ; set new grapics mode ; gets new mode in A ; returns handle or -1 on error ; uses tmp1, tmp2, tmp3, tmp4 (in subroutines) .proc __graphics ; tax ; and #15 ; get required graphics mode ; cmp #12 ; bcs invmode ; invalid mode ; txa ; and #$c0 ; invalid bits set? ; bne invmode ; stx tmp1 sta tmp1 ; remember graphics mode parmok: jsr findfreeiocb beq iocbok ; we found one lda #<EMFILE ; "too many open files" seterr: jsr __seterrno lda #$FF tax rts ; return -1 ;invmode:ldx #>EINVAL ; lda #<EINVAL ; bne seterr iocbok: txa tay ; move iocb # into Y lda #3 sta tmp3 ; name length + 1 lda #<scrdev ldx #>scrdev jsr newfd tya tax bcs doopen ; C set: open needed ldx #0 lda tmp2 ; get fd used jsr fdtoiocb tax doopen: txa ;brk pha jsr clriocb pla tax lda #<scrdev sta ICBAL,x lda #>scrdev sta ICBAH,x lda #OPEN sta ICCOM,x lda tmp1 ; get requested graphics mode and #15 sta ICAX2,x lda tmp1 and #$30 eor #$10 ora #12 sta ICAX1,x jsr CIOV bmi cioerr lda tmp2 ; get fd ldx #0 stx __oserror rts cioerr: jsr fddecusage ; decrement usage counter of fd as open failed jmp __do_oserror .endproc ; __graphics .rodata scrdev: .byte "S:", 0
wagiminator/C64-Collection
1,119
C64_xu1541/software/tools/cc65-2.13.2/libsrc/atari/rwcommon.s
; ; common iocb setup routine for read, write ; expects __fastcall__ parameters (int fd, void *buf, int count) ; .include "atari.inc" .include "errno.inc" .importzp tmp2,tmp3 .import incsp4,ldax0sp,ldaxysp .import __errno,__oserror .import fdtoiocb .export __rwsetup __rwsetup: sta tmp2 stx tmp3 ; remember size ldy #3 jsr ldaxysp ; get fd jsr fdtoiocb ; convert to iocb bmi iocberr tax cpx #$80 ; iocb must be 0...7 bcs iocberr lda tmp2 sta ICBLL,x lda tmp3 ; size hi sta ICBLH,x stx tmp3 jsr ldax0sp ; get buf addr stx tmp2 ldx tmp3 sta ICBAL,x lda tmp2 sta ICBAH,x jsr incsp4 ; pop args lda ICBLL,x ora ICBLH,x ; return with Z if length was 0 rts iocberr:jsr incsp4 ; pop args ldx #$FF ; indicate error + clear ZF rts ; ; this routine updates errno. do a JMP here right after calling ; CIOV. we expect status in Y. ; .export __do_oserror,__inviocb __do_oserror: sty __oserror ; save os dependent error code retminus: lda #$FF tax ; return -1 rts ; ; sets EINVAL error code and returns -1 ; __inviocb: lda #<EINVAL jsr __seterrno jmp retminus ; return -1
wagiminator/C64-Collection
2,120
C64_xu1541/software/tools/cc65-2.13.2/libsrc/atari/scroll.s
; ; Christian Groessler, June 2004 ; ; void __fastcall__ _scroll (signed char numlines); ; numlines > 0 scrolls up ; numlines < 0 scrolls down ; .include "atari.inc" .importzp tmp1,tmp4,ptr1,ptr2 .import mul40,_clrscr .export __scroll .proc __scroll cmp #0 beq jmpfin ; cmp #$80 ; bcc up bpl up ;scroll down eor #$ff clc adc #1 ; make positive sta tmp1 cmp #24 ; scroll >= the whole screen? bcc down_ok jmp _clrscr down_ok:lda SAVMSC clc adc #<(40*23) sta ptr1 sta ptr2 lda SAVMSC+1 adc #>(40*23) sta ptr1+1 ; point to last line on screen sta ptr2+1 lda tmp1 jsr mul40 sta tmp4 lda ptr2 sec sbc tmp4 sta ptr2 stx tmp4 lda ptr2+1 sbc tmp4 sta ptr2+1 lda #24 ; # of lines on screen sec sbc tmp1 ; # of lines to move tax ;very simple, could be improved scrold: ldy #39 ; # of chars on a line - 1 copy_d: lda (ptr2),y sta (ptr1),y dey bpl copy_d lda ptr1 sec sbc #40 sta ptr1 bcs u1 dec ptr1+1 u1: lda ptr2 sec sbc #40 sta ptr2 bcs u2 dec ptr2+1 u2: dex bne scrold ; fill new scrolled in lines with space ldx tmp1 ; # of new lines fild: lda #0 ldy #39 fill_d: sta (ptr1),y dey bpl fill_d dex jmpfin: beq finish lda ptr1 sec sbc #40 sta ptr1 bcs u3 dec ptr1+1 u3: jmp fild ;scroll up up: sta tmp1 ; # of lines to scroll cmp #24 ; scroll >= the whole screen? bcc up_ok jmp _clrscr ;multiply by 40 (xsize) up_ok: jsr mul40 clc adc SAVMSC ; add start of screen mem sta ptr2 txa adc SAVMSC+1 sta ptr2+1 lda SAVMSC+1 sta ptr1+1 lda SAVMSC sta ptr1 lda #24 ; # of lines on screen sec sbc tmp1 ; # of lines to move tax ;very simple, could be improved scroll: ldy #39 ; # of chars on a line - 1 copy_l: lda (ptr2),y sta (ptr1),y dey bpl copy_l lda #40 clc adc ptr1 sta ptr1 bcc l1 inc ptr1+1 l1: lda #40 clc adc ptr2 sta ptr2 bcc l2 inc ptr2+1 l2: dex bne scroll ; fill new scrolled in lines with space ldx tmp1 ; # of new lines fill: lda #0 ldy #39 fill_l: sta (ptr1),y dey bpl fill_l dex beq finish lda #40 clc adc ptr1 sta ptr1 bcc l3 inc ptr1+1 l3: jmp fill finish: rts .endproc
wagiminator/C64-Collection
6,809
C64_xu1541/software/tools/cc65-2.13.2/libsrc/atari/fdtable.s
; ; Christian Groessler, May-2000 ; ; fd indirection table & helper functions ; .include "atari.inc" .include "fd.inc" .importzp tmp1,tmp2,tmp3,ptr4,sp .import fd_table,fd_index .import fdt_to_fdi .export clriocb .export fdtoiocb .export fdtoiocb_down .export findfreeiocb .export fddecusage .export newfd .code ; gets fd in ax, decrements usage counter ; return iocb index in X ; return N bit set for invalid fd ; return Z bit set if last user ; all registers destroyed .proc fdtoiocb_down cpx #0 bne inval cmp #MAX_FD_INDEX bcs inval tax lda fd_index,x ; get index tay lda #$ff sta fd_index,x ; clear entry tya asl a ; create index into fd table asl a tax lda #$ff cmp fd_table+ft_iocb,x ; entry in use? beq inval ; no, return error lda fd_table+ft_usa,x ; get usage counter beq ok_notlast ; 0? (shouldn't happen) sec sbc #1 ; decr usage counter sta fd_table+ft_usa,x retiocb:php txa tay lda fd_table+ft_iocb,x ; get iocb tax plp bne cont lda #$ff sta fd_table+ft_iocb,y ; clear table entry lda fd_table+ft_flag,y and #16 ; opened by app? eor #16 ; return set Z if yes cont: rts ok_notlast: lda #1 ; clears Z jmp retiocb .endproc ; fdtoiocb_down inval: ldx #$ff ; sets N rts ; clear iocb except for ICHID field ; expects X to be index to IOCB (0,$10,$20,etc.) ; all registers destroyed .proc clriocb inx ; don't clear ICHID ldy #15 lda #0 loop: sta ICHID,x inx dey bne loop rts .endproc ; gets fd in ax ; return iocb index in A, fd_table index in X ; return N bit set for invalid fd ; all registers destroyed .proc fdtoiocb cpx #0 bne inval cmp #MAX_FD_INDEX bcs inval tax lda fd_index,x asl a ; create index into fd table asl a tax lda #$ff cmp fd_table+ft_iocb,x ; entry in use? beq inval ; no, return error lda fd_table+ft_usa,x ; get usage counter beq inval ; 0? should not happen lda fd_table+ft_iocb,x ; get iocb rts .endproc ; fdtoiocb ; find a free iocb ; no entry parameters ; return ZF = 0/1 for not found/found ; index in X if found ; all registers destroyed .proc findfreeiocb ldx #0 ldy #$FF loop: tya cmp ICHID,x beq found txa clc adc #$10 tax cmp #$80 bcc loop inx ; return ZF cleared found: rts .endproc ; findfreeiocb ; decrements usage counter for fd ; if 0 reached, it's marked as unused ; get fd index in tmp2 ; Y register preserved .proc fddecusage lda tmp2 ; get fd cmp #MAX_FD_INDEX bcs ret ; invalid index, do nothing tax lda fd_index,x pha lda #$ff sta fd_index,x pla asl a ; create index into fd table asl a tax lda #$ff cmp fd_table+ft_iocb,x ; entry in use? beq ret ; no, do nothing lda fd_table+ft_usa,x ; get usage counter beq ret ; 0? should not happen sec sbc #1 ; decrement by one sta fd_table+ft_usa,x bne ret ; not 0 lda #$ff ; 0, table entry unused now sta fd_table+ft_iocb,x ; clear table entry ret: rts .endproc ; fddecusage ; newfd ; ; called from open() function ; finds a fd to use for an open request ; checks whether it's a device or file (file: characters follow the ':') ; files always get an exclusive slot ; for devices it is checked whether the device is already open, and if yes, ; a link to this open device is returned ; ; Calling parameters: ; tmp3 - length of filename + 1 ; AX - points to filename ; Y - iocb to use (if we need a new open) ; Return parameters: ; tmp2 - fd num ($ff and C=0 in case of error - no free slot) ; C - 0/1 for no open needed/open should be performed ; all registers preserved! .bss ; local variables: loc_Y: .res 1 loc_ptr4_l: .res 1 loc_ptr4_h: .res 1 loc_tmp1: .res 1 loc_devnum: .res 1 loc_size: .res 1 .code .proc newfd pha txa pha tya pha ldx #0 stx loc_devnum lda tmp1 sta loc_tmp1 stx tmp1 ; init tmp1 stx tmp2 ; init tmp2 lda ptr4+1 sta loc_ptr4_h lda ptr4 sta loc_ptr4_l pla sta loc_Y pla sta ptr4+1 pla sta ptr4 ; ptr4 points to filename ldy #1 lda #':' cmp (ptr4),y ; "X:" beq colon1 iny cmp (ptr4),y ; "Xn:" beq colon2 ; no colon there!? OK, then we use a fresh iocb.... ; return error here? no, the subsequent open call should fail do_open_nd: ; do open and don't remember device lda #2 sta tmp1 do_open:lda tmp1 ora #1 sta tmp1 ; set flag to return 'open needed' : C = 1 ldx #ft_iocb ldy #$ff srchfree: tya cmp fd_table,x ; check ft_iocb field for $ff beq freefnd ; found a free slot txa clc adc #ft_entrylen tax cmp #(MAX_FD_VAL*4)+ft_iocb ; end of table reached? bcc srchfree ; error: no free slot found noslot: ldx #0 stx tmp1 ; return with C = 0 dex stx tmp2 ; iocb: $ff marks error jmp finish ; found a free slot freefnd:txa sec sbc #ft_iocb ; normalize tax lsr a lsr a sta tmp2 ; return fd lda #2 bit tmp1 ; remember device? beq l1 ; yes lda #0 ; no, put 0 in field beq l2 l1: ldy #0 lda (sp),y ; get device l2: sta fd_table+ft_dev,x ; set device lda #1 sta fd_table+ft_usa,x ; set usage counter lda loc_Y sta fd_table+ft_iocb,x ; set iocb index lda loc_devnum and #7 ; device number is 3 bits ora #16 ; indicated a fd actively opened by the app sta fd_table+ft_flag,x lda tmp2 jsr fdt_to_fdi ; get new index bcs noslot ; no one available ;cmp #$ff ; no one available ;beq noslot ;@@@ cleanup needed sta tmp2 ; return index jmp finish ; string in "Xn:xxx" format colon2: dey lda (ptr4),y ; get device number sec sbc #'0' and #7 sta loc_devnum sta tmp2 ; save it for speed later here also lda #4 ; max. length if only device + number ("Xn:") cmp tmp3 bcc do_open_nd ; string is longer -> contains filename bcs check_dev ; handle device only string ; string in "X:xxx" format colon1: lda #3 ; max. length if device only ("X:") cmp tmp3 bcc do_open_nd ; string is longer -> contains filename ; get device and search it in fd table check_dev: ldy #0 lda (ptr4),y ; get device id tay ldx #(MAX_FD_VAL*4) - ft_entrylen srchdev:lda #$ff cmp fd_table+ft_iocb,x ; is entry valid? beq srch2 ; no, skip this entry tya cmp fd_table+ft_dev,x beq fnddev srch2: txa sec sbc #ft_entrylen+1 tax bpl srchdev ; not found, open new iocb jmp do_open ; helper for branch out of range noslot1:jmp noslot ; found device in table, check device number (e.g R0 - R3) fnddev: lda fd_table+ft_flag,x and #7 cmp tmp2 ; contains devnum bne srch2 ; different device numbers ; found existing open iocb with same device txa lsr a lsr a sta tmp2 inc fd_table+ft_usa,x ; increment usage counter jsr fdt_to_fdi ; get new index bcs noslot1 ; no one available sta tmp2 ; return index ; clean up and go home finish: lda ptr4 pha lda ptr4+1 pha lda loc_Y pha lda tmp1 pha lda loc_tmp1 sta tmp1 pla lsr a ; set C as needed pla tay pla tax pla rts .endproc ; newfd
wagiminator/C64-Collection
1,465
C64_xu1541/software/tools/cc65-2.13.2/libsrc/atari/getfd.s
; ; Christian Groessler, Oct-2000 ; ; allocates a new fd in the indirection table ; the fdtable itself is defined here ; .include "atari.inc" .include "fd.inc" .importzp tmp1 .export fdt_to_fdi,getfd .export fd_table,fd_index .export ___fd_table,___fd_index ; for test(debug purposes only .data ___fd_index: fd_index: ; fd number is index into this table, entry's value specifies the fd_table entry .res MAX_FD_INDEX,$ff ___fd_table: fd_table: ; each entry represents an open iocb .byte 0,0,'E',0 ; system console, app starts with opened iocb #0 for E: .byte 0,$ff,0,0 .byte 0,$ff,0,0 .byte 0,$ff,0,0 .byte 0,$ff,0,0 .byte 0,$ff,0,0 .byte 0,$ff,0,0 .byte 0,$ff,0,0 .code ; fdt_to_fdi ; returns a fd_index entry pointing to the given ft_table entry ; get fd_table entry in A ; return C = 0/1 for OK/error ; return fd_index entry in A if OK ; registers destroyed .proc fdt_to_fdi tay lda #$ff tax inx loop: cmp fd_index,x beq found inx cpx #MAX_FD_INDEX bcc loop rts found: tya sta fd_index,x txa clc rts .endproc ; getfd ; get a new fd pointing to a ft_table entry ; usage counter of ft_table entry incremented ; A - fd_table entry ; return C = 0/1 for OK/error ; returns fd in A if OK ; registers destroyed, tmp1 destroyed .proc getfd sta tmp1 ; save fd_table entry jsr fdt_to_fdi bcs error pha lda tmp1 asl a asl a ; also clears C tax inc fd_table+ft_usa,x ; increment usage counter pla error: rts .endproc
wagiminator/C64-Collection
2,346
C64_xu1541/software/tools/cc65-2.13.2/libsrc/atari/atari-multijoy.s
; ; MultiJoy joystick driver for the Atari. May be used multiple times when linked ; to the statically application. ; ; Ullrich von Bassewitz, 2002-12-21 ; Stefan Haubenthal, 2009-04-10 ; Using code from Carsten Strotmann and help from Christian Groessler ; .include "zeropage.inc" .include "joy-kernel.inc" .include "joy-error.inc" .include "atari.inc" .macpack generic ; ------------------------------------------------------------------------ ; Header. Includes jump table .segment "JUMPTABLE" ; Driver signature .byte $6A, $6F, $79 ; "joy" .byte JOY_API_VERSION ; Driver API version number ; 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 .addr UNINSTALL .addr COUNT .addr READJOY .addr 0 ; IRQ entry not used ; ------------------------------------------------------------------------ ; Constants JOY_COUNT = 8 ; 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 #$30 sta PACTL lda #$F0 sta PORTA lda #$34 sta PACTL lda #JOY_ERR_OK ldx #0 ; 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 #0 rts ; ------------------------------------------------------------------------ ; READ: Read a particular joystick passed in A. ; READJOY: asl a asl a asl a asl a sta PORTA ; Read joystick lda PORTA ; get position and #%00001111 asl a ora TRIG0 ; add button information eor #%00011111 ldx #0 ; fix X rts
wagiminator/C64-Collection
1,877
C64_xu1541/software/tools/cc65-2.13.2/libsrc/atari/ostype.s
; ; Christian Groessler, July 2004 ; from Freddy Offenga's rominfo.c ; ; unsigned char get_ostype(void) ; ; x x x x x x x x - 8 bit flag ; | | | | | | | | ; | | | | | +-+-+-- main OS rev. ; | | +-+-+-------- minor OS rev. ; +-+-------------- unused ; ; main OS rev.: ; 000 - unknown ; 001 - 400/800 ROM ; 010 - 1200XL ROM ; 011 - XL/XE ROM ; 1xx - unassigned ; minor OS rev.: (depending on main OS rev.); ; 400/800: ; 000 - unknown ; 001 - Rev. A PAL ; 010 - Rev. B PAL ; 011 - Rev. A NTSC ; 100 - Rev. B NTSC ; 101 - unassigned (up to 111) ; 1200XL: ; 000 - unknown ; 001 - Rev. 10 ; 010 - Rev. 11 ; 011 - unassigned (up to 111) ; XL/XE: ; 000 - unknown ; 001 - Rev. 1 ; 010 - Rev. 2 ; 011 - Rev. 3 ; 100 - Rev. 4 ; 101 - unassigned (up to 111) ; .export _get_ostype .proc _get_ostype lda $fcd8 cmp #$a2 beq _400800 lda $fff1 cmp #1 beq _1200xl lda $fff7 cmp #1 bcc _unknown cmp #5 bcs _unknown ;XL/XE ROM sec asl a asl a asl a and #%00111000 ora #%11 _fin: ldx #0 rts ; unknown ROM _unknown: lda #0 tax rts ; 1200XL ROM _1200xl: lda $fff7 ; revision # cmp #10 beq _1200_10 cmp #11 beq _1200_11 lda #0 ; for unknown beq _1200_fin _1200_10: lda #%00001000 bne _1200_fin _1200_11: lda #%00010000 _1200_fin: ora #%010 bne _fin ; 400/800 ROM _400800: lda $fff8 ldx $fff9 cmp #$dd bne _400800_1 cpx #$57 bne _400800_unknown ; 400/800 NTSC Rev. A lda #%00011001 bne _fin ; 400/800 unknown _400800_unknown: lda #%00000001 bne _fin _400800_1: cmp #$d6 bne _400800_2 cpx #$57 bne _400800_unknown ; 400/800 PAL Rev. A lda #%00001001 bne _fin _400800_2: cmp #$f3 bne _400800_3 cpx #$e6 bne _400800_unknown ; 400/800 NTSC Rev. B lda #%00100001 bne _fin _400800_3: cmp #$22 bne _400800_unknown cpx #$58 bne _400800_unknown ; 400/800 PAL Rev. B lda #%00010001 bne _fin .endproc
wagiminator/C64-Collection
2,072
C64_xu1541/software/tools/cc65-2.13.2/libsrc/atari/getargs.s
; get arguments from command line (when DOS supports it) ; Freddy Offenga, 4/21/2000 MAXARGS = 16 ; max. amount of arguments in arg. table CL_SIZE = 64 ; command line buffer size SPACE = 32 ; SPACE char. .include "atari.inc" .import __argc, __argv .importzp ptr1 .import __dos_type .constructor initmainargs,25 ; -------------------------------------------------------------------------- ; Get command line .segment "INIT" initmainargs: lda #0 sta __argc sta __argc+1 sta __argv sta __argv+1 lda __dos_type ; which DOS? cmp #ATARIDOS beq nargdos ; DOS does not support arguments cmp #MYDOS bne argdos ; DOS supports arguments nargdos:rts ; Initialize ourcl buffer argdos: lda #ATEOL sta ourcl+CL_SIZE ; Move SpartaDOS command line to our own buffer lda DOSVEC clc adc #<LBUF sta ptr1 lda DOSVEC+1 adc #>LBUF sta ptr1+1 ldy #0 cpcl: lda (ptr1),y sta ourcl,y iny cmp #ATEOL beq movdon cpy #CL_SIZE bne cpcl movdon: lda #0 sta ourcl,y ; null terminate behind ATEOL ; Turn command line into argv table ;ldy #0 tay eatspc: lda ourcl,y ; eat spaces cmp #ATEOL beq finargs cmp #SPACE bne rpar ; begin of argument found iny cpy #CL_SIZE bne eatspc beq finargs ; only spaces is no argument ; Store argument vector rpar: lda __argc ; low-byte asl tax ; table index tya ; ourcl index clc adc #<ourcl sta argv,x lda #>ourcl adc #0 sta argv+1,x ldx __argc inx stx __argc cpx #MAXARGS beq finargs ; Skip this arg. skiparg: ldx ourcl,y cpx #ATEOL ; end of line? beq eopar cpx #SPACE beq eopar iny cpy #CL_SIZE bne skiparg ; End of arg. -> place 0 eopar: lda #0 sta ourcl,y iny ; y behind arg. cpx #ATEOL ; was it the last arg? bne eatspc ; Finish args finargs: lda __argc asl tax lda #0 sta argv,x sta argv+1,x lda #<argv ldx #>argv sta __argv stx __argv+1 rts ; -------------------------------------------------------------------------- ; Data .bss argv: .res (1 + MAXARGS) * 2 ; Buffer for command line / argv strings ourcl: .res CL_SIZE+1
wagiminator/C64-Collection
1,142
C64_xu1541/software/tools/cc65-2.13.2/libsrc/atari/dio_cts.s
; ; Christian Groessler, October 2000 ; ; this file provides the _dio_phys_to_log function ; (previously called _dio_chs_to_snum, so the filename) ; ; on the Atari this function is a dummy, it ignores ; cylinder and head and returns as sector number the ; sector number it got ; ; unsigned char __fastcall__ dio_phys_to_log(dhandle_t handle, ; dio_phys_pos *physpos, /* input */ ; sectnum_t *sectnum); /* output */ ; ; dhandle_t - 16bit (ptr) ; sectnum_t - 16bit ; .export _dio_phys_to_log .import popax,__oserror .importzp ptr1,ptr2,ptr3 .include "atari.inc" .proc _dio_phys_to_log sta ptr1 stx ptr1+1 ; pointer to result jsr popax sta ptr2 stx ptr2+1 ; pointer to input structure jsr popax sta ptr3 stx ptr3+1 ; pointer to handle ldy #sst_flag lda (ptr3),y and #128 beq _inv_hand ; handle not open or invalid ; ignore head and track and return the sector value ldy #diopp_sector lda (ptr2),y tax iny lda (ptr2),y ldy #1 sta (ptr1),y dey txa sta (ptr1),y ldx #0 txa ret: sta __oserror rts ; return success ; invalid handle _inv_hand: ldx #0 lda #BADIOC bne ret .endproc
wagiminator/C64-Collection
4,144
C64_xu1541/software/tools/cc65-2.13.2/libsrc/atari/oserror.s
; ; Christian Groessler, May-2000 ; ; os specific error code mapping ; int __fastcall__ _osmaperrno (unsigned char oserror); ; .include "errno.inc" .export __osmaperrno .proc __osmaperrno cmp #$80 ; error or success bcs errcode ; error, jump lda #0 ; no error, return 0 tax rts errcode:and #$7f ; create index from error number tax cpx #MAX_OSERR_VAL ; valid number? bcs inverr ; no lda maptable,x ldx #0 rts inverr: lda #<EUNKNOWN ldx #>EUNKNOWN rts .endproc .rodata maptable: .byte EINTR ;BRKABT = 128 ;($80) BREAK key abort .byte EBUSY ;PRVOPN = 129 ;($81) IOCB already open error .byte ENODEV ;NONDEV = 130 ;($82) nonexistent device error .byte EACCES ;WRONLY = 131 ;($83) IOCB opened for write only error .byte ENOSYS ;NVALID = 132 ;($84) invalid command error .byte EINVAL ;NOTOPN = 133 ;($85) device/file not open error .byte EINVAL ;BADIOC = 134 ;($86) invalid IOCB index error .byte EACCES ;RDONLY = 135 ;($87) IOCB opened for read only error .byte EINVAL ;EOFERR = 136 ;($88) end of file error (should never come, ; specially handled by read.s) .byte EIO ;TRNRCD = 137 ;($89) truncated record error .byte EIO ;TIMOUT = 138 ;($8A) peripheral device timeout error .byte EIO ;DNACK = 139 ;($8B) device does not acknowledge command .byte EIO ;FRMERR = 140 ;($8C) serial bus framing error .byte EINVAL ;CRSROR = 141 ;($8D) cursor out of range error .byte EIO ;OVRRUN = 142 ;($8E) serial bus data overrun error .byte EIO ;CHKERR = 143 ;($8F) serial bus checksum error .byte EIO ;DERROR = 144 ;($90) general device failure .byte EINVAL ;BADMOD = 145 ;($91) bad screen mode number error .byte ENOSYS ;FNCNOT = 146 ;($92) function not implemented in handler .byte ENOMEM ;SCRMEM = 147 ;($93) insufficient memory for screen mode ; codes below taken from "Mein Atari Computer" (german version of "Your Atari Computer") ; also SpartaDOS codes from http://www.atari-central.com/programming/cio_errors.txt ; MyDOS codes from Stefan Haubenthal .byte EUNKNOWN ; 148 - [SpartaDOS] unrecognized disk format .byte EUNKNOWN ; 149 - [SpartaDOS] disk created by incompatible version of SD .byte EBUSY ; 150 - serial port already open ; [SpartaDOS] directory not found .byte EACCES ; 151 - concurrent mode I/O not enabled (serial) ; [SpartaDOS] file exists .byte EINVAL ; 152 - invalid buffer address for concurrent mode ; [SpartaDOS] not binary format .byte EAGAIN ; 153 - concurrent mode enabled (and another access tried) .byte EACCES ; 154 - concurrent mode I/O not active (serial) ; [SpartaDOS X] loader symbol not defined .byte EUNKNOWN ; 155 - haven't found documentation .byte EUNKNOWN ; 156 - [SpartaDOS X] bad parameter .byte EUNKNOWN ; 157 - haven't found documentation .byte EUNKNOWN ; 158 - [SpartaDOS X] out of memory .byte EUNKNOWN ; 159 - haven't found documentation .byte ENOENT ; 160 - drive number error (DOS) .byte EMFILE ; 161 - too many open files .byte ENOSPC ; 162 - disk full .byte EIO ; 163 - unrecoverable system data I/O error .byte ESPIPE ; 164 - file number mismatch (inv. seek or disk data strucs damaged) .byte ENOENT ; 165 - invalid file name (e.g. lowercase) .byte ESPIPE ; 166 - point data length error .byte EACCES ; 167 - file locked (read-only) .byte ENOSYS ; 168 - command invalid for disk .byte ENOSPC ; 169 - directory full .byte ENOENT ; 170 - file not found .byte ESPIPE ; 171 - point command invalid .byte EEXIST ; 172 - [MYDOS] already exists in parent directory .byte EUNKNOWN ; 173 - bad disk - format couldn't complete .byte EUNKNOWN ; 174 - [MYDOS] directory not in parent directory .byte EUNKNOWN ; 175 - [MYDOS] directory not empty .byte EUNKNOWN ; 176 - [DOS 3] incompatible file system .byte EUNKNOWN ; 177 - haven't found documentation .byte EUNKNOWN ; 178 - haven't found documentation .byte EUNKNOWN ; 179 - haven't found documentation .byte EUNKNOWN ; 180 - not a binary file .byte EUNKNOWN ; 181 - [MYDOS] invalid address range .byte EINVAL ; 182 - dummy (used by cc65 rtl, see sysremove.s) MAX_OSERR_VAL = (* - maptable)
wagiminator/C64-Collection
1,272
C64_xu1541/software/tools/cc65-2.13.2/libsrc/atari/cputc.s
; ; Mark Keates, Christian Groessler ; ; void cputcxy (unsigned char x, unsigned char y, char c); ; void cputc (char c); ; .export _cputcxy, _cputc .export plot, cputdirect, putchar .import popa, _gotoxy, mul40 .importzp tmp4,ptr4 .import _revflag,setcursor .include "atari.inc" _cputcxy: pha ; Save C jsr popa ; Get Y jsr _gotoxy ; Set cursor, drop x pla ; Restore C _cputc: cmp #$0D ; CR bne L4 lda #0 sta COLCRS beq plot ; return L4: cmp #$0A ; LF beq newline cmp #ATEOL ; Atari-EOL? beq newline tay rol a rol a rol a rol a and #3 tax tya and #$9f ora ataint,x cputdirect: ; accepts screen code jsr putchar ; advance cursor inc COLCRS lda COLCRS cmp #40 bcc plot lda #0 sta COLCRS .export newline newline: inc ROWCRS lda ROWCRS cmp #24 bne plot lda #0 sta ROWCRS plot: jsr setcursor ldy COLCRS ldx ROWCRS rts ; turn off cursor, update screen, turn on cursor putchar: pha ; save char ldy #0 lda OLDCHR sta (OLDADR),y lda ROWCRS jsr mul40 ; destroys tmp4 clc adc SAVMSC ; add start of screen memory sta ptr4 txa adc SAVMSC+1 sta ptr4+1 pla ; get char again ora _revflag sta OLDCHR ldy COLCRS sta (ptr4),y jmp setcursor .rodata ataint: .byte 64,0,32,96
wagiminator/C64-Collection
3,071
C64_xu1541/software/tools/cc65-2.13.2/libsrc/atari/diopncls.s
; ; Christian Groessler, February 2005 ; ; This file provides the _dio_open and _dio_close functions ; Since on the Atari no real open and close is necessary, they ; do not open or close something. The _dio_open sets the sector ; size of the drive which is later used by the _dio_read and ; _dio_write functions. To query the sector size, the _dio_open ; accesses the disk drive. ; ; dhandle_t __fastcall__ dio_open (driveid_t drive_id); ; unsigned char __fastcall__ dio_close (dhandle_t handle); ; .export _dio_open, _dio_close .export sectsizetab .import __oserror, __sio_call, _dio_read .import pushax, addysp, subysp .importzp ptr2, sp .include "atari.inc" .bss sectsizetab: .res NUMDRVS * sst_size .code ; code for _dio_open _inv_drive: lda #NONDEV ; non-existent device sta __oserror lda #0 tax rts ; return NULL _dio_open: cmp #NUMDRVS ; valid drive id? bcs _inv_drive tay ; drive # asl a ; make index from drive id asl a tax lda #128 ; preset sectsize sta sectsizetab+sst_sectsize,x sta sectsizetab+sst_flag,x ; set flag that drive is "open" lda #0 sta sectsizetab+sst_sectsize+1,x sta __oserror ; success tya sta sectsizetab+sst_driveno,x stx ptr2 lda #<sectsizetab clc adc ptr2 sta ptr2 lda #>sectsizetab adc #0 tax stx ptr2+1 ; ptr2: pointer to sectsizetab entry ; query drive for current sector size ; procedure: ; - read sector #4 (SIO command $54) to update drive status; ; read length is 128 bytes, buffer is allocated on the stack, ; sector data is ignored; ; returned command status is ignored, we will get an error with ; a DD disk anyway (read size 128 vs. sector size 256); ; - issue SIO command $53 (get status) to retrieve the sector size; ; use the DVSTAT system area as return buffer; ; if the command returns with an error, set sector size to 128 ; bytes; ; ldy #128 jsr subysp ; allocate buffer on the stack lda sp pha lda sp+1 pha ; save sp (buffer address) on processor stack lda ptr2 ldx ptr2+1 jsr pushax ; handle ldx #0 lda #4 jsr pushax ; sect_num pla tax pla ; AX - buffer address ; sst_sectsize currently 128 jsr _dio_read ; read sector to update status ldy #128 jsr addysp ; discard stack buffer lda ptr2 ldx ptr2+1 jsr pushax ; handle ldx #0 lda #4 jsr pushax ; dummy sector #, ignored by this SIO command, ; but set to circumvent the special 1-3 sector ; handling in __sio_call ldx #>DVSTAT lda #<DVSTAT jsr pushax ; buffer address ldy #sst_sectsize lda #4 sta (ptr2),y ; 4 bytes transfer ldx #%01000000 ; direction value lda #SIO_STAT ; get status jsr __sio_call bmi error ldy #sst_sectsize lda DVSTAT and #%100000 beq s128 ;s256 lda #0 sta (ptr2),y iny lda #1 finish: sta (ptr2),y ; set default sector size fini2: lda ptr2 ldx ptr2+1 rts error: ldy #sst_sectsize s128: lda #128 bne finish ; end of _dio_open .proc _dio_close sta ptr2 stx ptr2+1 lda #0 ldy #sst_flag sta (ptr2),y sta __oserror ; success tax rts ; return no error .endproc
wagiminator/C64-Collection
3,096
C64_xu1541/software/tools/cc65-2.13.2/libsrc/atari/read.s
; ; Christian Groessler, Jul-2005 ; ; int __fastcall__ read(int fd,void *buf,int count) ; .include "atari.inc" .import __rwsetup,__do_oserror,__inviocb,__oserror .export _read _read: jsr __rwsetup ; do common setup for read and write beq done ; if size 0, it's a no-op cpx #$FF ; invalid iocb? beq _inviocb .ifdef LINEBUF ; E: should be always at IOCB #0 ; fixme: what happens when user closes and reopens stdin? cpx #0 ; E: handler (line oriented keyboard input)? beq do_line .endif lda #GETCHR ; iocb command code sta ICCOM,x jsr CIOV ; read it bpl done cpy #EOFERR ; eof is treated specially beq done jmp __do_oserror ; update errno done: lda ICBLL,x ; buf len lo pha ; save lda ICBLH,x ; get buf len hi tax ; to X okdone: lda #0 sta __oserror ; clear system dependend error code pla ; get buf len lo rts _inviocb: jmp __inviocb .ifdef LINEBUF ; line oriented input .segment "EXTZP" : zeropage index: .res 1 ; index into line buffer buflen: .res 1 ; length of used part of buffer cbs: .res 1 ; current buffer size: buflen - index dataptr:.res 2 ; temp pointer to user buffer copylen:.res 1 ; temp counter .bss linebuf:.res LINEBUF ; the line buffer .code do_line: lda buflen ; line buffer active? bne use_buf ; yes, get data from there ; save user buffer address & length ; update IOCB to point to line buffer lda ICBLL,x pha lda #LINEBUF sta ICBLL,x ;-------- lda ICBLH,x pha lda #0 sta ICBLH,x ;-------- lda ICBAL,x pha lda #<linebuf sta ICBAL,x ;-------- lda ICBAH,x pha lda #>linebuf sta ICBAH,x lda #GETREC sta ICCOM,x jsr CIOV ; read input data bpl newbuf cpy #EOFERR ; eof is treated specially beq newbuf pla ; fix stack pla pla pla jmp __do_oserror ; update errno newbuf: lda ICBLL,x ; get # of bytes read sta buflen lda #0 sta index ; fresh buffer ; restore user buffer address & length pla sta ICBAH,x ;-------- pla sta ICBAL,x ;-------- pla sta ICBLH,x ;-------- pla sta ICBLL,x ; fall into use_buf lda buflen ; return bytes from line buffer ; use buflen and index to access buffer ; update index ; use dataptr as a temporary pointer use_buf: sec sbc index ; size of unread data in the buffer sta cbs lda ICBLL,x ; buf len lo cmp cbs ; larger than buffer size? beq bl1 bcs btsmall ; yes, adjust length bl1: lda ICBLH,x ; get buf len hi bne btsmall ; buffer too small: buffer contents < read size ; copy ICBLL,x bytes icbll_copy: lda ICBAL,x ; buffer address sta dataptr lda ICBAH,x ; buffer address sta dataptr+1 lda ICBLL,x sta copylen pha ; remember for return value ldy #0 ldx index copy: lda linebuf,x sta (dataptr),y iny inx dec copylen bne copy pla ; length pha ; save length to return at okdone clc adc index sta index cmp buflen ; buffer used up? bcc c1 ; not yet lda #0 sta buflen ; indicate empty line buffer c1: ldx #0 jmp okdone ; return to caller btsmall: lda cbs sta ICBLL,x bpl icbll_copy .endif ; .ifdef LINEBUF
wagiminator/C64-Collection
1,549
C64_xu1541/software/tools/cc65-2.13.2/libsrc/atari/break.s
; ; Christian Groessler, 27-Feb-2000 ; ; void set_brk (unsigned Addr); ; void reset_brk (void); ; .export _set_brk, _reset_brk .destructor _reset_brk .export _brk_a, _brk_x, _brk_y, _brk_sr, _brk_pc .include "atari.inc" .bss _brk_a: .res 1 _brk_x: .res 1 _brk_y: .res 1 _brk_sr: .res 1 _brk_pc: .res 2 oldvec: .res 2 ; Old vector .data uservec: jmp $FFFF ; Patched at runtime .code ; Set the break vector .proc _set_brk sta uservec+1 stx uservec+2 ; Set the user vector lda oldvec ora oldvec+1 ; Did we save the vector already? bne L1 ; Jump if we installed the handler already lda VBREAK sta oldvec lda VBREAK+1 sta oldvec+1 ; Save the old vector L1: lda #<brk_handler ; Set the break vector to our routine sta VBREAK lda #>brk_handler sta VBREAK+1 rts .endproc ; Reset the break vector .proc _reset_brk lda oldvec ldx oldvec+1 beq @L9 ; Jump if vector not installed sta VBREAK stx VBREAK+1 lda #$00 sta oldvec ; Clear the old vector stx oldvec+1 @L9: rts .endproc ; Break handler, called if a break occurs .proc brk_handler sty _brk_y stx _brk_x pla sta _brk_a pla and #$EF ; Clear break bit sta _brk_sr pla ; PC low sec sbc #2 ; Point to start of brk sta _brk_pc pla ; PC high sbc #0 sta _brk_pc+1 jsr uservec ; Call the user's routine lda _brk_pc+1 pha lda _brk_pc pha lda _brk_sr pha ldx _brk_x ldy _brk_y lda _brk_a rti ; Jump back... .endproc
wagiminator/C64-Collection
1,609
C64_xu1541/software/tools/cc65-2.13.2/libsrc/atari/siocall.s
; ; Christian Groessler, October 2000 ; ; This file provides the __sio_call function ; The function does a SIO call, it's not completely ; generic (e.g. transfer size is fixed), it's used ; to save space with _dio_read and _dio_write functions. ; ; unsigned char __fastcall__ _sio_call(dhandle_t handle, ; sectnum_t sect_num, ; void *buffer, ; unsigned int sio_val); ; dhandle_t - 16bit (ptr) ; sectnum_t - 16bit ; sio_val is (sio_command | sio_direction << 8) ; .export __sio_call .include "atari.inc" .import popa,popax .import sectsizetab,__oserror .importzp ptr1 .proc __sio_call sta DCOMND ; set command into DCB stx DSTATS ; set data flow directon jsr popax ; get buffer address sta DBUFLO ; set buffer address into DCB stx DBUFHI jsr popax sta DAUX1 ; set sector # stx DAUX2 jsr popax sta ptr1 stx ptr1+1 ldy #sst_flag lda (ptr1),y and #128 beq _inv_hand ; handle not open or invalid ldy #sst_driveno lda (ptr1),y clc adc #1 sta DUNIT ; unit number (d1,d2,d3,...) lda DAUX2 ; high byte sector # bne _realsz lda DAUX1 cmp #4 ; sectors 1 to 3 are special (always 128 bytes) bcs _realsz lda #$80 sta DBYTLO asl a sta DBYTHI beq _cont _realsz:ldy #sst_sectsize lda (ptr1),y sta DBYTLO iny lda (ptr1),y sta DBYTHI _cont: lda #DISKID ; SIO bus ID of diskette drive sta DDEVIC lda #15 sta DTIMLO ; value got from DOS source jsr SIOV ; execute ldx #0 lda DSTATS bmi _req_err ; error occurred txa ; no error occurred _req_err: sta __oserror rts _inv_hand: ldx #0 lda #BADIOC bne _req_err .endproc
wagiminator/C64-Collection
1,029
C64_xu1541/software/tools/cc65-2.13.2/libsrc/atari/sysremove.s
; ; Christian Groessler, Aug-2003 ; ; int remove (const char* name); ; .include "atari.inc" .include "errno.inc" .import findfreeiocb .importzp tmp4 .ifdef UCASE_FILENAME .importzp tmp3 .import addysp .import ucase_fn .endif .export __sysremove .proc __sysremove pha ; save input parameter txa pha jsr findfreeiocb beq iocbok ; we found one pla pla ; fix up stack lda #TMOF ; too many open files rts iocbok: stx tmp4 ; remember IOCB index pla tax pla ; get argument again .ifdef UCASE_FILENAME jsr ucase_fn bcc ucok1 lda #182 ; see oserror.s rts ucok1: .endif ; defined UCASE_FILENAME ldy tmp4 ; IOCB index sta ICBAL,y ; store pointer to filename txa sta ICBAH,y tya tax lda #DELETE sta ICCOM,x lda #0 sta ICAX1,x sta ICAX2,x sta ICBLL,x sta ICBLH,x jsr CIOV .ifdef UCASE_FILENAME tya pha ldy tmp3 ; get size jsr addysp ; free used space on the stack pla tay .endif ; defined UCASE_FILENAME bmi cioerr lda #0 rts cioerr: tya rts .endproc ; __sysremove
wagiminator/C64-Collection
1,175
C64_xu1541/software/tools/cc65-2.13.2/libsrc/atari/dio_stc.s
; ; Christian Groessler, October 2000 ; ; this file provides the _dio_log_to_phys function ; (previously called _dio_snum_to_chs, so the filename) ; ; on the Atari this function is a dummy, it returns ; cylinder and head 0 and as sector the sectnum it got ; ; unsigned char __fastcall__ dio_log_to_phys(dhandle_t handle, ; sectnum_t *sectnum, /* input */ ; dio_phys_pos *physpos); /* output */ ; ; dhandle_t - 16bit (ptr) ; sectnum_t - 16bit ; .export _dio_log_to_phys .include "atari.inc" .importzp ptr1,ptr2,ptr3 .import popax,__oserror .proc _dio_log_to_phys sta ptr2 stx ptr2+1 ; pointer to output structure jsr popax sta ptr1 stx ptr1+1 ; save pointer to input data jsr popax sta ptr3 stx ptr3+1 ; pointer to handle ldy #sst_flag lda (ptr3),y and #128 beq _inv_hand ; handle not open or invalid lda #0 tay tax sta (ptr2),y ; head iny sta (ptr2),y ; track (low) iny sta (ptr2),y ; track (high) iny lda (ptr1,x) sta (ptr2),y iny inc ptr1 bne _l1 inc ptr1+1 _l1: lda (ptr1,x) sta (ptr2),y txa ret: sta __oserror rts ; return success ; invalid handle _inv_hand: ldx #0 lda #BADIOC bne ret .endproc
wagiminator/C64-Collection
4,005
C64_xu1541/software/tools/cc65-2.13.2/libsrc/atari/oserrlist.s
; ; Ullrich von Bassewitz, 18.07.2002 ; Christian Groessler, 24.07.2002 ; ; Defines the platform specific error list. ; ; The table is built as a list of entries ; ; .byte entrylen ; .byte errorcode ; .asciiz errormsg ; ; and terminated by an entry with length zero that is returned if the ; error code could not be found. ; .export __sys_oserrlist ;---------------------------------------------------------------------------- ; Macros used to generate the list (may get moved to an include file?) ; Regular entry .macro sys_oserr_entry code, msg .local Start, End Start: .byte End - Start .byte code .asciiz msg End: .endmacro ; Sentinel entry .macro sys_oserr_sentinel msg .byte 0 ; Length is always zero .byte 0 ; Code is unused .asciiz msg .endmacro ;---------------------------------------------------------------------------- ; The error message table .rodata __sys_oserrlist: sys_oserr_entry 1, "no error" sys_oserr_entry 128, "BREAK key abort" sys_oserr_entry 129, "IOCB already open" sys_oserr_entry 130, "device not found" sys_oserr_entry 131, "IOCB write only" sys_oserr_entry 132, "invalid command" sys_oserr_entry 133, "IOCB not open" sys_oserr_entry 134, "invalid IOCB index" sys_oserr_entry 135, "IOCB read only" sys_oserr_entry 136, "end-of-file" sys_oserr_entry 137, "record truncated" sys_oserr_entry 138, "device timeout" sys_oserr_entry 139, "device nak" sys_oserr_entry 140, "SIO frame error" sys_oserr_entry 141, "cursor out of range" sys_oserr_entry 142, "SIO data overrun" sys_oserr_entry 143, "SIO checksum mismatch" sys_oserr_entry 144, "general device failure" sys_oserr_entry 145, "bad screen mode" sys_oserr_entry 146, "invalid function" sys_oserr_entry 147, "insufficient memory for mode" sys_oserr_entry 148, "invalid disk format" sys_oserr_entry 149, "disk format version mismatch" sys_oserr_entry 150, "R: already open/dir not found" sys_oserr_entry 151, "concurrent mode not enabled/file exists" sys_oserr_entry 152, "concurrent mode invalid buffer address/not binary" sys_oserr_entry 153, "concurrent mode enabled" sys_oserr_entry 154, "concurrent mode not active/loader symbol not defined" sys_oserr_entry 156, "invalid parameter" sys_oserr_entry 158, "insufficient memory" sys_oserr_entry 160, "drive number error" sys_oserr_entry 161, "too many open files" sys_oserr_entry 162, "no space left on device" sys_oserr_entry 163, "unrecoverable system data I/O error" sys_oserr_entry 164, "file number mismatch" sys_oserr_entry 165, "invalid file name" sys_oserr_entry 166, "point data length error" sys_oserr_entry 167, "file read-only" sys_oserr_entry 168, "invalid command for disk" sys_oserr_entry 169, "directory full" sys_oserr_entry 170, "file not found" sys_oserr_entry 171, "invalid point command" sys_oserr_entry 172, "already exists in parent directory" sys_oserr_entry 173, "bad disk" sys_oserr_entry 174, "directory not in parent directory" sys_oserr_entry 175, "directory not empty" sys_oserr_entry 176, "invalid disk format" sys_oserr_entry 180, "not a binary file" sys_oserr_entry 181, "invalid address range" sys_oserr_sentinel "unknown error"
wagiminator/C64-Collection
2,357
C64_xu1541/software/tools/cc65-2.13.2/libsrc/atari/atari-stdjoy.s
; ; Standard joystick driver for the Atari. May be used multiple times when linked ; to the statically application. ; ; Ullrich von Bassewitz, 2002-12-21 ; Using the readjoy code from Christian Groessler ; .include "zeropage.inc" .include "joy-kernel.inc" .include "joy-error.inc" .include "atari.inc" .macpack generic ; ------------------------------------------------------------------------ ; Header. Includes jump table .segment "JUMPTABLE" ; Driver signature .byte $6A, $6F, $79 ; "joy" .byte JOY_API_VERSION ; 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 ; JOY_FIRE2 not available .byte $00 ; Future expansion .byte $00 ; Future expansion ; Jump table. .addr INSTALL .addr UNINSTALL .addr COUNT .addr READJOY .addr 0 ; IRQ entry not used ; ------------------------------------------------------------------------ ; Constants JOY_COUNT = 4 ; 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 #0 ; 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 $fcd8 cpx #$a2 beq _400800 lsr a ; XL and newer machines only have 2 ports _400800: ldx #0 rts ; ------------------------------------------------------------------------ ; READ: Read a particular joystick passed in A. ; READJOY: and #3 ; fix joystick number tax ; Joystick number (0-3) into X ; Read joystick lda STRIG0,x ; get button asl a asl a asl a asl a ora STICK0,x ; add position information eor #$1F ldx #0 ; fix X rts
wagiminator/C64-Collection
7,450
C64_xu1541/software/tools/cc65-2.13.2/libsrc/atari/rs232.s
; ; Christian Groessler, Dec-2001 ; ; RS232 routines using the R: device (currently tested with an 850 only) ; ; unsigned char __fastcall__ rs232_init (char hacked); ; unsigned char __fastcall__ rs232_params (unsigned char params, unsigned char parity); ; unsigned char __fastcall__ rs232_done (void); ; unsigned char __fastcall__ rs232_get (char* B); ; unsigned char __fastcall__ rs232_put (char B); ; unsigned char __fastcall__ rs232_pause (void); [TODO] ; unsigned char __fastcall__ rs232_unpause (void); [TODO] ; unsigned char __fastcall__ rs232_status (unsigned char* status, ; unsigned char* errors); [TODO] ; .import findfreeiocb .import __do_oserror .import fddecusage .import fdtoiocb .import __inviocb .import clriocb .import newfd .import _close, pushax, popax, popa .importzp ptr1, tmp2, tmp3 .export _rs232_init, _rs232_params, _rs232_done, _rs232_get .export _rs232_put, _rs232_pause, _rs232_unpause, _rs232_status .include "atari.inc" .include "errno.inc" .include "rs232.inc" .rodata rdev: .byte "R:", ATEOL, 0 .bss ; receive buffer RECVBUF_SZ = 256 recv_buf: .res RECVBUF_SZ cm_run: .res 1 ; concurrent mode running? .data rshand: .word $ffff .code ;---------------------------------------------------------------------------- ; ; unsigned char __fastcall__ rs232_init (char hacked); ; /* Initialize the serial port. The parameter is ignored in the Atari version. ; * return 0/-1 for OK/Error ; */ ; .proc _rs232_init jsr findfreeiocb bne init_err txa tay ; move iocb # into Y lda #3 sta tmp3 ; name length + 1 lda #<rdev ldx #>rdev jsr newfd tya bcs doopen ; C set: open needed / device not already open pha jsr _rs232_done ;** shut down if started @@@TODO check this out!! pla doopen: tax pha jsr clriocb pla tax lda #<rdev sta ICBAL,x lda #>rdev sta ICBAH,x lda #OPEN sta ICCOM,x lda #$0D ; mode in+out+concurrent sta ICAX1,x lda #0 sta ICAX2,x sta ICBLL,x ; zap buf len sta ICBLH,x jsr CIOV bmi cioerr1 lda tmp2 ; get fd sta rshand ldx #0 stx rshand+1 txa rts cioerr1:jsr fddecusage ; decrement usage counter of fd as open failed init_err: ldx #0 lda #RS_ERR_INIT_FAILED rts .endproc ; _rs232_init ;---------------------------------------------------------------------------- ; ; unsigned char __fastcall__ rs232_params (unsigned char params, unsigned char parity); ; ; Set communication parameters. ; ; params contains baud rate, stop bits and word size ; parity contains parity ; ; 850 manual documents restrictions on the baud rate (not > 300), when not ; using 8 bit word size. So only 8 bit is currently tested. ; .proc _rs232_params sta tmp2 lda rshand cmp #$ff bne work ; work only if initialized lda #RS_ERR_NOT_INITIALIZED bne done work: lda rshand ldx #0 jsr fdtoiocb ; get iocb index into X bmi inverr ; shouldn't happen tax ; set handshake lines lda #34 ; xio 34, set cts, dtr etc sta ICCOM,x lda #192+48+3 ; DTR on, RTS on, XMT on sta ICAX1,x lda #0 sta ICBLL,x sta ICBLH,x sta ICBAL,x sta ICBAH,x sta ICAX2,x jsr CIOV bmi cioerr ; set baud rate, word size, stop bits and ready monitoring lda #36 ; xio 36, baud rate sta ICCOM,x jsr popa ; get parameter sta ICAX1,x ;ICAX2 = 0, monitor nothing jsr CIOV bmi cioerr ; set translation and parity lda #38 ; xio 38, translation and parity sta ICCOM,x lda tmp2 ora #32 ; no translation sta ICAX1,x jsr CIOV bmi cioerr lda #0 done: ldx #0 rts inverr: jmp __inviocb .endproc ;_rs232_params cioerr: jmp __do_oserror ;---------------------------------------------------------------------------- ; ; unsigned char __fastcall__ rs232_done (void); ; /* Close the port, deinstall the interrupt hander. You MUST call this function ; * before terminating the program, otherwise the machine may crash later. If ; * in doubt, install an exit handler using atexit(). The function will do ; * nothing, if it was already called. ; */ ; .proc _rs232_done lda rshand cmp #$ff beq done work: ldx rshand+1 jsr pushax jsr _close pha txa pha ldx #$ff stx rshand stx rshand+1 inx stx cm_run pla tax pla done: rts .endproc ;rs232_done ;---------------------------------------------------------------------------- ; ; unsigned char __fastcall__ rs232_get (char* B); ; /* Get a character from the serial port. If no characters are available, the ; * function will return RS_ERR_NO_DATA, so this is not a fatal error. ; */ ; .proc _rs232_get ldy rshand cpy #$ff bne work ; work only if initialized lda #RS_ERR_NOT_INITIALIZED bne nierr work: sta ptr1 stx ptr1+1 ; store pointer to received char lda rshand ldx #0 jsr fdtoiocb tax lda cm_run ; concurrent mode already running? bne go jsr ena_cm ; turn on concurrent mode go: ; check whether there is any input available lda #STATIS ; status request, returns bytes pending sta ICCOM,x jsr CIOV bmi cioerr ; @@@ error handling lda DVSTAT+1 ; get byte count pending ora DVSTAT+2 beq nix_da ; no input waiting... ; input is available: get it! lda #GETCHR ; get raw bytes sta ICCOM,x ; in command code lda #0 sta ICBLL,x sta ICBLH,x sta ICBAL,x sta ICBAH,x jsr CIOV ; go get it bmi cioerr ; @@@ error handling ldx #0 sta (ptr1,x) ; return received byte txa rts nierr: ldx #0 rts nix_da: lda #RS_ERR_NO_DATA ldx #0 rts .endproc ;_rs232_get ;---------------------------------------------------------------------------- ; ; unsigned char __fastcall__ rs232_put (char B); ; /* Send a character via the serial port. There is a transmit buffer, but ; * transmitting is not done via interrupt. The function returns ; * RS_ERR_OVERFLOW if there is no space left in the transmit buffer. ; */ ; .proc _rs232_put ldy rshand cpy #$ff bne work ; work only if initialized lda #RS_ERR_NOT_INITIALIZED bne nierr work: pha lda rshand ldx #0 jsr fdtoiocb tax lda cm_run ; concurrent mode already running? bne go jsr ena_cm ; turn on concurrent mode ; @@@TODO: check output buffer overflow go: lda #PUTCHR ; put raw bytes sta ICCOM,x ; in command code lda #0 sta ICBLL,x sta ICBLH,x sta ICBAL,x sta ICBAH,x pla ; get the char back jsr CIOV ; go do it rts nierr: ldx #0 rts .endproc ;_rs232_put ;---------------------------------------------------------------------------- ; ; unsigned char __fastcall__ rs232_pause (void); ; /* Assert flow control and disable interrupts. */ ; _rs232_pause: ;---------------------------------------------------------------------------- ; ; unsigned char __fastcall__ rs232_unpause (void); ; /* Re-enable interrupts and release flow control */ ; _rs232_unpause: ;---------------------------------------------------------------------------- ; ; unsigned char __fastcall__ rs232_status (unsigned char* status, ; unsigned char* errors); ; /* Return the serial port status. */ ; _rs232_status: lda #255 tax rts ; enable concurrent rs232 mode ; gets iocb index in X ; all registers destroyed .proc ena_cm lda #40 ; XIO 40, start concurrent IO sta ICCOM,x sta cm_run ; indicate concurrent mode is running lda #0 sta ICAX1,x sta ICAX2,x lda #<recv_buf sta ICBAL,x lda #>recv_buf sta ICBAH,x lda #<RECVBUF_SZ sta ICBLL,x lda #>RECVBUF_SZ sta ICBLH,x lda #$0D ; value from 850 man, p62. must be 0D?, sta ICAX1,x ; or any non-zero? jmp CIOV .endproc ;ena_cm .end
wagiminator/C64-Collection
11,684
C64_xu1541/software/tools/cc65-2.13.2/libsrc/atari/ctype.s
; ; Ullrich von Bassewitz, 02.06.1998 ; ; Character specification table. ; ; adapted to Atari by Christian Groessler, June 2000 ; ; The tables are readonly, put them into the rodata segment .rodata ; The following 256 byte wide table specifies attributes for the isxxx type ; of functions. Doing it by a table means some overhead in space, but it ; has major advantages: ; ; * It is fast. If it were'nt for the slow parameter passing of cc65, one ; could even define macros for the isxxx functions (this is usually ; done on other platforms). ; ; * It is highly portable. The only unportable part is the table itself, ; all real code goes into the common library. ; ; * We save some code in the isxxx functions. ; ; ; Bit assignments: ; ; 0 - Lower case char ; 1 - Upper case char ; 2 - Numeric digit ; 3 - Hex digit (both, lower and upper) ; 4 - Control character ; 5 - The space character itself ; 6 - Other whitespace (that is: '\f', '\n', '\r', '\t' and '\v') ; 7 - Space or tab character .export __ctype __ctype: .byte $00 ; 0/00 ___heart____ .byte $00 ; 1/01 ___l_tee____ .byte $00 ; 2/02 ___ctrl_B___ .byte $00 ; 3/03 ___ctrl_C___ .byte $00 ; 4/04 ___r_tee____ .byte $00 ; 5/05 ___ctrl_E___ .byte $00 ; 6/06 ___ctrl_F___ .byte $00 ; 7/07 ___ctrl_G___ .byte $00 ; 8/08 ___ctrl_H___ .byte $00 ; 9/09 ___ctrl_I___ .byte $00 ; 10/0a ___ctrl_J___ .byte $00 ; 11/0b ___ctrl_K___ .byte $00 ; 12/0c ___ctrl_L___ .byte $00 ; 13/0d ___ctrl_M___ .byte $00 ; 14/0e ___ctrl_N___ .byte $00 ; 15/0f ___ctrl_O___ .byte $00 ; 16/10 ____club____ .byte $00 ; 17/11 ___ctrl_Q___ .byte $00 ; 18/12 ___h_line___ .byte $00 ; 19/13 ___ctrl_S___ .byte $00 ; 20/14 ____ball____ .byte $00 ; 21/15 ___ctrl_U___ .byte $00 ; 22/16 ___ctrl_V___ .byte $00 ; 23/17 ___t_tee____ .byte $00 ; 24/18 ___b_tee____ .byte $00 ; 25/19 ___ctrl_Y___ .byte $00 ; 26/1a ___ctrl_Z___ .byte $10 ; 27/1b ____ESC_____ .byte $10 ; 28/1c ___crsr_up__ .byte $10 ; 29/1d ___crsr_dn__ .byte $10 ; 30/1e ___crsr_lf__ .byte $10 ; 31/1f ___crsr_rg__ .byte $A0 ; 32/20 ___SPACE___ .byte $00 ; 33/21 _____!_____ .byte $00 ; 34/22 _____"_____ .byte $00 ; 35/23 _____#_____ .byte $00 ; 36/24 _____$_____ .byte $00 ; 37/25 _____%_____ .byte $00 ; 38/26 _____&_____ .byte $00 ; 39/27 _____'_____ .byte $00 ; 40/28 _____(_____ .byte $00 ; 41/29 _____)_____ .byte $00 ; 42/2a _____*_____ .byte $00 ; 43/2b _____+_____ .byte $00 ; 44/2c _____,_____ .byte $00 ; 45/2d _____-_____ .byte $00 ; 46/2e _____._____ .byte $00 ; 47/2f _____/_____ .byte $0C ; 48/30 _____0_____ .byte $0C ; 49/31 _____1_____ .byte $0C ; 50/32 _____2_____ .byte $0C ; 51/33 _____3_____ .byte $0C ; 52/34 _____4_____ .byte $0C ; 53/35 _____5_____ .byte $0C ; 54/36 _____6_____ .byte $0C ; 55/37 _____7_____ .byte $0C ; 56/38 _____8_____ .byte $0C ; 57/39 _____9_____ .byte $00 ; 58/3a _____:_____ .byte $00 ; 59/3b _____;_____ .byte $00 ; 60/3c _____<_____ .byte $00 ; 61/3d _____=_____ .byte $00 ; 62/3e _____>_____ .byte $00 ; 63/3f _____?_____ .byte $00 ; 64/40 _____@_____ .byte $0A ; 65/41 _____A_____ .byte $0A ; 66/42 _____B_____ .byte $0A ; 67/43 _____C_____ .byte $0A ; 68/44 _____D_____ .byte $0A ; 69/45 _____E_____ .byte $0A ; 70/46 _____F_____ .byte $02 ; 71/47 _____G_____ .byte $02 ; 72/48 _____H_____ .byte $02 ; 73/49 _____I_____ .byte $02 ; 74/4a _____J_____ .byte $02 ; 75/4b _____K_____ .byte $02 ; 76/4c _____L_____ .byte $02 ; 77/4d _____M_____ .byte $02 ; 78/4e _____N_____ .byte $02 ; 79/4f _____O_____ .byte $02 ; 80/50 _____P_____ .byte $02 ; 81/51 _____Q_____ .byte $02 ; 82/52 _____R_____ .byte $02 ; 83/53 _____S_____ .byte $02 ; 84/54 _____T_____ .byte $02 ; 85/55 _____U_____ .byte $02 ; 86/56 _____V_____ .byte $02 ; 87/57 _____W_____ .byte $02 ; 88/58 _____X_____ .byte $02 ; 89/59 _____Y_____ .byte $02 ; 90/5a _____Z_____ .byte $00 ; 91/5b _____[_____ .byte $00 ; 92/5c _____\_____ .byte $00 ; 93/5d _____]_____ .byte $00 ; 94/5e _____^_____ .byte $00 ; 95/5f _UNDERLINE_ .byte $00 ; 96/60 __diamond__ .byte $09 ; 97/61 _____a_____ .byte $09 ; 98/62 _____b_____ .byte $09 ; 99/63 _____c_____ .byte $09 ; 100/64 _____d_____ .byte $09 ; 101/65 _____e_____ .byte $09 ; 102/66 _____f_____ .byte $01 ; 103/67 _____g_____ .byte $01 ; 104/68 _____h_____ .byte $01 ; 105/69 _____i_____ .byte $01 ; 106/6a _____j_____ .byte $01 ; 107/6b _____k_____ .byte $01 ; 108/6c _____l_____ .byte $01 ; 109/6d _____m_____ .byte $01 ; 110/6e _____n_____ .byte $01 ; 111/6f _____o_____ .byte $01 ; 112/70 _____p_____ .byte $01 ; 113/71 _____q_____ .byte $01 ; 114/72 _____r_____ .byte $01 ; 115/73 _____s_____ .byte $01 ; 116/74 _____t_____ .byte $01 ; 117/75 _____u_____ .byte $01 ; 118/76 _____v_____ .byte $01 ; 119/77 _____w_____ .byte $01 ; 120/78 _____x_____ .byte $01 ; 121/79 _____y_____ .byte $01 ; 122/7a _____z_____ .byte $00 ; 123/7b ___spade___ .byte $00 ; 124/7c __v_line___ .byte $10 ; 125/7d __CLRSCR___ .byte $D0 ; 126/7e __backtab__ .byte $D0 ; 127/7f ____tab____ .byte $00 ; 128/80 _inv_heart___ .byte $00 ; 129/81 _inv_l_tee___ .byte $00 ; 130/82 _inv_ctrl_B__ .byte $00 ; 131/83 _inv_ctrl_C__ .byte $00 ; 132/84 _inv_r_tee___ .byte $00 ; 133/85 _inv_ctrl_E__ .byte $00 ; 134/86 _inv_ctrl_F__ .byte $00 ; 135/87 _inv_ctrl_G__ .byte $00 ; 136/88 _inv_ctrl_H__ .byte $00 ; 137/89 _inv_ctrl_I__ .byte $00 ; 138/8a _inv_ctrl_J__ .byte $00 ; 139/8b _inv_ctrl_K__ .byte $00 ; 140/8c _inv_ctrl_L__ .byte $00 ; 141/8d _inv_ctrl_M__ .byte $00 ; 142/8e _inv_ctrl_N__ .byte $00 ; 143/8f _inv_ctrl_O__ .byte $00 ; 144/90 __inv__club__ .byte $00 ; 145/91 _inv_ctrl_Q__ .byte $00 ; 146/92 _inv_h_line__ .byte $00 ; 147/93 _inv_ctrl_S__ .byte $00 ; 148/94 __inv__ball__ .byte $00 ; 149/95 _inv_ctrl_U__ .byte $00 ; 150/96 _inv_ctrl_V__ .byte $00 ; 151/97 __inv_t_tee__ .byte $00 ; 152/98 __inv_b_tee__ .byte $00 ; 153/99 _inv_ctrl_Y__ .byte $00 ; 154/9a _inv_ctrl_Z__ .byte $50 ; 155/9b _____EOL_____ .byte $10 ; 156/9c ___CLRLINE___ .byte $10 ; 157/9d ___INSLINE___ .byte $10 ; 158/9e ____CLRTAB___ .byte $10 ; 159/9f ____INSTAB___ .byte $A0 ; 160/a0 __inv_SPACE__ .byte $00 ; 161/a1 ___inv_!_____ .byte $00 ; 162/a2 ___inv_"_____ .byte $00 ; 163/a3 ___inv_#_____ .byte $00 ; 164/a4 ___inv_$_____ .byte $00 ; 165/a5 ___inv_%_____ .byte $00 ; 166/a6 ___inv_&_____ .byte $00 ; 167/a7 ___inv_'_____ .byte $00 ; 168/a8 ___inv_(_____ .byte $00 ; 169/a9 ___inv_)_____ .byte $00 ; 170/aa ___inv_*_____ .byte $00 ; 171/ab ___inv_+_____ .byte $00 ; 172/ac ___inv_,_____ .byte $00 ; 173/ad ___inv_-_____ .byte $00 ; 174/ae ___inv_._____ .byte $00 ; 175/af ___inv_/_____ .byte $0C ; 176/b0 ___inv_0_____ .byte $0C ; 177/b1 ___inv_1_____ .byte $0C ; 178/b2 ___inv_2_____ .byte $0C ; 179/b3 ___inv_3_____ .byte $0C ; 180/b4 ___inv_4_____ .byte $0C ; 181/b5 ___inv_5_____ .byte $0C ; 182/b6 ___inv_6_____ .byte $0C ; 183/b7 ___inv_7_____ .byte $0C ; 184/b8 ___inv_8_____ .byte $0C ; 185/b9 ___inv_9_____ .byte $00 ; 186/ba ___inv_:_____ .byte $00 ; 187/bb ___inv_;_____ .byte $00 ; 188/bc ___inv_<_____ .byte $00 ; 189/bd ___inv_=_____ .byte $00 ; 190/be ___inv_>_____ .byte $00 ; 191/bf ___inv_?_____ .byte $00 ; 192/c0 ___inv_@_____ .byte $0A ; 193/c1 ___inv_A_____ .byte $0A ; 194/c2 ___inv_B_____ .byte $0A ; 195/c3 ___inv_C_____ .byte $0A ; 196/c4 ___inv_D_____ .byte $0A ; 197/c5 ___inv_E_____ .byte $0A ; 198/c6 ___inv_F_____ .byte $02 ; 199/c7 ___inv_G_____ .byte $02 ; 200/c8 ___inv_H_____ .byte $02 ; 201/c9 ___inv_I_____ .byte $02 ; 202/ca ___inv_J_____ .byte $02 ; 203/cb ___inv_K_____ .byte $02 ; 204/cc ___inv_L_____ .byte $02 ; 205/cd ___inv_M_____ .byte $02 ; 206/ce ___inv_N_____ .byte $02 ; 207/cf ___inv_O_____ .byte $02 ; 208/d0 ___inv_P_____ .byte $02 ; 209/d1 ___inv_Q_____ .byte $02 ; 210/d2 ___inv_R_____ .byte $02 ; 211/d3 ___inv_S_____ .byte $02 ; 212/d4 ___inv_T_____ .byte $02 ; 213/d5 ___inv_U_____ .byte $02 ; 214/d6 ___inv_V_____ .byte $02 ; 215/d7 ___inv_W_____ .byte $02 ; 216/d8 ___inv_X_____ .byte $02 ; 217/d9 ___inv_Y_____ .byte $02 ; 218/da ___inv_Z_____ .byte $00 ; 219/db ___inv_[_____ .byte $00 ; 220/dc ___inv_\_____ .byte $00 ; 221/dd ___inv_]_____ .byte $00 ; 222/de ___inv_^_____ .byte $00 ; 223/df _inv_UNDRLIN_ .byte $00 ; 224/e0 _inv_diamond_ .byte $09 ; 225/e1 ___inv_a_____ .byte $09 ; 226/e2 ___inv_b_____ .byte $09 ; 227/e3 ___inv_c_____ .byte $09 ; 228/e4 ___inv_d_____ .byte $09 ; 229/e5 ___inv_e_____ .byte $09 ; 230/e6 ___inv_f_____ .byte $01 ; 231/e7 ___inv_g_____ .byte $01 ; 232/e8 ___inv_h_____ .byte $01 ; 233/e9 ___inv_i_____ .byte $01 ; 234/ea ___inv_j_____ .byte $01 ; 235/eb ___inv_k_____ .byte $01 ; 236/ec ___inv_l_____ .byte $01 ; 237/ed ___inv_m_____ .byte $01 ; 238/ee ___inv_n_____ .byte $01 ; 239/ef ___inv_o_____ .byte $01 ; 240/f0 ___inv_p_____ .byte $01 ; 241/f1 ___inv_q_____ .byte $01 ; 242/f2 ___inv_r_____ .byte $01 ; 243/f3 ___inv_s_____ .byte $01 ; 244/f4 ___inv_t_____ .byte $01 ; 245/f5 ___inv_u_____ .byte $01 ; 246/f6 ___inv_v_____ .byte $01 ; 247/f7 ___inv_w_____ .byte $01 ; 248/f8 ___inv_x_____ .byte $01 ; 249/f9 ___inv_y_____ .byte $01 ; 250/fa ___inv_z_____ .byte $00 ; 251/fb __inv_spade__ .byte $00 ; 252/fc __inv_v_line_ .byte $10 ; 253/fd ____BEEP_____ .byte $10 ; 254/fe ____DELBS____ .byte $10 ; 255/ff ___INSERT____
wagiminator/C64-Collection
2,602
C64_xu1541/software/tools/cc65-2.13.2/libsrc/atari/open.s
; ; Christian Groessler, Jan-2003 ; ; int open(const char *name,int flags,...); ; .include "atari.inc" .include "fcntl.inc" .include "errno.inc" .include "fd.inc" .export _open .destructor closeallfiles, 17 .import _close .import clriocb .import fddecusage,newfd .import findfreeiocb .import __do_oserror,incsp4 .import ldaxysp,addysp .import __oserror .importzp tmp4,tmp2 .ifdef UCASE_FILENAME .importzp tmp3 .import ucase_fn .endif .proc _open cpy #4 ; correct # of arguments (bytes)? beq parmok ; parameter count ok tya ; parm count < 4 shouldn't be needed to be checked sec ; (it generates a c compiler warning) sbc #4 tay jsr addysp ; fix stack, throw away unused parameters parmok: jsr findfreeiocb beq iocbok ; we found one lda #<EMFILE ; "too many open files" seterr: jsr __seterrno jsr incsp4 ; clean up stack lda #$FF tax rts ; return -1 ; process the mode argument iocbok: stx tmp4 jsr clriocb ; init with zero ldy #1 jsr ldaxysp ; get mode ldx tmp4 pha and #O_APPEND beq no_app pla and #15 cmp #O_RDONLY ; DOS supports append with write-only only beq invret cmp #O_RDWR beq invret lda #OPNOT|APPEND bne set .ifndef UCASE_FILENAME invret: lda #<EINVAL ; file name is too long ldx #>EINVAL jmp seterr .endif no_app: pla and #15 cmp #O_RDONLY bne l1 lda #OPNIN set: sta ICAX1,x bne cont l1: cmp #O_WRONLY bne l2 lda #OPNOT bne set l2: ; O_RDWR lda #OPNOT|OPNIN bne set ; process the filename argument cont: ldy #3 jsr ldaxysp .ifdef UCASE_FILENAME jsr ucase_fn bcc ucok1 invret: lda #<EINVAL ; file name is too long ldx #>EINVAL jmp seterr ucok1: .endif ; defined UCASE_FILENAME ldy tmp4 ;AX - points to filename ;Y - iocb to use, if open needed jsr newfd ; maybe we don't need to open and can reuse an iocb ; returns fd num to use in tmp2, all regs unchanged bcs doopen ; C set: open needed lda #0 ; clears N flag beq finish doopen: sta ICBAL,y txa sta ICBAH,y ldx tmp4 lda #OPEN sta ICCOM,x jsr CIOV ; clean up the stack finish: php txa pha tya pha .ifdef UCASE_FILENAME ldy tmp3 ; get size jsr addysp ; free used space on the stack .endif ; defined UCASE_FILENAME jsr incsp4 ; clean up stack pla tay pla tax plp bpl ok jsr fddecusage ; decrement usage counter of fd as open failed jmp __do_oserror ok: lda tmp2 ; get fd ldx #0 stx __oserror rts .endproc ; closeallfiles: Close all files opened by the program. .proc closeallfiles lda #MAX_FD_INDEX-1 loop: ldx #0 pha jsr _close pla clc sbc #0 bpl loop rts .endproc
wagiminator/C64-Collection
1,195
C64_xu1541/software/tools/cc65-2.13.2/libsrc/mouse/mouse_geterrormsg.s
; ; Ullrich von Bassewitz, 2004-11-07 ; ; const char* __fastcall__ mouse_geterrormsg (unsigned char code); ; /* Get an error message describing the error in code. */ ; .include "mouse-kernel.inc" .proc _mouse_geterrormsg cmp #MOUSE_ERR_COUNT bcc L1 lda #MOUSE_ERR_COUNT ; "Unknown error" L1: tay ldx #>msgtab lda #<msgtab clc adc offs,y bcc L2 inx L2: rts .endproc ;---------------------------------------------------------------------------- ; Error messages. The messages are currently limited to 256 bytes total. .rodata offs: .byte <(msg0-msgtab) .byte <(msg1-msgtab) .byte <(msg2-msgtab) .byte <(msg3-msgtab) .byte <(msg4-msgtab) .byte <(msg5-msgtab) .byte <(msg6-msgtab) msgtab: msg0: .asciiz "No error" msg1: .asciiz "No driver available" msg2: .asciiz "Cannot load driver" msg3: .asciiz "Invalid driver" msg4: .asciiz "Mouse hardware not found" msg5: .asciiz "Invalid ioctl code" msg6: .asciiz "Unknown error"
wagiminator/C64-Collection
5,387
C64_xu1541/software/tools/cc65-2.13.2/libsrc/mouse/mouse-kernel.s
; ; Ullrich von Bassewitz, 2003-12-28, 2009-09-26 ; ; Common functions of the mouse driver API. ; .import return0, popsreg, incsp2 .importzp sreg, ptr1, tmp1, tmp2 .interruptor mouse_irq ; Export as IRQ handler .include "mouse-kernel.inc" ;---------------------------------------------------------------------------- ; Variables .bss _mouse_drv: .res 2 ; Pointer to driver _mouse_hidden: .res 1 ; Mouse visibility flag ; Jump table for the driver functions. .data mouse_vectors: mouse_install: jmp return0 mouse_uninstall:jmp return0 mouse_hide: jmp return0 mouse_show: jmp return0 mouse_setbox: jmp return0 mouse_getbox: jmp return0 mouse_move: jmp return0 mouse_buttons: jmp return0 mouse_pos: jmp return0 mouse_info: jmp return0 mouse_ioctl: jmp return0 mouse_irq: .byte $60, $00, $00 ; RTS plus two dummy bytes mouse_flags: .byte $00 ; Driver header signature .rodata mouse_sig: .byte $6d, $6f, $75, MOUSE_API_VERSION ; "mou", version .code ;---------------------------------------------------------------------------- ; unsigned char __fastcall__ mouse_install (const struct mouse_callbacks* c, ; void* driver); ; /* Install an already loaded driver. Returns an error code. */ _mouse_install: sta _mouse_drv sta ptr1 stx _mouse_drv+1 stx ptr1+1 ; Check the driver signature ldy #.sizeof(mouse_sig)-1 @L0: lda (ptr1),y cmp mouse_sig,y bne inv_drv dey bpl @L0 ; Reset flags lda #1 sta _mouse_hidden ; Copy the jump vectors ldy #MOUSE_HDR::JUMPTAB ldx #0 @L1: inx ; Skip the JMP opcode jsr copyjv ; Copy one byte jsr copyjv ; Copy one byte cpy #(MOUSE_HDR::JUMPTAB + .sizeof(MOUSE_HDR::JUMPTAB)) bne @L1 ; Copy the flags byte. It is located directly behind the jump vectors, so Y ; is already correct when we come here. To save code, we use copyjv - crude ; but effective. jsr copyjv ; Copy the callback vectors into the driver space jsr popsreg ldy #(MOUSE_HDR::CALLBACKS + .sizeof(MOUSE_HDR::CALLBACKS) - 1) sty tmp2 ldy #.sizeof(MOUSE_CALLBACKS)-1 sty tmp1 @L2: jsr copycb ldy tmp1 jsr copycb dec tmp2 ; Skip opcode byte ldy tmp1 bpl @L2 ; Install the IRQ vector if the driver needs it bit mouse_flags ; Test MOUSE_FLAG_EARLY_IRQ bvc @L3 ; Jump if no interrupts at this time jsr install_irq ; Activate IRQ routine ; Call driver install routine and check for errors @L3: jsr mouse_install tay ; Test error code bne uninstall_irq ; Jump on error ; No errors on INSTALL. If the driver needs late IRQs, enable them now. Be ; careful not to use A/X since these registers contain the error code from ; INSTALL. bit mouse_flags ; Test MOUSE_FLAG_LATE_IRQ bpl Exit ; Jump if vector not needed install_irq: ldy #$4C ; Jump opcode sty mouse_irq ; Activate IRQ routine Exit: rts ; Uninstall IRQ vector if install routine had errors. A/X may contain the ; error code from mouse_install, so don't use it. uninstall_irq: ldy #$60 ; RTS opcode sty mouse_irq ; Disable IRQ entry point rts ; Driver signature invalid. One word is still on the stack inv_drv: lda #MOUSE_ERR_INV_DRIVER ldx #0 jmp incsp2 ; Copy one byte from the jump vectors copyjv: lda (ptr1),y sta mouse_vectors,x iny inx rts ; Copy one byte from the callback vectors copycb: lda (sreg),y dec tmp1 ldy tmp2 sta (ptr1),y dec tmp2 rts ;---------------------------------------------------------------------------- ; unsigned char __fastcall__ mouse_uninstall (void); ; /* Uninstall the currently loaded driver. Returns an error code. */ _mouse_uninstall: ; Depending on the late/early IRQ flag, we will disable IRQs before or after ; calling the driver mouse_uninstall routine. bit mouse_flags ; Test MOUSE_FLAG_LATE_IRQ bpl @L1 ; Don't disable interrupts now jsr uninstall_irq ; Disable driver interrupts @L1: jsr mouse_uninstall ; Call driver routine ; We don't check the flag a second time here, since disabling IRQs twice, ; or disabling them if they weren't enabled will do no harm, and the missing ; check will save a few bytes. jsr uninstall_irq ; Disable driver interrupts _mouse_clear_ptr: ; External entry point lda #0 sta _mouse_drv sta _mouse_drv+1 ; Clear the driver pointer tax rts ; Return zero
wagiminator/C64-Collection
3,193
C64_xu1541/software/tools/cc65-2.13.2/libsrc/mouse/mouse_load.s
; ; Ullrich von Bassewitz, 2006-06-05 ; ; unsigned char __fastcall__ mouse_load_driver (const struct mouse_callbacks* c, ; const char* name) ; /* Load a mouse driver and return an error code */ .include "mouse-kernel.inc" .include "modload.inc" .include "fcntl.inc" .import pushax .import pusha0 .import incsp2 .import _open .import _read .import _close ;---------------------------------------------------------------------------- ; Variables .data ctrl: .addr _read .res 2 ; CALLERDATA .res 2 ; MODULE .res 2 ; MODULE_SIZE .res 2 ; MODULE_ID ;---------------------------------------------------------------------------- ; Code .code .proc _mouse_load_driver ; Save name on the C stack. We will need it later as parameter passed to open() jsr pushax ; Check if we do already have a driver loaded. If so, remove it. lda _mouse_drv ora _mouse_drv+1 beq @L1 jsr _mouse_uninstall ; Open the file. The name parameter is already on stack and will get removed ; by open(). ; ctrl.callerdata = open (name, O_RDONLY); @L1: lda #<O_RDONLY jsr pusha0 ldy #4 ; Argument size jsr _open sta ctrl + MOD_CTRL::CALLERDATA stx ctrl + MOD_CTRL::CALLERDATA+1 ; if (ctrl.callerdata >= 0) { txa bmi @L3 ; /* Load the module */ ; Res = mod_load (&ctrl); lda #<ctrl ldx #>ctrl jsr _mod_load pha ; /* Close the input file */ ; close (ctrl.callerdata); lda ctrl + MOD_CTRL::CALLERDATA ldx ctrl + MOD_CTRL::CALLERDATA+1 jsr _close ; /* Check the return code */ ; if (Res == MLOAD_OK) { pla bne @L3 ; Check the driver signature, install the driver. c is already on stack and ; will get removed by mouse_install(). ; Res = mouse_install (c, ctrl.module); lda ctrl + MOD_CTRL::MODULE ldx ctrl + MOD_CTRL::MODULE+1 jsr _mouse_install ; If mouse_install was successful, we're done tax beq @L2 ; The driver didn't install correctly. Remove it from memory and return the ; error code. pha ; Save the error code lda _mouse_drv ldx _mouse_drv+1 jsr _mod_free ; Free the driver memory jsr _mouse_clear_ptr ; Clear mouse_drv pla ; Restore the error code ldx #0 ; We must return an int @L2: rts ; Done ; Open or mod_load failed. Remove excess arguments from stack and return an ; error code. @L3: jsr incsp2 lda #<MOUSE_ERR_CANNOT_LOAD ldx #>MOUSE_ERR_CANNOT_LOAD rts .endproc
wagiminator/C64-Collection
9,214
C64_xu1541/software/tools/cc65-2.13.2/libsrc/apple2/apple2-stdmou.s
; ; Driver for the AppleMouse II Card. ; ; Oliver Schmidt, 03.09.2005 ; .include "zeropage.inc" .include "mouse-kernel.inc" .include "apple2.inc" ; ------------------------------------------------------------------------ SETMOUSE = $12 ; Sets mouse mode SERVEMOUSE = $13 ; Services mouse interrupt READMOUSE = $14 ; Reads mouse position CLEARMOUSE = $15 ; Clears mouse position to 0 (for delta mode) POSMOUSE = $16 ; Sets mouse position to a user-defined pos CLAMPMOUSE = $17 ; Sets mouse bounds in a window HOMEMOUSE = $18 ; Sets mouse to upper-left corner of clamp win INITMOUSE = $19 ; Resets mouse clamps to default values and ; sets mouse position to 0,0 pos1_lo := $0478 pos1_hi := $0578 pos2_lo := $04F8 pos2_hi := $05F8 status := $0778 ; ------------------------------------------------------------------------ .segment "JUMPTABLE" ; Driver signature .byte $6D, $6F, $75 ; "mou" .byte MOUSE_API_VERSION ; Mouse driver API version number ; Jump table. .addr INSTALL .addr UNINSTALL .addr HIDE .addr SHOW .addr SETBOX .addr GETBOX .addr MOVE .addr BUTTONS .addr POS .addr INFO .addr IOCTL .addr IRQ ; Mouse driver flags .byte MOUSE_FLAG_EARLY_IRQ ; Callback table, set by the kernel before INSTALL is called CHIDE: jmp $0000 ; Hide the cursor CSHOW: jmp $0000 ; Show the cursor CMOVEX: jmp $0000 ; Move the cursor to X coord CMOVEY: jmp $0000 ; Move the cursor to Y coord ; ------------------------------------------------------------------------ .bss box: .tag MOUSE_BOX info: .tag MOUSE_INFO slot: .res 1 visible:.res 1 ; ------------------------------------------------------------------------ .rodata offsets:.byte $05 ; Pascal 1.0 ID byte .byte $07 ; Pascal 1.0 ID byte .byte $0B ; Pascal 1.1 generic signature byte .byte $0C ; Device signature byte values: .byte $38 ; Fixed .byte $18 ; Fixed .byte $01 ; Fixed .byte $20 ; X-Y pointing device type 0 size = * - values inibox: .word 0 ; MinX .word 0 ; MinY .word 279 ; MaxX .word 191 ; MaxY ; ------------------------------------------------------------------------ .data firmware: ; Lookup and patch firmware address lobyte lookup: ldy $FF00,x ; Patched at runtime sty jump+1 ; Modify code below ; Apple II Mouse TechNote #1, Interrupt Environment with the Mouse: ; "Enter all mouse routines (...) with the X register set to $Cn ; and Y register set to $n0, where n = the slot number." xparam: ldx #$FF ; Patched at runtime yparam: ldy #$FF ; Patched at runtime jump: jmp $FFFF ; Patched at runtime ; ------------------------------------------------------------------------ .code ; INSTALL: Is called after the driver is loaded into memory. If possible, ; check if the hardware is present. Must return an MOUSE_ERR_xx code in A/X. INSTALL: lda #<$C000 sta ptr1 lda #>$C000 sta ptr1+1 ; Search for AppleMouse II firmware in slots 1 - 7 next: inc ptr1+1 lda ptr1+1 cmp #>$C800 bcc :+ ; Mouse firmware not found lda #<MOUSE_ERR_NO_DEVICE ldx #>MOUSE_ERR_NO_DEVICE rts ; Check Pascal 1.1 Firmware Protocol ID bytes : ldx #size - 1 : ldy offsets,x lda values,x cmp (ptr1),y bne next dex bpl :- ; Get and patch firmware address hibyte lda ptr1+1 sta lookup+2 sta xparam+1 sta jump+2 ; Disable interrupts now because setting the slot number makes ; the IRQ handler (maybe called due to some non-mouse IRQ) try ; calling the firmware which isn't correctly set up yet sei ; Convert to and save slot number and #$0F sta slot ; Convert to and patch I/O register index asl asl asl asl sta yparam+1 ; The AppleMouse II Card needs the ROM switched in ; to be able to detect an Apple //e and use RDVBL bit $C082 ; Reset mouse hardware ldx #INITMOUSE jsr firmware ; Switch in LC bank 2 for R/O bit $C080 ; Turn mouse on lda #%00000001 ldx #SETMOUSE jsr firmware ; Set initial mouse clamps lda #<inibox ldx #>inibox jsr SETBOX ; Set initial mouse position ldx slot lda #<(279 / 2) sta pos1_lo,x lda #>(279 / 2) sta pos1_hi,x lda #<(191 / 2) sta pos2_lo,x lda #>(191 / 2) sta pos2_hi,x ldx #POSMOUSE jsr firmware ; Update cursor jsr update ; Turn VBL interrupt on lda #%00001001 ldx #SETMOUSE common: jsr firmware ; Enable interrupts and return success cli lda #<MOUSE_ERR_OK ldx #>MOUSE_ERR_OK rts ; UNINSTALL: Is called before the driver is removed from memory. ; No return code required (the driver is removed from memory on return). UNINSTALL: ; Hide cursor sei jsr CHIDE ; Turn mouse off lda #%00000000 ldx #SETMOUSE bne common ; Branch always ; SETBOX: Set the mouse bounding box. The parameters are passed as they come ; from the C program, that is, a pointer to a mouse_box struct in A/X. ; No checks are done if the mouse is currently inside the box, this is the job ; of the caller. It is not necessary to validate the parameters, trust the ; caller and save some code here. No return code required. SETBOX: sta ptr1 stx ptr1+1 ; Set x clamps ldx #$00 ldy #MOUSE_BOX::MINX jsr :+ ; Set y clamps ldx #$01 ldy #MOUSE_BOX::MINY ; Apple II Mouse TechNote #1, Interrupt Environment with the Mouse: ; "Disable interrupts before placing position information in the ; screen holes." : sei ; Set low clamp lda (ptr1),y sta box,y sta pos1_lo iny lda (ptr1),y sta box,y sta pos1_hi ; Skip one word iny iny ; Set high clamp iny lda (ptr1),y sta box,y sta pos2_lo iny lda (ptr1),y sta box,y sta pos2_hi txa ldx #CLAMPMOUSE bne common ; Branch always ; GETBOX: Return the mouse bounding box. The parameters are passed as they ; come from the C program, that is, a pointer to a mouse_box struct in A/X. GETBOX: sta ptr1 stx ptr1+1 ldy #.sizeof(MOUSE_BOX)-1 : lda box,y sta (ptr1),y dey bpl :- rts ; MOVE: Move the mouse to a new position. The position is passed as it comes ; from the C program, that is: x on the stack and y in A/X. The C wrapper will ; remove the parameter from the stack on return. ; No checks are done if the new position is valid (within the bounding box or ; the screen). No return code required. MOVE: ldy slot sei ; Set y sta pos2_lo,y txa sta pos2_hi,y tya tax ldy #$00 ; Start at top of stack ; Set x lda (sp),y iny sta pos1_lo,x lda (sp),y sta pos1_hi,x ; Update cursor jsr update ldx #POSMOUSE bne common ; Branch always ; HIDE: Is called to hide the mouse cursor. The mouse kernel manages a ; counter for calls to show/hide, and the driver entry point is only called ; if the mouse is currently visible and should get hidden. For most drivers, ; no special action is required besides hiding the mouse cursor. ; No return code required. HIDE: dec visible sei jsr CHIDE cli rts ; SHOW: Is called to show the mouse cursor. The mouse kernel manages a ; counter for calls to show/hide, and the driver entry point is only called ; if the mouse is currently hidden and should become visible. For most drivers, ; no special action is required besides enabling the mouse cursor. ; No return code required. SHOW: inc visible rts ; BUTTONS: Return the button mask in A/X. BUTTONS: lda info + MOUSE_INFO::BUTTONS ldx #$00 rts ; POS: Return the mouse position in the MOUSE_POS struct pointed to by ptr1. ; No return code required. POS: ldy #.sizeof(MOUSE_POS)-1 bne copy ; Branch always ; INFO: Returns mouse position and current button mask in the MOUSE_INFO ; struct pointed to by ptr1. No return code required. INFO: ldy #.sizeof(MOUSE_INFO)-1 copy: sei : lda info,y sta (ptr1),y dey bpl :- cli rts ; IOCTL: Driver defined entry point. The wrapper will pass a pointer to ioctl ; specific data in ptr1, and the ioctl code in A. ; Must return an MOUSE_ERR_xx code in A/X. IOCTL: lda #<MOUSE_ERR_INV_IOCTL ldx #>MOUSE_ERR_INV_IOCTL rts ; IRQ: Called from the builtin runtime IRQ handler as a subroutine. All ; registers are already saved, no parameters are passed, but the carry flag ; is clear on entry. The routine must return with carry set if the interrupt ; was handled, otherwise with carry clear. IRQ: ; Check for installed mouse lda slot beq done ; Check for mouse interrupt ldx #SERVEMOUSE jsr firmware bcc :+ clc ; Interrupt not handled done: rts : ldx #READMOUSE jsr firmware ; Get status ldy slot lda status,y tax ; Save status ; Extract button down values asl ; C = Button 0 is currently down and #%00100000 ; !Z = Button 1 is currently down ; Set button mask beq :+ lda #MOUSE_BTN_RIGHT : bcc :+ ora #MOUSE_BTN_LEFT : sta info + MOUSE_INFO::BUTTONS ; Check for mouse movement txa ; Restore status and #%00100000 ; X or Y changed since last READMOUSE beq :+ ; Remove the cursor at the old position update: jsr CHIDE ; Get and set the new X position ldy slot lda pos1_lo,y ldx pos1_hi,y sta info + MOUSE_POS::XCOORD stx info + MOUSE_POS::XCOORD+1 jsr CMOVEX ; Get and set the new Y position ldy slot lda pos2_lo,y ldx pos2_hi,y sta info + MOUSE_POS::YCOORD stx info + MOUSE_POS::YCOORD+1 jsr CMOVEY ; Check for visibility : lda visible beq :+ ; Draw the cursor at the new position jsr CSHOW : sec ; Interrupt handled rts
wagiminator/C64-Collection
1,262
C64_xu1541/software/tools/cc65-2.13.2/libsrc/apple2/sysmkdir.s
; ; Oliver Schmidt, 15.04.2005 ; ; unsigned char _sysmkdir (const char* name, ...); ; .export __sysmkdir .import pushname, popname .import addysp, popax .include "zeropage.inc" .include "mli.inc" __sysmkdir: ; Throw away all parameters except the name dey dey jsr addysp ; Get and push name jsr popax jsr pushname bne oserr ; Set pushed name lda sp ldx sp+1 sta mliparam + MLI::CREATE::PATHNAME stx mliparam + MLI::CREATE::PATHNAME+1 ; Set all other parameters from template ldx #(MLI::CREATE::CREATE_TIME+1) - (MLI::CREATE::PATHNAME+1) - 1 : lda CREATE,x sta mliparam + MLI::CREATE::ACCESS,x dex bpl :- ; Make directory lda #CREATE_CALL ldx #CREATE_COUNT jsr callmli ; Cleanup name jsr popname ; Preserves A oserr: rts .rodata CREATE: .byte %11000011 ; ACCESS: Standard full access .byte $0F ; FILE_TYPE: Directory file .word $0000 ; AUX_TYPE: N/A .byte $0D ; STORAGE_TYPE: Linked directory file .word $0000 ; CREATE_DATE: Current date .word $0000 ; CREATE_TIME: Current time
wagiminator/C64-Collection
1,113
C64_xu1541/software/tools/cc65-2.13.2/libsrc/apple2/sysrename.s
; ; Oliver Schmidt, 15.04.2005 ; ; unsigned char __fastcall__ _sysrename (const char* oldname, const char* newname); ; .export __sysrename .import pushname, popname .import popax .include "zeropage.inc" .include "mli.inc" __sysrename: ; Save newname sta ptr2 stx ptr2+1 ; Get and push oldname jsr popax jsr pushname bne oserr1 ; Save pushed oldname lda sp ldx sp+1 sta ptr3 stx ptr3+1 ; Restore and push newname lda ptr2 ldx ptr2+1 jsr pushname bne oserr2 ; Restore and set pushed oldname lda ptr3 ldx ptr3+1 sta mliparam + MLI::RENAME::PATHNAME stx mliparam + MLI::RENAME::PATHNAME+1 ; Set pushed newname lda sp ldx sp+1 sta mliparam + MLI::RENAME::NEW_PATHNAME stx mliparam + MLI::RENAME::NEW_PATHNAME+1 ; Rename file lda #RENAME_CALL ldx #RENAME_COUNT jsr callmli ; Cleanup newname jsr popname ; Preserves A ; Cleanup oldname oserr2: jsr popname ; Preserves A oserr1: rts
wagiminator/C64-Collection
8,761
C64_xu1541/software/tools/cc65-2.13.2/libsrc/apple2/crt0.s
; ; Oliver Schmidt, 15.09.2009 ; ; Startup code for cc65 (Apple2 version) ; .export _exit, done, return .export __STARTUP__ : absolute = 1 ; Mark as startup .import zerobss .import initlib, donelib .import callmain, callirq .import __RAM_START__ , __RAM_LAST__ ; Linker generated .import __MOVE_START__, __MOVE_LAST__ ; Linker generated .import __LC_START__ , __LC_LAST__ ; Linker generated .import __ZPSAVE_RUN__, __INIT_SIZE__ ; Linker generated .import __INTERRUPTOR_COUNT__ ; Linker generated .include "zeropage.inc" .include "apple2.inc" .linecont + ; ------------------------------------------------------------------------ .segment "EXEHDR" .addr __RAM_START__ ; Start address .word __ZPSAVE_RUN__ - __RAM_START__ + \ __MOVE_LAST__ - __MOVE_START__ ; Size ; ------------------------------------------------------------------------ .segment "STARTUP" ; ProDOS TechRefMan, chapter 5.2.1: ; "For maximum interrupt efficiency, a system program should not ; use more than the upper 3/4 of the stack." ldx #$FF txs ; Init stack pointer ; Switch in LC bank 2 for W/O bit $C081 bit $C081 ; Set source start address lda #<(__ZPSAVE_RUN__ + __INIT_SIZE__) ldy #>(__ZPSAVE_RUN__ + __INIT_SIZE__) sta $9B sty $9C ; Set source last address lda #<(__ZPSAVE_RUN__ + __INIT_SIZE__ + __LC_LAST__ - __LC_START__) ldy #>(__ZPSAVE_RUN__ + __INIT_SIZE__ + __LC_LAST__ - __LC_START__) sta $96 sty $97 ; Set destination last address lda #<__LC_LAST__ ldy #>__LC_LAST__ sta $94 sty $95 ; Call into Applesoft Block Transfer Utility - which handles zero ; sized blocks well - to move content of the LC memory area jsr $D396 ; BLTU + 3 ; Set source start address lda #<__ZPSAVE_RUN__ ldy #>__ZPSAVE_RUN__ sta $9B sty $9C ; Set source last address lda #<(__ZPSAVE_RUN__ + __INIT_SIZE__) ldy #>(__ZPSAVE_RUN__ + __INIT_SIZE__) sta $96 sty $97 ; Set destination last address lda #<__RAM_LAST__ ldy #>__RAM_LAST__ sta $94 sty $95 ; Call into Applesoft Block Transfer Utility - which handles moving ; overlapping blocks upwards well - to move the INIT segment jsr $D396 ; BLTU + 3 ; Delegate all further processing to keep the STARTUP segment small jsr init ; Avoid re-entrance of donelib. This is also the _exit entry _exit: ldx #<exit lda #>exit jsr reset ; Setup RESET vector ; Switch in ROM in case it wasn't already switched in by a RESET bit $C082 ; Call module destructors jsr donelib ; Check for valid interrupt vector table entry number lda int_num beq exit ; Deallocate interrupt vector table entry dec i_param ; Adjust parameter count jsr $BF00 ; MLI call entry point .byte $41 ; Dealloc interrupt .addr i_param ; Restore the original RESET vector exit: ldx #$02 : lda rvsave,x sta SOFTEV,x dex bpl :- ; Copy back the zero page stuff ldx #zpspace-1 : lda zpsave,x sta sp,x dex bpl :- ; ProDOS TechRefMan, chapter 5.2.1: ; "System programs should set the stack pointer to $FF at the ; warm-start entry point." ldx #$FF txs ; Re-init stack pointer ; We're done jmp (done) ; ------------------------------------------------------------------------ .segment "INIT" ; Save the zero page locations we need init: ldx #zpspace-1 : lda sp,x sta zpsave,x dex bpl :- ; Clear the BSS data jsr zerobss ; Save the original RESET vector ldx #$02 : lda SOFTEV,x sta rvsave,x dex bpl :- ; ProDOS TechRefMan, chapter 5.3.5: ; "Your system program should place in the RESET vector the ; address of a routine that ... closes the files." ldx #<_exit lda #>_exit jsr reset ; Setup RESET vector ; Check for ProDOS ldy $BF00 ; MLI call entry point cpy #$4C ; Is MLI present? (JMP opcode) bne basic ; Check ProDOS system bit map lda $BF6F ; protection for pages $B8 - $BF cmp #%00000001 ; exactly system global page is protected bne basic ; No BASIC.SYSTEM so quit to ProDOS dispatcher instead lda #<quit ldx #>quit sta done stx done+1 ; No BASIC.SYSTEM so use addr of ProDOS system global page lda #<$BF00 ldx #>$BF00 bne :+ ; Branch always ; Get highest available mem addr from BASIC interpreter basic: lda HIMEM ldx HIMEM+1 ; Setup the C stack : sta sp stx sp+1 ; Check for interruptors lda #<__INTERRUPTOR_COUNT__ beq :+ ; Check for ProDOS cpy #$4C ; Is MLI present? (JMP opcode) bne prterr ; Allocate interrupt vector table entry jsr $BF00 ; MLI call entry point .byte $40 ; Alloc interrupt .addr i_param bcs prterr ; Enable interrupts as old ProDOS versions (i.e. 1.1.1) ; jump to SYS and BIN programs with interrupts disabled cli ; Call module constructors : jsr initlib ; Switch in LC bank 2 for R/O bit $C080 ; Push arguments and call main() jmp callmain ; Print error message and return prterr: ldx #msglen-1 : lda errmsg,x jsr $FDED ; COUT dex bpl :- rts errmsg: .ifdef __APPLE2ENH__ .byte $8D, 't'|$80, 'p'|$80, 'u'|$80, 'r'|$80, 'r'|$80 .byte 'e'|$80, 't'|$80, 'n'|$80, 'i'|$80, ' '|$80, 'c'|$80 .byte 'o'|$80, 'l'|$80, 'l'|$80, 'a'|$80, ' '|$80, 'o'|$80 .byte 't'|$80, ' '|$80, 'd'|$80, 'e'|$80, 'l'|$80, 'i'|$80 .byte 'a'|$80, 'F'|$80, $8D .else .byte $8D, 'T'|$80, 'P'|$80, 'U'|$80, 'R'|$80, 'R'|$80 .byte 'E'|$80, 'T'|$80, 'N'|$80, 'I'|$80, ' '|$80, 'C'|$80 .byte 'O'|$80, 'L'|$80, 'L'|$80, 'A'|$80, ' '|$80, 'O'|$80 .byte 'T'|$80, ' '|$80, 'D'|$80, 'E'|$80, 'L'|$80, 'I'|$80 .byte 'A'|$80, 'F'|$80, $8D .endif msglen = * - errmsg ; ------------------------------------------------------------------------ .segment "LOWCODE" ; ProDOS TechRefMan, chapter 6.2: ; "Each installed routine must begin with a CLD instruction." intptr: cld ; Call interruptors and check for success jsr callirq bcc :+ ; ProDOS TechRefMan, chapter 6.2: ; "When the routine that can process the interrupt is called, it ; should ... return (via an RTS) with the carry flag clear." clc rts ; ProDOS TechRefMan, chapter 6.2: ; "When a routine that cannot process the interrupt is called, ; it should return (via an RTS) with the cary flag set ..." : sec rts ; Setup RESET vector reset: stx SOFTEV sta SOFTEV+1 eor #$A5 sta PWREDUP return: rts ; Quit to ProDOS dispatcher quit: jsr $BF00 ; MLI call entry point .byte $65 ; Quit .word q_param ; ------------------------------------------------------------------------ .rodata ; MLI parameter list for quit q_param:.byte $04 ; param_count .byte $00 ; quit_type .word $0000 ; reserved .byte $00 ; reserved .word $0000 ; reserved ; ------------------------------------------------------------------------ .data ; MLI parameter list for (de)alloc interrupt i_param:.byte $02 ; param_count int_num:.byte $00 ; int_num .addr intptr ; int_code ; Location to jump to when we're done done: .addr DOSWARM ; ------------------------------------------------------------------------ .segment "ZPSAVE" zpsave: .res zpspace ; ------------------------------------------------------------------------ .bss rvsave: .res 3
wagiminator/C64-Collection
2,303
C64_xu1541/software/tools/cc65-2.13.2/libsrc/apple2/videomode.s
; ; Oliver Schmidt, 07.09.2009 ; ; unsigned __fastcall__ videomode (unsigned mode); ; .export _videomode .import COUT .include "apple2.inc" .segment "LOWCODE" _videomode: ; Get and save current videomode flag bit RD80VID php ; If we are in 80 column mode then the 80 column firmware is ; known to be active so we can just print the ctrl-char code ; (even if this only means staying in the current videomode) bpl :+ jsr COUT bra done ; If we are in 40 column mode and want to set 40 column mode ; then we explicitly do nothing as we neither know about the ; current state of the 80 column firmware nor want to fix it : cmp #$11 ; Ctrl-char code for 40 cols beq done ; If we are in 40 column mode and want to set 80 column mode ; then we first presume the 80 column firmware being already ; active and print the ctrl-char code (this causes a garbage ; char to be printed on the screen if isn't already active) jsr COUT ; If we successfully switched to 80 column mode then the 80 ; column firmware was in fact already active and we're done bit RD80VID bmi done ; The 80 column firmware isn't already active so we need to ; initialize it - causing the screen to be cleared and thus ; the garbage char printed above to be erased (but for some ; reason the cursor horizontal position not to be zeroed) stz CH ; Initializing the 80 column firmware needs the ROM switched ; in, otherwise it would copy the F8 ROM to the LC (@ $CEF4) bit $C082 ; Initialize 80 column firmware jsr $C300 ; PR#3 ; Switch in LC bank 2 for R/O bit $C080 ; Return ctrl-char code for setting previous ; videomode using the saved videomode flag done: lda #$11 ; Ctrl-char code for 40 cols plp bpl :+ lda #$12 ; Ctrl-char code for 80 cols : rts ; X was preserved all the way
wagiminator/C64-Collection
1,195
C64_xu1541/software/tools/cc65-2.13.2/libsrc/apple2/rwcommon.s
; ; Oliver Schmidt, 12.01.2005 ; .export rwprolog, rwcommon, rwepilog .import oserrexit .import popax .include "zeropage.inc" .include "fcntl.inc" .include "mli.inc" .include "filedes.inc" rwprolog: ; Save count sta ptr2 stx ptr2+1 ; Get and save buf jsr popax sta ptr1 stx ptr1+1 ; Get and process fd jsr popax jmp getfd ; Returns A, Y and C rwcommon: ; Set fd sta mliparam + MLI::RW::REF_NUM ; Set buf lda ptr1 ldx ptr1+1 sta mliparam + MLI::RW::DATA_BUFFER stx mliparam + MLI::RW::DATA_BUFFER+1 ; Set count lda ptr2 ldx ptr2+1 sta mliparam + MLI::RW::REQUEST_COUNT stx mliparam + MLI::RW::REQUEST_COUNT+1 ; Call read or write tya ldx #RW_COUNT jsr callmli bcc rwepilog cmp #$4C ; "End of file" bne oserr rwepilog: ; Return success lda mliparam + MLI::RW::TRANS_COUNT ldx mliparam + MLI::RW::TRANS_COUNT+1 rts ; Return oserror oserr: jmp oserrexit
wagiminator/C64-Collection
2,722
C64_xu1541/software/tools/cc65-2.13.2/libsrc/apple2/mcbdefault.s
; ; Default mouse callbacks for the Apple II ; ; Oliver Schmidt, 22.09.2005 ; ; All functions in this module should be interrupt safe, because they may ; be called from an interrupt handler ; .export _mouse_def_callbacks .include "apple2.inc" ; ------------------------------------------------------------------------ .bss backup: .res 1 ; ------------------------------------------------------------------------ .rodata ; Callback structure _mouse_def_callbacks: .addr hide .addr show .addr movex .addr movey ; ------------------------------------------------------------------------ .data .ifdef __APPLE2ENH__ cursor = 'B' ; MouseText character .else cursor = '+' | $40 ; Flashing crosshair .endif getcursor: .ifdef __APPLE2ENH__ bit RD80VID ; In 80 column mode? bpl column ; No, skip bank switching switch: bit LOWSCR ; Patched at runtime .endif column: ldx #$00 ; Patched at runtime getscr: lda $0400,x ; Patched at runtime cmp #cursor rts setcursor: lda #cursor setscr: sta $0400,x ; Patched at runtime .ifdef __APPLE2ENH__ bit LOWSCR ; Doesn't hurt in 40 column mode .endif rts ; ------------------------------------------------------------------------ .code done: .ifdef __APPLE2ENH__ bit LOWSCR ; Doesn't hurt in 40 column mode .endif rts ; Hide the mouse cursor. hide: jsr getcursor ; Cursor visible at current position? bne done ; No, we're done lda backup ; Get character at cursor position jmp setscr ; Draw character ; Show the mouse cursor. show: jsr getcursor ; Cursor visible at current position? beq done ; Yes, we're done sta backup ; Save character at cursor position jmp setcursor ; Draw cursor ; Move the mouse cursor x position to the value in A/X. movex: dex ; Is position [256..279]? bmi :+ ; No, start with column 0 clc adc #$0100 .MOD 7 ; Bias position ldx #$0100 / 7 - 1 ; Bias column : sec : sbc #7 ; 280 positions / 40 columns inx bcs :- stx column+1 .ifdef __APPLE2ENH__ adc #7 / 2 ; Left or right half of 40-col column? ldx #<LOWSCR ; Columns 1,3,5..79 bcs :+ .assert LOWSCR + 1 = HISCR, error inx ; Columns 0,2,4..78 : stx switch+1 .endif rts ; Move the mouse cursor y position to the value in A/X. movey: tax ; ABCDExxx lsr ; 0ABCDExx lsr ; 00ABCDEx lsr ; 000ABCDE sta getscr+1 lsr ; 0000ABCD and #%00000011 ; 000000CD ora #>$0400 ; 000001CD sta getscr+2 sta setscr+2 txa ; ABCDExxx ror ; EABCDExx and #%11100000 ; EAB00000 ora getscr+1 ; EABABCDE and #%11111000 ; EABAB000 sta getscr+1 sta setscr+1 rts
wagiminator/C64-Collection
5,237
C64_xu1541/software/tools/cc65-2.13.2/libsrc/apple2/mainargs.s
; mainargs.s ; ; Ullrich von Bassewitz, 2003-03-07 ; Based on code from Stefan A. Haubenthal <polluks@web.de>, 2003-11-08 ; Greg King, 2003-05-18 ; Stefan Haubenthal, 2005-01-07 ; Oliver Schmidt, 2005-04-05 ; ; Scan a group of arguments that are in BASIC's input-buffer. ; Build an array that points to the beginning of each argument. ; Send, to main(), that array and the count of the arguments. ; Command-lines look like these lines: ; ; call2051 ; call2051 : rem ; call2051:rem arg1 " arg 2 is quoted " arg3 "" arg5 ; ; "call" and "rem" are entokenned; the args. are not. Leading and trailing ; spaces outside of quotes are ignored. ; TO-DO: ; Add a control-character quoting mechanism. .constructor initmainargs, 18 .import __argc, __argv, __dos_type .include "zeropage.inc" .include "apple2.inc" ; Maximum number of arguments allowed in the argument table. ; (An argument contains a comma, at least.) MAXARGS = 10 ; ProDOS stores the filename in the second half of BASIC's input buffer, so ; there are 128 characters left. At least 7 characters are necessary for the ; CALLxxxx:REM so 121 characters may be used before overwriting the ProDOS ; filename. As we don't want to put further restrictions on the command-line ; length we reserve those 121 characters terminated by a zero. BUF_LEN = 122 BASIC_BUF = $200 FNAM_LEN = $280 FNAM = $281 REM = $B2 ; BASIC token-code ; Get possible command-line arguments. Goes into the special INIT segment, ; which may be reused after the startup code is run. .segment "INIT" initmainargs: ; Assume that the program was loaded, a moment ago, by the traditional BLOAD ; statement of BASIC.SYSTEM. Save the filename as argument #0 if available. ldx __dos_type ; No ProDOS -> argv[0] = "" beq :+ ; Terminate the filename with a zero to make it a valid C string. ldx FNAM_LEN : lda #$00 sta FNAM,x inc __argc ; argc always is equal to, at least, 1 ; Find the "rem" token. ldx #$00 : lda BASIC_BUF,x beq done ; No "rem" -> no args inx cmp #REM bne :- ; If a clock is present it is called by ProDOS on file operations. On machines ; with a slot-based clock (like the Thunder Clock) the clock firmware places ; the current date in BASIC's input buffer. Therefore we have to create a copy ; of the command-line in a different buffer before the original is potentially ; destroyed. ldy #$00 : lda BASIC_BUF,x sta buffer,y inx iny cpy #BUF_LEN - 1 ; Keep the terminating zero intact bcc :- ; Start processing the arguments. ldx #$00 ldy #$01 * 2 ; Start with argv[1] ; Find the next argument. Stop if the end of the string or a character with the ; hibit set is reached. The later is true if the string isn't already parsed by ; BASIC (as expected) but is a still unprocessed input string. In this case the ; string isn't the expected command-line at all. We found this out the hard way ; by BRUNing the program with ProDOS on a machine with a slot-based clock (like ; the Thunder Clock). ProDOS called the clock firmware which places the current ; date as BASIC input string with hibits set in the input buffer. While looking ; for the REM token we stumbled across the first '2' character ($32+$80 = $B2) ; and interpreted the rest of the date as a spurious command-line parameter. next: lda buffer,x beq done bmi done inx cmp #' ' ; Skip leading spaces beq next ; Found start of next argument. We've incremented the pointer in X already, so ; it points to the second character of the argument. This is useful since we ; will check now for a quoted argument, in which case we will have to skip this ; first character. cmp #'"' ; Is the argument quoted? beq :+ ; Jump if so dex ; Reset pointer to first argument character lda #' ' ; A space ends the argument : sta tmp1 ; Set end of argument marker ; Now store a pointer to the argument into the next slot. txa ; Get low byte clc adc #<buffer sta argv,y ; argv[y] = &arg iny lda #$00 adc #>buffer sta argv,y iny inc __argc ; Found another arg ; Search for the end of the argument. : lda buffer,x beq done inx cmp tmp1 bne :- ; We've found the end of the argument. X points one character behind it, and ; A contains the terminating character. To make the argument a valid C string, ; replace the terminating character by a zero. lda #$00 sta buffer-1,x ; Check if the maximum number of command-line arguments is reached. If not, ; parse the next one. lda __argc ; Get low byte of argument count cmp #MAXARGS ; Maximum number of arguments reached? bcc next ; Parse next one if not ; (The last vector in argv[] already is NULL.) done: lda #<argv ldx #>argv sta __argv stx __argv+1 rts ; This array is zeroed before initmainargs is called. ; char* argv[MAXARGS+1] = {FNAM}; .data argv: .addr FNAM .res MAXARGS * 2 .bss buffer: .res BUF_LEN
wagiminator/C64-Collection
1,987
C64_xu1541/software/tools/cc65-2.13.2/libsrc/apple2/get_ostype.s
; ; Oliver Schmidt, 04.01.2005 ; ; unsigned char get_ostype (void) ; .constructor initostype .export _get_ostype ; Identify machine according to: ; Apple II Miscellaneous TechNote #7, Apple II Family Identification .segment "INIT" initostype: sec jsr $FE1F bcs nogs tya ora #$80 done: sta ostype rts nogs: ldx #$FF next: inx lda value,x ldy index,x beq done ; $00 is no valid index cmp $FB00,y beq next : inx ldy index,x bne :- beq next ; Branch always index: .byte $B3, $00 ; Apple ][ .byte $B3, $1E, $00 ; Apple ][+ .byte $B3, $1E, $00 ; Apple /// (emulation) .byte $B3, $C0, $00 ; Apple //e .byte $B3, $C0, $DD, $BE, $00 ; Apple //e Option Card .byte $B3, $C0, $00 ; Apple //e (enhanced) .byte $B3, $C0, $BF, $00 ; Apple //c .byte $B3, $C0, $BF, $00 ; Apple //c (3.5 ROM) .byte $B3, $C0, $BF, $00 ; Apple //c (Mem. Exp.) .byte $B3, $C0, $BF, $00 ; Apple //c (Rev. Mem. Exp.) .byte $B3, $C0, $BF, $00 ; Apple //c Plus .byte $00 value: .byte $38, $10 ; Apple ][ .byte $EA, $AD, $11 ; Apple ][+ .byte $EA, $8A, $20 ; Apple /// (emulation) .byte $06, $EA, $30 ; Apple //e .byte $06, $E0, $02, $00, $40 ; Apple //e Option Card .byte $06, $E0, $31 ; Apple //e (enhanced) .byte $06, $00, $FF, $50 ; Apple //c .byte $06, $00, $00, $51 ; Apple //c (3.5 ROM) .byte $06, $00, $03, $53 ; Apple //c (Mem. Exp.) .byte $06, $00, $04, $54 ; Apple //c (Rev. Mem. Exp.) .byte $06, $00, $05, $55 ; Apple //c Plus .byte $00 .code _get_ostype: lda ostype ldx #$00 rts .bss ostype: .res 1
wagiminator/C64-Collection
2,017
C64_xu1541/software/tools/cc65-2.13.2/libsrc/apple2/oserror.s
; ; Ullrich von Bassewitz, 17.05.2000 ; ; int __fastcall__ _osmaperrno (unsigned char oserror); ; .export __osmaperrno .include "errno.inc" __osmaperrno: ldx #ErrTabSize : cmp ErrTab-2,x ; Search for the error code beq :+ ; Jump if found dex dex bne :- ; Next entry ; Code not found, return EUNKNOWN lda #<EUNKNOWN ldx #>EUNKNOWN rts ; Found the code : lda ErrTab-1,x ldx #$00 ; High byte always zero rts .rodata ErrTab: .byte $01, ENOSYS ; Invalid MLI function code number .byte $04, EINVAL ; Incorrect parameter count .byte $25, ENOMEM ; Interrupt table full .byte $27, EIO ; I/O error .byte $28, ENODEV ; No device connected .byte $2B, EACCES ; Write protected ; .byte $2E, EUNKNOWN ; Disk switched .byte $2F, ENODEV ; No disk in drive .byte $40, EINVAL ; Invalid pathname syntax .byte $42, EMFILE ; Too many files open .byte $43, EINVAL ; Bad reference number .byte $44, ENOENT ; Bad pathname .byte $45, ENOENT ; Volume not mounted .byte $46, ENOENT ; File not found .byte $47, EEXIST ; File already exists .byte $48, ENOSPC ; Disk full .byte $49, ENOSPC ; Directory full ; .byte $4A, EUNKNOWN ; Incompatible ProDOS version .byte $4B, EINVAL ; Unsupported storage type ; .byte $4C, EUNKNOWN ; End of file .byte $4D, ESPIPE ; Position past EOF .byte $4E, EACCES ; Access denied .byte $50, EINVAL ; File already open ; .byte $51, EUNKNOWN ; File count bad .byte $52, ENODEV ; Not a ProDOS disk .byte $53, ERANGE ; Parameter out of range .byte $55, EMFILE ; Too many devices mounted .byte $56, EINVAL ; Bad buffer address ; .byte $57, EUNKNOWN ; Duplicate volume name ; .byte $5A, EUNKNOWN ; Damaged disk free space bit map ErrTabSize = (* - ErrTab)
wagiminator/C64-Collection
2,592
C64_xu1541/software/tools/cc65-2.13.2/libsrc/apple2/cputc.s
; ; Ullrich von Bassewitz, 06.08.1998 ; ; void __fastcall__ cputcxy (unsigned char x, unsigned char y, char c); ; void __fastcall__ cputc (char c); ; .ifdef __APPLE2ENH__ .constructor initconio, 17 .endif .export _cputcxy, _cputc .export cputdirect, newline, putchar .import popa, _gotoxy, VTABZ .include "apple2.inc" .segment "INIT" .ifdef __APPLE2ENH__ initconio: sta SETALTCHAR ; Switch in alternate charset bit LORES ; Limit SET80COL-HISCR to text rts .endif .code ; Plot a character - also used as internal function _cputcxy: pha ; Save C jsr popa ; Get Y jsr _gotoxy pla ; Restore C _cputc: cmp #$0D ; Test for \r = carrage return beq left cmp #$0A ; Test for \n = line feed beq newline ora #$80 ; Turn on high bit .ifndef __APPLE2ENH__ cmp #$E0 ; Test for lowercase bcc cputdirect and #$DF ; Convert to uppercase .endif cputdirect: jsr putchar inc CH ; Bump to next column lda CH cmp WNDWDTH bcc :+ left: lda #$00 ; Goto left edge of screen sta CH : rts newline: inc CV ; Bump to next line lda CV cmp WNDBTM bcc :+ lda WNDTOP ; Goto top of screen sta CV : jmp VTABZ putchar: .ifdef __APPLE2ENH__ ldy INVFLG cpy #$FF ; Normal character display mode? beq put cmp #$E0 ; Lowercase? bcc mask and #$7F ; Inverse lowercase bra put .endif mask: and INVFLG ; Apply normal, inverse, flash put: ldy CH .ifdef __APPLE2ENH__ bit RD80VID ; In 80 column mode? bpl col40 ; No, in 40 cols pha tya lsr ; Div by 2 tay pla bcs col40 ; Odd cols go in 40 col memory bit HISCR ; Assume SET80COL sta (BASL),Y bit LOWSCR ; Assume SET80COL rts .endif col40: sta (BASL),Y rts
wagiminator/C64-Collection
2,073
C64_xu1541/software/tools/cc65-2.13.2/libsrc/apple2/filename.s
; ; Oliver Schmidt, 30.12.2004 ; ; File name handling for ProDOS 8 file I/O ; .export pushname, popname .import subysp, addysp, decsp1 .include "zeropage.inc" .include "mli.inc" pushname: sta ptr1 stx ptr1+1 ; Alloc pathname buffer ldy #64+1 ; Max pathname length + zero jsr subysp ; Check for full pathname ldy #$00 lda (ptr1),y cmp #'/' beq copy ; Check for system prefix lda PFIXPTR bne copy ; Use unit number of most recent accessed device lda DEVNUM sta mliparam + MLI::ON_LINE::UNIT_NUM ; Use allocated pathname buffer lda sp ldx sp+1 sta mliparam + MLI::ON_LINE::DATA_BUFFER stx mliparam + MLI::ON_LINE::DATA_BUFFER+1 ; Get volume name lda #ON_LINE_CALL ldx #ON_LINE_COUNT jsr callmli bcs addsp65 ; Get volume name length lda (sp),y and #15 ; Max volume name length ; Bracket volume name with slashes to form prefix sta tmp1 lda #'/' sta (sp),y ldy tmp1 iny ; Leading slash sta (sp),y iny ; Trailing slash ; Adjust source pointer for copy sty tmp1 lda ptr1 sec sbc tmp1 bcs :+ dec ptr1+1 : sta ptr1 ; Copy source to allocated pathname buffer copy: lda (ptr1),y sta (sp),y beq setlen iny cpy #64+1 ; Max pathname length + zero bcc copy ; Load oserror code lda #$40 ; "Invalid pathname syntax" ; Free pathname buffer addsp65:ldy #64+1 bne addsp ; Branch always ; Alloc and set length byte setlen: tya jsr decsp1 ; Preserves A ldy #$00 sta (sp),y ; Return success tya rts popname: ; Cleanup stack ldy #1 + 64+1 ; Length byte + max pathname length + zero addsp: jmp addysp ; Preserves A
wagiminator/C64-Collection
13,598
C64_xu1541/software/tools/cc65-2.13.2/libsrc/apple2/apple2-40-48-16.s
; ; Graphics driver for the 40x48x16 mode on the Apple II ; ; Stefan Haubenthal <polluks@sdf.lonestar.org> ; Oliver Schmidt <ol.sc@web.de> ; Based on Maciej Witkowiak's line and circle routine ; .include "zeropage.inc" .include "tgi-kernel.inc" .include "tgi-mode.inc" .include "tgi-error.inc" .include "apple2.inc" .macpack generic ; ------------------------------------------------------------------------ ; Zero page stuff H2 := $2C ; ROM entry points TEXT := $F399 PLOT := $F800 HLINE := $F819 CLRSCR := $F832 SETCOL := $F864 SCRN := $F871 SETGR := $FB40 HOME := $FC58 ; ------------------------------------------------------------------------ ; Variables mapped to the zero page segment variables. Some of these are ; used for passing parameters to the driver. X1 := ptr1 Y1 := ptr2 X2 := ptr3 Y2 := ptr4 RADIUS := tmp1 ADDR := tmp1 TEMP := tmp3 TEMP2 := tmp4 TEMP3 := sreg TEMP4 := sreg+1 ; Line routine stuff (must be on zpage) PB := ptr3 ; (2) LINE UB := ptr4 ; (2) LINE ERR := regsave ; (2) LINE NX := regsave+2 ; (2) LINE ; Circle routine stuff (must be on zpage) XX := ptr3 ; (2) CIRCLE YY := ptr4 ; (2) CIRCLE MaxO := sreg ; (overwritten by TEMP3+TEMP4, but restored from OG/OU anyway) XS := regsave ; (2) CIRCLE YS := regsave+2 ; (2) CIRCLE ; ------------------------------------------------------------------------ .segment "JUMPTABLE" ; Header. Includes jump table and constants. ; First part of the header is a structure that has a magic and defines the ; capabilities of the driver .byte $74, $67, $69 ; "tgi" .byte TGI_API_VERSION ; TGI API version number xres: .word 40 ; X resolution yres: .word 48 ; Y resolution .byte 16 ; Number of drawing colors .byte 1 ; Number of screens available .byte 8 ; System font X size .byte 8 ; System font Y size .res 4, $00 ; Reserved for future extensions ; Next comes the jump table. Currently all entries must be valid and may point ; to an RTS for test versions (function not implemented). .addr INSTALL .addr UNINSTALL .addr INIT .addr DONE .addr GETERROR .addr CONTROL .addr CLEAR .addr SETVIEWPAGE .addr SETDRAWPAGE .addr SETCOLOR .addr SETPALETTE .addr GETPALETTE .addr GETDEFPALETTE .addr SETPIXEL .addr GETPIXEL .addr LINE .addr BAR .addr CIRCLE .addr TEXTSTYLE .addr OUTTEXT .addr 0 ; IRQ entry is unused ; ------------------------------------------------------------------------ .bss ; Absolute variables used in the code ERROR: .res 1 ; Error code ; Line routine stuff (combined with circle routine stuff to save space) OGora: COUNT: .res 2 OUkos: NY: .res 2 Y3: DX: .res 1 DY: .res 1 AX: .res 1 AY: .res 1 ; ------------------------------------------------------------------------ .rodata ; Constants and tables DEFPALETTE: .byte $00, $01, $02, $03, $04, $05, $06, $07 .byte $08, $09, $0A, $0B, $0C, $0D, $0E, $0F ; ------------------------------------------------------------------------ .code ; INIT: Changes an already installed device from text mode to graphics mode. ; Note that INIT/DONE may be called multiple times while the driver ; is loaded, while INSTALL is only called once, so any code that is needed ; to initializes variables and so on must go here. Setting palette and ; clearing the screen is not needed because this is called by the graphics ; kernel later. ; The graphics kernel will never call INIT when a graphics mode is already ; active, so there is no need to protect against that. ; Must set an error code: YES INIT: ; Switch into graphics mode bit $C082 ; Switch in ROM jsr SETGR bit MIXCLR bit $C080 ; Switch in LC bank 2 for R/O ; Done, reset the error code lda #TGI_ERR_OK sta ERROR ; Fall through ; INSTALL routine. Is called after the driver is loaded into memory. May ; initialize anything that has to be done just once. Is probably empty ; most of the time. ; Must set an error code: NO INSTALL: ; Fall through ; UNINSTALL routine. Is called before the driver is removed from memory. May ; clean up anything done by INSTALL but is probably empty most of the time. ; Must set an error code: NO UNINSTALL: ; Fall through ; SETVIEWPAGE: Set the visible page. Called with the new page in A (0..n). ; The page number is already checked to be valid by the graphics kernel. ; Must set an error code: NO (will only be called if page ok) SETVIEWPAGE: ; Fall through ; SETDRAWPAGE: Set the drawable page. Called with the new page in A (0..n). ; The page number is already checked to be valid by the graphics kernel. ; Must set an error code: NO (will only be called if page ok) SETDRAWPAGE: ; Fall through ; TEXTSTYLE: Set the style used when calling OUTTEXT. Text scaling in X and Y ; direction is passend in X/Y, the text direction is passed in A. ; Must set an error code: NO TEXTSTYLE: ; Fall through ; OUTTEXT: Output text at X/Y = ptr1/ptr2 using the current color and the ; current text style. The text to output is given as a zero terminated ; string with address in ptr3. ; Must set an error code: NO OUTTEXT: rts ; DONE: Will be called to switch the graphics device back into text mode. ; The graphics kernel will never call DONE when no graphics mode is active, ; so there is no need to protect against that. ; Must set an error code: NO DONE: bit $C082 ; Switch in ROM jsr TEXT jsr HOME bit $C080 ; Switch in LC bank 2 for R/O rts ; GETERROR: Return the error code in A and clear it. GETERROR: lda ERROR ldx #TGI_ERR_OK stx ERROR rts ; CLEAR: Clears the screen. ; Must set an error code: NO CLEAR: bit $C082 ; Switch in ROM jsr CLRSCR bit $C080 ; Switch in LC bank 2 for R/O rts ; SETCOLOR: Set the drawing color (in A). The new color is already checked ; to be in a valid range (0..maxcolor-1). ; Must set an error code: NO (will only be called if color ok) SETCOLOR: bit $C082 ; Switch in ROM jsr SETCOL bit $C080 ; Switch in LC bank 2 for R/O rts ; CONTROL: Platform/driver specific entry point. ; Must set an error code: YES CONTROL: ; Fall through ; SETPALETTE: Set the palette (not available with all drivers/hardware). ; A pointer to the palette is passed in ptr1. Must set an error if palettes ; are not supported ; Must set an error code: YES SETPALETTE: lda #TGI_ERR_INV_FUNC sta ERROR rts ; GETPALETTE: Return the current palette in A/X. Even drivers that cannot ; set the palette should return the default palette here, so there's no ; way for this function to fail. ; Must set an error code: NO GETPALETTE: ; Fall through ; GETDEFPALETTE: Return the default palette for the driver in A/X. All ; drivers should return something reasonable here, even drivers that don't ; support palettes, otherwise the caller has no way to determine the colors ; of the (not changeable) palette. ; Must set an error code: NO (all drivers must have a default palette) GETDEFPALETTE: lda #<DEFPALETTE ldx #>DEFPALETTE rts ; SETPIXEL: Draw one pixel at X1/Y1 = ptr1/ptr2 with the current drawing ; color. The coordinates passed to this function are never outside the ; visible screen area, so there is no need for clipping inside this function. ; Must set an error code: NO SETPIXEL: bit $C082 ; Switch in ROM ldy X1 lda Y1 jsr PLOT bit $C080 ; Switch in LC bank 2 for R/O rts SETPIXELCLIP: lda Y1+1 bmi :+ ; y < 0 lda X1+1 bmi :+ ; x < 0 lda X1 ldx X1+1 sta ADDR stx ADDR+1 ldx #ADDR lda xres ldy xres+1 jsr icmp ; ( x < xres ) ... bcs :+ lda Y1 ldx Y1+1 sta ADDR stx ADDR+1 ldx #ADDR lda yres ldy yres+1 jsr icmp ; ... && ( y < yres ) bcc SETPIXEL : rts ; GETPIXEL: Read the color value of a pixel and return it in A/X. The ; coordinates passed to this function are never outside the visible screen ; area, so there is no need for clipping inside this function. GETPIXEL: bit $C082 ; Switch in ROM ldy X1 lda Y1 jsr SCRN ldx #$00 bit $C080 ; Switch in LC bank 2 for R/O rts ; LINE: Draw a line from X1/Y1 to X2/Y2, where X1/Y1 = ptr1/ptr2 and ; X2/Y2 = ptr3/ptr4 using the current drawing color. ; Must set an error code: NO LINE: ; nx = abs (x2 - x1) lda X2 sub X1 sta NX lda X2+1 sbc X1+1 tay lda NX jsr abs sta NX sty NX+1 ; ny = abs (y2 - y1) lda Y2 sub Y1 sta NY lda Y2+1 sbc Y1+1 tay lda NY jsr abs sta NY sty NY+1 ; if (x2 >= x1) ldx #X2 lda X1 ldy X1+1 jsr icmp bcc :+ ; dx = 1 lda #$01 bne :++ ; else ; dx = -1 : lda #$FF : sta DX ; if (y2 >= y1) ldx #Y2 lda Y1 ldy Y1+1 jsr icmp bcc :+ ; dy = 1 lda #$01 bne :++ ; else ; dy = -1 : lda #$FF : sta DY ; err = ax = ay = 0 lda #$00 sta ERR sta ERR+1 sta AX sta AY ; if (nx < ny) { ldx #NX lda NY ldy NY+1 jsr icmp bcs :+ ; nx <-> ny lda NX ldx NY sta NY stx NX lda NX+1 ldx NY+1 sta NY+1 stx NX+1 ; ax = dx lda DX sta AX ; ay = dy lda DY sta AY ; dx = dy = 0 } lda #$00 sta DX sta DY ; ny = - ny : lda NY ldy NY+1 jsr neg sta NY sty NY+1 ; for (count = nx; count > 0; --count) { lda NX ldx NX+1 sta COUNT stx COUNT+1 for: lda COUNT ; count > 0 ora COUNT+1 bne :+ rts ; setpixel (X1, Y1) : jsr SETPIXELCLIP ; pb = err + ny lda ERR add NY sta PB lda ERR+1 adc NY+1 sta PB+1 tax ; ub = pb + nx lda PB add NX sta UB txa adc NX+1 sta UB+1 ; x1 = x1 + dx ldx #$00 lda DX bpl :+ dex : add X1 sta X1 txa adc X1+1 sta X1+1 ; y1 = y1 + ay ldx #$00 lda AY bpl :+ dex : add Y1 sta Y1 txa adc Y1+1 sta Y1+1 ; if (abs (pb) < abs (ub)) { lda PB ldy PB+1 jsr abs sta TEMP3 sty TEMP4 lda UB ldy UB+1 jsr abs ldx #TEMP3 jsr icmp bpl :+ ; err = pb } lda PB ldx PB+1 jmp next ; else { x1 = x1 + ax : ldx #$00 lda AX bpl :+ dex : add X1 sta X1 txa adc X1+1 sta X1+1 ; y1 = y1 + dy ldx #$00 lda DY bpl :+ dex : add Y1 sta Y1 txa adc Y1+1 sta Y1+1 ; err = ub } lda UB ldx UB+1 next: sta ERR stx ERR+1 ; } (--count) lda COUNT sub #$01 sta COUNT bcc :+ jmp for : dec COUNT+1 jmp for ; BAR: Draw a filled rectangle with the corners X1/Y1, X2/Y2, where ; X1/Y1 = ptr1/ptr2 and X2/Y2 = ptr3/ptr4 using the current drawing color. ; Contrary to most other functions, the graphics kernel will sort and clip ; the coordinates before calling the driver, so on entry the following ; conditions are valid: ; X1 <= X2 ; Y1 <= Y2 ; (X1 >= 0) && (X1 < XRES) ; (X2 >= 0) && (X2 < XRES) ; (Y1 >= 0) && (Y1 < YRES) ; (Y2 >= 0) && (Y2 < YRES) ; Must set an error code: NO BAR: bit $C082 ; Switch in ROM inc Y2 ldx X2 stx H2 : ldy X1 lda Y1 jsr HLINE inc Y1 lda Y2 cmp Y1 bne :- bit $C080 ; Switch in LC bank 2 for R/O rts ; CIRCLE: Draw a circle around the center X1/Y1 (= ptr1/ptr2) with the ; radius in tmp1 and the current drawing color. ; Must set an error code: NO CIRCLE: lda RADIUS bne :+ jmp SETPIXELCLIP ; Plot as a point : sta XX ; x = r lda #$00 sta XX+1 sta YY sta YY+1 sta MaxO sta MaxO+1 ; y = 0, mo = 0 lda X1 ldx X1+1 sta XS stx XS+1 lda Y1 ldx Y1+1 sta YS stx YS+1 ; XS/YS to remember the center ; while (y < x) { while: ldx #YY lda XX ldy XX+1 jsr icmp bcc :+ rts ; Plot points in 8 slices... : lda XS add XX sta X1 lda XS+1 adc XX+1 sta X1+1 ; x1 = xs + x lda YS add YY sta Y1 pha lda YS+1 adc YY+1 sta Y1+1 ; (stack) = ys + y, y1 = (stack) pha jsr SETPIXELCLIP ; plot (xs + x, ys + y) lda YS sub YY sta Y1 sta Y3 lda YS+1 sbc YY+1 sta Y1+1 ; y3 = y1 = ys - y sta Y3+1 jsr SETPIXELCLIP ; plot (xs + x, ys - y) pla sta Y1+1 pla sta Y1 ; y1 = ys + y lda XS sub XX sta X1 lda XS+1 sbc XX+1 sta X1+1 jsr SETPIXELCLIP ; plot (xs - x, ys + y) lda Y3 sta Y1 lda Y3+1 sta Y1+1 jsr SETPIXELCLIP ; plot (xs - x, ys - y) lda XS add YY sta X1 lda XS+1 adc YY+1 sta X1+1 ; x1 = xs + y lda YS add XX sta Y1 pha lda YS+1 adc XX+1 sta Y1+1 ; (stack) = ys + x, y1 = (stack) pha jsr SETPIXELCLIP ; plot (xs + y, ys + x) lda YS sub XX sta Y1 sta Y3 lda YS+1 sbc XX+1 sta Y1+1 ; y3 = y1 = ys - x sta Y3+1 jsr SETPIXELCLIP ; plot (xs + y, ys - x) pla sta Y1+1 pla sta Y1 ; y1 = ys + x(stack) lda XS sub YY sta X1 lda XS+1 sbc YY+1 sta X1+1 jsr SETPIXELCLIP ; plot (xs - y, ys + x) lda Y3 sta Y1 lda Y3+1 sta Y1+1 jsr SETPIXELCLIP ; plot (xs - y, ys - x) ; og = mo + y + y + 1 lda MaxO ldx MaxO+1 add YY tay txa adc YY+1 tax tya add YY tay txa adc YY+1 tax tya add #$01 bcc :+ inx : sta OGora stx OGora+1 ; ou = og - x - x + 1 sub XX tay txa sbc XX+1 tax tya sub XX tay txa sbc XX+1 tax tya add #$01 bcc :+ inx : sta OUkos stx OUkos+1 ; ++y inc YY bne :+ inc YY+1 ; if (abs (ou) < abs (og)) { : lda OUkos ldy OUkos+1 jsr abs sta TEMP3 sty TEMP4 lda OGora ldy OGora+1 jsr abs ldx #TEMP3 jsr icmp bpl :++ ; --x lda XX sub #$01 sta XX bcs :+ dec XX+1 ; mo = ou } : lda OUkos ldx OUkos+1 jmp :++ ; else mo = og : lda OGora ldx OGora+1 : sta MaxO stx MaxO+1 ; } jmp while ; Copies of some runtime routines abs: ; A/Y := abs (A/Y) cpy #$00 bpl :+ ; A/Y := neg (A/Y) neg: clc eor #$FF adc #$01 pha tya eor #$FF adc #$00 tay pla : rts icmp: ; Compare A/Y to zp,X sta TEMP ; TEMP/TEMP2 - arg2 sty TEMP2 lda $00,x pha lda $01,x tay pla tax tya ; X/A - arg1 (a = high) sub TEMP2 bne :++ cpx TEMP beq :+ adc #$FF ora #$01 : rts : bvc :+ eor #$FF ora #$01 : rts
wagiminator/C64-Collection
4,413
C64_xu1541/software/tools/cc65-2.13.2/libsrc/apple2/apple2-auxmem.s
; ; Extended memory driver for the Apple II auxiliary memory ; ; Stefan Haubenthal, 2003-12-12 ; Ullrich von Bassewitz, 2002-12-02 ; .include "zeropage.inc" .include "em-kernel.inc" .include "em-error.inc" .macpack generic ; ------------------------------------------------------------------------ ; Header. Includes jump table .segment "JUMPTABLE" ; Driver signature .byte $65, $6d, $64 ; "emd" .byte EMD_API_VERSION ; EM API version number ; Jump table. .word INSTALL .word DEINSTALL .word PAGECOUNT .word MAP .word USE .word COMMIT .word COPYFROM .word COPYTO ; ------------------------------------------------------------------------ ; Constants BASE = $0200 AUXCARD = $C30C ; Card signature AUXMOVE = $C311 ; Auxiliary move routine PAGES = ($C000 - BASE) / 256 ; ------------------------------------------------------------------------ ; Data. .data curpage: .byte $FF ; Current page number (invalid) .bss 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: ldx #0 lda AUXCARD and #$f0 cmp #$80 bne @L1 lda #EM_ERR_OK rts @L1: lda #EM_ERR_NO_DEVICE ; rts ; ------------------------------------------------------------------------ ; DEINSTALL routine. Is called before the driver is removed from memory. ; Can do cleanup or whatever. Must not return anything. ; DEINSTALL: rts ; ------------------------------------------------------------------------ ; PAGECOUNT: Return the total number of available pages in a/x. ; PAGECOUNT: lda #<PAGES ldx #>PAGES 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 add #>BASE sta ptr1+1 ldy #$00 sty ptr1 lda #<window sta ptr2 lda #>window sta ptr2+1 ; Transfer one page clc ; Direction flag jsr transfer ; Transfer one page ; Return the memory window lda #<window ldx #>window ; Return the window address ; Done done: rts ; ------------------------------------------------------------------------ ; USE: Tell the driver that the window is now associated with a given page. USE: sta curpage ; Remember the page 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 cmp #$FF beq done ; Jump if no page mapped add #>BASE sta ptr2+1 ldy #$00 sty ptr2 lda #<window sta ptr1 lda #>window sta ptr1+1 lda #<$FF sta ptr4 lda #>$FF sta ptr4+1 sec ; Direction flag ; Transfer one page/all bytes transfer: php lda ptr1 sta $3C add ptr4 sta $3E lda ptr1+1 sta $3D adc ptr4+1 sta $3F lda ptr2 sta $42 lda ptr2+1 sta $43 plp jmp AUXMOVE ; ------------------------------------------------------------------------ ; COPYFROM: Copy from extended into linear memory. A pointer to a structure ; describing the request is passed in a/x. ; The function must not return anything. ; COPYFROM: sta ptr3 stx ptr3+1 ; Save the passed em_copy pointer ldy #EM_COPY::OFFS lda (ptr3),y sta ptr1 ldy #EM_COPY::PAGE lda (ptr3),y add #>BASE sta ptr1+1 ; From ldy #EM_COPY::BUF lda (ptr3),y sta ptr2 iny lda (ptr3),y sta ptr2+1 ; To clc ; Direction flag common: ldy #EM_COPY::COUNT lda (ptr3),y ; Get bytes in last page sta ptr4 iny lda (ptr3),y ; Get number of pages sta ptr4+1 jmp transfer ; ------------------------------------------------------------------------ ; COPYTO: Copy from linear into extended memory. A pointer to a structure ; describing the request is passed in a/x. ; The function must not return anything. ; COPYTO: sta ptr3 stx ptr3+1 ; Save the passed em_copy pointer ldy #EM_COPY::OFFS lda (ptr3),y sta ptr2 ldy #EM_COPY::PAGE lda (ptr3),y add #>BASE sta ptr2+1 ; To ldy #EM_COPY::BUF lda (ptr3),y sta ptr1 iny lda (ptr3),y sta ptr1+1 ; From sec ; Direction flag jmp common
wagiminator/C64-Collection
2,059
C64_xu1541/software/tools/cc65-2.13.2/libsrc/apple2/read.s
; ; Oliver Schmidt, 12.01.2005 ; ; int __fastcall__ read (int fd, void* buf, unsigned count); ; .constructor initprompt .export _read .import rwprolog, rwcommon .import errnoexit .import RDKEY, COUT .include "zeropage.inc" .include "errno.inc" .include "fcntl.inc" .include "mli.inc" .include "filedes.inc" .include "apple2.inc" .segment "INIT" initprompt: ; Set prompt <> ']' to let DOS 3.3 know that we're ; not in Applesoft immediate mode and thus keep it ; from scanning our device I/O for DOS commands. lda #$80 ; Same value used at $D52C sta PROMPT rts .code _read: ; Get parameters jsr rwprolog bcs errno tax ; Save fd ; Check for read access lda fdtab + FD::FLAGS,y and #O_RDONLY beq einval ; Check for device txa ; Restore fd bmi device ; Do read ldy #READ_CALL jmp rwcommon ; Set counter to zero device: lda #$00 sta ptr3 sta ptr3+1 ; Check for zero count lda ptr2 ora ptr2+1 beq check ; Read from device and echo to device next: jsr RDKEY jsr COUT ; Clear hi bit and check for '\r' and #$7F cmp #$0D bne :+ ; Replace with '\n' and set count to zero lda #$0A ldy #$00 sty ptr2 sty ptr2+1 ; Put char into buf : ldy #$00 sta (ptr1),y ; Increment pointer inc ptr1 bne :+ inc ptr1+1 ; Increment counter : inc ptr3 bne check inc ptr3+1 ; Check for counter less than count check: lda ptr3 cmp ptr2 bcc next ldx ptr3+1 cpx ptr2+1 bcc next ; Return success, AX already set rts ; Load errno code einval: lda #EINVAL ; Return errno errno: jmp errnoexit
wagiminator/C64-Collection
1,682
C64_xu1541/software/tools/cc65-2.13.2/libsrc/apple2/break.s
; ; Ullrich von Bassewitz, 27.09.1998 ; ; void set_brk (unsigned Addr); ; void reset_brk (void); ; .export _set_brk, _reset_brk .destructor _reset_brk ; Be sure to export the following variables absolute .export _brk_a: abs, _brk_x: abs, _brk_y: abs .export _brk_sr: abs, _brk_pc: abs .include "apple2.inc" _brk_a = $45 _brk_x = $46 _brk_y = $47 _brk_sr = $48 _brk_sp = $49 _brk_pc = $3A .bss oldvec: .res 2 ; Old vector .data uservec: jmp $FFFF ; Patched at runtime .code ; Set the break vector .proc _set_brk sta uservec+1 stx uservec+2 ; Set the user vector lda oldvec ora oldvec+1 ; Did we save the vector already? bne L1 ; Jump if we installed the handler already lda BRKVec sta oldvec lda BRKVec+1 sta oldvec+1 ; Save the old vector L1: lda #<brk_handler ; Set the break vector to our routine ldx #>brk_handler sta BRKVec stx BRKVec+1 rts .endproc ; Reset the break vector .proc _reset_brk lda oldvec ldx oldvec+1 beq @L9 ; Jump if vector not installed sta BRKVec stx BRKVec+1 lda #$00 sta oldvec ; Clear the old vector stx oldvec+1 @L9: rts .endproc ; Break handler, called if a break occurs .proc brk_handler sec lda _brk_pc sbc #$02 ; Point to start of brk sta _brk_pc lda _brk_pc+1 sbc #$00 sta _brk_pc+1 clc lda _brk_sp adc #$04 ; Adjust stack pointer sta _brk_sp lda _brk_sr ; Clear brk and #$EF sta _brk_sr jsr uservec ; Call the user's routine lda _brk_pc+1 pha lda _brk_pc pha lda _brk_sr pha ldx _brk_x ldy _brk_y lda _brk_a rti ; Jump back... .endproc
wagiminator/C64-Collection
1,103
C64_xu1541/software/tools/cc65-2.13.2/libsrc/apple2/dosdetect.s
; ; Oliver Schmidt, 08.03.2004 ; ; Identify DOS version we're running on as one of these: ; ; AppleDOS 3.3 - $00 ; ProDOS 8 1.0.1 - $10 ; ProDOS 8 1.0.2 - $10 ; ProDOS 8 1.1.1 - $11 ; ProDOS 8 1.2 - $12 ; ProDOS 8 1.3 - $13 ; ProDOS 8 1.4 - $14 ; ProDOS 8 1.5 - $15 ; ProDOS 8 1.6 - $16 ; ProDOS 8 1.7 - $17 ; ProDOS 8 1.8 - $18 ; ProDOS 8 1.9 - $18 ; ProDOS 8 2.0.1 - $21 ; ProDOS 8 2.0.2 - $22 ; ProDOS 8 2.0.3 - $23 ; .constructor initdostype, 19 .export __dos_type .include "mli.inc" ; Identify DOS version according to: ; - Beneath Apple ProDOS, chapter 6-63 ; - Apple II ProDOS 8 TechNote #23, ProDOS 8 Changes and Minutia ; - ProDOS TechRefMan, chapter 5.2.4 .segment "INIT" initdostype: lda $BF00 cmp #$4C ; Is MLI present? (JMP opcode) bne done lda KVERSION ; ProDOS 8 kernel version cmp #$10 bcs :+ ora #$10 ; Make high nibble match major version : sta __dos_type done: rts .bss __dos_type: .res 1
wagiminator/C64-Collection
10,149
C64_xu1541/software/tools/cc65-2.13.2/libsrc/apple2/apple2-ssc.s
; ; Serial driver for the Apple II Super Serial Card. ; ; Oliver Schmidt, 21.04.2005 ; ; The driver is based on the cc65 rs232 module, which in turn is based on ; Craig Bruce device driver for the Switftlink/Turbo-232. ; ; SwiftLink/Turbo-232 v0.90 device driver, by Craig Bruce, 14-Apr-1998. ; ; This software is Public Domain. It is in Buddy assembler format. ; ; This device driver uses the SwiftLink RS-232 Serial Cartridge, available from ; Creative Micro Designs, Inc, and also supports the extensions of the Turbo232 ; Serial Cartridge. Both devices are based on the 6551 ACIA chip. It also ; supports the "hacked" SwiftLink with a 1.8432 MHz crystal. ; ; The code assumes that the kernal + I/O are in context. On the C128, call ; it from Bank 15. On the C64, don't flip out the Kernal unless a suitable ; NMI catcher is put into the RAM under then Kernal. For the SuperCPU, the ; interrupt handling assumes that the 65816 is in 6502-emulation mode. ; .include "zeropage.inc" .include "ser-kernel.inc" .include "ser-error.inc" ; ------------------------------------------------------------------------ ; Header. Includes jump table .segment "JUMPTABLE" ; Driver signature .byte $73, $65, $72 ; "ser" .byte SER_API_VERSION ; Serial API version number ; Jump table. .addr INSTALL .addr UNINSTALL .addr OPEN .addr CLOSE .addr GET .addr PUT .addr STATUS .addr IOCTL .addr IRQ ;---------------------------------------------------------------------------- ; I/O definitions ACIA = $C088 ACIA_DATA = ACIA+0 ; Data register ACIA_STATUS = ACIA+1 ; Status register ACIA_CMD = ACIA+2 ; Command register ACIA_CTRL = ACIA+3 ; Control register ;---------------------------------------------------------------------------- ; Global variables .bss RecvHead: .res 1 ; Head of receive buffer RecvTail: .res 1 ; Tail of receive buffer RecvFreeCnt: .res 1 ; Number of bytes in receive buffer SendHead: .res 1 ; Head of send buffer SendTail: .res 1 ; Tail of send buffer SendFreeCnt: .res 1 ; Number of bytes in send buffer Stopped: .res 1 ; Flow-stopped flag RtsOff: .res 1 ; RecvBuf: .res 256 ; Receive buffers: 256 bytes SendBuf: .res 256 ; Send buffers: 256 bytes Index: .res 1 ; I/O register index .data Slot: .byte $02 ; Default to SSC in slot 2 .rodata ; Tables used to translate RS232 params into register values BaudTable: ; bit7 = 1 means setting is invalid .byte $FF ; SER_BAUD_45_5 .byte $01 ; SER_BAUD_50 .byte $02 ; SER_BAUD_75 .byte $03 ; SER_BAUD_110 .byte $04 ; SER_BAUD_134_5 .byte $05 ; SER_BAUD_150 .byte $06 ; SER_BAUD_300 .byte $07 ; SER_BAUD_600 .byte $08 ; SER_BAUD_1200 .byte $09 ; SER_BAUD_1800 .byte $0A ; SER_BAUD_2400 .byte $0B ; SER_BAUD_3600 .byte $0C ; SER_BAUD_4800 .byte $0D ; SER_BAUD_7200 .byte $0E ; SER_BAUD_9600 .byte $0F ; SER_BAUD_19200 .byte $FF ; SER_BAUD_38400 .byte $FF ; SER_BAUD_57600 .byte $FF ; SER_BAUD_115200 .byte $FF ; SER_BAUD_230400 BitTable: .byte $60 ; SER_BITS_5 .byte $40 ; SER_BITS_6 .byte $20 ; SER_BITS_7 .byte $00 ; SER_BITS_8 StopTable: .byte $00 ; SER_STOP_1 .byte $80 ; SER_STOP_2 ParityTable: .byte $00 ; SER_PAR_NONE .byte $20 ; SER_PAR_ODD .byte $60 ; SER_PAR_EVEN .byte $A0 ; SER_PAR_MARK .byte $E0 ; SER_PAR_SPACE IdOfsTable: .byte $05 ; Pascal 1.0 ID byte .byte $07 ; Pascal 1.0 ID byte .byte $0B ; Pascal 1.1 generic signature byte .byte $0C ; Device signature byte IdValTable: .byte $38 ; Fixed .byte $18 ; Fixed .byte $01 ; Fixed .byte $31 ; Serial or parallel I/O card type 1 IdTableLen = * - IdValTable .code ;---------------------------------------------------------------------------- ; INSTALL: Is called after the driver is loaded into memory. If possible, ; check if the hardware is present. Must return an SER_ERR_xx code in a/x. ; ; Since we don't have to manage the IRQ vector on the Apple II, this is ; actually the same as: ; ; UNINSTALL: Is called before the driver is removed from memory. ; No return code required (the driver is removed from memory on return). ; ; and: ; ; CLOSE: Close the port and disable interrupts. Called without parameters. ; Must return an SER_ERR_xx code in a/x. INSTALL: UNINSTALL: CLOSE: ldx Index ; Check for open port beq :+ ; Deactivate DTR and disable 6551 interrupts lda #%00001010 sta ACIA_CMD,x ; Done, return an error code : lda #<SER_ERR_OK tax ; A is zero stx Index ; Mark port as closed rts ;---------------------------------------------------------------------------- ; OPEN: A pointer to a ser_params structure is passed in ptr1. ; Must return an SER_ERR_xx code in a/x. OPEN: ldx #<$C000 stx ptr2 lda #>$C000 ora Slot sta ptr2+1 ; Check Pascal 1.1 Firmware Protocol ID bytes : ldy IdOfsTable,x lda IdValTable,x cmp (ptr2),y bne NoDevice inx cpx #IdTableLen bcc :- ; Convert slot to I/O register index lda Slot asl asl asl asl tax ; Check if the handshake setting is valid ldy #SER_PARAMS::HANDSHAKE ; Handshake lda (ptr1),y cmp #SER_HS_HW ; This is all we support bne InvParam ; Initialize buffers ldy #$00 sty Stopped sty RecvHead sty RecvTail sty SendHead sty SendTail dey ; Y = 255 sty RecvFreeCnt sty SendFreeCnt ; Set the value for the control register, which contains stop bits, ; word length and the baud rate. ldy #SER_PARAMS::BAUDRATE lda (ptr1),y ; Baudrate index tay lda BaudTable,y ; Get 6551 value bmi InvBaud ; Branch if rate not supported sta tmp1 ldy #SER_PARAMS::DATABITS ; Databits lda (ptr1),y tay lda BitTable,y ora tmp1 sta tmp1 ldy #SER_PARAMS::STOPBITS ; Stopbits lda (ptr1),y tay lda StopTable,y ora tmp1 ora #%00010000 ; Receiver clock source = baudrate sta ACIA_CTRL,x ; Set the value for the command register. We remember the base value ; in RtsOff, since we will have to manipulate ACIA_CMD often. ldy #SER_PARAMS::PARITY ; Parity lda (ptr1),y tay lda ParityTable,y ora #%00000001 ; DTR active sta RtsOff ora #%00001000 ; Enable receive interrupts sta ACIA_CMD,x ; Done stx Index ; Mark port as open lda #<SER_ERR_OK tax ; A is zero rts ; Device (hardware) not found NoDevice:lda #<SER_ERR_NO_DEVICE ldx #>SER_ERR_NO_DEVICE rts ; Invalid parameter InvParam:lda #<SER_ERR_INIT_FAILED ldx #>SER_ERR_INIT_FAILED rts ; Baud rate not available InvBaud:lda #<SER_ERR_BAUD_UNAVAIL ldx #>SER_ERR_BAUD_UNAVAIL rts ;---------------------------------------------------------------------------- ; GET: Will fetch a character from the receive buffer and store it into the ; variable pointed to by ptr1. If no data is available, SER_ERR_NO_DATA is ; returned. GET: ldx Index ldy SendFreeCnt ; Send data if necessary iny ; Y == $FF? beq :+ lda #$00 ; TryHard = false jsr TryToSend ; Check for buffer empty : lda RecvFreeCnt ; (25) cmp #$FF bne :+ lda #<SER_ERR_NO_DATA ldx #>SER_ERR_NO_DATA rts ; Check for flow stopped & enough free: release flow control : ldy Stopped ; (34) beq :+ cmp #63 bcc :+ lda #$00 sta Stopped lda RtsOff ora #%00001000 sta ACIA_CMD,x ; Get byte from buffer : ldy RecvHead ; (41) lda RecvBuf,y inc RecvHead inc RecvFreeCnt ldx #$00 ; (59) sta (ptr1,x) txa ; Return code = 0 rts ;---------------------------------------------------------------------------- ; PUT: Output character in A. ; Must return an SER_ERR_xx code in a/x. PUT: ldx Index ; Try to send ldy SendFreeCnt iny ; Y = $FF? beq :+ pha lda #$00 ; TryHard = false jsr TryToSend pla ; Put byte into send buffer & send : ldy SendFreeCnt bne :+ lda #<SER_ERR_OVERFLOW ldx #>SER_ERR_OVERFLOW rts : ldy SendTail sta SendBuf,y inc SendTail dec SendFreeCnt lda #$FF ; TryHard = true jsr TryToSend lda #<SER_ERR_OK tax rts ;---------------------------------------------------------------------------- ; STATUS: Return the status in the variable pointed to by ptr1. ; Must return an SER_ERR_xx code in a/x. STATUS: ldx Index lda ACIA_STATUS,x ldx #$00 sta (ptr1,x) txa ; SER_ERR_OK rts ;---------------------------------------------------------------------------- ; IOCTL: Driver defined entry point. The wrapper will pass a pointer to ioctl ; specific data in ptr1, and the ioctl code in A. ; Must return an SER_ERR_xx code in a/x. IOCTL: ; Check code to be 0 tax bne :+ ; Check data to be [1..7] lda (ptr1,x) beq :+ cmp #7+1 bcs :+ sta Slot txa ; SER_ERR_OK rts : lda #<SER_ERR_INV_IOCTL ldx #>SER_ERR_INV_IOCTL rts ;---------------------------------------------------------------------------- ; IRQ: Called from the builtin runtime IRQ handler as a subroutine. All ; registers are already saved, no parameters are passed, but the carry flag ; is clear on entry. The routine must return with carry set if the interrupt ; was handled, otherwise with carry clear. IRQ: ldx Index ; Check for open port beq Done lda ACIA_STATUS,x ; Check ACIA status for receive interrupt and #$08 beq Done ; Jump if no ACIA interrupt lda ACIA_DATA,x ; Get byte from ACIA ldy RecvFreeCnt ; Check if we have free space left beq Flow ; Jump if no space in receive buffer ldy RecvTail ; Load buffer pointer sta RecvBuf,y ; Store received byte in buffer inc RecvTail ; Increment buffer pointer dec RecvFreeCnt ; Decrement free space counter ldy RecvFreeCnt ; Check for buffer space low cpy #33 bcc Flow ; Assert flow control if buffer space low rts ; Interrupt handled (carry already set) ; Assert flow control if buffer space too low Flow: lda RtsOff sta ACIA_CMD,x sta Stopped sec ; Interrupt handled Done: rts ;---------------------------------------------------------------------------- ; Try to send a byte. Internal routine. A = TryHard TryToSend: sta tmp1 ; Remember tryHard flag Again: lda SendFreeCnt cmp #$FF beq Quit ; Bail out ; Check for flow stopped lda Stopped bne Quit ; Bail out ; Check that ACIA is ready to send lda ACIA_STATUS,x and #$10 bne Send bit tmp1 ; Keep trying if must try hard bmi Again Quit: rts ; Send byte and try again Send: ldy SendHead lda SendBuf,y sta ACIA_DATA,x inc SendHead inc SendFreeCnt jmp Again
wagiminator/C64-Collection
1,187
C64_xu1541/software/tools/cc65-2.13.2/libsrc/apple2/dioopen.s
; ; Oliver Schmidt, 24.03.2005 ; ; dhandle_t __fastcall__ dio_open (driveid_t drive_id); ; ; drive_id = (slot * 2) + (drive - 1) .export _dio_open .import return0 .include "zeropage.inc" .include "errno.inc" .include "mli.inc" _dio_open: ; Convert drive id into unit number lsr bcc :+ ora #%00001000 : asl asl asl asl tay ; Save handle ; Set handle sta mliparam + MLI::ON_LINE::UNIT_NUM ; Alloc 16-byte buffer just below stack lda sp sec sbc #16 sta mliparam + MLI::ON_LINE::DATA_BUFFER lda sp+1 sbc #$00 sta mliparam + MLI::ON_LINE::DATA_BUFFER+1 ; Get device state lda #ON_LINE_CALL ldx #ON_LINE_COUNT jsr callmli bcc :+ ; DIO level access doesn't necessarily need a ; ProDOS 8 disk so ignore "high level" errors cmp #$40 bcc oserr ; Return success : tya ; Restore handle ldx #$00 stx __oserror rts ; Return oserror oserr: sta __oserror jmp return0
wagiminator/C64-Collection
1,185
C64_xu1541/software/tools/cc65-2.13.2/libsrc/apple2/filedes.s
; ; Oliver Schmidt, 30.12.2004 ; ; File descriptor management for the POSIX I/O routines ; .include "errno.inc" .include "fcntl.inc" .include "filedes.inc" getfd: ; Check for handle >= 256 cpx #$00 bne error ; Check for handle >= MAX_FDS cmp #MAX_FDS bcs error ; Convert handle to fdtab slot .assert .sizeof(FD) = 4, error asl asl ; Check for fdtab slot in use tay lda fdtab + FD::REF_NUM,y beq error ; Return success clc rts ; Load errno code and return error error: lda #EINVAL sec rts .data fdtab: .assert .sizeof(FD) = 4, error .byte $80 ; STDIN_FILENO ::REF_NUM .byte O_RDONLY ; STDIN_FILENO ::FLAGS .addr $0000 ; STDIN_FILENO ::BUFFER .byte $80 ; STDOUT_FILENO::REF_NUM .byte O_WRONLY ; STDOUT_FILENO::FLAGS .addr $0000 ; STDOUT_FILENO::BUFFER .byte $80 ; STDERR_FILENO::REF_NUM .byte O_WRONLY ; STDERR_FILENO::FLAGS .addr $0000 ; STDERR_FILENO::BUFFER .res (MAX_FDS - 3) * .sizeof(FD)
wagiminator/C64-Collection
3,371
C64_xu1541/software/tools/cc65-2.13.2/libsrc/apple2/apple2-stdjoy.s
; ; Standard joystick driver for the Apple ][. May be used multiple times ; when statically linked to the application. ; ; Ullrich von Bassewitz, 2003-05-02 ; Oliver Schmidt, 2008-02-25 ; Using the readjoy code from Stefan Haubenthal ; .include "zeropage.inc" .include "joy-kernel.inc" .include "joy-error.inc" .include "apple2.inc" .macpack generic ; ------------------------------------------------------------------------ ; Constants THRESHOLD = 20 ; Deviation from center triggering movement ; ------------------------------------------------------------------------ ; ROM entry points PREAD := $FB1E ; Read paddle in X, return AD conv. value in Y ; ------------------------------------------------------------------------ ; Header. Includes jump table. .segment "JUMPTABLE" ; Driver signature .byte $6A, $6F, $79 ; "joy" .byte JOY_API_VERSION ; Driver API version number ; 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 .addr UNINSTALL .addr COUNT .addr READJOY .addr 0 ; IRQ not used ; ------------------------------------------------------------------------ .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 ; Fall through ; 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 #$02 ; Number of joysticks we support ldx #$00 rts ; READ: Read a particular joystick passed in A. READJOY: bit $C082 ; Switch in ROM and #$01 ; Restrict joystick number ; Read horizontal paddle asl ; Joystick number -> paddle number tax ; Set paddle number (0, 2) jsr PREAD ; Read paddle value lda #$00 ; 0 0 0 0 0 0 0 0 cpy #127 - THRESHOLD ror ; !LEFT 0 0 0 0 0 0 0 cpy #127 + THRESHOLD ror ; RIGHT !LEFT 0 0 0 0 0 0 ; Read vertical paddle pha inx ; Set paddle number (1, 3) jsr PREAD ; Read paddle value pla cpy #127 - THRESHOLD ror ; !UP RIGHT !LEFT 0 0 0 0 0 cpy #127 + THRESHOLD ror ; DOWN !UP RIGHT !LEFT 0 0 0 0 ; Read primary button tay lda BUTN0-1,x ; Check button (1, 3) asl tya ror ; FIRE DOWN !UP RIGHT !LEFT 0 0 0 ; Read secondary button tay inx txa and #$03 ; IIgs has fourth button at TAPEIN tax lda BUTN0-1,x ; Check button (2, 0) asl tya ror ; FIRE2 FIRE DOWN !UP RIGHT !LEFT 0 0 ; Finalize eor #%00010100 ; FIRE2 FIRE DOWN UP RIGHT LEFT 0 0 ldx #$00 bit $C080 ; Switch in LC bank 2 for R/O rts
wagiminator/C64-Collection
2,846
C64_xu1541/software/tools/cc65-2.13.2/libsrc/apple2/oserrlist.s
; ; Stefan Haubenthal, 2003-12-24 ; Ullrich von Bassewitz, 18.07.2002 ; ; Defines the platform specific error list. ; ; The table is built as a list of entries ; ; .byte entrylen ; .byte errorcode ; .asciiz errormsg ; ; and terminated by an entry with length zero that is returned if the ; error code could not be found. ; .export __sys_oserrlist ;---------------------------------------------------------------------------- ; Macros used to generate the list (may get moved to an include file?) ; Regular entry .macro sys_oserr_entry code, msg .local Start, End Start: .byte End - Start .byte code .asciiz msg End: .endmacro ; Sentinel entry .macro sys_oserr_sentinel msg .byte 0 ; Length is always zero .byte 0 ; Code is unused .asciiz msg .endmacro ;---------------------------------------------------------------------------- ; The error message table .rodata __sys_oserrlist: sys_oserr_entry $01, "Invalid MLI function code number" sys_oserr_entry $04, "Incorrect parameter count" sys_oserr_entry $25, "Interrupt table full" sys_oserr_entry $27, "I/O error" sys_oserr_entry $28, "No device connected" sys_oserr_entry $2B, "Write protected" sys_oserr_entry $2E, "Disk switched" sys_oserr_entry $2F, "No disk in drive" sys_oserr_entry $40, "Invalid pathname syntax" sys_oserr_entry $42, "Too many files open" sys_oserr_entry $43, "Bad reference number" sys_oserr_entry $44, "Bad pathname" sys_oserr_entry $45, "Volume not mounted" sys_oserr_entry $46, "File not found" sys_oserr_entry $47, "File already exists" sys_oserr_entry $48, "Disk full" sys_oserr_entry $49, "Directory full" sys_oserr_entry $4A, "Incompatible ProDOS version" sys_oserr_entry $4B, "Unsupported storage type" sys_oserr_entry $4C, "End of file" sys_oserr_entry $4D, "Position past EOF" sys_oserr_entry $4E, "Access denied" sys_oserr_entry $50, "File already open" sys_oserr_entry $51, "File count bad" sys_oserr_entry $52, "Not a ProDOS disk" sys_oserr_entry $53, "Parameter out of range" sys_oserr_entry $55, "Too many devices mounted" sys_oserr_entry $56, "Bad buffer address" sys_oserr_entry $57, "Duplicate volume name" sys_oserr_entry $5A, "Damaged disk free space bit map" sys_oserr_sentinel "Unknown error"
wagiminator/C64-Collection
2,808
C64_xu1541/software/tools/cc65-2.13.2/libsrc/apple2/textframe.s
; ; Oliver Schmidt, 10.03.2004 ; ; void __fastcall__ textframexy (unsigned char x, unsigned char y, ; unsigned char width, unsigned char height, ; unsigned char style); ; void __fastcall__ textframe (unsigned char width, unsigned char height, ; unsigned char style); ; .export _textframexy, _textframe .import popa, pusha, _gotoxy .import chlinedirect, cvlinedirect .include "zeropage.inc" .include "apple2.inc" WIDTH = tmp2 HEIGHT = tmp3 XORIGIN = tmp4 YORIGIN = ptr1 _textframexy: sec bra :+ _textframe: clc : ldx INVFLG phx ; Save character display mode ldx #$FF stx INVFLG ; Set normal character display mode pha ; Save index jsr popa ; Get height sta HEIGHT jsr popa ; Get width sta WIDTH lda CH ldx CV bcc noxy jsr popa ; Get y tax jsr popa ; Get x noxy: sta XORIGIN stx YORIGIN plx ; Restore index loop: lda XOFFS,x clc bpl :+ ; Relative to left edge? adc WIDTH : adc XORIGIN jsr pusha lda YOFFS,x clc bpl :+ ; Relative to top? adc HEIGHT : adc YORIGIN jsr _gotoxy ; Call this one, will pop params txa tay lsr ; Get bit 0 (vline) into carry lda LENGTH,x phx ; Save index ldx CHAR,y bcc hline clc adc HEIGHT jsr cvlinedirect bra next hline: adc WIDTH jsr chlinedirect next: plx ; Restore index inx txa and #$03 ; Mask style bne loop pla sta INVFLG ; Restore character display mode rts .rodata ; 2 styles with 4 lines each make up 8 entries per table ; - even entry numbers mean horizontal lines ; - odd entry numbers mean vertical lines ; x offset for the line starting point ; - a positive value means relative to the frame left edge ; - a negative value menas relative to the frame right edge XOFFS: .byte 0, 0, 0, -2, 1, 0, 1, -2 ; y offset for the line starting point ; - a positive value means relative to the frame top ; - a negative value menas relative to the frame bottom YOFFS: .byte 0, 1, -2, 1, 0, 0, -2, 0 ; length of the line relative to the frame size ; - a negative value for hlines means shorter than the width ; - a negative value for vlines menas shorter than the height LENGTH: .byte 0, -2, 0, -2, -2, 0, -2, 0 ; character to use for drawing the line ; - hibit set means normal printable character ; - hibit clear means MouseText character CHAR: .byte '_'|$80, '_', 'L', 'Z', 'L', 'Z', '_'|$80, '_'
wagiminator/C64-Collection
20,167
C64_xu1541/software/tools/cc65-2.13.2/libsrc/apple2/apple2-280-192-8.s
; ; Graphics driver for the 280x192x8 mode on the Apple II ; ; Stefan Haubenthal <polluks@sdf.lonestar.org> ; Oliver Schmidt <ol.sc@web.de> ; Based on Maciej Witkowiak's circle routine ; .include "zeropage.inc" .include "tgi-kernel.inc" .include "tgi-mode.inc" .include "tgi-error.inc" .include "apple2.inc" .macpack generic ; ------------------------------------------------------------------------ ; Zero page stuff HBASL := $26 HMASK := $30 PAGE := $E6 SCALE := $E7 ROT := $F9 ; Graphics entry points, by cbmnut (applenut??) cbmnut@hushmail.com TEXT := $F399 ; Return to text screen HGR2 := $F3D8 ; Initialize and clear hi-res page 2. HGR := $F3E2 ; Initialize and clear hi-res page 1. HCLR := $F3F2 ; Clear the current hi-res screen to black. BKGND := $F3F6 ; Clear the current hi-res screen to the ; last plotted color (from ($1C). HPOSN := $F411 ; Positions the hi-res cursor without ; plotting a point. ; Enter with (A) = Y-coordinate, and ; (Y,X) = X-coordinate. HPLOT := $F457 ; Calls HPOSN and tries to plot a dot at ; the cursor's position. If you are ; trying to plot a non-white color at ; a complementary color position, no ; dot will be plotted. HLIN := $F53A ; Draws a line from the last plotted ; point or line destination to: ; (X,A) = X-coordinate, and ; (Y) = Y-coordinate. HFIND := $F5CB ; Converts the hi-res coursor's position ; back to X- and Y-coordinates; stores ; X-coordinate at $E0,E1 and Y-coordinate ; at $E2. DRAW := $F601 ; Draws a shape. Enter with (Y,X) = the ; address of the shape table, and (A) = ; the rotation factor. Uses the current ; color. XDRAW := $F65D ; Draws a shape by inverting the existing ; color of the dots the shape draws over. ; Same entry parameters as DRAW. SETHCOL := $F6EC ; Set the hi-res color to (X), where (X) ; must be between 0 and 7. ; ------------------------------------------------------------------------ ; Variables mapped to the zero page segment variables. Some of these are ; used for passing parameters to the driver. X1 := ptr1 Y1 := ptr2 X2 := ptr3 Y2 := ptr4 RADIUS := tmp1 ADDR := tmp1 ; (2) SETPIXELCLIP TEMP := tmp3 ; icmp TEMP2 := tmp4 ; icmp XX := ptr3 ; (2) CIRCLE YY := ptr4 ; (2) CIRCLE TEMP3 := sreg ; CIRCLE TEMP4 := sreg+1 ; CIRCLE MaxO := sreg ; (overwritten by TEMP3+TEMP4, but restored from OG/OU anyway) XS := regsave ; (2) CIRCLE YS := regsave+2 ; (2) CIRCLE ; ------------------------------------------------------------------------ .segment "JUMPTABLE" ; Header. Includes jump table and constants. ; First part of the header is a structure that has a magic and defines the ; capabilities of the driver .byte $74, $67, $69 ; "tgi" .byte TGI_API_VERSION ; TGI API version number xres: .word 280 ; X resolution yres: .word 192 ; Y resolution .byte 8 ; Number of drawing colors .byte 2 ; Number of screens available .byte 8 ; System font X size .byte 8 ; System font Y size .res 4, $00 ; Reserved for future extensions ; Next comes the jump table. Currently all entries must be valid and may point ; to an RTS for test versions (function not implemented). .addr INSTALL .addr UNINSTALL .addr INIT .addr DONE .addr GETERROR .addr CONTROL .addr CLEAR .addr SETVIEWPAGE .addr SETDRAWPAGE .addr SETCOLOR .addr SETPALETTE .addr GETPALETTE .addr GETDEFPALETTE .addr SETPIXEL .addr GETPIXEL .addr LINE .addr BAR .addr CIRCLE .addr TEXTSTYLE .addr OUTTEXT .addr 0 ; IRQ entry is unused ; ------------------------------------------------------------------------ .bss ; Absolute variables used in the code ERROR: .res 1 ; Error code .ifdef __APPLE2ENH__ Set80: .res 1 ; Set 80 column store .endif ; Circle stuff OGora: .res 2 OUkos: .res 2 Y3: .res 2 ; ------------------------------------------------------------------------ .rodata ; Constants and tables DEFPALETTE: .byte $00, $01, $02, $03, $04, $05, $06, $07 SHAPE: .byte $64,$01,$D0,$00,$D5,$00,$DA,$00,$E0,$00,$EF,$00,$FE,$00,$0C,$01 .byte $19,$01,$1D,$01,$25,$01,$2D,$01,$3D,$01,$46,$01,$4B,$01,$52,$01 .byte $56,$01,$60,$01,$70,$01,$77,$01,$83,$01,$8E,$01,$9A,$01,$A7,$01 .byte $B6,$01,$BF,$01,$CE,$01,$DD,$01,$E2,$01,$E7,$01,$F9,$01,$03,$02 .byte $15,$02,$1F,$02,$32,$02,$42,$02,$52,$02,$5E,$02,$6C,$02,$79,$02 .byte $85,$02,$91,$02,$A1,$02,$A9,$02,$B2,$02,$BF,$02,$C5,$02,$D5,$02 .byte $E5,$02,$F4,$02,$00,$03,$10,$03,$1F,$03,$2D,$03,$35,$03,$44,$03 .byte $53,$03,$63,$03,$71,$03,$7B,$03,$85,$03,$91,$03,$97,$03,$A3,$03 .byte $B6,$03,$BF,$03,$C3,$03,$CF,$03,$DC,$03,$E4,$03,$F3,$03,$00,$04 .byte $0A,$04,$19,$04,$25,$04,$2A,$04,$32,$04,$3C,$04,$43,$04,$50,$04 .byte $5A,$04,$66,$04,$72,$04,$7E,$04,$87,$04,$94,$04,$9C,$04,$A8,$04 .byte $B4,$04,$C1,$04,$CC,$04,$DB,$04,$E6,$04,$EE,$04,$F3,$04,$FB,$04 .byte $04,$05,$1A,$05,$1F,$05,$24,$05,$29,$05,$22,$01,$00,$00,$00,$00 .byte $09,$89,$92,$92,$00,$36,$36,$16,$0E,$00,$0D,$FE,$6E,$96,$52,$00 .byte $69,$FE,$17,$2D,$2D,$1E,$1F,$17,$2D,$2D,$1E,$1F,$6E,$4E,$00,$09 .byte $8D,$3F,$BF,$0D,$15,$3F,$0E,$0D,$1E,$3F,$77,$71,$09,$00,$6D,$11 .byte $DF,$77,$09,$1E,$17,$4D,$3A,$DF,$4E,$29,$0E,$00,$A9,$1F,$6E,$1E .byte $17,$0D,$0D,$1E,$DF,$0E,$6D,$0E,$00,$36,$96,$52,$00,$09,$1E,$17 .byte $36,$15,$0E,$0E,$00,$15,$0E,$36,$1E,$17,$4E,$01,$00,$09,$8D,$1F .byte $1F,$0E,$2D,$1E,$17,$2D,$15,$1F,$1F,$4E,$4E,$01,$00,$89,$6E,$3A .byte $3F,$77,$31,$56,$09,$00,$92,$8A,$F6,$0D,$00,$52,$89,$3F,$B7,$52 .byte $49,$00,$92,$92,$0E,$00,$49,$11,$17,$1E,$17,$1E,$56,$49,$01,$00 .byte $29,$AD,$DF,$33,$4D,$35,$1F,$1F,$2E,$4D,$FE,$1B,$0E,$2D,$4E,$00 .byte $31,$77,$36,$BE,$2D,$0E,$00,$29,$AD,$DF,$73,$49,$1E,$BF,$1E,$2E .byte $2D,$75,$00,$2D,$2D,$BE,$3E,$4E,$FE,$1B,$0E,$2D,$4E,$00,$49,$3E .byte $17,$0D,$FE,$33,$2D,$2D,$1E,$76,$01,$00,$2D,$2D,$DE,$1B,$2E,$2D .byte $15,$36,$DF,$73,$2D,$4E,$00,$09,$2D,$DE,$BB,$4D,$3A,$3F,$6E,$09 .byte $FE,$1B,$0E,$2D,$4E,$00,$2D,$2D,$BE,$1E,$17,$36,$4E,$09,$00,$29 .byte $AD,$DF,$33,$4D,$F1,$3F,$17,$4D,$31,$DF,$73,$2D,$4E,$00,$29,$AD .byte $DF,$33,$4D,$31,$3F,$77,$09,$1E,$DF,$2A,$75,$09,$00,$12,$16,$96 .byte $01,$00,$52,$B2,$F6,$0D,$00,$49,$3E,$17,$2D,$2D,$35,$3F,$3F,$3F .byte $0E,$2D,$2D,$F5,$1B,$77,$4E,$09,$00,$12,$2D,$2D,$DE,$9B,$2D,$2D .byte $96,$01,$00,$49,$15,$FF,$13,$2D,$2D,$AD,$3F,$3F,$3F,$2E,$2D,$2D .byte $1E,$37,$4E,$09,$00,$29,$AD,$DF,$73,$09,$1E,$B6,$4E,$01,$00,$09 .byte $2D,$3E,$37,$2D,$3E,$FF,$2A,$2D,$2D,$F5,$3F,$3F,$0E,$2D,$1E,$4D .byte $01,$00,$09,$15,$1F,$17,$4D,$31,$DF,$33,$2D,$2D,$FE,$1B,$6E,$09 .byte $0E,$00,$2D,$AD,$DF,$33,$4D,$F1,$3F,$37,$4D,$31,$DF,$33,$2D,$75 .byte $01,$00,$29,$AD,$DF,$33,$36,$4D,$11,$DF,$73,$2D,$4E,$00,$2D,$AD .byte $DF,$6E,$31,$DF,$6E,$31,$DF,$17,$2D,$75,$01,$00,$2D,$2D,$DE,$1B .byte $6E,$11,$3F,$37,$36,$2D,$2D,$0E,$00,$2D,$2D,$DE,$1B,$6E,$11,$3F .byte $37,$36,$4E,$49,$00,$29,$AD,$DF,$33,$36,$4D,$35,$DF,$73,$2D,$75 .byte $00,$4D,$31,$DF,$33,$4D,$31,$3F,$3F,$6E,$09,$FE,$1B,$6E,$09,$0E .byte $00,$2D,$1E,$36,$36,$17,$2D,$0E,$00,$49,$31,$36,$36,$DF,$73,$2D .byte $4E,$00,$4D,$F1,$DF,$6E,$1E,$37,$0D,$15,$DF,$6E,$09,$0E,$00,$36 .byte $36,$36,$2D,$75,$00,$4D,$31,$FF,$37,$0D,$0D,$FE,$1F,$6E,$09,$FE .byte $1B,$6E,$09,$0E,$00,$4D,$31,$DF,$33,$6D,$31,$1F,$1F,$6E,$29,$FE .byte $1B,$6E,$09,$0E,$00,$29,$AD,$DF,$33,$4D,$31,$DF,$33,$4D,$31,$DF .byte $73,$2D,$4E,$00,$2D,$AD,$DF,$33,$4D,$F1,$3F,$37,$36,$4E,$49,$00 .byte $29,$AD,$DF,$33,$4D,$31,$DF,$33,$0D,$0D,$1E,$DF,$0E,$6D,$0E,$00 .byte $2D,$AD,$DF,$33,$4D,$F1,$3F,$37,$0D,$15,$DF,$6E,$09,$0E,$00,$29 .byte $AD,$DF,$33,$4D,$3A,$77,$09,$FE,$1B,$0E,$2D,$4E,$00,$2D,$2D,$DE .byte $36,$36,$76,$09,$00,$4D,$31,$DF,$33,$4D,$31,$DF,$33,$4D,$31,$DF .byte $73,$2D,$4E,$00,$4D,$31,$DF,$33,$4D,$31,$DF,$33,$4D,$F1,$1F,$0E .byte $4E,$01,$00,$4D,$31,$DF,$33,$4D,$31,$1F,$1F,$6E,$0D,$3E,$1F,$37 .byte $4D,$71,$00,$4D,$31,$DF,$73,$0D,$1E,$17,$0D,$15,$DF,$33,$4D,$71 .byte $00,$4D,$31,$DF,$73,$0D,$1E,$36,$76,$09,$00,$2D,$2D,$BE,$1E,$17 .byte $1E,$2E,$2D,$75,$00,$2D,$2D,$DE,$3B,$2E,$3E,$2E,$3E,$2E,$2D,$75 .byte $00,$72,$15,$0E,$15,$56,$00,$2D,$2D,$3E,$2E,$3E,$2E,$3E,$DF,$2A .byte $2D,$75,$00,$49,$15,$3F,$17,$2D,$2D,$15,$3F,$3F,$3F,$4E,$2D,$3E .byte $37,$2D,$3E,$6F,$49,$00,$92,$92,$49,$11,$3F,$3F,$4D,$09,$00,$76 .byte $96,$52,$00,$52,$2D,$35,$DF,$33,$4D,$31,$FF,$73,$6D,$0E,$00,$36 .byte $2D,$AD,$DF,$33,$4D,$31,$DF,$33,$2D,$75,$01,$00,$52,$2D,$DE,$33 .byte $76,$2D,$0E,$00,$49,$31,$DF,$2A,$2D,$FE,$1B,$6E,$09,$FE,$1B,$0E .byte $2D,$75,$00,$52,$2D,$15,$DF,$33,$2D,$2D,$DE,$1B,$0E,$2D,$75,$00 .byte $09,$F5,$33,$8D,$3F,$77,$36,$4E,$01,$00,$52,$2D,$35,$DF,$33,$4D .byte $31,$3F,$77,$09,$1E,$3F,$4D,$01,$00,$36,$2D,$AD,$DF,$33,$4D,$31 .byte $DF,$33,$4D,$71,$00,$16,$36,$36,$0E,$00,$09,$9E,$35,$36,$F6,$6F .byte $01,$00,$36,$4D,$1E,$1F,$2E,$15,$1F,$6E,$71,$00,$35,$36,$36,$17 .byte $2D,$0E,$00,$12,$2D,$AD,$1F,$1F,$6E,$0D,$FE,$1F,$6E,$0D,$0E,$00 .byte $12,$2D,$15,$DF,$6E,$31,$DF,$6E,$71,$00,$52,$2D,$15,$DF,$33,$4D .byte $31,$DF,$73,$2D,$4E,$00,$12,$2D,$AD,$DF,$33,$4D,$F1,$3F,$37,$6E .byte $49,$00,$52,$2D,$35,$DF,$33,$4D,$31,$3F,$77,$09,$2E,$00,$12,$0D .byte $AD,$DF,$37,$36,$4E,$49,$00,$52,$2D,$F5,$DB,$0E,$2D,$15,$DF,$13 .byte $2D,$75,$01,$00,$31,$17,$2D,$F5,$33,$76,$75,$00,$12,$4D,$31,$DF .byte $33,$4D,$31,$FF,$73,$6D,$0E,$00,$12,$4D,$31,$DF,$33,$4D,$F1,$1F .byte $0E,$4E,$01,$00,$12,$4D,$31,$DF,$33,$0D,$0D,$FE,$1F,$0E,$0D,$4E .byte $00,$12,$4D,$F1,$1F,$0E,$15,$1F,$17,$4D,$71,$00,$12,$4D,$31,$DF .byte $33,$4D,$31,$3F,$77,$09,$1E,$3F,$4D,$01,$00,$12,$2D,$2D,$1E,$17 .byte $1E,$17,$2D,$2D,$0E,$00,$09,$F5,$33,$1E,$0E,$76,$75,$00,$36,$36 .byte $36,$2E,$00,$AD,$AE,$17,$FE,$2A,$4E,$01,$00,$69,$11,$1F,$1F,$4E .byte $B1,$92,$09,$00,$2D,$2D,$35,$3F,$3F,$37,$2D,$2D,$35,$3F,$3F,$37 .byte $2D,$2D,$35,$3F,$3F,$37,$2D,$2D,$75,$00,$40,$C0,$40,$18,$00,$40 .byte $C0,$40,$43,$00,$40,$C0,$40,$08,$00,$19,$00,$00 ; ------------------------------------------------------------------------ .code ; INIT: Changes an already installed device from text mode to graphics mode. ; Note that INIT/DONE may be called multiple times while the driver ; is loaded, while INSTALL is only called once, so any code that is needed ; to initializes variables and so on must go here. Setting palette and ; clearing the screen is not needed because this is called by the graphics ; kernel later. ; The graphics kernel will never call INIT when a graphics mode is already ; active, so there is no need to protect against that. ; Must set an error code: YES INIT: .ifdef __APPLE2ENH__ ; Save and clear 80 column store lda RD80COL sta Set80 sta CLR80COL .endif ; Switch into graphics mode bit HIRES bit MIXCLR bit TXTCLR ; Done, reset the error code lda #TGI_ERR_OK sta ERROR ; Fall through ; INSTALL routine. Is called after the driver is loaded into memory. May ; initialize anything that has to be done just once. Is probably empty ; most of the time. ; Must set an error code: NO INSTALL: ; Fall through ; UNINSTALL routine. Is called before the driver is removed from memory. May ; clean up anything done by INSTALL but is probably empty most of the time. ; Must set an error code: NO UNINSTALL: rts ; DONE: Will be called to switch the graphics device back into text mode. ; The graphics kernel will never call DONE when no graphics mode is active, ; so there is no need to protect against that. ; Must set an error code: NO DONE: ; Switch into text mode bit TXTSET bit LOWSCR .ifdef __APPLE2ENH__ ; Restore 80 column store lda Set80 bpl :+ sta SET80COL : bit LORES ; Limit SET80COL-HISCR to text .endif rts ; GETERROR: Return the error code in A and clear it. GETERROR: lda ERROR ldx #TGI_ERR_OK stx ERROR rts ; CLEAR: Clears the screen. ; Must set an error code: NO CLEAR: bit $C082 ; Switch in ROM jsr HCLR bit $C080 ; Switch in LC bank 2 for R/O rts ; SETVIEWPAGE: Set the visible page. Called with the new page in A (0..n). ; The page number is already checked to be valid by the graphics kernel. ; Must set an error code: NO (will only be called if page ok) SETVIEWPAGE: tax .assert LOWSCR + 1 = HISCR, error lda LOWSCR,x ; No BIT absolute,X available rts ; SETDRAWPAGE: Set the drawable page. Called with the new page in A (0..n). ; The page number is already checked to be valid by the graphics kernel. ; Must set an error code: NO (will only be called if page ok) SETDRAWPAGE: tax beq :+ lda #>$4000 ; Page 2 .byte $2C ; BIT absolute : lda #>$2000 ; Page 1 sta PAGE rts ; SETCOLOR: Set the drawing color (in A). The new color is already checked ; to be in a valid range (0..maxcolor-1). ; Must set an error code: NO (will only be called if color ok) SETCOLOR: bit $C082 ; Switch in ROM tax jsr SETHCOL bit $C080 ; Switch in LC bank 2 for R/O rts ; CONTROL: Platform/driver specific entry point. ; Must set an error code: YES CONTROL: ; Fall through ; SETPALETTE: Set the palette (not available with all drivers/hardware). ; A pointer to the palette is passed in ptr1. Must set an error if palettes ; are not supported ; Must set an error code: YES SETPALETTE: lda #TGI_ERR_INV_FUNC sta ERROR rts ; GETPALETTE: Return the current palette in A/X. Even drivers that cannot ; set the palette should return the default palette here, so there's no ; way for this function to fail. ; Must set an error code: NO GETPALETTE: ; Fall through ; GETDEFPALETTE: Return the default palette for the driver in A/X. All ; drivers should return something reasonable here, even drivers that don't ; support palettes, otherwise the caller has no way to determine the colors ; of the (not changeable) palette. ; Must set an error code: NO (all drivers must have a default palette) GETDEFPALETTE: lda #<DEFPALETTE ldx #>DEFPALETTE rts ; SETPIXEL: Draw one pixel at X1/Y1 = ptr1/ptr2 with the current drawing ; color. The coordinates passed to this function are never outside the ; visible screen area, so there is no need for clipping inside this function. ; Must set an error code: NO SETPIXEL: bit $C082 ; Switch in ROM ldx X1 ldy X1+1 lda Y1 jsr HPLOT bit $C080 ; Switch in LC bank 2 for R/O rts SETPIXELCLIP: lda Y1+1 bmi :+ ; y < 0 lda X1+1 bmi :+ ; x < 0 lda X1 ldx X1+1 sta ADDR stx ADDR+1 ldx #ADDR lda xres ldy xres+1 jsr icmp ; ( x < xres ) ... bcs :+ lda Y1 ldx Y1+1 sta ADDR stx ADDR+1 ldx #ADDR lda yres ldy yres+1 jsr icmp ; ... && ( y < yres ) bcc SETPIXEL : rts ; GETPIXEL: Read the color value of a pixel and return it in A/X. The ; coordinates passed to this function are never outside the visible screen ; area, so there is no need for clipping inside this function. GETPIXEL: bit $C082 ; Switch in ROM ldx X1 ldy X1+1 lda Y1 jsr HPOSN lda (HBASL),y and HMASK asl beq :+ ; 0 (black) lda #$03 ; 3 (white) : bcc :+ adc #$03 ; += 4 (black -> black2, white -> white2) : ldx #$00 bit $C080 ; Switch in LC bank 2 for R/O rts ; LINE: Draw a line from X1/Y1 to X2/Y2, where X1/Y1 = ptr1/ptr2 and ; X2/Y2 = ptr3/ptr4 using the current drawing color. ; Must set an error code: NO LINE: bit $C082 ; Switch in ROM ldx X1 ldy X1+1 lda Y1 jsr HPOSN lda X2 ldx X2+1 ldy Y2 jsr HLIN bit $C080 ; Switch in LC bank 2 for R/O rts ; BAR: Draw a filled rectangle with the corners X1/Y1, X2/Y2, where ; X1/Y1 = ptr1/ptr2 and X2/Y2 = ptr3/ptr4 using the current drawing color. ; Contrary to most other functions, the graphics kernel will sort and clip ; the coordinates before calling the driver, so on entry the following ; conditions are valid: ; X1 <= X2 ; Y1 <= Y2 ; (X1 >= 0) && (X1 < XRES) ; (X2 >= 0) && (X2 < XRES) ; (Y1 >= 0) && (Y1 < YRES) ; (Y2 >= 0) && (Y2 < YRES) ; Must set an error code: NO BAR: inc Y2 : lda Y2 pha lda Y1 sta Y2 jsr LINE pla sta Y2 inc Y1 cmp Y1 bne :- rts ; CIRCLE: Draw a circle around the center X1/Y1 (= ptr1/ptr2) with the ; radius in tmp1 and the current drawing color. ; Must set an error code: NO CIRCLE: lda RADIUS bne :+ jmp SETPIXELCLIP ; Plot as a point : sta XX ; x = r lda #$00 sta XX+1 sta YY sta YY+1 sta MaxO sta MaxO+1 ; y = 0, mo = 0 lda X1 ldx X1+1 sta XS stx XS+1 lda Y1 ldx Y1+1 sta YS stx YS+1 ; XS/YS to remember the center ; while (y < x) { while: ldx #YY lda XX ldy XX+1 jsr icmp bcc :+ rts ; Plot points in 8 slices... : lda XS add XX sta X1 lda XS+1 adc XX+1 sta X1+1 ; x1 = xs + x lda YS add YY sta Y1 pha lda YS+1 adc YY+1 sta Y1+1 ; (stack) = ys + y, y1 = (stack) pha jsr SETPIXELCLIP ; plot (xs + x, ys + y) lda YS sub YY sta Y1 sta Y3 lda YS+1 sbc YY+1 sta Y1+1 ; y3 = y1 = ys - y sta Y3+1 jsr SETPIXELCLIP ; plot (xs + x, ys - y) pla sta Y1+1 pla sta Y1 ; y1 = ys + y lda XS sub XX sta X1 lda XS+1 sbc XX+1 sta X1+1 jsr SETPIXELCLIP ; plot (xs - x, ys + y) lda Y3 sta Y1 lda Y3+1 sta Y1+1 jsr SETPIXELCLIP ; plot (xs - x, ys - y) lda XS add YY sta X1 lda XS+1 adc YY+1 sta X1+1 ; x1 = xs + y lda YS add XX sta Y1 pha lda YS+1 adc XX+1 sta Y1+1 ; (stack) = ys + x, y1 = (stack) pha jsr SETPIXELCLIP ; plot (xs + y, ys + x) lda YS sub XX sta Y1 sta Y3 lda YS+1 sbc XX+1 sta Y1+1 ; y3 = y1 = ys - x sta Y3+1 jsr SETPIXELCLIP ; plot (xs + y, ys - x) pla sta Y1+1 pla sta Y1 ; y1 = ys + x(stack) lda XS sub YY sta X1 lda XS+1 sbc YY+1 sta X1+1 jsr SETPIXELCLIP ; plot (xs - y, ys + x) lda Y3 sta Y1 lda Y3+1 sta Y1+1 jsr SETPIXELCLIP ; plot (xs - y, ys - x) ; og = mo + y + y + 1 lda MaxO ldx MaxO+1 add YY tay txa adc YY+1 tax tya add YY tay txa adc YY+1 tax tya add #$01 bcc :+ inx : sta OGora stx OGora+1 ; ou = og - x - x + 1 sub XX tay txa sbc XX+1 tax tya sub XX tay txa sbc XX+1 tax tya add #$01 bcc :+ inx : sta OUkos stx OUkos+1 ; ++y inc YY bne :+ inc YY+1 ; if (abs (ou) < abs (og)) { : lda OUkos ldy OUkos+1 jsr abs sta TEMP3 sty TEMP4 lda OGora ldy OGora+1 jsr abs ldx #TEMP3 jsr icmp bpl :++ ; --x lda XX sub #$01 sta XX bcs :+ dec XX+1 ; mo = ou } : lda OUkos ldx OUkos+1 jmp :++ ; else mo = og : lda OGora ldx OGora+1 : sta MaxO stx MaxO+1 ; } jmp while ; TEXTSTYLE: Set the style used when calling OUTTEXT. Text scaling in X and Y ; direction is passend in X/Y, the text direction is passed in A. ; Must set an error code: NO TEXTSTYLE: stx SCALE asl ; 16 <=> 90 asl asl asl sta ROT rts ; OUTTEXT: Output text at X/Y = ptr1/ptr2 using the current color and the ; current text style. The text to output is given as a zero terminated ; string with address in ptr3. ; Must set an error code: NO OUTTEXT: bit $C082 ; Switch in ROM ldx X1 ldy X1+1 lda Y1 jsr HPOSN lda SHAPE+2*99 add #<SHAPE sta tmp3 lda SHAPE+2*99+1 adc #>SHAPE sta tmp3+1 ldy #$00 : lda (ptr3),y beq :+ sub #$1F ; No controls asl ; Offset * 2 tax lda SHAPE,x add #<SHAPE sta tmp1 lda SHAPE+1,x adc #>SHAPE sta tmp1+1 tya pha ldx tmp1 ldy tmp1+1 lda ROT jsr DRAW ldx tmp3 ldy tmp3+1 lda ROT jsr DRAW pla tay iny bne :- : bit $C080 ; Switch in LC bank 2 for R/O rts ; Copies of some runtime routines abs: ; A/Y := abs (A/Y) cpy #$00 bpl :+ clc eor #$FF adc #$01 pha tya eor #$FF adc #$00 tay pla : rts icmp: ; Compare A/Y to zp,X sta TEMP ; TEMP/TEMP2 - arg2 sty TEMP2 lda $00,x pha lda $01,x tay pla tax tya ; X/A - arg1 (a = high) sub TEMP2 bne :++ cpx TEMP beq :+ adc #$FF ora #$01 : rts : bvc :+ eor #$FF ora #$01 : rts
wagiminator/C64-Collection
2,367
C64_xu1541/software/tools/cc65-2.13.2/libsrc/apple2/write.s
; ; Oliver Schmidt, 12.01.2005 ; ; int __fastcall__ write (int fd, const void* buf, unsigned count); ; .export _write .import rwprolog, rwcommon, rwepilog .import errnoexit, oserrexit .import COUT .include "zeropage.inc" .include "errno.inc" .include "fcntl.inc" .include "mli.inc" .include "filedes.inc" _write: ; Get parameters jsr rwprolog bcs errno tax ; Save fd ; Check for write access lda fdtab + FD::FLAGS,y and #O_WRONLY beq einval ; Check for device txa ; Restore fd bmi device ; Check for append flag lda fdtab + FD::FLAGS,y and #O_APPEND beq write ; Set fd stx mliparam + MLI::EOF::REF_NUM ; Get file size lda #GET_EOF_CALL ldx #EOF_COUNT jsr callmli bcs oserr ; REF_NUM already set .assert MLI::MARK::REF_NUM = MLI::EOF::REF_NUM, error ; POSITION already set .assert MLI::MARK::POSITION = MLI::EOF::EOF, error ; Set file pointer lda #SET_MARK_CALL ldx #MARK_COUNT jsr callmli bcs oserr ; Do write write: lda fdtab + FD::REF_NUM,y ldy #WRITE_CALL jmp rwcommon ; Save count for epilog device: ldx ptr2 lda ptr2+1 stx mliparam + MLI::RW::TRANS_COUNT sta mliparam + MLI::RW::TRANS_COUNT+1 ; Check for zero count ora ptr2 beq done ; Get char from buf ldy #$00 next: lda (ptr1),y ; Replace '\n' with '\r' cmp #$0A bne :+ lda #$0D ; Set hi bit and write to device : ora #$80 .ifndef __APPLE2ENH__ cmp #$E0 ; Test for lowercase bcc output and #$DF ; Convert to uppercase .endif output: jsr COUT ; Preserves X and Y ; Increment pointer iny bne :+ inc ptr1+1 ; Decrement count : dex bne next dec ptr2+1 bpl next ; Return success done: jmp rwepilog ; Load errno code einval: lda #EINVAL ; Return errno errno: jmp errnoexit ; Return oserror oserr: jmp oserrexit
wagiminator/C64-Collection
6,774
C64_xu1541/software/tools/cc65-2.13.2/libsrc/apple2/ctype.s
; ; Stefan Haubenthal with minor changes from Ullrich von Bassewitz, 2003-05-02 ; ; Character specification table. ; .include "ctype.inc" ; The tables are readonly, put them into the rodata segment .rodata ; The following 256 byte wide table specifies attributes for the isxxx type ; of functions. Doing it by a table means some overhead in space, but it ; has major advantages: ; ; * It is fast. If it were'nt for the slow parameter passing of cc65, one ; could even define macros for the isxxx functions (this is usually ; done on other platforms). ; ; * It is highly portable. The only unportable part is the table itself, ; all real code goes into the common library. ; ; * We save some code in the isxxx functions. __ctype: .repeat 2 .byte CT_CTRL ; 0/00 ___ctrl_@___ .byte CT_CTRL ; 1/01 ___ctrl_A___ .byte CT_CTRL ; 2/02 ___ctrl_B___ .byte CT_CTRL ; 3/03 ___ctrl_C___ .byte CT_CTRL ; 4/04 ___ctrl_D___ .byte CT_CTRL ; 5/05 ___ctrl_E___ .byte CT_CTRL ; 6/06 ___ctrl_F___ .byte CT_CTRL ; 7/07 ___ctrl_G___ .byte CT_CTRL ; 8/08 ___ctrl_H___ .byte CT_CTRL | CT_OTHER_WS | CT_SPACE_TAB ; 9/09 ___ctrl_I___ .byte CT_CTRL | CT_OTHER_WS ; 10/0a ___ctrl_J___ .byte CT_CTRL | CT_OTHER_WS ; 11/0b ___ctrl_K___ .byte CT_CTRL | CT_OTHER_WS ; 12/0c ___ctrl_L___ .byte CT_CTRL | CT_OTHER_WS ; 13/0d ___ctrl_M___ .byte CT_CTRL ; 14/0e ___ctrl_N___ .byte CT_CTRL ; 15/0f ___ctrl_O___ .byte CT_CTRL ; 16/10 ___ctrl_P___ .byte CT_CTRL ; 17/11 ___ctrl_Q___ .byte CT_CTRL ; 18/12 ___ctrl_R___ .byte CT_CTRL ; 19/13 ___ctrl_S___ .byte CT_CTRL ; 20/14 ___ctrl_T___ .byte CT_CTRL ; 21/15 ___ctrl_U___ .byte CT_CTRL ; 22/16 ___ctrl_V___ .byte CT_CTRL ; 23/17 ___ctrl_W___ .byte CT_CTRL ; 24/18 ___ctrl_X___ .byte CT_CTRL ; 25/19 ___ctrl_Y___ .byte CT_CTRL ; 26/1a ___ctrl_Z___ .byte CT_CTRL ; 27/1b ___ctrl_[___ .byte CT_CTRL ; 28/1c ___ctrl_\___ .byte CT_CTRL ; 29/1d ___ctrl_]___ .byte CT_CTRL ; 30/1e ___ctrl_^___ .byte CT_CTRL ; 31/1f ___ctrl_____ .byte CT_SPACE | CT_SPACE_TAB ; 32/20 ___SPACE___ .byte CT_NONE ; 33/21 _____!_____ .byte CT_NONE ; 34/22 _____"_____ .byte CT_NONE ; 35/23 _____#_____ .byte CT_NONE ; 36/24 _____$_____ .byte CT_NONE ; 37/25 _____%_____ .byte CT_NONE ; 38/26 _____&_____ .byte CT_NONE ; 39/27 _____'_____ .byte CT_NONE ; 40/28 _____(_____ .byte CT_NONE ; 41/29 _____)_____ .byte CT_NONE ; 42/2a _____*_____ .byte CT_NONE ; 43/2b _____+_____ .byte CT_NONE ; 44/2c _____,_____ .byte CT_NONE ; 45/2d _____-_____ .byte CT_NONE ; 46/2e _____._____ .byte CT_NONE ; 47/2f _____/_____ .byte CT_DIGIT | CT_XDIGIT ; 48/30 _____0_____ .byte CT_DIGIT | CT_XDIGIT ; 49/31 _____1_____ .byte CT_DIGIT | CT_XDIGIT ; 50/32 _____2_____ .byte CT_DIGIT | CT_XDIGIT ; 51/33 _____3_____ .byte CT_DIGIT | CT_XDIGIT ; 52/34 _____4_____ .byte CT_DIGIT | CT_XDIGIT ; 53/35 _____5_____ .byte CT_DIGIT | CT_XDIGIT ; 54/36 _____6_____ .byte CT_DIGIT | CT_XDIGIT ; 55/37 _____7_____ .byte CT_DIGIT | CT_XDIGIT ; 56/38 _____8_____ .byte CT_DIGIT | CT_XDIGIT ; 57/39 _____9_____ .byte CT_NONE ; 58/3a _____:_____ .byte CT_NONE ; 59/3b _____;_____ .byte CT_NONE ; 60/3c _____<_____ .byte CT_NONE ; 61/3d _____=_____ .byte CT_NONE ; 62/3e _____>_____ .byte CT_NONE ; 63/3f _____?_____ .byte CT_NONE ; 64/40 _____@_____ .byte CT_UPPER | CT_XDIGIT ; 65/41 _____A_____ .byte CT_UPPER | CT_XDIGIT ; 66/42 _____B_____ .byte CT_UPPER | CT_XDIGIT ; 67/43 _____C_____ .byte CT_UPPER | CT_XDIGIT ; 68/44 _____D_____ .byte CT_UPPER | CT_XDIGIT ; 69/45 _____E_____ .byte CT_UPPER | CT_XDIGIT ; 70/46 _____F_____ .byte CT_UPPER ; 71/47 _____G_____ .byte CT_UPPER ; 72/48 _____H_____ .byte CT_UPPER ; 73/49 _____I_____ .byte CT_UPPER ; 74/4a _____J_____ .byte CT_UPPER ; 75/4b _____K_____ .byte CT_UPPER ; 76/4c _____L_____ .byte CT_UPPER ; 77/4d _____M_____ .byte CT_UPPER ; 78/4e _____N_____ .byte CT_UPPER ; 79/4f _____O_____ .byte CT_UPPER ; 80/50 _____P_____ .byte CT_UPPER ; 81/51 _____Q_____ .byte CT_UPPER ; 82/52 _____R_____ .byte CT_UPPER ; 83/53 _____S_____ .byte CT_UPPER ; 84/54 _____T_____ .byte CT_UPPER ; 85/55 _____U_____ .byte CT_UPPER ; 86/56 _____V_____ .byte CT_UPPER ; 87/57 _____W_____ .byte CT_UPPER ; 88/58 _____X_____ .byte CT_UPPER ; 89/59 _____Y_____ .byte CT_UPPER ; 90/5a _____Z_____ .byte CT_NONE ; 91/5b _____[_____ .byte CT_NONE ; 92/5c _____\_____ .byte CT_NONE ; 93/5d _____]_____ .byte CT_NONE ; 94/5e _____^_____ .byte CT_NONE ; 95/5f _UNDERLINE_ .byte CT_NONE ; 96/60 ___grave___ .byte CT_LOWER | CT_XDIGIT ; 97/61 _____a_____ .byte CT_LOWER | CT_XDIGIT ; 98/62 _____b_____ .byte CT_LOWER | CT_XDIGIT ; 99/63 _____c_____ .byte CT_LOWER | CT_XDIGIT ; 100/64 _____d_____ .byte CT_LOWER | CT_XDIGIT ; 101/65 _____e_____ .byte CT_LOWER | CT_XDIGIT ; 102/66 _____f_____ .byte CT_LOWER ; 103/67 _____g_____ .byte CT_LOWER ; 104/68 _____h_____ .byte CT_LOWER ; 105/69 _____i_____ .byte CT_LOWER ; 106/6a _____j_____ .byte CT_LOWER ; 107/6b _____k_____ .byte CT_LOWER ; 108/6c _____l_____ .byte CT_LOWER ; 109/6d _____m_____ .byte CT_LOWER ; 110/6e _____n_____ .byte CT_LOWER ; 111/6f _____o_____ .byte CT_LOWER ; 112/70 _____p_____ .byte CT_LOWER ; 113/71 _____q_____ .byte CT_LOWER ; 114/72 _____r_____ .byte CT_LOWER ; 115/73 _____s_____ .byte CT_LOWER ; 116/74 _____t_____ .byte CT_LOWER ; 117/75 _____u_____ .byte CT_LOWER ; 118/76 _____v_____ .byte CT_LOWER ; 119/77 _____w_____ .byte CT_LOWER ; 120/78 _____x_____ .byte CT_LOWER ; 121/79 _____y_____ .byte CT_LOWER ; 122/7a _____z_____ .byte CT_NONE ; 123/7b _____{_____ .byte CT_NONE ; 124/7c _____|_____ .byte CT_NONE ; 125/7d _____}_____ .byte CT_NONE ; 126/7e _____~_____ .byte CT_OTHER_WS ; 127/7f ____DEL____ .endrepeat
wagiminator/C64-Collection
5,172
C64_xu1541/software/tools/cc65-2.13.2/libsrc/apple2/open.s
; ; Oliver Schmidt, 30.12.2004 ; ; int open (const char* name, int flags, ...); ; ; Be sure to keep the value priority of closeallfiles lower than that of ; closeallstreams (which is the high level C file I/O counterpart and must be ; called before closeallfiles). .export _open, closedirect, freebuffer .destructor closeallfiles, 17 .import pushname, popname .import errnoexit, oserrexit .import iobuf_alloc, iobuf_free .import addysp, incsp4, incaxy, pushax, popax .include "zeropage.inc" .include "errno.inc" .include "fcntl.inc" .include "mli.inc" .include "filedes.inc" _open: ; Throw away all parameters except name ; and flags occupying together 4 bytes dey dey dey dey jsr addysp ; Start with first fdtab slot ldy #$00 ; Check for free fdtab slot : lda fdtab + FD::REF_NUM,y beq found ; Advance to next fdtab slot .assert .sizeof(FD) = 4, error iny iny iny iny ; Check for end of fdtab cpy #MAX_FDS * .sizeof(FD) bcc :- ; Load errno code lda #EMFILE ; Cleanup stack errno: jsr incsp4 ; Preserves A ; Return errno jmp errnoexit ; Save fdtab slot found: tya pha ; Alloc I/O buffer lda #<(fdtab + FD::BUFFER) ldx #>(fdtab + FD::BUFFER) jsr incaxy jsr pushax lda #$00 ldx #>$0100 jsr pushax ; Preserves A ldx #>$0400 jsr iobuf_alloc tay ; Save errno code ; Restore fdtab slot pla sta tmp2 ; Save fdtab slot ; Check for error tya ; Restore errno code bne errno ; Get and save flags jsr popax sta tmp3 ; Get and push name jsr popax jsr pushname bne oserr1 ; Set pushed name lda sp ldx sp+1 sta mliparam + MLI::OPEN::PATHNAME stx mliparam + MLI::OPEN::PATHNAME+1 ; Check for create flag lda tmp3 ; Restore flags and #O_CREAT beq open ; PATHNAME already set .assert MLI::CREATE::PATHNAME = MLI::OPEN::PATHNAME, error ; Set all other parameters from template ldx #(MLI::CREATE::CREATE_TIME+1) - (MLI::CREATE::PATHNAME+1) - 1 : lda CREATE,x sta mliparam + MLI::CREATE::ACCESS,x dex bpl :- ; Create file lda #CREATE_CALL ldx #CREATE_COUNT jsr callmli bcc open ; Check for ordinary errors cmp #$47 ; "Duplicate filename" bne oserr2 ; Check for exclusive flag lda tmp3 ; Restore flags and #O_EXCL beq open lda #$47 ; "Duplicate filename" ; Cleanup name oserr2: jsr popname ; Preserves A oserr1: ldy tmp2 ; Restore fdtab slot ; Cleanup I/O buffer pha ; Save oserror code jsr freebuffer pla ; Restore oserror code ; Return oserror jmp oserrexit open: ldy tmp2 ; Restore fdtab slot ; Set allocated I/O buffer ldx fdtab + FD::BUFFER+1,y sta mliparam + MLI::OPEN::IO_BUFFER ; A = 0 stx mliparam + MLI::OPEN::IO_BUFFER+1 ; Open file lda #OPEN_CALL ldx #OPEN_COUNT jsr callmli bcs oserr2 ; Get and save fd ldx mliparam + MLI::OPEN::REF_NUM stx tmp1 ; Save fd ; Set flags and check for truncate flag lda tmp3 ; Restore flags sta fdtab + FD::FLAGS,y and #O_TRUNC beq done ; Set fd and zero size stx mliparam + MLI::EOF::REF_NUM ldx #$02 lda #$00 : sta mliparam + MLI::EOF::EOF,x dex bpl :- ; Set file size lda #SET_EOF_CALL ldx #EOF_COUNT jsr callmli bcc done ; Cleanup file pha ; Save oserror code lda tmp1 ; Restore fd jsr closedirect pla ; Restore oserror code bne oserr2 ; Branch always ; Store fd done: lda tmp1 ; Restore fd sta fdtab + FD::REF_NUM,y ; Convert fdtab slot to handle .assert .sizeof(FD) = 4, error tya lsr lsr ; Cleanup name jsr popname ; Preserves A ; Return success ldx #$00 rts freebuffer: ; Free I/O buffer lda #$00 ldx fdtab + FD::BUFFER+1,y jmp iobuf_free closeallfiles: ; All open files lda #$00 closedirect: ; Set fd sta mliparam + MLI::CLOSE::REF_NUM ; Call close lda #CLOSE_CALL ldx #CLOSE_COUNT jmp callmli .rodata CREATE: .byte %11000011 ; ACCESS: Standard full access .byte $06 ; FILE_TYPE: Standard binary file .word $0000 ; AUX_TYPE: Load address N/A .byte $01 ; STORAGE_TYPE: Standard seedling file .word $0000 ; CREATE_DATE: Current date .word $0000 ; CREATE_TIME: Current time
wagiminator/C64-Collection
5,311
C64_xu1541/software/tools/cc65-2.13.2/libsrc/plus4/crt0.s
; ; Startup code for cc65 (Plus/4 version) ; .export _exit .export brk_jmp .export __STARTUP__ : absolute = 1 ; Mark as startup .import callirq_y, initlib, donelib .import callmain, zerobss .import __INTERRUPTOR_COUNT__ .include "zeropage.inc" .include "plus4.inc" ; ------------------------------------------------------------------------ ; Constants IRQInd = $500 ; JMP $0000 - used as indirect IRQ vector ; ------------------------------------------------------------------------ ; Place the startup code in a special segment to cope with the quirks of ; plus/4 banking. .segment "STARTUP" .word Head ; Load address Head: .word @Next .word .version ; Line number .byte $9E,"4109" ; SYS 4109 .byte $00 ; End of BASIC line @Next: .word 0 ; BASIC end marker ; ------------------------------------------------------------------------ ; Actual code sei ; No interrupts since we're banking out the ROM sta ENABLE_RAM ldx #zpspace-1 L1: lda sp,x sta zpsave,x ; save the zero page locations we need dex bpl L1 sta ENABLE_ROM cli ; Close open files jsr $FFCC ; CLRCH ; Switch to second charset lda #14 jsr $FFD2 ; BSOUT ; Save system stuff and setup the stack. The stack starts at the top of the ; usable RAM. tsx stx spsave ; save system stk ptr lda #<$FD00 sta sp lda #>$FD00 sta sp+1 ; Setup the IRQ vector in the banked RAM and switch off the ROM ldx #<IRQ ldy #>IRQ sei ; No ints, handler not yet in place sta ENABLE_RAM stx $FFFE ; Install interrupt handler sty $FFFF cli ; Allow interrupts ; Clear the BSS data jsr zerobss ; Initialize irqcount, which means that from now own custom linked in IRQ ; handlers (via condes) will be called. lda #.lobyte(__INTERRUPTOR_COUNT__*2) sta irqcount ; Call module constructors jsr initlib ; Push arguments and call main() jsr callmain ; Back from main (this is also the _exit entry). Run module destructors. _exit: pha ; Save the return code jsr donelib ; Run module destructors ; Disable chained IRQ handlers lda #0 sta irqcount ; Disable custom IRQ handlers ; Copy back the zero page stuff ldx #zpspace-1 L2: lda zpsave,x sta sp,x dex bpl L2 ; Place the program return code into ST pla sta ST ; Restore the stack pointer ldx spsave txs ; Enable the ROM, reset changed vectors and return to BASIC sta ENABLE_ROM jmp $FF8A ; RESTOR ; ------------------------------------------------------------------------ ; IRQ handler. The handler in the ROM enables the kernal and jumps to ; $CE00, where the ROM code checks for a BRK or IRQ and branches via the ; indirect vectors at $314/$316. ; To make our stub as fast as possible, we skip the whole part of the ROM ; handler and jump to the indirect vectors directly. We do also call our ; own interrupt handlers if we have any, so they need not use $314. .segment "LOWCODE" IRQ: cld ; Just to be sure pha txa pha tya pha tsx ; Get the stack pointer lda $0104,x ; Get the saved status register and #$10 ; Test for BRK bit bne dobreak ; It's an IRQ and RAM is enabled. If we have handlers, call them. We will use ; a flag here instead of loading __INTERRUPTOR_COUNT__ directly, since the ; condes function is not reentrant. The irqcount flag will be set/reset from ; the main code, to avoid races. ldy irqcount beq @L1 jsr callirq_y ; Call the IRQ functions ; Since the ROM handler will end with an RTI, we have to fake an IRQ return ; on stack, so we get control of the CPU after the ROM handler and can switch ; back to RAM. @L1: lda #>irq_ret ; Push new return address pha lda #<irq_ret pha php ; Push faked IRQ frame on stack pha ; Push faked A register pha ; Push faked X register pha ; Push faked Y register sta ENABLE_ROM ; Switch to ROM jmp (IRQVec) ; Jump indirect to kernal irq handler irq_ret: sta ENABLE_RAM ; Switch back to RAM pla tay pla tax pla rti dobreak: lda brk_jmp+2 ; Check high byte of address beq nohandler jmp brk_jmp ; Jump to the handler ; No break handler installed, jump to ROM nohandler: sta ENABLE_ROM jmp (BRKVec) ; Jump indirect to the break vector ; ------------------------------------------------------------------------ ; Data .data ; BRK handling brk_jmp: jmp $0000 spsave: .res 1 irqcount: .byte 0 .segment "ZPSAVE" zpsave: .res zpspace
wagiminator/C64-Collection
2,702
C64_xu1541/software/tools/cc65-2.13.2/libsrc/plus4/plus4-stdjoy.s
; ; Standard joystick driver for the Plus/4. May be used multiple times when linked ; to the statically application. ; ; Ullrich von Bassewitz, 2002-12-21 ; .include "zeropage.inc" .include "joy-kernel.inc" .include "joy-error.inc" .include "plus4.inc" .macpack generic ; ------------------------------------------------------------------------ ; Header. Includes jump table .segment "JUMPTABLE" ; Driver signature .byte $6A, $6F, $79 ; "joy" .byte JOY_API_VERSION ; 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 ; JOY_FIRE2 unavailable .byte $00 ; Future expansion .byte $00 ; Future expansion ; Jump table. .addr INSTALL .addr UNINSTALL .addr COUNT .addr READ .addr 0 ; IRQ entry unused ; ------------------------------------------------------------------------ ; 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: ldy #$FA ; Load index for joystick #1 tax ; Test joystick number beq @L1 ldy #$FB ; Load index for joystick #2 @L1: sei sty TED_KBD lda TED_KBD cli ldx #$00 ; Clear high byte and #$1F eor #$1F rts
wagiminator/C64-Collection
11,306
C64_xu1541/software/tools/cc65-2.13.2/libsrc/plus4/plus4-stdser.s
; ; Serial driver for the builtin 6551 ACIA of the Plus/4. ; ; Ullrich von Bassewitz, 2003-12-13 ; ; The driver is based on the cc65 rs232 module, which in turn is based on ; Craig Bruce device driver for the Switftlink/Turbo-232. ; ; SwiftLink/Turbo-232 v0.90 device driver, by Craig Bruce, 14-Apr-1998. ; ; This software is Public Domain. It is in Buddy assembler format. ; ; This device driver uses the SwiftLink RS-232 Serial Cartridge, available from ; Creative Micro Designs, Inc, and also supports the extensions of the Turbo232 ; Serial Cartridge. Both devices are based on the 6551 ACIA chip. It also ; supports the "hacked" SwiftLink with a 1.8432 MHz crystal. ; ; The code assumes that the kernal + I/O are in context. On the C128, call ; it from Bank 15. On the C64, don't flip out the Kernal unless a suitable ; NMI catcher is put into the RAM under then Kernal. For the SuperCPU, the ; interrupt handling assumes that the 65816 is in 6502-emulation mode. ; .include "zeropage.inc" .include "ser-kernel.inc" .include "ser-error.inc" .include "plus4.inc" ; ------------------------------------------------------------------------ ; Header. Includes jump table .segment "JUMPTABLE" ; Driver signature .byte $73, $65, $72 ; "ser" .byte SER_API_VERSION ; Serial API version number ; Jump table. .word INSTALL .word UNINSTALL .word OPEN .word CLOSE .word GET .word PUT .word STATUS .word IOCTL .word IRQ ;---------------------------------------------------------------------------- ; I/O definitions ACIA = $DE00 ACIA_DATA = ACIA+0 ; Data register ACIA_STATUS = ACIA+1 ; Status register ACIA_CMD = ACIA+2 ; Command register ACIA_CTRL = ACIA+3 ; Control register ;---------------------------------------------------------------------------- ; ; Global variables ; .bss RecvHead: .res 1 ; Head of receive buffer RecvTail: .res 1 ; Tail of receive buffer RecvFreeCnt: .res 1 ; Number of bytes in receive buffer SendHead: .res 1 ; Head of send buffer SendTail: .res 1 ; Tail of send buffer SendFreeCnt: .res 1 ; Number of bytes in send buffer Stopped: .res 1 ; Flow-stopped flag RtsOff: .res 1 ; ; Send and receive buffers: 256 bytes each RecvBuf: .res 256 SendBuf: .res 256 .rodata ; Tables used to translate RS232 params into register values BaudTable: ; bit7 = 1 means setting is invalid .byte $FF ; SER_BAUD_45_5 .byte $01 ; SER_BAUD_50 .byte $02 ; SER_BAUD_75 .byte $03 ; SER_BAUD_110 .byte $04 ; SER_BAUD_134_5 .byte $05 ; SER_BAUD_150 .byte $06 ; SER_BAUD_300 .byte $07 ; SER_BAUD_600 .byte $08 ; SER_BAUD_1200 .byte $09 ; SER_BAUD_1800 .byte $0A ; SER_BAUD_2400 .byte $0B ; SER_BAUD_3600 .byte $0C ; SER_BAUD_4800 .byte $0D ; SER_BAUD_7200 .byte $0E ; SER_BAUD_9600 .byte $0F ; SER_BAUD_19200 .byte $FF ; SER_BAUD_38400 .byte $FF ; SER_BAUD_57600 .byte $FF ; SER_BAUD_115200 .byte $FF ; SER_BAUD_230400 BitTable: .byte $60 ; SER_BITS_5 .byte $40 ; SER_BITS_6 .byte $20 ; SER_BITS_7 .byte $00 ; SER_BITS_8 StopTable: .byte $00 ; SER_STOP_1 .byte $80 ; SER_STOP_2 ParityTable: .byte $00 ; SER_PAR_NONE .byte $20 ; SER_PAR_ODD .byte $60 ; SER_PAR_EVEN .byte $A0 ; SER_PAR_MARK .byte $E0 ; SER_PAR_SPACE .code ;---------------------------------------------------------------------------- ; INSTALL routine. Is called after the driver is loaded into memory. If ; possible, check if the hardware is present. ; Must return an SER_ERR_xx code in a/x. ; ; Since we don't have to manage the IRQ vector on the Plus/4, this is actually ; the same as: ; ; UNINSTALL routine. Is called before the driver is removed from memory. ; Must return an SER_ERR_xx code in a/x. ; ; and: ; ; CLOSE: Close the port, disable interrupts and flush the buffer. Called ; without parameters. Must return an error code in a/x. ; INSTALL: UNINSTALL: CLOSE: ; Deactivate DTR and disable 6551 interrupts lda #%00001010 sta ACIA_CMD ; Done, return an error code lda #<SER_ERR_OK tax ; A is zero rts ;---------------------------------------------------------------------------- ; PARAMS routine. A pointer to a ser_params structure is passed in ptr1. ; Must return an SER_ERR_xx code in a/x. OPEN: ; Check if the handshake setting is valid ldy #SER_PARAMS::HANDSHAKE ; Handshake lda (ptr1),y cmp #SER_HS_HW ; This is all we support bne InvParam ; Initialize buffers ldx #0 stx Stopped stx RecvHead stx RecvTail stx SendHead stx SendTail dex ; X = 255 stx RecvFreeCnt stx SendFreeCnt ; Set the value for the control register, which contains stop bits, word ; length and the baud rate. ldy #SER_PARAMS::BAUDRATE lda (ptr1),y ; Baudrate index tay lda BaudTable,y ; Get 6551 value bmi InvBaud ; Branch if rate not supported sta tmp1 ldy #SER_PARAMS::DATABITS ; Databits lda (ptr1),y tay lda BitTable,y ora tmp1 sta tmp1 ldy #SER_PARAMS::STOPBITS ; Stopbits lda (ptr1),y tay lda StopTable,y ora tmp1 ora #%00010000 ; Receiver clock source = baudrate sta ACIA_CTRL ; Set the value for the command register. We remember the base value in ; RtsOff, since we will have to manipulate ACIA_CMD often. ldy #SER_PARAMS::PARITY ; Parity lda (ptr1),y tay lda ParityTable,y ora #%00000001 ; DTR active sta RtsOff ora #%00001000 ; Enable receive interrupts sta ACIA_CMD ; Done lda #<SER_ERR_OK tax ; A is zero rts ; Invalid parameter InvParam: lda #<SER_ERR_INIT_FAILED ldx #>SER_ERR_INIT_FAILED rts ; Baud rate not available InvBaud: lda #<SER_ERR_BAUD_UNAVAIL ldx #>SER_ERR_BAUD_UNAVAIL rts ;---------------------------------------------------------------------------- ; GET: Will fetch a character from the receive buffer and store it into the ; variable pointer to by ptr1. If no data is available, SER_ERR_NO_DATA is ; return. ; GET: ldx SendFreeCnt ; Send data if necessary inx ; X == $FF? beq @L1 lda #$00 jsr TryToSend ; Check for buffer empty @L1: lda RecvFreeCnt ; (25) cmp #$ff bne @L2 lda #<SER_ERR_NO_DATA ldx #>SER_ERR_NO_DATA rts ; Check for flow stopped & enough free: release flow control @L2: ldx Stopped ; (34) beq @L3 cmp #63 bcc @L3 lda #$00 sta Stopped lda RtsOff ora #%00001000 sta ACIA_CMD ; Get byte from buffer @L3: ldx RecvHead ; (41) lda RecvBuf,x inc RecvHead inc RecvFreeCnt ldx #$00 ; (59) sta (ptr1,x) txa ; Return code = 0 rts ;---------------------------------------------------------------------------- ; PUT: Output character in A. ; Must return an error code in a/x. ; PUT: ; Try to send ldx SendFreeCnt inx ; X = $ff? beq @L2 pha lda #$00 jsr TryToSend pla ; Put byte into send buffer & send @L2: ldx SendFreeCnt bne @L3 lda #<SER_ERR_OVERFLOW ; X is already zero rts @L3: ldx SendTail sta SendBuf,x inc SendTail dec SendFreeCnt lda #$ff jsr TryToSend lda #<SER_ERR_OK tax rts ;---------------------------------------------------------------------------- ; STATUS: Return the status in the variable pointed to by ptr1. ; Must return an error code in a/x. ; STATUS: lda ACIA_STATUS ldx #0 sta (ptr1,x) txa ; SER_ERR_OK rts ;---------------------------------------------------------------------------- ; IOCTL: Driver defined entry point. The wrapper will pass a pointer to ioctl ; specific data in ptr1, and the ioctl code in A. ; Must return an error code in a/x. ; IOCTL: lda #<SER_ERR_INV_IOCTL ; We don't support ioclts for now ldx #>SER_ERR_INV_IOCTL rts ; Run into IRQ instead ;---------------------------------------------------------------------------- ; IRQ: Called from the builtin runtime IRQ handler as a subroutine. All ; registers are already save, no parameters are passed, but the carry flag ; is clear on entry. The routine must return with carry set if the interrupt ; was handled, otherwise with carry clear. ; IRQ: lda ACIA_STATUS ; Check ACIA status for receive interrupt and #$08 beq @L9 ; Jump if no ACIA interrupt (carry still clear) lda ACIA_DATA ; Get byte from ACIA ldx RecvFreeCnt ; Check if we have free space left beq @L1 ; Jump if no space in receive buffer ldy RecvTail ; Load buffer pointer sta RecvBuf,y ; Store received byte in buffer inc RecvTail ; Increment buffer pointer dec RecvFreeCnt ; Decrement free space counter cpx #33 ; Check for buffer space low bcc @L1 ; Assert flow control if buffer space low rts ; Return with carry set (interrupt handled) ; Assert flow control if buffer space too low @L1: lda RtsOff sta ACIA_CMD sta Stopped sec ; Interrupt handled @L9: rts ;---------------------------------------------------------------------------- ; Try to send a byte. Internal routine. A = TryHard .proc TryToSend sta tmp1 ; Remember tryHard flag @L0: lda SendFreeCnt cmp #$ff beq @L3 ; Bail out ; Check for flow stopped @L1: lda Stopped bne @L3 ; Bail out ; Check that swiftlink is ready to send @L2: lda ACIA_STATUS and #$10 bne @L4 bit tmp1 ;keep trying if must try hard bmi @L0 @L3: rts ; Send byte and try again @L4: ldx SendHead lda SendBuf,x sta ACIA_DATA inc SendHead inc SendFreeCnt jmp @L0 .endproc
wagiminator/C64-Collection
1,305
C64_xu1541/software/tools/cc65-2.13.2/libsrc/plus4/ksetnam.s
; ; Ullrich von Bassewitz, 22.11.2002 ; ; SETNAM replacement function ; .export SETNAM .include "plus4.inc" ; This function is special in that the name must reside in low memory, ; otherwise it is not accessible by the ROM code. .segment "LOWCODE" ; Must go into low memory .proc SETNAM ; Store the length of the name into the zero page sta FNAM_LEN ; Check if we have to copy the name to low memory cmp #$00 ; Length zero? beq @L3 ; Yes: Copying not needed cpy #$00 ; Is the name in low memory? bpl @L3 ; Yes: Copying not needed ; Store the length and the pointer to the name stx TMPPTR sty TMPPTR+1 ; Store pointer to name in TMPPTR ; Copy the given name into FNBUF. ldy #$00 @L2: lda (TMPPTR),y sta FNBUF,y iny cpy FNAM_LEN bne @L2 ; Load the new parameters for the low memory buffer ldx #<FNBUF ldy #>FNBUF ; Instead of banking in the ROM, store the values directly into the zeropage @L3: stx FNAM sty FNAM+1 ; Return to caller rts .endproc
wagiminator/C64-Collection
3,991
C64_xu1541/software/tools/cc65-2.13.2/libsrc/plus4/mainargs.s
; mainargs.s ; ; Ullrich von Bassewitz, 2003-03-07 ; Based on code from Stefan A. Haubenthal, <polluks@web.de> ; 2003-05-18, Greg King ; 2004-04-28, 2005-02-26, Ullrich von Bassewitz ; ; Scan a group of arguments that are in BASIC's input-buffer. ; Build an array that points to the beginning of each argument. ; Send, to main(), that array and the count of the arguments. ; ; Command-lines look like these lines: ; ; run ; run : rem ; run:rem arg1 " arg 2 is quoted " arg3 "" arg5 ; ; "run" and "rem" are entokenned; the args. are not. Leading and trailing ; spaces outside of quotes are ignored. ; ; TO-DO: ; - The "file-name" might be a path-name; don't copy the directory-components. ; - Add a control-character quoting mechanism. .constructor initmainargs, 24 .import __argc, __argv .include "plus4.inc" MAXARGS = 10 ; Maximum number of arguments allowed REM = $8f ; BASIC token-code NAME_LEN = 16 ; maximum length of command-name ; Get possible command-line arguments. Goes into the special INIT segment, ; which may be reused after the startup code is run .segment "INIT" initmainargs: ; Assume that the program was loaded, a moment ago, by the traditional LOAD ; statement. Save the "most-recent filename" as argument #0. ; Because the buffer, that we're copying into, was zeroed out, ; we don't need to add a NUL character. ; ldy FNAM_LEN cpy #NAME_LEN + 1 bcc L1 ldy #NAME_LEN - 1 ; limit the length L0: lda (FNAM),y sta name,y L1: dey bpl L0 inc __argc ; argc always is equal to, at least, 1 ; Find the "rem" token. ; ldx #0 L2: lda BASIC_BUF,x beq done ; no "rem," no args. inx cmp #REM bne L2 ldy #1 * 2 ; Find the next argument next: lda BASIC_BUF,x beq done ; End of line reached inx cmp #' ' ; Skip leading spaces beq next ; ; Found start of next argument. We've incremented the pointer in X already, so ; it points to the second character of the argument. This is useful since we ; will check now for a quoted argument, in which case we will have to skip this ; first character. found: cmp #'"' ; Is the argument quoted? beq setterm ; Jump if so dex ; Reset pointer to first argument character lda #' ' ; A space ends the argument setterm:sta term ; Set end of argument marker ; Now store a pointer to the argument into the next slot. Since the BASIC ; input buffer is located at the start of a RAM page, no calculations are ; necessary. txa ; Get low byte sta argv,y ; argv[y]= &arg iny lda #>BASIC_BUF sta argv,y iny inc __argc ; Found another arg ; Search for the end of the argument argloop:lda BASIC_BUF,x beq done inx cmp term bne argloop ; We've found the end of the argument. X points one character behind it, and ; A contains the terminating character. To make the argument a valid C string, ; replace the terminating character by a zero. lda #0 sta BASIC_BUF-1,x ; Check if the maximum number of command line arguments is reached. If not, ; parse the next one. lda __argc ; Get low byte of argument count cmp #MAXARGS ; Maximum number of arguments reached? bcc next ; Parse next one if not ; (The last vector in argv[] already is NULL.) done: lda #<argv ldx #>argv sta __argv stx __argv + 1 rts ; -------------------------------------------------------------------------- ; These arrays are zeroed before initmainargs is called. ; char name[16+1]; ; char* argv[MAXARGS+1]={name}; ; .bss term: .res 1 name: .res NAME_LEN + 1 .data argv: .addr name .res MAXARGS * 2
wagiminator/C64-Collection
1,852
C64_xu1541/software/tools/cc65-2.13.2/libsrc/plus4/cputc.s
; ; Ullrich von Bassewitz, 06.08.1998 ; ; void cputcxy (unsigned char x, unsigned char y, char c); ; void cputc (char c); ; .export _cputcxy, _cputc, cputdirect, putchar .export newline, plot .import popa, _gotoxy .import PLOT .include "plus4.inc" _cputcxy: pha ; Save C jsr popa ; Get Y jsr _gotoxy ; Set cursor, drop x 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 ; Printable char of some sort cmp #' ' bcc cputdirect ; Other control char tay bmi L10 cmp #$60 bcc L2 and #$DF bne cputdirect ; Branch always L2: and #$3F cputdirect: jsr putchar ; Write the character to the screen ; Advance cursor position advance: iny cpy #XSIZE bne L3 jsr newline ; new line ldy #0 ; + cr L3: sty CURS_X rts newline: clc lda #XSIZE adc SCREEN_PTR sta SCREEN_PTR bcc L4 inc SCREEN_PTR+1 clc L4: lda #XSIZE adc CRAM_PTR sta CRAM_PTR bcc L5 inc CRAM_PTR+1 L5: inc CURS_Y rts ; Handle character if high bit set L10: and #$7F cmp #$7E ; PI? bne L11 lda #$5E ; Load screen code for PI bne cputdirect L11: ora #$40 bne cputdirect ; Set cursor position, calculate RAM pointers plot: ldy CURS_X ldx CURS_Y clc jmp PLOT ; Set the new cursor ; Write one character to the screen without doing anything else, return X ; position in Y putchar: ora RVS ; Set revers bit ldy CURS_X sta (SCREEN_PTR),y ; Set char lda CHARCOLOR sta (CRAM_PTR),y ; Set color rts
wagiminator/C64-Collection
1,331
C64_xu1541/software/tools/cc65-2.13.2/libsrc/plus4/break.s
; ; Ullrich von Bassewitz, 27.09.1998 ; ; void set_brk (unsigned Addr); ; void reset_brk (void); ; .export _set_brk, _reset_brk .export _brk_a, _brk_x, _brk_y, _brk_sr, _brk_pc .import brk_jmp .include "plus4.inc" .bss _brk_a: .res 1 _brk_x: .res 1 _brk_y: .res 1 _brk_sr: .res 1 _brk_pc: .res 2 oldvec: .res 2 ; Old vector .data uservec: jmp $FFFF ; Patched at runtime .code ; Set the break vector .proc _set_brk sta uservec+1 stx uservec+2 ; Set the user vector lda #<brk_handler ; Set the break vector to our routine sta brk_jmp+1 lda #>brk_handler sta brk_jmp+2 rts .endproc ; Reset the break vector .proc _reset_brk lda #$00 sta brk_jmp+1 sta brk_jmp+2 ; Reset the vector rts .endproc ; Break handler, called if a break occurs. .proc brk_handler pla sta _brk_y pla sta _brk_x pla sta _brk_a pla and #$EF ; Clear break bit sta _brk_sr pla ; PC low sec sbc #2 ; Point to start of brk sta _brk_pc pla ; PC high sbc #0 sta _brk_pc+1 jsr uservec ; Call the user's routine lda _brk_pc+1 pha lda _brk_pc pha lda _brk_sr pha ldx _brk_x ldy _brk_y lda _brk_a rti ; Jump back... .endproc
wagiminator/C64-Collection
2,256
C64_xu1541/software/tools/cc65-2.13.2/libsrc/plus4/cgetc.s
; ; Ullrich von Bassewitz, 06.08.1998 ; ; char cgetc (void); ; .export _cgetc .import cursor .include "plus4.inc" ; -------------------------------------------------------------------------- .segment "LOWCODE" ; Accesses the ROM - must go into low mem _cgetc: lda KEY_COUNT ; Get number of characters ora FKEY_COUNT ; Or with number of function key chars bne L2 ; Jump if there are already chars waiting ; Switch on the cursor if needed ldy CURS_X lda (CRAM_PTR),y ; Get current char pha ; And save it lda CHARCOLOR sta (CRAM_PTR),y lda cursor beq L1 ; Jump if no cursor tya clc adc SCREEN_PTR sta TED_CURSLO lda SCREEN_PTR+1 adc #$00 sbc #$0B ; + carry = $C00 (screen address) sta TED_CURSHI L1: lda KEY_COUNT ora FKEY_COUNT beq L1 pla sta (CRAM_PTR),y lda #$ff sta TED_CURSLO ; Cursor off sta TED_CURSHI L2: sta ENABLE_ROM ; Bank in the ROM jsr KBDREAD ; Read char and return in A (ROM routine) sta ENABLE_RAM ; Reenable the RAM ldx #0 rts ; -------------------------------------------------------------------------- ; Make the function keys return function key codes instead of the current ; strings so the program will see and may handle them. ; Undo this change when the program ends .constructor initkbd .destructor donekbd .segment "INIT" ; Special init code segment may get overwritten .proc initkbd ldy #15 @L1: lda fnkeys,y sta FKEY_SPACE,y dey bpl @L1 rts .endproc .segment "LOWCODE" ; Accesses the ROM - must go into low mem .proc donekbd ldx #$39 ; Copy the original function keys sta ENABLE_ROM ; Bank in the ROM @L1: lda FKEY_ORIG,x sta FKEY_SPACE,x dex bpl @L1 sta ENABLE_RAM ; Bank out the ROM rts .endproc ; Function key table, readonly .rodata fnkeys: .byte $01, $01, $01, $01, $01, $01, $01, $01 .byte 133, 137, 134, 138, 135, 139, 136, 140
wagiminator/C64-Collection
3,045
C64_xu1541/software/tools/cc65-2.13.2/libsrc/c16/crt0.s
; ; Startup code for cc65 (C16 version) ; ; Note: The C16 is actually the Plus/4 with just 16KB of memory. So many ; things are similar here, and we even use the plus4.inc include file. ; .export _exit .export __STARTUP__ : absolute = 1 ; Mark as startup .import initlib, donelib, callirq .import callmain, zerobss .import MEMTOP, RESTOR, BSOUT, CLRCH .import __INTERRUPTOR_COUNT__ .include "zeropage.inc" .include "plus4.inc" ; ------------------------------------------------------------------------ ; Place the startup code in a special segment. .segment "STARTUP" ; BASIC header with a SYS call .word Head ; Load address Head: .word @Next .word .version ; Line number .byte $9E,"4109" ; SYS 4109 .byte $00 ; End of BASIC line @Next: .word 0 ; BASIC end marker ; ------------------------------------------------------------------------ ; Actual code ldx #zpspace-1 L1: lda sp,x sta zpsave,x ; save the zero page locations we need dex bpl L1 ; Close open files jsr CLRCH ; Switch to second charset lda #14 jsr BSOUT ; Clear the BSS data jsr zerobss ; Save system stuff and setup the stack tsx stx spsave ; save system stk ptr sec jsr MEMTOP ; Get top memory cpy #$80 ; We can only use the low 32K :-( bcc MemOk ldy #$80 ldx #$00 MemOk: stx sp sty sp+1 ; set argument stack ptr ; If we have IRQ functions, chain our stub into the IRQ vector lda #<__INTERRUPTOR_COUNT__ beq NoIRQ1 lda IRQVec ldx IRQVec+1 sta IRQInd+1 stx IRQInd+2 lda #<IRQStub ldx #>IRQStub sei sta IRQVec stx IRQVec+1 cli ; Call module constructors NoIRQ1: jsr initlib ; Push arguments and call main() jsr callmain ; Call module destructors. This is also the _exit entry. _exit: pha ; Save the return code on stack jsr donelib ; Run module destructors ; Reset the IRQ vector if we chained it. pha ; Save the return code on stack lda #<__INTERRUPTOR_COUNT__ beq NoIRQ2 lda IRQInd+1 ldx IRQInd+2 sei sta IRQVec stx IRQVec+1 cli ; Copy back the zero page stuff NoIRQ2: ldx #zpspace-1 L2: lda zpsave,x sta sp,x dex bpl L2 ; Store the return code into ST pla sta ST ; Restore the stack pointer ldx spsave txs ; Reset changed vectors jmp RESTOR ; ------------------------------------------------------------------------ ; The IRQ vector jumps here, if condes routines are defined with type 2. IRQStub: cld ; Just to be sure jsr callirq ; Call the functions jmp IRQInd ; Jump to the saved IRQ vector ; ------------------------------------------------------------------------ ; Data .data IRQInd: jmp $0000 .segment "ZPSAVE" zpsave: .res zpspace .bss spsave: .res 1
wagiminator/C64-Collection
6,797
C64_xu1541/software/tools/cc65-2.13.2/libsrc/c16/c16-ram.s
; ; Extended memory driver for the C16 hidden RAM. Driver works without ; problems when statically linked. ; ; Ullrich von Bassewitz, 2003-12-15 ; .include "zeropage.inc" .include "em-kernel.inc" .include "em-error.inc" .include "plus4.inc" .macpack generic ; ------------------------------------------------------------------------ ; Header. Includes jump table .segment "JUMPTABLE" ; Driver signature .byte $65, $6d, $64 ; "emd" .byte EMD_API_VERSION ; EM API version number ; Jump table. .word INSTALL .word UNINSTALL .word PAGECOUNT .word MAP .word USE .word COMMIT .word COPYFROM .word COPYTO ; ------------------------------------------------------------------------ ; Constants BASE = $8000 ; ------------------------------------------------------------------------ ; Data. .bss pages: .res 1 ; Number of pages curpage: .res 1 ; Current page number window: .res 256 ; Memory "window" .code ; ------------------------------------------------------------------------ ; INSTALL routine. Is called after the driver is loaded into memory. If ; possible, check if the hardware is present and determine the amount of ; memory available. ; Must return an EM_ERR_xx code in a/x. ; INSTALL: ; Determine how much memory is available. We will use all memory above ; $8000 up to MEMTOP sec jsr $FF99 ; MEMTOP: Get top memory into Y/X tya sub #>BASE ; Low 32 K are used bcc nomem beq nomem ; Offering zero pages is a bad idea sta pages ldx #$FF stx curpage ; Invalidate the current page inx ; X = 0 txa ; A = X = EM_ERR_OK rts nomem: ldx #>EM_ERR_NO_DEVICE lda #<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 pages ldx #$00 ; 128 pages max 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 add #>BASE sta ptr1+1 ldy #$00 sty ptr1 lda #<window sta ptr2 lda #>window sta ptr2+1 ; Transfer one page jsr transfer ; Transfer one page ; Return the memory window lda #<window ldx #>window ; Return the window address rts ; ------------------------------------------------------------------------ ; USE: Tell the driver that the window is now associated with a given page. USE: sta curpage ; Remember the page lda #<window ldx #>window ; Return the window rts ; ------------------------------------------------------------------------ ; COMMIT: Commit changes in the memory window to extended storage. COMMIT: lda curpage ; Get the current page bmi done ; Jump if no page mapped add #>BASE sta ptr2+1 ldy #$00 sty ptr2 lda #<window sta ptr1 lda #>window sta ptr1+1 ; Transfer one page. Y must be zero on entry. Because we bank out the ; kernal, we will run the routine with interrupts disabled but leave ; short breath times. Unroll the following loop to make it somewhat faster. transfer: sei sta ENABLE_RAM .repeat 8 lda (ptr1),y sta (ptr2),y iny .endrepeat sta ENABLE_ROM cli bne transfer ; Done done: rts ; ------------------------------------------------------------------------ ; COPYFROM: Copy from extended into linear memory. A pointer to a structure ; describing the request is passed in a/x. ; The function must not return anything. ; COPYFROM: sta ptr3 stx ptr3+1 ; Save the passed em_copy pointer ldy #EM_COPY::OFFS lda (ptr3),y sta ptr1 ldy #EM_COPY::PAGE lda (ptr3),y add #>BASE sta ptr1+1 ; From ldy #EM_COPY::BUF lda (ptr3),y sta ptr2 iny lda (ptr3),y sta ptr2+1 ; To common: ldy #EM_COPY::COUNT+1 lda (ptr3),y ; Get number of pages beq @L2 ; Skip if no full pages sta tmp1 ; Copy full pages allowing interrupts after each page copied ldy #$00 @L1: jsr transfer inc ptr1+1 inc ptr2+1 dec tmp1 bne @L1 ; Copy the remainder of the page @L2: ldy #EM_COPY::COUNT lda (ptr3),y ; Get bytes in last page beq @L4 tax sei ; Disable ints sta ENABLE_RAM ; Bank out the ROM ; Transfer the bytes in the last page ldy #$00 @L3: lda (ptr1),y sta (ptr2),y iny dex bne @L3 ; Restore the old memory configuration, allow interrupts sta ENABLE_ROM cli ; Done @L4: rts ; ------------------------------------------------------------------------ ; COPYTO: Copy from linear into extended memory. A pointer to a structure ; describing the request is passed in a/x. ; The function must not return anything. ; COPYTO: sta ptr3 stx ptr3+1 ; Save the passed em_copy pointer ldy #EM_COPY::OFFS lda (ptr3),y sta ptr2 ldy #EM_COPY::PAGE lda (ptr3),y add #>BASE sta ptr2+1 ; To ldy #EM_COPY::BUF lda (ptr3),y sta ptr1 iny lda (ptr3),y sta ptr1+1 ; From jmp common
wagiminator/C64-Collection
1,948
C64_xu1541/software/tools/cc65-2.13.2/libsrc/c16/kernal.s
; ; Ullrich von Bassewitz, 19.11.2002 ; ; C16 kernal functions ; .export CINT .export IOINIT .export RAMTAS .export RESTOR .export VECTOR .export SETMSG .export SECOND .export TKSA .export MEMTOP .export MEMBOT .export SCNKEY .export SETTMO .export ACPTR .export CIOUT .export UNTLK .export UNLSN .export LISTEN .export TALK .export READST .export SETLFS .export SETNAM .export OPEN .export CHKIN .export CKOUT .export CLRCH .export BASIN .export BSOUT .export LOAD .export SAVE .export SETTIM .export RDTIM .export STOP .export GETIN .export CLALL .export UDTIM .export SCREEN .export PLOT .export IOBASE ;----------------------------------------------------------------------------- ; All functions are available in the kernal jump table CINT = $FF81 IOINIT = $FF84 RAMTAS = $FF87 RESTOR = $FF8A VECTOR = $FF8D SETMSG = $FF90 SECOND = $FF93 TKSA = $FF96 MEMTOP = $FF99 MEMBOT = $FF9C SCNKEY = $FF9F SETTMO = $FFA2 ACPTR = $FFA5 CIOUT = $FFA8 UNTLK = $FFAB UNLSN = $FFAE LISTEN = $FFB1 TALK = $FFB4 READST = $FFB7 SETLFS = $FFBA SETNAM = $FFBD OPEN = $FFC0 ;CLOSE = $FFC3 CHKIN = $FFC6 CKOUT = $FFC9 CLRCH = $FFCC BASIN = $FFCF BSOUT = $FFD2 LOAD = $FFD5 SAVE = $FFD8 SETTIM = $FFDB RDTIM = $FFDE STOP = $FFE1 GETIN = $FFE4 CLALL = $FFE7 UDTIM = $FFEA SCREEN = $FFED PLOT = $FFF0 IOBASE = $FFF3
wagiminator/C64-Collection
3,901
C64_xu1541/software/tools/cc65-2.13.2/libsrc/c16/mainargs.s
; mainargs.s ; ; Ullrich von Bassewitz, 2003-03-07 ; Based on code from Stefan A. Haubenthal, <polluks@web.de> ; 2003-05-18, Greg King ; 2004-04-28, 2005-02-26, Ullrich von Bassewitz ; ; Scan a group of arguments that are in BASIC's input-buffer. ; Build an array that points to the beginning of each argument. ; Send, to main(), that array and the count of the arguments. ; ; Command-lines look like these lines: ; ; run ; run : rem ; run:rem arg1 " arg 2 is quoted " arg3 "" arg5 ; ; "run" and "rem" are entokenned; the args. are not. Leading and trailing ; spaces outside of quotes are ignored. ; ; TO-DO: ; - The "file-name" might be a path-name; don't copy the directory-components. ; - Add a control-character quoting mechanism. .constructor initmainargs, 24 .import __argc, __argv .include "plus4.inc" MAXARGS = 10 ; Maximum number of arguments allowed REM = $8f ; BASIC token-code NAME_LEN = 16 ; maximum length of command-name ; Get possible command-line arguments. Goes into the special INIT segment, ; which may be reused after the startup code is run .segment "INIT" initmainargs: ; Assume that the program was loaded, a moment ago, by the traditional LOAD ; statement. Save the "most-recent filename" as argument #0. ; Because the buffer, that we're copying into, was zeroed out, ; we don't need to add a NUL character. ; ldy FNAM_LEN cpy #NAME_LEN + 1 bcc L1 ldy #NAME_LEN - 1 ; limit the length L0: lda #FNAM ; Vector address jsr FETCH ; Load byte from RAM sta name,y L1: dey bpl L0 inc __argc ; argc always is equal to, at least, 1 ; Find the "rem" token. ; ldx #0 L2: lda BASIC_BUF,x beq done ; no "rem," no args. inx cmp #REM bne L2 ldy #1 * 2 ; Find the next argument next: lda BASIC_BUF,x beq done ; End of line reached inx cmp #' ' ; Skip leading spaces beq next ; ; Found start of next argument. We've incremented the pointer in X already, so ; it points to the second character of the argument. This is useful since we ; will check now for a quoted argument, in which case we will have to skip this ; first character. found: cmp #'"' ; Is the argument quoted? beq setterm ; Jump if so dex ; Reset pointer to first argument character lda #' ' ; A space ends the argument setterm:sta term ; Set end of argument marker ; Now store a pointer to the argument into the next slot. Since the BASIC ; input buffer is located at the start of a RAM page, no calculations are ; necessary. txa ; Get low byte sta argv,y ; argv[y]= &arg iny lda #>BASIC_BUF sta argv,y iny inc __argc ; Found another arg ; Search for the end of the argument argloop:lda BASIC_BUF,x beq done inx cmp term bne argloop ; We've found the end of the argument. X points one character behind it, and ; A contains the terminating character. To make the argument a valid C string, ; replace the terminating character by a zero. lda #0 sta BASIC_BUF-1,x ; Check if the maximum number of command line arguments is reached. If not, ; parse the next one. lda __argc ; Get low byte of argument count cmp #MAXARGS ; Maximum number of arguments reached? bcc next ; Parse next one if not ; (The last vector in argv[] already is NULL.) done: lda #<argv ldx #>argv sta __argv stx __argv + 1 rts ; These arrays are zeroed before initmainargs is called. ; char name[16+1]; ; char* argv[MAXARGS+1]={name}; ; .bss term: .res 1 name: .res NAME_LEN + 1 .data argv: .addr name .res MAXARGS * 2
wagiminator/C64-Collection
1,852
C64_xu1541/software/tools/cc65-2.13.2/libsrc/c16/cputc.s
; ; Ullrich von Bassewitz, 06.08.1998 ; ; void cputcxy (unsigned char x, unsigned char y, char c); ; void cputc (char c); ; .export _cputcxy, _cputc, cputdirect, putchar .export newline, plot .import popa, _gotoxy .import PLOT .include "plus4.inc" _cputcxy: pha ; Save C jsr popa ; Get Y jsr _gotoxy ; Set cursor, drop x 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 ; Printable char of some sort cmp #' ' bcc cputdirect ; Other control char tay bmi L10 cmp #$60 bcc L2 and #$DF bne cputdirect ; Branch always L2: and #$3F cputdirect: jsr putchar ; Write the character to the screen ; Advance cursor position advance: iny cpy #XSIZE bne L3 jsr newline ; new line ldy #0 ; + cr L3: sty CURS_X rts newline: clc lda #XSIZE adc SCREEN_PTR sta SCREEN_PTR bcc L4 inc SCREEN_PTR+1 clc L4: lda #XSIZE adc CRAM_PTR sta CRAM_PTR bcc L5 inc CRAM_PTR+1 L5: inc CURS_Y rts ; Handle character if high bit set L10: and #$7F cmp #$7E ; PI? bne L11 lda #$5E ; Load screen code for PI bne cputdirect L11: ora #$40 bne cputdirect ; Set cursor position, calculate RAM pointers plot: ldy CURS_X ldx CURS_Y clc jmp PLOT ; Set the new cursor ; Write one character to the screen without doing anything else, return X ; position in Y putchar: ora RVS ; Set revers bit ldy CURS_X sta (SCREEN_PTR),y ; Set char lda CHARCOLOR sta (CRAM_PTR),y ; Set color rts
wagiminator/C64-Collection
1,548
C64_xu1541/software/tools/cc65-2.13.2/libsrc/c16/break.s
; ; Ullrich von Bassewitz, 27.09.1998 ; ; void set_brk (unsigned Addr); ; void reset_brk (void); ; .export _set_brk, _reset_brk .destructor _reset_brk .export _brk_a, _brk_x, _brk_y, _brk_sr, _brk_pc .include "plus4.inc" .bss _brk_a: .res 1 _brk_x: .res 1 _brk_y: .res 1 _brk_sr: .res 1 _brk_pc: .res 2 oldvec: .res 2 ; Old vector .data uservec: jmp $FFFF ; Patched at runtime .code ; Set the break vector .proc _set_brk sta uservec+1 stx uservec+2 ; Set the user vector lda oldvec ora oldvec+1 ; Did we save the vector already? bne L1 ; Jump if we installed the handler already lda BRKVec sta oldvec lda BRKVec+1 sta oldvec+1 ; Save the old vector L1: lda #<brk_handler ; Set the break vector to our routine ldx #>brk_handler sta BRKVec stx BRKVec+1 rts .endproc ; Reset the break vector .proc _reset_brk lda oldvec ldx oldvec+1 beq @L9 ; Jump if vector not installed sta BRKVec stx BRKVec+1 lda #$00 sta oldvec ; Clear the old vector stx oldvec+1 @L9: rts .endproc ; Break handler, called if a break occurs .proc brk_handler pla sta _brk_y pla sta _brk_x pla sta _brk_a pla and #$EF ; Clear break bit sta _brk_sr pla ; PC low sec sbc #2 ; Point to start of brk sta _brk_pc pla ; PC high sbc #0 sta _brk_pc+1 jsr uservec ; Call the user's routine lda _brk_pc+1 pha lda _brk_pc pha lda _brk_sr pha ldx _brk_x ldy _brk_y lda _brk_a rti ; Jump back... .endproc
wagiminator/C64-Collection
1,841
C64_xu1541/software/tools/cc65-2.13.2/libsrc/c16/cgetc.s
; ; Ullrich von Bassewitz, 06.08.1998 ; ; char cgetc (void); ; .export _cgetc .import cursor .include "plus4.inc" ; -------------------------------------------------------------------------- _cgetc: lda KEY_COUNT ; Get number of characters ora FKEY_COUNT ; Or with number of function key chars bne L2 ; Jump if there are already chars waiting ; Switch on the cursor if needed ldy CURS_X lda (CRAM_PTR),y ; Get current char pha ; And save it lda CHARCOLOR sta (CRAM_PTR),y lda cursor beq L1 ; Jump if no cursor tya clc adc SCREEN_PTR sta TED_CURSLO lda SCREEN_PTR+1 adc #$00 sbc #$0B ; + carry = $C00 (screen address) sta TED_CURSHI L1: lda KEY_COUNT ora FKEY_COUNT beq L1 pla sta (CRAM_PTR),y lda #$ff sta TED_CURSLO ; Cursor off sta TED_CURSHI L2: jsr KBDREAD ; Read char and return in A ldx #0 rts ; -------------------------------------------------------------------------- ; Make the function keys return function key codes instead of the current ; strings so the program will see and may handle them. ; Undo this change when the program ends .constructor initkbd .destructor donekbd .segment "INIT" .proc initkbd ldy #15 @L1: lda fnkeys,y sta FKEY_SPACE,y dey bpl @L1 rts .endproc .code .proc donekbd ldx #$39 ; Copy the original function keys @L1: lda FKEY_ORIG,x sta FKEY_SPACE,x dex bpl @L1 rts .endproc ; Function key table, readonly .rodata fnkeys: .byte $01, $01, $01, $01, $01, $01, $01, $01 .byte 133, 137, 134, 138, 135, 139, 136, 140
wagiminator/C64-Collection
6,567
C64_xu1541/software/tools/cc65-2.13.2/libsrc/c64/dtv-himem.s
; ; Extended memory driver for the C64 D2TV (the second or PAL version). ; Driver works without problems when statically linked. ; ; Ullrich von Bassewitz, 2005-11-27 ; .include "zeropage.inc" .include "em-kernel.inc" .include "em-error.inc" .macpack generic ; ------------------------------------------------------------------------ ; Header. Includes jump table .segment "JUMPTABLE" ; Driver signature .byte $65, $6d, $64 ; "emd" .byte EMD_API_VERSION ; EM API version number ; Jump table. .word INSTALL .word UNINSTALL .word PAGECOUNT .word MAP .word USE .word COMMIT .word COPYFROM .word COPYTO ; ------------------------------------------------------------------------ ; Constants OP_COPYFROM = %00001101 OP_COPYTO = %00001111 START_BANK = 2 ; Start at $20000 PAGES = (2048 - 128) * 4 ; ------------------------------------------------------------------------ ; Data. .bss window: .res 256 ; Memory "window" .data ; The MAP and COMMIT entries will actually call COPYFROM/COPYTO with ; a pointer to the following data structure: dma_params: .word window ; Host address .byte 0 ; Offset in page curpage: .word $0000 ; Page .word .sizeof (window); # bytes to move, lo, hi .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: lda #$01 sta $d03f ; Enable extended register access ldx #$FF stx curpage+1 ; Invalidate curpage inx ; X = 0 txa ; A/X = EM_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 ; ------------------------------------------------------------------------ ; PAGECOUNT: Return the total number of available pages in a/x. ; PAGECOUNT: lda #<PAGES ldx #>PAGES 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 stx curpage+1 ; Remember the new page lda #<dma_params ldx #>dma_params jsr COPYFROM ; Copy data into the window lda #<window ldx #>window ; Return the window address done: rts ; ------------------------------------------------------------------------ ; USE: Tell the driver that the window is now associated with a given page. USE: sta curpage stx curpage+1 ; Remember the page lda #<window ldx #>window ; Return the window rts ; ------------------------------------------------------------------------ ; COMMIT: Commit changes in the memory window to extended storage. COMMIT: lda curpage+1 ; Do we have a page mapped? bmi done ; Jump if no page mapped lda #<dma_params ldx #>dma_params ; Run into COPYTO ; ------------------------------------------------------------------------ ; 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 ptr1 stx ptr1+1 ; Save the pointer ldx #OP_COPYTO ; Load the command bne transfer ; ------------------------------------------------------------------------ ; 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 ptr1 stx ptr1+1 ; Save the pointer ldx #OP_COPYFROM ; DTV DMA transfer routine. Expects the command in X. ; NOTE: We're using knowledge about field order in the EM_COPY struct here! transfer: jsr WAIT ; Wait until DMA is finished ; Modulo disable ldy #$00 sty $d31e ; Setup the target address and the source and target steps. Y contains zero, ; which is EM_COPY::BUF. sty $d307 ; Source step high = 0 sty $d309 ; Dest step high = 0 lda (ptr1),y sta $d303 ; Dest address low iny ; Y = 1 sty $d306 ; Source step low = 1 sty $d308 ; Dest step low = 1 lda (ptr1),y sta $d304 lda #$40 ; Dest is always RAM, start at $00000 sta $d305 ; Setup the source address. Incrementing Y will make it point to EM_COPY::OFFS. ; We will allow page numbers higher than PAGES and map them to ROM. This will ; allow reading the ROM by specifying a page starting with PAGES. iny ; EM_COPY::OFFS lda (ptr1),y sta $d300 iny ; EM_COPY::PAGE lda (ptr1),y sta $d301 iny lda (ptr1),y adc #START_BANK ; Carry clear here from WAIT and #$3f cmp #>PAGES+START_BANK ; Valid range? bcs @L1 ; Jump if no ora #$40 ; Address RAM @L1: sta $d302 ; Length iny ; EM_COPY::COUNT lda (ptr1),y sta $d30a iny lda (ptr1),y sta $d30b ; Start DMA stx $d31f ; Wait until DMA is done WAIT: lda $d31f lsr a bcs WAIT rts
wagiminator/C64-Collection
7,756
C64_xu1541/software/tools/cc65-2.13.2/libsrc/c64/c64-vdc.s
; ; Extended memory driver for the VDC RAM available on all C128 machines ; (based on code by Ullrich von Bassewitz) ; Maciej 'YTM/Elysium' Witkowiak <ytm@elysium.pl> ; 06,20.12.2002 .include "zeropage.inc" .include "em-kernel.inc" .include "em-error.inc" .macpack generic ; ------------------------------------------------------------------------ ; Header. Includes jump table .segment "JUMPTABLE" ; Driver signature .byte $65, $6d, $64 ; "emd" .byte EMD_API_VERSION ; EM API version number ; Jump table. .word INSTALL .word UNINSTALL .word PAGECOUNT .word MAP .word USE .word COMMIT .word COPYFROM .word COPYTO ; ------------------------------------------------------------------------ ; Constants VDC_ADDR_REG = $D600 ; VDC address VDC_DATA_REG = $D601 ; VDC data VDC_DATA_HI = 18 ; used registers VDC_DATA_LO = 19 VDC_CSET = 28 VDC_DATA = 31 ; ------------------------------------------------------------------------ ; Data. .data pagecount: .word 64 ; $0000-$3fff as 16k default curpage: .word $ffff ; currently mapped-in page (invalid) .bss 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: ; do test for VDC presence here??? ldx #VDC_CSET ; determine size of RAM... jsr vdcgetreg sta tmp1 ora #%00010000 jsr vdcputreg ; turn on 64k jsr settestadr1 ; save original value of test byte jsr vdcgetbyte sta tmp2 lda #$55 ; write $55 here ldy #ptr1 jsr test64k ; read it here and there lda #$aa ; write $aa here ldy #ptr2 jsr test64k ; read it here and there jsr settestadr1 lda tmp2 jsr vdcputbyte ; restore original value of test byte lda ptr1 ; do bytes match? cmp ptr1+1 bne @have64k lda ptr2 cmp ptr2+1 bne @have64k ldx #VDC_CSET lda tmp1 jsr vdcputreg ; restore 16/64k flag jmp @endok ; and leave default values for 16k @have64k: lda #<256 ldx #>256 sta pagecount stx pagecount+1 @endok: lda #<EM_ERR_OK ldx #>EM_ERR_OK rts test64k: sta tmp1 sty ptr3 lda #0 sta ptr3+1 jsr settestadr1 lda tmp1 jsr vdcputbyte ; write $55 jsr settestadr1 jsr vdcgetbyte ; read here pha jsr settestadr2 jsr vdcgetbyte ; and there ldy #1 sta (ptr3),y pla dey sta (ptr3),y rts settestadr1: ldy #$02 ; test page 2 (here) .byte $2c settestadr2: ldy #$42 ; or page 64+2 (there) lda #0 jmp vdcsetsrcaddr ; ------------------------------------------------------------------------ ; UNINSTALL routine. Is called before the driver is removed from memory. ; Can do cleanup or whatever. Must not return anything. ; UNINSTALL: ;on C128 restore font and clear the screen? rts ; ------------------------------------------------------------------------ ; PAGECOUNT: Return the total number of available pages in a/x. ; PAGECOUNT: lda pagecount ldx pagecount+1 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 stx curpage+1 sta ptr1+1 ldy #0 sty ptr1 lda #<window sta ptr2 lda #>window sta ptr2+1 jsr transferin lda #<window ldx #>window rts ; copy a single page from (ptr1):VDCRAM to (ptr2):RAM transferin: lda ptr1 ldy ptr1+1 jsr vdcsetsrcaddr ; set source address in VDC ldy #0 ldx #VDC_DATA stx VDC_ADDR_REG @L0: bit VDC_ADDR_REG bpl @L0 lda VDC_DATA_REG ; get 2 bytes at a time to speed-up sta (ptr2),y ; (in fact up to 8 bytes could be fetched with special VDC config) iny lda VDC_DATA_REG sta (ptr2),y iny bne @L0 rts ; ------------------------------------------------------------------------ ; USE: Tell the driver that the window is now associated with a given page. USE: sta curpage stx curpage+1 ; Remember the page lda #<window ldx #>window ; Return the window done: rts ; ------------------------------------------------------------------------ ; COMMIT: Commit changes in the memory window to extended storage. COMMIT: lda curpage ; jump if no page mapped ldx curpage+1 bmi done sta ptr1+1 ldy #0 sty ptr1 lda #<window sta ptr2 lda #>window sta ptr2+1 ; fall through to transferout ; copy a single page from (ptr2):RAM to (ptr1):VDCRAM transferout: lda ptr1 ldy ptr1+1 jsr vdcsetsrcaddr ; set source address in VDC ldy #0 ldx #VDC_DATA stx VDC_ADDR_REG @L0: bit VDC_ADDR_REG bpl @L0 lda (ptr2),y ; speedup does not work for writing sta VDC_DATA_REG iny bne @L0 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: jsr setup beq @L2 ; Skip if no full pages ; Copy full pages @L1: jsr transferin inc ptr1+1 inc ptr2+1 dec tmp1 bne @L1 ; Copy the remainder of the page @L2: ldy #EM_COPY::COUNT lda (ptr3),y ; Get bytes in last page beq @L4 sta tmp1 ; Transfer the bytes in the last page ldy #0 @L3: jsr vdcgetbyte sta (ptr2),y iny dec tmp1 lda tmp1 bne @L3 @L4: rts ; ------------------------------------------------------------------------ ; COPYTO: Copy from linear into extended memory. A pointer to a structure ; describing the request is passed in a/x. ; The function must not return anything. ; COPYTO: jsr setup beq @L2 ; Skip if no full pages ; Copy full pages @L1: jsr transferout inc ptr1+1 inc ptr2+1 dec tmp1 bne @L1 ; Copy the remainder of the page @L2: ldy #EM_COPY::COUNT lda (ptr3),y ; Get bytes in last page beq @L4 sta tmp1 ; Transfer the bytes in the last page ldy #0 @L3: lda (ptr2),y jsr vdcputbyte iny dec tmp1 lda tmp1 bne @L3 @L4: rts ;------------------------------------------------------------------------- ; Helper functions to handle VDC ram ; vdcsetsrcaddr: ldx #VDC_DATA_LO stx VDC_ADDR_REG @L0: bit VDC_ADDR_REG bpl @L0 sta VDC_DATA_REG dex tya stx VDC_ADDR_REG sta VDC_DATA_REG rts vdcgetbyte: ldx #VDC_DATA vdcgetreg: stx VDC_ADDR_REG @L0: bit VDC_ADDR_REG bpl @L0 lda VDC_DATA_REG rts vdcputbyte: ldx #VDC_DATA vdcputreg: stx VDC_ADDR_REG @L0: bit VDC_ADDR_REG bpl @L0 sta VDC_DATA_REG rts ; ------------------------------------------------------------------------ ; Helper function for COPYFROM and COPYTO: Store the pointer to the request ; structure and prepare data for the copy ; setup: sta ptr3 stx ptr3+1 ; Save the passed em_copy pointer ldy #EM_COPY::OFFS lda (ptr3),y sta ptr1 ldy #EM_COPY::PAGE lda (ptr3),y sta ptr1+1 ; From ldy #EM_COPY::BUF lda (ptr3),y sta ptr2 iny lda (ptr3),y sta ptr2+1 ; To ldy #EM_COPY::COUNT+1 lda (ptr3),y ; Get number of pages sta tmp1 rts
wagiminator/C64-Collection
2,772
C64_xu1541/software/tools/cc65-2.13.2/libsrc/c64/c64-stdjoy.s
; ; Standard joystick driver for the C64. May be used multiple times when linked ; to the statically application. ; ; Ullrich von Bassewitz, 2002-12-20 ; .include "zeropage.inc" .include "joy-kernel.inc" .include "joy-error.inc" .include "c64.inc" .macpack generic ; ------------------------------------------------------------------------ ; Header. Includes jump table .segment "JUMPTABLE" ; Driver signature .byte $6A, $6F, $79 ; "joy" .byte JOY_API_VERSION ; 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 ; JOY_FIRE2 unavailable .byte $00 ; Future expansion .byte $00 ; Future expansion ; Jump table. .addr INSTALL .addr UNINSTALL .addr COUNT .addr READ .addr 0 ; IRQ entry unused ; ------------------------------------------------------------------------ ; 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: tax ; Joystick number into X bne joy2 ; Read joystick 1 joy1: lda #$7F sei sta CIA1_PRA lda CIA1_PRB cli and #$1F eor #$1F rts ; Read joystick 2 joy2: ldx #0 lda #$E0 ldy #$FF sei sta CIA1_DDRA lda CIA1_PRA sty CIA1_DDRA cli and #$1F eor #$1F rts
wagiminator/C64-Collection
2,666
C64_xu1541/software/tools/cc65-2.13.2/libsrc/c64/c64-numpad.s
; ; Joystick driver using C128 number pad in 64 mode. ; May be used multiple times when linked to the statically application. ; ; Stefan Haubenthal, 2004-01-26 ; Based on Ullrich von Bassewitz, 2002-12-20 ; .include "zeropage.inc" .include "joy-kernel.inc" .include "joy-error.inc" .include "c64.inc" .macpack generic ; ------------------------------------------------------------------------ ; Header. Includes jump table .segment "JUMPTABLE" ; Driver signature .byte $6A, $6F, $79 ; "joy" .byte JOY_API_VERSION ; Driver API version number ; 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 .addr UNINSTALL .addr COUNT .addr READ .addr 0 ; IRQ entry unused ; ------------------------------------------------------------------------ ; Constants JOY_COUNT = 1 ; 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 ; Assume we have a joystick ldx VIC_CLK_128 ; Test for a C128 cpx #$FF bne @C128 ; Jump if we have one lda #JOY_ERR_NO_DEVICE ; No C128 -> no numpad @C128: ldx #0 ; Set high byte ; 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 #0 rts ; ------------------------------------------------------------------------ ; READ: Read a particular joystick passed in A. ; READ: tax ; Clear high byte lda #$FD ldy #$FE sei sta VIC_KBD_128 lda CIA1_PRB and #%00110000 eor #%00110000 lsr lsr sty VIC_KBD_128 eor CIA1_PRB iny sty VIC_KBD_128 ; Reset to $FF cli and #%11111110 eor #%11111110 rts
wagiminator/C64-Collection
3,269
C64_xu1541/software/tools/cc65-2.13.2/libsrc/c64/crt0.s
; ; Startup code for cc65 (C64 version) ; .export _exit .export __STARTUP__ : absolute = 1 ; Mark as startup .import initlib, donelib, callirq .import zerobss .import callmain .import RESTOR, BSOUT, CLRCH .import __INTERRUPTOR_COUNT__ .import __RAM_START__, __RAM_SIZE__ ; Linker generated .include "zeropage.inc" .include "c64.inc" ; ------------------------------------------------------------------------ ; Place the startup code in a special segment. .segment "STARTUP" ; BASIC header with a SYS call .word Head ; Load address Head: .word @Next .word .version ; Line number .byte $9E,"2061" ; SYS 2061 .byte $00 ; End of BASIC line @Next: .word 0 ; BASIC end marker ; ------------------------------------------------------------------------ ; Actual code ldx #zpspace-1 L1: lda sp,x sta zpsave,x ; Save the zero page locations we need dex bpl L1 ; Close open files jsr CLRCH ; Switch to second charset lda #14 jsr BSOUT ; Switch off the BASIC ROM lda $01 pha ; Remember the value and #$F8 ora #$06 ; Enable kernal+I/O, disable basic sta $01 ; Clear the BSS data jsr zerobss ; Save system settings and setup the stack pla sta mmusave ; Save the memory configuration tsx stx spsave ; Save the system stack ptr lda #<(__RAM_START__ + __RAM_SIZE__) sta sp lda #>(__RAM_START__ + __RAM_SIZE__) sta sp+1 ; Set argument stack ptr ; If we have IRQ functions, chain our stub into the IRQ vector lda #<__INTERRUPTOR_COUNT__ beq NoIRQ1 lda IRQVec ldx IRQVec+1 sta IRQInd+1 stx IRQInd+2 lda #<IRQStub ldx #>IRQStub sei sta IRQVec stx IRQVec+1 cli ; Call module constructors NoIRQ1: jsr initlib ; Push arguments and call main jsr callmain ; Back from main (This is also the _exit entry). Run module destructors _exit: jsr donelib ; Reset the IRQ vector if we chained it. pha ; Save the return code on stack lda #<__INTERRUPTOR_COUNT__ beq NoIRQ2 lda IRQInd+1 ldx IRQInd+2 sei sta IRQVec stx IRQVec+1 cli ; Copy back the zero page stuff NoIRQ2: ldx #zpspace-1 L2: lda zpsave,x sta sp,x dex bpl L2 ; Place the program return code into ST pla sta ST ; Restore system stuff ldx spsave txs ; Restore stack pointer ldx mmusave stx $01 ; Restore memory configuration ; Reset changed vectors, back to basic jmp RESTOR ; ------------------------------------------------------------------------ ; The IRQ vector jumps here, if condes routines are defined with type 2. IRQStub: cld ; Just to be sure jsr callirq ; Call the functions jmp IRQInd ; Jump to the saved IRQ vector ; ------------------------------------------------------------------------ ; Data .data IRQInd: jmp $0000 .segment "ZPSAVE" zpsave: .res zpspace .bss spsave: .res 1 mmusave:.res 1
wagiminator/C64-Collection
6,628
C64_xu1541/software/tools/cc65-2.13.2/libsrc/c64/c64-georam.s
; ; Extended memory driver for the GEORAM cartridge. Driver works without ; problems when statically linked. ; ; Ullrich von Bassewitz, 2002-11-29 ; .include "zeropage.inc" .include "em-kernel.inc" .include "em-error.inc" .macpack generic ; ------------------------------------------------------------------------ ; Header. Includes jump table .segment "JUMPTABLE" ; Driver signature .byte $65, $6d, $64 ; "emd" .byte EMD_API_VERSION ; EM API version number ; Jump table. .word INSTALL .word UNINSTALL .word PAGECOUNT .word MAP .word USE .word COMMIT .word COPYFROM .word COPYTO ; ------------------------------------------------------------------------ ; Constants GR_WINDOW = $DE00 ; Address of GEORAM window GR_PAGE_LO = $DFFE ; Page register low GR_PAGE_HI = $DFFF ; Page register high ; ------------------------------------------------------------------------ ; Data. .data pagecount: .word 2048 ; Currently fixed .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: lda #<EM_ERR_OK ldx #>EM_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 ; ------------------------------------------------------------------------ ; PAGECOUNT: Return the total number of available pages in a/x. ; PAGECOUNT: lda pagecount ldx pagecount+1 rts ; ------------------------------------------------------------------------ ; USE: Tell the driver that the window is now associated with a given page. ; The GeoRAM cartridge does not copy but actually map the window, so USE is ; identical to MAP. USE = MAP ; ------------------------------------------------------------------------ ; 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 tmp1 txa asl tmp1 rol a asl tmp1 rol a sta GR_PAGE_HI lda tmp1 lsr a lsr a sta GR_PAGE_LO lda #<GR_WINDOW ldx #>GR_WINDOW ; Use the RTS from COMMIT below to save a precious byte of storage ; ------------------------------------------------------------------------ ; COMMIT: Commit changes in the memory window to extended storage. COMMIT: 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: jsr setup ; Setup is: ; ; - ptr1 contains the struct pointer ; - ptr2 contains the linear memory buffer ; - ptr3 contains -(count-1) ; - tmp1 contains the low page register value ; - tmp2 contains the high page register value ; - X contains the page offset ; - Y contains zero jmp @L5 @L1: lda GR_WINDOW,x sta (ptr2),y iny bne @L2 inc ptr2+1 @L2: inx beq @L4 ; Bump count and repeat @L3: inc ptr3 bne @L1 inc ptr3+1 bne @L1 rts ; Bump page register @L4: inc tmp1 ; Bump low page register bit tmp1 ; Check for overflow in bit 6 bvc @L6 ; Jump if no overflow inc tmp2 @L5: lda tmp2 sta GR_PAGE_HI @L6: lda tmp1 sta GR_PAGE_LO jmp @L3 ; ------------------------------------------------------------------------ ; 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: jsr setup ; Setup is: ; ; - ptr1 contains the struct pointer ; - ptr2 contains the linear memory buffer ; - ptr3 contains -(count-1) ; - tmp1 contains the low page register value ; - tmp2 contains the high page register value ; - X contains the page offset ; - Y contains zero jmp @L5 @L1: lda (ptr2),y sta GR_WINDOW,x iny bne @L2 inc ptr2+1 @L2: inx beq @L4 ; Bump count and repeat @L3: inc ptr3 bne @L1 inc ptr3+1 bne @L1 rts ; Bump page register @L4: inc tmp1 ; Bump low page register bit tmp1 ; Check for overflow in bit 6 bvc @L6 ; Jump if no overflow inc tmp2 @L5: lda tmp2 sta GR_PAGE_HI @L6: lda tmp1 sta GR_PAGE_LO jmp @L3 ; ------------------------------------------------------------------------ ; Helper function for COPYFROM and COPYTO: Store the pointer to the request ; structure and prepare data for the copy setup: sta ptr1 stx ptr1+1 ; Save passed pointer ; Get the page number from the struct and adjust it so that it may be used ; with the hardware. That is: lower 6 bits in tmp1, high bits in tmp2. ldy #EM_COPY::PAGE+1 lda (ptr1),y sta tmp2 dey lda (ptr1),y asl a rol tmp2 asl a rol tmp2 lsr a lsr a sta tmp1 ; Get the buffer pointer into ptr2 ldy #EM_COPY::BUF lda (ptr1),y sta ptr2 iny lda (ptr1),y sta ptr2+1 ; Get the count, calculate -(count-1) and store it into ptr3 ldy #EM_COPY::COUNT lda (ptr1),y eor #$FF sta ptr3 iny lda (ptr1),y eor #$FF sta ptr3+1 ; Get the page offset into X and clear Y ldy #EM_COPY::OFFS lda (ptr1),y tax ldy #$00 ; Done rts
wagiminator/C64-Collection
6,881
C64_xu1541/software/tools/cc65-2.13.2/libsrc/c64/c64-reu.s
; ; Extended memory driver for the Commodore REU. Driver works without ; problems when statically linked. ; ; Ullrich von Bassewitz, 2002-11-29 ; .include "zeropage.inc" .include "em-kernel.inc" .include "em-error.inc" .macpack generic ; ------------------------------------------------------------------------ ; Header. Includes jump table .segment "JUMPTABLE" ; Driver signature .byte $65, $6d, $64 ; "emd" .byte EMD_API_VERSION ; EM API version number ; Jump table. .word INSTALL .word UNINSTALL .word PAGECOUNT .word MAP .word USE .word COMMIT .word COPYFROM .word COPYTO ; ------------------------------------------------------------------------ ; Constants REU_STATUS = $DF00 ; Status register REU_COMMAND = $DF01 ; Command register REU_C64ADDR = $DF02 ; C64 base address register REU_REUADDR = $DF04 ; REU base address register REU_COUNT = $DF07 ; Transfer count register REU_IRQMASK = $DF09 ; IRQ mask register REU_CONTROL = $DF0A ; Control register REU_TRIGGER = $FF00 ; REU command trigger OP_COPYFROM = $ED OP_COPYTO = $EC ; ------------------------------------------------------------------------ ; Data. .bss pagecount: .res 2 ; Number of pages available curpage: .res 2 ; Current page number window: .res 256 ; Memory "window" reu_params: .word $0000 ; Host address, lo, hi .word $0000 ; Exp address, lo, hi .byte $00 ; Expansion bank no. .word $0000 ; # bytes to move, lo, hi .byte $00 ; Interrupt mask reg. .byte $00 ; Adress control reg. .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: ldx #$00 ; High byte of return code lda #$55 sta REU_REUADDR cmp REU_REUADDR ; Check for presence of REU bne nodevice asl a ; A = $AA sta REU_REUADDR cmp REU_REUADDR ; Check for presence of REU bne nodevice ldy #>(128*4) ; Assume 128KB lda REU_STATUS and #$10 ; Check size bit beq @L1 ldy #>(256*4) ; 256KB when size bit is set @L1: sty pagecount+1 ldy #$FF sty curpage sty curpage+1 ; Invalidate the current page txa ; X = A = EM_ERR_OK rts ; No REU found nodevice: lda #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 pagecount ldx pagecount+1 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 stx curpage+1 ; Remember the new page ldy #OP_COPYFROM jsr common ; Copy the window lda #<window ldx #>window ; Return the window address done: rts ; ------------------------------------------------------------------------ ; USE: Tell the driver that the window is now associated with a given page. USE: sta curpage stx curpage+1 ; Remember the page lda #<window ldx #>window ; Return the window rts ; ------------------------------------------------------------------------ ; COMMIT: Commit changes in the memory window to extended storage. COMMIT: lda curpage ldx curpage+1 ; Do we have a page mapped? bmi done ; Jump if no page mapped ldy #OP_COPYTO common: sty tmp1 ldy #<window sty REU_C64ADDR ldy #>window sty REU_C64ADDR+1 ldy #0 sty REU_REUADDR+0 sta REU_REUADDR+1 stx REU_REUADDR+2 sty REU_COUNT+0 ldy #1 sty REU_COUNT+1 ; Move 256 bytes bne transfer1 ; Transfer 256 bytes into REU ; ------------------------------------------------------------------------ ; 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: ldy #OP_COPYFROM .byte $2C ; ------------------------------------------------------------------------ ; 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: ldy #OP_COPYTO sty tmp1 ; Remember the passed pointer sta ptr1 stx ptr1+1 ; Save the pointer ; The structure passed to the functions has the same layout as the registers ; of the Commodore REU, so register programming is easy. ldy #7-1 @L1: lda (ptr1),y sta REU_C64ADDR,y dey bpl @L1 ; Invalidate the page in the memory window sty curpage+1 ; Y = $FF ; Reload the REU command and start the transfer transfer1: ldy tmp1 ; Transfer subroutine for the REU. Expects command in Y. transfer: sty REU_COMMAND ; Issue command ldy $01 ; Save the value of the c64 control port... tya ; and #$F8 ; Disable ROMs and I/O. sei ; sta $01 lda REU_TRIGGER ; Don't change $FF00 sta REU_TRIGGER ; Start the transfer... sty $01 ; Restore the old configuration cli rts
wagiminator/C64-Collection
1,939
C64_xu1541/software/tools/cc65-2.13.2/libsrc/c64/systime.s
; ; Stefan Haubenthal, 27.7.2009 ; ; time_t _systime (void); ; /* Similar to time(), but: ; * - Is not ISO C ; * - Does not take the additional pointer ; * - Does not set errno when returning -1 ; */ ; .include "time.inc" .include "c64.inc" .constructor initsystime .importzp tmp1, tmp2 ;---------------------------------------------------------------------------- .code .proc __systime lda CIA1_TODHR bpl AM and #%01111111 sed clc adc #$12 cld AM: jsr BCD2dec sta TM + tm::tm_hour lda CIA1_TODMIN jsr BCD2dec sta TM + tm::tm_min lda CIA1_TODSEC jsr BCD2dec sta TM + tm::tm_sec lda CIA1_TOD10 ; Dummy read to unfreeze lda #<TM ldx #>TM jmp _mktime ; dec = (((BCD>>4)*10) + (BCD&0xf)) BCD2dec:tax and #%00001111 sta tmp1 txa and #%11110000 ; *16 lsr ; *8 sta tmp2 lsr lsr ; *2 adc tmp2 ; = *10 adc tmp1 rts .endproc ;---------------------------------------------------------------------------- ; Constructor that writes to the 1/10 sec register of the TOD to kick it ; into action. If this is not done, the clock hangs. We will read the register ; and write it again, ignoring a possible change in between. .proc initsystime lda CIA1_TOD10 sta CIA1_TOD10 rts .endproc ;---------------------------------------------------------------------------- ; TM struct with date set to 1970-01-01 .data TM: .word 0 ; tm_sec .word 0 ; tm_min .word 0 ; tm_hour .word 1 ; tm_mday .word 0 ; tm_mon .word 70 ; tm_year .word 0 ; tm_wday .word 0 ; tm_yday .word 0 ; tm_isdst
wagiminator/C64-Collection
1,934
C64_xu1541/software/tools/cc65-2.13.2/libsrc/c64/kernal.s
; ; Ullrich von Bassewitz, 19.11.2002 ; ; C64 kernal functions ; .export CINT .export IOINIT .export RAMTAS .export RESTOR .export VECTOR .export SETMSG .export SECOND .export TKSA .export MEMTOP .export MEMBOT .export SCNKEY .export SETTMO .export ACPTR .export CIOUT .export UNTLK .export UNLSN .export LISTEN .export TALK .export READST .export SETLFS .export SETNAM .export OPEN .export CLOSE .export CHKIN .export CKOUT .export CLRCH .export BASIN .export BSOUT .export LOAD .export SAVE .export SETTIM .export RDTIM .export STOP .export GETIN .export CLALL .export UDTIM .export SCREEN .export IOBASE ;----------------------------------------------------------------------------- ; All functions are available in the kernal jump table CINT = $FF81 IOINIT = $FF84 RAMTAS = $FF87 RESTOR = $FF8A VECTOR = $FF8D SETMSG = $FF90 SECOND = $FF93 TKSA = $FF96 MEMTOP = $FF99 MEMBOT = $FF9C SCNKEY = $FF9F SETTMO = $FFA2 ACPTR = $FFA5 CIOUT = $FFA8 UNTLK = $FFAB UNLSN = $FFAE LISTEN = $FFB1 TALK = $FFB4 READST = $FFB7 SETLFS = $FFBA SETNAM = $FFBD OPEN = $FFC0 CLOSE = $FFC3 CHKIN = $FFC6 CKOUT = $FFC9 CLRCH = $FFCC BASIN = $FFCF BSOUT = $FFD2 LOAD = $FFD5 SAVE = $FFD8 SETTIM = $FFDB RDTIM = $FFDE STOP = $FFE1 GETIN = $FFE4 CLALL = $FFE7 UDTIM = $FFEA SCREEN = $FFED IOBASE = $FFF3
wagiminator/C64-Collection
6,507
C64_xu1541/software/tools/cc65-2.13.2/libsrc/c64/c64-ram.s
; ; Extended memory driver for the C64 hidden RAM. Driver works without ; problems when statically linked. ; ; Ullrich von Bassewitz, 2002-12-02 ; .include "zeropage.inc" .include "em-kernel.inc" .include "em-error.inc" .macpack generic ; ------------------------------------------------------------------------ ; Header. Includes jump table .segment "JUMPTABLE" ; Driver signature .byte $65, $6d, $64 ; "emd" .byte EMD_API_VERSION ; EM API version number ; Jump table. .word INSTALL .word UNINSTALL .word PAGECOUNT .word MAP .word USE .word COMMIT .word COPYFROM .word COPYTO ; ------------------------------------------------------------------------ ; Constants BASE = $D000 PAGES = ($10000 - BASE) / 256 ; ------------------------------------------------------------------------ ; Data. .bss curpage: .res 1 ; Current page number window: .res 256 ; Memory "window" .code ; ------------------------------------------------------------------------ ; INSTALL routine. Is called after the driver is loaded into memory. If ; possible, check if the hardware is present and determine the amount of ; memory available. ; Must return an EM_ERR_xx code in a/x. ; INSTALL: ldx #$FF stx curpage ; Invalidate the current page inx ; X = 0 txa ; A = X = EM_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 ; ------------------------------------------------------------------------ ; PAGECOUNT: Return the total number of available pages in a/x. ; PAGECOUNT: lda #<PAGES ldx #>PAGES 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 clc adc #>BASE sta ptr1+1 ldy #$00 sty ptr1 lda #<window sta ptr2 lda #>window sta ptr2+1 ; Transfer one page jsr transfer ; Transfer one page ; Return the memory window lda #<window ldx #>window ; Return the window address rts ; ------------------------------------------------------------------------ ; USE: Tell the driver that the window is now associated with a given page. USE: sta curpage ; Remember the page lda #<window ldx #>window ; Return the window rts ; ------------------------------------------------------------------------ ; COMMIT: Commit changes in the memory window to extended storage. COMMIT: lda curpage ; Get the current page bmi done ; Jump if no page mapped clc adc #>BASE sta ptr2+1 ldy #$00 sty ptr2 lda #<window sta ptr1 lda #>window sta ptr1+1 ; Transfer one page. Y must be zero on entry transfer: ldx $01 ; Remember c64 control port txa and #$F8 ; Bank out ROMs, I/O sei sta $01 ; Unroll the following loop loop: .repeat 8 lda (ptr1),y sta (ptr2),y iny .endrepeat bne loop ; Restore the old memory configuration, allow interrupts stx $01 ; Restore the old configuration cli ; Done done: rts ; ------------------------------------------------------------------------ ; COPYFROM: Copy from extended into linear memory. A pointer to a structure ; describing the request is passed in a/x. ; The function must not return anything. ; COPYFROM: sta ptr3 stx ptr3+1 ; Save the passed em_copy pointer ldy #EM_COPY::OFFS lda (ptr3),y sta ptr1 ldy #EM_COPY::PAGE lda (ptr3),y clc adc #>BASE sta ptr1+1 ; From ldy #EM_COPY::BUF lda (ptr3),y sta ptr2 iny lda (ptr3),y sta ptr2+1 ; To common: ldy #EM_COPY::COUNT+1 lda (ptr3),y ; Get number of pages beq @L2 ; Skip if no full pages sta tmp1 ; Copy full pages allowing interrupts after each page copied ldy #$00 @L1: jsr transfer inc ptr1+1 inc ptr2+1 dec tmp1 bne @L1 ; Copy the remainder of the page @L2: ldy #EM_COPY::COUNT lda (ptr3),y ; Get bytes in last page beq @L4 tax lda $01 ; Remember c64 control port pha and #$F8 ; Bank out ROMs, I/O sei sta $01 ; Transfer the bytes in the last page ldy #$00 @L3: lda (ptr1),y sta (ptr2),y iny dex bne @L3 ; Restore the old memory configuration, allow interrupts pla sta $01 ; Restore the old configuration cli ; Done @L4: rts ; ------------------------------------------------------------------------ ; COPYTO: Copy from linear into extended memory. A pointer to a structure ; describing the request is passed in a/x. ; The function must not return anything. ; COPYTO: sta ptr3 stx ptr3+1 ; Save the passed em_copy pointer ldy #EM_COPY::OFFS lda (ptr3),y sta ptr2 ldy #EM_COPY::PAGE lda (ptr3),y clc adc #>BASE sta ptr2+1 ; To ldy #EM_COPY::BUF lda (ptr3),y sta ptr1 iny lda (ptr3),y sta ptr1+1 ; From jmp common
wagiminator/C64-Collection
2,745
C64_xu1541/software/tools/cc65-2.13.2/libsrc/c64/mcbdefault.s
; ; Default mouse callbacks for the C64 ; ; Ullrich von Bassewitz, 2004-03-20 ; ; All functions in this module should be interrupt safe, because they may ; be called from an interrupt handler ; .export _mouse_def_callbacks .include "mouse-kernel.inc" .include "c64.inc" .macpack generic ; Sprite definitions. The first value can be changed to adjust the number ; of the sprite used for the mouse. All others depend on this value. MOUSE_SPR = 0 ; Sprite used for the mouse MOUSE_SPR_MASK = $01 .shl MOUSE_SPR ; Positive mask MOUSE_SPR_NMASK = .lobyte(.not MOUSE_SPR_MASK) ; Negative mask VIC_SPR_X = (VIC_SPR0_X + 2*MOUSE_SPR) ; Sprite X register VIC_SPR_Y = (VIC_SPR0_Y + 2*MOUSE_SPR) ; Sprite Y register .code ; -------------------------------------------------------------------------- ; Hide the mouse pointer. Always called with interrupts disabled. .proc hide lda #MOUSE_SPR_NMASK and VIC_SPR_ENA sta VIC_SPR_ENA rts .endproc ; -------------------------------------------------------------------------- ; Show the mouse pointer. Always called with interrupts disabled. .proc show lda #MOUSE_SPR_MASK ora VIC_SPR_ENA sta VIC_SPR_ENA rts .endproc ; -------------------------------------------------------------------------- ; Move the mouse pointer X position to the value in a/x. Always called with ; interrupts disabled. .proc movex ; Add the X correction and set the low byte. This frees A. add #24 ; X correction sta VIC_SPR_X ; Set the high byte txa adc #0 bne @L1 ; Branch if high byte not zero lda VIC_SPR_HI_X ; Get high X bits of all sprites and #MOUSE_SPR_NMASK ; Clear high bit for sprite sta VIC_SPR_HI_X rts @L1: lda VIC_SPR_HI_X ; Get high X bits of all sprites ora #MOUSE_SPR_MASK ; Set high bit for sprite sta VIC_SPR_HI_X rts .endproc ; -------------------------------------------------------------------------- ; Move the mouse pointer Y position to the value in a/x. Always called with ; interrupts disabled. .proc movey add #50 ; Y correction (first visible line) sta VIC_SPR_Y ; Set Y position rts .endproc ; -------------------------------------------------------------------------- ; Callback structure .rodata _mouse_def_callbacks: .addr hide .addr show .addr movex .addr movey
wagiminator/C64-Collection
3,810
C64_xu1541/software/tools/cc65-2.13.2/libsrc/c64/mainargs.s
; mainargs.s ; ; Ullrich von Bassewitz, 2003-03-07 ; Based on code from Stefan A. Haubenthal, <polluks@web.de> ; 2003-05-18, Greg King ; 2004-04-28, 2005-02-26, Ullrich von Bassewitz ; ; Scan a group of arguments that are in BASIC's input-buffer. ; Build an array that points to the beginning of each argument. ; Send, to main(), that array and the count of the arguments. ; ; Command-lines look like these lines: ; ; run ; run : rem ; run:rem arg1 " arg 2 is quoted " arg3 "" arg5 ; ; "run" and "rem" are entokenned; the args. are not. Leading and trailing ; spaces outside of quotes are ignored. ; ; TO-DO: ; - The "file-name" might be a path-name; don't copy the directory-components. ; - Add a control-character quoting mechanism. .constructor initmainargs, 24 .import __argc, __argv .include "c64.inc" MAXARGS = 10 ; Maximum number of arguments allowed REM = $8f ; BASIC token-code NAME_LEN = 16 ; maximum length of command-name ; Get possible command-line arguments. Goes into the special INIT segment, ; which may be reused after the startup code is run .segment "INIT" initmainargs: ; Assume that the program was loaded, a moment ago, by the traditional LOAD ; statement. Save the "most-recent filename" as argument #0. ; Because the buffer, that we're copying into, was zeroed out, ; we don't need to add a NUL character. ; ldy FNAM_LEN cpy #NAME_LEN + 1 bcc L1 ldy #NAME_LEN - 1 ; limit the length L0: lda (FNAM),y sta name,y L1: dey bpl L0 inc __argc ; argc always is equal to, at least, 1 ; Find the "rem" token. ; ldx #0 L2: lda BASIC_BUF,x beq done ; no "rem," no args. inx cmp #REM bne L2 ldy #1 * 2 ; Find the next argument next: lda BASIC_BUF,x beq done ; End of line reached inx cmp #' ' ; Skip leading spaces beq next ; ; Found start of next argument. We've incremented the pointer in X already, so ; it points to the second character of the argument. This is useful since we ; will check now for a quoted argument, in which case we will have to skip this ; first character. found: cmp #'"' ; Is the argument quoted? beq setterm ; Jump if so dex ; Reset pointer to first argument character lda #' ' ; A space ends the argument setterm:sta term ; Set end of argument marker ; Now store a pointer to the argument into the next slot. Since the BASIC ; input buffer is located at the start of a RAM page, no calculations are ; necessary. txa ; Get low byte sta argv,y ; argv[y]= &arg iny lda #>BASIC_BUF sta argv,y iny inc __argc ; Found another arg ; Search for the end of the argument argloop:lda BASIC_BUF,x beq done inx cmp term bne argloop ; We've found the end of the argument. X points one character behind it, and ; A contains the terminating character. To make the argument a valid C string, ; replace the terminating character by a zero. lda #0 sta BASIC_BUF-1,x ; Check if the maximum number of command line arguments is reached. If not, ; parse the next one. lda __argc ; Get low byte of argument count cmp #MAXARGS ; Maximum number of arguments reached? bcc next ; Parse next one if not ; (The last vector in argv[] already is NULL.) done: lda #<argv ldx #>argv sta __argv stx __argv + 1 rts ; These arrays are zeroed before initmainargs is called. ; char name[16+1]; ; char* argv[MAXARGS+1]={name}; ; .bss term: .res 1 name: .res NAME_LEN + 1 .data argv: .addr name .res MAXARGS * 2
wagiminator/C64-Collection
6,570
C64_xu1541/software/tools/cc65-2.13.2/libsrc/c64/c64-ramcart.s
; ; Extended memory driver for the RamCart 64/128KB cartridge. Driver works ; without problems when statically linked. ; Code is based on GEORAM code by Ullrich von Bassewitz. ; Maciej 'YTM/Elysium' Witkowiak <ytm@elysium.pl> ; 06,22.12.2002 ; .include "zeropage.inc" .include "em-kernel.inc" .include "em-error.inc" .macpack generic ; ------------------------------------------------------------------------ ; Header. Includes jump table .segment "JUMPTABLE" ; Driver signature .byte $65, $6d, $64 ; "emd" .byte EMD_API_VERSION ; EM API version number ; Jump table. .word INSTALL .word UNINSTALL .word PAGECOUNT .word MAP .word USE .word COMMIT .word COPYFROM .word COPYTO ; ------------------------------------------------------------------------ ; Constants RAMC_WINDOW = $DF00 ; Address of RamCart window RAMC_PAGE_LO = $DE00 ; Page register low RAMC_PAGE_HI = $DE01 ; Page register high (only for RC128) ; ------------------------------------------------------------------------ ; Data. .bss pagecount: .res 2 ; Number of available pages .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: ldx RAMC_WINDOW cpx RAMC_WINDOW bne @notpresent lda #0 sta RAMC_PAGE_LO sta RAMC_PAGE_HI ldx RAMC_WINDOW cpx RAMC_WINDOW bne @notpresent lda #2 sta RAMC_WINDOW cmp RAMC_WINDOW beq @cont cpx RAMC_WINDOW beq @readonly @cont: ldy #1 sty RAMC_PAGE_HI sty RAMC_WINDOW dey sty RAMC_PAGE_HI iny cpy RAMC_WINDOW beq @rc64 ; we're on rc128 ldx #>512 bne @setsize @rc64: ldx #>256 @setsize: lda #0 sta pagecount stx pagecount+1 lda #<EM_ERR_OK ldx #>EM_ERR_OK rts @notpresent: @readonly: 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 pagecount ldx pagecount+1 rts ; ------------------------------------------------------------------------ ; USE: Tell the driver that the window is now associated with a given page. ; The RamCart cartridge does not copy but actually map the window, so USE is ; identical to MAP. USE = MAP ; ------------------------------------------------------------------------ ; 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 RAMC_PAGE_LO stx RAMC_PAGE_HI lda #<RAMC_WINDOW ldx #>RAMC_WINDOW ; Use the RTS from COMMIT below to save a precious byte of storage ; ------------------------------------------------------------------------ ; COMMIT: Commit changes in the memory window to extended storage. COMMIT: 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: jsr setup ; Setup is: ; ; - ptr1 contains the struct pointer ; - ptr2 contains the linear memory buffer ; - ptr3 contains -(count-1) ; - tmp1 contains the low page register value ; - tmp2 contains the high page register value ; - X contains the page offset ; - Y contains zero jmp @L5 @L1: lda RAMC_WINDOW,x sta (ptr2),y iny bne @L2 inc ptr2+1 @L2: inx beq @L4 ; Bump count and repeat @L3: inc ptr3 bne @L1 inc ptr3+1 bne @L1 rts ; Bump page register @L4: inc tmp1 bne @L5 inc tmp2 @L5: lda tmp1 sta RAMC_PAGE_LO lda tmp2 sta RAMC_PAGE_HI jmp @L3 ; ------------------------------------------------------------------------ ; 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: jsr setup ; Setup is: ; ; - ptr1 contains the struct pointer ; - ptr2 contains the linear memory buffer ; - ptr3 contains -(count-1) ; - tmp1 contains the low page register value ; - tmp2 contains the high page register value ; - X contains the page offset ; - Y contains zero jmp @L5 @L1: lda (ptr2),y sta RAMC_WINDOW,x iny bne @L2 inc ptr2+1 @L2: inx beq @L4 ; Bump count and repeat @L3: inc ptr3 bne @L1 inc ptr3+1 bne @L1 rts ; Bump page register @L4: inc tmp1 bne @L5 inc tmp2 @L5: lda tmp1 sta RAMC_PAGE_LO lda tmp2 sta RAMC_PAGE_HI jmp @L3 ; ------------------------------------------------------------------------ ; Helper function for COPYFROM and COPYTO: Store the pointer to the request ; structure and prepare data for the copy setup: sta ptr1 stx ptr1+1 ; Save passed pointer ; Get the page number from the struct and adjust it so that it may be used ; with the hardware. That is: lower 6 bits in tmp1, high bits in tmp2. ldy #EM_COPY::PAGE+1 lda (ptr1),y sta tmp2 dey lda (ptr1),y sta tmp1 ; Get the buffer pointer into ptr2 ldy #EM_COPY::BUF lda (ptr1),y sta ptr2 iny lda (ptr1),y sta ptr2+1 ; Get the count, calculate -(count-1) and store it into ptr3 ldy #EM_COPY::COUNT lda (ptr1),y eor #$FF sta ptr3 iny lda (ptr1),y eor #$FF sta ptr3+1 ; Get the page offset into X and clear Y ldy #EM_COPY::OFFS lda (ptr1),y tax ldy #$00 ; Done rts
wagiminator/C64-Collection
1,839
C64_xu1541/software/tools/cc65-2.13.2/libsrc/c64/cputc.s
; ; Ullrich von Bassewitz, 1998-08-06, 2009-09-26 ; ; void __fastcall__ cputcxy (unsigned char x, unsigned char y, char c); ; void __fastcall__ cputc (char c); ; .export _cputcxy, _cputc, cputdirect, putchar .export newline, plot .import popa, _gotoxy .import PLOT .include "c64.inc" _cputcxy: pha ; Save C jsr popa ; Get Y jsr _gotoxy ; Set cursor, drop x 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 ; Printable char of some sort cmp #' ' bcc cputdirect ; Other control char tay bmi L10 cmp #$60 bcc L2 and #$DF bne cputdirect ; Branch always L2: and #$3F cputdirect: jsr putchar ; Write the character to the screen ; Advance cursor position advance: iny cpy #XSIZE bne L3 jsr newline ; new line ldy #0 ; + cr L3: sty CURS_X rts newline: clc lda #XSIZE adc SCREEN_PTR sta SCREEN_PTR bcc L4 inc SCREEN_PTR+1 clc L4: lda #XSIZE adc CRAM_PTR sta CRAM_PTR bcc L5 inc CRAM_PTR+1 L5: inc CURS_Y rts ; Handle character if high bit set L10: and #$7F cmp #$7E ; PI? bne L11 lda #$5E ; Load screen code for PI bne cputdirect L11: ora #$40 bne cputdirect ; Set cursor position, calculate RAM pointers. plot: ldy CURS_X ldx CURS_Y clc jmp PLOT ; Set the new cursor ; Write one character to the screen without doing anything else, return X ; position in Y putchar: ora RVS ; Set revers bit ldy CURS_X sta (SCREEN_PTR),y ; Set char lda CHARCOLOR sta (CRAM_PTR),y ; Set color rts
wagiminator/C64-Collection
1,613
C64_xu1541/software/tools/cc65-2.13.2/libsrc/c64/break.s
; ; Ullrich von Bassewitz, 27.09.1998 ; ; void set_brk (unsigned Addr); ; void reset_brk (void); ; .export _set_brk, _reset_brk .destructor _reset_brk .export _brk_a, _brk_x, _brk_y, _brk_sr, _brk_pc .include "c64.inc" .bss _brk_a: .res 1 _brk_x: .res 1 _brk_y: .res 1 _brk_sr: .res 1 _brk_pc: .res 2 oldvec: .res 2 ; Old vector .data uservec: jmp $FFFF ; Patched at runtime .code ; Set the break vector .proc _set_brk sta uservec+1 stx uservec+2 ; Set the user vector lda oldvec ora oldvec+1 ; Did we save the vector already? bne L1 ; Jump if we installed the handler already lda BRKVec sta oldvec lda BRKVec+1 sta oldvec+1 ; Save the old vector L1: lda #<brk_handler ; Set the break vector to our routine ldx #>brk_handler sta BRKVec stx BRKVec+1 rts .endproc ; Reset the break vector .proc _reset_brk lda oldvec ldx oldvec+1 beq @L9 ; Jump if vector not installed sta BRKVec stx BRKVec+1 lda #$00 sta oldvec ; Clear the old vector stx oldvec+1 @L9: rts .endproc ; Break handler, called if a break occurs .proc brk_handler pla sta _brk_y pla sta _brk_x pla sta _brk_a pla and #$EF ; Clear break bit sta _brk_sr pla ; PC low sec sbc #2 ; Point to start of brk sta _brk_pc pla ; PC high sbc #0 sta _brk_pc+1 jsr uservec ; Call the user's routine lda _brk_pc+1 pha lda _brk_pc pha lda _brk_sr pha ldx _brk_x ldy _brk_y lda _brk_a rti ; Jump back... .endproc
wagiminator/C64-Collection
31,707
C64_xu1541/software/tools/cc65-2.13.2/libsrc/c64/c64-320-200-2.s
; ; Graphics driver for the 320x200x2 mode on the C64. ; ; Based on Stephen L. Judds GRLIB code ; .include "zeropage.inc" .include "tgi-kernel.inc" .include "tgi-mode.inc" .include "tgi-error.inc" .macpack generic ; ------------------------------------------------------------------------ ; Header. Includes jump table and constants. .segment "JUMPTABLE" ; First part of the header is a structure that has a magic and defines the ; capabilities of the driver .byte $74, $67, $69 ; "tgi" .byte TGI_API_VERSION ; TGI API version number .word 320 ; X resolution .word 200 ; Y resolution .byte 2 ; Number of drawing colors .byte 1 ; Number of screens available .byte 8 ; System font X size .byte 8 ; System font Y size .res 4, $00 ; Reserved for future extensions ; Next comes the jump table. Currently all entries must be valid and may point ; to an RTS for test versions (function not implemented). A future version may ; allow for emulation: In this case the vector will be zero. Emulation means ; that the graphics kernel will emulate the function by using lower level ; primitives - for example ploting a line by using calls to SETPIXEL. .addr INSTALL .addr UNINSTALL .addr INIT .addr DONE .addr GETERROR .addr CONTROL .addr CLEAR .addr SETVIEWPAGE .addr SETDRAWPAGE .addr SETCOLOR .addr SETPALETTE .addr GETPALETTE .addr GETDEFPALETTE .addr SETPIXEL .addr GETPIXEL .addr LINE .addr BAR .addr CIRCLE .addr TEXTSTYLE .addr OUTTEXT .addr 0 ; IRQ entry is unused ; ------------------------------------------------------------------------ ; Data. ; Variables mapped to the zero page segment variables. Some of these are ; used for passing parameters to the driver. X1 := ptr1 Y1 := ptr2 X2 := ptr3 Y2 := ptr4 RADIUS := tmp1 ROW := tmp2 ; Bitmap row... COL := tmp3 ; ...and column, both set by PLOT TEMP := tmp4 TEMP2 := sreg POINT := regsave INRANGE := regsave+2 ; PLOT variable, $00 = coordinates in range CHUNK := X2 ; Used in the line routine OLDCHUNK := X2+1 ; Dito ; Absolute variables used in the code .bss ERROR: .res 1 ; Error code PALETTE: .res 2 ; The current palette BITMASK: .res 1 ; $00 = clear, $FF = set pixels ; INIT/DONE OLDD018: .res 1 ; Old register value ; Line routine stuff DX: .res 2 DY: .res 2 ; Circle routine stuff, overlaid by BAR variables X1SAVE: CURX: .res 1 CURY: .res 1 Y1SAVE: BROW: .res 1 ; Bottom row TROW: .res 1 ; Top row X2SAVE: LCOL: .res 1 ; Left column RCOL: .res 1 ; Right column Y2SAVE: CHUNK1: .res 1 OLDCH1: .res 1 CHUNK2: .res 1 OLDCH2: .res 1 ; Text output stuff TEXTMAGX: .res 1 TEXTMAGY: .res 1 TEXTDIR: .res 1 ; Constants and tables .rodata DEFPALETTE: .byte $00, $01 ; White on black PALETTESIZE = * - DEFPALETTE BITTAB: .byte $80,$40,$20,$10,$08,$04,$02,$01 BITCHUNK: .byte $FF,$7F,$3F,$1F,$0F,$07,$03,$01 VBASE = $E000 ; Video memory base address CBASE = $D000 ; Color memory base address .code ; ------------------------------------------------------------------------ ; INSTALL routine. Is called after the driver is loaded into memory. May ; initialize anything that has to be done just once. Is probably empty ; most of the time. ; ; Must set an error code: NO ; INSTALL: rts ; ------------------------------------------------------------------------ ; UNINSTALL routine. Is called before the driver is removed from memory. May ; clean up anything done by INSTALL but is probably empty most of the time. ; ; Must set an error code: NO ; UNINSTALL: rts ; ------------------------------------------------------------------------ ; INIT: Changes an already installed device from text mode to graphics ; mode. ; Note that INIT/DONE may be called multiple times while the driver ; is loaded, while INSTALL is only called once, so any code that is needed ; to initializes variables and so on must go here. Setting palette and ; clearing the screen is not needed because this is called by the graphics ; kernel later. ; The graphics kernel will never call INIT when a graphics mode is already ; active, so there is no need to protect against that. ; ; Must set an error code: YES ; INIT: ; Initialize variables ldx #$FF stx BITMASK ; Switch into graphics mode lda $DD02 ; Set the data direction regs ora #3 sta $DD02 lda $DD00 and #$FC ; Switch to bank 3 sta $DD00 lda $D018 sta OLDD018 lda #$48 ; Set color map to $D000, screen to $E000 sta $D018 lda $D011 ; And turn on bitmap ora #$20 DONE1: sta $D011 ; Done, reset the error code lda #TGI_ERR_OK sta ERROR rts ; ------------------------------------------------------------------------ ; DONE: Will be called to switch the graphics device back into text mode. ; The graphics kernel will never call DONE when no graphics mode is active, ; so there is no need to protect against that. ; ; Must set an error code: NO ; DONE: lda $DD02 ; Set the data direction regs ora #3 sta $DD02 lda $DD00 ora #$03 ; Bank 0 sta $DD00 lda OLDD018 ; Screen mem --> $0400 sta $D018 lda $D011 and #<~$20 sta $D011 rts ; ------------------------------------------------------------------------ ; GETERROR: Return the error code in A and clear it. GETERROR: ldx #TGI_ERR_OK lda ERROR stx ERROR rts ; ------------------------------------------------------------------------ ; CONTROL: Platform/driver specific entry point. ; ; Must set an error code: YES ; CONTROL: lda #TGI_ERR_INV_FUNC sta ERROR rts ; ------------------------------------------------------------------------ ; CLEAR: Clears the screen. ; ; Must set an error code: NO ; CLEAR: ldy #$00 tya @L1: sta VBASE+$0000,y sta VBASE+$0100,y sta VBASE+$0200,y sta VBASE+$0300,y sta VBASE+$0400,y sta VBASE+$0500,y sta VBASE+$0600,y sta VBASE+$0700,y sta VBASE+$0800,y sta VBASE+$0900,y sta VBASE+$0A00,y sta VBASE+$0B00,y sta VBASE+$0C00,y sta VBASE+$0D00,y sta VBASE+$0E00,y sta VBASE+$0F00,y sta VBASE+$1000,y sta VBASE+$1100,y sta VBASE+$1200,y sta VBASE+$1300,y sta VBASE+$1400,y sta VBASE+$1500,y sta VBASE+$1600,y sta VBASE+$1700,y sta VBASE+$1800,y sta VBASE+$1900,y sta VBASE+$1A00,y sta VBASE+$1B00,y sta VBASE+$1C00,y sta VBASE+$1D00,y sta VBASE+$1E00,y sta VBASE+$1F00,y iny bne @L1 rts ; ------------------------------------------------------------------------ ; SETVIEWPAGE: Set the visible page. Called with the new page in A (0..n). ; The page number is already checked to be valid by the graphics kernel. ; ; Must set an error code: NO (will only be called if page ok) ; SETVIEWPAGE: rts ; ------------------------------------------------------------------------ ; SETDRAWPAGE: Set the drawable page. Called with the new page in A (0..n). ; The page number is already checked to be valid by the graphics kernel. ; ; Must set an error code: NO (will only be called if page ok) ; SETDRAWPAGE: rts ; ------------------------------------------------------------------------ ; SETCOLOR: Set the drawing color (in A). The new color is already checked ; to be in a valid range (0..maxcolor-1). ; ; Must set an error code: NO (will only be called if color ok) ; SETCOLOR: tax beq @L1 lda #$FF @L1: sta BITMASK rts ; ------------------------------------------------------------------------ ; SETPALETTE: Set the palette (not available with all drivers/hardware). ; A pointer to the palette is passed in ptr1. Must set an error if palettes ; are not supported ; ; Must set an error code: YES ; SETPALETTE: ldy #PALETTESIZE - 1 @L1: lda (ptr1),y ; Copy the palette and #$0F ; Make a valid color sta PALETTE,y dey bpl @L1 ; Get the color entries from the palette lda PALETTE+1 ; Foreground color asl a asl a asl a asl a ora PALETTE ; Background color tax ; Initialize the color map with the new color settings (it is below the ; I/O area) ldy #$00 sei lda $01 ; Get ROM config pha ; Save it and #%11111100 ; Clear bit 0 and 1 sta $01 txa ; Load color code @L2: sta CBASE+$0000,y sta CBASE+$0100,y sta CBASE+$0200,y sta CBASE+$0300,y iny bne @L2 pla sta $01 cli ; Done, reset the error code lda #TGI_ERR_OK sta ERROR rts ; ------------------------------------------------------------------------ ; GETPALETTE: Return the current palette in A/X. Even drivers that cannot ; set the palette should return the default palette here, so there's no ; way for this function to fail. ; ; Must set an error code: NO ; GETPALETTE: lda #<PALETTE ldx #>PALETTE rts ; ------------------------------------------------------------------------ ; GETDEFPALETTE: Return the default palette for the driver in A/X. All ; drivers should return something reasonable here, even drivers that don't ; support palettes, otherwise the caller has no way to determine the colors ; of the (not changeable) palette. ; ; Must set an error code: NO (all drivers must have a default palette) ; GETDEFPALETTE: lda #<DEFPALETTE ldx #>DEFPALETTE rts ; ------------------------------------------------------------------------ ; SETPIXEL: Draw one pixel at X1/Y1 = ptr1/ptr2 with the current drawing ; color. The coordinates passed to this function are never outside the ; visible screen area, so there is no need for clipping inside this function. ; ; Must set an error code: NO ; SETPIXEL: jsr CALC ; Calculate coordinates sei ; Get underneath ROM lda $01 pha lda #$34 sta $01 lda (POINT),Y eor BITMASK and BITTAB,X eor (POINT),Y sta (POINT),Y pla sta $01 cli @L9: rts ; ------------------------------------------------------------------------ ; GETPIXEL: Read the color value of a pixel and return it in A/X. The ; coordinates passed to this function are never outside the visible screen ; area, so there is no need for clipping inside this function. GETPIXEL: jsr CALC ; Calculate coordinates sei ; Get underneath ROM lda $01 pha lda #$34 sta $01 lda (POINT),Y ldy #$00 and BITTAB,X beq @L1 iny @L1: pla sta $01 cli tya ; Get color value into A ldx #$00 ; Clear high byte rts ; ------------------------------------------------------------------------ ; LINE: Draw a line from X1/Y1 to X2/Y2, where X1/Y1 = ptr1/ptr2 and ; X2/Y2 = ptr3/ptr4 using the current drawing color. ; ; To deal with off-screen coordinates, the current row ; and column (40x25) is kept track of. These are set ; negative when the point is off the screen, and made ; positive when the point is within the visible screen. ; ; X1,X2 etc. are set up above (x2=LINNUM in particular) ; Format is LINE x2,y2,x1,y1 ; ; Must set an error code: NO ; LINE: @CHECK: lda X2 ;Make sure x1<x2 sec sbc X1 tax lda X2+1 sbc X1+1 bpl @CONT lda Y2 ;If not, swap P1 and P2 ldy Y1 sta Y1 sty Y2 lda Y2+1 ldy Y1+1 sta Y1+1 sty Y2+1 lda X1 ldy X2 sty X1 sta X2 lda X2+1 ldy X1+1 sta X1+1 sty X2+1 bcc @CHECK @CONT: sta DX+1 stx DX ldx #$C8 ;INY lda Y2 ;Calculate dy sec sbc Y1 tay lda Y2+1 sbc Y1+1 bpl @DYPOS ;Is y2>=y1? lda Y1 ;Otherwise dy=y1-y2 sec sbc Y2 tay ldx #$88 ;DEY @DYPOS: sty DY ; 8-bit DY -- FIX ME? stx YINCDEC stx XINCDEC jsr CALC ; Set up .X,.Y,POINT, and INRANGE lda BITCHUNK,X sta OLDCHUNK sta CHUNK sei ; Get underneath ROM lda #$34 sta $01 ldx DY cpx DX ;Who's bigger: dy or dx? bcc STEPINX ;If dx, then... lda DX+1 bne STEPINX ; ; Big steps in Y ; ; To simplify my life, just use PLOT to plot points. ; ; No more! ; Added special plotting routine -- cool! ; ; X is now counter, Y is y-coordinate ; ; On entry, X=DY=number of loop iterations, and Y= ; Y1 AND #$07 STEPINY: lda #00 sta OLDCHUNK ;So plotting routine will work right lda CHUNK lsr ;Strip the bit eor CHUNK sta CHUNK txa bne @CONT ;If dy=0 it's just a point inx @CONT: lsr ;Init counter to dy/2 ; ; Main loop ; YLOOP: sta TEMP lda INRANGE ;Range check bne @SKIP lda (POINT),y ;Otherwise plot eor BITMASK and CHUNK eor (POINT),y sta (POINT),y @SKIP: YINCDEC: iny ;Advance Y coordinate cpy #8 bcc @CONT ;No prob if Y=0..7 jsr FIXY @CONT: lda TEMP ;Restore A sec sbc DX bcc YFIXX YCONT: dex ;X is counter bne YLOOP YCONT2: lda (POINT),y ;Plot endpoint eor BITMASK and CHUNK eor (POINT),y sta (POINT),y YDONE: lda #$37 sta $01 cli rts YFIXX: ;x=x+1 adc DY lsr CHUNK bne YCONT ;If we pass a column boundary... ror CHUNK ;then reset CHUNK to $80 sta TEMP2 lda COL bmi @C1 ;Skip if column is negative cmp #39 ;End if move past end of screen bcs YDONE @C1: lda POINT ;And add 8 to POINT adc #8 sta POINT bcc @CONT inc POINT+1 @CONT: inc COL ;Increment column bne @C2 lda ROW ;Range check cmp #25 bcs @C2 lda #00 ;Passed into col 0 sta INRANGE @C2: lda TEMP2 dex bne YLOOP beq YCONT2 ; ; Big steps in X direction ; ; On entry, X=DY=number of loop iterations, and Y= ; Y1 AND #$07 .bss COUNTHI: .byte $00 ;Temporary counter ;only used once .code STEPINX: ldx DX lda DX+1 sta COUNTHI cmp #$80 ror ;Need bit for initialization sta Y1 ;High byte of counter txa bne @CONT ;Could be $100 dec COUNTHI @CONT: ror ; ; Main loop ; XLOOP: lsr CHUNK beq XFIXC ;If we pass a column boundary... XCONT1: sbc DY bcc XFIXY ;Time to step in Y? XCONT2: dex bne XLOOP dec COUNTHI ;High bits set? bpl XLOOP XDONE: lsr CHUNK ;Advance to last point jsr LINEPLOT ;Plot the last chunk EXIT: lda #$37 sta $01 cli rts ; ; CHUNK has passed a column, so plot and increment pointer ; and fix up CHUNK, OLDCHUNK. ; XFIXC: sta TEMP jsr LINEPLOT lda #$FF sta CHUNK sta OLDCHUNK lda COL bmi @C1 ;Skip if column is negative cmp #39 ;End if move past end of screen bcs EXIT @C1: lda POINT adc #8 sta POINT bcc @CONT inc POINT+1 @CONT: inc COL bne @C2 lda ROW cmp #25 bcs @C2 lda #00 sta INRANGE @C2: lda TEMP sec bcs XCONT1 ; ; Check to make sure there isn't a high bit, plot chunk, ; and update Y-coordinate. ; XFIXY: dec Y1 ;Maybe high bit set bpl XCONT2 adc DX sta TEMP lda DX+1 adc #$FF ;Hi byte sta Y1 jsr LINEPLOT ;Plot chunk lda CHUNK sta OLDCHUNK lda TEMP XINCDEC: iny ;Y-coord cpy #8 ;0..7 is ok bcc XCONT2 sta TEMP jsr FIXY lda TEMP jmp XCONT2 ; ; Subroutine to plot chunks/points (to save a little ; room, gray hair, etc.) ; LINEPLOT: ; Plot the line chunk lda INRANGE bne @SKIP lda (POINT),Y ; Otherwise plot eor BITMASK ora CHUNK and OLDCHUNK eor CHUNK eor (POINT),Y sta (POINT),Y @SKIP: rts ; ; Subroutine to fix up pointer when Y decreases through ; zero or increases through 7. ; FIXY: cpy #255 ;Y=255 or Y=8 beq @DECPTR @INCPTR: ;Add 320 to pointer ldy #0 ;Y increased through 7 lda ROW bmi @C1 ;If negative, then don't update cmp #24 bcs @TOAST ;If at bottom of screen then quit @C1: lda POINT adc #<320 sta POINT lda POINT+1 adc #>320 sta POINT+1 @CONT1: inc ROW bne @DONE lda COL bpl @CLEAR @DONE: rts @DECPTR: ;Okay, subtract 320 then ldy #7 ;Y decreased through 0 lda POINT sec sbc #<320 sta POINT lda POINT+1 sbc #>320 sta POINT+1 @CONT2: dec ROW bmi @TOAST lda ROW cmp #24 bne @DONE lda COL bmi @DONE @CLEAR: lda #00 sta INRANGE rts @TOAST: pla ;Remove old return address pla jmp EXIT ;Restore interrupts, etc. ; ------------------------------------------------------------------------ ; BAR: Draw a filled rectangle with the corners X1/Y1, X2/Y2, where ; X1/Y1 = ptr1/ptr2 and X2/Y2 = ptr3/ptr4 using the current drawing color. ; Contrary to most other functions, the graphics kernel will sort and clip ; the coordinates before calling the driver, so on entry the following ; conditions are valid: ; X1 <= X2 ; Y1 <= Y2 ; (X1 >= 0) && (X1 < XRES) ; (X2 >= 0) && (X2 < XRES) ; (Y1 >= 0) && (Y1 < YRES) ; (Y2 >= 0) && (Y2 < YRES) ; ; Must set an error code: NO ; ; Note: This function needs optimization. It's just a cheap translation of ; the original C wrapper and could be written much smaller (besides that, ; calling LINE is not a good idea either). BAR: lda Y2 sta Y2SAVE lda Y2+1 sta Y2SAVE+1 lda X2 sta X2SAVE lda X2+1 sta X2SAVE+1 lda Y1 sta Y1SAVE lda Y1+1 sta Y1SAVE+1 lda X1 sta X1SAVE lda X1+1 sta X1SAVE+1 @L1: lda Y1 sta Y2 lda Y1+1 sta Y2+1 jsr LINE lda Y1SAVE cmp Y2SAVE bne @L2 lda Y1SAVE cmp Y2SAVE beq @L4 @L2: inc Y1SAVE bne @L3 inc Y1SAVE+1 @L3: lda Y1SAVE sta Y1 lda Y1SAVE+1 sta Y1+1 lda X1SAVE sta X1 lda X1SAVE+1 sta X1+1 lda X2SAVE sta X2 lda X2SAVE+1 sta X2+1 jmp @L1 @L4: rts ; ------------------------------------------------------------------------ ; CIRCLE: Draw a circle around the center X1/Y1 (= ptr1/ptr2) with the ; radius in tmp1 and the current drawing color. ; ; Must set an error code: NO ; CIRCLE: lda RADIUS sta CURY bne @L1 jmp SETPIXEL ; Plot as a point @L1: clc adc Y1 sta Y1 bcc @L2 inc Y1+1 @L2: jsr CALC ; Compute XC, YC+R lda ROW sta BROW lda COL sta LCOL sta RCOL sty Y2 ; Y AND 07 lda BITCHUNK,X sta CHUNK1 ; Forwards chunk sta OLDCH1 lsr eor #$FF sta CHUNK2 ; Backwards chunk sta OLDCH2 lda POINT sta TEMP2 ; TEMP2 = forwards high pointer sta X2 ; X2 = backwards high pointer lda POINT+1 sta TEMP2+1 sta X2+1 ; Next compute CY-R lda Y1 sec sbc RADIUS bcs @C3 dec Y1+1 sec @C3: sbc RADIUS bcs @C4 dec Y1+1 @C4: sta Y1 jsr CALC ; Compute new coords sty Y1 lda POINT sta X1 ; X1 will be the backwards lda POINT+1 ; low-pointer sta X1+1 ; POINT will be forwards lda ROW sta TROW sei ; Get underneath ROM lda #$34 sta $01 lda RADIUS lsr ; A=r/2 ldx #00 stx CURX ; y=0 ; Main loop @LOOP: inc CURX ; x=x+1 lsr CHUNK1 ; Right chunk bne @CONT1 jsr UPCHUNK1 ; Update if we move past a column @CONT1: asl CHUNK2 bne @CONT2 jsr UPCHUNK2 @CONT2: sec sbc CURX ; a=a-x bcs @LOOP adc CURY ;if a<0 then a=a+y; y=y-1 tax jsr PCHUNK1 jsr PCHUNK2 lda CHUNK1 sta OLDCH1 lda CHUNK2 sta OLDCH2 txa dec CURY ;(y=y-1) dec Y2 ;Decrement y-offest for upper bpl @CONT3 ;points jsr DECYOFF @CONT3: ldy Y1 iny sty Y1 cpy #8 bcc @CONT4 jsr INCYOFF @CONT4: ldy CURX cpy CURY ;if y<=x then punt bcc @LOOP ;Now draw the other half ; ; Draw the other half of the circle by exactly reversing ; the above! ; NEXTHALF: lsr OLDCH1 ;Only plot a bit at a time asl OLDCH2 lda RADIUS ;A=-R/2-1 lsr eor #$FF @LOOP: tax jsr PCHUNK1 ;Plot points jsr PCHUNK2 txa dec Y2 ;Y2=bottom bpl @CONT1 jsr DECYOFF @CONT1: inc Y1 ldy Y1 cpy #8 bcc @CONT2 jsr INCYOFF @CONT2: ldx CURY beq @DONE clc adc CURY ;a=a+y dec CURY ;y=y-1 bcc @LOOP inc CURX sbc CURX ;if a<0 then x=x+1; a=a+x lsr CHUNK1 bne @CONT3 tax jsr UPCH1 ;Upchunk, but no plot @CONT3: lsr OLDCH1 ;Only the bits... asl CHUNK2 ;Fix chunks bne @CONT4 tax jsr UPCH2 @CONT4: asl OLDCH2 bcs @LOOP @DONE: CIRCEXIT: ;Restore interrupts lda #$37 sta $01 cli rts ; ; Decrement lower pointers ; DECYOFF: tay lda #7 sta Y2 lda X2 ;If we pass through zero, then sec sbc #<320 ;subtract 320 sta X2 lda X2+1 sbc #>320 sta X2+1 lda TEMP2 sec sbc #<320 sta TEMP2 lda TEMP2+1 sbc #>320 sta TEMP2+1 tya dec BROW bmi EXIT2 rts EXIT2: pla ;Grab return address pla jmp CIRCEXIT ;Restore interrupts, etc. ; Increment upper pointers INCYOFF: tay lda #00 sta Y1 lda X1 clc adc #<320 sta X1 lda X1+1 adc #>320 sta X1+1 lda POINT clc adc #<320 sta POINT lda POINT+1 adc #>320 sta POINT+1 @ISKIP: inc TROW bmi @DONE lda TROW cmp #25 bcs EXIT2 @DONE: tya rts ; ; UPCHUNK1 -- Update right-moving chunk pointers ; Due to passing through a column ; UPCHUNK1: tax jsr PCHUNK1 UPCH1: lda #$FF ;Alternative entry point sta CHUNK1 sta OLDCH1 lda TEMP2 clc adc #8 sta TEMP2 bcc @CONT inc TEMP2+1 clc @CONT: lda POINT adc #8 sta POINT bcc @DONE inc POINT+1 @DONE: txa inc RCOL rts ; ; UPCHUNK2 -- Update left-moving chunk pointers ; UPCHUNK2: tax jsr PCHUNK2 UPCH2: lda #$FF sta CHUNK2 sta OLDCH2 lda X2 sec sbc #8 sta X2 bcs @CONT dec X2+1 sec @CONT: lda X1 sbc #8 sta X1 bcs @DONE dec X1+1 @DONE: txa dec LCOL rts ; ; Plot right-moving chunk pairs for circle routine ; PCHUNK1: lda RCOL ;Make sure we're in range cmp #40 bcs @SKIP2 lda CHUNK1 ;Otherwise plot eor OLDCH1 sta TEMP lda TROW ;Check for underflow bmi @SKIP ldy Y1 lda (POINT),y eor BITMASK and TEMP eor (POINT),y sta (POINT),y @SKIP: lda BROW ;If CY+Y >= 200... cmp #25 bcs @SKIP2 ldy Y2 lda (TEMP2),y eor BITMASK and TEMP eor (TEMP2),y sta (TEMP2),y @SKIP2: rts ; ; Plot left-moving chunk pairs for circle routine ; PCHUNK2: lda LCOL ;Range check in X cmp #40 bcs EXIT3 lda CHUNK2 ;Otherwise plot eor OLDCH2 sta TEMP lda TROW ;Check for underflow bmi @SKIP ldy Y1 lda (X1),y eor BITMASK and TEMP eor (X1),y sta (X1),y @SKIP: lda BROW ;If CY+Y >= 200... cmp #25 bcs EXIT3 ldy Y2 lda (X2),y eor BITMASK and TEMP eor (X2),y sta (X2),y EXIT3: rts ; ------------------------------------------------------------------------ ; TEXTSTYLE: Set the style used when calling OUTTEXT. Text scaling in X and Y ; direction is passend in X/Y, the text direction is passed in A. ; ; Must set an error code: NO ; TEXTSTYLE: stx TEXTMAGX sty TEXTMAGY sta TEXTDIR rts ; ------------------------------------------------------------------------ ; OUTTEXT: Output text at X/Y = ptr1/ptr2 using the current color and the ; current text style. The text to output is given as a zero terminated ; string with address in ptr3. ; ; Must set an error code: NO ; OUTTEXT: rts ; ------------------------------------------------------------------------ ; Calculate all variables to plot the pixel at X1/Y1. If the point is out ; of range, a carry is returned and INRANGE is set to a value !0 zero. If ; the coordinates are valid, INRANGE is zero and the carry clear. CALC: lda Y1 sta ROW and #7 tay lda Y1+1 lsr ; Neg is possible ror ROW lsr ror ROW lsr ror ROW lda #00 sta POINT lda ROW cmp #$80 ror ror POINT cmp #$80 ror ror POINT ; row*64 adc ROW ; +row*256 clc adc #>VBASE ; +bitmap base sta POINT+1 lda X1 tax sta COL lda X1+1 lsr ror COL lsr ror COL lsr ror COL txa and #$F8 clc adc POINT ; +(X AND #$F8) sta POINT lda X1+1 adc POINT+1 sta POINT+1 txa and #7 tax lda ROW cmp #25 bcs @L9 lda COL cmp #40 bcs @L9 lda #00 @L9: sta INRANGE rts
wagiminator/C64-Collection
5,776
C64_xu1541/software/tools/cc65-2.13.2/libsrc/c64/c64-hitjoy.s
; ; DXS/HIT-4 Player joystick driver for the C64 ; ; Groepaz/Hitmen, 2002-12-23 ; obviously based on Ullrichs driver :) ; .include "zeropage.inc" .include "joy-kernel.inc" .include "joy-error.inc" .include "c64.inc" .macpack generic ; ------------------------------------------------------------------------ ; Header. Includes jump table .segment "JUMPTABLE" ; Driver signature .byte $6A, $6F, $79 ; "joy" .byte JOY_API_VERSION ; 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 ; JOY_FIRE2 unavailable .byte $00 ; Future expansion .byte $00 ; Future expansion ; Jump table. .addr INSTALL .addr UNINSTALL .addr COUNT .addr READ .addr IRQ ; ------------------------------------------------------------------------ ; Constants JOY_COUNT = 4 ; Number of joysticks we support ; ------------------------------------------------------------------------ ; Data. Written in the IRQ, read by the READ routine .bss temp3: .byte 0 temp4: .byte 0 .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 ; ------------------------------------------------------------------------ ; IRQ entry point. Is called from the C layer as a subroutine in the ; interrupt. The routine MUST return carry set if the interrupt has been ; 'handled' - which means that the interrupt source is gone. Otherwise it ; MUST return carry clear. IRQ: ; cia 2 setup ldy #$00 ; port b direction sty $dd03 ; => input sty $dd05 ; cia2 timer a highbyte sty $dc05 ; cia1 timer a highbyte iny sty $dd04 ; cia2 timer a lowbyte sty $dc04 ; cia1 timer a lowbyte lda #%00010001 sta $dd0e ; control register a ; timer: start ; continous ; forced load ; serial port: input ; cia 1 setup lda #%01010001 sta $dc0e ; control register a ; timer: start ; continous ; forced load ; serial port: output ; read directions 3 lda $dd01 ;read cia 2 port b and #$0f sta temp3 ; read button 3 lda $dd02 ;cia 2 port a and #%11111011 ;data direction sta $dd02 ;=> bit 2 input lda $dd00 ;read cia 2 p.A and #%00000100 ;check bit 2 asl a asl a ora temp3 sta temp3 ; read directions 4 lda $dd01 ;read cia 2 port b lsr a lsr a lsr a lsr a sta temp4 ; read button 4 ldx #$ff ;serial data register stx $dc0c ;=> writing $ff causes ;cia to output some ;count signals at cnt1 ldx $dd0c ;read cia 2 serial in beq fire ;button press if zero lda temp4 ora #%00010000 sta temp4 fire: ; Default Value: $40/64 on PAL ; $42/66 on NTSC lda #$41 sta $dc05 ; Default Value: $25/37 on PAL ; $95/149 on NTSC lda #0 sta $dc04 ; We do never "handle" the interrupt, we use it just as a timer. clc 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: tax ; Joystick number into X bne joy2 ; Read joystick 1 joy1: lda #$7F sei sta CIA1_PRA lda CIA1_PRB cli and #$1F eor #$1F rts ; Read joystick 2 joy2: dex bne joy3 ; ldx #0 lda #$E0 ldy #$FF sei sta CIA1_DDRA lda CIA1_PRA sty CIA1_DDRA cli and #$1F eor #$1F rts ; Read joystick 3 joy3: dex bne joy4 lda temp3 eor #$1F rts ; Read joystick 4 joy4: lda temp4 eor #$1F ldx #0 rts
wagiminator/C64-Collection
3,700
C64_xu1541/software/tools/cc65-2.13.2/libsrc/c64/c64-ptvjoy.s
; ; PTV-4 Player joystick driver for the C64 ; ; Groepaz/Hitmen, 2002-12-23 ; obviously based on Ullrichs driver :) ; .include "zeropage.inc" .include "joy-kernel.inc" .include "joy-error.inc" .include "c64.inc" .macpack generic ; ------------------------------------------------------------------------ ; Header. Includes jump table .segment "JUMPTABLE" ; Driver signature .byte $6A, $6F, $79 ; "joy" .byte JOY_API_VERSION ; 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 ; JOY_FIRE2 unavailable .byte $00 ; Future expansion .byte $00 ; Future expansion ; Jump table. .addr INSTALL .addr UNINSTALL .addr COUNT .addr READ .addr 0 ; IRQ entry unused ; ------------------------------------------------------------------------ ; Constants JOY_COUNT = 4 ; Number of joysticks we support .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: tax ; Joystick number into X bne joy2 ; Read joystick 1 joy1: lda #$7F sei sta CIA1_PRA lda CIA1_PRB cli and #$1F eor #$1F rts ; Read joystick 2 joy2: dex bne joy3 lda #$E0 ldy #$FF sei sta CIA1_DDRA lda CIA1_PRA sty CIA1_DDRA cli and #$1F eor #$1F rts ; Read joystick 3 joy3: lda #%10000000 ; cia 2 port B Data-Direction sta CIA2_DDRB ; bit 7: out bit 6-0: in dex bne joy4 lda #$80 ; cia 2 port B read/write 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 rts ; Read joystick 4 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) 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 ldx #0 rts
wagiminator/C64-Collection
1,142
C64_xu1541/software/tools/cc65-2.13.2/libsrc/c64/cgetc.s
; ; Ullrich von Bassewitz, 06.08.1998 ; ; char cgetc (void); ; .export _cgetc .import cursor .include "c64.inc" _cgetc: lda KEY_COUNT ; Get number of characters bne L3 ; Jump if there are already chars waiting ; Switch on the cursor if needed lda CURS_FLAG pha lda cursor jsr setcursor L1: lda KEY_COUNT beq L1 ldx #0 pla bne L2 inx L2: txa jsr setcursor L3: jsr KBDREAD ; Read char and return in A ldx #0 rts ; Switch the cursor on or off .proc setcursor tax ; On or off? bne seton ; Go set it on lda CURS_FLAG ; Is the cursor currently off? bne crs9 ; Jump if yes lda #1 sta CURS_FLAG ; Mark it as off lda CURS_STATE ; Cursor currently displayed? beq crs8 ; Jump if no ldy CURS_X ; Get the character column lda (SCREEN_PTR),y ; Get character eor #$80 sta (SCREEN_PTR),y ; Store character back lda CURS_COLOR sta (CRAM_PTR),y ; Store color back crs8: lda #0 sta CURS_STATE ; Cursor not displayed crs9: rts seton: lda #0 sta CURS_FLAG rts .endproc
wagiminator/C64-Collection
12,946
C64_xu1541/software/tools/cc65-2.13.2/libsrc/c64/c64-1351.s
; ; Driver for the 1351 proportional mouse. Parts of the code are from ; the Commodore 1351 mouse users guide. ; ; 2009-09-26, Ullrich von Bassewitz ; 2010-02-06, Greg King ; ; The driver prevents the keyboard from interfering by changing the ; keyboard's output port into an input port while the driver reads its ; controller device. That disables a wire that is left active by the ; Kernal. That wire is used by the STOP-key to break out of BASIC ; programs -- CC65 programs don't use that feature. The wire is shared ; by these keys: STOP, "Q", Commodore, Space, "2", CTRL, Left-Arrow, and ; "1". I listed them, in order, from bit 7 over to bit 0. The ; rightmost five keys can look like joystick switches. ; ; The driver prevents the mouse/joystick from interfering by "blinding" ; the keyboard scanner while any button/switch is active. It changes ; the input port into an output port, then stores all zero-bits in that ; port's latch. Reading from an output port sees the bitwise-AND of the ; latch and the input signals. Therefore, the scanner thinks that eight ; keys are being pushed at the same time. It doesn't know what to do ; about that condition; so, it does nothing. The driver lets the ; scanner see normally, again, when no buttons/switches are active. ; .include "zeropage.inc" .include "mouse-kernel.inc" .include "c64.inc" .macpack generic ; ------------------------------------------------------------------------ ; Header. Includes jump table .segment "JUMPTABLE" HEADER: ; Driver signature .byte $6d, $6f, $75 ; "mou" .byte MOUSE_API_VERSION ; Mouse driver API version number ; Jump table. .addr INSTALL .addr UNINSTALL .addr HIDE .addr SHOW .addr SETBOX .addr GETBOX .addr MOVE .addr BUTTONS .addr POS .addr INFO .addr IOCTL .addr IRQ ; Mouse driver flags .byte MOUSE_FLAG_LATE_IRQ ; Callback table, set by the kernel before INSTALL is called CHIDE: jmp $0000 ; Hide the cursor CSHOW: jmp $0000 ; Show the cursor CMOVEX: jmp $0000 ; Move the cursor to X coord CMOVEY: jmp $0000 ; Move the cursor to Y coord ;---------------------------------------------------------------------------- ; Constants SCREEN_HEIGHT = YSIZE * 8 - 1 ; (origin is zero) SCREEN_WIDTH = XSIZE * 8 - 1 ;---------------------------------------------------------------------------- ; Global variables. The bounding box values are sorted so that they can be ; written with the least effort in the SETBOX and GETBOX routines, so don't ; reorder them. .bss Vars: OldPotX: .res 1 ; Old hw counter values OldPotY: .res 1 XPos: .res 2 ; Current mouse position, X YPos: .res 2 ; Current mouse position, Y XMin: .res 2 ; X1 value of bounding box YMin: .res 2 ; Y1 value of bounding box XMax: .res 2 ; X2 value of bounding box YMax: .res 2 ; Y2 value of bounding box Buttons: .res 1 ; button status bits OldValue: .res 1 ; Temp for MoveCheck routine NewValue: .res 1 ; Temp for MoveCheck routine ; Default values for above variables .rodata ; (We use ".proc" because we want to define both a label and a scope.) .proc DefVars .byte 0, 0 ; OldPotX/OldPotY .word SCREEN_WIDTH/2 ; XPos .word SCREEN_HEIGHT/2 ; YPos .word 0 ; XMin .word 0 ; YMin .word SCREEN_WIDTH ; XMax .word SCREEN_HEIGHT ; YMax .byte %00000000 ; Buttons .endproc .code ;---------------------------------------------------------------------------- ; INSTALL routine. Is called after the driver is loaded into memory. If ; possible, check if the hardware is present. ; Must return an MOUSE_ERR_xx code in a/x. INSTALL: ; Initialize variables. Just copy the default stuff over ldx #.sizeof(DefVars)-1 @L1: lda DefVars,x sta Vars,x dex bpl @L1 ; Be sure the mouse cursor is invisible and at the default location. We ; need to do that here, because our mouse interrupt handler doesn't set the ; mouse position if it hasn't changed. sei jsr CHIDE lda XPos ldx XPos+1 jsr CMOVEX lda YPos ldx YPos+1 jsr CMOVEY cli ; Done, return zero (= MOUSE_ERR_OK) ldx #$00 txa rts ;---------------------------------------------------------------------------- ; UNINSTALL routine. Is called before the driver is removed from memory. ; No return code required (the driver is removed from memory on return). UNINSTALL = HIDE ; Hide cursor on exit ;---------------------------------------------------------------------------- ; HIDE routine. Is called to hide the mouse pointer. The mouse kernel manages ; a counter for calls to show/hide, and the driver entry point is only called ; if the mouse is currently visible and should get hidden. For most drivers, ; no special action is required besides hiding the mouse cursor. ; No return code required. HIDE: sei jsr CHIDE cli rts ;---------------------------------------------------------------------------- ; SHOW routine. Is called to show the mouse pointer. The mouse kernel manages ; a counter for calls to show/hide, and the driver entry point is only called ; if the mouse is currently hidden and should become visible. For most drivers, ; no special action is required besides enabling the mouse cursor. ; No return code required. SHOW: sei jsr CSHOW cli rts ;---------------------------------------------------------------------------- ; SETBOX: Set the mouse bounding box. The parameters are passed as they come ; from the C program, that is, a pointer to a mouse_box struct in a/x. ; No checks are done if the mouse is currently inside the box, this is the job ; of the caller. It is not necessary to validate the parameters, trust the ; caller and save some code here. No return code required. SETBOX: sta ptr1 stx ptr1+1 ; Save data pointer ldy #.sizeof (MOUSE_BOX)-1 sei @L1: lda (ptr1),y sta XMin,y dey bpl @L1 cli rts ;---------------------------------------------------------------------------- ; GETBOX: Return the mouse bounding box. The parameters are passed as they ; come from the C program, that is, a pointer to a mouse_box struct in a/x. GETBOX: sta ptr1 stx ptr1+1 ; Save data pointer ldy #.sizeof (MOUSE_BOX)-1 @L1: lda XMin,y sta (ptr1),y dey bpl @L1 rts ;---------------------------------------------------------------------------- ; MOVE: Move the mouse to a new position. The position is passed as it comes ; from the C program, that is: X on the stack and Y in a/x. The C wrapper will ; remove the parameter from the stack on return. ; No checks are done if the new position is valid (within the bounding box or ; the screen). No return code required. ; MOVE: sei ; No interrupts sta YPos stx YPos+1 ; New Y position jsr CMOVEY ; Set it ldy #$01 lda (sp),y sta XPos+1 tax dey lda (sp),y sta XPos ; New X position jsr CMOVEX ; Move the cursor cli ; Allow interrupts rts ;---------------------------------------------------------------------------- ; BUTTONS: Return the button mask in a/x. BUTTONS: lda Buttons ldx #0 and #$1F rts ;---------------------------------------------------------------------------- ; POS: Return the mouse position in the MOUSE_POS struct pointed to by ptr1. ; No return code required. POS: ldy #MOUSE_POS::XCOORD ; Structure offset sei ; Disable interrupts lda XPos ; Transfer the position sta (ptr1),y lda XPos+1 iny sta (ptr1),y lda YPos iny sta (ptr1),y lda YPos+1 cli ; Enable interrupts iny sta (ptr1),y ; Store last byte rts ; Done ;---------------------------------------------------------------------------- ; INFO: Returns mouse position and current button mask in the MOUSE_INFO ; struct pointed to by ptr1. No return code required. ; ; We're cheating here to keep the code smaller: The first fields of the ; mouse_info struct are identical to the mouse_pos struct, so we will just ; call _mouse_pos to initialize the struct pointer and fill the position ; fields. INFO: jsr POS ; Fill in the button state jsr BUTTONS ; Will not touch ptr1 ldy #MOUSE_INFO::BUTTONS sta (ptr1),y rts ;---------------------------------------------------------------------------- ; IOCTL: Driver defined entry point. The wrapper will pass a pointer to ioctl ; specific data in ptr1, and the ioctl code in A. ; Must return an error code in a/x. ; IOCTL: lda #<MOUSE_ERR_INV_IOCTL ; We don't support ioclts for now ldx #>MOUSE_ERR_INV_IOCTL rts ;---------------------------------------------------------------------------- ; IRQ: Irq handler entry point. Called as a subroutine but in IRQ context ; (so be careful). The routine MUST return carry set if the interrupt has been ; 'handled' - which means that the interrupt source is gone. Otherwise it ; MUST return carry clear. ; IRQ: ; Record the state of the buttons. ; Avoid crosstalk between the keyboard and the mouse. ldy #%00000000 ; Set ports A and B to input sty CIA1_DDRB sty CIA1_DDRA ; Keyboard won't look like mouse lda CIA1_PRB ; Read Control-Port 1 dec CIA1_DDRA ; Set port A back to output eor #%11111111 ; Bit goes up when button goes down sta Buttons beq @L0 ;(bze) dec CIA1_DDRB ; Mouse won't look like keyboard sty CIA1_PRB ; Set "all keys pushed" @L0: lda SID_ADConv1 ; Get mouse X movement ldy OldPotX jsr MoveCheck ; Calculate movement vector ; Skip processing if nothing has changed bcc @SkipX sty OldPotX ; Calculate the new X coordinate (--> a/y) add XPos tay ; Remember low byte txa adc XPos+1 tax ; Limit the X coordinate to the bounding box cpy XMin sbc XMin+1 bpl @L1 ldy XMin ldx XMin+1 jmp @L2 @L1: txa cpy XMax sbc XMax+1 bmi @L2 ldy XMax ldx XMax+1 @L2: sty XPos stx XPos+1 ; Move the mouse pointer to the new X pos tya jsr CMOVEX ; Calculate the Y movement vector @SkipX: lda SID_ADConv2 ; Get mouse Y movement ldy OldPotY jsr MoveCheck ; Calculate movement ; Skip processing if nothing has changed bcc @SkipY sty OldPotY ; Calculate the new Y coordinate (--> a/y) sta OldValue lda YPos sub OldValue tay stx OldValue lda YPos+1 sbc OldValue tax ; Limit the Y coordinate to the bounding box cpy YMin sbc YMin+1 bpl @L3 ldy YMin ldx YMin+1 jmp @L4 @L3: txa cpy YMax sbc YMax+1 bmi @L4 ldy YMax ldx YMax+1 @L4: sty YPos stx YPos+1 ; Move the mouse pointer to the new Y pos tya jsr CMOVEY ; Done clc ; Interrupt not "handled" @SkipY: rts ; -------------------------------------------------------------------------- ; ; Move check routine, called for both coordinates. ; ; Entry: y = old value of pot register ; a = current value of pot register ; Exit: y = value to use for old value ; x/a = delta value for position ; MoveCheck: sty OldValue sta NewValue ldx #$00 sub OldValue ; a = mod64 (new - old) and #%01111111 cmp #%01000000 ; if (a > 0) bcs @L1 ; lsr a ; a /= 2; beq @L2 ; if (a != 0) ldy NewValue ; y = NewValue sec rts ; return @L1: ora #%11000000 ; else, "or" in high-order bits cmp #$FF ; if (a != -1) beq @L2 sec ror a ; a /= 2 dex ; high byte = -1 (X = $FF) ldy NewValue sec rts @L2: txa ; A = $00 clc rts
wagiminator/C64-Collection
12,400
C64_xu1541/software/tools/cc65-2.13.2/libsrc/c64/c64-joymouse.s
; ; Driver for a "joystick mouse". ; ; Ullrich von Bassewitz, 2004-03-29, 2009-09-26 ; 2010-02-08, Greg King ; ; The driver prevents the keyboard from interfering by changing the ; keyboard's output port into an input port while the driver reads its ; controller device. That disables a wire that is left active by the ; Kernal. That wire is used by the STOP-key to break out of BASIC ; programs -- CC65 programs don't use that feature. The wire is shared ; by these keys: STOP, "Q", Commodore, Space, "2", CTRL, Left-Arrow, and ; "1". I listed them, in order, from bit 7 over to bit 0. The ; rightmost five keys can look like joystick switches. ; ; The driver prevents the mouse/joystick from interfering by "blinding" ; the keyboard scanner while any button/switch is active. It changes ; the input port into an output port, then stores all zero-bits in that ; port's latch. Reading from an output port sees the bitwise-AND of the ; latch and the input signals. Therefore, the scanner thinks that eight ; keys are being pushed at the same time. It doesn't know what to do ; about that condition; so, it does nothing. The driver lets the ; scanner see normally, again, when no buttons/switches are active. ; .include "zeropage.inc" .include "mouse-kernel.inc" .include "c64.inc" .macpack generic ; ------------------------------------------------------------------------ ; Header. Includes jump table .segment "JUMPTABLE" HEADER: ; Driver signature .byte $6d, $6f, $75 ; "mou" .byte MOUSE_API_VERSION ; Mouse driver API version number ; Jump table. .addr INSTALL .addr UNINSTALL .addr HIDE .addr SHOW .addr SETBOX .addr GETBOX .addr MOVE .addr BUTTONS .addr POS .addr INFO .addr IOCTL .addr IRQ ; Mouse driver flags .byte MOUSE_FLAG_LATE_IRQ ; Callback table, set by the kernel before INSTALL is called CHIDE: jmp $0000 ; Hide the cursor CSHOW: jmp $0000 ; Show the cursor CMOVEX: jmp $0000 ; Move the cursor to X coord CMOVEY: jmp $0000 ; Move the cursor to Y coord ;---------------------------------------------------------------------------- ; Constants SCREEN_HEIGHT = 200 SCREEN_WIDTH = 320 .enum JOY UP = $01 DOWN = $02 LEFT = $04 RIGHT = $08 FIRE = $10 .endenum ;---------------------------------------------------------------------------- ; Global variables. The bounding box values are sorted so that they can be ; written with the least effort in the SETBOX and GETBOX routines, so don't ; reorder them. .bss Vars: YPos: .res 2 ; Current mouse position, Y XPos: .res 2 ; Current mouse position, X XMin: .res 2 ; X1 value of bounding box YMin: .res 2 ; Y1 value of bounding box XMax: .res 2 ; X2 value of bounding box YMax: .res 2 ; Y2 value of bounding box Buttons: .res 1 ; Button mask ; Temporary value used in the int handler Temp: .res 1 ; Default values for above variables .rodata .proc DefVars .word SCREEN_HEIGHT/2 ; YPos .word SCREEN_WIDTH/2 ; XPos .word 0 ; XMin .word 0 ; YMin .word SCREEN_WIDTH ; XMax .word SCREEN_HEIGHT ; YMax .byte 0 ; Buttons .endproc .code ;---------------------------------------------------------------------------- ; INSTALL routine. Is called after the driver is loaded into memory. If ; possible, check if the hardware is present. ; Must return an MOUSE_ERR_xx code in a/x. INSTALL: ; Initialize variables. Just copy the default stuff over ldx #.sizeof(DefVars)-1 @L1: lda DefVars,x sta Vars,x dex bpl @L1 ; Be sure the mouse cursor is invisible and at the default location. We ; need to do that here, because our mouse interrupt handler doesn't set the ; mouse position if it hasn't changed. sei jsr CHIDE lda XPos ldx XPos+1 jsr CMOVEX lda YPos ldx YPos+1 jsr CMOVEY cli ; Done, return zero (= MOUSE_ERR_OK) ldx #$00 txa rts ;---------------------------------------------------------------------------- ; UNINSTALL routine. Is called before the driver is removed from memory. ; No return code required (the driver is removed from memory on return). UNINSTALL = HIDE ; Hide cursor on exit ;---------------------------------------------------------------------------- ; HIDE routine. Is called to hide the mouse pointer. The mouse kernel manages ; a counter for calls to show/hide, and the driver entry point is only called ; if the mouse is currently visible and should get hidden. For most drivers, ; no special action is required besides hiding the mouse cursor. ; No return code required. HIDE: sei jsr CHIDE cli rts ;---------------------------------------------------------------------------- ; SHOW routine. Is called to show the mouse pointer. The mouse kernel manages ; a counter for calls to show/hide, and the driver entry point is only called ; if the mouse is currently hidden and should become visible. For most drivers, ; no special action is required besides enabling the mouse cursor. ; No return code required. SHOW: sei jsr CSHOW cli rts ;---------------------------------------------------------------------------- ; SETBOX: Set the mouse bounding box. The parameters are passed as they come ; from the C program, that is, a pointer to a mouse_box struct in a/x. ; No checks are done if the mouse is currently inside the box, this is the job ; of the caller. It is not necessary to validate the parameters, trust the ; caller and save some code here. No return code required. SETBOX: sta ptr1 stx ptr1+1 ; Save data pointer ldy #.sizeof (MOUSE_BOX)-1 sei @L1: lda (ptr1),y sta XMin,y dey bpl @L1 cli rts ;---------------------------------------------------------------------------- ; GETBOX: Return the mouse bounding box. The parameters are passed as they ; come from the C program, that is, a pointer to a mouse_box struct in a/x. GETBOX: sta ptr1 stx ptr1+1 ; Save data pointer ldy #.sizeof (MOUSE_BOX)-1 @L1: lda XMin,y sta (ptr1),y dey bpl @L1 rts ;---------------------------------------------------------------------------- ; MOVE: Move the mouse to a new position. The position is passed as it comes ; from the C program, that is: X on the stack and Y in a/x. The C wrapper will ; remove the parameter from the stack on return. ; No checks are done if the new position is valid (within the bounding box or ; the screen). No return code required. ; MOVE: sei ; No interrupts sta YPos stx YPos+1 ; New Y position jsr CMOVEY ; Set it ldy #$01 lda (sp),y sta XPos+1 tax dey lda (sp),y sta XPos ; New X position jsr CMOVEX ; Move the cursor cli ; Allow interrupts rts ;---------------------------------------------------------------------------- ; BUTTONS: Return the button mask in a/x. BUTTONS: lda Buttons ldx #$00 rts ;---------------------------------------------------------------------------- ; POS: Return the mouse position in the MOUSE_POS struct pointed to by ptr1. ; No return code required. POS: ldy #MOUSE_POS::XCOORD ; Structure offset sei ; Disable interrupts lda XPos ; Transfer the position sta (ptr1),y lda XPos+1 iny sta (ptr1),y lda YPos iny sta (ptr1),y lda YPos+1 cli ; Enable interrupts iny sta (ptr1),y ; Store last byte rts ; Done ;---------------------------------------------------------------------------- ; INFO: Returns mouse position and current button mask in the MOUSE_INFO ; struct pointed to by ptr1. No return code required. ; ; We're cheating here to keep the code smaller: The first fields of the ; mouse_info struct are identical to the mouse_pos struct, so we will just ; call _mouse_pos to initialize the struct pointer and fill the position ; fields. INFO: jsr POS ; Fill in the button state lda Buttons ldy #MOUSE_INFO::BUTTONS sta (ptr1),y rts ;---------------------------------------------------------------------------- ; IOCTL: Driver defined entry point. The wrapper will pass a pointer to ioctl ; specific data in ptr1, and the ioctl code in A. ; Must return an error code in a/x. ; IOCTL: lda #<MOUSE_ERR_INV_IOCTL ; We don't support ioclts for now ldx #>MOUSE_ERR_INV_IOCTL rts ;---------------------------------------------------------------------------- ; IRQ: Irq handler entry point. Called as a subroutine but in IRQ context ; (so be careful). The routine MUST return carry set if the interrupt has been ; 'handled' - which means that the interrupt source is gone. Otherwise it ; MUST return carry clear. ; ; Avoid crosstalk between the keyboard and a joystick. IRQ: ldy #%00000000 ; Set ports A and B to input sty CIA1_DDRB sty CIA1_DDRA ; Keyboard won't look like joystick lda CIA1_PRB ; Read Control-Port 1 dec CIA1_DDRA ; Set port A back to output eor #%11111111 ; Bit goes up when switch goes down beq @Save ;(bze) dec CIA1_DDRB ; Joystick won't look like keyboard sty CIA1_PRB ; Set "all keys pushed" @Save: sta Temp ; Check for a pressed button and place the result into Buttons ldx #$00 ; Assume no button pressed and #JOY::FIRE ; Check fire button beq @L0 ; Jump if not pressed ldx #MOUSE_BTN_LEFT ; Left (only) button is pressed @L0: stx Buttons ; Check left/right lda Temp ; Read joystick #0 and #(JOY::LEFT | JOY::RIGHT) beq @SkipX ; ; We will cheat here and rely on the fact that either the left, OR the right ; bit can be active and #JOY::RIGHT ; Check RIGHT bit bne @Right lda #$FF tax bne @AddX ; Branch always @Right: lda #$01 ldx #$00 ; Calculate the new X coordinate (--> a/y) @AddX: add XPos tay ; Remember low byte txa adc XPos+1 tax ; Limit the X coordinate to the bounding box cpy XMin sbc XMin+1 bpl @L1 ldy XMin ldx XMin+1 jmp @L2 @L1: txa cpy XMax sbc XMax+1 bmi @L2 ldy XMax ldx XMax+1 @L2: sty XPos stx XPos+1 ; Move the mouse pointer to the new X pos tya jsr CMOVEX ; Calculate the Y movement vector @SkipX: lda Temp ; Read joystick #0 and #(JOY::UP | JOY::DOWN) ; Check up/down beq @SkipY ; ; We will cheat here and rely on the fact that either the up, OR the down ; bit can be active lsr a ; Check UP bit bcc @Down lda #$FF tax bne @AddY @Down: lda #$01 ldx #$00 ; Calculate the new Y coordinate (--> a/y) @AddY: add YPos tay ; Remember low byte txa adc YPos+1 tax ; Limit the Y coordinate to the bounding box cpy YMin sbc YMin+1 bpl @L3 ldy YMin ldx YMin+1 jmp @L4 @L3: txa cpy YMax sbc YMax+1 bmi @L4 ldy YMax ldx YMax+1 @L4: sty YPos stx YPos+1 ; Move the mouse pointer to the new X pos tya jsr CMOVEY ; Done @SkipY: clc ; Interrupt not handled rts
wagiminator/C64-Collection
8,486
C64_xu1541/software/tools/cc65-2.13.2/libsrc/c64/c64-potmouse.s
; ; Driver for a potentiometer "mouse" e.g. Koala Pad ; ; Ullrich von Bassewitz, 2004-03-29, 2009-09-26 ; Stefan Haubenthal, 2006-08-20 ; .include "zeropage.inc" .include "mouse-kernel.inc" .include "c64.inc" .macpack generic ; ------------------------------------------------------------------------ ; Header. Includes jump table .segment "JUMPTABLE" HEADER: ; Driver signature .byte $6d, $6f, $75 ; "mou" .byte MOUSE_API_VERSION ; Mouse driver API version number ; Jump table. .addr INSTALL .addr UNINSTALL .addr HIDE .addr SHOW .addr SETBOX .addr GETBOX .addr MOVE .addr BUTTONS .addr POS .addr INFO .addr IOCTL .addr IRQ ; Callback table, set by the kernel before INSTALL is called CHIDE: jmp $0000 ; Hide the cursor CSHOW: jmp $0000 ; Show the cursor CMOVEX: jmp $0000 ; Move the cursor to X coord CMOVEY: jmp $0000 ; Move the cursor to Y coord ;---------------------------------------------------------------------------- ; Constants SCREEN_HEIGHT = 200 SCREEN_WIDTH = 320 .enum JOY UP = $01 DOWN = $02 LEFT = $04 RIGHT = $08 FIRE = $10 .endenum ;---------------------------------------------------------------------------- ; Global variables. The bounding box values are sorted so that they can be ; written with the least effort in the SETBOX and GETBOX routines, so don't ; reorder them. .bss Vars: YPos: .res 2 ; Current mouse position, Y XPos: .res 2 ; Current mouse position, X XMin: .res 2 ; X1 value of bounding box YMin: .res 2 ; Y1 value of bounding box XMax: .res 2 ; X2 value of bounding box YMax: .res 2 ; Y2 value of bounding box Buttons: .res 1 ; Button mask ; Temporary value used in the int handler Temp: .res 1 ; Default values for above variables .rodata .proc DefVars .word SCREEN_HEIGHT/2 ; YPos .word SCREEN_WIDTH/2 ; XPos .word 0 ; XMin .word 0 ; YMin .word SCREEN_WIDTH ; XMax .word SCREEN_HEIGHT ; YMax .byte 0 ; Buttons .endproc .code ;---------------------------------------------------------------------------- ; INSTALL routine. Is called after the driver is loaded into memory. If ; possible, check if the hardware is present. ; Must return an MOUSE_ERR_xx code in a/x. INSTALL: ; Initialize variables. Just copy the default stuff over ldx #.sizeof(DefVars)-1 @L1: lda DefVars,x sta Vars,x dex bpl @L1 ; Be sure the mouse cursor is invisible and at the default location. We ; need to do that here, because our mouse interrupt handler doesn't set the ; mouse position if it hasn't changed. sei jsr CHIDE lda XPos ldx XPos+1 jsr CMOVEX lda YPos ldx YPos+1 jsr CMOVEY cli ; Done, return zero (= MOUSE_ERR_OK) ldx #$00 txa rts ;---------------------------------------------------------------------------- ; UNINSTALL routine. Is called before the driver is removed from memory. ; No return code required (the driver is removed from memory on return). UNINSTALL = HIDE ; Hide cursor on exit ;---------------------------------------------------------------------------- ; HIDE routine. Is called to hide the mouse pointer. The mouse kernel manages ; a counter for calls to show/hide, and the driver entry point is only called ; if the mouse is currently visible and should get hidden. For most drivers, ; no special action is required besides hiding the mouse cursor. ; No return code required. HIDE: sei jsr CHIDE cli rts ;---------------------------------------------------------------------------- ; SHOW routine. Is called to show the mouse pointer. The mouse kernel manages ; a counter for calls to show/hide, and the driver entry point is only called ; if the mouse is currently hidden and should become visible. For most drivers, ; no special action is required besides enabling the mouse cursor. ; No return code required. SHOW: sei jsr CSHOW cli rts ;---------------------------------------------------------------------------- ; SETBOX: Set the mouse bounding box. The parameters are passed as they come ; from the C program, that is, a pointer to a mouse_box struct in a/x. ; No checks are done if the mouse is currently inside the box, this is the job ; of the caller. It is not necessary to validate the parameters, trust the ; caller and save some code here. No return code required. SETBOX: sta ptr1 stx ptr1+1 ; Save data pointer ldy #.sizeof (MOUSE_BOX)-1 sei @L1: lda (ptr1),y sta XMin,y dey bpl @L1 cli rts ;---------------------------------------------------------------------------- ; GETBOX: Return the mouse bounding box. The parameters are passed as they ; come from the C program, that is, a pointer to a mouse_box struct in a/x. GETBOX: sta ptr1 stx ptr1+1 ; Save data pointer ldy #.sizeof (MOUSE_BOX)-1 sei @L1: lda XMin,y sta (ptr1),y dey bpl @L1 cli rts ;---------------------------------------------------------------------------- ; MOVE: Move the mouse to a new position. The position is passed as it comes ; from the C program, that is: X on the stack and Y in a/x. The C wrapper will ; remove the parameter from the stack on return. ; No checks are done if the new position is valid (within the bounding box or ; the screen). No return code required. ; MOVE: sei ; No interrupts sta YPos stx YPos+1 ; New Y position jsr CMOVEY ; Set it ldy #$01 lda (sp),y sta XPos+1 tax dey lda (sp),y sta XPos ; New X position jsr CMOVEX ; Move the cursor cli ; Allow interrupts rts ;---------------------------------------------------------------------------- ; BUTTONS: Return the button mask in a/x. BUTTONS: lda Buttons ldx #$00 rts ;---------------------------------------------------------------------------- ; POS: Return the mouse position in the MOUSE_POS struct pointed to by ptr1. ; No return code required. POS: ldy #MOUSE_POS::XCOORD ; Structure offset sei ; Disable interrupts lda XPos ; Transfer the position sta (ptr1),y lda XPos+1 iny sta (ptr1),y lda YPos iny sta (ptr1),y lda YPos+1 cli ; Enable interrupts iny sta (ptr1),y ; Store last byte rts ; Done ;---------------------------------------------------------------------------- ; INFO: Returns mouse position and current button mask in the MOUSE_INFO ; struct pointed to by ptr1. No return code required. ; ; We're cheating here to keep the code smaller: The first fields of the ; mouse_info struct are identical to the mouse_pos struct, so we will just ; call _mouse_pos to initialize the struct pointer and fill the position ; fields. INFO: jsr POS ; Fill in the button state lda Buttons ldy #MOUSE_INFO::BUTTONS sta (ptr1),y rts ;---------------------------------------------------------------------------- ; IOCTL: Driver defined entry point. The wrapper will pass a pointer to ioctl ; specific data in ptr1, and the ioctl code in A. ; Must return an error code in a/x. ; IOCTL: lda #<MOUSE_ERR_INV_IOCTL ; We don't support ioclts for now ldx #>MOUSE_ERR_INV_IOCTL rts ;---------------------------------------------------------------------------- ; IRQ: Irq handler entry point. Called as a subroutine but in IRQ context ; (so be careful). ; IRQ: lda #$7F sta CIA1_PRA lda CIA1_PRB ; Read port #1 and #%00001100 eor #%00001100 ; Make all bits active high asl sta Buttons lsr lsr lsr and #%00000001 ora Buttons sta Buttons ldx #%01000000 stx CIA1_PRA ldy #0 : dey bne :- ldx SID_ADConv1 stx XPos ldx SID_ADConv2 stx YPos lda #$FF tax bne @AddX ; Branch always lda #$01 ldx #$00 ; Calculate the new X coordinate (--> a/y) @AddX: add XPos tay ; Remember low byte txa adc XPos+1 tax ; Limit the X coordinate to the bounding box cpy XMin sbc XMin+1 bpl @L1 ldy XMin ldx XMin+1 jmp @L2 @L1: txa cpy XMax sbc XMax+1 bmi @L2 ldy XMax ldx XMax+1 @L2: sty XPos stx XPos+1 ; Move the mouse pointer to the new X pos tya jsr CMOVEX lda #$FF tax bne @AddY @Down: lda #$01 ldx #$00 ; Calculate the new Y coordinate (--> a/y) @AddY: add YPos tay ; Remember low byte txa adc YPos+1 tax ; Limit the Y coordinate to the bounding box cpy YMin sbc YMin+1 bpl @L3 ldy YMin ldx YMin+1 jmp @L4 @L3: txa cpy YMax sbc YMax+1 bmi @L4 ldy YMax ldx YMax+1 @L4: sty YPos stx YPos+1 ; Move the mouse pointer to the new X pos tya jmp CMOVEY
wagiminator/C64-Collection
12,546
C64_xu1541/software/tools/cc65-2.13.2/libsrc/c64/c64-swlink.s
; ; Serial driver for the C64 using a Swiftlink or Turbo-232 cartridge. ; ; Ullrich von Bassewitz, 2003-04-18 ; ; The driver is based on the cc65 rs232 module, which in turn is based on ; Craig Bruce device driver for the Switftlink/Turbo-232. ; ; SwiftLink/Turbo-232 v0.90 device driver, by Craig Bruce, 14-Apr-1998. ; ; This software is Public Domain. It is in Buddy assembler format. ; ; This device driver uses the SwiftLink RS-232 Serial Cartridge, available from ; Creative Micro Designs, Inc, and also supports the extensions of the Turbo232 ; Serial Cartridge. Both devices are based on the 6551 ACIA chip. It also ; supports the "hacked" SwiftLink with a 1.8432 MHz crystal. ; ; The code assumes that the kernal + I/O are in context. On the C128, call ; it from Bank 15. On the C64, don't flip out the Kernal unless a suitable ; NMI catcher is put into the RAM under then Kernal. For the SuperCPU, the ; interrupt handling assumes that the 65816 is in 6502-emulation mode. ; .include "zeropage.inc" .include "ser-kernel.inc" .include "ser-error.inc" .include "c64.inc" ; ------------------------------------------------------------------------ ; Header. Includes jump table .segment "JUMPTABLE" ; Driver signature .byte $73, $65, $72 ; "ser" .byte SER_API_VERSION ; Serial API version number ; Jump table. .word INSTALL .word UNINSTALL .word OPEN .word CLOSE .word GET .word PUT .word STATUS .word IOCTL .word IRQ ;---------------------------------------------------------------------------- ; I/O definitions ACIA = $DE00 ACIA_DATA = ACIA+0 ; Data register ACIA_STATUS = ACIA+1 ; Status register ACIA_CMD = ACIA+2 ; Command register ACIA_CTRL = ACIA+3 ; Control register ;---------------------------------------------------------------------------- ; ; Global variables ; ; We reuse the RS232 zero page variables for the driver, since the ROM ; routines cannot be used together with this driver. RecvHead = $B5 ; Head of receive buffer RecvTail = $BD ; Tail of receive buffer RecvFreeCnt = $F7 ; Number of bytes in receive buffer SendHead = $F8 ; Head of send buffer SendTail = $F9 ; Tail of send buffer SendFreeCnt = $FA ; Number of bytes free in send buffer .bss Stopped: .res 1 ; Flow-stopped flag RtsOff: .res 1 ; ; Send and receive buffers: 256 bytes each RecvBuf: .res 256 SendBuf: .res 256 .data NmiContinue: .byte $4c ; JMP instruction for NMI save -- continue NmiSave: .res 2 ; normal NMI handler .rodata ; Tables used to translate RS232 params into register values BaudTable: ; bit7 = 1 means setting is invalid .byte $FF ; SER_BAUD_45_5 .byte $FF ; SER_BAUD_50 .byte $FF ; SER_BAUD_75 .byte $FF ; SER_BAUD_110 .byte $FF ; SER_BAUD_134_5 .byte $02 ; SER_BAUD_150 .byte $05 ; SER_BAUD_300 .byte $06 ; SER_BAUD_600 .byte $07 ; SER_BAUD_1200 .byte $FF ; SER_BAUD_1800 .byte $08 ; SER_BAUD_2400 .byte $09 ; SER_BAUD_3600 .byte $0A ; SER_BAUD_4800 .byte $0B ; SER_BAUD_7200 .byte $0C ; SER_BAUD_9600 .byte $0E ; SER_BAUD_19200 .byte $0F ; SER_BAUD_38400 .byte $FF ; SER_BAUD_57600 .byte $FF ; SER_BAUD_115200 .byte $FF ; SER_BAUD_230400 BitTable: .byte $60 ; SER_BITS_5 .byte $40 ; SER_BITS_6 .byte $20 ; SER_BITS_7 .byte $00 ; SER_BITS_8 StopTable: .byte $00 ; SER_STOP_1 .byte $80 ; SER_STOP_2 ParityTable: .byte $00 ; SER_PAR_NONE .byte $20 ; SER_PAR_ODD .byte $60 ; SER_PAR_EVEN .byte $A0 ; SER_PAR_MARK .byte $E0 ; SER_PAR_SPACE .code ;---------------------------------------------------------------------------- ; INSTALL routine. Is called after the driver is loaded into memory. If ; possible, check if the hardware is present. ; Must return an SER_ERR_xx code in a/x. INSTALL: ; Deactivate DTR and disable 6551 interrupts lda #%00001010 sta ACIA_CMD ; Set up the nmi vector lda NMIVec ldy NMIVec+1 sta NmiSave+0 sty NmiSave+1 lda #<NmiHandler ldy #>NmiHandler SetNMI: sta NMIVec sty NMIVec+1 ; Done, return an error code lda #<SER_ERR_OK tax ; A is zero rts ;---------------------------------------------------------------------------- ; UNINSTALL routine. Is called before the driver is removed from memory. ; Must return an SER_ERR_xx code in a/x. UNINSTALL: ; Stop interrupts, drop DTR lda #%00001010 sta ACIA_CMD ; Restore NMI vector and return OK lda NmiSave+0 ldy NmiSave+1 jmp SetNMI ;---------------------------------------------------------------------------- ; PARAMS routine. A pointer to a ser_params structure is passed in ptr1. ; Must return an SER_ERR_xx code in a/x. OPEN: ; Check if the handshake setting is valid ldy #SER_PARAMS::HANDSHAKE ; Handshake lda (ptr1),y cmp #SER_HS_HW ; This is all we support bne InvParam ; Initialize buffers jsr InitBuffers ; Set the value for the control register, which contains stop bits, word ; length and the baud rate. ldy #SER_PARAMS::BAUDRATE lda (ptr1),y ; Baudrate index tay lda BaudTable,y ; Get 6551 value bmi InvBaud ; Branch if rate not supported sta tmp1 ldy #SER_PARAMS::DATABITS ; Databits lda (ptr1),y tay lda BitTable,y ora tmp1 sta tmp1 ldy #SER_PARAMS::STOPBITS ; Stopbits lda (ptr1),y tay lda StopTable,y ora tmp1 ora #%00010000 ; Receiver clock source = baudrate sta ACIA_CTRL ; Set the value for the command register. We remember the base value in ; RtsOff, since we will have to manipulate ACIA_CMD often. ldy #SER_PARAMS::PARITY ; Parity lda (ptr1),y tay lda ParityTable,y ora #%00000001 ; DTR active sta RtsOff ora #%00001000 ; Enable receive interrupts sta ACIA_CMD ; Done lda #<SER_ERR_OK tax ; A is zero rts ; Invalid parameter InvParam: lda #<SER_ERR_INIT_FAILED ldx #>SER_ERR_INIT_FAILED rts ; Baud rate not available InvBaud: lda #<SER_ERR_BAUD_UNAVAIL ldx #>SER_ERR_BAUD_UNAVAIL rts ;---------------------------------------------------------------------------- ; CLOSE: Close the port, disable interrupts and flush the buffer. Called ; without parameters. Must return an error code in a/x. ; CLOSE: ; Stop interrupts, drop DTR lda #%00001010 sta ACIA_CMD ; Initalize buffers. Returns zero in a jsr InitBuffers ; Return OK lda #<SER_ERR_OK tax ; A is zero rts ;---------------------------------------------------------------------------- ; GET: Will fetch a character from the receive buffer and store it into the ; variable pointer to by ptr1. If no data is available, SER_ERR_NO_DATA is ; return. ; GET: ldx SendFreeCnt ; Send data if necessary inx ; X == $FF? beq @L1 lda #$00 jsr TryToSend ; Check for buffer empty @L1: lda RecvFreeCnt ; (25) cmp #$ff bne @L2 lda #<SER_ERR_NO_DATA ldx #>SER_ERR_NO_DATA rts ; Check for flow stopped & enough free: release flow control @L2: ldx Stopped ; (34) beq @L3 cmp #63 bcc @L3 lda #$00 sta Stopped lda RtsOff ora #%00001000 sta ACIA_CMD ; Get byte from buffer @L3: ldx RecvHead ; (41) lda RecvBuf,x inc RecvHead inc RecvFreeCnt ldx #$00 ; (59) sta (ptr1,x) txa ; Return code = 0 rts ;---------------------------------------------------------------------------- ; PUT: Output character in A. ; Must return an error code in a/x. ; PUT: ; Try to send ldx SendFreeCnt inx ; X = $ff? beq @L2 pha lda #$00 jsr TryToSend pla ; Put byte into send buffer & send @L2: ldx SendFreeCnt bne @L3 lda #<SER_ERR_OVERFLOW ; X is already zero rts @L3: ldx SendTail sta SendBuf,x inc SendTail dec SendFreeCnt lda #$ff jsr TryToSend lda #<SER_ERR_OK tax rts ;---------------------------------------------------------------------------- ; STATUS: Return the status in the variable pointed to by ptr1. ; Must return an error code in a/x. ; STATUS: lda ACIA_STATUS ldx #0 sta (ptr1,x) txa ; SER_ERR_OK rts ;---------------------------------------------------------------------------- ; IOCTL: Driver defined entry point. The wrapper will pass a pointer to ioctl ; specific data in ptr1, and the ioctl code in A. ; Must return an error code in a/x. ; IOCTL: lda #<SER_ERR_INV_IOCTL ; We don't support ioclts for now ldx #>SER_ERR_INV_IOCTL rts ;---------------------------------------------------------------------------- ; IRQ: Not used on the C64 ; IRQ = $0000 ;---------------------------------------------------------------------------- ; ; NMI handler ; C128 NMI overhead=76 cycles: int=7, maxLatency=6, ROMenter=33, ROMexit=30 ; C64 NMI overhead=76 cycles: int=7, maxLatency=6, ROMenter=34, ROMexit=29 ; ; timing: normal=76+43+9=128 cycles, assertFlow=76+52+9=137 cycles ; ; C128 @ 115.2k: 177 cycles avail (fast) ; C64 @ 57.6k: 177 cycles avail, worstAvail=177-43? = 134 ; SCPU @ 230.4k: 868 cycles avail: for a joke! ; NmiHandler: pha lda ACIA_STATUS ;(4) ;status ;check for byte received and #$08 ;(2) beq @L9 ;(2*) cld txa pha tya pha @L1: lda ACIA_DATA ;(4) data ;get byte and put into receive buffer ldy RecvTail ;(4) ldx RecvFreeCnt ;(4) beq @L3 ;(2*) Jump if no space in receive buffer sta RecvBuf,y ;(5) inc RecvTail ;(6) dec RecvFreeCnt ;(6) cpx #33 ;(2) check for buffer space low bcc @L2 ;(2*) jmp NMIEXIT ;(3) ; Assert flow control @L2: lda RtsOff ;(3) assert flow control if buffer space too low sta ACIA_CMD ;(4) command sta Stopped ;(3) @L3: jmp NMIEXIT ;(3) @L9: pla jmp NmiContinue ;---------------------------------------------------------------------------- ; Try to send a byte. Internal routine. A = TryHard .proc TryToSend sta tmp1 ; Remember tryHard flag @L0: lda SendFreeCnt cmp #$ff beq @L3 ; Bail out ; Check for flow stopped @L1: lda Stopped bne @L3 ; Bail out ; Check that swiftlink is ready to send @L2: lda ACIA_STATUS and #$10 bne @L4 bit tmp1 ;keep trying if must try hard bmi @L0 @L3: rts ; Send byte and try again @L4: ldx SendHead lda SendBuf,x sta ACIA_DATA inc SendHead inc SendFreeCnt jmp @L0 .endproc ;---------------------------------------------------------------------------- ; Initialize buffers InitBuffers: ldx #0 stx Stopped stx RecvHead stx RecvTail stx SendHead stx SendTail dex ; X = 255 stx RecvFreeCnt stx SendFreeCnt rts
wagiminator/C64-Collection
1,584
C64_xu1541/software/tools/cc65-2.13.2/libsrc/cbm510/color.s
; ; Ullrich von Bassewitz, 13.09.2001 ; .export _textcolor, _bgcolor, _bordercolor .import sys_bank, restore_bank .import vic: zp, CHARCOLOR: zp .include "cbm510.inc" ; ------------------------------------------------------------------------ ; unsigned char __fastcall__ textcolor (unsigned char color); ; /* Set the color for text output. The old color setting is returned. */ ; .proc _textcolor ldx CHARCOLOR ; get old value sta CHARCOLOR ; set new value txa rts .endproc ; ------------------------------------------------------------------------ ; unsigned char __fastcall__ bgcolor (unsigned char color); ; /* Set the color for the background. The old color setting is returned. */ ; .proc _bgcolor jsr sys_bank ; Switch to the system bank pha ; Save new color ldy #VIC_BG_COLOR0 lda (vic),y ; Get current color... tax ; ...into X pla ; Get new color sta (vic),y ; Set new color txa ; Get old color into X jmp restore_bank ; Restore the old color .endproc ; ------------------------------------------------------------------------ ; unsigned char __fastcall__ bordercolor (unsigned char color); ; /* Set the color for the border. The old color setting is returned. */ .proc _bordercolor jsr sys_bank ; Switch to the system bank pha ; Save new color ldy #VIC_BORDERCOLOR lda (vic),y ; Get current color... tax ; ...into X pla ; Get new color sta (vic),y ; Set new color txa ; Get old color into X jmp restore_bank ; Restore the old color .endproc
wagiminator/C64-Collection
14,192
C64_xu1541/software/tools/cc65-2.13.2/libsrc/cbm510/crt0.s
; ; Startup code for cc65 (CBM 500 version) ; .export _exit .export __STARTUP__ : absolute = 1 ; Mark as startup .import _clrscr, initlib, donelib, callirq_y .import push0, callmain .import __CHARRAM_START__, __CHARRAM_SIZE__, __VIDRAM_START__ .import __BSS_RUN__, __BSS_SIZE__, __EXTZP_RUN__ .import __INTERRUPTOR_COUNT__ .import scnkey, UDTIM .include "zeropage.inc" .include "extzp.inc" .include "cbm510.inc" ; ------------------------------------------------------------------------ ; BASIC header and a small BASIC program. Since it is not possible to start ; programs in other banks using SYS, the BASIC program will write a small ; machine code program into memory at $100 and start that machine code ; program. The machine code program will then start the machine language ; code in bank 0, which will initialize the system by copying stuff from ; the system bank, and start the application. ; ; Here's the basic program that's in the following lines: ; ; 10 for i=0 to 4 ; 20 read j ; 30 poke 256+i,j ; 40 next i ; 50 sys 256 ; 60 data 120,169,0,133,0 ; ; The machine program in the data lines is: ; ; sei ; lda #$00 ; sta $00 <-- Switch to bank 0 after this command ; ; Initialization is not only complex because of the jumping from one bank ; into another. but also because we want to save memory, and because of ; this, we will use the system memory ($00-$3FF) for initialization stuff ; that is overwritten later. ; .segment "BASICHDR" .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 ;------------------------------------------------------------------------------ ; A table that contains values that must be transfered from the system zero ; page into out zero page. Contains pairs of bytes, first one is the address ; in the system ZP, second one is our ZP address. The table goes into page 2, ; but is declared here, because it is needed earlier. .SEGMENT "PAGE2" .proc transfer_table .byte $9F, DEVNUM .byte $CA, CURS_Y .byte $CB, CURS_X .byte $EC, CHARCOLOR .endproc ;------------------------------------------------------------------------------ ; Page 3 data. This page contains the break vector and the bankswitch ; subroutine that is copied into high memory on startup. The space occupied by ; this routine will later be used for a copy of the bank 15 stack. It must be ; saved, since we're going to destroy it when calling bank 15. .segment "PAGE3" BRKVec: .addr _exit ; BRK indirect vector .proc callbank15 excrts = $FEFE .org $FEC3 entry: php pha lda #$0F ; Bank 15 sta IndReg txa pha tya pha sei ldy #$FF lda (sysp1),y tay lda ExecReg sta (sysp1),y dey lda #.hibyte(excrts-1) sta (sysp1),y dey lda #.lobyte(excrts-1) sta (sysp1),y tya sec sbc #7 sta $1FF ; Save new sp tay tsx pla iny sta (sysp1),y pla iny sta (sysp1),y pla iny sta (sysp1),y pla iny sta (sysp1),y lda $105,x sec sbc #3 iny sta (sysp1),y lda $106,x sbc #0 iny sta (sysp1),y ldy $1FF ; Restore sp in bank 15 lda #.hibyte(expull-1) sta (sysp1),y dey lda #.lobyte(expull-1) sta (sysp1),y dey pla pla tsx stx $1FF tya tax txs lda IndReg jmp $FFF6 expull: pla tay pla tax pla plp rts .if (expull <> $FF26) .error "Symbol expull must be aligned with kernal in bank 15" .endif .reloc .endproc ;------------------------------------------------------------------------------ ; 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. .segment "STARTUP" Back: sta ExecReg ; We are at $100 now. The following snippet is a copy of the code that is poked ; in the system bank memory by the basic header program, it's only for ; documentation and not actually used here: sei lda #$00 sta ExecReg ; This is the actual starting point of our code after switching banks for ; startup. Beware: The following code will get overwritten as soon as we ; use the stack (since it's in page 1)! We jump to another location, since ; we need some space for subroutines that aren't used later. jmp Origin ; Hardware vectors, copied to $FFFA .proc vectors sta ExecReg rts nop .word nmi ; NMI vector .word 0 ; Reset - not used .word irq ; IRQ vector .endproc ; Initializers for the extended zeropage. See extzp.s .proc extzp .word $0100 ; sysp1 .word $0300 ; sysp3 .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 .endproc ; Switch the indirect segment to the system bank Origin: lda #$0F sta IndReg ; Initialize the extended zeropage ldx #.sizeof(extzp)-1 L1: lda extzp,x sta <__EXTZP_RUN__,x dex bpl L1 ; Save the old stack pointer from the system bank and setup our hw sp tsx txa ldy #$FF sta (sysp1),y ; Save system stack point into $F:$1FF ldx #$FE ; Leave $1FF untouched for cross bank calls txs ; Set up our own stack ; Copy stuff from the system zeropage to ours lda #.sizeof(transfer_table) sta ktmp L2: ldx ktmp ldy transfer_table-2,x lda transfer_table-1,x tax lda (sysp0),y sta $00,x dec ktmp dec ktmp bne L2 ; Set the interrupt, NMI and other vectors ldx #.sizeof(vectors)-1 L3: lda vectors,x sta $10000 - .sizeof(vectors),x dex bpl L3 ; Setup the C stack lda #.lobyte(callbank15::entry) sta sp lda #.hibyte(callbank15::entry) sta sp+1 ; Setup the subroutine and jump vector table that redirects kernal calls to ; the system bank. ldy #.sizeof(callbank15) @L1: lda callbank15-1,y sta callbank15::entry-1,y dey bne @L1 ; Setup the jump vector table. Y is zero on entry. ldx #45-1 ; Number of vectors @L2: lda #$20 ; JSR opcode sta $FF6F,y iny lda #.lobyte(callbank15::entry) sta $FF6F,y iny lda #.hibyte(callbank15::entry) sta $FF6F,y iny dex bpl @L2 ; Set the indirect segment to bank we're executing in lda ExecReg 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, ; it's reused later. lda #<__BSS_RUN__ sta ptr1 lda #>__BSS_RUN__ sta ptr1+1 lda #0 tay ; Clear full pages ldx #>__BSS_SIZE__ beq Z2 Z1: sta (ptr1),y iny bne Z1 inc ptr1+1 ; Next page dex bne Z1 ; Clear the remaining page Z2: ldx #<__BSS_SIZE__ beq Z4 Z3: sta (ptr1),y iny dex bne Z3 Z4: jmp Init ; ------------------------------------------------------------------------ ; We are at $200 now. We may now start calling subroutines safely, since ; the code we execute is no longer in the stack page. .segment "PAGE2" ; Copy the character rom from the system bank into the execution bank Init: lda #<$C000 sta ptr1 lda #>$C000 sta ptr1+1 lda #<__CHARRAM_START__ sta ptr2 lda #>__CHARRAM_START__ sta ptr2+1 lda #>__CHARRAM_SIZE__ ; 16 * 256 bytes to copy sta tmp1 ldy #$00 ccopy: lda #$0F sta IndReg ; Access the system bank ccopy1: lda (ptr1),y sta __VIDRAM_START__,y iny bne ccopy1 lda ExecReg sta IndReg ccopy2: lda __VIDRAM_START__,y sta (ptr2),y iny bne ccopy2 inc ptr1+1 inc ptr2+1 ; Bump high pointer bytes dec tmp1 bne ccopy ; Clear the video memory. We will do this before switching the video to bank 0 ; to avoid garbage when doing so. jsr _clrscr ; Reprogram the VIC so that the text screen and the character ROM is in the ; execution bank. This is done in three steps: lda #$0F ; We need access to the system bank sta IndReg ; Place the VIC video RAM into bank 0 ; CA (STATVID) = 0 ; CB (VICDOTSEL) = 0 ldy #TPI::CR lda (tpi1),y sta vidsave+0 and #%00001111 ora #%10100000 sta (tpi1),y ; Set bit 14/15 of the VIC address range to the high bits of __VIDRAM_START__ ; PC6/PC7 (VICBANKSEL 0/1) = 11 ldy #TPI::PRC lda (tpi2),y sta vidsave+1 and #$3F ora #<((>__VIDRAM_START__) & $C0) sta (tpi2),y ; Set the VIC base address register to the addresses of the video and ; character RAM. ldy #VIC_VIDEO_ADR lda (vic),y sta vidsave+2 and #$01 ora #<(((__VIDRAM_START__ >> 6) & $F0) | ((__CHARRAM_START__ >> 10) & $0E) | $02) ; and #$0F ; ora #<(((>__VIDRAM_START__) << 2) & $F0) sta (vic),y ; Switch back to the execution bank lda ExecReg sta IndReg ; Activate chained interrupt handlers, then enable interrupts. lda #.lobyte(__INTERRUPTOR_COUNT__*2) sta irqcount cli ; Call module constructors. jsr initlib ; Push arguments and call main() jsr callmain ; Call module destructors. This is also the _exit entry and the default entry ; point for the break vector. _exit: pha ; Save the return code on stack jsr donelib ; Run module destructors lda #$00 sta irqcount ; Disable custom irq handlers ; Address the system bank lda #$0F sta IndReg ; Switch back the video to the system bank ldy #TPI::CR lda vidsave+0 sta (tpi1),y ldy #TPI::PRC lda vidsave+1 sta (tpi2),y ldy #VIC_VIDEO_ADR lda vidsave+2 sta (vic),y ; Copy stuff back from our zeropage to the systems .if 0 lda #.sizeof(transfer_table) sta ktmp @L0: ldx ktmp ldy transfer_table-2,x lda transfer_table-1,x tax lda $00,x sta (sysp0),y dec ktmp dec ktmp bne @L0 .endif ; Place the program return code into ST pla ldy #$9C ; ST sta (sysp0),y ; Setup the welcome code at the stack bottom in the system bank. ldy #$FF lda (sysp1),y ; Load system bank sp tax iny ; Y = 0 lda #$58 ; CLI opcode sta (sysp1),y iny lda #$60 ; RTS opcode sta (sysp1),y lda IndReg sei txs jmp Back ; ------------------------------------------------------------------------- ; The IRQ handler goes into PAGE2. For performance reasons, and to allow ; easier chaining, we do handle the IRQs in the execution bank (instead of ; passing them to the system bank). ; This is the mapping of the active irq register of the 6525 (tpi1): ; ; Bit 7 6 5 4 3 2 1 0 ; | | | | ^ 50 Hz ; | | | ^ SRQ IEEE 488 ; | | ^ cia ; | ^ IRQB ext. Port ; ^ acia irq: pha txa pha tya pha lda IndReg pha lda ExecReg sta IndReg ; Be sure to address our segment tsx lda $105,x ; Get the flags from the stack and #$10 ; Test break flag bne dobrk ; It's an IRQ cld ; Call chained IRQ handlers ldy irqcount beq irqskip jsr callirq_y ; Call the functions ; Done with chained IRQ handlers, check the TPI for IRQs and handle them irqskip:lda #$0F sta IndReg ldy #TPI::AIR lda (tpi1),y ; Interrupt Register 6525 beq noirq ; 50/60Hz interrupt cmp #%00000001 ; ticker irq? bne irqend jsr scnkey ; Poll the keyboard jsr UDTIM ; Bump the time ; Done irqend: ldy #TPI::AIR sta (tpi1),y ; Clear interrupt noirq: pla sta IndReg pla tay pla tax pla nmi: rti dobrk: jmp (BRKVec) ; ------------------------------------------------------------------------- ; Data area .data vidsave:.res 3 .bss irqcount: .byte 0
wagiminator/C64-Collection
1,908
C64_xu1541/software/tools/cc65-2.13.2/libsrc/cbm510/systime.s
; ; Stefan Haubenthal, 2009-07-27 ; Ullrich von Bassewitz, 2009-09-24 ; ; time_t _systime (void); ; /* Similar to time(), but: ; * - Is not ISO C ; * - Does not take the additional pointer ; * - Does not set errno when returning -1 ; */ ; .include "time.inc" .include "cbm510.inc" .include "extzp.inc" .import sys_bank, restore_bank .importzp tmp1, tmp2 ;---------------------------------------------------------------------------- .code .proc __systime ; Switch to the system bank jsr sys_bank ; Read the clock ldy #CIA::TODHR lda (cia2),y bpl AM and #%01111111 sed clc adc #$12 cld AM: jsr BCD2dec sta TM + tm::tm_hour ldy #CIA::TODMIN lda (cia2),y jsr BCD2dec sta TM + tm::tm_min ldy #CIA::TODSEC lda (cia2),y jsr BCD2dec sta TM + tm::tm_sec ldy #CIA::TOD10 lda (cia2),y ; Dummy read to unfreeze ; Restore the bank jsr restore_bank ; Convert to a time lda #<TM ldx #>TM jmp _mktime .endproc ;---------------------------------------------------------------------------- ; dec = (((BCD>>4)*10) + (BCD&0xf)) .proc BCD2dec tax and #%00001111 sta tmp1 txa and #%11110000 ; *16 lsr ; *8 sta tmp2 lsr lsr ; *2 adc tmp2 ; = *10 adc tmp1 rts .endproc ;---------------------------------------------------------------------------- ; TM struct with date set to 1970-01-01 .data TM: .word 0 ; tm_sec .word 0 ; tm_min .word 0 ; tm_hour .word 1 ; tm_mday .word 0 ; tm_mon .word 70 ; tm_year .word 0 ; tm_wday .word 0 ; tm_yday .word 0 ; tm_isdst
wagiminator/C64-Collection
1,857
C64_xu1541/software/tools/cc65-2.13.2/libsrc/cbm510/kernal.s
; ; Ullrich von Bassewitz, 2003-12-20 ; ; CBM610 kernal functions ; .export CINT .export IOINIT .export RAMTAS .export RESTOR .export VECTOR .export SETMSG .export SECOND .export TKSA .export MEMTOP .export MEMBOT .export SCNKEY .export SETTMO .export ACPTR .export CIOUT .export UNTLK .export UNLSN .export LISTEN .export TALK .export SETLFS .export CHKIN .export CKOUT .export CLRCH .export BASIN .export BSOUT .export LOAD .export SAVE .export STOP .export GETIN .export CLALL .export PLOT ;----------------------------------------------------------------------------- ; All functions are available in the kernal jump table. Functions having ; replacements (usually short ones where the overhead of the cross bank call ; is not worth the trouble) are commented out. CINT = $FF81 IOINIT = $FF84 RAMTAS = $FF87 RESTOR = $FF8A VECTOR = $FF8D SETMSG = $FF90 SECOND = $FF93 TKSA = $FF96 MEMTOP = $FF99 MEMBOT = $FF9C SCNKEY = $FF9F SETTMO = $FFA2 ACPTR = $FFA5 CIOUT = $FFA8 UNTLK = $FFAB UNLSN = $FFAE LISTEN = $FFB1 TALK = $FFB4 ;READST = $FFB7 SETLFS = $FFBA ;SETNAM = $FFBD ;OPEN = $FFC0 ;CLOSE = $FFC3 CHKIN = $FFC6 CKOUT = $FFC9 CLRCH = $FFCC BASIN = $FFCF BSOUT = $FFD2 LOAD = $FFD5 SAVE = $FFD8 ;SETTIM = $FFDB ;RDTIM = $FFDE STOP = $FFE1 GETIN = $FFE4 CLALL = $FFE7 ;UDTIM = $FFEA ;SCREEN = $FFED PLOT = $FFF0 ;IOBASE = $FFF3
wagiminator/C64-Collection
2,531
C64_xu1541/software/tools/cc65-2.13.2/libsrc/cbm510/kscnkey.s
; ; Ullrich von Bassewitz, 13.09.2001 ; ; Keyboard polling stuff for the 510. ; .export scnkey .importzp tpi2, ktab1, ktab2, ktab3, ktab4 .importzp keyidx, keybuf, keyscanbuf, keysave, modkey, norkey .importzp graphmode, lastidx, rptdelay, rptcount .include "cbm510.inc" .proc scnkey lda #$FF sta modkey sta norkey lda #$00 sta keyscanbuf ldy #TPI::PRB sta (tpi2),y ldy #TPI::PRA sta (tpi2),y jsr Poll and #$3F eor #$3F bne L1 jmp NoKey L1: lda #$FF ldy #TPI::PRA sta (tpi2),y asl a ldy #TPI::PRB sta (tpi2),y jsr Poll pha sta modkey ora #$30 bne L3 ; Branch always L2: jsr Poll L3: ldx #$05 ldy #$00 L4: lsr a bcc L5 inc keyscanbuf dex bpl L4 sec ldy #TPI::PRB lda (tpi2),y rol a sta (tpi2),y ldy #TPI::PRA lda (tpi2),y rol a sta (tpi2),y bcs L2 pla bcc NoKey ; Branch always L5: ldy keyscanbuf sty norkey pla asl a asl a asl a bcc L6 bmi L7 lda (ktab2),y ; Shifted normal key ldx graphmode beq L8 lda (ktab3),y ; Shifted key in graph mode bne L8 L6: lda (ktab4),y ; Key with ctrl pressed bne L8 L7: lda (ktab1),y ; Normal key L8: tax cpx #$FF ; Valid key? beq Done cpy lastidx beq Repeat ldx #$13 stx rptdelay ldx keyidx cpx #$09 beq NoKey cpy #$59 bne PutKey cpx #$08 beq NoKey sta keybuf,x inx bne PutKey NoKey: ldy #$FF Done: sty lastidx End: lda #$7F ldy #TPI::PRA sta (tpi2),y ldy #TPI::PRB lda #$FF sta (tpi2),y rts Repeat: dec rptdelay bpl End inc rptdelay dec rptcount bpl End inc rptcount ldx keyidx bne End PutKey: sta keybuf,x inx stx keyidx ldx #$03 stx rptcount bne Done .endproc ; Poll the keyboard port until it's stable .proc Poll ldy #TPI::PRC L1: lda (tpi2),y sta keysave lda (tpi2),y cmp keysave bne L1 rts .endproc
wagiminator/C64-Collection
11,856
C64_xu1541/software/tools/cc65-2.13.2/libsrc/cbm510/cbm510-stdser.s
; ; Serial driver for the builtin 6551 ACIA of the Commodore 510. ; ; Ullrich von Bassewitz, 2003-12-18 ; ; The driver is based on the cc65 rs232 module, which in turn is based on ; Craig Bruce device driver for the Switftlink/Turbo-232. ; ; SwiftLink/Turbo-232 v0.90 device driver, by Craig Bruce, 14-Apr-1998. ; ; This software is Public Domain. It is in Buddy assembler format. ; ; This device driver uses the SwiftLink RS-232 Serial Cartridge, available from ; Creative Micro Designs, Inc, and also supports the extensions of the Turbo232 ; Serial Cartridge. Both devices are based on the 6551 ACIA chip. It also ; supports the "hacked" SwiftLink with a 1.8432 MHz crystal. ; ; The code assumes that the kernal + I/O are in context. On the C128, call ; it from Bank 15. On the C64, don't flip out the Kernal unless a suitable ; NMI catcher is put into the RAM under then Kernal. For the SuperCPU, the ; interrupt handling assumes that the 65816 is in 6502-emulation mode. ; .include "zeropage.inc" .include "extzp.inc" .include "ser-kernel.inc" .include "ser-error.inc" .include "cbm510.inc" ; ------------------------------------------------------------------------ ; Header. Includes jump table .segment "JUMPTABLE" ; Driver signature .byte $73, $65, $72 ; "ser" .byte SER_API_VERSION ; Serial API version number ; Jump table. .word INSTALL .word UNINSTALL .word OPEN .word CLOSE .word GET .word PUT .word STATUS .word IOCTL .word IRQ ;---------------------------------------------------------------------------- ; ; Global variables ; .bss RecvHead: .res 1 ; Head of receive buffer RecvTail: .res 1 ; Tail of receive buffer RecvFreeCnt: .res 1 ; Number of bytes in receive buffer SendHead: .res 1 ; Head of send buffer SendTail: .res 1 ; Tail of send buffer SendFreeCnt: .res 1 ; Number of bytes in send buffer Stopped: .res 1 ; Flow-stopped flag RtsOff: .res 1 ; ; Send and receive buffers: 256 bytes each RecvBuf: .res 256 SendBuf: .res 256 .rodata ; Tables used to translate RS232 params into register values BaudTable: ; bit7 = 1 means setting is invalid .byte $FF ; SER_BAUD_45_5 .byte $01 ; SER_BAUD_50 .byte $02 ; SER_BAUD_75 .byte $03 ; SER_BAUD_110 .byte $04 ; SER_BAUD_134_5 .byte $05 ; SER_BAUD_150 .byte $06 ; SER_BAUD_300 .byte $07 ; SER_BAUD_600 .byte $08 ; SER_BAUD_1200 .byte $09 ; SER_BAUD_1800 .byte $0A ; SER_BAUD_2400 .byte $0B ; SER_BAUD_3600 .byte $0C ; SER_BAUD_4800 .byte $0D ; SER_BAUD_7200 .byte $0E ; SER_BAUD_9600 .byte $0F ; SER_BAUD_19200 .byte $FF ; SER_BAUD_38400 .byte $FF ; SER_BAUD_57600 .byte $FF ; SER_BAUD_115200 .byte $FF ; SER_BAUD_230400 BitTable: .byte $60 ; SER_BITS_5 .byte $40 ; SER_BITS_6 .byte $20 ; SER_BITS_7 .byte $00 ; SER_BITS_8 StopTable: .byte $00 ; SER_STOP_1 .byte $80 ; SER_STOP_2 ParityTable: .byte $00 ; SER_PAR_NONE .byte $20 ; SER_PAR_ODD .byte $60 ; SER_PAR_EVEN .byte $A0 ; SER_PAR_MARK .byte $E0 ; SER_PAR_SPACE .code ;---------------------------------------------------------------------------- ; INSTALL routine. Is called after the driver is loaded into memory. If ; possible, check if the hardware is present. ; Must return an SER_ERR_xx code in a/x. ; ; Since we don't have to manage the IRQ vector on the Plus/4, this is actually ; the same as: ; ; UNINSTALL routine. Is called before the driver is removed from memory. ; Must return an SER_ERR_xx code in a/x. ; and: ; ; CLOSE: Close the port, disable interrupts and flush the buffer. Called ; without parameters. Must return an error code in a/x. ; INSTALL: UNINSTALL: CLOSE: ; Deactivate DTR and disable 6551 interrupts lda #%00001010 jsr write_cmd ; Done, return an error code lda #<SER_ERR_OK tax ; A is zero rts ;---------------------------------------------------------------------------- ; PARAMS routine. A pointer to a ser_params structure is passed in ptr1. ; Must return an SER_ERR_xx code in a/x. OPEN: ; Check if the handshake setting is valid ldy #SER_PARAMS::HANDSHAKE ; Handshake lda (ptr1),y cmp #SER_HS_HW ; This is all we support bne InvParam ; Initialize buffers ldx #0 stx Stopped stx RecvHead stx RecvTail stx SendHead stx SendTail dex ; X = 255 stx RecvFreeCnt stx SendFreeCnt ; Set the value for the control register, which contains stop bits, word ; length and the baud rate. ldy #SER_PARAMS::BAUDRATE lda (ptr1),y ; Baudrate index tay lda BaudTable,y ; Get 6551 value bmi InvBaud ; Branch if rate not supported sta tmp1 ldy #SER_PARAMS::DATABITS ; Databits lda (ptr1),y tay lda BitTable,y ora tmp1 sta tmp1 ldy #SER_PARAMS::STOPBITS ; Stopbits lda (ptr1),y tay lda StopTable,y ora tmp1 ora #%00010000 ; Receiver clock source = baudrate ldy #ACIA::CTRL jsr write ; Set the value for the command register. We remember the base value in ; RtsOff, since we will have to manipulate ACIA_CMD often. ldy #SER_PARAMS::PARITY ; Parity lda (ptr1),y tay lda ParityTable,y ora #%00000001 ; DTR active sta RtsOff ora #%00001000 ; Enable receive interrupts jsr write_cmd ; Done lda #<SER_ERR_OK tax ; A is zero rts ; Invalid parameter InvParam: lda #<SER_ERR_INIT_FAILED ldx #>SER_ERR_INIT_FAILED rts ; Baud rate not available InvBaud: lda #<SER_ERR_BAUD_UNAVAIL ldx #>SER_ERR_BAUD_UNAVAIL rts ;---------------------------------------------------------------------------- ; GET: Will fetch a character from the receive buffer and store it into the ; variable pointer to by ptr1. If no data is available, SER_ERR_NO_DATA is ; return. ; GET: ldx SendFreeCnt ; Send data if necessary inx ; X == $FF? beq @L1 lda #$00 jsr TryToSend ; Check for buffer empty @L1: lda RecvFreeCnt cmp #$ff bne @L2 lda #<SER_ERR_NO_DATA ldx #>SER_ERR_NO_DATA rts ; Check for flow stopped & enough free: release flow control @L2: ldx Stopped beq @L3 cmp #63 bcc @L3 lda #$00 sta Stopped lda RtsOff ora #%00001000 jsr write_cmd ; Get byte from buffer @L3: ldx RecvHead lda RecvBuf,x inc RecvHead inc RecvFreeCnt ldx #$00 sta (ptr1,x) txa ; Return code = 0 rts ;---------------------------------------------------------------------------- ; PUT: Output character in A. ; Must return an error code in a/x. ; PUT: ; Try to send ldx SendFreeCnt inx ; X = $ff? beq @L2 pha lda #$00 jsr TryToSend pla ; Put byte into send buffer & send @L2: ldx SendFreeCnt bne @L3 lda #<SER_ERR_OVERFLOW ; X is already zero rts @L3: ldx SendTail sta SendBuf,x inc SendTail dec SendFreeCnt lda #$ff jsr TryToSend lda #<SER_ERR_OK tax rts ;---------------------------------------------------------------------------- ; STATUS: Return the status in the variable pointed to by ptr1. ; Must return an error code in a/x. ; STATUS: lda #$0F sta IndReg ldy #ACIA::STATUS lda (acia),y ldx #0 sta (ptr1,x) lda IndReg sta ExecReg txa ; SER_ERR_OK rts ;---------------------------------------------------------------------------- ; IOCTL: Driver defined entry point. The wrapper will pass a pointer to ioctl ; specific data in ptr1, and the ioctl code in A. ; Must return an error code in a/x. ; IOCTL: lda #<SER_ERR_INV_IOCTL ; We don't support ioclts for now ldx #>SER_ERR_INV_IOCTL rts ;---------------------------------------------------------------------------- ; IRQ: Called from the builtin runtime IRQ handler as a subroutine. All ; registers are already save, no parameters are passed, but the carry flag ; is clear on entry. The routine must return with carry set if the interrupt ; was handled, otherwise with carry clear. ; IRQ: lda #$0F sta IndReg ; Switch to the system bank ldy #ACIA::STATUS lda (acia),y ; Check ACIA status for receive interrupt and #$08 beq @L9 ; Jump if no ACIA interrupt (carry still clear) ldy #ACIA::DATA lda (acia),y ; Get byte from ACIA ldx RecvFreeCnt ; Check if we have free space left beq @L1 ; Jump if no space in receive buffer ldy RecvTail ; Load buffer pointer sta RecvBuf,y ; Store received byte in buffer inc RecvTail ; Increment buffer pointer dec RecvFreeCnt ; Decrement free space counter cpx #33 ; Check for buffer space low bcs @L9 ; Assert flow control if buffer space low ; Assert flow control if buffer space too low @L1: lda RtsOff ldy #ACIA::CMD sta (acia),y sta Stopped sec ; Interrupt handled ; Done, switch back to the execution segment @L9: lda ExecReg sta IndReg rts ;---------------------------------------------------------------------------- ; Try to send a byte. Internal routine. A = TryHard .proc TryToSend sta tmp1 ; Remember tryHard flag lda #$0F sta IndReg ; Switch to the system bank @L0: lda SendFreeCnt cmp #$ff beq @L3 ; Bail out ; Check for flow stopped @L1: lda Stopped bne @L3 ; Bail out ; Check that swiftlink is ready to send @L2: ldy #ACIA::STATUS lda (acia),y and #$10 bne @L4 bit tmp1 ; Keep trying if must try hard bmi @L0 ; Switch back the bank and return @L3: lda ExecReg sta IndReg rts ; Send byte and try again @L4: ldx SendHead lda SendBuf,x ldy #ACIA::DATA sta (acia),y inc SendHead inc SendFreeCnt jmp @L0 .endproc ;---------------------------------------------------------------------------- ; Write to the ACIA changing the indirect segment. Offset is in Y, value in A. write_cmd: ldy #ACIA::CMD write: pha lda #$0F sta IndReg pla sta (acia),y lda ExecReg sta IndReg rts
wagiminator/C64-Collection
1,722
C64_xu1541/software/tools/cc65-2.13.2/libsrc/cbm510/extzp.s
; ; 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 ; The following values get initialized from a table in the startup code. ; While this sounds crazy, it has reasons that have to do with modules (and ; we have the space anyway). So when changing anything, be sure to adjust the ; initializer table sysp1: .res 2 sysp3: .res 2 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 sysp0: .word $0000 time: .dword $0000 segsave: .byte 0 ktmp: .byte 0 CURS_X: .byte 0 CURS_Y: .byte 0 CURS_FLAG: .byte 0 CURS_STATE: .byte 0 CURS_BLINK: .byte 0 CURS_COLOR: .byte 0 CHARCOLOR: .byte 0 RVS: .byte 0 DEVNUM: .byte 0 SCREEN_PTR: .word 0 CRAM_PTR: .word 0 ; Stuff for our own kbd polling routine keyidx: .byte 0 ; Number of keys in keyboard buffer keybuf: .res 10 ; Keyboard buffer keyscanbuf: .byte 0 keysave: .byte 0 modkey: .byte 0 norkey: .byte 0 graphmode: .byte 0 lastidx: .byte 0 rptdelay: .byte 0 rptcount: .byte 0
wagiminator/C64-Collection
2,593
C64_xu1541/software/tools/cc65-2.13.2/libsrc/cbm510/cputc.s
; ; Ullrich von Bassewitz, 14.09.2001 ; ; void cputcxy (unsigned char x, unsigned char y, char c); ; void cputc (char c); ; .export _cputcxy, _cputc, cputdirect, putchar .export newline, plot .import popa, _gotoxy .import __VIDRAM_START__ .import CURS_X: zp, CURS_Y: zp, CHARCOLOR: zp, RVS: zp .import SCREEN_PTR: zp, CRAM_PTR: zp .include "cbm510.inc" .macpack generic ; ------------------------------------------------------------------------ ; _cputcxy: pha ; Save C jsr popa ; Get Y jsr _gotoxy ; Set cursor, drop x 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 ; Printable char of some sort cmp #' ' bcc cputdirect ; Other control char tay bmi L10 cmp #$60 bcc L2 and #$DF bne cputdirect ; Branch always L2: and #$3F cputdirect: jsr putchar ; Write the character to the screen ; Advance cursor position advance: iny cpy #XSIZE bne L3 jsr newline ; new line ldy #0 ; + cr L3: sty CURS_X rts ; Handle character if high bit set L10: and #$7F cmp #$7E ; PI? bne L11 lda #$5E ; Load screen code for PI bne cputdirect L11: ora #$40 bne cputdirect ; Branch always ; Move the cursor into the next line newline: inc CURS_Y ; Set cursor position, calculate RAM pointers plot: ldx CURS_Y lda LineLSBTab,x sta SCREEN_PTR sta CRAM_PTR lda LineMSBTab,x sta SCREEN_PTR+1 add #.hibyte(COLOR_RAM - __VIDRAM_START__) sta CRAM_PTR+1 rts ; Write one character to the screen without doing anything else, return X ; position in Y putchar: ora RVS ; Set revers bit ldy CURS_X sta (SCREEN_PTR),y ; Set char ldx IndReg lda #$0F sta IndReg lda CHARCOLOR sta (CRAM_PTR),y ; Set color stx IndReg rts ; ------------------------------------------------------------------------- ; Low bytes of the start address of the screen lines .rodata LineLSBTab: .repeat 25, I .byte .lobyte(__VIDRAM_START__ + I * 40) .endrep ; ------------------------------------------------------------------------- ; High bytes of the start address of the screen lines LineMSBTab: .repeat 25, I .byte .hibyte(__VIDRAM_START__ + I * 40) .endrep
wagiminator/C64-Collection
1,646
C64_xu1541/software/tools/cc65-2.13.2/libsrc/cbm510/break.s
; ; Ullrich von Bassewitz, 27.09.1998 ; ; void set_brk (unsigned Addr); ; void reset_brk (void); ; .export _set_brk, _reset_brk .export _brk_a, _brk_x, _brk_y, _brk_sr, _brk_pc .import _atexit, BRKVec .include "cbm510.inc" .bss _brk_a: .res 1 _brk_x: .res 1 _brk_y: .res 1 _brk_sr: .res 1 _brk_pc: .res 2 _brk_01: .res 1 oldvec: .res 2 ; Old vector .data uservec: jmp $FFFF ; Patched at runtime .code ; Set the break vector .proc _set_brk sta uservec+1 stx uservec+2 ; Set the user vector lda oldvec ora oldvec+1 ; Did we save the vector already? bne L1 ; Jump if we installed the handler already lda BRKVec sta oldvec lda BRKVec+1 sta oldvec+1 ; Save the old vector L1: lda #<brk_handler ; Set the break vector to our routine ldx #>brk_handler sta BRKVec stx BRKVec+1 rts .endproc ; Reset the break vector .proc _reset_brk lda oldvec ldx oldvec+1 beq @L9 ; Jump if vector not installed sta BRKVec stx BRKVec+1 lda #$00 sta oldvec ; Clear the old vector stx oldvec+1 @L9: rts .endproc ; Break handler, called if a break occurs .proc brk_handler pla sta _brk_01 pla sta _brk_y pla sta _brk_x pla sta _brk_a pla and #$EF ; Clear break bit sta _brk_sr pla ; PC low sec sbc #2 ; Point to start of brk sta _brk_pc pla ; PC high sbc #0 sta _brk_pc+1 jsr uservec ; Call the user's routine lda _brk_01 sta IndReg lda _brk_pc+1 pha lda _brk_pc pha lda _brk_sr pha ldx _brk_x ldy _brk_y lda _brk_a rti ; Jump back... .endproc
wagiminator/C64-Collection
7,097
C64_xu1541/software/tools/cc65-2.13.2/libsrc/cbm510/cbm510-ram.s
; ; Extended memory driver for the CBM510 additional RAM banks. Driver works ; without problems when linked statically. ; ; Ullrich von Bassewitz, 2002-12-09, 2003-12-27 ; .include "zeropage.inc" .include "em-kernel.inc" .include "em-error.inc" .include "cbm510.inc" .macpack generic ; ------------------------------------------------------------------------ ; Header. Includes jump table .segment "JUMPTABLE" ; Driver signature .byte $65, $6d, $64 ; "emd" .byte EMD_API_VERSION ; EM API version number ; Jump table. .word INSTALL .word UNINSTALL .word PAGECOUNT .word MAP .word USE .word COMMIT .word COPYFROM .word COPYTO ; ------------------------------------------------------------------------ ; Constants RAMBANK = 1 OFFS = 2 ; ------------------------------------------------------------------------ ; Data. .bss curpage: .res 1 ; Current page number window: .res 256 ; Memory "window" pagecount: .res 1 ; Number of available pages .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: lda #$FF sta curpage ; Invalidate the current page sta pagecount ; Assume all memory available sec jsr $FF99 ; MEMTOP cmp #RAMBANK ; Top of memory in bank 2? bne @L1 ; No: We can use all the memory txa sub #OFFS tya sbc #$00 sta pagecount @L1: lda #<EM_ERR_OK ldx #>EM_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 ; ------------------------------------------------------------------------ ; PAGECOUNT: Return the total number of available pages in a/x. ; PAGECOUNT: lda pagecount ldx #0 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 sta ptr1+1 lda #OFFS sta ptr1 ; Transfer one page ldx IndReg lda #RAMBANK sta IndReg ldy #$00 @L1: .repeat 2 lda (ptr1),y sta window,y iny .endrepeat bne @L1 stx IndReg ; Return the memory window lda #<window ldx #>window ; Return the window address rts ; ------------------------------------------------------------------------ ; USE: Tell the driver that the window is now associated with a given page. USE: sta curpage ; Remember the page lda #<window ldx #>window ; Return the window rts ; ------------------------------------------------------------------------ ; COMMIT: Commit changes in the memory window to extended storage. COMMIT: lda curpage ; Get the current page cmp #$FF beq done ; Jump if no page mapped sta ptr1+1 lda #OFFS sta ptr1 ; Transfer one page ldx IndReg lda #RAMBANK sta IndReg ldy #$00 @L1: .repeat 2 lda window,y sta (ptr1),y iny .endrepeat bne @L1 stx IndReg ; Done done: rts ; ------------------------------------------------------------------------ ; COPYFROM: Copy from extended into linear memory. A pointer to a structure ; describing the request is passed in a/x. ; The function must not return anything. ; COPYFROM: jsr setup ; Setup the buffer address in this bank. sta copyfrom_buf stx copyfrom_buf+1 ; Check if we must copy full pages ldx ptr2+1 beq @L2 ; Copy full pages ldx #$00 @L1: jsr copyfrom inc ptr1+1 inc copyfrom_buf+1 @L2: dec ptr2+1 bne @L1 ; Copy the remaining page ldx ptr2 beq @L3 jsr copyfrom ; Restore the indirect segment @L3: lda ExecReg sta IndReg ; Done 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: jsr setup ; Setup the buffer address in this bank. sta copyto_buf stx copyto_buf+1 ; Check if we must copy full pages ldx ptr2+1 beq @L2 ; Copy full pages ldx #$00 @L1: jsr copyto inc ptr1+1 inc copyto_buf+1 @L2: dec ptr2+1 bne @L1 ; Copy the remaining page ldx ptr2 beq @L3 jsr copyto ; Restore the indirect segment @L3: lda ExecReg sta IndReg ; Done rts ; ------------------------------------------------------------------------ ; setup: Helper function for COPYFROM and COPYTO, will setup parameters. ; setup: sta ptr3 stx ptr3+1 ; Save the passed em_copy pointer ldy #EM_COPY::OFFS lda (ptr3),y add #OFFS sta ptr1 ldy #EM_COPY::PAGE lda (ptr3),y adc #$00 sta ptr1+1 ldy #EM_COPY::COUNT lda (ptr3),y sta ptr2 iny lda (ptr3),y sta ptr2+1 ; Get count into ptr2 ldy #EM_COPY::BUF+1 lda (ptr3),y tax dey lda (ptr3),y ; Get the buffer pointer into a/x ldy #RAMBANK sty IndReg ldy #$00 rts ; ------------------------------------------------------------------------ ; copyfrom .data copyfrom: lda (ptr1),y copyfrom_buf = * + 1 sta $0000,y iny dex bne copyfrom rts ; ------------------------------------------------------------------------ ; copyto .data copyto: copyto_buf = * + 1 lda $0000,y sta (ptr1),y iny dex bne copyto rts