Merge remote-tracking branch 'origin/master' into coniopeek

This commit is contained in:
mrdudz
2022-07-24 03:24:45 +02:00
2250 changed files with 195541 additions and 36938 deletions

View File

@@ -1,7 +1,7 @@
;
; Ullrich von Bassewitz, 27.09.1998
;
; void set_brk (unsigned Addr);
; void __fastcall__ set_brk (unsigned Addr);
; void reset_brk (void);
;

28
libsrc/vic20/c_readst.s Normal file
View File

@@ -0,0 +1,28 @@
;
; 1999-06-03, Ullrich von Bassewitz
; 2021-01-12, Greg King
;
; unsigned char cbm_k_readst (void);
;
; This version works around a bug in VIC-20 Kernal's READST function.
;
.include "vic20.inc"
.include "../cbm/cbm.inc"
.export _cbm_k_readst
_cbm_k_readst:
ldx #>$0000
lda DEVNUM
cmp #CBMDEV_RS232
beq @L1
jmp READST
; Work-around: Read the RS-232 status variable directly.
@L1: lda RSSTAT
stx RSSTAT ; reset the status bits
rts

View File

@@ -7,6 +7,7 @@
.export _cgetc
.import cursor
.include "cbm_kernal.inc"
.include "vic20.inc"
_cgetc: lda KEY_COUNT ; Get number of characters
@@ -40,8 +41,7 @@ L3: jsr KBDREAD ; Read char and return in A
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
inc CURS_FLAG ; Mark it as off
lda CURS_STATE ; Cursor currently displayed?
beq crs8 ; Jump if no
ldy CURS_X ; Get the character column

View File

@@ -6,9 +6,6 @@
.export _clrscr
.include "vic20.inc"
.include "cbm_kernal.inc"
_clrscr = CLRSCR

View File

@@ -1,5 +1,6 @@
;
; Ullrich von Bassewitz, 06.08.1998
; 1998-08-06, Ullrich von Bassewitz
; 2020-10-09, Greg King
;
; void cputcxy (unsigned char x, unsigned char y, char c);
; void cputc (char c);
@@ -7,82 +8,96 @@
.export _cputcxy, _cputc, cputdirect, putchar
.export newline, plot
.import popa, _gotoxy
.import gotoxy
.import PLOT
.scope KERNAL
.include "cbm_kernal.inc"
.endscope
.include "vic20.inc"
; VIC-20 KERNAL routines (such as PLOT) do not always leave the color RAM
; pointer CRAM_PTR pointing at the color RAM location matching the screen
; RAM pointer SCREEN_PTR. Instead they update it when they need it to be
; correct by calling UPDCRAMPTR.
;
; We make things more efficient by having conio always update CRAM_PTR when
; we move the screen pointer to avoid extra calls to ensure it's updated
; before doing screen output. (Among other things, We replace the ROM
; version of PLOT with our own in libsrc/vic20/kplot.s to ensure this
; precondition.)
;
; However, this means that CRAM_PTR may be (and is, after a cold boot)
; incorrect for us at program startup, causing cputc() not to work. We fix
; this with a constructor that ensures CRAM_PTR matches SCREEN_PTR.
;
UPDCRAMPTR := KERNAL::UPDCRAMPTR ; .constructor doesn't understand namespaces
.constructor UPDCRAMPTR
_cputcxy:
pha ; Save C
jsr popa ; Get Y
jsr _gotoxy ; Set cursor, drop x
jsr gotoxy ; Set cursor, drop x and y
pla ; Restore C
; Plot a character - also used as internal function
; Plot a character -- also used as an internal function
_cputc: cmp #$0A ; CR?
bne L1
lda #0
sta CURS_X
beq plot ; Recalculate pointers
L1: cmp #$0D ; LF?
_cputc: cmp #$0D ; Is it CBM '\n'?
beq newline ; Recalculate pointers
cmp #$0A ; Is it CBM '\r'?
beq cr
; Printable char of some sort
; Printable char. of some sort
; Convert it from PetSCII into a screen-code
cmp #' '
bcc cputdirect ; Other control char
cmp #$FF ; BASIC token?
bne convert
lda #$DE ; Pi symbol
convert:
tay
bmi L10
cmp #$60
bcc L2
and #$DF
bne cputdirect ; Branch always
L2: and #$3F
lsr a ; Divide by 256/8
lsr a
lsr a
lsr a
lsr a
tax ; .X = %00000xxx
tya
eor pet_to_screen,x
cputdirect:
jsr putchar ; Write the character to the screen
; Advance cursor position
; Advance the cursor position
advance:
iny
cpy #XSIZE
bne L3
jsr newline ; new line
ldy #0 ; + cr
jsr newline ; Wrap around
cr: ldy #$00 ; Do carriage-return
L3: sty CURS_X
rts
; Move down by one full screen-line. Note: this routine doesn't scroll.
;
; (Both screen RAM and color RAM are aligned to page boundaries.
; Therefore, the lower bytes of their addresses have the same values.
; Shorten the code by taking advantage of that fact.)
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 SCREEN_PTR+1
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
@@ -92,14 +107,19 @@ plot: ldy CURS_X
jmp PLOT ; Set the new cursor
; Write one character to the screen without doing anything else, return X
; position in Y
; Write one character to the screen without doing anything else,
; return the X position in .Y
putchar:
ora RVS ; Set revers bit
ldy CURS_X
sta (SCREEN_PTR),y ; Set char
sta (SCREEN_PTR),y ; Set char.
lda CHARCOLOR
sta (CRAM_PTR),y ; Set color
rts
.rodata
pet_to_screen:
.byte %10000000,%00000000,%01000000,%00100000 ; PetSCII -> screen-code
.byte %01000000,%11000000,%10000000,%10000000

