repo_id
stringlengths
5
115
size
int64
590
5.01M
file_path
stringlengths
4
212
content
stringlengths
590
5.01M
wagiminator/C64-Collection
8,313
C64_xu1541/software/tools/cc65-2.13.2/libsrc/lynx/lynx-comlynx.s
; ; Serial driver for the Atari Lynx ComLynx port. ; ; Karri Kaksonen, 17.09.2009 ; .include "lynx.inc" .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 ;---------------------------------------------------------------------------- ; Global variables ; ; The ring buffers will be at the fixed place ; Tx buffer $200 - $2ff. Rx buffer $300 - $3ff. ; This memory area can usually not be used for anything as the encryption ; stuff needs it. But for this purpose it fits perfectly. .bss TxBuffer = $0200 RxBuffer = $0300 RxPtrIn: .res 1 RxPtrOut: .res 1 TxPtrIn: .res 1 TxPtrOut: .res 1 contrl: .res 1 SerialStat: .res 1 TxDone: .res 1 .code ;---------------------------------------------------------------------------- ; INSTALL: Is called after the driver is loaded into memory. ; ; Must return an SER_ERR_xx code in a/x. INSTALL: ; Set up IRQ vector ? ;---------------------------------------------------------------------------- ; UNINSTALL: Is called before the driver is removed from memory. ; No return code required (the driver is removed from memory on return). ; UNINSTALL: ;---------------------------------------------------------------------------- ; CLOSE: Close the port and disable interrupts. Called without parameters. ; Must return an SER_ERR_xx code in a/x. CLOSE: ; Disable interrupts ; Done, return an error code lda #<SER_ERR_OK ldx #>SER_ERR_OK rts ;---------------------------------------------------------------------------- ; OPEN: A pointer to a ser_params structure is passed in ptr1. ; ; The Lynx has only two correct serial data formats: ; 8 bits, parity mark, 1 stop bit ; 8 bits, parity space, 1 stop bit ; ; It also has two wrong formats; ; 8 bits, even parity, 1 stop bit ; 8 bits, odd parity, 1 stop bit ; ; Unfortunately the parity bit includes itself in the calculation making ; parity not compatible with the rest of the world. ; ; We can only specify a few baud rates. ; Lynx has two non-standard speeds 31250 and 62500 which are ; frequently used in games. ; ; The receiver will always read the parity and report parity errors. ; ; Must return an SER_ERR_xx code in a/x. OPEN: stz RxPtrIn stz RxPtrOut stz TxPtrIn stz TxPtrOut ; clock = 8 * 15625 lda #%00011000 sta TIM4CTLA ldy #SER_PARAMS::BAUDRATE lda (ptr1),y ldx #1 cmp #SER_BAUD_62500 beq setbaudrate ldx #2 cmp #SER_BAUD_31250 beq setbaudrate ldx #12 cmp #SER_BAUD_9600 beq setbaudrate ldx #25 cmp #SER_BAUD_4800 beq setbaudrate ldx #51 cmp #SER_BAUD_2400 beq setbaudrate ldx #103 cmp #SER_BAUD_1200 beq setbaudrate ldx #207 cmp #SER_BAUD_600 beq setbaudrate ; clock = 6 * 15625 ldx #%00011010 stx TIM4CTLA ldx #12 cmp #SER_BAUD_7200 beq setbaudrate ldx #25 cmp #SER_BAUD_3600 beq setbaudrate ldx #207 stx TIM4BKUP ; clock = 4 * 15625 ldx #%00011100 cmp #SER_BAUD_300 beq setprescaler ; clock = 6 * 15625 ldx #%00011110 cmp #SER_BAUD_150 beq setprescaler ; clock = 1 * 15625 ldx #%00011111 stx TIM4CTLA cmp #SER_BAUD_75 beq baudsuccess ldx #141 cmp #SER_BAUD_110 beq setbaudrate ; clock = 2 * 15625 ldx #%00011010 stx TIM4CTLA ldx #68 cmp #SER_BAUD_1800 beq setbaudrate ; clock = 6 * 15625 ldx #%00011110 stx TIM4CTLA ldx #231 cmp #SER_BAUD_134_5 beq setbaudrate lda #<SER_ERR_BAUD_UNAVAIL ldx #>SER_ERR_BAUD_UNAVAIL rts setprescaler: stx TIM4CTLA bra baudsuccess setbaudrate: stx TIM4BKUP baudsuccess: ldx #TxOpenColl|ParEven stx contrl ldy #SER_PARAMS::DATABITS ; Databits lda (ptr1),y cmp #SER_BITS_8 bne invparameter ldy #SER_PARAMS::STOPBITS ; Stopbits lda (ptr1),y cmp #SER_STOP_1 bne invparameter ldy #SER_PARAMS::PARITY ; Parity lda (ptr1),y cmp #SER_PAR_NONE beq invparameter cmp #SER_PAR_MARK beq checkhs cmp #SER_PAR_SPACE bne @L0 ldx #TxOpenColl stx contrl bra checkhs @L0: ldx #TxParEnable|TxOpenColl|ParEven stx contrl cmp #SER_PAR_EVEN beq checkhs ldx #TxParEnable|TxOpenColl stx contrl checkhs: ldx contrl stx SERCTL ldy #SER_PARAMS::HANDSHAKE ; Handshake lda (ptr1),y cmp #SER_HS_NONE bne invparameter lda SERDAT lda contrl ora #RxIntEnable|ResetErr sta SERCTL lda #<SER_ERR_OK ldx #>SER_ERR_OK rts invparameter: lda #<SER_ERR_INIT_FAILED ldx #>SER_ERR_INIT_FAILED 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: lda RxPtrIn cmp RxPtrOut bne GetByte lda #<SER_ERR_NO_DATA ldx #>SER_ERR_NO_DATA rts GetByte: ldy RxPtrOut lda RxBuffer,y inc RxPtrOut ldx #$00 sta (ptr1,x) txa ; Return code = 0 rts ;---------------------------------------------------------------------------- ; PUT: Output character in A. ; Must return an SER_ERR_xx code in a/x. PUT: tax lda TxPtrIn ina cmp TxPtrOut bne PutByte lda #<SER_ERR_OVERFLOW ldx #>SER_ERR_OVERFLOW rts PutByte: ldy TxPtrIn txa sta TxBuffer,y inc TxPtrIn bit TxDone bmi @L1 php sei lda contrl ora #TxIntEnable|ResetErr sta SERCTL ; Allow TX-IRQ to hang RX-IRQ sta TxDone plp @L1: 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: ldy SerialStat ldx #$00 sta (ptr1,x) txa ; Return code = 0 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: 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. ; ; Both the Tx and Rx interrupts are level sensitive instead of edge sensitive. ; Due to this bug you have to disable the interrupt before clearing it. IRQ: lda INTSET ; Poll all pending interrupts and #SERIAL_INTERRUPT bne @L0 clc rts @L0: bit TxDone bmi @tx_irq ; Transmit in progress ldx SERDAT lda SERCTL and #RxParityErr|RxOverrun|RxFrameErr|RxBreak beq @rx_irq tsb SerialStat ; Save error condition bit #RxBreak beq @noBreak stz TxPtrIn ; Break received - drop buffers stz TxPtrOut stz RxPtrIn stz RxPtrOut @noBreak: lda contrl ora #RxIntEnable|ResetErr sta SERCTL lda #$10 sta INTRST bra @IRQexit @rx_irq: lda contrl ora #RxIntEnable|ResetErr sta SERCTL txa ldx RxPtrIn sta RxBuffer,x txa inx @cont0: cpx RxPtrOut beq @1 stx RxPtrIn lda #SERIAL_INTERRUPT sta INTRST bra @IRQexit @1: sta RxPtrIn lda #$80 tsb SerialStat @tx_irq: ldx TxPtrOut ; Has all bytes been sent? cpx TxPtrIn beq @allSent lda TxBuffer,x ; Send next byte sta SERDAT inc TxPtrOut @exit1: lda contrl ora #TxIntEnable|ResetErr sta SERCTL lda #SERIAL_INTERRUPT sta INTRST bra @IRQexit @allSent: lda SERCTL ; All bytes sent bit #TxEmpty beq @exit1 bvs @exit1 stz TxDone lda contrl ora #RxIntEnable|ResetErr sta SERCTL lda #SERIAL_INTERRUPT sta INTRST @IRQexit: clc rts
wagiminator/C64-Collection
1,403
C64_xu1541/software/tools/cc65-2.13.2/libsrc/lynx/cgetc.s
; ; Karri Kaksonen, Harry Dodgson 2006-01-07 ; ; char cgetc (void); ; .export _cgetc .import _kbhit .import KBEDG .import KBSTL ; -------------------------------------------------------------------------- ; The Atari Lynx has a very small keyboard - only 3 keys ; Opt1, Opt2 and Pause. ; But the designers have decided that pressing Pause and Opt1 at the ; same time means Restart and pressing Pause and Opt2 means Flip screen. ; For "easter egg" use I have also included all three keys pressed '?' ; and Opt1 + Opt2 pressed '3'. ; So the keyboard returns '1', '2', '3', 'P', 'R', 'F' or '?'. _cgetc: lda KBSTL ora KBEDG bne @L1 jsr _kbhit ; Check for char available tax ; Test result bra _cgetc @L1: ldx #0 and #1 beq @L6 lda KBEDG ; Pause button is pressed and #$0c beq @L3 ora KBSTL @L2: bit #$04 beq @L4 ; Pause + Opt 1 = Reset bit #$08 beq @L5 ; Pause + Opt 2 = Flip lda #'?' ; All buttons pressed rts @L3: lda KBSTL ; Pause alone was the last placed button and #$0c bne @L2 lda #'P' ; Pause pressed rts @L4: lda #'R' ; Reset pressed rts @L5: lda #'F' ; Flip pressed rts @L6: lda KBEDG ; No Pause pressed ora KBSTL bit #$08 beq @L8 bit #$04 beq @L7 lda #'3' ; opt 1 + opt 2 pressed rts @L7: lda #'1' ; opt 1 pressed rts @L8: lda #'2' ; opt 2 pressed rts
wagiminator/C64-Collection
6,268
C64_xu1541/software/tools/cc65-2.13.2/libsrc/lynx/ctype.s
; ; Ullrich von Bassewitz, 02.06.1998 ; ; Character specification table. ; ; 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: .repeat 2 ; 2 times for normal and inverted .byte $10 ; 0/00 ___ctrl_@___ .byte $10 ; 1/01 ___ctrl_A___ .byte $10 ; 2/02 ___ctrl_B___ .byte $10 ; 3/03 ___ctrl_C___ .byte $10 ; 4/04 ___ctrl_D___ .byte $10 ; 5/05 ___ctrl_E___ .byte $10 ; 6/06 ___ctrl_F___ .byte $10 ; 7/07 ___ctrl_G___ .byte $10 ; 8/08 ___ctrl_H___ .byte $D0 ; 9/09 ___ctrl_I___ .byte $50 ; 10/0a ___ctrl_J___ .byte $50 ; 11/0b ___ctrl_K___ .byte $50 ; 12/0c ___ctrl_L___ .byte $50 ; 13/0d ___ctrl_M___ .byte $10 ; 14/0e ___ctrl_N___ .byte $10 ; 15/0f ___ctrl_O___ .byte $10 ; 16/10 ___ctrl_P___ .byte $10 ; 17/11 ___ctrl_Q___ .byte $10 ; 18/12 ___ctrl_R___ .byte $10 ; 19/13 ___ctrl_S___ .byte $10 ; 20/14 ___ctrl_T___ .byte $10 ; 21/15 ___ctrl_U___ .byte $10 ; 22/16 ___ctrl_V___ .byte $10 ; 23/17 ___ctrl_W___ .byte $10 ; 24/18 ___ctrl_X___ .byte $10 ; 25/19 ___ctrl_Y___ .byte $10 ; 26/1a ___ctrl_Z___ .byte $10 ; 27/1b ___ctrl_[___ .byte $10 ; 28/1c ___ctrl_\___ .byte $10 ; 29/1d ___ctrl_]___ .byte $10 ; 30/1e ___ctrl_^___ .byte $10 ; 31/1f ___ctrl_____ .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 ___grave___ .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 _____{_____ .byte $00 ; 124/7c _____|_____ .byte $00 ; 125/7d _____}_____ .byte $00 ; 126/7e _____~_____ .byte $40 ; 127/7f ____DEL____ .endrepeat
wagiminator/C64-Collection
1,610
C64_xu1541/software/tools/cc65-2.13.2/libsrc/tgi/tgi_textsize.s
; ; Ullrich von Bassewitz, 22.06.2002 ; .include "tgi-kernel.inc" .import _strlen, pushax, tosumulax ;----------------------------------------------------------------------------- ; unsigned __fastcall__ tgi_textwidth (const char* s); ; /* Calculate the width of the text in pixels according to the current text ; * style. ; */ _tgi_textwidth: ldy _tgi_textdir ; Get text direction bne height ; Result is ; ; strlen (s) * tgi_textmagx * tgi_fontsizex ; ; Since we don't expect textmagx to have large values, we do the multiplication ; by looping. width: jsr _strlen jsr pushax lda #0 tax ldy _tgi_textmagx @L1: clc adc _tgi_fontsizex bcc @L2 inx @L2: dey bne @L1 jmp tosumulax ; Result * strlen (s) ;----------------------------------------------------------------------------- ; unsigned __fastcall__ tgi_textheight (const char* s); ; /* Calculate the height of the text in pixels according to the current text ; * style. ; */ _tgi_textheight: ldy _tgi_textdir ; Get text direction bne width ; Jump if vertical ; Result is ; ; tgi_textmagy * tgi_fontsizey ; ; Since we don't expect textmagx to have large values, we do the multiplication ; by looping. height: lda #0 tax ldy _tgi_textmagy @L1: clc adc _tgi_fontsizey bcc @L2 inx @L2: dey bne @L1 rts
wagiminator/C64-Collection
3,034
C64_xu1541/software/tools/cc65-2.13.2/libsrc/tgi/tgi_bar.s
; ; Ullrich von Bassewitz, 21.06.2002 ; ; void __fastcall__ tgi_bar (int x1, int y1, int x2, int y2); ; /* Draw a bar (a filled rectangle) using the current color */ .include "tgi-kernel.inc" .importzp ptr1, ptr2, ptr3, ptr4 .import popax .proc _tgi_bar sta ptr4 ; Y2 stx ptr4+1 jsr popax sta ptr3 ; X2 stx ptr3+1 jsr popax sta ptr2 ; Y1 stx ptr2+1 jsr popax sta ptr1 ; X1 stx ptr1+1 ; Make sure X1 is less than X2. Swap both if not. lda ptr3 cmp ptr1 lda ptr3+1 sbc ptr1+1 bpl @L1 lda ptr3 ldy ptr1 sta ptr1 sty ptr3 lda ptr3+1 ldy ptr1+1 sta ptr1+1 sty ptr3+1 ; Make sure Y1 is less than Y2. Swap both if not. @L1: lda ptr4 cmp ptr2 lda ptr4+1 sbc ptr2+1 bpl @L2 lda ptr4 ldy ptr2 sta ptr2 sty ptr4 lda ptr4+1 ldy ptr2+1 sta ptr2+1 sty ptr4+1 ; Check if X2 or Y2 are negative. If so, the bar is completely out of screen. @L2: lda ptr4+1 ora ptr3+1 bmi @L9 ; Bail out ; Check if X1 is negative. If so, clip it to the left border (zero). bit ptr1+1 bpl @L3 lda #$00 sta ptr1 sta ptr1+1 beq @L4 ; Branch always, skip following test ; Check if X1 is beyond the right border. If so, the bar is invisible. @L3: lda ptr1 cmp _tgi_xres lda ptr1+1 sbc _tgi_xres bcs @L9 ; Bail out if invisible ; Check if Y1 is negative. If so, clip it to the top border (zero). @L4: bit ptr2+1 bpl @L5 lda #$00 sta ptr2 sta ptr2+1 beq @L6 ; Branch always, skip following test ; Check if Y1 is beyond the bottom border. If so, the bar is invisible. @L5: lda ptr2 cmp _tgi_yres lda ptr2+1 sbc _tgi_yres bcs @L9 ; Bail out if invisible ; Check if X2 is larger than the maximum x coord. If so, clip it. @L6: lda ptr3 cmp _tgi_xres lda ptr3+1 sbc _tgi_xres+1 bcc @L7 jsr _tgi_getmaxx sta ptr3 stx ptr3+1 ; Check if Y2 is larger than the maximum y coord. If so, clip it. @L7: lda ptr4 cmp _tgi_yres lda ptr4+1 sbc _tgi_yres+1 bcc @L8 jsr _tgi_getmaxy sta ptr4 stx ptr4+1 ; The coordinates are now valid. Call the driver. @L8: jmp tgi_bar ; Error exit @L9: rts .endproc
wagiminator/C64-Collection
1,647
C64_xu1541/software/tools/cc65-2.13.2/libsrc/tgi/tgi_init.s
; ; Ullrich von Bassewitz, 21.06.2002 ; ; void __fastcall__ tgi_init (void); ; /* Initialize the already loaded graphics driver */ .include "tgi-kernel.inc" .include "tgi-error.inc" .importzp ptr1 .proc _tgi_init jsr _tgi_done ; Switch off graphics if needed jsr tgi_init ; Go into graphics mode jsr tgi_geterror ; Get the error code sta _tgi_error ; Save for later reference cmp #TGI_ERR_OK bne @L9 ; Jump on error inc _tgi_gmode ; Remember that graph mode is active ; Do driver initialization. Set draw and view pages. lda #0 jsr tgi_setviewpage lda #0 jsr tgi_setdrawpage ; Set the default palette. jsr tgi_getdefpalette ; Get the default palette into A/X sta ptr1 stx ptr1+1 ; Save it jsr tgi_setpalette ; Set the default palette. jsr tgi_geterror ; Clear a possible error code ; Set the drawing color to the maximum color @L1: ldx _tgi_colorcount dex txa jsr _tgi_setcolor ; tgi_setcolor (tgi_getmaxcolor ()); ; Set the text style lda #TGI_TEXT_HORIZONTAL sta _tgi_textdir ldx #1 stx _tgi_textmagx ldy #1 sty _tgi_textmagy jsr tgi_textstyle ; Tell the driver about the text style ; Clear the screen jmp tgi_clear ; Error exit @L9: rts .endproc
wagiminator/C64-Collection
1,269
C64_xu1541/software/tools/cc65-2.13.2/libsrc/tgi/tgi_map_mode.s
; ; Ullrich von Bassewitz, 31.05.2002 ; ; const char* __fastcall__ tgi_map_mode (unsigned char mode); ; /* Map tgi mode codes to driver names */ ; .export _tgi_map_mode .import _tgi_mode_table .import return0 .importzp tmp1 ;---------------------------------------------------------------------------- ; BEWARE: The current implementation of tgi_map_mode does not work with tables ; larger that 255 bytes! .code .proc _tgi_map_mode sta tmp1 ; Save mode ldy #$00 @L0: lda _tgi_mode_table,y beq NotFound ; Branch if mode code zero cmp tmp1 beq Found ; Skip the name @L1: iny lda _tgi_mode_table,y bne @L1 ; Loop until end marker found iny ; Skip end marker bne @L0 ; Branch always ; Mode not found NotFound: jmp return0 ; Mode found Found: tya ldx #>_tgi_mode_table sec ; Account for the mode byte adc #<_tgi_mode_table ; Return pointer to file name bcc @L1 inx @L1: rts .endproc
wagiminator/C64-Collection
5,462
C64_xu1541/software/tools/cc65-2.13.2/libsrc/tgi/tgi-kernel.s
; ; Ullrich von Bassewitz, 21.06.2002 ; ; Common functions of the tgi graphics kernel. ; .include "tgi-kernel.inc" .include "tgi-error.inc" .importzp ptr1 .interruptor tgi_irq ; Export as IRQ handler ;---------------------------------------------------------------------------- ; Variables .bss _tgi_drv: .res 2 ; Pointer to driver _tgi_error: .res 1 ; Last error code _tgi_gmode: .res 1 ; Flag: Graphics mode active _tgi_curx: .res 2 ; Current drawing cursor X _tgi_cury: .res 2 ; Current drawing cursor Y _tgi_color: .res 1 ; Current drawing color _tgi_textdir: .res 1 ; Current text direction _tgi_textmagx: .res 1 ; Text magnification in X dir _tgi_textmagy: .res 1 ; Text magnification in Y dir ; The following variables are copied from the driver header for faster access tgi_driver_vars: _tgi_xres: .res 2 ; X resolution of the current mode _tgi_yres: .res 2 ; Y resolution of the current mode _tgi_colorcount: .res 1 ; Number of available colors _tgi_pagecount: .res 1 ; Number of available screen pages _tgi_fontsizex: .res 1 ; System font X size _tgi_fontsizey: .res 1 ; System font Y size .data ; Jump table for the driver functions. tgi_install: jmp $0000 tgi_uninstall: jmp $0000 tgi_init: jmp $0000 tgi_done: jmp $0000 tgi_geterror: jmp $0000 tgi_control: jmp $0000 tgi_clear: jmp $0000 tgi_setviewpage: jmp $0000 tgi_setdrawpage: jmp $0000 tgi_setcolor: jmp $0000 tgi_setpalette: jmp $0000 tgi_getpalette: jmp $0000 tgi_getdefpalette: jmp $0000 tgi_setpixel: jmp $0000 tgi_getpixel: jmp $0000 tgi_line: jmp $0000 tgi_bar: jmp $0000 tgi_circle: jmp $0000 tgi_textstyle: jmp $0000 tgi_outtext: jmp $0000 tgi_irq: .byte $60, $00, $00 ; RTS plus two dummy bytes ; Driver header signature .rodata tgi_sig: .byte $74, $67, $69, TGI_API_VERSION ; "tgi", version .code ;---------------------------------------------------------------------------- ; void __fastcall__ tgi_install (void* driver); ; /* Install an already loaded driver. */ _tgi_install: sta _tgi_drv sta ptr1 stx _tgi_drv+1 stx ptr1+1 ; Check the driver signature ldy #.sizeof(tgi_sig)-1 @L0: lda (ptr1),y cmp tgi_sig,y bne tgi_inv_drv dey bpl @L0 ; Copy the jump vectors ldy #TGI_HDR::JUMPTAB ldx #0 @L1: inx ; Skip JMP opcode jsr copy ; Copy one byte jsr copy ; Copy one byte cpy #(TGI_HDR::JUMPTAB + .sizeof(TGI_HDR::JUMPTAB)) bne @L1 ; Call the driver install routine. It may update header variables, so we copy ; them after this call. jsr tgi_install ; Copy variables from the driver header for faster access. jsr tgi_set_ptr ; Set ptr1 to tgi_drv ldy #(TGI_HDR::VARS + .sizeof(TGI_HDR::VARS) - 1) ldx #.sizeof(TGI_HDR::VARS)-1 @L3: lda (ptr1),y sta tgi_driver_vars,x dey dex bpl @L3 ; Install the IRQ vector if the driver needs it. lda tgi_irq+2 ; Check high byte of IRQ vector beq @L4 ; Jump if vector invalid lda #$4C ; Jump opcode sta tgi_irq ; Activate IRQ routine ; Initialize some other variables lda #$00 @L4: ldx #8-1 @L5: sta _tgi_error,x ; Clear error/mode/curx/cury/textdir dex bpl @L5 rts ; Copy one byte from the jump vectors copy: lda (ptr1),y sta tgi_install,x iny inx rts ;---------------------------------------------------------------------------- ; Set an invalid argument error tgi_inv_arg: lda #TGI_ERR_INV_ARG sta _tgi_error rts ;---------------------------------------------------------------------------- ; Set an invalid driver error tgi_inv_drv: lda #TGI_ERR_INV_DRIVER sta _tgi_error rts ;---------------------------------------------------------------------------- ; Load the pointer to the tgi driver into ptr1. tgi_set_ptr: lda _tgi_drv sta ptr1 lda _tgi_drv+1 sta ptr1+1 rts ;---------------------------------------------------------------------------- ; void __fastcall__ tgi_uninstall (void); ; /* Uninstall the currently loaded driver but do not unload it. Will call ; * tgi_done if necessary. ; */ _tgi_uninstall: jsr _tgi_done ; Switch off graphics jsr tgi_uninstall ; Allow the driver to clean up lda #$60 ; RTS opcode sta tgi_irq ; Disable IRQ entry point ; Clear driver pointer and error code lda #$00 sta _tgi_drv sta _tgi_drv+1 sta _tgi_error rts
wagiminator/C64-Collection
1,318
C64_xu1541/software/tools/cc65-2.13.2/libsrc/tgi/tgi_geterrormsg.s
; ; Ullrich von Bassewitz, 2004-06-15 ; ; const char* __fastcall__ tgi_geterrormsg (unsigned char code); ; /* Get an error message describing the error in code. */ ; .include "tgi-kernel.inc" .include "tgi-error.inc" .proc _tgi_geterrormsg cmp #TGI_ERR_COUNT bcc L1 lda #TGI_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) .byte <(msg7-msgtab) msgtab: msg0: .asciiz "No error" msg1: .asciiz "No driver available" msg2: .asciiz "Cannot load driver" msg3: .asciiz "Invalid driver" msg4: .asciiz "Mode not supported by driver" msg5: .asciiz "Invalid function argument" msg6: .asciiz "Function not supported" msg7: .asciiz "Unknown error"
wagiminator/C64-Collection
1,054
C64_xu1541/software/tools/cc65-2.13.2/libsrc/tgi/tgi_textstyle.s
; ; Ullrich von Bassewitz, 22.06.2002 ; ; void __fastcall__ tgi_textstyle (unsigned char magx, unsigned char magy, ; unsigned char dir); ; /* Set the style for text output. */ .include "tgi-kernel.inc" .import popax, incsp2 .proc _tgi_textstyle pha jsr popax ; Get magx/magy in one call tay pla ; A = textdir, X = textmagx, Y = textmagy cmp #TGI_TEXT_HORIZONTAL beq DirOk cmp #TGI_TEXT_VERTICAL beq DirOk Fail: jmp tgi_inv_arg ; Invalid argument DirOk: cpy #$00 beq Fail ; Cannot have magnification of zero cpx #$00 beq Fail ; Cannot have magnification of zero ; Parameter check ok, store them stx _tgi_textmagx sty _tgi_textmagy sta _tgi_textdir ; Call the driver, parameters are passed in registers jmp tgi_textstyle .endproc
wagiminator/C64-Collection
1,112
C64_xu1541/software/tools/cc65-2.13.2/libsrc/cbm/cbm_open.s
; ; Ullrich von Bassewitz, 22.06.2002 ; ; Original C code by Marc 'BlackJack' Rintsch, 18.03.2001 ; ; unsigned char __fastcall__ cbm_open (unsigned char lfn, ; unsigned char device, ; unsigned char sec_addr, ; const char* name); ; /* Opens a file. Works just like the BASIC command. ; * Returns 0 if opening was successful, otherwise an errorcode (see table ; * below). ; */ ; { ; cbm_k_setlfs(lfn, device, sec_addr); ; cbm_k_setnam(name); ; return _oserror = cbm_k_open(); ; } ; .export _cbm_open .import popa .import _cbm_k_setlfs, _cbm_k_setnam, _cbm_k_open .import __oserror _cbm_open: pha txa pha ; Save name jsr popa ; Get sec_addr jsr _cbm_k_setlfs ; Call SETLFS, pop all args pla tax pla ; Get name jsr _cbm_k_setnam jsr _cbm_k_open sta __oserror rts
wagiminator/C64-Collection
2,161
C64_xu1541/software/tools/cc65-2.13.2/libsrc/cbm/close.s
; ; Ullrich von Bassewitz, 16.11.2002 ; ; int __fastcall__ close (int fd); ; .export _close .import CLOSE .import readdiskerror, closecmdchannel .import __oserror .importzp tmp2 .include "errno.inc" .include "cbm.inc" .include "filedes.inc" ;-------------------------------------------------------------------------- ; _close .proc _close ; Check if we have a valid handle cpx #$00 bne invalidfd cmp #MAX_FDS ; Is it valid? bcs invalidfd ; Jump if no sta tmp2 ; Save the handle ; Check if the file is actually open tax lda fdtab,x ; Get flags for this handle and #LFN_OPEN beq notopen ; Valid lfn, close it. The close call is always error free, at least as far ; as the kernal is involved lda #LFN_CLOSED sta fdtab,x lda tmp2 ; Get the handle clc adc #LFN_OFFS ; Make LFN from handle jsr CLOSE ; Read the drive error channel, then close it ldy tmp2 ; Get the handle ldx unittab,y ; Get teh disk for this handle jsr readdiskerror ; Read the disk error code pha ; Save it on stack ldy tmp2 ldx unittab,y jsr closecmdchannel ; Close the disk command channel pla ; Get the error code from the disk bne error ; Jump if error ; Successful tax ; Return zero in a/x rts ; Error entry, file descriptor is invalid invalidfd: lda #EINVAL sta __errno lda #0 sta __errno+1 beq errout ; Error entry, file is not open notopen: lda #3 ; File not open bne error ; Error entry, status not ok error: sta __oserror errout: lda #$FF tax ; Return -1 rts .endproc
wagiminator/C64-Collection
1,174
C64_xu1541/software/tools/cc65-2.13.2/libsrc/cbm/sysrename.s
; ; Ullrich von Bassewitz, 2009-02-22 ; ; unsigned char __fastcall__ _sysrename (const char *oldpath, const char *newpath); ; .export __sysrename .import fnparse, fnadd, fnparsename .import opencmdchannel, closecmdchannel .import writefndiskcmd, readdiskerror .import popax .import fncmd, fnunit .importzp ptr1 ;-------------------------------------------------------------------------- ; __sysrename: .proc __sysrename jsr fnparse ; Parse first filename, pops newpath bne done lda #'=' jsr fnadd jsr popax sta ptr1 stx ptr1+1 ldy #0 jsr fnparsename ; Parse second filename bne done ldx fnunit jsr opencmdchannel bne done lda #'r' ; Rename command sta fncmd jsr writefndiskcmd ; ldx fnunit ; jsr readdiskerror pha ldx fnunit jsr closecmdchannel pla done: rts .endproc
wagiminator/C64-Collection
1,304
C64_xu1541/software/tools/cc65-2.13.2/libsrc/cbm/rwcommon.s
; ; Ullrich von Bassewitz, 17.11.2002 ; ; Common stuff for the read/write routines ; .export rwcommon .import popax .importzp ptr1, ptr2, ptr3, tmp2 .include "errno.inc" .include "filedes.inc" ;-------------------------------------------------------------------------- ; rwcommon: Pop the parameters from stack, preprocess them and place them ; into zero page locations. Return carry set if the handle is invalid, ; return carry clear if it is ok. If the carry is clear, the handle is ; returned in A. .proc rwcommon eor #$FF sta ptr1 txa eor #$FF sta ptr1+1 ; Remember -count-1 jsr popax ; Get buf sta ptr2 stx ptr2+1 lda #$00 sta ptr3 sta ptr3+1 ; Clear ptr3 jsr popax ; Get the handle cpx #$01 bcs invhandle cmp #MAX_FDS bcs invhandle sta tmp2 rts ; Return with carry clear invhandle: lda #EINVAL sta __errno lda #0 sta __errno+1 rts ; Return with carry set .endproc
wagiminator/C64-Collection
2,118
C64_xu1541/software/tools/cc65-2.13.2/libsrc/cbm/cbm_write.s
; ; Ullrich von Bassewitz, 15.11.2002 ; ; Original C code by Marc 'BlackJack' Rintsch, 25.03.2001 ; ; int __fastcall__ cbm_write(unsigned char lfn, void* buffer, unsigned int size) ; { ; ; static unsigned int byteswritten; ; ; /* if we can't change to the outputchannel #lfn then return an error */ ; if (_oserror = cbm_k_ckout(lfn)) return -1; ; ; byteswritten = 0; ; ; while (byteswritten<size && !cbm_k_readst()) { ; cbm_k_bsout(((unsigned char*)buffer)[byteswritten++]); ; } ; ; if (cbm_k_readst()) { ; _oserror = 5; /* device not present */ ; byteswritten = -1; ; } ; ; cbm_k_clrch(); ; ; return byteswritten; ; } ; .include "cbm.inc" .export _cbm_write .import CKOUT, READST, BSOUT, CLRCH .importzp ptr1, ptr2, ptr3 .import popax, popa .import __oserror _cbm_write: sta ptr3 stx ptr3+1 ; Save size eor #$FF sta ptr1 txa eor #$FF sta ptr1+1 ; Save -size-1 jsr popax sta ptr2 stx ptr2+1 ; Save buffer jsr popa tax jsr CKOUT bcs @E2 ; Branch on error bcc @L3 ; Branch always ; Loop @L1: jsr READST cmp #0 ; Status ok? bne @E1 ldy #0 lda (ptr2),y ; inc ptr2 bne @L2 inc ptr2+1 ; A = *buffer++; @L2: jsr BSOUT ; cbm_k_bsout (A); @L3: inc ptr1 ; --size; bne @L1 inc ptr1+1 bne @L1 jsr CLRCH lda ptr3 ldx ptr3+1 ; return size; rts ; Error entry, called when READST fails @E1: lda #5 ; Error entry, error code is in A @E2: sta __oserror lda #$FF tax rts ; return -1
wagiminator/C64-Collection
2,205
C64_xu1541/software/tools/cc65-2.13.2/libsrc/cbm/oserror.s
; ; Ullrich von Bassewitz, 17.05.2000 ; ; int __fastcall__ _osmaperrno (unsigned char oserror); ; /* Map a system specific error into a system independent code */ ; .export __osmaperrno .include "errno.inc" .code __osmaperrno: ldx #ErrTabSize @L1: cmp ErrTab-2,x ; Search for the error code beq @L2 ; Jump if found dex dex bne @L1 ; Next entry ; Code not found, return EINVAL lda #<EINVAL ldx #>EINVAL rts ; Found the code @L2: lda ErrTab-1,x ldx #$00 ; High byte always zero rts .rodata ErrTab: .byte 1, EMFILE ; Too many open files .byte 2, EINVAL ; File is open .byte 3, EINVAL ; File not open .byte 4, ENOENT ; File not found .byte 5, ENODEV ; Device not present .byte 6, EINVAL ; File not input .byte 7, EINVAL ; File not output .byte 8, EINVAL ; Filename missing .byte 9, ENODEV ; Ilegal device ; .byte 20, ; Read error ; .byte 21, ; Read error ; .byte 22, ; Read error ; .byte 23, ; Read error ; .byte 24, ; Read error ; .byte 25, ; Write error .byte 26, EACCES ; Write protect on ; .byte 27, ; Read error ; .byte 28, ; Write error ; .byte 29, ; Disk ID mismatch ; .byte 30, ; Syntax error ; .byte 31, ; Syntax error ; .byte 32, ; Syntax error .byte 33, EINVAL ; Syntax error (invalid file name) .byte 34, EINVAL ; Syntax error (no file given) ; .byte 39, ; Syntax error ; .byte 50, ; Record not present ; .byte 51, ; Overflow in record ; .byte 52, ; File too large .byte 60, EINVAL ; Write file open .byte 61, EINVAL ; File not open .byte 62, ENOENT ; File not found .byte 63, EEXIST ; File exists .byte 64, EINVAL ; File type mismatch ; .byte 65, ; No block ; .byte 66, ; Illegal track or sector ; .byte 67, ; Illegal system track or sector .byte 70, EBUSY ; No channel ; .byte 71, ; Directory error ; .byte 72, ; Disk full ; .byte 73, ; DOS version mismatch .byte 74, ENODEV ; Drive not ready ErrTabSize = (* - ErrTab)
wagiminator/C64-Collection
4,734
C64_xu1541/software/tools/cc65-2.13.2/libsrc/cbm/filename.s
; ; Ullrich von Bassewitz, 16.11.2002 ; ; File name handling for CBM file I/O ; .export fnparse, fnparsename, fnset .export fnadd, fnaddmode, fncomplete, fndefunit .export fnunit, fnlen, fncmd, fnbuf .import SETNAM .import __curunit, __filetype .importzp ptr1, tmp1 .include "ctype.inc" ;------------------------------------------------------------------------------ ; fnparsename: Parse a filename (without drive spec) passed in in ptr1 and y. .proc fnparsename lda #0 sta tmp1 ; Remember length of name nameloop: lda (ptr1),y ; Get next char from filename beq namedone ; Jump if end of name reached ; Check for valid chars in the file name. We allow letters, digits, plus some ; additional chars from a table. ldx #fncharcount-1 namecheck: cmp fnchars,x beq nameok dex bpl namecheck tax lda __ctype,x and #CT_ALNUM beq invalidname ; Check the maximum length, store the character nameok: ldx tmp1 cpx #16 ; Maximum length reached? bcs invalidname lda (ptr1),y ; Reload char jsr fnadd ; Add character to name iny ; Next char from name inc tmp1 ; Increment length of name bne nameloop ; Branch always ; Invalid file name invalidname: lda #33 ; Invalid file name ; Done, we've successfully parsed the name. namedone: rts .endproc ;------------------------------------------------------------------------------ ; fnparse: Parse a full filename passed in in a/x. Will set the following ; variables: ; ; fnlen -> length of filename ; fnbuf -> filename including drive spec ; fnunit -> unit from spec or default unit ; ; Returns an error code in A or zero if all is ok. .proc fnparse sta ptr1 stx ptr1+1 ; Save pointer to name ; For now we will always use the default unit jsr fndefunit ; Check the name for a drive spec ldy #0 lda (ptr1),y cmp #'0' beq digit cmp #'1' bne nodrive digit: sta fnbuf+0 iny lda (ptr1),y cmp #':' bne nodrive ; We found a drive spec, copy it to the buffer sta fnbuf+1 iny ; Skip colon bne drivedone ; Branch always ; We did not find a drive spec, always use drive zero nodrive: lda #'0' sta fnbuf+0 lda #':' sta fnbuf+1 ldy #$00 ; Reposition to start of name ; Drive spec done. We do now have a drive spec in the buffer. drivedone: lda #2 ; Length of drive spec sta fnlen ; Copy the name into the file name buffer. The subroutine returns an error ; code in A and zero flag set if the were no errors. jmp fnparsename .endproc ;-------------------------------------------------------------------------- ; fndefunit: Use the default unit .proc fndefunit lda __curunit sta fnunit rts .endproc ;-------------------------------------------------------------------------- ; fnset: Tell the kernal about the file name .proc fnset lda fnlen ldx #<fnbuf ldy #>fnbuf jmp SETNAM .endproc ;-------------------------------------------------------------------------- ; fncomplete: Complete a filename by adding ",t,m" where t is the file type ; and m is the access mode passed in in the A register ; ; fnaddmode: Add ",m" to a filename, where "m" is passed in A fncomplete: pha ; Save mode jsr fnaddcomma ; Add a comma lda __filetype jsr fnadd ; Add the type pla fnaddmode: pha jsr fnaddcomma pla fnadd: ldx fnlen inc fnlen sta fnbuf,x rts fnaddcomma: lda #',' bne fnadd ;-------------------------------------------------------------------------- ; Data .bss fnunit: .res 1 fnlen: .res 1 .data fncmd: .byte 's' ; Use as scratch command fnbuf: .res 35 ; Either 0:0123456789012345,t,m ; Or 0:0123456789012345=0123456789012345 .rodata ; Characters that are ok in filenames besides digits and letters fnchars:.byte ".,-_+()" fncharcount = *-fnchars
wagiminator/C64-Collection
2,704
C64_xu1541/software/tools/cc65-2.13.2/libsrc/cbm/cbm_read.s
; ; Ullrich von Bassewitz, 22.06.2002 ; ; Original C code by Marc 'BlackJack' Rintsch, 19.03.2001 ; ; int __fastcall__ cbm_read (unsigned char lfn, void* buffer, unsigned int size) ; /* Reads up to "size" bytes from a file to "buffer". ; * Returns the number of actually read bytes, 0 if there are no bytes left ; * (EOF) or -1 in case of an error. _oserror contains an errorcode then (see ; * table below). ; */ ; { ; static unsigned int bytesread; ; static unsigned char tmp; ; ; /* if we can't change to the inputchannel #lfn then return an error */ ; if (_oserror = cbm_k_chkin(lfn)) return -1; ; ; bytesread = 0; ; ; while (bytesread<size && !cbm_k_readst()) { ; tmp = cbm_k_basin(); ; ; /* the kernal routine BASIN sets ST to EOF if the end of file ; * is reached the first time, then we have store tmp. ; * every subsequent call returns EOF and READ ERROR in ST, then ; * we have to exit the loop here immidiatly. */ ; if (cbm_k_readst() & 0xBF) break; ; ; ((unsigned char*)buffer)[bytesread++] = tmp; ; } ; ; cbm_k_clrch(); ; return bytesread; ; } ; .include "cbm.inc" .export _cbm_read .import CHKIN, READST, BASIN, CLRCH .importzp ptr1, ptr2, ptr3, tmp1 .import popax, popa .import __oserror _cbm_read: eor #$FF sta ptr1 txa eor #$FF sta ptr1+1 ; Save -size-1 jsr popax sta ptr2 stx ptr2+1 ; Save buffer jsr popa tax jsr CHKIN bcs @E1 ; Branch on error ; bytesread = 0; lda #$00 sta ptr3 sta ptr3+1 beq @L3 ; Branch always ; Loop @L1: jsr READST cmp #0 ; Status ok? bne @L4 jsr BASIN ; Read next char from file sta tmp1 ; Save it for later jsr READST and #$BF bne @L4 lda tmp1 ldy #0 sta (ptr2),y ; Save read byte inc ptr2 bne @L2 inc ptr2+1 ; ++buffer; @L2: inc ptr3 bne @L3 inc ptr3+1 ; ++bytesread; @L3: inc ptr1 bne @L1 inc ptr1+1 bne @L1 @L4: jsr CLRCH lda ptr3 ldx ptr3+1 ; return bytesread; rts ; CHKIN failed @E1: sta __oserror lda #$FF tax rts ; return -1
wagiminator/C64-Collection
3,297
C64_xu1541/software/tools/cc65-2.13.2/libsrc/cbm/read.s
; ; Ullrich von Bassewitz, 16.11.2002 ; ; int read (int fd, void* buf, unsigned count); ; .export _read .constructor initstdin .import SETLFS, OPEN, CHKIN, BASIN, CLRCH, READST .import rwcommon .import popax .import __oserror .importzp ptr1, ptr2, ptr3, tmp1, tmp2, tmp3 .include "fcntl.inc" .include "cbm.inc" .include "filedes.inc" ;-------------------------------------------------------------------------- ; initstdin: Open the stdin file descriptors for the keyboard .segment "INIT" .proc initstdin lda #LFN_READ sta fdtab+STDIN_FILENO lda #STDIN_FILENO + LFN_OFFS ldx #CBMDEV_KBD stx unittab+STDIN_FILENO ldy #$FF jsr SETLFS jmp OPEN ; Will always succeed .endproc ;-------------------------------------------------------------------------- ; _read .code .proc _read jsr rwcommon ; Pop params, check handle bcs errout ; Invalid handle, errno already set ; Check if the LFN is valid and the file is open for writing adc #LFN_OFFS ; Carry is already clear tax lda fdtab-LFN_OFFS,x; Get flags for this handle and #LFN_READ ; File open for writing? beq notopen ; Check the EOF flag. If it is set, don't read anything lda fdtab-LFN_OFFS,x; Get flags for this handle bmi eof ; Valid lfn. Make it the input file jsr CHKIN bcs error ; Go looping... bcc @L3 ; Branch always ; Read the next byte @L0: jsr BASIN sta tmp1 ; Save the input byte jsr READST ; Read the IEEE status sta tmp3 ; Save it and #%10111111 ; Check anything but the EOI bit bne error5 ; Assume device not present ; Store the byte just read ldy #0 lda tmp1 sta (ptr2),y inc ptr2 bne @L1 inc ptr2+1 ; *buf++ = A; ; Increment the byte count @L1: inc ptr3 bne @L2 inc ptr3+1 ; Get the status again and check the EOI bit @L2: lda tmp3 and #%01000000 ; Check for EOI bne @L4 ; Jump if end of file reached ; Decrement the count @L3: inc ptr1 bne @L0 inc ptr1+1 bne @L0 beq done ; Branch always ; Set the EOI flag and bail out @L4: ldx tmp2 ; Get the handle lda #LFN_EOF ora fdtab,x sta fdtab,x ; Read done, close the input channel done: jsr CLRCH ; Return the number of chars read eof: lda ptr3 ldx ptr3+1 rts ; Error entry, file is not open notopen: lda #3 ; File not open bne error ; Error entry, status not ok error5: lda #5 ; Device not present error: sta __oserror errout: lda #$FF tax ; Return -1 rts .endproc
wagiminator/C64-Collection
6,345
C64_xu1541/software/tools/cc65-2.13.2/libsrc/cbm/diskcmd.s
; ; Ullrich von Bassewitz, 2002-11-17, 2009-02-22 ; ; Handle disk command channels ; .export isdisk .export opencmdchannel .export closecmdchannel .export readdiskerror .export writediskcmd .export writefndiskcmd .import SETLFS, SETNAM, OPEN, CLOSE, BSOUT, BASIN .import CHKIN, CKOUT, CLRCH .import fncmd, fnlen, fnunit .importzp tmp1, ptr1 .include "cbm.inc" .include "filedes.inc" ;-------------------------------------------------------------------------- ; isdisk: Return carry clear if the unit number in X is a disk, return ; carry set if not. .proc isdisk cpx #FIRST_DRIVE ; Disk unit? bcc @L1 ; Branch if no disk cpx #FIRST_DRIVE+MAX_DRIVES rts @L1: sec rts .endproc ;-------------------------------------------------------------------------- ; Open the command channel for the disk unit in X. The function returns an ; error code in A and sets the flags according to the contents of A. opencmdchannel: jsr isdisk ; Disk unit? bcs success ; Is this channel already open? ldy opentab-FIRST_DRIVE,x bne isopen ; Open the command channel, Carry is still clear stx tmp1 ; Save the unit number txa ; Get unit number adc #(LFN_OFFS+MAX_FDS-FIRST_DRIVE) ldy #15 ; Secondary address for cmd channel jsr SETLFS lda #0 jsr SETNAM ; No name supplied to OPEN jsr OPEN bcs done ; Error, code is in A ; Command channel is open now. Increment the count ldx tmp1 ; Unit number ldy opentab-FIRST_DRIVE,x isopen: iny tya sta opentab-FIRST_DRIVE,x ; Done, return success success:lda #$00 done: cmp #$00 ; Set flags for return code rts ;-------------------------------------------------------------------------- ; closecmdchannel: Decrement the counter for the disk command channel and ; close the channel if the counter drops to zero. The function expects the ; drive number in X and returns an error code in A. The flags for the return ; code are set when the function returns. closecmdchannel: jsr isdisk ; Disk unit? bcs success ; Is this channel really open? ldy opentab-FIRST_DRIVE,x beq success ; OOPS! Channel is not open ; Decrement the count and stor it back dey tya sta opentab-FIRST_DRIVE,x ; If the counter is now zero, close the channel. We still have carry clear ; when we come here. bne success txa ; Make LFN from drive number adc #(LFN_OFFS+MAX_FDS-FIRST_DRIVE) jsr CLOSE bcs done bcc success ;-------------------------------------------------------------------------- ; readdiskerror: Read a disk error from an already open command channel. ; Returns an error code in A, which may either be the code read from the ; command channel, or another error when accessing the command channel failed. readdiskerror: jsr isdisk bcs success ; Read the command channel. We won't check the status after the channel is ; open, because this seems to be unnecessary in most cases. txa clc ; Make LFN from drive number adc #(LFN_OFFS+MAX_FDS-FIRST_DRIVE) tax jsr CHKIN ; Make the command channel input bcs done ; Bail out with error code in A jsr BASIN and #$0F ; Make digit value from PETSCII sta tmp1 asl a ; * 2 asl a ; * 4, carry clear adc tmp1 ; * 5 asl a ; * 10 sta tmp1 jsr BASIN and #$0F ; Make digit value from PETSCII clc adc tmp1 ; Errors below 20 are not real errors. Fix that cmp #20+1 bcs @L1 lda #$00 @L1: pha ; Read the remainder of the message and throw it away @L2: jsr BASIN cmp #$0D bne @L2 ; Close the input channel jsr CLRCH ; Restore the error code (will also set the flags) and return pla rts ;-------------------------------------------------------------------------- ; writefndiskcmd: Write the contents of fncmd to the command channel of the ; drive in fnunit. Returns an error code in A, flags are set according to ; the contents of A. writefndiskcmd: lda #<fncmd sta ptr1 lda #>fncmd sta ptr1+1 ldx fnlen inx ; Account for command char in fncmd txa ; Length of name into A ldx fnunit ; Unit ; Run directly into writediskcmd ; jmp writediskcmd ;-------------------------------------------------------------------------- ; writediskcmd: Gets pointer to data in ptr1, length in A. Writes all data ; to the command channel of the drive in X. Returns an error code in A, ; flags are set according to the contents of A. writediskcmd: jsr isdisk bcs success ; No disk - already done ; Remember the length sta tmp1 ; Write to the command channel. txa clc ; Make LFN from drive number adc #(LFN_OFFS+MAX_FDS-FIRST_DRIVE) tax jsr CKOUT ; Make the command channel output bcs done ; Bail out with error code in A ldy #$00 @L1: cpy tmp1 bcs @L3 lda (ptr1),y iny jsr BSOUT bcc @L1 @L2: pha jsr CLRCH pla rts @L3: jsr CLRCH lda #$00 rts ;-------------------------------------------------------------------------- ; Data .bss opentab: .res MAX_DRIVES, 0
wagiminator/C64-Collection
3,267
C64_xu1541/software/tools/cc65-2.13.2/libsrc/cbm/oserrlist.s
; ; 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 1, "Too many open files" sys_oserr_entry 2, "File is open" sys_oserr_entry 3, "File not open" sys_oserr_entry 4, "File not found" sys_oserr_entry 5, "Device not present" sys_oserr_entry 6, "File not input" sys_oserr_entry 7, "File not output" sys_oserr_entry 8, "Filename missing" sys_oserr_entry 9, "Ilegal device" sys_oserr_entry 20, "Read error" sys_oserr_entry 21, "Read error" sys_oserr_entry 22, "Read error" sys_oserr_entry 23, "Read error" sys_oserr_entry 24, "Read error" sys_oserr_entry 25, "Write error" sys_oserr_entry 26, "Write protect on" sys_oserr_entry 27, "Read error" sys_oserr_entry 28, "Write error" sys_oserr_entry 29, "Disk ID mismatch" sys_oserr_entry 30, "Syntax error" sys_oserr_entry 31, "Syntax error" sys_oserr_entry 32, "Syntax error" sys_oserr_entry 33, "Syntax error (invalid file name)" sys_oserr_entry 34, "Syntax error (no file given)" sys_oserr_entry 39, "Syntax error" sys_oserr_entry 50, "Record not present" sys_oserr_entry 51, "Overflow in record" sys_oserr_entry 52, "File too large" sys_oserr_entry 60, "Write file open" sys_oserr_entry 61, "File not open" sys_oserr_entry 62, "File not found" sys_oserr_entry 63, "File exists" sys_oserr_entry 64, "File type mismatch" sys_oserr_entry 65, "No block" sys_oserr_entry 66, "Illegal track or sector" sys_oserr_entry 67, "Illegal system track or sector" sys_oserr_entry 70, "No channel" sys_oserr_entry 71, "Directory error" sys_oserr_entry 72, "Disk full" sys_oserr_entry 73, "DOS version mismatch" sys_oserr_entry 74, "Drive not ready" sys_oserr_sentinel "Unknown error"
wagiminator/C64-Collection
2,651
C64_xu1541/software/tools/cc65-2.13.2/libsrc/cbm/write.s
; ; Ullrich von Bassewitz, 16.11.2002 ; ; int write (int fd, const void* buf, unsigned count); ; .export _write .constructor initstdout .import SETLFS, OPEN, CKOUT, BSOUT, CLRCH .import rwcommon .import __oserror .importzp sp, ptr1, ptr2, ptr3 .include "fcntl.inc" .include "cbm.inc" .include "filedes.inc" ;-------------------------------------------------------------------------- ; initstdout: Open the stdout and stderr file descriptors for the screen. .segment "INIT" .proc initstdout lda #LFN_WRITE sta fdtab+STDOUT_FILENO sta fdtab+STDERR_FILENO lda #CBMDEV_SCREEN sta unittab+STDOUT_FILENO sta unittab+STDERR_FILENO lda #STDOUT_FILENO + LFN_OFFS jsr @L1 lda #STDERR_FILENO + LFN_OFFS @L1: ldx #CBMDEV_SCREEN ldy #$FF jsr SETLFS jmp OPEN ; Will always succeed .endproc ;-------------------------------------------------------------------------- ; _write .code .proc _write jsr rwcommon ; Pop params, check handle bcs errout ; Invalid handle, errno already set ; Check if the LFN is valid and the file is open for writing adc #LFN_OFFS ; Carry is already clear tax lda fdtab-LFN_OFFS,x; Get flags for this handle and #LFN_WRITE ; File open for writing? beq notopen ; Valid lfn. Make it the output file jsr CKOUT bcs error bcc @L2 ; Output the next character from the buffer @L0: ldy #0 lda (ptr2),y inc ptr2 bne @L1 inc ptr2+1 ; A = *buf++; @L1: jsr BSOUT bcs error ; Bail out on errors ; Count characters written inc ptr3 bne @L2 inc ptr3+1 ; Decrement count @L2: inc ptr1 bne @L0 inc ptr1+1 bne @L0 ; Wrote all chars, close the output channel jsr CLRCH ; Return the number of chars written lda ptr3 ldx ptr3+1 rts ; Error entry, file is not open notopen: lda #3 ; File not open bne error ; Error entry, status not ok error5: lda #5 ; Device not present error: sta __oserror errout: lda #$FF tax ; Return -1 rts .endproc
wagiminator/C64-Collection
10,987
C64_xu1541/software/tools/cc65-2.13.2/libsrc/cbm/ctype.s
; ; Character specification table. ; ; Ullrich von Bassewitz, 02.06.1998 ; 2003-05-02, Greg King ; ; 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 weren't for the slow parameter-passing of cc65, ; one even could define C-language macroes for the isxxx functions ; (as it usually is 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. ; This table is taken from Craig S. Bruce's technical docs. for the ACE OS. .include "ctype.inc" ; The table is read-only, put it into the RODATA segment. .rodata __ctype: .byte CT_CTRL ; 0/00 ___rvs_@___ .byte CT_CTRL ; 1/01 ___rvs_a___ .byte CT_CTRL ; 2/02 ___rvs_b___ .byte CT_CTRL ; 3/03 ___rvs_c___ .byte CT_CTRL ; 4/04 ___rvs_d___ .byte CT_CTRL ; 5/05 ___rvs_e___ .byte CT_CTRL ; 6/06 ___rvs_f___ .byte CT_CTRL ; 7/07 _BEL/rvs_g_ .byte CT_CTRL ; 8/08 ___rvs_h___ .byte CT_CTRL | CT_OTHER_WS | CT_SPACE_TAB ; 9/09 _TAB/rvs_i_ .byte CT_CTRL | CT_OTHER_WS ; 10/0a _BOL/rvs_j_ .byte CT_CTRL ; 11/0b ___rvs_k___ .byte CT_CTRL ; 12/0c ___rvs_l___ .byte CT_CTRL | CT_OTHER_WS ; 13/0d _CR_/rvs_m_ .byte CT_CTRL ; 14/0e ___rvs_n___ .byte CT_CTRL ; 15/0f ___rvs_o___ .byte CT_CTRL ; 16/10 ___rvs_p___ .byte CT_CTRL | CT_OTHER_WS ; 17/11 _VT_/rvs_q_ .byte CT_CTRL ; 18/12 ___rvs_r___ .byte CT_CTRL | CT_OTHER_WS ; 19/13 HOME/rvs_s_ .byte CT_CTRL | CT_OTHER_WS ; 20/14 _BS_/rvs_t_ .byte CT_CTRL ; 21/15 ___rvs_u___ .byte CT_CTRL ; 22/16 ___rvs_v___ .byte CT_CTRL ; 23/17 ___rvs_w___ .byte CT_CTRL ; 24/18 ___rvs_x___ .byte CT_CTRL ; 25/19 ___rvs_y___ .byte CT_CTRL ; 26/1a ___rvs_z___ .byte CT_CTRL ; 27/1b ___rvs_[___ .byte CT_CTRL ; 28/1c ___rvs_\___ .byte CT_CTRL | CT_OTHER_WS ; 29/1d cursr-right .byte CT_CTRL ; 30/1e ___rvs_^___ .byte CT_CTRL ; 31/1f _rvs_under_ .byte CT_SPACE | CT_SPACE_TAB ; 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 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 $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 CT_LOWER | CT_XDIGIT ; 65/41 _____a_____ .byte CT_LOWER | CT_XDIGIT ; 66/42 _____b_____ .byte CT_LOWER | CT_XDIGIT ; 67/43 _____c_____ .byte CT_LOWER | CT_XDIGIT ; 68/44 _____d_____ .byte CT_LOWER | CT_XDIGIT ; 69/45 _____e_____ .byte CT_LOWER | CT_XDIGIT ; 70/46 _____f_____ .byte CT_LOWER ; 71/47 _____g_____ .byte CT_LOWER ; 72/48 _____h_____ .byte CT_LOWER ; 73/49 _____i_____ .byte CT_LOWER ; 74/4a _____j_____ .byte CT_LOWER ; 75/4b _____k_____ .byte CT_LOWER ; 76/4c _____l_____ .byte CT_LOWER ; 77/4d _____m_____ .byte CT_LOWER ; 78/4e _____n_____ .byte CT_LOWER ; 79/4f _____o_____ .byte CT_LOWER ; 80/50 _____p_____ .byte CT_LOWER ; 81/51 _____q_____ .byte CT_LOWER ; 82/52 _____r_____ .byte CT_LOWER ; 83/53 _____s_____ .byte CT_LOWER ; 84/54 _____t_____ .byte CT_LOWER ; 85/55 _____u_____ .byte CT_LOWER ; 86/56 _____v_____ .byte CT_LOWER ; 87/57 _____w_____ .byte CT_LOWER ; 88/58 _____x_____ .byte CT_LOWER ; 89/59 _____y_____ .byte CT_LOWER ; 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 _A`_grave__ .byte $00 ; 97/61 _A'_acute__ .byte $00 ; 98/62 _A^_circum_ .byte $00 ; 99/63 _A~_tilde__ .byte $00 ; 100/64 _A"_dieres_ .byte $00 ; 101/65 _A__ring___ .byte $00 ; 102/66 _AE________ .byte $00 ; 103/67 _C,cedilla_ .byte $00 ; 104/68 _E`_grave__ .byte $00 ; 105/69 _E'_acute__ .byte $00 ; 106/6a _E^_circum_ .byte $00 ; 107/6b _E"_dieres_ .byte $00 ; 108/6c _I`_grave__ .byte $00 ; 109/6d _I'_acute__ .byte $00 ; 110/6e _I^_circum_ .byte $00 ; 111/6f _I"_dieres_ .byte $00 ; 112/70 _D-_Eth_lr_ .byte $00 ; 113/71 _N~_tilde__ .byte $00 ; 114/72 _O`_grave__ .byte $00 ; 115/73 _O'_acute__ .byte $00 ; 116/74 _O^_circum_ .byte $00 ; 117/75 _O~_tilde__ .byte $00 ; 118/76 _O"_dieres_ .byte $00 ; 119/77 __multiply_ .byte $00 ; 120/78 _O/_slash__ .byte $00 ; 121/79 _U`_grave__ .byte $00 ; 122/7a _U'_acute__ .byte $00 ; 123/7b _U^_circum_ .byte $00 ; 124/7c _U"_dieres_ .byte $00 ; 125/7d _Y'_acute__ .byte $00 ; 126/7e _cap_thorn_ .byte $00 ; 127/7f _Es-sed_B__ .byte CT_CTRL ; 128/80 __bullet___ .byte CT_CTRL ; 129/81 __v_line___ .byte CT_CTRL ; 130/82 __h_line___ .byte CT_CTRL ; 131/83 ___cross___ .byte CT_CTRL ; 132/84 _tl_corner_ .byte CT_CTRL ; 133/85 _tr_corner_ .byte CT_CTRL ; 134/86 _bl_corner_ .byte CT_CTRL ; 135/87 _br_corner_ .byte CT_CTRL ; 136/88 ___l_tee___ .byte CT_CTRL ; 137/89 ___r_tee___ .byte CT_CTRL ; 138/8a ___t_tee___ .byte CT_CTRL ; 139/8b ___b_tee___ .byte CT_CTRL ; 140/8c ___heart___ .byte CT_CTRL | CT_OTHER_WS ; 141/8d _CR/diamond .byte CT_CTRL ; 142/8e ___club____ .byte CT_CTRL ; 143/8f ___spade___ .byte CT_CTRL ; 144/90 _s_circle__ .byte CT_CTRL | CT_OTHER_WS ; 145/91 _cursor-up_ .byte CT_CTRL ; 146/92 ___pound___ .byte CT_CTRL | CT_OTHER_WS ; 147/93 _CLS/check_ .byte CT_CTRL | CT_OTHER_WS ; 148/94 __INSert___ .byte CT_CTRL ; 149/95 ____+/-____ .byte CT_CTRL ; 150/96 __divide___ .byte CT_CTRL ; 151/97 __degree___ .byte CT_CTRL ; 152/98 _c_checker_ .byte CT_CTRL ; 153/99 _f_checker_ .byte CT_CTRL ; 154/9a _solid_sq__ .byte CT_CTRL ; 155/9b __cr_char__ .byte CT_CTRL ; 156/9c _up_arrow__ .byte CT_CTRL | CT_OTHER_WS ; 157/9d cursor-left .byte CT_CTRL ; 158/9e _left_arro_ .byte CT_CTRL ; 159/9f _right_arr_ .byte CT_SPACE | CT_SPACE_TAB ; 160/a0 _req space_ .byte $00 ; 161/a1 _!_invertd_ .byte $00 ; 162/a2 ___cent____ .byte $00 ; 163/a3 ___pound___ .byte $00 ; 164/a4 __currency_ .byte $00 ; 165/a5 ____yen____ .byte $00 ; 166/a6 _|_broken__ .byte $00 ; 167/a7 __section__ .byte $00 ; 168/a8 __umulaut__ .byte $00 ; 169/a9 _copyright_ .byte $00 ; 170/aa __fem_ord__ .byte $00 ; 171/ab _l_ang_quo_ .byte $00 ; 172/ac ____not____ .byte $00 ; 173/ad _syl_hyphn_ .byte $00 ; 174/ae _registerd_ .byte $00 ; 175/af _overline__ .byte $00 ; 176/b0 __degrees__ .byte $00 ; 177/b1 ____+/-____ .byte $00 ; 178/b2 _2_supersc_ .byte $00 ; 179/b3 _3_supersc_ .byte $00 ; 180/b4 ___acute___ .byte $00 ; 181/b5 ____mu_____ .byte $00 ; 182/b6 _paragraph_ .byte $00 ; 183/b7 __mid_dot__ .byte $00 ; 184/b8 __cedilla__ .byte $00 ; 185/b9 _1_supersc_ .byte $00 ; 186/ba __mas_ord__ .byte $00 ; 187/bb _r_ang_quo_ .byte $00 ; 188/bc ____1/4____ .byte $00 ; 189/bd ____1/2____ .byte $00 ; 190/be ____3/4____ .byte $00 ; 191/bf _?_invertd_ .byte $00 ; 192/c0 _____`_____ .byte CT_UPPER | CT_XDIGIT ; 193/c1 _____A_____ .byte CT_UPPER | CT_XDIGIT ; 194/c2 _____B_____ .byte CT_UPPER | CT_XDIGIT ; 195/c3 _____C_____ .byte CT_UPPER | CT_XDIGIT ; 196/c4 _____D_____ .byte CT_UPPER | CT_XDIGIT ; 197/c5 _____E_____ .byte CT_UPPER | CT_XDIGIT ; 198/c6 _____F_____ .byte CT_UPPER ; 199/c7 _____G_____ .byte CT_UPPER ; 200/c8 _____H_____ .byte CT_UPPER ; 201/c9 _____I_____ .byte CT_UPPER ; 202/ca _____J_____ .byte CT_UPPER ; 203/cb _____K_____ .byte CT_UPPER ; 204/cc _____L_____ .byte CT_UPPER ; 205/cd _____M_____ .byte CT_UPPER ; 206/ce _____N_____ .byte CT_UPPER ; 207/cf _____O_____ .byte CT_UPPER ; 208/d0 _____P_____ .byte CT_UPPER ; 209/d1 _____Q_____ .byte CT_UPPER ; 210/d2 _____R_____ .byte CT_UPPER ; 211/d3 _____S_____ .byte CT_UPPER ; 212/d4 _____T_____ .byte CT_UPPER ; 213/d5 _____U_____ .byte CT_UPPER ; 214/d6 _____V_____ .byte CT_UPPER ; 215/d7 _____W_____ .byte CT_UPPER ; 216/d8 _____X_____ .byte CT_UPPER ; 217/d9 _____Y_____ .byte CT_UPPER ; 218/da _____Z_____ .byte $00 ; 219/db _____{_____ .byte $00 ; 220/dc _____|_____ .byte $00 ; 221/dd _____}_____ .byte $00 ; 222/de _____~_____ .byte $00 ; 223/df ___HOUSE___ .byte $00 ; 224/e0 _a`_grave__ .byte $00 ; 225/e1 _a'_acute__ .byte $00 ; 226/e2 _a^_circum_ .byte $00 ; 227/e3 _a~_tilde__ .byte $00 ; 228/e4 _a"_dieres_ .byte $00 ; 229/e5 _a__ring___ .byte $00 ; 230/e6 _ae________ .byte $00 ; 231/e7 _c,cedilla_ .byte $00 ; 232/e8 _e`_grave__ .byte $00 ; 233/e9 _e'_acute__ .byte $00 ; 234/ea _e^_circum_ .byte $00 ; 235/eb _e"_dieres_ .byte $00 ; 236/ec _i`_grave__ .byte $00 ; 237/ed _i'_acute__ .byte $00 ; 238/ee _i^_circum_ .byte $00 ; 239/ef _i"_dieres_ .byte $00 ; 240/f0 _o^x_Eth_s_ .byte $00 ; 241/f1 _n~_tilda__ .byte $00 ; 242/f2 _o`_grave__ .byte $00 ; 243/f3 _o'_acute__ .byte $00 ; 244/f4 _o^_circum_ .byte $00 ; 245/f5 _o~_tilde__ .byte $00 ; 246/f6 _o"_dieres_ .byte $00 ; 247/f7 __divide___ .byte $00 ; 248/f8 _o/_slash__ .byte $00 ; 249/f9 _u`_grave__ .byte $00 ; 250/fa _u'_acute__ .byte $00 ; 251/fb _u^_circum_ .byte $00 ; 252/fc _u"_dieres_ .byte $00 ; 253/fd _y'_acute__ .byte $00 ; 254/fe _sm_thorn__ .byte $00 ; 255/ff _y"_dieres_
wagiminator/C64-Collection
4,936
C64_xu1541/software/tools/cc65-2.13.2/libsrc/cbm/open.s
; ; Ullrich von Bassewitz, 16.11.2002 ; ; int open (const char* name, int flags, ...); /* May take a mode argument */ ; ; 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 .destructor closeallfiles, 17 .import SETLFS, OPEN, CLOSE .import addysp, popax .import scratch, fnparse, fnaddmode, fncomplete, fnset .import opencmdchannel, closecmdchannel, readdiskerror .import __oserror .import fnunit .import _close .importzp sp, tmp2, tmp3 .include "errno.inc" .include "fcntl.inc" .include "filedes.inc" ;-------------------------------------------------------------------------- ; closeallfiles: Close all open files. .proc closeallfiles ldx #MAX_FDS-1 loop: lda fdtab,x beq next ; Skip unused entries ; Close this file txa pha ; Save current value of X ldx #0 jsr _close pla tax ; Next file next: dex bpl loop rts .endproc ;-------------------------------------------------------------------------- ; _open .proc _open ; Throw away any additional parameters passed through the ellipsis dey ; Parm count < 4 shouldn't be needed to be... dey ; ...checked (it generates a c compiler warning) dey dey beq parmok ; Branch if parameter count ok jsr addysp ; Fix stack, throw away unused parameters ; Parameters ok. Pop the flags and save them into tmp3 parmok: jsr popax ; Get flags sta tmp3 ; Get the filename from stack and parse it. Bail out if is not ok jsr popax ; Get name jsr fnparse ; Parse it cmp #0 bne error ; Bail out if problem with name ; Get a free file handle and remember it in tmp2 jsr freefd bcs nofile stx tmp2 ; Check the flags. We cannot have both, read and write flags set, and we cannot ; open a file for writing without creating it. lda tmp3 and #(O_RDWR | O_CREAT) cmp #O_RDONLY ; Open for reading? beq doread ; Yes: Branch cmp #(O_WRONLY | O_CREAT) ; Open for writing? bne invflags ; No: Invalid open mode ; If O_TRUNC is set, scratch the file, but ignore any errors lda tmp3 and #O_TRUNC beq notrunc jsr scratch ; Complete the the file name. Check for append mode here. notrunc: lda tmp3 ; Get the mode again ldx #'a' and #O_APPEND ; Append mode? bne append ; Branch if yes ldx #'w' append: txa jsr fncomplete ; Add type and mode to the name ; Setup the real open flags lda #LFN_WRITE bne common ; Read bit is set. Add an 'r' to the name doread: lda #'r' jsr fnaddmode ; Add the mode to the name lda #LFN_READ ; Common read/write code. Flags in A, handle in tmp2 common: sta tmp3 jsr fnset ; Set the file name lda tmp2 clc adc #LFN_OFFS ldx fnunit tay ; Use the LFN also as SA jsr SETLFS ; Set the file params jsr OPEN bcs error ; Open the the drive command channel and read it ldx fnunit jsr opencmdchannel bne closeandexit ldx fnunit jsr readdiskerror bne closeandexit ; Branch on error ; File is open. Mark it as open in the table ldx tmp2 lda tmp3 sta fdtab,x lda fnunit sta unittab,x ; Remember ; Done. Return the handle in a/x txa ; Handle ldx #0 rts ; Error entry: No more file handles nofile: lda #1 ; Too many open files ; Error entry. Error code is in A. error: sta __oserror errout: lda #$FF tax ; Return -1 rts ; Error entry: Invalid flag parameter invflags: lda #EINVAL sta __errno lda #0 sta __errno+1 beq errout ; Error entry: Close the file and exit closeandexit: pha lda tmp2 clc adc #LFN_OFFS jsr CLOSE ldx fnunit jsr closecmdchannel pla bne error ; Branch always .endproc
wagiminator/C64-Collection
3,546
C64_xu1541/software/tools/cc65-2.13.2/libsrc/vic20/vic20-stdjoy.s
; ; Standard joystick driver for the VIC20. May be used multiple times when linked ; to the statically application. ; ; Ullrich von Bassewitz, 2002-12-20 ; Using code from Steve Schmidtke ; .include "zeropage.inc" .include "joy-kernel.inc" .include "joy-error.inc" .include "vic20.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 $80 ; 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 = 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 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. ; The current implemenation will ignore the joystick number because we do only ; have one joystick READ: lda #$7F ; mask for VIA2 JOYBIT: sw3 ldx #$C3 ; mask for VIA1 JOYBITS: sw0,sw1,sw2,sw4 sei ; necessary? ldy VIA2_DDRB ; remember the date of DDRB sta VIA2_DDRB ; set JOYBITS on this VIA for input lda VIA2_JOY ; read JOYBIT: sw3 sty VIA2_DDRB ; restore the state of DDRB asl ; Shift sw3 into carry ldy VIA1_DDRA ; remember the state of DDRA stx VIA1_DDRA ; set JOYBITS on this VIA for input lda VIA1_JOY ; read JOYBITS: sw0,sw1,sw2,sw4 sty VIA1_DDRA ; restore the state of DDRA cli ; necessary? ror ; Shift sw3 into bit 7 and #$9E ; Mask relevant bits eor #$9E ; Active states are inverted rts
wagiminator/C64-Collection
3,149
C64_xu1541/software/tools/cc65-2.13.2/libsrc/vic20/crt0.s
; ; Startup code for cc65 (Vic20 version) ; .export _exit .export __STARTUP__ : absolute = 1 ; Mark as startup .import initlib, donelib, callirq .import zerobss, push0 .import callmain .import RESTOR, BSOUT, CLRCH .import __INTERRUPTOR_COUNT__ .import __RAM_START__, __RAM_SIZE__ ; Linker generated .include "zeropage.inc" .include "vic20.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 ; SYS token .byte <(((@Start / 1000) .mod 10) + $30) .byte <(((@Start / 100) .mod 10) + $30) .byte <(((@Start / 10) .mod 10) + $30) .byte <(((@Start / 1) .mod 10) + $30) .byte $00 ; End of BASIC line @Next: .word 0 ; BASIC end marker @Start: ; ------------------------------------------------------------------------ ; 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 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 the stack pointer ldx spsave txs ; 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
wagiminator/C64-Collection
1,936
C64_xu1541/software/tools/cc65-2.13.2/libsrc/vic20/kernal.s
; ; Ullrich von Bassewitz, 19.11.2002 ; ; VIC20 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
3,287
C64_xu1541/software/tools/cc65-2.13.2/libsrc/vic20/vic20-ptvjoy.s
; ; PTV-3 Player joystick driver for the VIC20 ; ; Stefan Haubenthal, 2005-05-25 ; Groepaz/Hitmen, 2002-12-23 ; obviously based on Ullrichs driver :) ; Using code from Steve Schmidtke ; .include "zeropage.inc" .include "joy-kernel.inc" .include "joy-error.inc" .include "vic20.inc" ; ------------------------------------------------------------------------ ; 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 VIA1_PRB := VIA1 ; User port register JOY_COUNT = 3 ; 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 ; mask for VIA2 JOYBIT: sw3 ldx #$C3 ; mask for VIA1 JOYBITS: sw0,sw1,sw2,sw4 sei ; necessary? ldy VIA2_DDRB ; remember the date of DDRB sta VIA2_DDRB ; set JOYBITS on this VIA for input lda VIA2_JOY ; read JOYBIT: sw3 sty VIA2_DDRB ; restore the state of DDRB asl ; Shift sw3 into carry ldy VIA1_DDRA ; remember the state of DDRA stx VIA1_DDRA ; set JOYBITS on this VIA for input lda VIA1_JOY ; read JOYBITS: sw0,sw1,sw2,sw4 sty VIA1_DDRA ; restore the state of DDRA cli ; necessary? ror ; Shift sw3 into bit 7 and #$9E ; Mask relevant bits eor #$9E ; Active states are inverted rts ; Read joystick 2 joy2: lda #%10000000 ; via port B Data-Direction sta VIA1_DDRB ; bit 7: out bit 6-0: in dex bne joy3 lda #$80 ; via port B read/write sta VIA1_PRB ; (output one at PB7) lda VIA1_PRB ; via port B read/write and #$1f ; get bit 4-0 (PB4-PB0) eor #$1f rts ; Read joystick 3 joy3: lda #$00 ; via port B read/write sta VIA1_PRB ; (output zero at PB7) lda VIA1_PRB ; via port B read/write and #$0f ; get bit 3-0 (PB3-PB0) sta tmp1 ; joy 4 directions lda VIA1_PRB ; via port B read/write and #%00100000 ; get bit 5 (PB5) lsr ora tmp1 eor #$1f ldx #0 rts
wagiminator/C64-Collection
3,838
C64_xu1541/software/tools/cc65-2.13.2/libsrc/vic20/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 "vic20.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,780
C64_xu1541/software/tools/cc65-2.13.2/libsrc/vic20/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 "vic20.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,615
C64_xu1541/software/tools/cc65-2.13.2/libsrc/vic20/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 "vic20.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,144
C64_xu1541/software/tools/cc65-2.13.2/libsrc/vic20/cgetc.s
; ; Ullrich von Bassewitz, 06.08.1998 ; ; char cgetc (void); ; .export _cgetc .import cursor .include "vic20.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
3,031
C64_xu1541/software/tools/cc65-2.13.2/libsrc/serial/ser_load.s
; ; Ullrich von Bassewitz, 2006-06-05 ; ; unsigned char __fastcall__ ser_load_driver (const char* name) ; /* Load a serial driver and return an error code */ .include "ser-kernel.inc" .include "ser-error.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 _ser_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 _ser_drv ora _ser_drv+1 beq @L1 jsr _ser_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 ser_install(). ; Res = ser_install (ctrl.module); lda ctrl + MOD_CTRL::MODULE ldx ctrl + MOD_CTRL::MODULE+1 jsr _ser_install ; If ser_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 _ser_drv ldx _ser_drv+1 jsr _mod_free ; Free the driver memory jsr _ser_clear_ptr ; Clear ser_drv pla ; Restore the error code ldx #0 ; We must return an int @L2: rts ; Done ; Open or mod_load failed. Return an error code. @L3: lda #<SER_ERR_CANNOT_LOAD ldx #>SER_ERR_CANNOT_LOAD rts .endproc
wagiminator/C64-Collection
2,905
C64_xu1541/software/tools/cc65-2.13.2/libsrc/serial/ser-kernel.s
; ; Ullrich von Bassewitz, 2003-04-15 ; ; Common functions of the serial drivers ; .import return0 .importzp ptr1 .interruptor ser_irq, 29 ; Export as high priority IRQ handler .include "ser-kernel.inc" .include "ser-error.inc" ;---------------------------------------------------------------------------- ; Variables .bss _ser_drv: .res 2 ; Pointer to driver ; Jump table for the driver functions. .data ser_vectors: ser_install: jmp return0 ser_uninstall: jmp return0 ser_open: jmp return0 ser_close: jmp return0 ser_get: jmp return0 ser_put: jmp return0 ser_status: jmp return0 ser_ioctl: jmp return0 ser_irq: .byte $60, $00, $00 ; RTS plus two dummy bytes ; Driver header signature .rodata ser_sig: .byte $73, $65, $72, SER_API_VERSION ; "ser", version .code ;---------------------------------------------------------------------------- ; unsigned char __fastcall__ ser_install (void* driver); ; /* Install the driver once it is loaded */ _ser_install: sta _ser_drv sta ptr1 stx _ser_drv+1 stx ptr1+1 ; Check the driver signature ldy #.sizeof(ser_sig)-1 @L0: lda (ptr1),y cmp ser_sig,y bne inv_drv dey bpl @L0 ; Copy the jump vectors ldy #SER_HDR::JUMPTAB ldx #0 @L1: inx ; Skip the JMP opcode jsr copy ; Copy one byte jsr copy ; Copy one byte cpy #(SER_HDR::JUMPTAB + .sizeof(SER_HDR::JUMPTAB)) bne @L1 jsr ser_install ; Call driver install routine ldy ser_irq+2 ; Check high byte of IRQ vector beq @L2 ; Jump if vector invalid ldy #$4C ; Jump opcode sty ser_irq ; Activate IRQ routine @L2: rts ; Driver signature invalid inv_drv: lda #SER_ERR_INV_DRIVER ldx #0 rts ; Copy one byte from the jump vectors copy: lda (ptr1),y sta ser_vectors,x iny inx rts ;---------------------------------------------------------------------------- ; unsigned char __fastcall__ ser_uninstall (void); ; /* Uninstall the currently loaded driver and return an error code. ; * Note: This call does not free allocated memory. ; */ _ser_uninstall: jsr ser_uninstall ; Call driver routine lda #$60 ; RTS opcode sta ser_irq ; Disable IRQ entry point _ser_clear_ptr: ; External entry point lda #0 sta _ser_drv sta _ser_drv+1 ; Clear the driver pointer tax rts ; Return zero
wagiminator/C64-Collection
1,291
C64_xu1541/software/tools/cc65-2.13.2/libsrc/nes/color.s
; ; Written by Groepaz/Hitmen <groepaz@gmx.net> ; Cleanup by Ullrich von Bassewitz <uz@cc65.org> ; ; unsigned char __fastcall__ textcolor (unsigned char color); ; unsigned char __fastcall__ bgcolor (unsigned char color); ; unsigned char __fastcall__ bordercolor (unsigned char color); ; .export _textcolor, _bgcolor, _bordercolor .import return0, ppubuf_put .include "nes.inc" _textcolor = return0 _bordercolor = return0 .proc _bgcolor tax lda BGCOLOR ; get old value stx BGCOLOR ; set new value pha lda colors,x pha ldy #$3F ldx #0 jsr ppubuf_put pla pha ldy #$3F ldx #4 jsr ppubuf_put pla pha ldy #$3F ldx #8 jsr ppubuf_put pla ldy #$3F ldx #12 jsr ppubuf_put pla rts .endproc .rodata colors: .byte $0f ; 0 black .byte $3d ; 1 white .byte $04 ; 2 red .byte $3b ; 3 cyan .byte $14 ; 4 violett .byte $1a ; 5 green .byte $01 ; 6 blue .byte $38 ; 7 yellow .byte $18 ; 8 orange .byte $08 ; 9 brown .byte $35 ; a light red .byte $2d ; b dark grey .byte $10 ; c middle grey .byte $2b ; d light green .byte $22 ; e light blue .byte $3d ; f light gray
wagiminator/C64-Collection
5,387
C64_xu1541/software/tools/cc65-2.13.2/libsrc/nes/crt0.s
; ; Startup code for cc65 (NES version) ; ; by Groepaz/Hitmen <groepaz@gmx.net> ; based on code by Ullrich von Bassewitz <uz@cc65.org> ; .export _exit .export __STARTUP__ : absolute = 1 ; Mark as startup .import initlib, donelib, callmain .import push0, _main, zerobss, copydata .import ppubuf_flush ; Linker generated symbols .import __RAM_START__, __RAM_SIZE__ .import __SRAM_START__, __SRAM_SIZE__ .import __ROM0_START__, __ROM0_SIZE__ .import __STARTUP_LOAD__,__STARTUP_RUN__, __STARTUP_SIZE__ .import __CODE_LOAD__,__CODE_RUN__, __CODE_SIZE__ .import __RODATA_LOAD__,__RODATA_RUN__, __RODATA_SIZE__ .include "zeropage.inc" .include "nes.inc" ; ------------------------------------------------------------------------ ; 16 bytes INES header .segment "HEADER" ; +--------+------+------------------------------------------+ ; | Offset | Size | Content(s) | ; +--------+------+------------------------------------------+ ; | 0 | 3 | 'NES' | ; | 3 | 1 | $1A | ; | 4 | 1 | 16K PRG-ROM page count | ; | 5 | 1 | 8K CHR-ROM page count | ; | 6 | 1 | ROM Control Byte #1 | ; | | | %####vTsM | ; | | | | ||||+- 0=Horizontal mirroring | ; | | | | |||| 1=Vertical mirroring | ; | | | | |||+-- 1=SRAM enabled | ; | | | | ||+--- 1=512-byte trainer present | ; | | | | |+---- 1=Four-screen mirroring | ; | | | | | | ; | | | +--+----- Mapper # (lower 4-bits) | ; | 7 | 1 | ROM Control Byte #2 | ; | | | %####0000 | ; | | | | | | ; | | | +--+----- Mapper # (upper 4-bits) | ; | 8-15 | 8 | $00 | ; | 16-.. | | Actual 16K PRG-ROM pages (in linear | ; | ... | | order). If a trainer exists, it precedes | ; | ... | | the first PRG-ROM page. | ; | ..-EOF | | CHR-ROM pages (in ascending order). | ; +--------+------+------------------------------------------+ .byte $4e,$45,$53,$1a ; "NES"^Z .byte 2 ; ines prg - Specifies the number of 16k prg banks. .byte 1 ; ines chr - Specifies the number of 8k chr banks. .byte %00000011 ; ines mir - Specifies VRAM mirroring of the banks. .byte %00000000 ; ines map - Specifies the NES mapper used. .byte 0,0,0,0,0,0,0,0 ; 8 zeroes ; ------------------------------------------------------------------------ ; Place the startup code in a special segment. .segment "STARTUP" start: ; setup the CPU and System-IRQ sei cld ldx #0 stx VBLANK_FLAG stx ringread stx ringwrite stx ringcount txs lda #$20 @l: sta ringbuff,x sta ringbuff+$0100,x sta ringbuff+$0200,x inx bne @l ; Clear the BSS data jsr zerobss ; initialize data jsr copydata ; setup the stack lda #<(__SRAM_START__ + __SRAM_SIZE__) sta sp lda #>(__SRAM_START__ + __SRAM_SIZE__) sta sp+1 ; Set argument stack ptr ; Call module constructors jsr initlib ; Push arguments and call main() jsr callmain ; Call module destructors. This is also the _exit entry. _exit: jsr donelib ; Run module destructors ; Reset the NES jmp start ; ------------------------------------------------------------------------ ; System V-Blank Interupt ; updates PPU Memory (buffered) ; updates VBLANK_FLAG and tickcount ; ------------------------------------------------------------------------ nmi: pha tya pha txa pha lda #1 sta VBLANK_FLAG inc tickcount bne @s inc tickcount+1 @s: jsr ppubuf_flush ; reset the video counter lda #$20 sta PPU_VRAM_ADDR2 lda #$00 sta PPU_VRAM_ADDR2 ; reset scrolling sta PPU_VRAM_ADDR1 sta PPU_VRAM_ADDR1 pla tax pla tay pla ; Interrupt exit irq2: irq1: timerirq: irq: rti ; ------------------------------------------------------------------------ ; hardware vectors ; ------------------------------------------------------------------------ .segment "VECTORS" .word irq2 ; $fff4 ? .word irq1 ; $fff6 ? .word timerirq ; $fff8 ? .word nmi ; $fffa vblank nmi .word start ; $fffc reset .word irq ; $fffe irq / brk ; ------------------------------------------------------------------------ ; character data ; ------------------------------------------------------------------------ .segment "CHARS" .include "neschar.inc"
wagiminator/C64-Collection
2,113
C64_xu1541/software/tools/cc65-2.13.2/libsrc/nes/ppubuf.s
; ; Written by Groepaz/Hitmen <groepaz@gmx.net> ; Cleanup by Ullrich von Bassewitz <uz@cc65.org> ; .export ppubuf_waitempty .export ppubuf_wait .export ppubuf_put .export ppubuf_flush .include "nes.inc" .code ; ------------------------------------------------------------------------ ; ppubuf_waitempty ; Wait until buffer is empty .proc ppubuf_waitempty @wait: lda ringcount bne @wait rts .endproc ; ------------------------------------------------------------------------ ; ppubuf_wait ; Wait until buffer is full .proc ppubuf_wait lda #$ff ; (($0100/3)*1) @wait: cmp ringcount beq @wait rts .endproc ; ------------------------------------------------------------------------ ; Put a PPU-Memory write to buffer ; called from main program (not necessary when in vblank irq) .proc ppubuf_put sta ppuval sty ppuhi stx ppulo jsr ppubuf_wait ; wait if buffer is full ldy ringwrite lda ppuhi sta ringbuff,y lda ppulo sta ringbuff+$0100,y lda ppuval sta ringbuff+$0200,y iny sty ringwrite inc ringcount rts .endproc ; ------------------------------------------------------------------------ ; Flush PPU-Memory write buffer ; called from vblank interupt .proc ppubuf_flush ldy ringcount bne @doloop rts @doloop: ldx ringread lda #$0e sta temp @loop: .repeat 5 lda ringbuff,x sta $2006 lda ringbuff+$0100,x sta $2006 lda ringbuff+$0200,x sta $2007 inx dey beq @end .endrepeat dec temp bne @loop @end: stx ringread sty ringcount rts .endproc ; ------------------------------------------------------------------------ ; Data .bss temp: .res 1
wagiminator/C64-Collection
5,964
C64_xu1541/software/tools/cc65-2.13.2/libsrc/nes/ppu.s
; ; Written by Groepaz/Hitmen <groepaz@gmx.net> ; Cleanup by Ullrich von Bassewitz <uz@cc65.org> ; .export ppuinit .export paletteinit .include "nes.inc" ;+---------+----------------------------------------------------------+ ;| $2000 | PPU Control Register #1 (W) | ;| | | ;| | D7: Execute NMI on VBlank | ;| | 0 = Disabled | ;| | 1 = Enabled | ;| | D6: PPU Master/Slave Selection --+ | ;| | 0 = Master +-- UNUSED | ;| | 1 = Slave --+ | ;| | D5: Sprite Size | ;| | 0 = 8x8 | ;| | 1 = 8x16 | ;| | D4: Background Pattern Table Address | ;| | 0 = $0000 (VRAM) | ;| | 1 = $1000 (VRAM) | ;| | D3: Sprite Pattern Table Address | ;| | 0 = $0000 (VRAM) | ;| | 1 = $1000 (VRAM) | ;| | D2: PPU Address Increment | ;| | 0 = Increment by 1 | ;| | 1 = Increment by 32 | ;| | D1-D0: Name Table Address | ;| | 00 = $2000 (VRAM) | ;| | 01 = $2400 (VRAM) | ;| | 10 = $2800 (VRAM) | ;| | 11 = $2C00 (VRAM) | ;+---------+----------------------------------------------------------+ ;+---------+----------------------------------------------------------+ ;| $2001 | PPU Control Register #2 (W) | ;| | | ;| | D7-D5: Full Background Colour (when D0 == 1) | ;| | 000 = None +------------+ | ;| | 001 = Green | NOTE: Do not use more | ;| | 010 = Blue | than one type | ;| | 100 = Red +------------+ | ;| | D7-D5: Colour Intensity (when D0 == 0) | ;| | 000 = None +--+ | ;| | 001 = Intensify green | NOTE: Do not use more | ;| | 010 = Intensify blue | than one type | ;| | 100 = Intensify red +--+ | ;| | D4: Sprite Visibility | ;| | 0 = Sprites not displayed | ;| | 1 = Sprites visible | ;| | D3: Background Visibility | ;| | 0 = Background not displayed | ;| | 1 = Background visible | ;| | D2: Sprite Clipping | ;| | 0 = Sprites invisible in left 8-pixel column | ;| | 1 = No clipping | ;| | D1: Background Clipping | ;| | 0 = BG invisible in left 8-pixel column | ;| | 1 = No clipping | ;| | D0: Display Type | ;| | 0 = Colour display | ;| | 1 = Monochrome display | ;+---------+----------------------------------------------------------+ ;----------------------------------------------------------------------------- .proc ppuinit lda #%10101000 sta PPU_CTRL1 lda #%00011110 sta PPU_CTRL2 ; Wait for vblank @wait: lda PPU_STATUS bpl @wait ; reset scrolling lda #0 sta PPU_VRAM_ADDR1 sta PPU_VRAM_ADDR1 ; Make all sprites invisible lda #$00 ldy #$f0 sta PPU_SPR_ADDR ldx #$40 @loop: sty PPU_SPR_IO sta PPU_SPR_IO sta PPU_SPR_IO sty PPU_SPR_IO dex bne @loop rts .endproc ;----------------------------------------------------------------------------- .proc paletteinit ; Wait for v-blank @wait: lda PPU_STATUS bpl @wait lda #$3F sta PPU_VRAM_ADDR2 lda #$00 sta PPU_VRAM_ADDR2 ldx #0 @loop: lda paldata,x sta PPU_VRAM_IO inx cpx #(16*2) bne @loop rts .endproc ;----------------------------------------------------------------------------- .rodata paldata: .repeat 2 .byte $0f ; 0 black .byte $14 ; 4 violett .byte $3b ; 3 cyan .byte $3d ; 1 white .byte $38 ; 7 yellow .byte $2d ; b dark grey .byte $22 ; e light blue .byte $04 ; 2 red .byte $18 ; 8 orange .byte $08 ; 9 brown .byte $35 ; a light red .byte $01 ; 6 blue .byte $10 ; c middle grey .byte $2b ; d light green .byte $3d ; f light gray .byte $1a ; 5 green .endrepeat
wagiminator/C64-Collection
1,951
C64_xu1541/software/tools/cc65-2.13.2/libsrc/nes/cputc.s
; ; Written by Groepaz/Hitmen <groepaz@gmx.net> ; Cleanup by Ullrich von Bassewitz <uz@cc65.org> ; ; void cputcxy (unsigned char x, unsigned char y, char c); ; void cputc (char c); ; .export _cputcxy, _cputc, cputdirect, putchar .export newline .constructor conioinit .import popa, _gotoxy .import ppuinit, paletteinit, ppubuf_put .import setcursor .importzp tmp3,tmp4 .include "nes.inc" ;----------------------------------------------------------------------------- .code _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 #$0d ; CR? bne L1 lda #0 sta CURS_X beq plot ; Recalculate pointers L1: cmp #$0a ; LF? beq newline ; Recalculate pointers ; Printable char of some sort cputdirect: jsr putchar ; Write the character to the screen ; Advance cursor position advance: ldy CURS_X iny cpy #xsize bne L3 inc CURS_Y ; new line ldy #0 ; + cr L3: sty CURS_X jmp plot newline: inc CURS_Y ; Set cursor position, calculate RAM pointers plot: ldy CURS_X ldx CURS_Y jmp setcursor ; 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 SCREEN_PTR+1 ldx SCREEN_PTR jmp ppubuf_put ;----------------------------------------------------------------------------- ; Initialize the conio subsystem. Code goes into the INIT segment, which may ; be reused after startup. .segment "INIT" conioinit: jsr ppuinit jsr paletteinit lda #0 sta RVS sta CURS_X sta CURS_Y jmp plot ; Set the cursor
wagiminator/C64-Collection
1,365
C64_xu1541/software/tools/cc65-2.13.2/libsrc/nes/clrscr.s
; ; Written by Groepaz/Hitmen <groepaz@gmx.net> ; Cleanup by Ullrich von Bassewitz <uz@cc65.org> ; ; void clrscr (void); ; .export _clrscr .import ppubuf_waitempty .include "nes.inc" .proc _clrscr ; wait until all console data has been written jsr ppubuf_waitempty ; wait for vblank lda #0 sta VBLANK_FLAG @w2: lda VBLANK_FLAG beq @w2 ; switch screen off lda #%00000000 sta PPU_CTRL2 ; Set start address to Name Table #1 lda #$20 sta PPU_VRAM_ADDR2 lda #$00 sta PPU_VRAM_ADDR2 ; Clear Name Table #1 lda #' ' ldx #$f0 ; 4*$f0=$03c0 beg: sta PPU_VRAM_IO sta PPU_VRAM_IO sta PPU_VRAM_IO sta PPU_VRAM_IO dex bne beg lda #$23 ; sta PPU_VRAM_ADDR2 ; Set start address to PPU address $23C0 lda #$C0 ; (1st attribute table) sta PPU_VRAM_ADDR2 ldx #$00 lll: lda #$00 ; Write attribute table value and auto increment sta PPU_VRAM_IO ; to next address inx cpx #$40 bne lll ; switch screen on again lda #%00011110 sta PPU_CTRL2 rts .endproc
wagiminator/C64-Collection
2,442
C64_xu1541/software/tools/cc65-2.13.2/libsrc/nes/nes-stdjoy.s
; ; Standard joypad driver for the NES. May be used multiple times when ; linked to the statically application. ; ; Ullrich von Bassewitz, 2003-05-02 ; Stefan Haubenthal, 2004-10-05 ; .include "zeropage.inc" .include "joy-kernel.inc" .include "joy-error.inc" .include "nes.inc" ; ------------------------------------------------------------------------ ; 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 ; JOY_UP .byte $20 ; JOY_DOWN .byte $40 ; JOY_LEFT .byte $80 ; JOY_RIGHT .byte $01 ; JOY_FIRE (A) .byte $02 ; JOY_FIRE2 (B) .byte $04 ; (Select) .byte $08 ; (Start) ; Jump table. .addr INSTALL .addr UNINSTALL .addr COUNT .addr READJOY .addr 0 ; IRQ entry unused ; ------------------------------------------------------------------------ ; Constants JOY_COUNT = 2 ; 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 #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: and #$01 ; Fix joystick number tay ; Joystick number (0,1) into Y lda #1 sta APU_PAD1,y lda #0 sta APU_PAD1,y ; Read joystick ldx #8 @Loop: lda APU_PAD1,y ror a ror tmp1 dex bne @Loop lda tmp1 ; ldx #$00 ; X implicitly fixed rts
wagiminator/C64-Collection
6,268
C64_xu1541/software/tools/cc65-2.13.2/libsrc/nes/ctype.s
; ; Ullrich von Bassewitz, 02.06.1998 ; ; Character specification table. ; ; 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: .repeat 2 ; 2 times for normal and inverted .byte $10 ; 0/00 ___ctrl_@___ .byte $10 ; 1/01 ___ctrl_A___ .byte $10 ; 2/02 ___ctrl_B___ .byte $10 ; 3/03 ___ctrl_C___ .byte $10 ; 4/04 ___ctrl_D___ .byte $10 ; 5/05 ___ctrl_E___ .byte $10 ; 6/06 ___ctrl_F___ .byte $10 ; 7/07 ___ctrl_G___ .byte $10 ; 8/08 ___ctrl_H___ .byte $D0 ; 9/09 ___ctrl_I___ .byte $50 ; 10/0a ___ctrl_J___ .byte $50 ; 11/0b ___ctrl_K___ .byte $50 ; 12/0c ___ctrl_L___ .byte $50 ; 13/0d ___ctrl_M___ .byte $10 ; 14/0e ___ctrl_N___ .byte $10 ; 15/0f ___ctrl_O___ .byte $10 ; 16/10 ___ctrl_P___ .byte $10 ; 17/11 ___ctrl_Q___ .byte $10 ; 18/12 ___ctrl_R___ .byte $10 ; 19/13 ___ctrl_S___ .byte $10 ; 20/14 ___ctrl_T___ .byte $10 ; 21/15 ___ctrl_U___ .byte $10 ; 22/16 ___ctrl_V___ .byte $10 ; 23/17 ___ctrl_W___ .byte $10 ; 24/18 ___ctrl_X___ .byte $10 ; 25/19 ___ctrl_Y___ .byte $10 ; 26/1a ___ctrl_Z___ .byte $10 ; 27/1b ___ctrl_[___ .byte $10 ; 28/1c ___ctrl_\___ .byte $10 ; 29/1d ___ctrl_]___ .byte $10 ; 30/1e ___ctrl_^___ .byte $10 ; 31/1f ___ctrl_____ .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 ___grave___ .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 _____{_____ .byte $00 ; 124/7c _____|_____ .byte $00 ; 125/7d _____}_____ .byte $00 ; 126/7e _____~_____ .byte $40 ; 127/7f ____DEL____ .endrepeat
wagiminator/C64-Collection
1,518
C64_xu1541/software/tools/cc65-2.13.2/libsrc/runtime/asr.s
; ; Ullrich von Bassewitz, 2004-06-30 ; ; CC65 runtime: right shift support for ints ; ; Note: The standard declares a shift count that is negative or >= the ; bitcount of the shifted type for undefined behaviour. ; ; Note^2: The compiler knowns about the register/zero page usage of this ; function, so you need to change the compiler source if you change it! ; .export tosasrax .import popax .importzp tmp1 tosasrax: and #$0F ; Bring the shift count into a valid range sta tmp1 ; Save it jsr popax ; Get the left hand operand ldy tmp1 ; Get shift count beq L9 ; Bail out if shift count zero cpy #8 ; Shift count 8 or greater? bcc L1 ; Jump if not ; Shift count is greater 8. The carry is set when we enter here. tya sbc #8 tay ; Adjust shift count txa ldx #$00 ; Shift by 8 bits cmp #$00 ; Test sign bit bpl L1 dex ; Make X the correct sign extended value ; Save the high byte so we can shift it L1: stx tmp1 ; Save high byte jmp L3 ; Do the actual shift L2: cpx #$80 ; Copy bit 15 into the carry ror tmp1 ror a L3: dey bpl L2 ; Done with shift ldx tmp1 L9: rts
wagiminator/C64-Collection
2,951
C64_xu1541/software/tools/cc65-2.13.2/libsrc/runtime/stkchk.s
; ; Ullrich von Bassewitz, 19.03.2001 ; ; Stack checking code. These are actually two routines, one to check the C ; stack, and the other one to check the 6502 hardware stack. ; For performance reasons (to avoid having to pass a parameter), the compiler ; calls the cstkchk routine *after* allocating space on the stack. So the ; stackpointer may already be invalid if this routine is called. In addition ; to that, pushs and pops that are needed for expression evaluation are not ; checked (this would be way too much overhead). As a consequence we will ; operate using a safety area at the stack bottom. Once the stack reaches this ; safety area, we consider it an overflow, even if the stack is still inside ; its' bounds. ; .export stkchk, cstkchk .constructor initstkchk, 25 .import __STACKSIZE__ ; Linker defined .import pusha0, _exit .importzp sp ; Use macros for better readability .macpack generic .macpack cpu ; ---------------------------------------------------------------------------- ; Initialization code. This is a constructor, so it is called on startup if ; the linker has detected references to this module. .segment "INIT" .proc initstkchk lda sp sta initialsp sub #<__STACKSIZE__ sta lowwater lda sp+1 sta initialsp+1 sbc #>__STACKSIZE__ .if (.cpu .bitand ::CPU_ISET_65SC02) ina ; Add 256 bytes safety area .else add #1 ; Add 256 bytes safety area .endif sta lowwater+1 rts .endproc ; ---------------------------------------------------------------------------- ; 6502 stack checking routine. Does not need to save any registers. ; Safety zone for the hardware stack is 12 bytes. .code stkchk: tsx cpx #12 bcc Fail ; Jump on stack overflow rts ; Return if ok ; ---------------------------------------------------------------------------- ; C stack checking routine. Does not need to save any registers. .code cstkchk: ; Check the high byte of the software stack @L0: lda lowwater+1 cmp sp+1 bcs @L1 rts ; Check low byte @L1: bne CStackOverflow lda lowwater cmp sp bcs CStackOverflow Done: rts ; We have a C stack overflow. Set the stack pointer to the initial value, so ; we can continue without worrying about stack issues. CStackOverflow: lda initialsp sta sp lda initialsp+1 sta sp+1 ; Generic abort entry. We should output a diagnostic here, but this is ; difficult, since we're operating at a lower level here. Fail: lda #4 ldx #0 jmp _exit ; ---------------------------------------------------------------------------- ; Data .bss ; Initial stack pointer value. Stack is reset to this in case of overflows to ; allow program exit processing. initialsp: .word 0 ; Stack low water mark. lowwater: .word 0
wagiminator/C64-Collection
2,095
C64_xu1541/software/tools/cc65-2.13.2/libsrc/runtime/condes.s
; ; Ullrich von Bassewitz, 20.11.2000 ; ; CC65 runtime: Support for calling module constructors/destructors ; ; The condes routine must be called with the table address in a/x and the ; size of the table (which must not be zero!) in y. The current implementation ; limits the table size to 254 bytes (127 vectors) but this shouldn't be ; problem for now and may be changed later. ; ; libinit and libdone call condes with the predefined module constructor and ; destructor tables, they must be called from the platform specific startup ; code. .export initlib, donelib, condes .import __CONSTRUCTOR_TABLE__, __CONSTRUCTOR_COUNT__ .import __DESTRUCTOR_TABLE__, __DESTRUCTOR_COUNT__ .macpack cpu ; -------------------------------------------------------------------------- ; Initialize library modules .segment "INIT" .proc initlib ldy #<(__CONSTRUCTOR_COUNT__*2) beq exit lda #<__CONSTRUCTOR_TABLE__ ldx #>__CONSTRUCTOR_TABLE__ jmp condes exit: rts .endproc ; -------------------------------------------------------------------------- ; Cleanup library modules .code .proc donelib ldy #<(__DESTRUCTOR_COUNT__*2) beq exit lda #<__DESTRUCTOR_TABLE__ ldx #>__DESTRUCTOR_TABLE__ jmp condes exit: rts .endproc ; -------------------------------------------------------------------------- ; Generic table call handler. The code uses self modifying code and goes ; into the data segment for this reason. ; NOTE: The routine must not be called if the table is empty! .data .proc condes sta fetch1+1 stx fetch1+2 sta fetch2+1 stx fetch2+2 loop: dey fetch1: lda $FFFF,y ; Patched at runtime sta jmpvec+2 dey fetch2: lda $FFFF,y ; Patched at runtime sta jmpvec+1 sty index+1 jmpvec: jsr $FFFF ; Patched at runtime index: ldy #$FF ; Patched at runtime bne loop rts .endproc
wagiminator/C64-Collection
1,069
C64_xu1541/software/tools/cc65-2.13.2/libsrc/runtime/lshl.s
; ; Ullrich von Bassewitz, 2004-06-30 ; ; CC65 runtime: left shift support for long and unsigned long ; ; Note: The standard declares a shift count that is negative or >= the ; bitcount of the shifted type for undefined behaviour. ; ; Note^2: The compiler knowns about the register/zero page usage of this ; function, so you need to change the compiler source if you change it! ; .export tosasleax, tosshleax .import popeax .importzp sreg, tmp1 tosshleax: tosasleax: and #$1F ; Bring the shift count into a valid range sta tmp1 ; Save it jsr popeax ; Get the left hand operand ldy tmp1 ; Get shift count beq L9 ; Bail out if shift count zero stx tmp1 ; Save byte 1 ; Do the actual shift. Faster solutions are possible but need a lot more code. L2: asl a rol tmp1 rol sreg rol sreg+1 dey bne L2 ; Shift done ldx tmp1 L9: rts
wagiminator/C64-Collection
1,734
C64_xu1541/software/tools/cc65-2.13.2/libsrc/runtime/ludiv.s
; ; Ullrich von Bassewitz, 17.08.1998 ; ; CC65 runtime: division for long unsigned ints ; .export tosudiv0ax, tosudiveax, getlop, udiv32 .import addysp1 .importzp sp, sreg, tmp3, tmp4, ptr1, ptr2, ptr3, ptr4 tosudiv0ax: ldy #$00 sty sreg sty sreg+1 tosudiveax: jsr getlop ; Get the paramameters jsr udiv32 ; Do the division lda ptr1 ; Result is in ptr1:sreg ldx ptr1+1 rts ; Pop the parameters for the long division and put it into the relevant ; memory cells. Called from the signed divisions also. getlop: sta ptr3 ; Put right operand in place stx ptr3+1 lda sreg sta ptr4 lda sreg+1 sta ptr4+1 ldy #0 ; Put left operand in place lda (sp),y sta ptr1 iny lda (sp),y sta ptr1+1 iny lda (sp),y sta sreg iny lda (sp),y sta sreg+1 jmp addysp1 ; Drop parameters ; Do (ptr1:sreg) / (ptr3:ptr4) --> (ptr1:sreg), remainder in (ptr2:tmp3:tmp4) ; This is also the entry point for the signed division udiv32: lda #0 sta ptr2+1 sta tmp3 sta tmp4 ; sta ptr1+1 ldy #32 L0: asl ptr1 rol ptr1+1 rol sreg rol sreg+1 rol a rol ptr2+1 rol tmp3 rol tmp4 ; Do a subtraction. we do not have enough space to store the intermediate ; result, so we may have to do the subtraction twice. pha cmp ptr3 lda ptr2+1 sbc ptr3+1 lda tmp3 sbc ptr4 lda tmp4 sbc ptr4+1 bcc L1 ; Overflow, do the subtraction again, this time store the result sta tmp4 ; We have the high byte already pla sbc ptr3 ; byte 0 pha lda ptr2+1 sbc ptr3+1 sta ptr2+1 ; byte 1 lda tmp3 sbc ptr4 sta tmp3 ; byte 2 inc ptr1 ; Set result bit L1: pla dey bne L0 sta ptr2 rts
wagiminator/C64-Collection
1,509
C64_xu1541/software/tools/cc65-2.13.2/libsrc/runtime/mul8.s
; ; Ullrich von Bassewitz, 2009-08-17 ; ; CC65 runtime: multiplication for ints. Short versions. ; .export tosumula0, tosmula0 .export mul8x16, mul8x16a .import popsreg .importzp sreg, ptr4 ;--------------------------------------------------------------------------- ; 8x16 routine with external entry points used by the 16x16 routine in mul.s tosmula0: tosumula0: sta ptr4 mul8x16:jsr popsreg ; Get left operand lda #0 ; Clear byte 1 ldy #8 ; Number of bits ldx sreg+1 ; Get into register for speed beq mul8x8 ; Do 8x8 multiplication if high byte zero mul8x16a: sta ptr4+1 ; Clear byte 2 lsr ptr4 ; Get first bit into carry @L0: bcc @L1 clc adc sreg pha txa ; hi byte of left op adc ptr4+1 sta ptr4+1 pla @L1: ror ptr4+1 ror a ror ptr4 dey bne @L0 tax lda ptr4 ; Load the result rts ;--------------------------------------------------------------------------- ; 8x8 multiplication routine mul8x8: lsr ptr4 ; Get first bit into carry @L0: bcc @L1 clc adc sreg @L1: ror ror ptr4 dey bne @L0 tax lda ptr4 ; Load the result rts ; Done
wagiminator/C64-Collection
1,045
C64_xu1541/software/tools/cc65-2.13.2/libsrc/runtime/toslong.s
; ; Ullrich von Bassewitz, 25.10.2000 ; ; CC65 runtime: Convert tos from int to long ; .export tosulong, toslong .import decsp2 .importzp sp .macpack cpu ; Convert TOS from int to long tosulong: pha jsr decsp2 ; Make room ldy #2 lda (sp),y .if (.cpu .bitand CPU_ISET_65SC02) sta (sp) ; 65C02 version iny ; Y = 3 .else ldy #0 sta (sp),y ldy #3 .endif lda (sp),y toslong1: ldy #1 sta (sp),y lda #0 ; Zero extend toslong2: iny sta (sp),y iny sta (sp),y pla rts toslong: pha jsr decsp2 ; Make room ldy #2 lda (sp),y .if (.cpu .bitand CPU_ISET_65SC02) sta (sp) ; 65C02 version iny ; Y = 3 .else ldy #0 sta (sp),y ldy #3 .endif lda (sp),y bpl toslong1 ; Jump if positive, high word is zero ldy #1 sta (sp),y lda #$FF bne toslong2 ; Branch always
wagiminator/C64-Collection
1,270
C64_xu1541/software/tools/cc65-2.13.2/libsrc/runtime/udiv.s
; ; Ullrich von Bassewitz, 07.08.1998 ; ; CC65 runtime: division for unsigned ints ; .export tosudiva0, tosudivax, udiv16 .import popsreg .importzp sreg, ptr1, ptr4 tosudiva0: ldx #$00 ; Clear high byte tosudivax: sta ptr4 stx ptr4+1 ; Save right operand jsr popsreg ; Get left operand ; Do the division jsr udiv16 ; Result is in sreg, remainder in ptr1 lda sreg ldx sreg+1 rts ;--------------------------------------------------------------------------- ; 16by16 division. Divide sreg by ptr4. Result is in sreg, remainder in ptr1 ; (see mult-div.s from "The Fridge"). ; This is also the entry point for the signed division udiv16: lda #0 sta ptr1+1 ldy #16 ldx sreg+1 beq udiv16by8a L0: asl sreg rol sreg+1 rol a rol ptr1+1 pha cmp ptr4 lda ptr1+1 sbc ptr4+1 bcc L1 sta ptr1+1 pla sbc ptr4 pha inc sreg L1: pla dey bne L0 sta ptr1 rts ;--------------------------------------------------------------------------- ; 16by8 division udiv16by8a: @L0: asl sreg rol sreg+1 rol a bcs @L1 cmp ptr4 bcc @L2 @L1: sbc ptr4 inc sreg @L2: dey bne @L0 sta ptr1 rts
wagiminator/C64-Collection
1,054
C64_xu1541/software/tools/cc65-2.13.2/libsrc/runtime/lshr.s
; ; Ullrich von Bassewitz, 2004-06-30 ; ; CC65 runtime: right shift support for unsigned longs ; ; Note: The standard declares a shift count that is negative or >= the ; bitcount of the shifted type for undefined behaviour. ; ; Note^2: The compiler knowns about the register/zero page usage of this ; function, so you need to change the compiler source if you change it! ; .export tosshreax .import popeax .importzp sreg, tmp1 tosshreax: and #$1F ; Bring the shift count into a valid range sta tmp1 ; Save it jsr popeax ; Get the left hand operand ldy tmp1 ; Get shift count beq L9 ; Bail out if shift count zero stx tmp1 ; Save byte 1 ; Do the actual shift. Faster solutions are possible but need a lot more code. L2: lsr sreg+1 ror sreg ror tmp1 ror a dey bne L2 ; Shift done ldx tmp1 L9: rts
wagiminator/C64-Collection
1,382
C64_xu1541/software/tools/cc65-2.13.2/libsrc/runtime/shr.s
; ; Ullrich von Bassewitz, 2004-06-30 ; ; CC65 runtime: right shift support for unsigneds ; ; Note: The standard declares a shift count that is negative or >= the ; bitcount of the shifted type for undefined behaviour. ; ; Note^2: The compiler knowns about the register/zero page usage of this ; function, so you need to change the compiler source if you change it! ; .export tosshrax .import popax .importzp tmp1 tosshrax: and #$0F ; Bring the shift count into a valid range sta tmp1 ; Save it jsr popax ; Get the left hand operand ldy tmp1 ; Get shift count beq L9 ; Bail out if shift count zero cpy #8 ; Shift count 8 or greater? bcc L3 ; Jump if not ; Shift count is greater 7. The carry is set when we enter here. tya sbc #8 tay ; Adjust shift count txa ldx #$00 ; Shift by 8 bits beq L2 ; Branch always L1: lsr a L2: dey bpl L1 rts ; Shift count is less than 8. Do the actual shift. L3: stx tmp1 ; Save high byte of lhs L4: lsr tmp1 ror a dey bne L4 ; Done with shift ldx tmp1 L9: rts
wagiminator/C64-Collection
1,040
C64_xu1541/software/tools/cc65-2.13.2/libsrc/runtime/lmod.s
; ; Ullrich von Bassewitz, 07.08.1998 ; ; CC65 runtime: modulo operation for long signed ints ; ; When negating values, we will ignore the possibility here, that one of the ; values if $8000, in which case the negate will fail. .export tosmod0ax, tosmodeax .import poplsargs, udiv32, negeax .importzp sreg, ptr1, ptr2, tmp1, tmp3, tmp4 tosmod0ax: ldy #$00 sty sreg sty sreg+1 tosmodeax: jsr poplsargs ; Get arguments from stack, adjust sign jsr udiv32 ; Do the division, remainder is in (ptr2:tmp3:tmp4) ; Load the result lda ptr2 ldx ptr2+1 ldy tmp3 sty sreg ldy tmp4 sty sreg+1 ; Check the sign of the result. It is the sign of the left operand. bit tmp1 ; Check sign of left operand bpl Pos ; Jump if result is positive ; Result is negative jmp negeax ; Negate result ; Result is positive Pos: rts ; Done
wagiminator/C64-Collection
1,158
C64_xu1541/software/tools/cc65-2.13.2/libsrc/runtime/lasr.s
; ; Ullrich von Bassewitz, 2004-06-30 ; ; CC65 runtime: right shift support for longs ; ; Note: The standard declares a shift count that is negative or >= the ; bitcount of the shifted type for undefined behaviour. ; ; Note^2: The compiler knowns about the register/zero page usage of this ; function, so you need to change the compiler source if you change it! ; .export tosasreax .import popeax .importzp sreg, tmp1 tosasreax: and #$1F ; Bring the shift count into a valid range sta tmp1 ; Save it jsr popeax ; Get the left hand operand ldy tmp1 ; Get shift count beq L9 ; Bail out if shift count zero stx tmp1 ; Save byte 1 ldx sreg+1 ; Load byte 3 ; Do the actual shift. Faster solutions are possible but need a lot more code. L2: cpx #$80 ; Copy bit 31 into the carry ror sreg+1 ror sreg ror tmp1 ror a dey bne L2 ; Shift done ldx tmp1 L9: rts
wagiminator/C64-Collection
2,386
C64_xu1541/software/tools/cc65-2.13.2/libsrc/runtime/callirq.s
; ; Ullrich von Bassewitz, 2004-04-04 ; ; CC65 runtime: Support for calling special irq routines declared as condes ; type 2. ; ; There are two reasons, why this is a separate routine, and the generic ; condes routine in condes.s is not used: ; ; 1. Speed. Having several things hardcoded makes it faster. This is ; important if it is called in each interrupt. ; ; 2. Reentrancy. The condes routines must use self modyfiying code, which ; means it is not reentrant. An IRQ using condes, that interrupts ; another use of condes will cause unpredicatble behaviour. The current ; code avoids this by using locking mechanisms, but it's complex and ; has a size and performance penalty. ; ; 3. Special semantics: An interruptor called by callirq must tell by ; setting or resetting the carry flag if the interrupt has been handled ; (which means that the interrupt is no longer active at the interrupt ; source). callirq will call no other interruptors if this happens. To ; simplify code, all interrupt routines will be called with carry clear ; on entry. ; ; As the normal condes routine, this one has the limitation of 127 table ; entries. ; .export callirq .export callirq_y ; Same but with Y preloaded .import __INTERRUPTOR_TABLE__, __INTERRUPTOR_COUNT__ .code ; -------------------------------------------------------------------------- ; Call all IRQ routines. The function needs to use self modifying code and ; is thereforce placed in the data segment. It will return carry set if the ; interrupt was handled and carry clear if not. The caller may choose to ; ignore this at will. ; NOTE: The routine must not be called if the table is empty! .data callirq: ldy #.lobyte(__INTERRUPTOR_COUNT__*2) callirq_y: clc ; Preset carry flag loop: dey lda __INTERRUPTOR_TABLE__,y sta jmpvec+2 ; Modify code below dey lda __INTERRUPTOR_TABLE__,y sta jmpvec+1 ; Modify code below sty index+1 ; Modify code below jmpvec: jsr $FFFF ; Patched at runtime bcs done ; Bail out if interrupt handled index: ldy #$FF ; Patched at runtime bne loop done: rts
wagiminator/C64-Collection
1,792
C64_xu1541/software/tools/cc65-2.13.2/libsrc/runtime/mul.s
; ; Ullrich von Bassewitz, 2009-08-17 ; ; CC65 runtime: multiplication for ints ; .export tosumulax, tosmulax .import mul8x16, mul8x16a ; in mul8.s .import popsreg .importzp sreg, tmp1, ptr4 ;--------------------------------------------------------------------------- ; 16x16 multiplication routine tosmulax: tosumulax: sta ptr4 txa ; High byte zero beq @L3 ; Do 8x16 multiplication if high byte zero stx ptr4+1 ; Save right operand jsr popsreg ; Get left operand ; Do ptr4:ptr4+1 * sreg:sreg+1 --> AX lda #0 ldx sreg+1 ; Get high byte into register for speed beq @L4 ; -> we can do 8x16 after swap sta tmp1 ldy #16 ; Number of bits lsr ptr4+1 ror ptr4 ; Get first bit into carry @L0: bcc @L1 clc adc sreg pha txa ; hi byte of left op adc tmp1 sta tmp1 pla @L1: ror tmp1 ror a ror ptr4+1 ror ptr4 dey bne @L0 lda ptr4 ; Load the result ldx ptr4+1 rts ; Done ; High byte of rhs is zero, jump to the 8x16 routine instead @L3: jmp mul8x16 ; If the high byte of rhs is zero, swap the operands and use the 8x16 ; routine. On entry, A and X are zero @L4: ldy sreg ; Save right operand (8 bit) ldx ptr4 ; Copy left 16 bit operand to right stx sreg ldx ptr4+1 ; Don't store, this is done later sty ptr4 ; Copy low 8 bit of right op to left ldy #8 jmp mul8x16a
wagiminator/C64-Collection
1,173
C64_xu1541/software/tools/cc65-2.13.2/libsrc/runtime/lshelp.s
; ; Ullrich von Bassewitz, 13.08.1998 ; ; CC65 runtime: helper stuff for mod/div/mul with long signed ints ; ; When negating values, we will ignore the possibility here, that one of the ; values if $80000000, in which case the negate will fail. .export poplsargs .import getlop .importzp sreg, tmp1, tmp2, ptr1, ptr3, ptr4 poplsargs: jsr getlop ; Get the operands ; Remember the signs of the operands (that is, the high bytes) in tmp1 and ; tmp2. Make both operands positive. lda sreg+1 ; Is the left operand negative? sta tmp1 ; Remember the sign for later bpl L1 ; Jump if not clc ; Make it positive lda ptr1 eor #$FF adc #$01 sta ptr1 lda ptr1+1 eor #$FF adc #$00 sta ptr1+1 lda sreg eor #$FF adc #$00 sta sreg lda sreg+1 eor #$FF adc #$00 sta sreg+1 L1: lda ptr4+1 ; Is the right operand nagative? sta tmp2 ; Remember the sign for later bpl L2 ; Jump if not clc ; Make it positive lda ptr3 eor #$FF adc #$01 sta ptr3 lda ptr3+1 eor #$FF adc #$00 sta ptr3+1 lda ptr4 eor #$FF adc #$00 sta ptr4 lda ptr4+1 eor #$FF adc #$00 sta ptr4+1 L2: rts
wagiminator/C64-Collection
1,074
C64_xu1541/software/tools/cc65-2.13.2/libsrc/runtime/lmul.s
; ; Ullrich von Bassewitz, 13.08.1998 ; ; CC65 runtime: multiplication for long (unsigned) ints ; .export tosumul0ax, tosumuleax, tosmul0ax, tosmuleax .import addysp1 .importzp sp, sreg, tmp1, tmp2, tmp3, tmp4, ptr1, ptr3, ptr4 tosmul0ax: tosumul0ax: ldy #$00 sty sreg sty sreg+1 tosmuleax: tosumuleax: mul32: sta ptr1 stx ptr1+1 ; op2 now in ptr1/sreg ldy #0 lda (sp),y sta ptr3 iny lda (sp),y sta ptr3+1 iny lda (sp),y sta ptr4 iny lda (sp),y sta ptr4+1 ; op1 in pre3/ptr4 jsr addysp1 ; Drop TOS ; Do (ptr1:sreg)*(ptr3:ptr4) --> EAX. lda #0 sta tmp4 sta tmp3 sta tmp2 ldy #32 L0: lsr tmp4 ror tmp3 ror tmp2 ror a ror sreg+1 ror sreg ror ptr1+1 ror ptr1 bcc L1 clc adc ptr3 pha lda ptr3+1 adc tmp2 sta tmp2 lda ptr4 adc tmp3 sta tmp3 lda ptr4+1 adc tmp4 sta tmp4 pla L1: dey bpl L0 lda ptr1 ; Load the low result word ldx ptr1+1 rts
wagiminator/C64-Collection
1,313
C64_xu1541/software/tools/cc65-2.13.2/libsrc/runtime/shl.s
; ; Ullrich von Bassewitz, 1998-08-05, 2004-06-25 ; ; CC65 runtime: left shift support for ints and unsigneds ; ; Note: The standard declares a shift count that is negative or >= the ; bitcount of the shifted type for undefined behaviour. ; ; Note^2: The compiler knowns about the register/zero page usage of this ; function, so you need to change the compiler source if you change it! ; .export tosaslax, tosshlax .import popax .importzp tmp1 tosshlax: tosaslax: and #$0F ; Bring the shift count into a valid range sta tmp1 ; Save it jsr popax ; Get the left hand operand ldy tmp1 ; Get shift count beq L9 ; Bail out if shift count zero cpy #8 ; Shift count 8 or greater? bcc L3 ; Jump if not ; Shift count is greater 7. The carry is set when we enter here. tax tya sbc #8 tay txa jmp L2 L1: asl a L2: dey bpl L1 tax lda #$00 rts ; Shift count is less than 8. L3: stx tmp1 ; Save high byte of lhs L4: asl a rol tmp1 dey bne L4 ; Done with shift ldx tmp1 L9: rts
wagiminator/C64-Collection
1,776
C64_xu1541/software/tools/cc65-2.13.2/libsrc/zlib/crc32.s
; ; Piotr Fusik, 14.11.2001 ; ; unsigned long __fastcall__ crc32 (unsigned long crc, unsigned char* buf, ; unsigned len); ; .export _crc32 .import compleax, incsp2, incsp4, popax, popeax .importzp sreg, ptr1, ptr2, tmp1, tmp2 POLYNOMIAL = $EDB88320 make_table: ldx #0 @L1: lda #0 sta tmp2 sta sreg sta sreg+1 ldy #8 txa @L2: sta tmp1 lsr a bcc @L3 lda sreg+1 lsr a eor #(POLYNOMIAL>>24)&$FF sta sreg+1 lda sreg ror a eor #(POLYNOMIAL>>16)&$FF sta sreg lda tmp2 ror a eor #(POLYNOMIAL>>8)&$FF sta tmp2 lda tmp1 ror a eor #POLYNOMIAL&$FF bcs @L4 ; branch always @L3: rol a lsr sreg+1 ror sreg ror tmp2 ror a @L4: dey bne @L2 sta table_0,x lda tmp2 sta table_1,x lda sreg sta table_2,x lda sreg+1 sta table_3,x inx bne @L1 inc table_initialised RET: rts _crc32: ; ptr2 = (len & 0xff) == 0 ? len : len + 0x100; tay beq @L1 inx @L1: sta ptr2 stx ptr2+1 ; ptr1 = buf jsr popax sta ptr1 stx ptr1+1 ; if (buf == NULL) return 0; ora ptr1+1 beq @L0 ; if (!tables_initialised) make_tables(); lda table_initialised bne @dont_make jsr make_table @dont_make: ; eax = crc jsr popeax ; if (len == 0) return crc; ldy ptr2 bne @L2 ldy ptr2+1 beq RET @L2: ; eax = ~crc jsr compleax stx tmp2 ldy #0 ; crc = (crc >> 8) ^ table[(crc & 0xff) ^ *p++]; @L3: eor (ptr1),y tax lda table_0,x eor tmp2 sta tmp1 lda table_1,x eor sreg sta tmp2 lda table_2,x eor sreg+1 sta sreg lda table_3,x sta sreg+1 lda tmp1 iny bne @L4 inc ptr1+1 @L4: dec ptr2 bne @L3 dec ptr2+1 bne @L3 ldx tmp2 jmp compleax ; return 0L @L0: sta sreg sta sreg+1 ; ignore crc jmp incsp4 .data table_initialised: .byte 0 .bss table_0: .res 256 table_1: .res 256 table_2: .res 256 table_3: .res 256
wagiminator/C64-Collection
14,431
C64_xu1541/software/tools/cc65-2.13.2/libsrc/zlib/inflatemem.s
; ; Piotr Fusik, 21.09.2003 ; ; unsigned __fastcall__ inflatemem (char* dest, const char* source); ; .export _inflatemem .import incsp2 .importzp sp, sreg, ptr1, ptr2, ptr3, ptr4, tmp1 ; -------------------------------------------------------------------------- ; ; Constants ; ; Maximum length of a Huffman code. MAX_BITS = 15 ; All Huffman trees are stored in the bitsCount, bitsPointer_l ; and bitsPointer_h arrays. There may be two trees: the literal/length tree ; and the distance tree, or just one - the temporary tree. ; Index in the mentioned arrays for the beginning of the literal/length tree ; or the temporary tree. PRIMARY_TREE = 0 ; Index in the mentioned arrays for the beginning of the distance tree. DISTANCE_TREE = MAX_BITS ; Size of each array. TREES_SIZE = 2*MAX_BITS ; -------------------------------------------------------------------------- ; ; Page zero ; ; Pointer to the compressed data. inputPointer = ptr1 ; 2 bytes ; Pointer to the uncompressed data. outputPointer = ptr2 ; 2 bytes ; Local variables. ; As far as there is no conflict, same memory locations are used ; for different variables. inflateDynamicBlock_cnt = ptr3 ; 1 byte inflateCodes_src = ptr3 ; 2 bytes buildHuffmanTree_src = ptr3 ; 2 bytes getNextLength_last = ptr3 ; 1 byte getNextLength_index = ptr3+1 ; 1 byte buildHuffmanTree_ptr = ptr4 ; 2 bytes fetchCode_ptr = ptr4 ; 2 bytes getBits_tmp = ptr4 ; 1 byte moveBlock_len = sreg ; 2 bytes inflateDynamicBlock_np = sreg ; 1 byte inflateDynamicBlock_nd = sreg+1 ; 1 byte getBit_hold = tmp1 ; 1 byte ; -------------------------------------------------------------------------- ; ; Code ; _inflatemem: ; inputPointer = source sta inputPointer stx inputPointer+1 ; outputPointer = dest .ifpc02 lda (sp) ldy #1 .else ldy #0 lda (sp),y iny .endif sta outputPointer lda (sp),y sta outputPointer+1 ; ldy #1 sty getBit_hold inflatemem_1: ; Get a bit of EOF and two bits of block type ldx #3 lda #0 jsr getBits lsr a ; A and Z contain block type, C contains EOF flag ; Save EOF flag php ; Go to the routine decompressing this block jsr callExtr plp bcc inflatemem_1 ; C flag is set! ; return outputPointer - dest; lda outputPointer .ifpc02 sbc (sp) ; C flag is set ldy #1 .else ldy #0 sbc (sp),y ; C flag is set iny .endif pha lda outputPointer+1 sbc (sp),y tax pla ; pop dest jmp incsp2 ; -------------------------------------------------------------------------- ; Go to proper block decoding routine. callExtr: bne inflateCompressedBlock ; -------------------------------------------------------------------------- ; Decompress a 'stored' data block. inflateCopyBlock: ; Ignore bits until byte boundary ldy #1 sty getBit_hold ; Get 16-bit length ldx #inputPointer lda (0,x) sta moveBlock_len lda (inputPointer),y sta moveBlock_len+1 ; Skip the length and one's complement of it lda #4 clc adc inputPointer sta inputPointer bcc moveBlock inc inputPointer+1 ; jmp moveBlock ; -------------------------------------------------------------------------- ; Copy block of length moveBlock_len from (0,x) to the output. moveBlock: ldy moveBlock_len beq moveBlock_1 .ifpc02 .else ldy #0 .endif inc moveBlock_len+1 moveBlock_1: lda (0,x) .ifpc02 sta (outputPointer) .else sta (outputPointer),y .endif inc 0,x bne moveBlock_2 inc 1,x moveBlock_2: inc outputPointer bne moveBlock_3 inc outputPointer+1 moveBlock_3: .ifpc02 dey .else dec moveBlock_len .endif bne moveBlock_1 dec moveBlock_len+1 bne moveBlock_1 rts ; -------------------------------------------------------------------------- ; Decompress a Huffman-coded data block ; (A = 1: fixed, A = 2: dynamic). inflateCompressedBlock: lsr a bne inflateDynamicBlock ; Note: inflateDynamicBlock may assume that A = 1 ; -------------------------------------------------------------------------- ; Decompress a Huffman-coded data block with default Huffman trees ; (defined by the DEFLATE format): ; literalCodeLength: 144 times 8, 112 times 9 ; endCodeLength: 7 ; lengthCodeLength: 23 times 7, 6 times 8 ; distanceCodeLength: 30 times 5+DISTANCE_TREE, 2 times 8 ; (two 8-bit codes from the primary tree are not used). inflateFixedBlock: ldx #159 stx distanceCodeLength+32 lda #8 inflateFixedBlock_1: sta literalCodeLength-1,x sta literalCodeLength+159-1,x dex bne inflateFixedBlock_1 ldx #112 ; lda #9 inflateFixedBlock_2: inc literalCodeLength+144-1,x ; sta dex bne inflateFixedBlock_2 ldx #24 ; lda #7 inflateFixedBlock_3: dec endCodeLength-1,x ; sta dex bne inflateFixedBlock_3 ldx #30 lda #5+DISTANCE_TREE inflateFixedBlock_4: sta distanceCodeLength-1,x dex bne inflateFixedBlock_4 beq inflateCodes ; branch always ; -------------------------------------------------------------------------- ; Decompress a Huffman-coded data block, reading Huffman trees first. inflateDynamicBlock: ; numberOfPrimaryCodes = 257 + getBits(5) ldx #5 ; lda #1 jsr getBits sta inflateDynamicBlock_np ; numberOfDistanceCodes = 1 + getBits(5) ldx #5 lda #1+29+1 jsr getBits sta inflateDynamicBlock_nd ; numberOfTemporaryCodes = 4 + getBits(4) lda #4 tax jsr getBits sta inflateDynamicBlock_cnt ; Get lengths of temporary codes in the order stored in tempCodeLengthOrder txa ; lda #0 tay inflateDynamicBlock_1: ldx #3 ; A = 0 jsr getBits ; does not change Y inflateDynamicBlock_2: ldx tempCodeLengthOrder,y sta literalCodeLength,x lda #0 iny cpy inflateDynamicBlock_cnt bcc inflateDynamicBlock_1 cpy #19 bcc inflateDynamicBlock_2 ror literalCodeLength+19 ; C flag is set, so this will set b7 ; Build the tree for temporary codes jsr buildHuffmanTree ; Use temporary codes to get lengths of literal/length and distance codes ldx #0 ldy #1 stx getNextLength_last inflateDynamicBlock_3: jsr getNextLength sta literalCodeLength,x inx bne inflateDynamicBlock_3 inflateDynamicBlock_4: jsr getNextLength inflateDynamicBlock_5: sta endCodeLength,x inx cpx inflateDynamicBlock_np bcc inflateDynamicBlock_4 lda #0 cpx #1+29 bcc inflateDynamicBlock_5 inflateDynamicBlock_6: jsr getNextLength cmp #0 beq inflateDynamicBlock_7 adc #DISTANCE_TREE-1 ; C flag is set inflateDynamicBlock_7: sta endCodeLength,x inx cpx inflateDynamicBlock_nd bcc inflateDynamicBlock_6 ror endCodeLength,x ; C flag is set, so this will set b7 ; jmp inflateCodes ; -------------------------------------------------------------------------- ; Decompress a data block basing on given Huffman trees. inflateCodes: jsr buildHuffmanTree inflateCodes_1: jsr fetchPrimaryCode bcs inflateCodes_2 ; Literal code .ifpc02 sta (outputPointer) .else ldy #0 sta (outputPointer),y .endif inc outputPointer bne inflateCodes_1 inc outputPointer+1 bcc inflateCodes_1 ; branch always ; End of block inflateCodes_ret: rts inflateCodes_2: beq inflateCodes_ret ; Restore a block from the look-behind buffer jsr getValue sta moveBlock_len tya jsr getBits sta moveBlock_len+1 ldx #DISTANCE_TREE jsr fetchCode jsr getValue sec eor #$ff adc outputPointer sta inflateCodes_src php tya jsr getBits plp eor #$ff adc outputPointer+1 sta inflateCodes_src+1 ldx #inflateCodes_src jsr moveBlock beq inflateCodes_1 ; branch always ; -------------------------------------------------------------------------- ; Build Huffman trees basing on code lengths (in bits). ; stored in the *CodeLength arrays. ; A byte with its highest bit set marks the end. buildHuffmanTree: lda #<literalCodeLength sta buildHuffmanTree_src lda #>literalCodeLength sta buildHuffmanTree_src+1 ; Clear bitsCount and bitsPointer_l ldy #2*TREES_SIZE+1 lda #0 buildHuffmanTree_1: sta bitsCount-1,y dey bne buildHuffmanTree_1 beq buildHuffmanTree_3 ; branch always ; Count number of codes of each length buildHuffmanTree_2: tax inc bitsPointer_l,x iny bne buildHuffmanTree_3 inc buildHuffmanTree_src+1 buildHuffmanTree_3: lda (buildHuffmanTree_src),y bpl buildHuffmanTree_2 ; Calculate a pointer for each length ldx #0 lda #<sortedCodes ldy #>sortedCodes clc buildHuffmanTree_4: sta bitsPointer_l,x tya sta bitsPointer_h,x lda bitsPointer_l+1,x adc bitsPointer_l,x ; C flag is zero bcc buildHuffmanTree_5 iny buildHuffmanTree_5: inx cpx #TREES_SIZE bcc buildHuffmanTree_4 lda #>literalCodeLength sta buildHuffmanTree_src+1 ldy #0 bcs buildHuffmanTree_9 ; branch always ; Put codes into their place in sorted table buildHuffmanTree_6: beq buildHuffmanTree_7 tax lda bitsPointer_l-1,x sta buildHuffmanTree_ptr lda bitsPointer_h-1,x sta buildHuffmanTree_ptr+1 tya ldy bitsCount-1,x inc bitsCount-1,x sta (buildHuffmanTree_ptr),y tay buildHuffmanTree_7: iny bne buildHuffmanTree_9 inc buildHuffmanTree_src+1 ldx #MAX_BITS-1 buildHuffmanTree_8: lda bitsCount,x sta literalCount,x dex bpl buildHuffmanTree_8 buildHuffmanTree_9: lda (buildHuffmanTree_src),y bpl buildHuffmanTree_6 rts ; -------------------------------------------------------------------------- ; Decode next code length using temporary codes. getNextLength: stx getNextLength_index dey bne getNextLength_1 ; Fetch a temporary code jsr fetchPrimaryCode ; Temporary code 0..15: put this length ldy #1 cmp #16 bcc getNextLength_2 ; Temporary code 16: repeat last length 3 + getBits(2) times ; Temporary code 17: put zero length 3 + getBits(3) times ; Temporary code 18: put zero length 11 + getBits(7) times tay ldx tempExtraBits-16,y lda tempBaseValue-16,y jsr getBits cpy #17 tay txa ; lda #0 bcs getNextLength_2 getNextLength_1: lda getNextLength_last getNextLength_2: sta getNextLength_last ldx getNextLength_index rts ; -------------------------------------------------------------------------- ; Read a code basing on the primary tree. fetchPrimaryCode: ldx #PRIMARY_TREE ; jmp fetchCode ; -------------------------------------------------------------------------- ; Read a code from input basing on the tree specified in X. ; Return low byte of this code in A. ; For the literal/length tree, the C flag is set if the code is non-literal. fetchCode: lda #0 fetchCode_1: jsr getBit rol a inx sec sbc bitsCount-1,x bcs fetchCode_1 adc bitsCount-1,x ; C flag is zero cmp literalCount-1,x sta fetchCode_ptr ldy bitsPointer_l-1,x lda bitsPointer_h-1,x sta fetchCode_ptr+1 lda (fetchCode_ptr),y rts ; -------------------------------------------------------------------------- ; Decode low byte of a value (length or distance), basing on the code in A. ; The result is the base value for this code plus some bits read from input. getValue: tay ldx lengthExtraBits-1,y lda lengthBaseValue_l-1,y pha lda lengthBaseValue_h-1,y tay pla ; jmp getBits ; -------------------------------------------------------------------------- ; Read X-bit number from the input and add it to A. ; Increment Y if overflow. ; If X > 8, read only 8 bits. ; On return X holds number of unread bits: X = (X > 8 ? X - 8 : 0); getBits: cpx #0 beq getBits_ret .ifpc02 stz getBits_tmp dec getBits_tmp .else pha lda #$ff sta getBits_tmp pla .endif getBits_1: jsr getBit bcc getBits_2 sbc getBits_tmp ; C flag is set bcc getBits_2 iny getBits_2: dex beq getBits_ret asl getBits_tmp bmi getBits_1 getBits_ret: rts ; -------------------------------------------------------------------------- ; Read a single bit from input, return it in the C flag. getBit: lsr getBit_hold bne getBit_ret pha .ifpc02 lda (inputPointer) .else sty getBit_hold ldy #0 lda (inputPointer),y ldy getBit_hold .endif inc inputPointer bne getBit_1 inc inputPointer+1 getBit_1: ror a ; C flag is set sta getBit_hold pla getBit_ret: rts ; -------------------------------------------------------------------------- ; ; Constant data ; .rodata ; -------------------------------------------------------------------------- ; Arrays for the temporary codes. ; Order, in which lengths of the temporary codes are stored. tempCodeLengthOrder: .byte 16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15 ; Base values. tempBaseValue: .byte 3,3,11 ; Number of extra bits to read. tempExtraBits: .byte 2,3,7 ; -------------------------------------------------------------------------- ; Arrays for the length and distance codes. ; Base values. lengthBaseValue_l: .byte <3,<4,<5,<6,<7,<8,<9,<10 .byte <11,<13,<15,<17,<19,<23,<27,<31 .byte <35,<43,<51,<59,<67,<83,<99,<115 .byte <131,<163,<195,<227,<258 distanceBaseValue_l: .byte <1,<2,<3,<4,<5,<7,<9,<13 .byte <17,<25,<33,<49,<65,<97,<129,<193 .byte <257,<385,<513,<769,<1025,<1537,<2049,<3073 .byte <4097,<6145,<8193,<12289,<16385,<24577 lengthBaseValue_h: .byte >3,>4,>5,>6,>7,>8,>9,>10 .byte >11,>13,>15,>17,>19,>23,>27,>31 .byte >35,>43,>51,>59,>67,>83,>99,>115 .byte >131,>163,>195,>227,>258 distanceBaseValue_h: .byte >1,>2,>3,>4,>5,>7,>9,>13 .byte >17,>25,>33,>49,>65,>97,>129,>193 .byte >257,>385,>513,>769,>1025,>1537,>2049,>3073 .byte >4097,>6145,>8193,>12289,>16385,>24577 ; Number of extra bits to read. lengthExtraBits: .byte 0,0,0,0,0,0,0,0 .byte 1,1,1,1,2,2,2,2 .byte 3,3,3,3,4,4,4,4 .byte 5,5,5,5,0 distanceExtraBits: .byte 0,0,0,0,1,1,2,2 .byte 3,3,4,4,5,5,6,6 .byte 7,7,8,8,9,9,10,10 .byte 11,11,12,12,13,13 ; -------------------------------------------------------------------------- ; ; Uninitialised data ; .bss ; Number of literal codes of each length in the primary tree ; (MAX_BITS bytes, overlap with literalCodeLength). literalCount: ; -------------------------------------------------------------------------- ; Data for building the primary tree. ; Lengths of literal codes. literalCodeLength: .res 256 ; Length of the end code. endCodeLength: .res 1 ; Lengths of length codes. lengthCodeLength: .res 29 ; -------------------------------------------------------------------------- ; Data for building the distance tree. ; Lengths of distance codes. distanceCodeLength: .res 30 ; For two unused codes in the fixed trees and an 'end' mark. .res 3 ; -------------------------------------------------------------------------- ; The Huffman trees. ; Number of codes of each length. bitsCount: .res TREES_SIZE ; Pointers to sorted codes of each length. bitsPointer_l: .res TREES_SIZE+1 bitsPointer_h: .res TREES_SIZE ; Sorted codes. sortedCodes: .res 256+1+29+30+2
wagiminator/C64-Collection
1,312
C64_xu1541/software/tools/cc65-2.13.2/libsrc/zlib/adler32.s
; ; Piotr Fusik, 18.11.2001 ; ; unsigned long __fastcall__ adler32 (unsigned long adler, unsigned char* buf, ; unsigned len); ; .export _adler32 .import incsp2, incsp4, popax, popeax .importzp sreg, ptr1, ptr2, tmp1 BASE = 65521 ; largest prime smaller than 65536 _adler32: ; ptr2 = (len & 0xff) == 0 ? len : len + 0x100; tay beq @L1 inx @L1: sta ptr2 stx ptr2+1 ; ptr1 = buf jsr popax sta ptr1 stx ptr1+1 ; if (buf == NULL) return 1L; ora ptr1+1 beq @L0 ; s1 = adler & 0xFFFF; s2 = adler >> 16; jsr popeax ; if (len == 0) return adler; ldy ptr2 bne @L2 ldy ptr2+1 beq @RET @L2: ldy #0 ; s1 += *ptr++; if (s1 >= BASE) s1 -= BASE; @L3: clc adc (ptr1),y bcc @L4 inx beq @L5 ; C flag is set @L4: cpx #>BASE bcc @L6 cmp #<BASE bcc @L6 inx ; ldx #0 @L5: sbc #<BASE ; C flag is set clc @L6: sta tmp1 ; s2 += s1; if (s2 >= BASE) s2 -= BASE; adc sreg ; C flag is clear sta sreg txa adc sreg+1 sta sreg+1 bcs @L7 cmp #>BASE bcc @L8 lda sreg cmp #<BASE bcc @L8 @L7: lda sreg sbc #<BASE ; C flag is set sta sreg lda sreg+1 sbc #>BASE sta sreg+1 @L8: lda tmp1 iny bne @L9 inc ptr1+1 @L9: dec ptr2 bne @L3 dec ptr2+1 bne @L3 ; return (s2 << 16) | s1; @RET: rts ; return 1L @L0: sta sreg sta sreg+1 lda #1 ; ignore adler jmp incsp4
wagiminator/C64-Collection
2,507
C64_xu1541/software/tools/cc65-2.13.2/libsrc/em/em-kernel.s
; ; Ullrich von Bassewitz, 2002-11-29 ; ; Common functions of the extended memory API. ; .export em_clear_ptr .import return0 .importzp ptr1 .include "em-kernel.inc" .include "em-error.inc" ;---------------------------------------------------------------------------- ; Variables .bss _em_drv: .res 2 ; Pointer to driver ; Jump table for the driver functions. .data emd_vectors: emd_install: jmp return0 emd_uninstall: jmp return0 emd_pagecount: jmp return0 emd_map: jmp return0 emd_use: jmp return0 emd_commit: jmp return0 emd_copyfrom: jmp return0 emd_copyto: jmp return0 ; Driver header signature .rodata emd_sig: .byte $65, $6d, $64, EMD_API_VERSION ; "emd", version ;---------------------------------------------------------------------------- ; unsigned char __fastcall__ em_install (void* driver); ; /* Install the driver once it is loaded */ _em_install: sta _em_drv sta ptr1 stx _em_drv+1 stx ptr1+1 ; Check the driver signature ldy #.sizeof(emd_sig)-1 @L0: lda (ptr1),y cmp emd_sig,y bne inv_drv dey bpl @L0 ; Copy the jump vectors ldy #EMD_HDR::JUMPTAB ldx #0 @L1: inx ; Skip the JMP opcode jsr copy ; Copy one byte jsr copy ; Copy one byte cpy #(EMD_HDR::JUMPTAB + .sizeof(EMD_HDR::JUMPTAB)) bne @L1 jmp emd_install ; Call driver install routine ; Driver signature invalid inv_drv: lda #EM_ERR_INV_DRIVER ldx #0 rts ; Copy one byte from the jump vectors copy: lda (ptr1),y sta emd_vectors,x iny inx rts ;---------------------------------------------------------------------------- ; unsigned char __fastcall__ em_uninstall (void); ; /* Uninstall the currently loaded driver and return an error code. ; * Note: This call does not free allocated memory. ; */ _em_uninstall: jsr emd_uninstall ; Call driver routine em_clear_ptr: ; External entry point lda #0 sta _em_drv sta _em_drv+1 ; Clear the driver pointer tax rts ; Return zero
wagiminator/C64-Collection
7,097
C64_xu1541/software/tools/cc65-2.13.2/libsrc/cbm610/cbm610-ram.s
; ; Extended memory driver for the CBM610 additional RAM banks. Driver works ; without problems when linked statically. ; ; Ullrich von Bassewitz, 2002-12-09, 2003-12-20 ; .include "zeropage.inc" .include "em-kernel.inc" .include "em-error.inc" .include "cbm610.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 = 2 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
wagiminator/C64-Collection
12,018
C64_xu1541/software/tools/cc65-2.13.2/libsrc/cbm610/crt0.s
; ; Startup code for cc65 (CBM 600/700 version) ; .export _exit, BRKVec .export __STARTUP__ : absolute = 1 ; Mark as startup .import callirq_y, initlib, donelib .import push0, callmain .import __BSS_RUN__, __BSS_SIZE__, __EXTZP_RUN__ .import __INTERRUPTOR_COUNT__ .import scnkey, UDTIM .include "zeropage.inc" .include "extzp.inc" .include "cbm610.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 1, 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,1,133,0 ; ; The machine program in the data lines is: ; ; sei ; lda #$01 ; sta $00 <-- Switch to bank 1 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,$31,$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 $CC, graphmode .byte $D4, config .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 = $FF05 .org $FECB 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 <> $FF2E) .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 #$01 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 $FFF6 .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 ; crtc .word $da00 ; sid .word $db00 ; ipccia .word $dc00 ; cia .word $dd00 ; acia .word $de00 ; tpi1 .word $df00 ; tpi2 .word $ea29 ; ktab1 .word $ea89 ; ktab2 .word $eae9 ; ktab3 .word $eb49 ; 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" ; Activate chained interrupt handlers, then enable interrupts. Init: 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 jsr donelib ; Run module destructors lda #$00 sta irqcount ; Disable custom irq handlers ; Address the system bank lda #$0F sta IndReg ; 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. .bss irqcount: .byte 0
wagiminator/C64-Collection
1,894
C64_xu1541/software/tools/cc65-2.13.2/libsrc/cbm610/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 "cbm610.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 (cia),y bpl AM and #%01111111 sed clc adc #$12 cld AM: jsr BCD2dec sta TM + tm::tm_hour ldy #CIA::TODMIN lda (cia),y jsr BCD2dec sta TM + tm::tm_min ldy #CIA::TODSEC lda (cia),y jsr BCD2dec sta TM + tm::tm_sec ldy #CIA::TOD10 lda (cia),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/cbm610/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,687
C64_xu1541/software/tools/cc65-2.13.2/libsrc/cbm610/kscnkey.s
; ; Ullrich von Bassewitz, 28.09.1998 ; ; Keyboard polling stuff for the 610. ; .export scnkey .importzp tpi2, ktab1, ktab2, ktab3, ktab4 .importzp keyidx, keybuf, keyscanbuf, keysave, modkey, norkey .importzp graphmode, lastidx, rptdelay, rptcount .include "cbm610.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 ; This code goes into page 2, since it is included in every program and ; there's space left in p2 .segment "PAGE2" .proc Poll ldy #TPI::PRC L1: lda (tpi2),y sta keysave lda (tpi2),y cmp keysave bne L1 rts .endproc
wagiminator/C64-Collection
1,670
C64_xu1541/software/tools/cc65-2.13.2/libsrc/cbm610/extzp.s
; ; Ullrich von Bassewitz, 2003-12-20 ; ; Additional zero page locations for the CBM610. ; NOTE: This file is actually linked to an application with its full contents, ; so the program comes up with the values given in this 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: .word $0000 sysp3: .word $0000 crtc: .word $0000 sid: .word $0000 ipccia: .word $0000 cia: .word $0000 acia: .word $0000 tpi1: .word $0000 tpi2: .word $0000 ktab1: .word $0000 ktab2: .word $0000 ktab3: .word $0000 ktab4: .word $0000 sysp0: .word $0000 time: .dword $0000 segsave: .byte 0 ktmp: .byte 0 CURS_X: .byte 0 CURS_Y: .byte 0 RVS: .byte 0 DEVNUM: .byte 0 config: .byte 0 CharPtr: .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
3,131
C64_xu1541/software/tools/cc65-2.13.2/libsrc/cbm610/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 .destructor setsyscursor .import _gotoxy .import popa .import PLOT .import ktmp: zp, crtc: zp, CURS_X: zp, CURS_Y: zp, RVS: zp .import CharPtr: zp .include "cbm610.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 CharPtr sta CharPtr bcc L4 inc CharPtr+1 L4: 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 ; Branch always ; Write one character to the screen without doing anything else, return X ; position in Y putchar: ldx IndReg ldy #$0F sty IndReg ora RVS ; Set revers bit ldy CURS_X sta (CharPtr),y ; Set char stx IndReg rts ; Set cursor position, calculate RAM pointers plot: ldx CURS_Y lda LineLSBTab,x sta CharPtr lda LineMSBTab,x sta CharPtr+1 lda IndReg pha lda #$0F sta IndReg ldy #$00 clc sei sta (crtc),y lda CharPtr adc CURS_X iny sta (crtc),y dey lda #$0E sta (crtc),y iny lda (crtc),y and #$F8 sta ktmp lda CharPtr+1 adc #$00 and #$07 ora ktmp sta (crtc),y cli pla sta IndReg rts ; ------------------------------------------------------------------------- ; Cleanup routine that sets the kernal cursor position to ours .segment "PAGE2" setsyscursor: ldy CURS_X ldx CURS_Y clc jmp PLOT ; Set the new cursor ; ------------------------------------------------------------------------- ; Low bytes of the start address of the screen lines .rodata LineLSBTab: .byte $00,$50,$A0,$F0,$40,$90,$E0,$30 .byte $80,$D0,$20,$70,$C0,$10,$60,$B0 .byte $00,$50,$A0,$F0,$40,$90,$E0,$30 .byte $80 ; ------------------------------------------------------------------------- ; High bytes of the start address of the screen lines LineMSBTab: .byte $D0,$D0,$D0,$D0,$D1,$D1,$D1,$D2 .byte $D2,$D2,$D3,$D3,$D3,$D4,$D4,$D4 .byte $D5,$D5,$D5,$D5,$D6,$D6,$D6,$D7 .byte $D7
wagiminator/C64-Collection
1,646
C64_xu1541/software/tools/cc65-2.13.2/libsrc/cbm610/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 "cbm610.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
1,029
C64_xu1541/software/tools/cc65-2.13.2/libsrc/cbm610/cgetc.s
; ; Ullrich von Bassewitz, 06.08.1998 ; ; char cgetc (void); ; .export _cgetc .import plot, write_crtc .import cursor .import keyidx: zp, keybuf: zp, config: zp _cgetc: lda keyidx ; Get number of characters bne L2 ; Jump if there are already chars waiting ; Switch on the cursor if needed lda cursor beq L1 ; Jump if no cursor jsr plot ; Set the current cursor position ldy #10 lda config ; Cursor format jsr write_crtc ; Set the cursor formar L1: lda keyidx beq L1 ldy #10 lda #$20 ; Cursor off jsr write_crtc L2: ldx #$00 ; Get index ldy keybuf ; Get first character in the buffer sei L3: lda keybuf+1,x ; Move up the remaining chars sta keybuf,x inx cpx keyidx bne L3 dec keyidx cli ldx #$00 ; High byte tya ; First char from buffer rts
wagiminator/C64-Collection
11,858
C64_xu1541/software/tools/cc65-2.13.2/libsrc/cbm610/cbm610-stdser.s
; ; Serial driver for the builtin 6551 ACIA of the Commodore 610. ; ; 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 "cbm610.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
2,585
C64_xu1541/software/tools/cc65-2.13.2/libsrc/pet/pet-ptvjoy.s
; ; PTV-2 Player joystick driver for the PET ; ; Stefan Haubenthal, 2005-05-25 ; Groepaz/Hitmen, 2002-12-23 ; obviously based on Ullrichs driver :) ; .include "zeropage.inc" .include "joy-kernel.inc" .include "joy-error.inc" ; .include "pet.inc" VIA_PRA := $E841 ; Port register A VIA_DDRA := $E843 ; Data direction register A ; ------------------------------------------------------------------------ ; 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 .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: lda #%10000000 ; via port A Data-Direction sta VIA_DDRA ; bit 7: out bit 6-0: in tax ; Joystick number into X bne joy2 ; Read joystick 1 joy1: lda #$80 ; via port A read/write sta VIA_PRA ; (output one at PA7) lda VIA_PRA ; via port A read/write and #$1f ; get bit 4-0 (PA4-PA0) rts ; Read joystick 2 joy2: lda #$00 ; via port A read/write sta VIA_PRA ; (output zero at PA7) lda VIA_PRA ; via port A read/write and #$0f ; get bit 3-0 (PA3-PA0) sta tmp1 ; joy 4 directions lda VIA_PRA ; via port A read/write and #%00100000 ; get bit 5 (PA5) lsr ora tmp1 ldx #0 rts
wagiminator/C64-Collection
3,179
C64_xu1541/software/tools/cc65-2.13.2/libsrc/pet/crt0.s
; ; Startup code for cc65 (PET version) ; .export _exit .export __STARTUP__ : absolute = 1 ; Mark as startup .import initlib, donelib, callirq .import zerobss, push0 .import callmain .import CLRCH, BSOUT .import __INTERRUPTOR_COUNT__ .include "zeropage.inc" .include "pet.inc" .include "../cbm/cbm.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,"1037" ; SYS 1037 .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. The routine that is called by BSOUT to switch the ; character set will use FNLEN as temporary storage - YUCK! Since the ; initmainargs routine, which parses the command line for arguments needs this ; information, we need to save and restore it here. ; Thanks to Stefan Haubenthal for this information! lda FNLEN pha ; Save FNLEN lda #14 ; sta $E84C ; See PET FAQ jsr BSOUT pla sta FNLEN ; Restore FNLEN ; Clear the BSS data jsr zerobss ; Save system stuff and setup the stack tsx stx spsave ; Save the system stack ptr lda MEMSIZE sta sp lda MEMSIZE+1 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 ; Call module destructors. This is also the _exit entry. _exit: pha ; Save the return code on stack jsr donelib ; Reset the IRQ vector if we chained it. 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 program return code into ST pla sta ST ; Restore the stack pointer ldx spsave txs ; Restore stack pointer ; Back to basic rts ; ------------------------------------------------------------------------ ; 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
2,880
C64_xu1541/software/tools/cc65-2.13.2/libsrc/pet/mainargs.s
; ; Ullrich von Bassewitz, 2003-03-07 ; Stefan Haubenthal, 2008-08-11 ; ; Setup arguments for main ; .constructor initmainargs, 24 .import __argc, __argv .include "pet.inc" MAXARGS = 10 ; Maximum number of arguments allowed REM = $8f ; BASIC token-code NAME_LEN = 16 ; maximum length of command-name BASIC_BUF= $200 ;--------------------------------------------------------------------------- ; Get possible command-line arguments. Goes into the special INIT segment, ; which may be reused after the startup code is run .segment "INIT" .proc initmainargs ; 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 FNLEN cpy #NAME_LEN + 1 bcc L1 ldy #NAME_LEN - 1 ; limit the length L0: lda (FNADR),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 .endproc ; 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
2,332
C64_xu1541/software/tools/cc65-2.13.2/libsrc/pet/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 .include "pet.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: cpy SCR_LINELEN ; xsize-1 bne L3 jsr newline ; new line ldy #$FF ; + cr L3: iny sty CURS_X rts newline: lda SCR_LINELEN ; xsize-1 sec ; Account for -1 above adc SCREEN_PTR sta SCREEN_PTR bcc L4 inc SCREEN_PTR+1 L4: 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_Y lda ScrLo,y sta SCREEN_PTR lda ScrHi,y ldy SCR_LINELEN cpy #40+1 bcc @L1 asl SCREEN_PTR ; 80 column mode rol a @L1: ora #$80 ; Screen at $8000 sta SCREEN_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 rts ; Screen address tables - offset to real screen .rodata ScrLo: .byte $00, $28, $50, $78, $A0, $C8, $F0, $18 .byte $40, $68, $90, $B8, $E0, $08, $30, $58 .byte $80, $A8, $D0, $F8, $20, $48, $70, $98 .byte $C0 ScrHi: .byte $00, $00, $00, $00, $00, $00, $00, $01 .byte $01, $01, $01, $01, $01, $02, $02, $02 .byte $02, $02, $02, $02, $03, $03, $03, $03 .byte $03
wagiminator/C64-Collection
1,621
C64_xu1541/software/tools/cc65-2.13.2/libsrc/pet/break.s
; ; Ullrich von Bassewitz, 26.11.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 "pet.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,236
C64_xu1541/software/tools/cc65-2.13.2/libsrc/pet/cgetc.s
; ; Ullrich von Bassewitz, 06.08.1998 ; ; char cgetc (void); ; .export _cgetc .import cursor .include "pet.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 ; Fetch the character from the keyboard buffer L3: sei ldy KEY_BUF ldx #$00 L4: lda KEY_BUF+1,x sta KEY_BUF,x inx cpx KEY_COUNT bne L4 dec KEY_COUNT cli ldx #$00 ; Clear high byte tya rts ; Switch the cursor on or off 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 crs8: lda #0 sta CURS_STATE ; Cursor not displayed crs9: rts seton: lda #0 sta CURS_FLAG rts
wagiminator/C64-Collection
1,459
C64_xu1541/software/tools/cc65-2.13.2/libsrc/supervision/crt0.s
; ; Startup code for cc65 (supervision version) ; .export _exit .export __STARTUP__ : absolute = 1 ; Mark as startup .import _main .import initlib, donelib, copydata .import zerobss .import __RAM_START__, __RAM_SIZE__ ; Linker generated .include "zeropage.inc" .include "supervision.inc" .export _sv_irq_timer_counter, _sv_irq_dma_counter .export _sv_nmi_counter .bss _sv_irq_dma_counter: .byte 0 _sv_irq_timer_counter: .byte 0 _sv_nmi_counter: .byte 0 .code reset: jsr zerobss ; initialize data jsr copydata lda #>(__RAM_START__ + __RAM_SIZE__) sta sp+1 ; Set argument stack ptr stz sp ; #<(__RAM_START__ + __RAM_SIZE__) jsr initlib jsr _main _exit: jsr donelib exit: jmp exit .proc irq pha lda sv_irq_source and #SV_IRQ_REQUEST_TIMER beq not_timer lda sv_timer_quit inc _sv_irq_timer_counter not_timer: lda sv_irq_source and #SV_IRQ_REQUEST_DMA beq not_dma lda sv_dma_quit inc _sv_irq_dma_counter not_dma: pla rti .endproc .proc nmi inc _sv_nmi_counter rti .endproc ; removing this segment gives only a warning .segment "FFF0" .proc reset32kcode lda #(6<<5) sta sv_bank ; now the 32kbyte image can reside in the top of 64kbyte, 128kbyte roms jmp reset .endproc .segment "VECTOR" .word nmi .word reset32kcode .word irq
wagiminator/C64-Collection
6,747
C64_xu1541/software/tools/cc65-2.13.2/libsrc/supervision/ctype.s
; ; Ullrich von Bassewitz, 2003-10-10 ; ; 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 weren't 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: .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____ .res 128, CT_NONE ; 128-255
wagiminator/C64-Collection
1,809
C64_xu1541/software/tools/cc65-2.13.2/libsrc/apple2/extra/iobuf-0800.s
; ; Oliver Schmidt, 15.09.2009 ; ; ProDOS 8 I/O buffer management for memory between ; location $0800 and the cc65 program start address ; .constructor initiobuf .export iobuf_alloc, iobuf_free .import __RAM_START__ .import incsp2, popax .include "zeropage.inc" .include "errno.inc" .include "filedes.inc" .segment "INIT" initiobuf: ; Convert end address highbyte to table index lda #>__RAM_START__ sec sbc #>$0800 lsr lsr ; Mark all remaining table entries as used tax lda #$FF : cpx #MAX_FDS bcc :+ rts : sta table,x inx bne :-- ; Branch always ; ------------------------------------------------------------------------ .code iobuf_alloc: ; Get and save "memptr" jsr incsp2 jsr popax sta ptr1 stx ptr1+1 ; Search table for free entry ldx #$00 : lda table,x beq :+ inx cpx #MAX_FDS bcc :- lda #ENOMEM rts ; Mark table entry as used : lda #$FF sta table,x ; Convert table index to address hibyte txa asl asl clc adc #>$0800 ; Store address in "memptr" ldy #$01 sta (ptr1),y dey lda #$00 sta (ptr1),y rts iobuf_free: ; Convert address hibyte to table index txa sec sbc #>$0800 lsr lsr ; Mark table entry as free tax lda #$00 sta table,x rts ; ------------------------------------------------------------------------ .bss table: .res MAX_FDS
wagiminator/C64-Collection
1,382
C64_xu1541/software/tools/cc65-2.13.2/libsrc/geos/disk/dio_openclose.s
; ; Maciej 'YTM/Elysium' Witkowiak ; ; based on Atari version by Christian Groessler ; 2.7.2001 ; ; dhandle_t __fastcall__ dio_open (driveid_t drive_id); ; unsigned char __fastcall__ dio_close (dhandle_t handle); ; ; dio_open sets given device as current and initializes disk ; dio_close does nothing special .export _dio_open, _dio_close .import __oserror, _OpenDisk .importzp ptr1, tmp1 .include "../inc/dio.inc" .include "../inc/jumptab.inc" .include "../inc/geossym.inc" .include "../inc/const.inc" .bss sectsizetab: .res 4 * sst_size ; this is hardcoded .code .proc _dio_open pha tax lda driveType,x ; check if there's a device beq _inv_drive txa clc adc #8 ; normalize devnum sta curDevice jsr SetDevice jsr _OpenDisk ; take care for errors there pla tay ; drive # asl a ; make index from drive id asl a tax lda #0 sta sectsizetab+sst_sectsize,x lda #128 sta sectsizetab+sst_flag,x ; set flag that drive is "open" lda #1 sta sectsizetab+sst_sectsize+1,x tya sta sectsizetab+sst_driveno,x stx tmp1 lda #<sectsizetab clc adc tmp1 sta tmp1 lda #>sectsizetab adc #0 tax lda tmp1 rts _inv_drive: lda #DEV_NOT_FOUND sta __oserror lda #0 tax rts .endproc .proc _dio_close sta ptr1 stx ptr1+1 lda #0 ldy #sst_flag sta (ptr1),y sta __oserror ; success tax rts ; return no error .endproc
wagiminator/C64-Collection
3,202
C64_xu1541/software/tools/cc65-2.13.2/libsrc/geos/disk/dio_cts.s
; ; Maciej 'YTM/Elysium' Witkowiak ; 2.7.2001 ; ; ; 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 .export sectab_1541_l, sectab_1541_h ; for log_to_phys .import popax,__oserror .importzp ptr1,ptr2,ptr3,tmp1,tmp2,tmp3,tmp4 .include "../inc/dio.inc" .include "../inc/geossym.inc" .include "../inc/const.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 ldy #diopp_head lda (ptr2),y bne _inv_data ; there is only head 0 ldy #diopp_track lda (ptr2),y beq _inv_data ; there is no track 0 sta tmp1 iny lda (ptr2),y bne _inv_data ; there are no more than 256 tracks dec tmp1 ; normalize track to start from 0 ldy #diopp_sector lda (ptr2),y sta tmp2 iny lda (ptr2),y bne _inv_data ; there are no more than 256 sectors ; tmp1 (int) holds track+sector, translate it using device info ldy #sst_driveno lda (ptr3),y tay lda driveType,y and #%00000011 ; this is for RamDrive compatibility cmp #DRV_1541 beq dio_cts1541 cmp #DRV_1571 beq dio_cts1571 cmp #DRV_1581 beq dio_cts1581 lda #DEV_NOT_FOUND ; unknown device ldx #0 beq ret dio_ctsend: ldy #1 lda tmp2 sta (ptr1),y dey lda tmp1 sta (ptr1),y ldx #0 txa ret: sta __oserror rts ; return success ; errors _inv_data: lda #INV_TRACK .byte $2c _inv_hand: lda #INCOMPATIBLE ldx #0 beq ret ; device-depended stuff, tmp1=track-1, tmp2=sector dio_cts1541: ldy tmp1 cpy #35 bcs _inv_data lda sectab_1541_l,y clc adc tmp2 sta tmp1 lda sectab_1541_h,y adc #0 sta tmp2 jmp dio_ctsend dio_cts1571: lda tmp1 cmp #70 bcs _inv_data cmp #35 ; last track of one side bcs _sub35 jmp dio_cts1541 ; track <=35 - same as 1541 _sub35: sec sbc #35 sta tmp1 jsr dio_cts1541 ; get offset on second side of disk lda tmp1 ; add second side base clc adc #<683 sta tmp1 lda tmp2 adc #>683 sta tmp2 jmp dio_ctsend dio_cts1581: ; 1581 has 80 tracks, 40 sectors each secnum=track*40+sector ldx #0 stx tmp3 stx tmp4 lda tmp1 beq _nomult cmp #80 bcs _inv_data ; mul40 by Christian Groessler sta tmp4 asl a rol tmp3 asl a rol tmp3 ; val * 4 adc tmp4 bcc L1 inc tmp3 ; val * 5 L1: asl a rol tmp3 ; val * 10 asl a rol tmp3 asl a rol tmp3 ; val * 40 = AX ldx tmp3 sta tmp3 stx tmp4 _nomult: lda tmp2 clc adc tmp3 sta tmp1 lda tmp4 adc #0 sta tmp2 jmp dio_ctsend .endproc .rodata sectab_1541_l: .byte $00, $15, $2a, $3f, $54, $69, $7e, $93 .byte $a8, $bd, $d2, $e7, $fc, $11, $26, $3b .byte $50, $65, $78, $8b, $9e, $b1, $c4, $d7 .byte $ea, $fc, $0e, $20, $32, $44, $56, $67 .byte $78, $89, $9a, $ab sectab_1541_h: .byte $00, $00, $00, $00, $00, $00, $00, $00 .byte $00, $00, $00, $00, $00, $01, $01, $01 .byte $01, $01, $01, $01, $01, $01, $01, $01 .byte $01, $01, $02, $02, $02, $02, $02, $02 .byte $02, $02, $02, $02
wagiminator/C64-Collection
2,680
C64_xu1541/software/tools/cc65-2.13.2/libsrc/geos/disk/dio_stc.s
; ; Maciej 'YTM/Elysium' Witkowiak ; 2.7.2001 ; ; 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 .importzp ptr1,ptr2,ptr3,tmp1,tmp2 .import popax,__oserror .import sectab_1541_l, sectab_1541_h .include "../inc/dio.inc" .include "../inc/geossym.inc" .include "../inc/const.inc" .proc _dio_log_to_phys ; check device type sta ptr1 stx ptr1+1 ; pointer to result (struct dio_phys_pos) jsr popax sta ptr2 stx ptr2+1 ; pointer to input structure (pointer to int) 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 ; fill in all we have ldy #diopp_head lda #0 ; head 0 sta (ptr1),y ldy #diopp_track+1 sta (ptr1),y ; track <256 ldy #diopp_sector+1 sta (ptr1),y ; sector <256 ldy #0 lda (ptr2),y sta tmp1 iny lda (ptr2),y sta tmp2 ; get drive info ldy #sst_driveno lda (ptr3),y tay lda driveType,y and #%00000011 ; this is for RamDrive compatibility cmp #DRV_1541 beq dio_stc1541 cmp #DRV_1571 beq dio_stc1571 cmp #DRV_1581 beq dio_stc1581 lda #DEV_NOT_FOUND ; unknown device ldx #0 beq _ret dio_stcend: ldy #diopp_track lda tmp1 sta (ptr1),y ldy #diopp_sector lda tmp2 sta (ptr1),y ldx #0 txa _ret: sta __oserror rts ; return success ; errors _inv_data: lda #INV_TRACK .byte $2c _inv_hand: lda #INCOMPATIBLE ldx #0 beq _ret dio_stc1541: ; if 1541: ; - compare with table to find track ; - subtract and find sector ldx #0 ; index=(track-1) _loop41: lda tmp2 cmp sectab_1541_h+1,x bne _nxt lda tmp1 cmp sectab_1541_l+1,x bcc _found _nxt: inx cpx #35 bne _loop41 beq _inv_data _found: lda tmp1 sec sbc sectab_1541_l,x sta tmp2 _fndend: inx stx tmp1 jmp dio_stcend dio_stc1571: ; if 1571: ; - check size, if too big - subtract and add 35 to track ; - fall down to 1541 lda tmp2 cmp #>683 bne _cnt71 lda tmp1 cmp #<683 bcc dio_stc1541 _cnt71: lda tmp1 sec sbc #<683 sta tmp1 lda tmp2 sbc #>683 sta tmp2 jsr dio_stc1541 ; will fall through here ldy #diopp_track lda (ptr1),y clc adc #35 sta (ptr1),y lda #0 beq _ret ; if 1581: ; - subtract 40 in loop (at most 80 times) to find track ; - the remainder is sector dio_stc1581: ldx #0 ; index=(track-1) _loop81: lda tmp2 bne _sub81 lda tmp1 cmp #40 bcc _got81 _sub81: lda tmp1 sec sbc #40 sta tmp1 lda tmp2 sbc #0 sta tmp2 inx cpx #81 bne _loop81 beq _inv_data _got81: lda tmp1 sta tmp2 inx stx tmp1 jmp dio_stcend .endproc
wagiminator/C64-Collection
3,563
C64_xu1541/software/tools/cc65-2.13.2/libsrc/geos/mousesprite/mouse.s
; ; Maciej 'YTM/Elysium' Witkowiak ; ; 2.7.2001 ; ; Wrapper for GEOS standard input device interface ; .export _mouse_init, _mouse_done .export _mouse_hide, _mouse_show .export _mouse_box .export _mouse_pos, _mouse_info .export _mouse_move, _mouse_buttons .import popsreg, addysp1 .importzp sp, sreg, ptr1 .include "../inc/const.inc" .include "../inc/jumptab.inc" .include "../inc/geossym.inc" .code ; -------------------------------------------------------------------------- ; ; unsigned char __fastcall__ mouse_init (unsigned char type); ; _mouse_init: jsr StartMouseMode jsr MouseOff lda #0 sta mouseTop sta mouseLeft sta mouseLeft+1 lda #199 sta mouseBottom lda graphMode bpl _mse_screen320 lda #<639 ; 80 columns on C128 ldx #>639 bne _mse_storex _mse_screen320: lda #<319 ; 40 columns on C64/C128 ldx #>319 _mse_storex: sta mouseRight stx mouseRight+1 _mse_initend: lda #0 tax ; -------------------------------------------------------------------------- ; ; void mouse_done (void); ; _mouse_done: rts ; -------------------------------------------------------------------------- ; ; void mouse_hide (void); ; _mouse_hide = MouseOff ; -------------------------------------------------------------------------- ; ; void mouse_show (void); ; _mouse_show = MouseUp ; -------------------------------------------------------------------------- ; ; void __fastcall__ mouse_box (int minx, int miny, int maxx, int maxy); ; _mouse_box: ldy #0 ; Stack offset sta mouseBottom lda (sp),y sta mouseRight iny lda (sp),y sta mouseRight+1 ; maxx iny lda (sp),y sta mouseTop iny ; Skip high byte iny lda (sp),y sta mouseLeft iny lda (sp),y sta mouseLeft+1 ; minx jmp addysp1 ; Drop params, return ; -------------------------------------------------------------------------- ; ; void __fastcall__ mouse_pos (struct mouse_pos* pos); ; /* Return the current mouse position */ ; _mouse_pos: sta ptr1 stx ptr1+1 ; Remember the argument pointer ldy #0 ; Structure offset php sei ; Disable interrupts lda mouseXPos ; Transfer the position sta (ptr1),y lda mouseXPos+1 iny sta (ptr1),y lda mouseYPos iny sta (ptr1),y lda #$00 iny sta (ptr1),y plp ; Reenable interrupts rts ; Done ; -------------------------------------------------------------------------- ; ; void __fastcall__ mouse_info (struct mouse_info* info); ; /* Return the state of the mouse buttons and the position of the mouse */ ; _mouse_info: ; 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. jsr _mouse_pos ; Fill in the button state jsr _mouse_buttons ; Will not touch ptr1 iny sta (ptr1),y rts ; -------------------------------------------------------------------------- ; ; void __fastcall__ mouse_move (int x, int y); ; _mouse_move: jsr popsreg ; Get X php sei ; Disable interrupts sta mouseYPos lda sreg ldx sreg+1 sta mouseXPos stx mouseXPos+1 plp ; Enable interrupts rts ; -------------------------------------------------------------------------- ; ; unsigned char mouse_buttons (void); ; _mouse_buttons: ldx #0 lda pressFlag and #SET_MOUSE lsr rts
wagiminator/C64-Collection
1,951
C64_xu1541/software/tools/cc65-2.13.2/libsrc/geos/conio/cputc.s
; ; Maciej 'YTM/Elysium' Witkowiak ; ; 27.10.2001 ; 06.03.2002 ; 25.07.2005 ; void cputcxy (unsigned char x, unsigned char y, char c); ; void cputc (char c); ; TODO: ; TAB (should be implemented) ; other special characters directly from keyboard are unsafe, though some might be ; implemented: ; HOME, UPLINE, ULINEON, ULINEOFF, REV_ON, REV_OFF, BOLDON, ITALICON, OUTLINEON, PLAINTEXT ; and cursor movement, maybe stuff like INSERT too ; ; these must be ignored: ; ESC_GRAPHICS, ESC_RULER, GOTOX, GOTOY, GOTOXY, NEWCARDSET, all 1..8 ; ; note that there are conflicts between control characters and keyboard: ; HOME = KEY_ENTER, KEY_HOME = REV_ON, ; UPLINE = ?, KEY_UPARROW = GOTOY, ... .export _cputcxy, _cputc, update_cursor .import _gotoxy, fixcursor .import popa .import xsize,ysize .importzp cursor_x, cursor_y, cursor_c, cursor_r .include "../inc/const.inc" .include "../inc/geossym.inc" .include "../inc/jumptab.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: tax ; save character ; some characters 0-31 are not safe for PutChar cmp #$20 bcs L1 cmp #CR beq do_cr cmp #LF beq do_lf cmp #KEY_DELETE bne L0 ldx #BACKSPACE sec bcs L2 L0: rts L1: clc L2: php lda cursor_x sta r11L lda cursor_x+1 sta r11H lda cursor_y sta r1H txa jsr PutChar plp bcs update_cursor inc cursor_c lda cursor_c cmp xsize ; hit right margin? bne update_cursor lda #0 ; yes - do cr+lf sta cursor_c do_lf: inc cursor_r lda cursor_r cmp ysize ; hit bottom margin? bne update_cursor dec cursor_r ; yes - stay in the last line update_cursor: jsr fixcursor lda cursor_x sta r4L lda cursor_x+1 sta r4H lda cursor_y sec sbc curHeight sta r5L lda #1 ; update cursor prompt position sta r3L jmp PosSprite do_cr: lda #0 sta cursor_c beq update_cursor
wagiminator/C64-Collection
18,273
C64_xu1541/software/tools/cc65-2.13.2/libsrc/geos/devel/geos-tgi.s
; ; Graphics driver for the 320x200x2 or 640x200x2 mode on GEOS 64/128 ; Maciej 'YTM/Elysium' Witkowiak <ytm@elysium.pl> ; 28-31.12.2002 .include "zeropage.inc" .include "tgi-kernel.inc" .include "tgi-mode.inc" .include "tgi-error.inc" .include "../inc/const.inc" .include "../inc/jumptab.inc" .include "../inc/geossym.inc" .include "../inc/geossym2.inc" .macpack generic ; ------------------------------------------------------------------------ ; Constants VDC_ADDR_REG = $D600 ; VDC address VDC_DATA_REG = $D601 ; VDC data VDC_DSP_HI = 12 ; registers used VDC_DSP_LO = 13 VDC_DATA_HI = 18 VDC_DATA_LO = 19 VDC_VSCROLL = 24 VDC_HSCROLL = 25 VDC_COLORS = 26 VDC_CSET = 28 VDC_COUNT = 30 VDC_DATA = 31 ; ------------------------------------------------------------------------ ; 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 xres: .word 320 ; X resolution yres: .word 200 ; Y resolution .byte 2 ; Number of drawing colors pages: .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). .word INSTALL .word UNINSTALL .word INIT .word DONE .word GETERROR .word CONTROL .word CLEAR .word SETVIEWPAGE .word SETDRAWPAGE .word SETCOLOR .word SETPALETTE .word GETPALETTE .word GETDEFPALETTE .word SETPIXEL .word GETPIXEL .word LINE .word BAR .word CIRCLE .word TEXTSTYLE .word OUTTEXT ; ------------------------------------------------------------------------ ; 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 ADDR = tmp1 TEMP = tmp3 TEMP2 = tmp4 TEMP3 = sreg TEMP4 = sreg+1 ; Circle stuff 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 ; Absolute variables used in the code .bss SCRBASE: .res 1 ; High byte of screen base (64k VDC only) ERROR: .res 1 ; Error code PALETTE: .res 2 ; The current palette BITMASK: .res 1 ; $00 = clear, $01 = set pixels OLDCOLOR: .res 1 ; colors before entering gfx mode ; Line routine stuff (combined with CIRCLE to save space) OGora: .res 2 OUkos: .res 2 Y3: .res 2 ; Text output stuff TEXTMAGX: .res 1 TEXTMAGY: .res 1 TEXTDIR: .res 1 ; Constants and tables .rodata DEFPALETTE: .byte $00, $0f ; White on black PALETTESIZE = * - DEFPALETTE ; color translation table (indexed by VIC color) COLTRANS: .byte $00, $0f, $08, $06, $0a, $04, $02, $0c .byte $0d, $0b, $09, $01, $0e, $05, $03, $07 ; colors BROWN and GRAY3 are wrong .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: lda version ; if GEOS 1.0... and #$f0 cmp #$10 beq @L40 lda c128Flag ; at least GEOS 2.0, but we're on C128? bpl @L40 lda graphMode ; GEOS 2.0, C128, but is 80 column screen enabled? bmi @L80 @L40: rts ; leave default values for 40 column screen ; check for VDC version and update register $19 value @L80: lda #<640 ldx #>640 sta xres stx xres+1 ; update number of available screens ldx #VDC_CSET ; determine size of RAM... jsr VDCReadReg sta tmp1 ora #%00010000 jsr VDCWriteReg ; turn on 64k jsr settestadr1 ; save original value of test byte jsr VDCReadByte 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 VDCWriteByte ; 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 VDCWriteReg ; restore 16/64k flag jmp @endok ; and leave default values for 16k @have64k: lda #4 sta pages @endok: lda #0 sta SCRBASE ; draw page 0 as default rts test64k: sta tmp1 sty ptr3 lda #0 sta ptr3+1 jsr settestadr1 lda tmp1 jsr VDCWriteByte ; write $55 jsr settestadr1 jsr VDCReadByte ; read here pha jsr settestadr2 jsr VDCReadByte ; 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 VDCSetSourceAddr ; ------------------------------------------------------------------------ ; 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: ldx #$01 stx BITMASK ; solid black as pattern lda #1 jsr SetPattern lda #ST_WR_FORE ; write only on foreground sta dispBufferOn lda graphMode bmi @L80 ; Remember current color value (40 columns) lda screencolors sta OLDCOLOR jmp @L99 ; Remember current color value (80 columns) @L80: lda scr80colors sta OLDCOLOR @L99: lda #0 jsr SETVIEWPAGE ; switch into viewpage 0 ; 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 #0 jsr SETVIEWPAGE ; switch into viewpage 0 lda graphMode bmi @L80 lda OLDCOLOR sta screencolors ; restore color for 40 columns ldx #0 @L1: sta COLOR_MATRIX,x sta COLOR_MATRIX+$0100,x sta COLOR_MATRIX+$0200,x sta COLOR_MATRIX+1000-256,x inx bne @L1 rts @L80: lda OLDCOLOR ; restore color for 80 columns ldx #VDC_COLORS jmp VDCWriteReg ; ------------------------------------------------------------------------ ; 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: lda curPattern pha lda #0 jsr SetPattern ldx #0 stx r3L stx r3H stx r2L lda #199 sta r2H lda graphMode bpl @L40 lda #>639 ; 80 columns ldx #<639 bne @L99 @L40: lda #>319 ; 40 columns ldx #<319 @L99: sta r4H stx r4L jsr Rectangle pla sta curPattern 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: ldx graphMode bmi @L80 rts @L80: clc ror ror ror ldx #VDC_DSP_HI jmp VDCWriteReg ; ------------------------------------------------------------------------ ; 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: ldx graphMode bmi @L80 rts @L80: clc ror ror ror sta SCRBASE 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 #1 @L1: sta BITMASK jmp SetPattern ; need to have either 0 or 1 ; ------------------------------------------------------------------------ ; 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: jsr GETERROR ; clear error (if any) ldy #PALETTESIZE - 1 @L1: lda (ptr1),y ; Copy the palette and #$0F ; Make a valid color sta PALETTE,y dey bpl @L1 ; Put colors from palette into screen lda graphMode bmi @L80 lda PALETTE+1 ; foreground asl a asl a asl a asl a ora PALETTE ; background ldx #0 @L2: sta COLOR_MATRIX,x sta COLOR_MATRIX+$0100,x sta COLOR_MATRIX+$0200,x sta COLOR_MATRIX+1000-256,x inx bne @L2 rts @L80: ldy PALETTE+1 ; Foreground color lda COLTRANS,y asl a asl a asl a asl a ldy PALETTE ; Background color ora COLTRANS,y ldx #VDC_COLORS jmp VDCWriteReg ; ------------------------------------------------------------------------ ; 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 ; SETPIXELCLIP: lda Y1+1 bmi @finito ; y<0 lda X1+1 bmi @finito ; x<0 lda X1 ldx X1+1 sta ADDR stx ADDR+1 ldx #ADDR lda xres ldy xres+1 jsr icmp ; ( x < xres ) ... bcs @finito lda Y1 ldx Y1+1 sta ADDR stx ADDR+1 ldx #ADDR lda yres ldy yres+1 jsr icmp ; ... && ( y < yres ) bcc SETPIXEL @finito:rts SETPIXEL: lda X1 ldx X1+1 ldy Y1 sta r3L stx r3H sty r11L sec lda BITMASK ; set or clear C flag bne @L1 clc @L1: lda #0 jmp DrawPoint ; ------------------------------------------------------------------------ ; 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: lda X1 ldx X1+1 ldy Y1 sta r3L stx r3H sty r11L jsr TestPoint ldx #0 bcc @L1 inx @L1: txa ldx #0 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: lda X1 ldx X1+1 ldy Y1 sta r3L stx r3H sty r11L lda X2 ldx X2+1 ldy Y2 sta r4L stx r4H sty r11H sec lda BITMASK ; set or clear C flag bne @L1 clc @L1: lda #0 jmp DrawLine ; ------------------------------------------------------------------------ ; 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: lda X1 ldx X1+1 ldy Y1 sta r3L stx r3H sty r2L lda X2 ldx X2+1 ldy Y2 sta r4L stx r4H sty r2H jmp Rectangle ; ------------------------------------------------------------------------ ; 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 @L1 jmp SETPIXELCLIP ; Plot as a point @L1: sta XX ; x = r; lda #0 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) { @L013B: ldx #YY lda XX ldy XX+1 jsr icmp bcc @L12 rts @L12: ; plot points in 8 slices... lda XS clc adc XX sta X1 lda XS+1 adc XX+1 sta X1+1 ; x1 = xs+x lda YS clc adc 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 sec sbc 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 sec sbc 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 clc adc YY sta X1 lda XS+1 adc YY+1 sta X1+1 ; x1 = xs+y lda YS clc adc 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 sec sbc 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 sec sbc 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 clc adc YY tay txa adc YY+1 tax tya clc adc YY tay txa adc YY+1 tax tya clc adc #1 bcc @L0143 inx @L0143: sta OGora stx OGora+1 ; ou = og-x-x+1 sec sbc XX tay txa sbc XX+1 tax tya sec sbc XX tay txa sbc XX+1 tax tya clc adc #1 bcc @L0146 inx @L0146: sta OUkos stx OUkos+1 ; ++y inc YY bne @L0148 inc YY+1 @L0148: ; 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 @L0149 ; { --x; sec lda XX sbc #1 sta XX bcs @L014E dec XX+1 @L014E: ; mo = ou; } lda OUkos ldx OUkos+1 jmp @L014G ; else { mo = og } @L0149: lda OGora ldx OGora+1 @L014G: sta MaxO stx MaxO+1 ; } jmp @L013B ; ------------------------------------------------------------------------ ; 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: lda TEXTDIR ; cmp #TGI_TEXT_HORIZONTAL ; this is equal 0 bne @vertical lda X1 ; horizontal text output ldx X1+1 ldy Y1 sta r11L stx r11H sty r1H lda ptr3 ldx ptr3+1 sta r0L stx r0H jmp PutString @vertical: lda X1 ; vertical text output ldx X1+1 ldy Y1 sta r11L stx r11H sty r1H ldy #0 lda (ptr3),y beq @end jsr PutChar inc ptr3 bne @L1 inc ptr3+1 @L1: lda Y1 clc adc #8 sta Y1 bne @vertical @end: rts ;------------- ; copies of some runtime routines abs: ; a/y := abs(a/y) dey iny bpl @L1 ; negay clc eor #$ff adc #1 pha tya eor #$ff adc #0 tay pla @L1: rts icmp: ; compare a/y to zp,x sta TEMP ; TEMP/TEMP2 - arg2 sty TEMP2 lda $0,x pha lda $1,x tay pla tax tya ; x/a - arg1 (a=high) sec sbc TEMP2 bne @L4 cpx TEMP beq @L3 adc #$ff ora #$01 @L3: rts @L4: bvc @L3 eor #$ff ora #$01 rts ;------------- ; VDC helpers VDCSetSourceAddr: pha tya ldx #VDC_DATA_HI jsr VDCWriteReg pla ldx #VDC_DATA_LO bne VDCWriteReg VDCReadByte: ldx #VDC_DATA VDCReadReg: stx VDC_ADDR_REG @L0: bit VDC_ADDR_REG bpl @L0 lda VDC_DATA_REG rts VDCWriteByte: ldx #VDC_DATA VDCWriteReg: stx VDC_ADDR_REG @L0: bit VDC_ADDR_REG bpl @L0 sta VDC_DATA_REG rts
wagiminator/C64-Collection
3,447
C64_xu1541/software/tools/cc65-2.13.2/libsrc/geos/devel/fio_module.s
; ; Low level file I/O routines, ONLY for module loading OR sth similar ; ; Maciej 'YTM/Elysium' Witkowiak <ytm@elysium.pl> ; 25.12.2002 ; ; only ONE opened file at a time, only O_RDONLY flag ; int open (const char* name, int flags, ...); /* May take a mode argument */ ; int __fastcall__ close (int fd); ; int __fastcall__ read (int fd, void* buf, unsigned count); FILEDES = 3 ; first free to use file descriptor .include "../inc/geossym.inc" .include "../inc/const.inc" .include "fcntl.inc" .importzp ptr1, ptr2, ptr3, tmp1 .import addysp, popax .import __oserror .import _FindFile, _ReadByte .export _open, _close, _read ;-------------------------------------------------------------------------- ; _open _open: cpy #4 ; correct # of arguments (bytes)? beq @parmok ; parameter count ok tya ; parm count < 4 shouldn't be needed to be... sec ; ...checked (it generates a c compiler warning) sbc #4 tay jsr addysp ; fix stack, throw away unused parameters ; Parameters ok. Pop the flags and save them into tmp3 @parmok: jsr popax ; Get flags sta tmp1 jsr popax ; Get name sta ptr1 stx ptr1+1 lda filedesc ; is there a file already open? bne @alreadyopen lda tmp1 ; check open mode and #(O_RDWR | O_CREAT) cmp #O_RDONLY ; only O_RDONLY is valid bne @badmode lda ptr1 ldx ptr1+1 jsr _FindFile ; try to find the file tax bne @error lda dirEntryBuf + OFF_DE_TR_SC ; tr&se for ReadByte (r1) sta f_track lda dirEntryBuf + OFF_DE_TR_SC + 1 sta f_sector lda #<diskBlkBuf ; buffer for ReadByte (r4) sta f_buffer lda #>diskBlkBuf sta f_buffer+1 ldx #0 ; offset for ReadByte (r5) stx f_offset stx f_offset+1 lda #FILEDES ; return fd sta filedesc rts @badmode: @alreadyopen: lda #70 ; no channel sta __oserror @error: lda #$ff tax rts _close: lda #0 ; clear fd sta filedesc tax rts _read: ; a/x - number of bytes ; popax - buffer ptr ; popax - fd, must be == to the above one ; return -1+__oserror or number of bytes read eor #$ff sta ptr1 txa eor #$ff sta ptr1+1 ; -(# of bytes to read)-1 jsr popax sta ptr2 stx ptr2+1 ; buffer ptr jsr popax cmp #FILEDES bne @notopen txa bne @notopen ; fd must be == FILEDES lda #0 sta ptr3 sta ptr3+1 ; put 0 into ptr3 (number of bytes read) lda f_track ; restore stuff for ReadByte ldx f_sector sta r1L stx r1H lda f_buffer ldx f_buffer+1 sta r4L stx r4H lda f_offset ldx f_offset+1 sta r5L stx r5H clc bcc @L3 ; branch always @L0: jsr _ReadByte ldy #0 ; store the byte sta (ptr2),y inc ptr2 ; increment target address bne @L1 inc ptr2+1 @L1: inc ptr3 ; increment byte count bne @L2 inc ptr3+1 @L2: lda __oserror ; was there error ? beq @L3 cmp #BFR_OVERFLOW ; EOF? bne @error beq @done @L3: inc ptr1 ; decrement the count bne @L0 inc ptr1+1 bne @L0 @done: lda r1L ; preserve data for ReadByte ldx r1H sta f_track stx f_sector lda r4L ldx r4H sta f_buffer stx f_buffer+1 lda r5L ldx r5H sta f_offset stx f_offset+1 lda ptr3 ; return byte count ldx ptr3+1 rts @notopen: lda #61 ; File not open @error: sta __oserror lda #$ff tax rts .bss filedesc: .res 1 ; file open flag - 0 (no file opened) or 1 f_track: .res 1 ; values preserved for ReadByte f_sector: .res 1 f_offset: .res 2 f_buffer: .res 2
wagiminator/C64-Collection
1,582
C64_xu1541/software/tools/cc65-2.13.2/libsrc/geos/devel/mainargs.s
; ; Ullrich von Bassewitz, 2003-03-07 ; Maciej Witkowiak, 2003-05-02 ; ; Setup arguments for main ; ; There is always either 1 or 3 arguments: ; <program name>,0 ; or ; <program name>, <data file name>, <data disk name>, 0 ; the 2nd case is when using DeskTop user drags an icon of a file and drops it ; on icon of your application ; .constructor initmainargs, 24 .import __argc, __argv .include "../inc/const.inc" .include "../inc/geossym.inc" ;--------------------------------------------------------------------------- ; Setup arguments for main .segment "INIT" .proc initmainargs ; Setup a pointer to our argv vector lda #<argv sta __argv lda #>argv sta __argv+1 ; Copy program name ldy #0 @fn_loop: lda dirEntryBuf+OFF_FNAME,y cmp #$a0 beq @fn_end sta argv0,y iny cpy #16+1 bne @fn_loop @fn_end: lda #0 sta argv0,y sta __argc+1 ; Check if there are any more arguments lda dataFileName bne @threeargs ldx #0 ; no dataFileName - NULL the 2nd argument stx argv+2 stx argv+3 inx ; there is only one argument bne @setargc @threeargs: ldx #3 ; there are three arguments @setargc: stx __argc rts .endproc ;--------------------------------------------------------------------------- ; Data .data argv: .word argv0 ; Pointer to program name .word dataFileName ; dataFileName or NULL if last one .word dataDiskName ; dataDiskName .word $0000 ; last one must be NULL .bss argv0: .res 17 ; Program name
wagiminator/C64-Collection
8,098
C64_xu1541/software/tools/cc65-2.13.2/libsrc/geos/devel/geos-vdc.s
; ; Extended memory driver for the VDC RAM available on all C128 machines ; version for GEOS enters safe I/O config on C64 (transparent on C128) ; ; Maciej 'YTM/Elysium' Witkowiak <ytm@elysium.pl> ; 06,20,25.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??? php sei lda $01 pha lda #$35 sta $01 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: pla sta $01 plp 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: php sei lda $01 pha lda #$35 sta $01 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 pla sta $01 plp 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: php sei lda $01 pha lda #$35 sta $01 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 pla sta $01 plp 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 php sei lda $01 pha lda #$35 sta $01 ldy #0 @L3: jsr vdcgetbyte sta (ptr2),y iny dec tmp1 lda tmp1 bne @L3 pla sta $01 plp @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 php sei lda $01 pha lda #$35 sta $01 ldy #0 @L3: lda (ptr2),y jsr vdcputbyte iny dec tmp1 lda tmp1 bne @L3 pla sta $01 plp @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,521
C64_xu1541/software/tools/cc65-2.13.2/libsrc/geos/devel/oserror.s
; ; Ullrich von Bassewitz, 17.05.2000 ; GEOS port: Maciej 'YTM/Elysium' Witkowiak ; 2.7.2001 ; ; int __fastcall__ _osmaperrno (unsigned char oserror); ; /* Map a system specific error into a system independent code */ ; .export __osmaperrno .include "errno.inc" .include "../inc/const.inc" .code __osmaperrno: ldx #ErrTabSize @L1: cmp ErrTab-2,x ; Search for the error code beq @L2 ; Jump if found dex dex bne @L1 ; Next entry ; Code not found, return EINVAL lda #<EINVAL ldx #>EINVAL rts ; Found the code @L2: lda ErrTab-1,x ldx #$00 ; High byte always zero rts .rodata ErrTab: .byte NO_BLOCKS, EINVAL ; ??? .byte INV_TRACK, EINVAL ; invalid track&sector pair .byte INSUFF_SPACE, ENOSPC ; out of space .byte FULL_DIRECTORY, ENOSPC ; directory is full .byte FILE_NOT_FOUND, ENOENT ; file not found .byte BAD_BAM, EIO ; bam inconsistent .byte UNOPENED_VLIR, EINVAL ; using VLIR file without opening .byte INV_RECORD, EINVAL ; using >128 VLIR record number .byte OUT_OF_RECORDS, ENOSPC ; cannot insert/add record .byte STRUCT_MISMAT, EINVAL ; ??? .byte BFR_OVERFLOW, ENOMEM ; file longer than buffer or end of file .byte CANCEL_ERR, EIO ; ??? .byte DEV_NOT_FOUND, ENODEV ; device not found .byte INCOMPATIBLE, EINVAL ; ??? ; .byte 20, ; Read error ; .byte 21, ; Read error ; .byte 22, ; Read error ; .byte 23, ; Read error ; .byte 24, ; Read error ; .byte 25, ; Write error .byte 26, EACCES ; Write protect on ; .byte 27, ; Read error ; .byte 28, ; Write error ; .byte 29, ; Disk ID mismatch ; .byte 30, ; Syntax error ; .byte 31, ; Syntax error ; .byte 32, ; Syntax error .byte 33, EINVAL ; Syntax error (invalid file name) .byte 34, EINVAL ; Syntax error (no file given) ; .byte 39, ; Syntax error ; .byte 50, ; Record not present ; .byte 51, ; Overflow in record ; .byte 52, ; File too large .byte 60, EINVAL ; Write file open .byte 61, EINVAL ; File not open .byte 62, ENOENT ; File not found .byte 63, EEXIST ; File exists .byte 64, EINVAL ; File type mismatch ; .byte 65, ; No block ; .byte 66, ; Illegal track or sector ; .byte 67, ; Illegal system track or sector .byte 70, EBUSY ; No channel ; .byte 71, ; Directory error ; .byte 72, ; Disk full ; .byte 73, ; DOS version mismatch ErrTabSize = (* - ErrTab)
wagiminator/C64-Collection
2,793
C64_xu1541/software/tools/cc65-2.13.2/libsrc/geos/devel/geos-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 "../inc/geossym.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 ; Future expansion .byte $00 ; Future expansion .byte $00 ; Future expansion ; Jump table. .word INSTALL .word UNINSTALL .word COUNT .word READ ; ------------------------------------------------------------------------ ; Constants JOY_COUNT = 2 ; Number of joysticks we support ; ------------------------------------------------------------------------ ; Data. .code ; ------------------------------------------------------------------------ ; INSTALL routine. Is called after the driver is loaded into memory. If ; possible, check if the hardware is present and determine the amount of ; memory available. ; Must return an JOY_ERR_xx code in a/x. ; INSTALL: lda #<JOY_ERR_OK ldx #>JOY_ERR_OK ; rts ; Run into UNINSTALL instead ; ------------------------------------------------------------------------ ; UNINSTALL routine. Is called before the driver is removed from memory. ; Can do cleanup or whatever. Must not return anything. ; UNINSTALL: rts ; ------------------------------------------------------------------------ ; COUNT: Return the total number of available joysticks in a/x. ; COUNT: lda #<JOY_COUNT ldx #>JOY_COUNT rts ; ------------------------------------------------------------------------ ; READ: Read a particular joystick passed in A. ; READ: tax php sei ; disable IRQ lda $01 pha lda #$35 sta $01 ; enable I/O txa ; Joystick number into X bne joy2 ; Read joystick 1 joy1: lda #$7F sta cia1base lda cia1base+1 back: tay pla sta $01 plp tya and #$1F eor #$1F rts ; Read joystick 2 joy2: ldx #0 lda #$E0 ldy #$FF sta cia1base+2 lda cia1base+1 sty cia1base+2 jmp back
wagiminator/C64-Collection
3,763
C64_xu1541/software/tools/cc65-2.13.2/libsrc/geos/devel/oserrlist.s
; ; Maciej 'YTM/Elysium' Witkowiak <ytm@elysium.pl> ; 25.12.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. ; .include "../inc/const.inc" .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 NO_BLOCKS, "No free blocks" sys_oserr_entry INV_TRACK, "Illegal track or sector" sys_oserr_entry INSUFF_SPACE, "Disk full" sys_oserr_entry FULL_DIRECTORY, "Directory full" sys_oserr_entry FILE_NOT_FOUND, "File not found" sys_oserr_entry BAD_BAM, "Inconsistent BAM" sys_oserr_entry UNOPENED_VLIR, "VLIR file not opened" sys_oserr_entry INV_RECORD, "Invalid VLIR record" sys_oserr_entry OUT_OF_RECORDS, "Out of VLIR records" sys_oserr_entry STRUCT_MISMAT, "Structure mismatch" sys_oserr_entry BFR_OVERFLOW, "Buffer overflow" sys_oserr_entry CANCEL_ERR, "Operation cancelled" sys_oserr_entry DEV_NOT_FOUND, "Device not found" sys_oserr_entry INCOMPATIBLE, "Incompatible device" sys_oserr_entry 20, "Read error" sys_oserr_entry 21, "Read error" sys_oserr_entry 22, "Read error" sys_oserr_entry 23, "Read error" sys_oserr_entry 24, "Read error" sys_oserr_entry 25, "Write error" sys_oserr_entry 26, "Write protect on" sys_oserr_entry 27, "Read error" sys_oserr_entry 28, "Write error" sys_oserr_entry 29, "Disk ID mismatch" sys_oserr_entry 30, "Syntax error" sys_oserr_entry 31, "Syntax error" sys_oserr_entry 32, "Syntax error" sys_oserr_entry 33, "Syntax error (invalid file name)" sys_oserr_entry 34, "Syntax error (no file given)" sys_oserr_entry 39, "Syntax error" sys_oserr_entry 50, "Record not present" sys_oserr_entry 51, "Overflow in record" sys_oserr_entry 52, "File too large" sys_oserr_entry 60, "Write file open" sys_oserr_entry 61, "File not open" sys_oserr_entry 62, "File not found" sys_oserr_entry 63, "File exists" sys_oserr_entry 64, "File type mismatch" sys_oserr_entry 65, "No block" sys_oserr_entry 66, "Illegal track or sector" sys_oserr_entry 67, "Illegal system track or sector" sys_oserr_entry 70, "No channel" sys_oserr_entry 71, "Directory error" sys_oserr_entry 72, "Disk full" sys_oserr_entry 73, "DOS version mismatch" sys_oserr_entry 74, "Drive not ready" sys_oserr_sentinel "Unknown error"
wagiminator/C64-Collection
1,438
C64_xu1541/software/tools/cc65-2.13.2/libsrc/geos/system/get_ostype.s
; ; Maciej 'YTM/Elysium' Witkowiak ; ; 10.09.2001 ; unsigned char get_ostype (void); ; unsigned char get_tv (void); .export _get_ostype .export _get_tv .importzp tmp1 .include "../inc/const.inc" .include "../inc/geossym.inc" .include "../inc/geossym2.inc" _get_ostype: ldx #0 lda version and #%11110000 cmp #$10 beq geos10 lda c128Flag ; we're on at least 2.0 ora version rts geos10: lda version rts _get_tv: jsr _get_ostype bpl only40 ; C64 with 40 columns only lda graphMode bpl only40 ; C128 but currently on 40 columns ldx #1 ; COLUMNS80 bne tvmode only40: ldx #0 ; COLUMNS40 tvmode: ; PAL/NTSC check here, result in A php sei ; disable interrupts lda CPU_DATA ; this is for C64 pha lda #IO_IN ; enable access to I/O sta CPU_DATA bit rasreg bpl tvmode ; wait for rasterline 127<x<256 lda #24 ; (rasterline now >=256!) modelp: cmp rasreg ; wait for rasterline = 24 (or 280 on PAL) bne modelp lda grcntrl1 ; 24 or 280 ? bpl ntsc lda #0 ; PAL beq modeend ntsc: lda #$80 ; NTSC modeend: stx tmp1 ora tmp1 sta tmp1 ldx #0 pla sta CPU_DATA ; restore memory config plp ; restore interrupt state lda tmp1 rts
wagiminator/C64-Collection
9,657
C64_xu1541/software/tools/cc65-2.13.2/libsrc/geos/system/ctype.s
; ; Ullrich von Bassewitz, 02.06.1998 ; Maciej Witkowiak, 06.04.2002 ; ; Character specification table. ; ; The tables are readonly, put them into the rodata segment .rodata ; Value that must be added to a lower case char to make it an upper case ; char (example: for ASCII, this must be $E0). .export __cdiff __cdiff: .byte $e0 ; 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 ; The table is taken from Craig S. Bruce technical docs for the ACE os .export __ctype __ctype: .byte $10 ; 0/00 ___rvs_@___ .byte $10 ; 1/01 ___rvs_a___ .byte $10 ; 2/02 ___rvs_b___ .byte $10 ; 3/03 ___rvs_c___ .byte $10 ; 4/04 ___rvs_d___ .byte $10 ; 5/05 ___rvs_e___ .byte $10 ; 6/06 ___rvs_f___ .byte $10 ; 7/07 _BEL/rvs_g_ .byte $10 ; 8/08 ___rvs_h___ .byte $D0 ; 9/09 _TAB/rvs_i_ .byte $50 ; 10/0a _BOL/rvs_j_ .byte $10 ; 11/0b ___rvs_k___ .byte $10 ; 12/0c ___rvs_l___ .byte $50 ; 13/0d _CR_/rvs_m_ .byte $10 ; 14/0e ___rvs_n___ .byte $10 ; 15/0f ___rvs_o___ .byte $10 ; 16/10 ___rvs_p___ .byte $50 ; 17/11 _VT_/rvs_q_ .byte $10 ; 18/12 ___rvs_r___ .byte $10 ; 19/13 ___rvs_s___ .byte $50 ; 20/14 _BS_/rvs_t_ .byte $10 ; 21/15 ___rvs_u___ .byte $10 ; 22/16 ___rvs_v___ .byte $10 ; 23/17 ___rvs_w___ .byte $10 ; 24/18 ___rvs_x___ .byte $10 ; 25/19 ___rvs_y___ .byte $10 ; 26/1a ___rvs_z___ .byte $10 ; 27/1b ___rvs_[___ .byte $10 ; 28/1c ___rvs_\___ .byte $10 ; 29/1d ___rvs_]___ .byte $10 ; 30/1e ___rvs_^___ .byte $10 ; 31/1f _rvs_under_ .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 $09 ; 65/41 _____a_____ .byte $09 ; 66/42 _____b_____ .byte $09 ; 67/43 _____c_____ .byte $09 ; 68/44 _____d_____ .byte $09 ; 69/45 _____e_____ .byte $09 ; 70/46 _____f_____ .byte $01 ; 71/47 _____g_____ .byte $01 ; 72/48 _____h_____ .byte $01 ; 73/49 _____i_____ .byte $01 ; 74/4a _____j_____ .byte $01 ; 75/4b _____k_____ .byte $01 ; 76/4c _____l_____ .byte $01 ; 77/4d _____m_____ .byte $01 ; 78/4e _____n_____ .byte $01 ; 79/4f _____o_____ .byte $01 ; 80/50 _____p_____ .byte $01 ; 81/51 _____q_____ .byte $01 ; 82/52 _____r_____ .byte $01 ; 83/53 _____s_____ .byte $01 ; 84/54 _____t_____ .byte $01 ; 85/55 _____u_____ .byte $01 ; 86/56 _____v_____ .byte $01 ; 87/57 _____w_____ .byte $01 ; 88/58 _____x_____ .byte $01 ; 89/59 _____y_____ .byte $01 ; 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 _A`_grave__ .byte $0a ; 97/61 _A'_acute__ .byte $0a ; 98/62 _A^_circum_ .byte $0a ; 99/63 _A~_tilde__ .byte $0a ; 100/64 _A"_dieres_ .byte $0a ; 101/65 _A__ring___ .byte $0a ; 102/66 _AE________ .byte $02 ; 103/67 _C,cedilla_ .byte $02 ; 104/68 _E`_grave__ .byte $02 ; 105/69 _E'_acute__ .byte $02 ; 106/6a _E^_circum_ .byte $02 ; 107/6b _E"_dieres_ .byte $02 ; 108/6c _I`_grave__ .byte $02 ; 109/6d _I'_acute__ .byte $02 ; 110/6e _I^_circum_ .byte $02 ; 111/6f _I"_dieres_ .byte $02 ; 112/70 _D-_Eth_lr_ .byte $02 ; 113/71 _N~_tilde__ .byte $02 ; 114/72 _O`_grave__ .byte $02 ; 115/73 _O'_acute__ .byte $02 ; 116/74 _O^_circum_ .byte $02 ; 117/75 _O~_tilde__ .byte $02 ; 118/76 _O"_dieres_ .byte $02 ; 119/77 __multiply_ .byte $02 ; 120/78 _O/_slash__ .byte $02 ; 121/79 _U`_grave__ .byte $02 ; 122/7a _U'_acute__ .byte $00 ; 123/7b _U^_circum_ .byte $00 ; 124/7c _U"_dieres_ .byte $00 ; 125/7d _Y'_acute__ .byte $00 ; 126/7e _cap_thorn_ .byte $00 ; 127/7f _Es-sed_B__ .byte $00 ; 128/80 __bullet___ .byte $00 ; 129/81 __v_line___ .byte $00 ; 130/82 __h_line___ .byte $00 ; 131/83 ___cross___ .byte $00 ; 132/84 _tl_corner_ .byte $00 ; 133/85 _tr_corner_ .byte $00 ; 134/86 _bl_corner_ .byte $00 ; 135/87 _br_corner_ .byte $00 ; 136/88 ___l_tee___ .byte $00 ; 137/89 ___r_tee___ .byte $00 ; 138/8a ___t_tee___ .byte $00 ; 139/8b ___b_tee___ .byte $00 ; 140/8c ___heart___ .byte $00 ; 141/8d __diamond__ .byte $00 ; 142/8e ___club____ .byte $00 ; 143/8f ___spade___ .byte $00 ; 144/90 _s_circle__ .byte $00 ; 145/91 __circle___ .byte $00 ; 146/92 ___pound___ .byte $00 ; 147/93 _CLS/check_ .byte $00 ; 148/94 ____pi_____ .byte $00 ; 149/95 ____+/-____ .byte $00 ; 150/96 __divide___ .byte $00 ; 151/97 __degree___ .byte $00 ; 152/98 _c_checker_ .byte $00 ; 153/99 _f_checker_ .byte $00 ; 154/9a _solid_sq__ .byte $00 ; 155/9b __cr_char__ .byte $00 ; 156/9c _up_arrow__ .byte $00 ; 157/9d _down_arro_ .byte $00 ; 158/9e _left_arro_ .byte $00 ; 159/9f _right_arr_ .byte $00 ; 160/a0 _req space_ .byte $00 ; 161/a1 _!_invertd_ .byte $00 ; 162/a2 ___cent____ .byte $00 ; 163/a3 ___pound___ .byte $00 ; 164/a4 __currency_ .byte $00 ; 165/a5 ____yen____ .byte $00 ; 166/a6 _|_broken__ .byte $00 ; 167/a7 __section__ .byte $00 ; 168/a8 __umulaut__ .byte $00 ; 169/a9 _copyright_ .byte $00 ; 170/aa __fem_ord__ .byte $00 ; 171/ab _l_ang_quo_ .byte $00 ; 172/ac ____not____ .byte $00 ; 173/ad _syl_hyphn_ .byte $00 ; 174/ae _registerd_ .byte $00 ; 175/af _overline__ .byte $00 ; 176/b0 __degrees__ .byte $00 ; 177/b1 ____+/-____ .byte $00 ; 178/b2 _2_supersc_ .byte $00 ; 179/b3 _3_supersc_ .byte $00 ; 180/b4 ___acute___ .byte $00 ; 181/b5 ____mu_____ .byte $00 ; 182/b6 _paragraph_ .byte $00 ; 183/b7 __mid_dot__ .byte $00 ; 184/b8 __cedilla__ .byte $00 ; 185/b9 _1_supersc_ .byte $00 ; 186/ba __mas_ord__ .byte $00 ; 187/bb _r_ang_quo_ .byte $00 ; 188/bc ____1/4____ .byte $00 ; 189/bd ____1/2____ .byte $00 ; 190/be ____3/4____ .byte $00 ; 191/bf _?_invertd_ .byte $00 ; 192/c0 _____`_____ .byte $00 ; 193/c1 _____A_____ .byte $00 ; 194/c2 _____B_____ .byte $00 ; 195/c3 _____C_____ .byte $00 ; 196/c4 _____D_____ .byte $00 ; 197/c5 _____E_____ .byte $00 ; 198/c6 _____F_____ .byte $00 ; 199/c7 _____G_____ .byte $00 ; 200/c8 _____H_____ .byte $00 ; 201/c9 _____I_____ .byte $00 ; 202/ca _____J_____ .byte $00 ; 203/cb _____K_____ .byte $00 ; 204/cc _____L_____ .byte $00 ; 205/cd _____M_____ .byte $00 ; 206/ce _____N_____ .byte $00 ; 207/cf _____O_____ .byte $00 ; 208/d0 _____P_____ .byte $00 ; 209/d1 _____Q_____ .byte $00 ; 210/d2 _____R_____ .byte $00 ; 211/d3 _____S_____ .byte $00 ; 212/d4 _____T_____ .byte $00 ; 213/d5 _____U_____ .byte $00 ; 214/d6 _____V_____ .byte $00 ; 215/d7 _____W_____ .byte $00 ; 216/d8 _____X_____ .byte $00 ; 217/d9 _____Y_____ .byte $00 ; 218/da _____Z_____ .byte $00 ; 219/db _____{_____ .byte $00 ; 220/dc _____|_____ .byte $00 ; 221/dd _____}_____ .byte $00 ; 222/de _____~_____ .byte $00 ; 223/df ___HOUSE___ .byte $00 ; 224/e0 _a`_grave__ .byte $00 ; 225/e1 _a'_acute__ .byte $00 ; 226/e2 _a^_circum_ .byte $00 ; 227/e3 _a~_tilde__ .byte $00 ; 228/e4 _a"_dieres_ .byte $00 ; 229/e5 _a__ring___ .byte $00 ; 230/e6 _ae________ .byte $00 ; 231/e7 _c,cedilla_ .byte $00 ; 232/e8 _e`_grave__ .byte $00 ; 233/e9 _e'_acute__ .byte $00 ; 234/ea _e^_circum_ .byte $00 ; 235/eb _e"_dieres_ .byte $00 ; 236/ec _i`_grave__ .byte $00 ; 237/ed _i'_acute__ .byte $00 ; 238/ee _i^_circum_ .byte $00 ; 239/ef _i"_dieres_ .byte $00 ; 240/f0 _o^x_Eth_s_ .byte $00 ; 241/f1 _n~_tilda__ .byte $00 ; 242/f2 _o`_grave__ .byte $00 ; 243/f3 _o'_acute__ .byte $00 ; 244/f4 _o^_circum_ .byte $00 ; 245/f5 _o~_tilde__ .byte $00 ; 246/f6 _o"_dieres_ .byte $00 ; 247/f7 __divide___ .byte $00 ; 248/f8 _o/_slash__ .byte $00 ; 249/f9 _u`_grave__ .byte $00 ; 250/fa _u'_acute__ .byte $00 ; 251/fb _u^_circum_ .byte $00 ; 252/fc _u"_dieres_ .byte $00 ; 253/fd _y'_acute__ .byte $00 ; 254/fe _sm_thorn__ .byte $00 ; 255/ff _y"_dieres_
wagiminator/C64-Collection
1,145
C64_xu1541/software/tools/cc65-2.13.2/samples/geos/ca65-vlir/vlir1.s
; Maciej 'YTM/Elysium' Witkowiak ; 06.06.2002 ; This is source for loadable VLIR-structured program part ; include some GEOS defines .include "../../../libsrc/geos/inc/const.inc" .include "../../../libsrc/geos/inc/jumptab.inc" .include "../../../libsrc/geos/inc/geossym.inc" .include "../../../libsrc/geos/inc/geosmac.ca65.inc" ; export names of functions that will be used in main program .export VLIR1_Function1 .export VLIR1_Function2 ; go into VLIR1 segment - everything that is here will go into ; VLIR chain #1 .segment "VLIR1" VLIR1_Function1: jmp Function1 ; jump table, not really necessary VLIR1_Function2: jmp Function2 ; etc. ; rodata - if this is defined in .segment "RODATA" ; it will end in VLIR0 part, you don't want that paramString: .byte DEF_DB_POS | 1 .byte DBTXTSTR, TXT_LN_X, TXT_LN_2_Y .word line1 .byte DBTXTSTR, TXT_LN_X, TXT_LN_3_Y .word line2 .byte OK, DBI_X_0, DBI_Y_2 .byte NULL line1: .byte "This is in module 1",0 line2: .byte "This is in module 1",0 ; code Function1: LoadW r0, paramString jsr DoDlgBox Function2: rts
wagiminator/C64-Collection
2,236
C64_xu1541/software/tools/cc65-2.13.2/samples/geos/ca65-vlir/vlir0.s
; Maciej 'YTM/Elysium' Witkowiak ; 06.06.2002 ; This is source for main VLIR-structured program part ; include some GEOS defines .include "../../../libsrc/geos/inc/const.inc" .include "../../../libsrc/geos/inc/jumptab.inc" .include "../../../libsrc/geos/inc/geossym.inc" .include "../../../libsrc/geos/inc/geosmac.ca65.inc" ; import load addresses for all VLIR chains ; by default they are all the same, but this is not required ; these labels are defined upon linking with ld65 - each segment has it .import __VLIR1_LOAD__ .import __VLIR2_LOAD__ ; import names of functions defined (and exported) in each VLIR part ; of your application ; here I used VLIRx_ prefix to prevent name clash .import VLIR1_Function1 .import VLIR2_Function2 ; segments "CODE", "DATA", "RODATA" and "BSS" all go to VLIR0 chain .segment "CODE" ; code segment for VLIR 0 chain ProgExec: LoadW r0, paramString ; show something jsr DoDlgBox MoveW dirEntryBuf+OFF_DE_TR_SC, r1 LoadW r4, fileHeader jsr GetBlock ; load back VLIR t&s table bnex error lda #1 jsr PointRecord ; we want next module (#1) LoadW r2, $ffff ; length - as many bytes as there are LoadW r7, __VLIR1_LOAD__ ; all VLIR segments have the same load address jsr ReadRecord ; load it bnex error jsr VLIR1_Function1 ; execute something lda #2 jsr PointRecord ; next module LoadW r2, $ffff LoadW r7, __VLIR2_LOAD__ jsr ReadRecord ; load it bnex error jsr VLIR2_Function2 ; execute something error: jmp EnterDeskTop ; end of application .segment "RODATA" ; read-only data segment paramString: .byte DEF_DB_POS | 1 .byte DBTXTSTR, TXT_LN_X, TXT_LN_2_Y .word line1 .byte DBTXTSTR, TXT_LN_X, TXT_LN_3_Y .word line2 .byte OK, DBI_X_0, DBI_Y_2 .byte NULL line1: .byte BOLDON, "Hello World!",0 line2: .byte OUTLINEON,"Hello",PLAINTEXT," world!",0 .segment "DATA" ; read/write initialized data segment counter: .word 0 .segment "BSS" ; read/write uninitialized data segment ; this space doesn't go into output file, only its size and ; position is remembered
wagiminator/C64-Collection
2,832
C64_xu1541/software/tools/opencbm-0.4.99.99/xu1541/firmware/memcpy.S
/* Copyright (c) 2002, 2007 Marek Michalkiewicz All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "macros.inc" #define dest_hi r25 #define dest_lo r24 #define src_hi r23 #define src_lo r22 #define len_hi r21 #define len_lo r20 /** \file */ /** \ingroup avr_string \fn void *memcpy(void *dest, const void *src, size_t len) \brief Copy a memory area. The memcpy() function copies len bytes from memory area src to memory area dest. The memory areas may not overlap. Use memmove() if the memory areas do overlap. \returns The memcpy() function returns a pointer to dest. */ #if !defined(__DOXYGEN__) .text .global _U(memcpy) .type _U(memcpy), @function _U(memcpy): X_movw ZL, src_lo X_movw XL, dest_lo #if OPTIMIZE_SPEED ; 15 words, (14 + len * 6 - (len & 1)) cycles sbrs len_lo, 0 rjmp .L_memcpy_start rjmp .L_memcpy_odd .L_memcpy_loop: ld __tmp_reg__, Z+ st X+, __tmp_reg__ .L_memcpy_odd: ld __tmp_reg__, Z+ st X+, __tmp_reg__ .L_memcpy_start: subi len_lo, lo8(2) sbci len_hi, hi8(2) #else ; 11 words, (13 + len * 8) cycles rjmp .L_memcpy_start .L_memcpy_loop: ld __tmp_reg__, Z+ st X+, __tmp_reg__ .L_memcpy_start: subi len_lo, lo8(1) sbci len_hi, hi8(1) #endif brcc .L_memcpy_loop ; return dest (unchanged) ret .L_memcpy_end: .size _U(memcpy), .L_memcpy_end - _U(memcpy) #endif /* not __DOXYGEN__ */
wagiminator/C64-Collection
5,298
C64_xu1541/software/tools/opencbm-0.4.99.99/xu1541/firmware/gcrt1.S
/* Copyright (c) 2002, Marek Michalkiewicz <marekm@amelek.gda.pl> All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #if (__GNUC__ < 3) || (__GNUC__ == 3 && __GNUC_MINOR__ < 3) #error "GCC version >= 3.3 required" #endif #include "macros.inc" .macro vector name .if (. - __vectors < _VECTORS_SIZE) .weak \name .set \name, __bad_interrupt XJMP \name .endif .endm .section .vectors,"ax",@progbits .global __vectors .func __vectors __vectors: XJMP init vector __vector_1 vector __vector_2 vector __vector_3 vector __vector_4 vector __vector_5 vector __vector_6 vector __vector_7 vector __vector_8 vector __vector_9 vector __vector_10 vector __vector_11 vector __vector_12 vector __vector_13 vector __vector_14 vector __vector_15 vector __vector_16 vector __vector_17 vector __vector_18 vector __vector_19 vector __vector_20 vector __vector_21 vector __vector_22 vector __vector_23 vector __vector_24 vector __vector_25 vector __vector_26 vector __vector_27 vector __vector_28 vector __vector_29 vector __vector_30 vector __vector_31 vector __vector_32 vector __vector_33 vector __vector_34 vector __vector_35 vector __vector_36 vector __vector_37 vector __vector_38 vector __vector_39 vector __vector_40 vector __vector_41 vector __vector_42 vector __vector_43 vector __vector_44 vector __vector_45 vector __vector_46 vector __vector_47 vector __vector_48 vector __vector_49 vector __vector_50 vector __vector_51 vector __vector_52 vector __vector_53 vector __vector_54 vector __vector_55 vector __vector_56 .endfunc /* Handle unexpected interrupts (enabled and no handler), which usually indicate a bug. Jump to the __vector_default function if defined by the user, otherwise jump to the reset address. This must be in a different section, otherwise the assembler will resolve "rjmp" offsets and there will be no relocs. */ .text .global __bad_interrupt .func __bad_interrupt __bad_interrupt: .weak __vector_default .set __vector_default, __vectors XJMP __vector_default .endfunc #if 0 #ifndef __AVR_ASM_ONLY__ .weak __stack /* By default, malloc() uses the current value of the stack pointer minus __malloc_margin as the highest available address. In some applications with external SRAM, the stack can be below the data section (in the internal SRAM - faster), and __heap_end should be set to the highest address available for malloc(). */ .weak __heap_end .set __heap_end, 0 .section .init2,"ax",@progbits clr __zero_reg__ out _SFR_IO_ADDR(SREG), __zero_reg__ ldi r28,lo8(__stack) #ifdef SPH ldi r29,hi8(__stack) out _SFR_IO_ADDR(SPH), r29 #endif out _SFR_IO_ADDR(SPL), r28 #if BIG_CODE /* Only for >64K devices with RAMPZ, replaces the default code provided by libgcc.S which is only linked in if necessary. */ .section .init4,"ax",@progbits .global __do_copy_data __do_copy_data: ldi r17, hi8(__data_end) ldi r26, lo8(__data_start) ldi r27, hi8(__data_start) ldi r30, lo8(__data_load_start) ldi r31, hi8(__data_load_start) /* On the enhanced core, "elpm" with post-increment updates RAMPZ automatically. Otherwise we have to handle it ourselves. */ #ifdef __AVR_ENHANCED__ ldi r16, hh8(__data_load_start) #else ldi r16, hh8(__data_load_start - 0x10000) .L__do_copy_data_carry: inc r16 #endif out _SFR_IO_ADDR(RAMPZ), r16 rjmp .L__do_copy_data_start .L__do_copy_data_loop: #ifdef __AVR_ENHANCED__ elpm r0, Z+ #else elpm #endif st X+, r0 #ifndef __AVR_ENHANCED__ adiw r30, 1 brcs .L__do_copy_data_carry #endif .L__do_copy_data_start: cpi r26, lo8(__data_end) cpc r27, r17 brne .L__do_copy_data_loop #endif /* BIG_CODE */ .set __stack, RAMEND #endif /* !__AVR_ASM_ONLY__ */ .section .init9,"ax",@progbits XCALL main XJMP exit ; .endfunc #endif