View File

@@ -8,12 +8,11 @@
.import zerobss, push0
.import callmain
.import RESTOR, BSOUT, CLRCH
.import __RAM_START__, __RAM_SIZE__ ; Linker generated
.import __MAIN_START__, __MAIN_SIZE__ ; Linker generated
.import __STACKSIZE__ ; Linker generated
.importzp ST
.include "zeropage.inc"
.include "vic20.inc"
; ------------------------------------------------------------------------
; Startup code
@@ -44,10 +43,10 @@ L1: lda sp,x
tsx
stx spsave ; Save the system stack ptr
lda #<(__RAM_START__ + __RAM_SIZE__ + __STACKSIZE__)
lda #<(__MAIN_START__ + __MAIN_SIZE__ + __STACKSIZE__)
ldx #>(__MAIN_START__ + __MAIN_SIZE__ + __STACKSIZE__)
sta sp
lda #>(__RAM_START__ + __RAM_SIZE__ + __STACKSIZE__)
sta sp+1 ; Set argument stack ptr
stx sp+1 ; Set argument stack ptr
; Call the module constructors.
@@ -86,7 +85,7 @@ L2: lda zpsave,x
; ------------------------------------------------------------------------
.segment "INITBSS"
.segment "INIT"
zpsave: .res zpspace

View File

@@ -0,0 +1,352 @@
;
; Extended memory driver for the GEORAM cartridge through the masC=erade
; c64 cartridge adapter. Driver works without problems when statically
; linked.
;
; Marco van den Heuvel, 2018-03-18
;
.include "zeropage.inc"
.include "em-kernel.inc"
.include "em-error.inc"
.macpack generic
.macpack module
; ------------------------------------------------------------------------
; Header. Includes jump table
module_header _vic20_georam_emd
; Driver signature
.byte $65, $6d, $64 ; "emd"
.byte EMD_API_VERSION ; EM API version number
; Library reference
.addr $0000
; Jump table
.addr INSTALL
.addr UNINSTALL
.addr PAGECOUNT
.addr MAP
.addr USE
.addr COMMIT
.addr COPYFROM
.addr COPYTO
; ------------------------------------------------------------------------
; Constants
GR_WINDOW = $9800 ; Address of GEORAM window
GR_PAGE_LO = $9CFE ; Page register low
GR_PAGE_HI = $9CFF ; Page register high
; ------------------------------------------------------------------------
; Data.
.data
pagecount: .res 2 ; Number of available pages
.code
; ------------------------------------------------------------------------
; INSTALL routine. Is called after the driver is loaded into memory. If
; possible, check if the hardware is present and determine the amount of
; memory available.
; Must return an EM_ERR_xx code in a/x.
;
INSTALL:
ldx GR_WINDOW
cpx GR_WINDOW
bne @notpresent
inc GR_WINDOW
cpx GR_WINDOW
beq @notpresent
lda #4
jsr check
cpy GR_WINDOW
beq @has64k
lda #8
jsr check
cpy GR_WINDOW
beq @has128k
lda #16
jsr check
cpy GR_WINDOW
beq @has256k
lda #32
jsr check
cpy GR_WINDOW
beq @has512k
lda #64
jsr check
cpy GR_WINDOW
beq @has1024k
lda #128
jsr check
cpy GR_WINDOW
beq @has2048k
ldx #>16384
bne @setok
@has64k:
ldx #>256
bne @setok
@has128k:
ldx #>512
bne @setok
@has256k:
ldx #>1024
bne @setok
@has512k:
ldx #>2048
bne @setok
@has1024k:
ldx #>4096
bne @setok
@has2048k:
ldx #>8192
bne @setok
@notpresent:
lda #<EM_ERR_NO_DEVICE
ldx #>EM_ERR_NO_DEVICE
rts
@setok:
lda #0
sta pagecount
stx pagecount+1
lda #<EM_ERR_OK
ldx #>EM_ERR_OK
rts
check:
ldx #0
stx GR_PAGE_LO
stx GR_PAGE_HI
ldy GR_WINDOW
iny
sta GR_PAGE_HI
sty GR_WINDOW
ldx #0
stx GR_PAGE_HI
; rts ; Run into UNINSTALL instead
; ------------------------------------------------------------------------
; UNINSTALL routine. Is called before the driver is removed from memory.
; Can do cleanup or whatever. Must not return anything.
;
UNINSTALL:
rts
; ------------------------------------------------------------------------
; PAGECOUNT: Return the total number of available pages in a/x.
;
PAGECOUNT:
lda pagecount
ldx pagecount+1
rts
; ------------------------------------------------------------------------
; USE: Tell the driver that the window is now associated with a given page.
; The GeoRAM cartridge does not copy but actually map the window, so USE is
; identical to MAP.
USE = MAP
; ------------------------------------------------------------------------
; MAP: Map the page in a/x into memory and return a pointer to the page in
; a/x. The contents of the currently mapped page (if any) may be discarded
; by the driver.
;
MAP: sta tmp1
txa
asl tmp1
rol a
asl tmp1
rol a
sta GR_PAGE_HI
lda tmp1
lsr a
lsr a
sta GR_PAGE_LO
lda #<GR_WINDOW
ldx #>GR_WINDOW
; Use the RTS from COMMIT below to save a precious byte of storage
; ------------------------------------------------------------------------
; COMMIT: Commit changes in the memory window to extended storage.
COMMIT: rts
; ------------------------------------------------------------------------
; COPYFROM: Copy from extended into linear memory. A pointer to a structure
; describing the request is passed in a/x.
; The function must not return anything.
;
COPYFROM:
jsr setup
; Setup is:
;
; - ptr1 contains the struct pointer
; - ptr2 contains the linear memory buffer
; - ptr3 contains -(count-1)
; - tmp1 contains the low page register value
; - tmp2 contains the high page register value
; - X contains the page offset
; - Y contains zero
jmp @L5
@L1: lda GR_WINDOW,x
sta (ptr2),y
iny
bne @L2
inc ptr2+1
@L2: inx
beq @L4
; Bump count and repeat
@L3: inc ptr3
bne @L1
inc ptr3+1
bne @L1
rts
; Bump page register
@L4: inc tmp1 ; Bump low page register
bit tmp1 ; Check for overflow in bit 6
bvc @L6 ; Jump if no overflow
inc tmp2
@L5: lda tmp2
sta GR_PAGE_HI
@L6: lda tmp1
sta GR_PAGE_LO
jmp @L3
; ------------------------------------------------------------------------
; COPYTO: Copy from linear into extended memory. A pointer to a structure
; describing the request is passed in a/x.
; The function must not return anything.
;
COPYTO:
jsr setup
; Setup is:
;
; - ptr1 contains the struct pointer
; - ptr2 contains the linear memory buffer
; - ptr3 contains -(count-1)
; - tmp1 contains the low page register value
; - tmp2 contains the high page register value
; - X contains the page offset
; - Y contains zero
jmp @L5
@L1: lda (ptr2),y
sta GR_WINDOW,x
iny
bne @L2
inc ptr2+1
@L2: inx
beq @L4
; Bump count and repeat
@L3: inc ptr3
bne @L1
inc ptr3+1
bne @L1
rts
; Bump page register
@L4: inc tmp1 ; Bump low page register
bit tmp1 ; Check for overflow in bit 6
bvc @L6 ; Jump if no overflow
inc tmp2
@L5: lda tmp2
sta GR_PAGE_HI
@L6: lda tmp1
sta GR_PAGE_LO
jmp @L3
; ------------------------------------------------------------------------
; Helper function for COPYFROM and COPYTO: Store the pointer to the request
; structure and prepare data for the copy
setup: sta ptr1
stx ptr1+1 ; Save passed pointer
; Get the page number from the struct and adjust it so that it may be used
; with the hardware. That is: lower 6 bits in tmp1, high bits in tmp2.
ldy #EM_COPY::PAGE+1
lda (ptr1),y
sta tmp2
dey
lda (ptr1),y
asl a
rol tmp2
asl a
rol tmp2
lsr a
lsr a
sta tmp1
; Get the buffer pointer into ptr2
ldy #EM_COPY::BUF
lda (ptr1),y
sta ptr2
iny
lda (ptr1),y
sta ptr2+1
; Get the count, calculate -(count-1) and store it into ptr3
ldy #EM_COPY::COUNT
lda (ptr1),y
eor #$FF
sta ptr3
iny
lda (ptr1),y
eor #$FF
sta ptr3+1
; Get the page offset into X and clear Y
ldy #EM_COPY::OFFS
lda (ptr1),y
tax
ldy #$00
; Done
rts

View File

@@ -0,0 +1,258 @@
;
; Extended memory driver for the VIC20 $A000-$BFFF RAM. Driver works without
; problems when statically linked.
;
; Marco van den Heuvel, 2018-03-16
;
.include "zeropage.inc"
.include "em-kernel.inc"
.include "em-error.inc"
.macpack generic
.macpack module
; ------------------------------------------------------------------------
; Header. Includes jump table
module_header _vic20_rama_emd
; Driver signature
.byte $65, $6d, $64 ; "emd"
.byte EMD_API_VERSION ; EM API version number
; Library reference
.addr $0000
; Jump table
.addr INSTALL
.addr UNINSTALL
.addr PAGECOUNT
.addr MAP
.addr USE
.addr COMMIT
.addr COPYFROM
.addr COPYTO
; ------------------------------------------------------------------------
; Constants
BASE = $A000
PAGES = ($C000 - BASE) / 256
; ------------------------------------------------------------------------
; Data.
.bss
curpage: .res 1 ; Current page number
window: .res 256 ; Memory "window"
.code
; ------------------------------------------------------------------------
; INSTALL routine. Is called after the driver is loaded into memory. If
; possible, check if the hardware is present and determine the amount of
; memory available.
; Must return an EM_ERR_xx code in a/x.
;
INSTALL:
lda $A000 ; see what is at address $A000
inc $A000 ; see if it can be changed
cmp $A000 ; did it stick ?
beq nomem
dec $A000
ldx #$FF
stx curpage ; Invalidate the current page
inx ; X = 0
txa ; A = X = EM_ERR_OK
rts
nomem: ldx #>EM_ERR_NO_DEVICE
lda #<EM_ERR_NO_DEVICE
; rts ; Run into UNINSTALL instead
; ------------------------------------------------------------------------
; UNINSTALL routine. Is called before the driver is removed from memory.
; Can do cleanup or whatever. Must not return anything.
;
UNINSTALL:
rts
; ------------------------------------------------------------------------
; PAGECOUNT: Return the total number of available pages in a/x.
;
PAGECOUNT:
lda #<PAGES
ldx #>PAGES
rts
; ------------------------------------------------------------------------
; MAP: Map the page in a/x into memory and return a pointer to the page in
; a/x. The contents of the currently mapped page (if any) may be discarded
; by the driver.
;
MAP: sta curpage ; Remember the new page
clc
adc #>BASE
sta ptr1+1
ldy #$00
sty ptr1
lda #<window
sta ptr2
lda #>window
sta ptr2+1
; Transfer one page
jsr transfer ; Transfer one page
; Return the memory window
lda #<window
ldx #>window ; Return the window address
rts
; ------------------------------------------------------------------------
; USE: Tell the driver that the window is now associated with a given page.
USE: sta curpage ; Remember the page
lda #<window
ldx #>window ; Return the window
rts
; ------------------------------------------------------------------------
; COMMIT: Commit changes in the memory window to extended storage.
COMMIT: lda curpage ; Get the current page
bmi done ; Jump if no page mapped
clc
adc #>BASE
sta ptr2+1
ldy #$00
sty ptr2
lda #<window
sta ptr1
lda #>window
sta ptr1+1
; Transfer one page. Y must be zero on entry
transfer:
; Unroll the following loop
loop: .repeat 8
lda (ptr1),y
sta (ptr2),y
iny
.endrepeat
bne loop
; Done
done: rts
; ------------------------------------------------------------------------
; COPYFROM: Copy from extended into linear memory. A pointer to a structure
; describing the request is passed in a/x.
; The function must not return anything.
;
COPYFROM:
sta ptr3
stx ptr3+1 ; Save the passed em_copy pointer
ldy #EM_COPY::OFFS
lda (ptr3),y
sta ptr1
ldy #EM_COPY::PAGE
lda (ptr3),y
clc
adc #>BASE
sta ptr1+1 ; From
ldy #EM_COPY::BUF
lda (ptr3),y
sta ptr2
iny
lda (ptr3),y
sta ptr2+1 ; To
common: ldy #EM_COPY::COUNT+1
lda (ptr3),y ; Get number of pages
beq @L2 ; Skip if no full pages
sta tmp1
; Copy full pages allowing interrupts after each page copied
ldy #$00
@L1: jsr transfer
inc ptr1+1
inc ptr2+1
dec tmp1
bne @L1
; Copy the remainder of the page
@L2: ldy #EM_COPY::COUNT
lda (ptr3),y ; Get bytes in last page
beq @L4
tax
; Transfer the bytes in the last page
ldy #$00
@L3: lda (ptr1),y
sta (ptr2),y
iny
dex
bne @L3
; Done
@L4: rts
; ------------------------------------------------------------------------
; COPYTO: Copy from linear into extended memory. A pointer to a structure
; describing the request is passed in a/x.
; The function must not return anything.
;
COPYTO: sta ptr3
stx ptr3+1 ; Save the passed em_copy pointer
ldy #EM_COPY::OFFS
lda (ptr3),y
sta ptr2
ldy #EM_COPY::PAGE
lda (ptr3),y
clc
adc #>BASE
sta ptr2+1 ; To
ldy #EM_COPY::BUF
lda (ptr3),y
sta ptr1
iny
lda (ptr3),y
sta ptr1+1 ; From
jmp common

View File

@@ -1,12 +1,11 @@
;
; Stefan Haubenthal, 2004-10-07
; Based on code from Pu-239
; Stefan Haubenthal, 2018-04-10
; Based on code by Mike
;
; unsigned char get_tv (void);
; /* Return the video mode the machine is using */
;
.include "vic20.inc"
.include "get_tv.inc"
;--------------------------------------------------------------------------
@@ -14,18 +13,13 @@
.proc _get_tv
NTSC_LINES = 261
; detect the system
lda #TV::NTSC
tax
@L0: ldy VIC_HLINE
cpy #1
bne @L0 ; wait for line 1
@L1: ldy VIC_HLINE
beq @L2 ; line 0 reached -> NTSC
cpy #NTSC_LINES/2+2
bne @L1
ldy $EDE4 ; VIC init table
cpy #5
beq @L0
lda #TV::PAL
@L2: rts ; system detected: 0 for NTSC, 1 for PAL
@L0: rts ; system detected: 0 for NTSC, 1 for PAL
.endproc

View File

@@ -9,7 +9,7 @@
; ------------------------------------------------------------------------
.segment "INIT"
.segment "ONCE"
initirq:
lda IRQVec

View File

@@ -30,29 +30,16 @@
.addr $0000
; Button state masks (8 values)
.byte $01 ; JOY_UP
.byte $02 ; JOY_DOWN
.byte $04 ; JOY_LEFT
.byte $08 ; JOY_RIGHT
.byte $10 ; JOY_FIRE
.byte $00 ; JOY_FIRE2 unavailable
.byte $00 ; Future expansion
.byte $00 ; Future expansion
; Jump table.
.addr INSTALL
.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
@@ -103,20 +90,31 @@ joy1: lda #$7F ; mask for VIA2 JOYBIT: sw3
ldy VIA2_DDRB ; remember the date of DDRB
sta VIA2_DDRB ; set JOYBITS on this VIA for input
lda VIA2_JOY ; read JOYBIT: sw3
lda VIA2_PB ; 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
lda VIA1_PA1 ; 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
php ; Save sw3 in carry
lsr ; Shift sw0,sw1,sw2,sw4 into bits 1-4
tax ; Save sw0,sw1,sw2
and #$10 ; Extract sw4 in bit 4
sta tmp1 ; Save sw4 in bit 4
txa ; Restore sw0,sw1,sw2
lsr ; Shift sw0,sw1,sw2 into bits 0-2
and #$07 ; Mask bits 0-2
plp ; Restore sw3 in carry
bcc @L0 ; Is sw3 set?
ora #$08 ; Yes: Add sw3 in bit 3
@L0: ora tmp1 ; Add sw4 in bit 4
eor #$1F ; Active states are inverted
ldx #0
rts
; Read joystick 2
@@ -128,28 +126,27 @@ joy2: lda #%10000000 ; via port B Data-Direction
bne joy3
lda #$80 ; via port B read/write
sta VIA1_PRB ; (output one at PB7)
sta VIA1_PB ; (output one at PB7)
lda VIA1_PRB ; via port B read/write
and #$1f ; get bit 4-0 (PB4-PB0)
eor #$1f
lda VIA1_PB ; 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)
sta VIA1_PB ; (output zero at PB7)
lda VIA1_PRB ; via port B read/write
and #$0f ; get bit 3-0 (PB3-PB0)
lda VIA1_PB ; 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
lda VIA1_PB ; via port B read/write
and #%00100000 ; get bit 5 (PB5)
lsr
ora tmp1
eor #$1f
eor #$1F
ldx #0
rts

View File

@@ -30,24 +30,12 @@
.addr $0000
; Button state masks (8 values)
.byte $02 ; JOY_UP
.byte $04 ; JOY_DOWN
.byte $08 ; JOY_LEFT
.byte $80 ; JOY_RIGHT
.byte $10 ; JOY_FIRE
.byte $00 ; JOY_FIRE2 unavailable
.byte $00 ; Future expansion
.byte $00 ; Future expansion
; Jump table.
.addr INSTALL
.addr UNINSTALL
.addr COUNT
.addr READ
.addr 0 ; IRQ entry unused
; ------------------------------------------------------------------------
; Constants
@@ -102,20 +90,29 @@ READ: lda #$7F ; mask for VIA2 JOYBIT: sw3
ldy VIA2_DDRB ; remember the date of DDRB
sta VIA2_DDRB ; set JOYBITS on this VIA for input
lda VIA2_JOY ; read JOYBIT: sw3
lda VIA2_PB ; 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
lda VIA1_PA1 ; 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
php ; Save sw3 in carry
lsr ; Shift sw0,sw1,sw2,sw4 into bits 1-4
tax ; Save sw0,sw1,sw2
and #$10 ; Extract sw4 in bit 4
sta tmp1 ; Save sw4 in bit 4
txa ; Restore sw0,sw1,sw2
lsr ; Shift sw0,sw1,sw2 into bits 0-2
and #$07 ; Mask bits 0-2
plp ; Restore sw3 in carry
bcc @L0 ; Is sw3 set?
ora #$08 ; Yes: Add sw3 in bit 3
@L0: ora tmp1 ; Add sw4 in bit 4
eor #$1F ; Active states are inverted
ldx #0
rts

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

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

View File

@@ -1,9 +1,14 @@
;
; Ullrich von Bassewitz, 19.11.2002
;
; VIC20 kernal functions
; VIC20 Kernal functions
;
.include "cbm_kernal.inc"
.export CLRSCR
.export KBDREAD
.export CINT
.export IOINIT
.export RAMTAS
@@ -31,7 +36,9 @@
.export CKOUT
.export CLRCH
.export BASIN
.export CHRIN
.export BSOUT
.export CHROUT
.export LOAD
.export SAVE
.export SETTIM
@@ -42,47 +49,3 @@
.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

View File

@@ -7,15 +7,16 @@
.export PLOT
.scope KERNAL
.include "cbm_kernal.inc"
.endscope
.proc PLOT
bcs @L1
jsr $FFF0 ; Set cursor position
jmp $EAB2 ; Set pointer to color RAM
bcs @L1
jsr KERNAL::PLOT ; Set cursor position using original ROM PLOT
jmp KERNAL::UPDCRAMPTR ; Set pointer to color RAM to match new cursor position
@L1: jmp $FFF0 ; Get cursor position
@L1: jmp KERNAL::PLOT ; Get cursor position
.endproc

View File

@@ -1,8 +1,14 @@
;
; Oliver Schmidt, 2013-05-31
; 2013-05-31, Oliver Schmidt
; 2018-03-11, Sven Michael Klose
;
.export em_libref
.export joy_libref
.export tgi_libref
.import _exit
em_libref := _exit
joy_libref := _exit
tgi_libref := _exit

View File

@@ -32,10 +32,10 @@ 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,
; Get possible command-line arguments. Goes into the special ONCE segment,
; which may be reused after the startup code is run
.segment "INIT"
.segment "ONCE"
initmainargs:
@@ -102,7 +102,7 @@ argloop:lda BASIC_BUF,x
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.
@@ -125,7 +125,7 @@ done: lda #<argv
stx __argv + 1
rts
.segment "INITBSS"
.segment "INIT"
term: .res 1
name: .res NAME_LEN + 1

1008
libsrc/vic20/tgi/vic20-hi.s Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,8 @@
;
; Address of the static standard TGI driver
;
; const void tgi_static_stddrv[];
;
.import _vic20_hi_tgi
.export _tgi_static_stddrv := _vic20_hi_tgi

13
libsrc/vic20/tgi_stddrv.s Normal file
View File

@@ -0,0 +1,13 @@
;
; Name of the standard TGI driver
;
; 2018-03-11, Sven Michael Klose
;
; const char tgi_stddrv[];
;
.export _tgi_stddrv
.rodata
_tgi_stddrv: .asciiz "vic20-hi.tgi"

67
libsrc/vic20/tgihdr.s Normal file
View File

@@ -0,0 +1,67 @@
;
; This code sits immediately after the BASIC stub program.
; Therefore, it's executed by that stub.
;
; 2018-04-17, Greg King
;
.export __TGIHDR__ : abs = 1 ; Mark as TGI housekeeper
.import __MAIN_LAST__
.importzp ptr1, ptr2, tmp1
basic_reset := $C000 ; vector to BASIC's cold-start code
; This code moves the program to $2000. That move allows $1000 - $1FFF
; to be used by the TGI driver to hold its graphics data.
.segment "TGI1HDR"
lda #<(tgi1end + prog_size) ; source
ldx #>(tgi1end + prog_size)
sta ptr1
stx ptr1+1
lda #<(tgi2hdr + prog_size) ; destination
ldx #>(tgi2hdr + prog_size)
sta ptr2
stx ptr2+1
ldx #<~prog_size
lda #>~prog_size ; use -(prog_size + 1)
sta tmp1
ldy #<$0000
; Copy loop
@L1: inx ; bump counter's low byte
beq @L4
@L2: tya ; will .Y underflow?
bne @L3
dec ptr1+1 ; yes, do next lower page
dec ptr2+1
@L3: dey
lda (ptr1),y
sta (ptr2),y
jmp @L1
@L4: inc tmp1 ; bump counter's high byte
bne @L2
jmp tgi2hdr ; go to moved program
tgi1end:
.segment "TGI2HDR"
tgi2hdr:
jsr tgi2end ; run actual program
jmp (basic_reset)
tgi2end:
; The length of the TGI program (including the TGI2HDR segment)
prog_size = __MAIN_LAST__ - tgi2hdr

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

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